1.1. Motif Widget Library -Xm   

The OSF/Motif widget1 set is (See footnote) 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.


 
User Interface Development Model
Fig. 1.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.


 
Basic Widget Class Hierarchy
Fig. 1.2 : Basic Widget Class Hierarchy
Figure 1.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. 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.


 
Primitive Class Widgets
Fig. 1.3 : Primitive Class Widgets
Figure 1.3 shows the subclasses of the Primitive class.

 
Shell Widgets
Fig. 1.4 : Shell Widgets
Figure 1.4 shows the Subclasses of the Shell class.


     
Manager Widgets
Fig. 1.5 : Manager Widgets
Figure 1.5 shows the Manager class widgets. Note from the Basic Widget Class Hierarchy figure that Manager is a subclass of Composite and Constraint.

 
Dialog Widgets
Fig. 1.6 : Dialog Widgets
Figure 1.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.

 
Gadgets
Fig. 1.7 : Gadgets
Figure 1.7 shows the Gadgets that are an integral part of the Motif toolkit.

1.1.1. Widgets, Gadgets, and Convenience Functions   

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.

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.


 
Complex application using Motif widgets
Fig. 1.8 : Complex application using Motif widgets
Figure 1.8 shows how widgets might be combined in an application.




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
BUT USE AN IMAKEFILE
9 Create defaults files. /usr/lib/X11/app-defaults/class
$HOME/.Xdefaults