3 The Motif Programming Model
This chapter teaches the fundamentals of Motif by example. It dissects a simple "Hello, World" program, showing the
program structure and style common to all Motif programs. Because much of this material is already covered in detail
in Volume Four, X Toolkit Intrinsics Programming Manual, Motif Edition, this chapter can be used as a refresher or a
light introduction for those who haven't read the earlier book. It makes reference to Volume One, Xlib Programming
Manual, and Volume Four to point out areas that the programmer needs to understand (windows, widgets, events,
callbacks, resources, translations) before progressing with Motif.
Though we expect most readers of this book to be familiar with the X Toolkit Intrinsics (Xt), this chapter briefly
reviews the foundations of Motif in Xt. This review serves a variety of purposes. First, for completeness, we define
our terms, so if you are unfamiliar with Xt, you will not be completely at sea if you forge ahead. Second, there are
many important aspects of the X Toolkit Intrinsics that we aren't going to cover in this book; this review gives us a
chance to direct you to other sources of information about these areas. Third, Motif diverges from Xt in some
important ways, and we point out these differences up front. Finally, we point out some of the particular choices you
can make when Xt or Motif provides more than one way to accomplish the same task.
If you are unfamiliar with any of the concepts introduced in this chapter, please read the first few chapters of
Volume Four, X Toolkit Intrinsics Programming Manual. Portions of Volume One, Xlib Programming Manual, and
Volume Three, X Window System User's Guide, Motif Edition, may also be appropriate.
3.1 Basic X Toolkit Terminology and Concepts
As discussed in Chapter 1, Introduction to Motif, the Motif user−interface specification is completely independent of
how it is implemented. In other words, you do not have to use the X Window System to implement a Motif−style
graphical user interface (GUI). However, to enhance portability and robustness, the Open Software Foundation (OSF)
chose to implement the Motif GUI using X as the window system and the X Toolkit Intrinsics as the platform for the
Application Programmer's Interface (API).
Xt provides an object−oriented framework for creating reusable, configurable user−interface components called
widgets. Motif provides widgets for such common user−interface elements as labels, buttons, menus, dialog boxes,
scrollbars, and text−entry or display areas. In addition, there are widgets called managers, whose only job is to control
the layout of other widgets, so the application doesn't have to worry about details of widget placement when the
application is moved or resized.
A widget operates independently of the application, except through prearranged interactions. For example, a button
widget knows how to draw itself, how to highlight itself when it is clicked on with the mouse, and how to respond to
that mouse click.
The general behavior of a widget, such as a PushButton, is defined as part of the Motif library. Xt defines certain base
classes of widgets, whose behavior can be inherited and augmented or modified by other widget classes (subclasses).
The base widget classes provide a common foundation for all Xt−based widget sets. A widget set, such as Motif's Xm
library, defines a complete set of widget classes, sufficient for most user−interface needs. Xt also supports
mechanisms for creating new widgets or for modifying existing ones.
Xt also supports lighter−weight objects called gadgets, which for the most part look and act just like widgets, but their
behavior is actually provided by the manager widget that contains them. For example, a pulldown menu pane can be
made up of button gadgets rather than button widgets, with the menu pane doing much of the work that would