17.4 GNOMEGTKWIDGETS


17.4 GNOME/GTK+WIDGETS

In Chapter 3, we showed that it is possible to simulate object-oriented behavior directly in C, provided one rigidly obeys certain programming and naming conventions (and also provided one is willing to accept the resulting somewhat more tortured programming syntax). The C-based package of software that goes under the name GNOME/GTK+ uses such object orientation for GUI design.

GNOME, which stands for GNU Object Modeling Environment, was designed for creating desktop environments. In functionality and in terms of the widgets included, GNOME is an extension of the GTK+ toolkit. The GTK+ toolkit contains two libraries: GTK and GDK. GTK, which stands for the GIMP[7] Tool Kit, consists of a large collection of functions and structures for creating different kinds of GUI widgets and for controlling various aspects of the widgets included in a GUI, such as their spatial layout. The GDK library-GDK stands for GIMP Drawing Kit-provides numerous drawing functions and facilities for managing colors, fonts, and so on.

The fundamental data types used in GNOME, GTK+, GDK, GIMP, and so on, are defined in the library glib of low-level C functions, macros, and structures. The glib library was created as a part of GIMP development for the purpose of standardization and portability. For example, an int in C may be represented by 16 bits in some machines and 32 in others. Similarly, a char may be signed in some and unsigned in others. By contrast, glib defines a type called gint for representing integers; a gint is always 32 bits. If your GNOME/GTK+ code needs a shorter integer, you can use gint8 for an 8-bit integer, or a gint 16 for a 16-bit integer. Similarly, a gchar will always be signed. If you need an unsigned char, you can use guchar. The glib library also comes with utility functions for memory management, string manipulation, and the formatting of textual output. GNOME/GTK+ programs will, for example, use g_print() instead of printf(), g_malloc() instead of malloc(), and so on.

GtkObject is the root of the GNOME/GTK+ type hierarchy. The GNOME/GTK+ widgets are all in the subtree that hangs from GtkWidget, a direct subtype of GtkObject. While many of these widgets can be displayed, others are intended to serve either as containers for the displayable widgets or just to serve as base types for lending organization to the displayable widgets. A widget type whose instances can be displayed must have associated with it a function that has ‘_new_' somewhere in the name of the function and this function must return a pointer to the newly constructed instance. If no such function exists for a widget type, it can only be used as a base type to create other subtypes.

The GNOME/GTK+ widget types can be categorized in the same way that was shown earlier for AWT/Swing and for Qt. There are the top-level containers like GtkWindow that get displayed as windows on a terminal; intermediate level containers like GtkTable, GtkHBox, and so on, for creating different kinds of groupings of the more atomic widgets; atomic widgets like GtkButton, GtkEditable, GtkLabel, and so on, that actually get displayed in a window; and utility widgets like GtkLayout, GtkSeparator, and so on.

[7]GIMP stands for the GNU Image Manipulation Program. GIMP, available as open source software, is to a Unix-like platform what Photoshop is to a Windows-based system.




Programming With Objects[c] A Comparative Presentation of Object-Oriented Programming With C++ and Java
Programming with Objects: A Comparative Presentation of Object Oriented Programming with C++ and Java
ISBN: 0471268526
EAN: 2147483647
Year: 2005
Pages: 273
Authors: Avinash Kak

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net