Edinburgh Castle
Foundations of GTK+ Development
AuthorAndrew Krause
DateApril 2007
ReviewerChris Yocum
Cover image for Foundations of GTK+ Development

When a developer begins the design process for a new open source GUI application, there are only two viable choices, Trolltech's Qt and GTK+. GUI applications are complicated to write and often complicated to understand. Into this space steps, Apress' "Foundations of GTK+ Development" by Andrew Krause, the developer of OpenLDev IDE built with GTK+ 2. From the first page, the reader is impressed with the scope and depth of the topics covered. Krause takes the reader from the first Hello World program to creating custom widgets in thirteen chapters. The layout of the page is clean and the code sections are clearly typeset with good variable names and structure making the intent of the code clear.

While the main purpose of the book is to provide a reference for the experienced GTK+ developer, the layout of the chapters emphasizes teaching the beginner the basic structures of a GTK+ program all the way to advanced topics such as developing custom widgets and the Glade GUI builder application. Many of the most important details, such as various enumerations, are placed appropriately in the appendices while those that are used are clearly detailed in the text.

As Krause focuses on the foundation of GTK+ development, all the examples are in C and the reader should be prepared with a good knowledge of C. While there are many different languages which have bindings for GTK+, which allow programmers to use their programming language of choice, the advantage of learning the C foundations of GTK+ is that the reader gets a clear understanding of how the library works "under the hood". The reader will appreciate how their chosen bindings interact with the base library.

Each chapter begins with a list of what a reader will learn and ends with a summary of the major points of the chapter followed by an exercise. These exercises are designed to be broad and leave much for the reader to do and learn with in the structure given by the exercise. If the reader becomes stuck the website (http://www.gtkbook.com) has the appropriate sources to help the reader understand the structure being used within the program to achieve its ends.

Chapter 1 gives the history of the GTK+ project, X11, covers the installation of the details of the libraries involved in developing GTK+ applications. The exercise at the end of Chapter 1 has the reader verify the installation of the GTK+ libraries.

Chapter 2 is where the rubber hits the road as far as programming with GTK+ is concerned. The "Hello World" program gives the general structure of GTK+ development, which is maintained through out the following chapters. The widget hierarchy is discussed as well as how to cast objects properly ensuring correct pointer type to each particular function. All the signals and event handlers are discussed at a proper level of detail for a beginning chapter. If this were the only chapter, it would provide any programmer with enough detail to begin exploring the API and begin their own application.

Chapter 3 and 4 cover container widgets, which control layout and decorations, which allow different effects on widgets, and basic widgets (e.g. GtkToggleButton, GtkCheckButton, etc.). These are the basis for any good windowing toolkit and they are demonstrated ablely and with confidence by an author who is clearly comfortable with the toolkit and has no trouble articulating this to his reader.

Chapter 5 covers the different stock dialogs which come with GTK+, the About dialog, Information dialogs, and the FileChooser dialog, etc. While these are useful, building your own dialog boxes are left until later chapters but this chapter does give the reader a feel for how to use dialogs and where to place them in your program source for maximum readability.

Chapter 6 is an odd chapter as it covers GLib and is not related directly to GTK+ but it is necessary as some GTK+ functions return structures from this library. While it does give the reader a break from learning directly about GTK+, it seems oddly placed however as it needed to go somewhere and Chapter 6 is as good as any other chapter. This chapter is the longest chapter in the book and the author gives the reader a well deserved pat on the back at the end.

Chapter 7 and 8 are devoted to the most complicated but useful widgets, TextView and TreeView. The TextView widget allows many different operations for displaying text and the reader is introduced to many of the functions that would allow one to write a word processor. This chapter is helped heavily by the fact that Krause is the developer of an application that uses this widget heavily. The use of the Pango library and the facilities for fonts are also covered in this chapter. In the next chapter, the reader is taken for a tour of the TreeView widget which mostly consists of creating different renderers for the different cells. The reader is given useful advice about which to use where and where to avoid using renderers which are called too often.

Chapter 9 describes how to build menus, toolbars, and popup menus both manually and with the XML based mark-up language which comes with GTK+. The reader is also introduced to the method for creating their own stock icons for the tool bars and menu items. This chapter basically completes the core development needs of an application programmer and if the book stopped here, it would be well worth purchasing. The reader should now be acquainted well enough with GTK+ to explore the API for needed functions and structures themselves. The XML demonstrated is a help as much of the code for this section is a tad boring and repetitive and the XML allows the reader to quickly create the required objects for the system.

Chapter 10 is another break from direct GTK+ development and the author has a few points about user interface design before showing the reader the Glade UI designer and libglade, which is necessary to use the interface builder. Much of a GTK+ application can be created from Glade but, as Krause rightly cautions the reader, there is still much development that needs to occur for the application to have the correct behavior. The XML created by Glade is similar to that used in the previous chapter but it covers much of what a developer would need in an application. While some may have wished that Glade was introduced earlier in the course of the book, Glade is an advanced topic and it is beneficial for the reader to understand how to create applications without Glade so that one could appreciate the design decisions when developing with GTK+.

Chapter 11 shows the reader how to create custom widgets within the toolkit from scratch which exposes in detail the inner workings of GTK+. Here Krause demonstrates using an IP input widget and a marquee widget. This chapter is quite long and involved and may take more than one read but it is well worth the exercise to understand more about the internals of the widgets that were introduced in earlier chapters.

Chapter 12 is a miscellaneous chapter with some interesting widgets that did not fit into the structure of the previous chapters including the helpful GtkPrintOperation. Chapter 13 gives you five applications built with the facilities of the previous chapters and the code for these can be obtained from the book's web site. The appendices follow and contain much information that is helpful when creating applications with GTK+.

For the beginner, this book is an invaluable resource for learning about GTK+. The content is substantive and concise while maintaining consistency throughout. The consistency, especially in the code sections, reinforces the information presented and code structure, which helps the beginner keep good coding style when writing for GTK+. The book remains tightly focused on presenting this sometimes daunting amount of information, which is one of the other great qualities of the book. For the expert, the table of contents, the appendices, and the index are the most important aspects of the book. These parts of the book are amply treated so that it is easy to use the book as a quick memory refresh. Overall, this book is a solid and dependable guide to a large windowing toolkit and should sit comfortably on any GUI application developer's desk.

Table of contents

Foundations of GTK+ Development
Ch  1 Getting Started
Ch  2 Your First GTK+ Applications
Ch  3 Container Widgets
Ch  4 Basic Widgets
Ch  5 Dialogs
Ch  6 Using GLib
Ch  7 The Text View Widget
Ch  8 The Tree View Widget
Ch  9 Menus and Toolbars
Ch 10 Dynamic Custom Widgets
Ch 11 Creating Custom Widgets
Ch 12 Additional GTK+ Widgets
Ch 13 Putting It All Together
App A GTK+ Properties
App B GTK+ Signals
App C GTK+ Styles
App D GTK+ Stock Items
App E GError Types
App F Exercis Solutions and Hints

faded separator

Page maintained via github.com/edinburgh-pm/edinburgh.pm