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



Application-Defined Color Generation

Motif generates default colors whenever the application creates a widget that has no specified value for one or more of the color resources. Motif does not regenerate default colors when an application changes the value of XmNbackground using XtSetValues.

An application can use XmChangeColor to recalculate default colors for a widget based on a new background and set the appropriate color resources in the widget. For primitives and managers, XmChangeColor sets XmNbackground, XmNforeground, XmNtopShadowColor, and XmNbottomShadowColor. For widgets and gadgets with select colors, XmChangeColor also sets the appropriate resources for those colors.

An application can use XmGetColors to produce default colors for a given background color without setting any resources. XmGetColors takes as arguments a screen pointer, a colormap, and a background pixel representing a color allocated in the colormap. XmGetColors also has return arguments that are pointers to pixel values for the foreground, top shadow, bottom shadow, and select colors. The function generates default colors for the given background. For each of the return arguments that is not NULL, XmGetColors allocates a color in the colormap and returns the pixel value at the address specified by the argument.

By default, XmChangeColor and XmGetColors calculate colors as described in the previous discussion of default colors. An application can use XmSetColorCalculation to change the procedure that these routines use and that Motif uses to calculate default colors when the application creates a widget. XmSetColorCalculation takes as its only argument a procedure of type XmColorProc. It sets Motif's color-calculation procedure to the new XmColorProc and returns the color-calculation procedure used previously. XmSetColorCalculation does not change the procedure used by XmChangeColor, XmGetColors, and Motif to calculate default colors for a monochrome screen.

Motif calls the XmColorProc when it needs to compute default colors or when the application calls XmChangeColor or XmGetColors. The XmColorProc takes five arguments, all pointers to XColor structures. The red, green, blue, and pixel members of the first structure are filled in with the background color. The procedure calculates red, green, and blue values for the foreground, select, top shadow, and bottom shadow colors and fills in the other four XColor structures with these values.

The procedure should not allocate color cells for any of these colors. Motif caches the returned XColor structures and allocates a color when it needs a pixel value. Usually Motif allocates a color when it computes the default value for a resource, when the application calls XmChangeColor, or when the application calls XmGetColors with a non-NULL value for one of the return pixel values. When allocating colors as a result of widget creation or a call to XmChangeColor, Motif uses the colormap of the widget. When allocating colors as a result of a call to XmGetColors, Motif uses the colormap passed as an argument to the function.

XmGetColorCalculation returns the color-calculation procedure being used at the time of the call to that routine. Calling XmSetColorCalculation with an argument of NULL restores the Motif default color-calculation procedure.


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