Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.sao.ru/cats/~satr/GGAD/z4.html
Дата изменения: Wed Jul 12 23:54:36 2000 Дата индексирования: Mon Oct 1 23:49:13 2012 Кодировка: Поисковые слова: storm |
GTK+ / Gnome Application Development | |||
---|---|---|---|
<<< Previous | Home | Next >>> |
Gnome's application development framework centers around a suite of libraries, all written in portable ANSI C and intended to be used on UNIX-like systems. Libraries which involve graphics realy on the X Window System. Wrappers are available which export the Gnome API to nearly any language you can think of, including Ada, Scheme, Python, Perl, Tom, Eiffel, Dylan, and Objective C. There are at least three different C++ wrappers as well.
This book will cover the C interface to the libraries; however, it should be useful for users of any language binding, since the mapping from C to your preferred language is typically straightforward. The book covers version 1.0 of the Gnome libraries (including the compatible bug fix releases, such as 1.0.9---all 1.0.x versions are compatible).
Taking full advantage of the free software tradition, Gnome didn't start from scratch. It uses several libraries which are maintained separately from the Gnome project. These are a part of the Gnome application development framework, and you can count on their presence in a Gnome environment.
glib is the base of the Gnome infrastructure. It's a C utility library, providing routines to create and manipulate common data structures. It also addresses portability issues; for example, many systems lack the snprintf() function, but glib contains an implementation called g_snprintf() which is both guaranteed to exist on all platforms and slightly safer than snprintf() (it always NULL-terminates the target buffer).
Gnome 1.0 uses glib version 1.2 and works with any glib in the 1.2 series (1.2.1, 1.2.2, etc.). All glib versions beginning with 1.2 are compatible bug-fix releases.
GTK+, or the Gimp Tool Kit, is the GUI toolkit used in Gnome applications. GTK+ was originally written for the Gimp (GNU Image Manipulation Program --- http://www.gimp.org), but has become a general-purpose library. GTK+ depends on glib.
The GTK+ package includes GDK, the Gimp Drawing Kit, which is a simplification and abstraction of the low-level X Window System libraries. Since GTK+ uses GDK rather than calling X directly, a port of GDK permits GTK+ to run on windowing systems other than X with relatively few modifications. GTK+ and the Gimp have already been ported to the Win32 platform in this way.
GTK+ provides several features for Gnome applications:
A dynamic type system.
An object system written in C, complete with inheritance, type checking, and a signal/callback infrastructure. The type and object systems are not GUI-specific.
A GtkWidget object written using the object system, which defines the interface GTK+'s graphical components implement.
A large collection of useful GtkWidget subclasses (widgets); this collection forms the bulk of GTK+'s code.
Gnome adds a number of additional widgets to the basic GTK+ collection.
Gnome 1.0 is based on GTK+ version 1.2. All GTK+ versions beginning with 1.2 are compatible bug-fix releases; 1.2.1, for example.
ORBit is a CORBA 2.2 ORB written in C. It was designed to be small and fast compared to other ORBs, and supports the C language mapping. ORBit is implemented as a suite of libraries.
CORBA, or Common Object Request Broker Architecture, is a specification for Object Request Brokers, or ORBs. An ORB is much like a dynamic linker, but it works with objects, rather than subroutines. At runtime, a program can request the services of a particular object; the ORB locates the object and creates a connection between it and the program. For example, an email program might request an ``addressbook'' object, and use it to look up a person's name. Unlike dynamic linking, CORBA works fine across a network, and even allows different programming languages and operating systems to interact with one another. If you're familiar with DCOM on the Windows operating system, CORBA is analagous.
Imlib ("Image Library") provides routines for loading, saving, displaying, and scaling images in a variety of popular formats (including GIF, JPEG, PNG, and TIFF). It comes in two versions; an Xlib-only version, and a GDK-based version. Gnome uses the GDK version.
The libraries in this section are a part of the gnome-libs package and were developed specifically for the Gnome Project.
libgnome is a collection of non-GUI-related routines for use by Gnome applications. It includes code to parse configuration files, for example. It also includes interfaces to some external facilities, such as internationalization (via the GNU gettext package), argument parsing (via the popt package), and sound (via the Enlightenment Sound Daemon, esound). The gnome-libs package takes care of interacting with these external libraries, so the programmer does not need to concern herself with their implementation or availability.
libgnomeui collects GUI-related Gnome code. It consists primarily of widgets designed to enhance and extend GTK+. Gnome widgets generally impose user interface policy, which permits a more convenient API (since there is less for the programmer to specify). It also results in applications with more consistent interfaces, of course.
Highlights of libgnomeui include:
The GnomeApp widget, which makes it easy to create a nice main window for your application. It uses another widget called GnomeDock which enables users to rearrange and "undock" toolbars.
The GnomeCanvas widget which makes it easy to write intricate, flicker-free custom displays.
The Gnome stock pixmaps (icons for open, close, save, and other operations).
Convenient routines for creating and using dialogs.
The GnomePixmap widget which is more versatile than GtkPixmap.
libgnorba provides CORBA-related facilities, including a security mechanism and object activation. (Object activation is the process of obtaining a reference to an object that implements a given interface; it can involve executing a server program, loading a shared library module, or asking an existing program for a new object instance.)
This small library contains a terminal widget (ZvtTerm) you can use in your Gnome programs.
This library contains graphics rendering routines by Raph Levien. The routines included here are released under the GNU Library General Public License and used in the GnomeCanvas widget; Raph Levien also sells an enhanced proprietary version. libart_lgpl provides antialiasing, microtile refresh regions, and other magic. In essence it is a vector graphics rasterization library, functionally analogous to the PostScript language.
These libraries are commonly used in Gnome applications, but are not a part of gnome-libs proper.
gnome-print is still somewhat experimental, but very promising. It uses libart_lgpl and works nicely with GnomeCanvas. It provides virtual output devices (called "print contexts"), so a single codebase can output to a print preview widget, to PostScript, and eventually to other printer formats. gnome-print also includes printing-related GUI elements, like a print setup dialog, and a virtual font interface (to deal with the problem that X fonts are not printable).
gnome-xml is a non-validating XML engine written by Daniel Veillard of the World Wide Web Consortium. It can parse XML into a tree structure, and output a tree structure as XML. It's useful for any application that needs to load and save structured data; many Gnome applications use it as a file format. This library does not depend on any of the others, not even glib --- so it is tied to Gnome in name only. However, you can expect most Gnome users to have it installed, so it should not inconvenience your users if your application uses this library.
Guile is an implementation of the Scheme programming language in a library, so that any application can have an embedded Scheme interpreter. It is the official extension language of the GNU Project, and is used by several Gnome applications. Adding an extension language to your application might sound complex, but Guile makes it almost trivial. (Several Gnome applications support Perl and Python as well; it is usually easy to support several languages once you implement the first. But Guile has a special place in the Gnome developer's hearts.)
At press time, the Gnome hackers were putting the finishing touches on Bonobo. Bonobo is a compound document architecture in the tradition of Microsoft's OLE; it allows you to embed charts in spreadsheets, for example. It will be used pervasively throughout Gnome; any application will be able to display MIME-typed data such as plain text, HTML, or images by asking the Gnome libraries for an appropriate Bonobo component. Look for Bonobo technology in the next major Gnome release.
Throughout the book, the exact header file which declares each function is given alongside the function prototype. This is to facilitate your exploration of the source code. However, you probably don't want to manually include the hundreds of headers found in GTK+ and Gnome. You can include all GTK+ headers en masse by including the gtk/gtk.h header file. gtk/gtk.h also includes gdk/gdk.h for you. You can include all Gnome headers by including gnome.h; gnome.h includes gtk/gtk.h for you. Most Gnome application files simply include gnome.h.