This document is a programming textbook titled "MOTIF PROGRAMMING: The Essentials ... and More" by Marshall Brain, published by Digital Press in 1992. It serves as a practical, example-driven introduction to developing graphical user interfaces (GUIs) using the Motif toolkit on X workstations, primarily for C programmers.
Core Philosophy and Approach:
The book aims to demystify Motif programming by emphasizing its underlying simplicity despite the perceived complexity of the X Window System. It focuses on showing readers how to design and build graphical applications efficiently, starting with basic concepts and gradually introducing more advanced topics. The author encourages learning by doing, recommending that readers actively type, compile, and experiment with the provided code examples.
Key Topics Covered:
- Introduction to Motif and X: Begins with simple "Hello World" programs to introduce fundamental Motif concepts, the event-driven programming paradigm, and the layered architecture of Motif, X Toolkit (Xt), X Window System (X), and UNIX.
- Widgets and Resources: Explores Motif's user interface objects (widgets) like labels, push buttons, scales, text widgets, and various manager widgets (Bulletin Board, Form, RowColumn). A central theme is the concept of "resources," which are variables used to control a widget's appearance and behavior, along with methods for setting and retrieving these resources (e.g.,
XtSetArg, XtSetValues, XtGetValues). It also covers resource inheritance and external resource files.
- Callbacks: Explains how widgets communicate user interactions back to the application through "callback functions," detailing the
client_data and call_data parameters and their utility in differentiating events and passing information. It also warns about potential UI stalls from long-running callback functions and introduces XtAppWorkProc and XtAppTimeOut for background processing.
- GUI Components: Provides comprehensive coverage of common GUI elements:
- Menus: How to create menu bars, pull-down menus, cascade buttons, and customize them with labels, separators, accelerators, and mnemonics. It also discusses hierarchical menus and the Motif Style Guide for menu design.
- Dialog Boxes: Introduces various "canned" dialog box types (Message, Prompt, Selection, File Selection, Error, Warning, Information, Question, Working) and demonstrates how to create customized dialogs by assembling widgets within a Bulletin Board or Form dialog.
- Text Widget: Explores the powerful text widget, showing how to implement text editing functionalities, including string manipulation, cursor positioning, and clipboard operations (cut, copy, paste).
- Application Development Examples: Demonstrates the integration of multiple Motif features into complete applications:
- A Celsius-to-Fahrenheit conversion program to illustrate manager widgets and resource handling.
- A Tic-Tac-Toe game to showcase interactions between various widgets, menus, and dialogs, and to explain "callback chains."
- "mkill," a wrapper application that graphically manages UNIX processes, illustrating inter-process communication using custom C libraries (
fork, exec, pipes).
- A simple text editor, built upon the text widget and menus, showing file loading/saving and various text manipulation features.
- Underlying Layers (X and Xt): Delves into the capabilities of the lower X and Xt layers:
- X Window System: Explains basic windowing, the server/client model, X resources (windows, pixmaps, fonts, colormaps, cursors, graphics contexts), and event handling (
XNextEvent, event masks). It also covers direct X drawing commands (points, lines, rectangles, arcs, strings, bitmaps, pixmaps), advanced drawing concepts (exposure handling, resizing, rubber-banding, clip masks), and output buffering (XFlush).
- X Toolkit (Xt): Discusses Xt's role in supporting widget sets, its memory management functions, and how to handle events, timeouts, and background tasks.
Appendices: The book includes several valuable appendices:
- Sources of Information: Provides FTP locations for example code and a list of recommended reference books.
- Debugging Hints: Offers solutions to common Motif and C programming problems, including segmentation faults, widget display issues, and resource setting errors.
- Motif Style Guide: Summarizes key principles for consistent and intuitive GUI design within the Motif environment.
- PostScript Printing: A detailed tutorial on generating PostScript output for graphics, covering its terminology, coordinate system, syntax, drawing operators, and procedures.
- C Review: A comprehensive refresher for C programming, including pointers, arrays, strings, functions, libraries, makefiles, and file I/O, often comparing concepts to Pascal.
- Reference Guides: Extensive summaries of Motif widgets, Xt functions, and X functions, including their resources, callbacks, and parameters.
In essence, "Motif Programming: The Essentials ... and More" is a hands-on guide that empowers programmers to build robust graphical applications by thoroughly explaining Motif's object-oriented nature, resource management, callback mechanisms, and integration with the lower-level X and Xt libraries.