Read an Excerpt
Gtk+ was originally developed by two University of California at Berkeley students, Spencer Kimball and Peter Mattis. They had developed, as a part of a school project, an image manipulation called The GNU Image Manipulation Program (The GIMP, www.gimp.org). Originally it was written in Motif, but due to the (at the time) closed-source nature of Motif and, as a result, its scarcity on freely available open-source UNIX platforms, they decided to come up with an open-source toolkit, inspired by Motif, to which The GIMP could then be ported. The goal was not to develop a general-purpose toolkit for the X Window System, although that is what Gtk+ has become. Hundreds if not thousands of programs have been written using Gtk+ to date, ensuring that Gtk+ will be around for some time to come. More information on the history of Gtk+ (and The GIMP) can be found at www.gimp.org/~sjburges/gimp-history.htmlAbout This Book
This book covers the 1.2 version of the GIMP Toolkit (Gtk+) and was written with the following goals in mind:
- To provide a general introduction to programming applications with Gtk+ 1.2
- To provide a detailed description of the Gtk+ 1.2 widget set
- To provide a quick reference to the Gtk+ 1.2 widget set for those programmers already familiar with Gtk+
For those of you looking for an introduction to Gtk+ programming, I suggest reading Chapters 1 through 4 first, followed by Chapter 10, "Container and Bin Classes." The first few chapters (Chapters 1, 2, and 3) describe the architecture of Gtk+ and provide information needed to program and build a simple Gtk+ application. Most readers will want to skimthrough Chapter 4, "Widgets," which describes GtkWidget. GtkWidget is the parent class from which the remaining widgets in the Gtk+ class hierarchy inherit much of their functionality. Container widgets are used to organize the layout of other widgets in a window (or within other containers). The concept of container widgets is described in the first few sections of Chapter 10. The GtkBox widgets are by far the most versatile of the container widgets implemented by Gtk+ 1.2 and, as a result, are the most commonly used. GtkBox, GtkHBox, and GtkVBox are all described in Chapter 10 of this book.
The remaining chapters provide detailed descriptions of the bulk of the widget classes implemented in Gtk+ 1.2. I have made every effort to describe in detail the application-level programming interfaces exposed by the Gtk+ widget sets covered in this book. I have included most of the code I wrote while investigating the Gtk+ widget set. In some cases, the source code consists of a full-size (although functionally limited) application. In all other cases, I simply present short code snippets that help to illustrate points made in the surrounding text. Complete source-code examples for the book can be found on my Web site at www.cts.com/crash/s/slogan/gtkbook.html
I have placed Gtk+ widget reference material directly in the main body of the text (as opposed to placing it at the end of the book in an appendix). The reference material provides function prototypes for each of the application-level functions that have been exposed by the widgets described in the book and a one-line sentence describing the purpose of each of these functions. In the reference section, I also enumerate all of the object attributes that can be set and/or retrieved on the widget (see the "Object Attributes" section in Chapter 3, "Signals, Events, Objects, and Types"). I also list the signals that can be generated by the widget, if any. For each signal, I supply the function prototype of the application-level signal handler invoked when the signal fires (see the "Signals" section in Chapter 3). The reference material provides an introduction to the widget for first-time programmers and can serve as a quick reference for programmers who are already familiar with widgets. More information about the structure of the reference section is spelled out in Chapter 4 (see the reference section for the GtkWidget widget).
This book focuses on describing the Gtk+ widget set. This book does not cover the Gtk+ Drawing Kit (GDK), or the G Library (Glib), or widget writing in any detail (except where unavoidable). For GDK and GLib, I refer you to one or both of the following books: Developing Linux Applications with GTK+ and GDK by Eric Harlow and GTK+/Gnome Application Development by Havoc Pennington. You can also find reference material on these topics at www.gtk.org. I do plan to provide an additional chapter on Gtk+ widget development on my Web site; it should be available shortly after this book goes to press. Hopefully, this material will be included in a subsequent edition of this book.Source Code
I plan to make the source code for this book available online. Please go to www.users.cts.com/crash/s/slogan/gtkbook.html for further details.Onward...
By purchasing this book, you have decided to develop an application for Linux/UNIX, and you have also decided to develop this application using Gtk+. In addition to learning about Gtk+, you should take some time to learn more about the desktop environment(s) within which users will be executing your application. If you are targeting GNOME-and some of you are-you should learn about developing for the GNOME environment using the books and Internet resources available. This book covers the Gtk+ toolkit, upon which all GNOME applications are based, but I do not cover GNOME application development specifically within these covers.