Writing GNOME Applications

Writing GNOME Applications

by John R. Sheets

Paperback

$40.46 $44.95 Save 10% Current price is $40.46, Original price is $44.95. You Save 10%.

Overview

Writing GNOME Applications will help Linux programmers learn the basics of GNOME and understand how to write real-world applications using this important programming environment. Focusing on the essentials, this book guides you through GNOME's fundamental elements and explains how and why these elements function as they do. Rather than serving as an exhaustive reference, the book offers detailed discussion on the most important function calls, demonstrating how to put them to work in application development.

You will also find important background on UNIX and the X Window System, upon which GNOME is based. Writing GNOME Applications also presents the essentials of GTK+, GNOME's GUI toolkit. Featuring GNOME 1.2, the latest version, this book provides a comprehensive overview of the GNOME development environment and then discusses in detail such vital GNOME programming topics as:

  • Menus and toolbars, focusing on the GTK+ and GNOME menu systems
  • Dialogs, featuring the GnomeDialog Widget
  • GNOME MDI
  • Session management
  • Graphics, including X Window graphics, GdkRGB, Libart, and GdkPixbuf
  • The GNOME canvas for scrolling, mouse control, and grabbing, dragging, and dropping
  • Documentation, focusing on HTML help systems for applications

Sample applications throughout the book illustrate how these elements function in practice. You will come away from this book with a solid grounding in GNOME fundamentals and the knowledge you need to write a complete GNOME application from front to back.

Product Details

ISBN-13: 9780201657913
Publisher: Addison Wesley Professional
Publication date: 09/21/2000
Pages: 480
Product dimensions: 7.38(w) x 9.23(h) x 0.93(d)

Read an Excerpt

PREFACE: Programming with GNOME is no simple task for the uninitiated. GNOME is one of the larger desktop programming suites you'll find. It has taken two years and hundreds of programmers to become what it is now. GNOME covers a lot of ground and makes use of many, many supporting libraries. Despite its necessary complexity, however, GNOME is very well laid out. It makes sense when you see it as a whole. On a line-by-line basis the code is not arcane or obfuscated. It's actually well written and quite nicely formatted. There's just so much of it!

This book will attempt to guide you through all the fundamental parts of GNOME, to explain how things work and why. Rather than taking you through an exhaustive listing of function calls and coding semantics, we'll concentrate on what makes GNOME tick. We'll certainly go into detail about the important function calls and how to use them, but you'll still want to keep the official GNOME and GTK+ documentation on hand. The official documents are free, just like the rest of GNOME, and should even be bundled with your GNOME distribution.

When you finish with this book, you should have a very clear, intuitive understanding of the GNOME 1.2 framework. You'll be able to write a complete GNOME application, from front to back. If you run into problems, you'll know how to diagnose the problem and where to look for the answers. It's impossible to know absolutely everything, but this book should at least identify everything you need to know.

Prerequisites
Since the core GNOME libraries are written in C, you'll want to know how to read C code. All the code examples inthis book are in C. GNOME covers quite a lot of ground, and we have only so much space in which to talk about it, so we won't be able to go into the beginner's basics of C coding, or even shell scripting. Check your local book store or library for books dedicated to this topic. A full book will do a much better job of explaining it than I would by trying to slip it into the margins.

Although not critical, some knowledge of the GTK+ widget library will help. We'll cover the conceptual basics of GTK+ as we go, and the online documentation is very good, so even if you're not familiar with GTK+, you should be able to follow along without problems.

If you're a Win32 programmer interested in writing a GNOME application, this book has all you need to get started. Chapter 1 provides you with high-level conceptual discussions about UNIX and the X Window System. Chapter 10 covers the fundamentals of the graphics subsystem.

You will need GNOME installed on your system. For the most part, the techniques and API covered in this book will apply equally to the GNOME 1.0 and GNOME 1.2 releases; furthermore, even though the GNOME 2.0 release will bring about many fundamental changes, it will still support backward compatibility. So even though GNOME 2.0 may encourage a different way of doing things, your old 1.x applications should compile just fine under 2.0 (possibly with minor modifications).

