Resource Handling

Since release 1.9, the library provides support for resource handling in ascii text configuration file with standard .ini format under Windows and DOS, with standard .Xdefaults format under X11. A system configuration file, in the /mgui/sys directory, defines general resources as the resolution sensitive static fonts or the default background and foreground colors. The name of this file is system dependent: MGui under X11, mgui.ini under Windows and DOS. Under X11 colors are specified in the standard X format (eg: <yellow> or <#ffff00>). Three decimal values, separated by commas, are used instead in all other environments (eg: <255,255,0> for yellow).
Static fonts in the system configuration file are specified in the standard X format under X11 while under DOS and Windows the fonts are defined in the format <family,height,bold> (eg: <arial,20,1> for arial 20 points bold). Under DOS only the font file name (.mfn) can be used directly to define a static font.

Another resource file is used to determine the resources of a MGUI program. This file is located in same directory where the executable resides (in the user's home directory under Unix) and has the same name of the program, with the appropriate extension (.progname under Unix).

The application's resource database is constructed at program startup by merging all option definitions in the MGUI resource file and then those in the application's resource file. By defining in the application's resource file a resource already defined in the MGUI resource file, you overwrite its previous value.

A resource is identified by the combination of an object name and a resource (option) name. Valid resources for GUI object are the following attributes: background/foreground colors, font, text and shadow. The Object font resource must be expressed as a static font name (eg: TIMES_LARGE or FIXED_MEDIUM).

All resources are loaded at program startup, Object resources are enabled via the function call MObjectEnableOptions(), after the Object creation. For example, the code:

label = MCreateLabel(mainshell,
    "Ctrl+Shift+MouseClick here to customize",
    FIXED_MEDIUM);

MObjectEnableOptions(label, "label_1", MO_ALL);

will cause the Object label to be customized with all available resources for the object named label_1. Object resources, enabled via MObjectEnableOptions(), can be saved in the application's resource file at any time by using the call MObjectSaveOptions().

MGUI provides a run-time advanced feature that lets the user change, and optionally store in the application file, the resources enabled for a given Object. This can be done via a dialog window open by clicking the mouse button in an enabled Object while holding down the <Ctrl+Shift> keys.

The library API also lets the programmer load/save general application resources, by specifying arbitrary object and resource names.

Back