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



Resources: User and Program Customization

A widget, a class of widgets, and an application as a whole have a set of attributes that the program can examine and that the user and program may be able to specify. These attributes are implemented as X resources. Xlib has a facility called the X resource manager (Xrm) whose purpose is to establish and query databases of resources. Xt and Motif build on Xrm to make resources the repository of publicly available attributes of widgets as well as applications.

Xt maintains databases of resources that apply to several levels:

  1. To the application as a whole

  2. To the display on which an application is running

  3. To the screen on which a widget hierarchy is created

  4. To a class of widgets

  5. To an individual widget

    The user can specify resources at any of these levels through resource files or the command line used to start the program. The application can also specify resources through resource files.

    Each application has a name and a class; each widget within an application has a name and a class; and each resource has a name and a class. When supplying resource values in a file or on the command line, the user or the application specifies the scope of the resource value by qualifying the resource according to its name or class. For example, a user might specify that all resources of the class Background should have a particular value for all widgets; or the user might specify that only the resource named background within a particular hierarchy of named widgets should have a particular value. The qualification mechanism allows resource values to be specified at any level.

    Most widget classes define a set of resources, by name and class, that apply to those classes. Subclasses inherit superclass resources, unless a subclass overrides the superclass resource specification. A widget class also defines a default value for each of its resources, used in case the user and the application do not provide another value.

    When an application starts up, Xt constructs an initial database of resource values. This database is derived from a combination of user and application resource files and the command line. Some resources in the database may have different values depending on the display or the screen on which the application is running. When an application creates a widget, Xt uses this initial database in combination with the widget class resource defaults to supply values for the widget's resources. The application can override these values by supplying arguments to the routine that creates the widget. It can set a resource value after creating the widget by using the Xt function XtSetValues.

    Setting resources is the primary means by which an application changes the attributes of a widget. However, an application should be careful not to override the user's specification of many resources governing characteristics such as visual appearance and the policy for determining which widget has keyboard focus. In general, the application should set only those resources necessary for the proper functioning of the program. An application can specify preferences for other resource values in an application defaults file. Xt reads this file when an application starts up, but a user can override the values supplied there.

    The process by which Xt creates the initial resource database is discussed in more detail in Chapter 3.


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