This book was written according to GTK+ 1.2.7, gnome-libs 1.2.0, and gdk-pixbuf 0.7.0, as well as autoconf 2.13, automake 1.4, libtool 1.3.2, and gettext 0.10.35. If your software is different from the above snapshot, you may or may not experience subtle differences from the presentation here. Generally speaking, though, if your libraries are newer than these, you should be fine. Aside from the technical essentials, you'll need patience, dedication, and curiosity. A little stubborn drive won't hurt, either. GNOME has a pretty steep learning curve at first, but the journey is well worth it. GNOME has great power, and even greater potential; you'll be happy you stuck with it to the end.

Conventions
The conventions in this book are pretty simple. All function names, file names, commands, and source code listings use a monospace font--for example, "use the gnome_init() function in the file gnome-libs/libgnomeui/gnome-init.c." In some cases, a software package is distributed under the same name as its primary executable. To differentiate between the package and the tool, the package name will appear in normal roman typeface, and the tool name in monospace as always. Thus we might find the following statement: "The autoconf package contains the autoconf tool." The build tools in Chapter 3 are particularly guilty of this ambiguity.

Shell interactions are also in monospace. Commands you type in are prefaced with a "$" prompt and appear in bold (although you shouldn't actually type in the "$"). The output of the command appears in nonbold after the command. In the interest of clarity, certain repetitive output has been omitted. The output on your system may be different from what appears in the book. In the example that follows, the gnome-config command would obviously print out the version of your own GNOME installation.

$ gnome-config --version
gnome-libs 1.2.0

Resources
Your starting point for online documentation about GNOME development should always be ...

Table of Contents

Figures
xiii
Tables
xv
Listings
xvii
Preface xxi
The UNIX Experience
1(20)
What Is GNOME?
1(3)
The Tools
4(9)
Availability
4(1)
Editors, Compilers, and Debuggers
4(3)
Autoconf and Automake
7(2)
Libtool
9(2)
Internalization
11(1)
CORBA
12(1)
The X Window System
13(8)
The System
13(1)
Clients and Servers
14(1)
X Services and Extensions
14(2)
The Event Queue
16(1)
X Resources
17(1)
Graphics
18(3)
The GTK+/GNOME System
21(36)
GLib
21(13)
Simple Data Types
22(1)
Namespaces
22(1)
Logging
23(1)
Containers
24(7)
Other Toys
31(3)
GDK
34(5)
The GTK+ Connection
34(1)
The Thin Wrapper
34(1)
GDK Events
35(1)
Drawing Primitives
36(2)
Reference Counting
38(1)
GTK+
39(13)
Widgets
39(1)
The GTK+ Type System
40(3)
Object Classes
43(2)
Object Properties
45(2)
Signals
47(5)
GNOME
52(5)
Core Libraries
52(1)
Graphics Libraries
52(1)
Components
53(1)
Gnome-xml
54(3)
The GNOME Build Environment
57(60)
The Configuration Script
58(5)
Running configure
58(1)
Inside the configure Script
59(2)
Makefile Variable Substitution
61(2)
Creating Your Own Configuration
63(10)
Autoconf
63(1)
The Configuration Header
64(2)
Checking for Tools
66(2)
Checking for Header Files
68(1)
Custom Checks
69(3)
Helper Tools
72(1)
Generating Makefiles
73(16)
GNU Makefile Standards
73(5)
Using Automake
78(2)
Automake Variables
80(4)
Conditional Compiling
84(3)
Cutting a Distribution
87(2)
Dealing with Libraries
89(8)
Libtool Support
89(1)
libtoolize
90(1)
A Grumpy Example
91(3)
Exploring the Results
94(1)
A Note about Version Numbers
95(2)
Adding GNOME
97(20)
GNOME Macros
97(1)
gnome-config
98(4)
GNOME Makefile Variables
102(1)
autogen.sh
103(2)
Some Grumpy GNOME Examples
105(12)
Internationalization
117(16)
How Internationalization Works
117(2)
Preparing the Source Files
119(1)
Setting Up the Environment
120(2)
Creating the Translation Files
122(4)
Updating the Translation Files
126(2)
Integrating into GNOME
128(5)
The GNOME Application
133(22)
Header Files
133(1)
The GnomeApp Widget
134(2)
The Main Loop
136(3)
Command Line Options
139(4)
The Popt Library
139(4)
Adding Command Line Options
143(1)
Saving Options
143(9)
GNOME Desktop Files
152(3)
Menus and Toolbars
155(32)
The GTK+ Menu System
155(3)
GTK+ Menus
156(1)
GtkMenuItem
156(1)
GtkMenuBar and GtkMenu
157(1)
The GNOME Menu System
158(15)
The GnomeUIInfo Structure
159(2)
Menu Item Types
161(2)
Pixmaps in a Menu
163(3)
Menu Callbacks
166(1)
Menu Macros
167(4)
Menu Array Examples
171(2)
The GNOME Menu API
173(5)
Creating Menus
174(3)
Creating Toolbars
177(1)
Pop-up Menus
178(3)
Popping Up on a Click
178(1)
Popping Up on an Event
179(2)
The Status Bar
181(6)
GnomeAppBar versus GtkStatusbar
181(1)
Creating a GnomeAppBar Widget
182(2)
Setting Messages
184(1)
Updating the Progress Bar
185(2)
Dialogs
187(26)
Message Dialogs
188(8)
Information Dialogs
188(2)
The Question Dialog
190(2)
Message Boxes
192(3)
GnomeApp Messages
195(1)
The GnomeDialog Widget
196(7)
Creating a GnomeDialog Widget
196(2)
Running the Dialog
198(2)
Dialog Properties
200(2)
Closing the Dialog
202(1)
The About Box
203(3)
Property Boxes
206(7)
Creating a Property Box
206(2)
Property Box Signals
208(5)
Using GnomeMDI
213(32)
Multiple Documents in GNOME
213(8)
The GnomeMDI Object
213(2)
MDI Modes
215(3)
Menu Templates
218(2)
Getting Around
220(1)
Registration
220(1)
GnomeMDIChild
221(11)
The Child Object
221(2)
GnomeMDIChild Callbacks
223(4)
Using the Generic Child
227(2)
Menu Creation through a Callback
229(3)
MDI Signals
232(3)
add and remove Signals
232(1)
changed Signals
233(2)
Sample MDI Application
235(10)
Session Management
245(14)
GnomeClient
246(1)
Session Commands
247(2)
Session Signals
249(2)
Adding Session Management to Your Application
251(8)
Graphics
259(54)
Graphics in the X Window System
259(6)
Frame Buffers
259(1)
Color Maps
260(2)
Visuals
262(1)
Drawables
263(1)
Images
264(1)
The GDK Wrapper
265(3)
Simpler API
265(1)
Using Color in GDK
266(2)
GdkRGB
268(6)
The RGB Buffer
269(2)
Drawing Functions
271(2)
Color Management
273(1)
Libart
274(11)
Vector Paths
275(1)
Bezier Paths
276(1)
Sorted Vector Paths
277(1)
Microtile Arrays
278(2)
Affine Transformations
280(2)
Pixel Buffers
282(3)
Gdk-pixbuf
285(28)
Creating
285(4)
Rendering
289(3)
Scaling
292(4)
Progressive Loading
296(2)
Autoconf Support
298(1)
Gdk-pixbuf Application Example
299(14)
The GNOME Canvas
313(54)
The Canvas
313(4)
Double-Buffered Drawing Surface
313(1)
The Canvas Abstraction
314(2)
Canvas Groups
316(1)
Events
316(1)
Coordinate Systems
317(3)
World Coordinates
317(1)
Item Coordinates
318(1)
Canvas Coordinates
319(1)
Window Coordinates
320(1)
Using the Canvas
320(10)
GDK versus AA
321(2)
The Scrolling Region
323(2)
Adding Canvas Items
325(2)
Moving Canvas Items Around
327(2)
Transformations
329(1)
Canvas Items
330(20)
Vector-Based Drawing Items
330(5)
Line Styles
335(2)
The Shape of the Item
337(4)
Widgets in the Canvas
341(1)
Text Canvas Items
341(5)
Graphical Canvas Items
346(4)
Canvas Events
350(17)
The Event Callback
350(1)
Clicks and Double Clicks
351(5)
Mouse Motion
356(3)
Rollovers
359(1)
Keyboard Events
359(2)
Grabbing Items
361(3)
Dragging and Dropping Canvas Items
364(3)
Documentation
367(24)
Writing Documentation
367(5)
HTML Documents
368(1)
DocBook Documents
369(3)
Installing Documentation
372(5)
The Help Directory
372(1)
Setting Up Makefile.am
372(4)
Adding a topic.dat File
376(1)
Invoking the Help System
377(6)
The Help Browser
377(1)
URL Handlers
378(1)
Bringing Up Help
379(1)
Adding Help to the Menu
380(2)
Help in a Property Box
382(1)
Sample Help Application
383(8)
The HTML Help File
383(1)
topic.dat
384(1)
configure.in
384(1)
Makefile.am
385(1)
main.c
385(2)
Compiling and Running the Application
387(4)
Appendix 391(30)
A.1 What Is GNOME?
391(3)
A.2 GNOME Platforms and Support
394(2)
A.3 The X Window System
396(1)
A.4 Installing GNOME
397(3)
A.5 Compilation Issues
400(5)
A.6 Starting GNOME Up
405(1)
A.7 Using GNOME Day to Day
406(4)
A.8 Problems
410(3)
A.9 What Does That Do?
413(3)
A.10 Further Resources
416(2)
A.11 Getting Involved
418(1)
A.12 About This FAQ
419(2)
Index 421

Preface

Programming with GNOME is no simple task for the uninitiated. GNOME is one of the larger desktop programming suites you'll find. It has taken two years and hundreds of programmers to become what it is now. GNOME covers a lot of ground and makes use of many, many supporting libraries. Despite its necessary complexity, however, GNOME is very well laid out. It makes sense when you see it as a whole. On a line-by-line basis the code is not arcane or obfuscated. It's actually well written and quite nicely formatted. There's just so much of it!

This book will attempt to guide you through all the fundamental parts of GNOME, to explain how things work and why. Rather than taking you through an exhaustive listing of function calls and coding semantics, we'll concentrate on what makes GNOME tick. We'll certainly go into detail about the important function calls and how to use them, but you'll still want to keep the official GNOME and GTK+ documentation on hand. The official documents are free, just like the rest of GNOME, and should even be bundled with your GNOME distribution.

When you finish with this book, you should have a very clear, intuitive understanding of the GNOME 1.2 framework. You'll be able to write a complete GNOME application, from front to back. If you run into problems, you'll know how to diagnose the problem and where to look for the answers. It's impossible to know absolutely everything, but this book should at least identify everything you need to know.

Prerequisites
Since the core GNOME libraries are written in C, you'll want to know how to read C code. All the codeexamples in this book are in C. GNOME covers quite a lot of ground, and we have only so much space in which to talk about it, so we won't be able to go into the beginner's basics of C coding, or even shell scripting. Check your local book store or library for books dedicated to this topic. A full book will do a much better job of explaining it than I would by trying to slip it into the margins.

Although not critical, some knowledge of the GTK+ widget library will help. We'll cover the conceptual basics of GTK+ as we go, and the online documentation is very good, so even if you're not familiar with GTK+, you should be able to follow along without problems.

If you're a Win32 programmer interested in writing a GNOME application, this book has all you need to get started. Chapter 1 provides you with high-level conceptual discussions about UNIX and the X Window System. Chapter 10 covers the fundamentals of the graphics subsystem.

You will need GNOME installed on your system. For the most part, the techniques and API covered in this book will apply equally to the GNOME 1.0 and GNOME 1.2 releases; furthermore, even though the GNOME 2.0 release will bring about many fundamental changes, it will still support backward compatibility. So even though GNOME 2.0 may encourage a different way of doing things, your old 1.x applications should compile just fine under 2.0 (possibly with minor modifications).

This book was written according to GTK+ 1.2.7, gnome-libs 1.2.0, and gdk-pixbuf 0.7.0, as well as autoconf 2.13, automake 1.4, libtool 1.3.2, and gettext 0.10.35. If your software is different from the above snapshot, you may or may not experience subtle differences from the presentation here. Generally speaking, though, if your libraries are newer than these, you should be fine. Aside from the technical essentials, you'll need patience, dedication, and curiosity. A little stubborn drive won't hurt, either. GNOME has a pretty steep learning curve at first, but the journey is well worth it. GNOME has great power, and even greater potential; you'll be happy you stuck with it to the end.

Conventions
The conventions in this book are pretty simple. All function names, file names, commands, and source code listings use a monospace font—for example, "use the gnome_init() function in the file gnome-libs/libgnomeui/gnome-init.c." In some cases, a software package is distributed under the same name as its primary executable. To differentiate between the package and the tool, the package name will appear in normal roman typeface, and the tool name in monospace as always. Thus we might find the following statement: "The autoconf package contains the autoconf tool." The build tools in Chapter 3 are particularly guilty of this ambiguity.

Shell interactions are also in monospace. Commands you type in are prefaced with a "$" prompt and appear in bold (although you shouldn't actually type in the "$"). The output of the command appears in nonbold after the command. In the interest of clarity, certain repetitive output has been omitted. The output on your system may be different from what appears in the book. In the example that follows, the gnome-config command would obviously print out the version of your own GNOME installation.

$ gnome-config —version
gnome-libs 1.2.0

Resources
Your starting point for online documentation about GNOME development should always be http://developer.gnome.org. This site contains the complete up-to-date API documentation for both GTK+ and GNOME, as well as an assortment of articles and white papers. Much of this information is distributed with GNOME itself, so you don't necessarily have to go online for access to the developer documents.

The main GNOME Web site, at http://www.gnome.org, is oriented more toward the GNOME community and includes a software map (so you don't end up recreating a GNOME application that already exists), instructions on how to subscribe to the dozens of GNOME-related mailing lists, interviews, the latest version of the GNOME FAQ, and lots of other goodies. For your convenience, the GNOME FAQ is also included in the Appendix of this book.

Also worthy of mention is the GNOME Documentation Project (GDP), located at http://www.gnome.org/gdp, a virtual treasure trove of user-level documentation and writing guides. After you've mastered Chapter 12, "Documentation," you can further expand your writing prowess at the GDP site. Finally, the official GTK+ Web site is at http://www.gtk.org.

The documentation on the Web sites is excellent, but don't underestimate the collection of documents that already reside on your system, accessible through the man and info tools. With these, you can browse the X11 documents (e.g., man XCreatePixmap), the build system documents (e.g., info automake), and much more.

The open-source paradigm also makes available another incredible resource unavailable in the closed-source world: thousands of lines of application source code. Don't be afraid to tap this resource. You can often save hours of work by cracking open an application that already implements the feature you're working on, to see how the original developers handled it. In fact, with the proper attributions you can often yank an entire chunk of code from an existing application and distribute it with your own application. Most GNOME applications are released under the GPL or LGPL licenses (described in Chapter 1), so take care to abide by the rules stated in those licenses, or whatever other license you're borrowing under.

The official Web site for Writing GNOME Applications is http://www.aw.com/cseng/titles/0-201-65791-0/. You can check there for errata and updates, and to download the source code from the book.



Customer Reviews

Most Helpful Customer Reviews

See All Customer Reviews