4 Overview of the Motif Toolkit
This chapter helps the reader understand the components of a real Motif application. It discusses how to handle the
geometry management of primitive widgets within a manager widget, when to put components into the main window,
when to use dialog boxes and menus, and how to relate to the window manager. After reading this chapter, the
programmer should have a solid overview of Motif application programming, and she should be able to read the
remaining chapters in any order.
In Chapter 2, The Motif Programming Model, we talked about the basic structure of an Xt−based program. We
described how to initialize the toolkit, create and configure widgets, link them to the application, and turn control over
to Xt's main loop. In this chapter, we discuss the widgets in the Motif toolkit and how you can put them together to
create an effective user interface for an application.
If you already have a basic understanding of the Motif widgets, you can jump ahead to any of the later chapters in the
book that focus on individual widget classes. This chapter provides some insight into the design of the widgets and a
general overview of the Motif style and methodology, which you may find useful when developing your own
applications.
This chapter also describes all of the new features in Release 1.2 of Motif. If you are familiar with Motif 1.1 but need
to get up to speed with Motif 1.2, you should read Section #smotif12. In this section, we summarize the new features
and tell you where to find more information about them. We also describe all the changes made to the example
programs in this book to make them up−to−date with Motif 1.2. While Motif 1.2 is backwards−compatible with Motif
1.1, there are a number of functions and resources in Motif 1.2 that replace obsolete functions and resources in Motif
1.1.
4.1 The Motif Style
You don't build a house just by nailing together a bunch of boards; you have to design it from the ground up before
you really get started. Even with a prefabricated house, where many of the components have already been built, you
need a master plan for putting the pieces together. Similarly, when you are designing a graphical user interface for an
application, you have to think about the tasks your application is going to perform. You must envision the interface
and then learn to use your tools effectively in order to create what you've envisioned.
The Motif toolkit provides basic components that you can assemble into a graphical user interface. However, without
design schematics, the process of assembling the user−interface elements may become ad hoc or inconsistent. Here is
where the Motif Style Guide comes in. It presents a set of guidelines for how widgets should be assembled and
grouped, as well as how they should function and interact with the user.
All Motif programmers should be intimately familiar with the Style Guide. While we make recommendations for
Motif style from time to time, this book is not a replacement for the Style Guide. There are many aspects of Motif
style that are not covered in detail here, as they involve the content of an application rather than just the mechanics.
On the other hand, the Motif Style Guide is not an instructional manual for the Motif toolkit. In fact, many of the
objects described in the Style Guide are not even widgets, but higher−level, more complex objects that are composed
of many widgets.
For example, the Style Guide describes an object called a MenuBar, which spans the top of the main window of an
application. The MenuBar contains menu titles that, when clicked on, display PulldownMenus. The Motif toolkit does
not implement MenuBars or PulldownMenus as distinct widget classes, nor does the Style Guide make any
43
recommendations about how menu objects should be implemented. What the Style Guide does talk about (albeit
somewhat loosely) is the actions that can be taken by an item on a menu: it can invoke an application function, pop up
a dialog box containing yet more options and commands, or display a cascading menu (also known as a pullright
menu).
The Style Guide also makes recommendations about the menus that an application should provide. For example, most
applications should have a File menu that provides items such as an Exit button to exit the application and a Save
button to save file. It also specifies details of presentation, such as that you should provide an ellipsis (...) as part of
the label for a menu item that requires the user to provide more information before action is taken.
How the Motif toolkit goes about supporting, and in some cases enforcing, the guidelines of the Motif Style Guide
brings up some interesting points, particularly in relation to some of the underlying principles of the X Toolkit
Intrinsics. In Xt, a widget is envisioned as a self−contained object that is designed to serve a specific, clearly−defined
function. Many of the Motif widgets, such as Labels, PushButtons, ScrollBars, and other common interface objects,
are implemented as separate widgets.
In other cases, however, Motif steps outside of the Xt model by creating compound objects out of several widgets and
then expecting you to treat them as if they were a single object. For example, Motif provides the ScrolledText and
ScrolledList objects, which combine a Text or List widget with a ScrolledWindow widget, which in turn automatically
manages horizontal and vertical ScrollBars.
In another case, the Motif toolkit provides a complex, general−purpose widget that can be configured to appear in
several guises. There is no MenuBar widget class and no PulldownMenu widget class. Instead, the RowColumn
widget, which also serves as a general−purpose manager widget, has resources that allow it to be configured as either
a MenuBar or a PulldownMenu pane. Those familiar with Xt may find this widget design to be a breach of Xt's design
goals, though.
In order to allow the programmer to think of ScrolledText objects, MenuBars, and PulldownMenus as distinct objects,
the Motif toolkit provides convenience creation functions. These routines make it appear as though you are creating
discrete objects when, in fact, you are not. For example, XmCreateMenuBar() and
XmCreateSimplePulldownMenu() automatically create and configure a RowColumn widget as a MenuBar and
a PulldownMenu, respectively. There are also convenience routines for creating various types of predefined dialog
boxes, which are actually composed of widgets from four or five separate widget classes.
Convenience routines emphasize the functional side of user−interface objects while hiding their implementation.
However, since Motif is a truly object−oriented system, it behooves you to understand what you're really dealing with.
For example, if you want to use resource classes to configure all MenuBars to be one color and all PulldownMenus
another, you cannot do so because they are not actually distinct widget classes. The class name for both objects is
XmRowColumn.
In the remainder of this chapter, we look at Motif user−interface objects from the perspective of both the functional
object illusion and the actual widget implementation. In the body of the book, we use the Motif convenience routines
for creating most compound objects, but stick to the underlying Xt routines for creating simple widgets or gadgets.
With the compound objects, we show you how to pierce the veil of Motif's convenience functions and work directly
with the underlying widgets when necessary. the figure shows the entire class hierarchy of the Motif widget set.
4 Overview of the Motif Toolkit 4 Overview of the Motif Toolkit
44

Get Volume 6A: Motif Programming Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.