GNOME

The GNOME layer is the highest, most abstract layer of libraries that we will discuss. We'll spend most of the rest of the book exploring libgnomeui, making an occasional foray into libgnome. The remaining libraries lie beyond the scope of this book. You can learn more about these other libraries at the GNOME developers' Web site: http://developer.gnome.org.

Core Libraries

The core GNOME distribution is divided into numerous smaller libraries, each with its own range of functionality. The main GNOME libraries are libgnome, libgnomeui, and libgnorba.

Libgnome implements the non-GUI functions that GNOME needs, such as command line parsing, process execution, MIME (Multipurpose Internet Mail Extensions), and metadata. It also handles the GNOME configuration database, which is used by applications to persistently store their state. Libgnome provides wrappers for invoking the GNOME help system, playing sounds, and managing games scores, plus a lot more. Libgnome is GNOME's handyman tool belt.

Libgnomeui is GNOME's wrapper and extension around GTK+. It adds more support for dialogs, graphics, and entry boxes, plus a host of interesting new widgets. Libgnomeui also adds extended support for dockable menus and toolbars, as well as a multiple document interface (MDI) for handling multiple windows in the same application (see Chapter 8).

The final core library is libgnorba, a helpful wrapper around GNOME's CORBA functionality. Libgnorba provides functions to initialize ORBit, and to integrate it into the main loop of your application. Through GOAD, the GNOME Object Activation Directory, libgnorba allows you to find, load, and activate a wide variety of CORBA objects.

Graphics Libraries

Xlib and GDK make up the foundation upon which GNOME's graphics are built. GNOME adds a few layers of its own. The simplest graphical extensions are GNOME's graphical widgets, which implement a small, focused slice of functionality. These include the GnomePixmap widget, which makes it very easy to load a single image into a widget for display. GNOME's graphical widgets, just like all its other widgets, reside in libgnomeui.

One of GNOME's crowning achievements is a somewhat complex drawing widget, the GNOME Canvas. The Canvas is a double-buffered, object-oriented drawing surface that will handle all the rendering and buffering for you. You can rotate objects, and even click on them and drag them around inside the Canvas. See Chapter 11 for details on how to do this.

If you need more than image loading and simple manipulation, GNOME provides libart, a library of advanced functions to stretch, scale, rotate, bend, clip, and render raw RGB (red-green-blue) images. This library is not for the faint of heart, but fortunately GNOME wraps most of it up and uses it behind the scenes, where you'll never have to see it directly (unless you really want to). In fact, the GNOME Canvas uses libart extensively, but for the most part it exposes that functionality only through its own API.

The official image-loading library for GNOME 1.2 is the gdk-pixbuf library, which has many useful functions for loading different image file formats, like PNG, JPEG, TIFF, and more, into RGB pixel buffers that you can then display in your applications. It also provides some rendering functions for copying images onto various drawing surfaces. Gdk-pixbuf is the graphics library you'll most likely use for manipulating images. We'll explore libart and gdk-pixbuf in Chapter 10.

Components

One of the main differences between GTK+ and GNOME is that GNOME imposes a certain amount of GUI policy on its applications. While at first this may seem like a limiting choice, in practice it frees you from having to recon- struct the basics of your GUI each time you create a new application. GNOME's policy constraints aren't much of a limitation, either, unless you plan on making a radical departure from common GUI designs, as certain graphics- intensive music-playing applications do.

Much of the added architecture of the GNOME system takes two forms: (1) simplification of the more complex GTK+ interfaces and (2) division of the new functionality into widgets, GTK+ objects, and CORBA components. The GnomeApp widget is the cornerstone of the GNOME GUI encapsulation. Transparently, GnomeApp adds support for the menus and floating toolbars, with only minor effort from you-much less than you would have to do to add the same features to a GTK+-only application (see Chapter 5).

The GNOME Multiple Document Interface (GnomeMDI) provides an infrastructure for displaying and managing more than one document in the same application. GnomeMDI displays its documents in various different MDI modes, including a tabbed notebook mode and a multiwindow mode. End users can choose which MDI mode they want to use.

GNOME also offers its own CORBA-based component system, called Bonobo. Bonobo is a specification for communicating between components in graphical applications. It has a lot in common with Microsoft's OLE2 technology, and in fact OLE2 was a prominent consideration in the initial design of Bonobo. Using Bonobo, you can embed parts of one application into another, transparently to the user.

The classic example is the spreadsheet inside a word processor document. GNOME's spreadsheet application, Gnumeric, has a Bonobo spreadsheet component. Any Bonobo-based application can load that spreadsheet into itself. The host application, called the container, will take care of drawing the Bonobo spreadsheet and will add any spreadsheet-specific menus and toolbars into the container application. The actual functionality of the spreadsheet, including data storage and math calculations, is contained within Gnumeric's Bonobo component, using CORBA to communicate back and forth.

Bonobo's component model makes good on the promise of the object-oriented desktop. Rather than reimplementing fundamental components like spreadsheets, text editors, and file browsers in each new application that needs them, developers can create these components once, as Bonobo objects, and all new applications can share them. Unfortunately, we don't have room for a full CORBA/Bonobo treatment here. For more information about Bonobo, look through the online documentation at http://developer.gnome.org and examine the examples distributed with the Bonobo source code. You may also want to pore over the source code of some GNOME applications that use Bonobo, to learn from example.

Gnome-xml

One of the biggest buzzwords to come out of the computer industry in recent years is XML (eXtensible Markup Language). Yet despite the sudden glamour and hype, XML rests on a foundation that has been around for years and years: the Standard Generalized Markup Language (SGML). SGML is one of the most widely used documentation and data formats around, and HTML (HyperText Markup Language) is one of its most popular variants. XML is essentially a smaller, narrower snapshot of the larger SGML specification, making it much easier to use and parse. Many implementations of XML exist on a wide variety of platforms, including UNIX and Microsoft Windows. GNOME's implementation of XML resides in the gnome-xml package.

Gnome-xml offers several features that make it a powerful, flexible interface for dealing with XML. You can read an XML document from memory or from a file. For smaller documents, you can parse the entire document in one fell swoop, before interacting with it. For larger documents, or for perfor- mance-intensive applications, you can use gnome-xml's Simple API for XML (SAX) interface, an event-based approach that triggers actions as it reads through the document, rather than waiting until the end. When you're done with an XML document, you can save it back to disk or to a memory buffer. Gnome-xml can also use compression when you're loading from and saving to files.

Gnome-xml supports many important standards, where possible, as declared by the World Wide Web Consortium (http://www.w3.org), including the XML specification itself, the Document Object Model (DOM), and XPath. DOM is an API for accessing structured SGML documents; XPath is a specification for addressing parts of an XML document in a standardized manner. Gnome-xml also supports XML namespaces. For more information on gnome-xml, go to its Web site at http://xmlsoft.org.