[ Previous | Next | Contents | Glossary | Home | Search ]
Motif 2.1 Programmer's Guide



Chapter 2. The Motif Programming Model

Motif accommodates a variety of application programming styles. An application can accomplish most tasks, such as handling a particular kind of user input or displaying a particular kind of output, in more than one way. While this flexibility is one of the strengths of Motif, the toolkit has been designed with a set of programming principles in mind. This chapter explains at a general level the intended uses of Motif widgets and other features of the toolkit. The next chapter outlines the structure of common Motif programs, and succeeding chapters explain toolkit features in more detail.

The following general principles make sense in writing any Motif program:

  1. Adopt a user-centered perspective. In most Motif programs, the application does its work in response to commands or other input from the user. An important part of interface design is deciding precisely which commands, options, and other information the user can give the application. The interface then consists largely of procedures that execute the user's commands or otherwise respond to the user's input.

  2. Separate the design of the core application and the user interface. The core application should not depend on a particular user interface. Often it's a good idea to specify a set of generic routines and data structures for obtaining input and displaying output. The developer can then implement these routines in different ways to provide different user interfaces for the application.

  3. Follow the Motif Style Guide in designing the user interface. Although an application can use Motif widgets in many configurations, users find some more common, intuitive, and comfortable than others. The Motif Style Guide contains requirements and recommendations for compliant applications, and it offers more advice on application design.

  4. Outline the widget hierarchy. Once you have settled on one or more combinations of widgets, you may find the implementation more tractable if you sketch a genealogy of all the widgets the program uses. Constructing a widget tree can reveal gaps and awkwardness in the design. Attaching dialogs and menus to the hierarchy may help ensure consistency and completeness in the presentation and solicitation of information.

  5. Use high-level interfaces when possible. A Motif application must use some X Toolkit Intrinsics (Xt) interfaces, and it may call other public Xt and Xlib routines. For some tasks, such as drawing graphics, an application must call lower-level routines. However, Motif provides interfaces such as resources, callback lists, and convenience routines to handle many common tasks. Motif also includes both simple and composite widgets that do most of the work related to their specific functions, such as text editing or constraint-based geometry management. Using a high-level Motif interface instead of a comparable series of lower-level calls can make code simpler and more maintainable.

  6. Use resource files and the User Interface Language (UIL) to specify characteristics of the interface. Avoid locking the user-interface specification and data into the application code. Using resources gives the user the power to override application-supplied default behavior. UIL provides the opportunity to separate the widget hierarchy from the application. With both resources and UIL, the developer can change the interface without recompiling the application code. These mechanisms also provide the means to tailor the interface and data for particular language environments.

  7. [ Previous | Next | Contents | Glossary | Home | Search ]