The OSF /Motif widget set is based on the Xt Intrinsics, a set of functions and procedures that provide quick and easy access to the lower levels of the X Window system.
Fig. 8.1 : User Interface Development Model
You can see from the above that the Motif Widget system is layered on top of the Xt Intrinsics, which in turn are layered on top of the X Window System, thus extending the basic abstractions provided by X. The Motif Widget system supports independent development of new or extended widgets. The Motif Widget system consists of a number of different widgets, each of which can be used independently or in combination to aid in creating complex applications. Applications can be written faster and with less lines of code using the Motif Widgets; however, they will require more memory than similar applications written without using these widgets.
Every widget is dynamically allocated and contains state information. Every widget belongs to one class, and each class has a structure that is statically allocated and initialized and contains operations for that class. Figure 8.2 shows the basic widget classes.
The basic class is the Core class. It contains resources that are inherited by all other classes. Two classes are layered beneath the Core class, the Composite class and the Primitive class. The Primitive class has no other classes beneath it, but the Composite class has two - the Constraint class and the Shell class. Each lower class can inherit some or all of the resources belonging to a higher class. For example, a Manager class widget can inherit some or all of the resources belonging to the Constraint class, the Composite class, and the Core class. You can find exactly what resources a given widget has by examining its man page in the OSF /Motif P rogrammer's Reference Manual.
Fig. 8.2 : Basic Widget Class Hierarchy
This section has a number of hierarchy diagrams to help you understand how the widgets relate to each other. The figure shows the highest level of widget classes. You can see that the Core class is composed of Object, RectObj, and WindowObj. Core is the base class for all other widget classes. Figure 8.3 shows the subclasses of the Primitive class. Figure 8.4 shows the Subclasses of the Shell class.
Fig. 8.3 : Primitive Class Widgets
Fig. 8.4 : Shell Widgets
Figure 8.5 shows the Manager class widgets. Note from the
Basic Widget Class Hierarchy figure that Manager is a subclass of
Composite and Constraint. Figure 8.6 shows the Dialog widgets
that are a subclass of Manager. Note that all of the Dialog
widgets are subclasses of BulletinBoard. Also, note the
convenience functions that are present. Figure 8.7 shows the
Gadgets that are an integral part of the Motif toolkit.
Motif has a variety of widgets and gadgets, each designed to accomplish a specific set of tasks, either individually or in combination with others. There are convenience functions that create certain widgets or sets of widgets for a specific purpose.
Fig. 8.5 : Manager Widgets
Fig. 8.6 : Dialog Widgets
Fig. 8.7 : Gadgets
Widgets are used either individually or in combination to make the creation of complex applications easier and faster. Some widgets display information, others are merely containers for other widgets. Some widgets are restricted to displaying information and do not react to keyboard or mouse input. Others change their display in response to input and can invoke functions when instructed to do so. You can customize some aspects of a widget, such as fonts, foreground and background colors, border widths and colors, and sizes.
An instance of a widget class is composed of a data structure containing values and procedures for that particular widget instance. There is also a class structure that contains values and procedures applicable to all widgets of that class. Widgets are grouped into several classes, depending on the function of the widget. Logically, a widget class consists of the procedures and data associated with all widgets belonging to that class. These procedures and data can be inherited by subclasses. Physically, a widget class is a pointer to a structure. The contents of this structure are constant for all widgets of the widget class. A widget instance is allocated and initialized by XmCreate <widget name>, XmCreate Widget, or XmCreateManagedWidget. See chapter 3, "Using Motif Widgets in Programs," for specific examples of creating widgets. The man pages in the OSF /Motif P rogrammer's Reference Manual contain detailed information for each of the widgets. Figure 8.8 shows how widgets might be combined in an application.
Fig. 8.8 : Complex application using Motif widgets
Step Description Related Functions 1 Include required header files. #include <X11/Intrinsic.h> #include <Xm/Xm.h> #include <Xm/ widget .h> 2 Initialize Xt Intrinsics. XtInitialize(...) 3 Add additional top-level windows. XtAppCreateShell(...) Do steps 4 through 6 for each widget. 4 Set up argument lists for widget. XtSetArg(...) 5 Add callback routines. XtAddCallback(...) 6 Create widget. XtCreateManagedWidget(...) followed by XtManageChild(widget) 7 Realize widgets and loop. XtRealizeWidget(toplevel) XtMainLoop() 8 Link relevant libraries. cc -o application \ \ application.c -lXm -lXt -lX11 -lPW 9 Create defaults files. /usr/lib/X11/app-defaults/class $HOME/.Xdefaults
![]()
The best way to understand how to use any programming library is by trying some simple examples. A collection of example programs that introduces some of the widgets in the Motif widget set can be found in the directory
/usr/units/Xm
A simple example is shown here.
