Unable to get background to work using renditions

Adding new posting since noone has responded to the "Rendition Background color" posting.

We have been attempting to get the multiple background colors in a string to work using renditions. We initally had problems with fonts also but discovered that any app-default or Xdefault resourse that set the Fonts attribute would prevent the fonts from working. See notes included app-default code for examples.

Similarly we found a posting in another website that indicated that the setting of the widget's background color will prevent the XmNrenditionBackground from working. But we have found no way to have an undefined background. We have done everything that we can think of to force the backgound to XmUNSPECIFIED_PIXEL. Setting background to XmUNSPECIFIED_PIXEL in the code causes an error.

Does anyone have and example that works?

We basicly used the example code from the "Rendition Background color" posting. We modified it to use a rendition table that we setup in an app-default file.

Here is the app-default file that we used.

<br />
!! This file is provided as is, and may be used and<br />
!! distributed freely without liability.</p>
<p>!! App-Defaults for ColoredList application</p>
<p>! If either is set it messes up the XmRenderTable redefinition for the fonts<br />
!*Font:                                10x20<br />
!ColoredList*Font:    -adobe-helvetica-bold-r-normal-*-12-*</p>
<p>! The following will affect the background color of the list widget<br />
!*backgound : moccasin<br />
!ColoredList*list.background: brown</p>
<p>ColoredList*list.renderTable: bold, oblique<br />
ColoredList*list.renderTable.bold.renditionForeground: blue<br />
ColoredList*list.renderTable.bold.fontName: *-*-*-bold-*-iso8859-1<br />
ColoredList*list.renderTable.bold.fontType: FONT_IS_FONT<br />
ColoredList*list.renderTable.oblique.renditionForeground: Purple</p>
<p>!! THIS DOESN't WORK !!!<br />
!! Whether the *background is set or not, this doesn't work.<br />
!! renditionForeground setting works fine. The renditionBackground appears<br />
!! to be getting it's default background color from somewhere else and we<br />
!! cannot override it.<br />
ColoredList*list.renderTable.oblique.renditionBackground: Pink</p>
<p>ColoredList*list.renderTable.oblique.fontName: lucidasans-bolditalic-24<br />
ColoredList*list.renderTable.oblique.fontType: FONT_IS_FONT<br />
ColoredList*list.renderTable.oblique.underlineType: AS_IS<br />
ColoredList*list.renderTable.fontName: fixed<br />
ColoredList*list.renderTable.fontType: FONT_IS_FONT<br />
ColoredList*list.renderTable.renditionForegound: black<br />
ColoredList*list.renderTable*tabList: 1in, +1.5in, +3in<br />
ColoredList*list.renderTable*renditionBackground: Pink<br />

Here is the file that we took from the "Rendition Background color" posting and we modifed to use the app-default file:

<br />
/* compiled with OpenMotif 2.2.3-r8 with command<br />
*<br />
* gcc colored_list.c -o colored_list -I/usr/X11R6/include -L/usr/X11R6/lib -lXm -lXt -lX11 -lXp -lXext -lSM -lICE<br />
*<br />
* I`ve modified the original slightly to just show implication of color and to use the<br />
*  rendition table from the app-default file<br />
*/<br />
/*<br />
** This file is provided as is, and may be used and<br />
** distributed freely without liability.<br />
*/<br />
#ifndef lint<br />
static char *sccsid[] = {"%Z%%Q%%M% %I%"} ; /* %E% */<br />
#endif /* lint */</p>
<p>/* colored_list.c: illustrates the basic features of<br />
** render tables and renditions by creating a<br />
** multi-font, multi-color List widget.<br />
*/</p>
<p>#include <Xm/Xm.h><br />
#include <Xm/List.h><br />
#include <Xm/RowColumn.h></p>
<p>/* ConvertStringToPixel()<br />
** A utility function to convert a color name to a Pixel<br />
*/<br />
Pixel ConvertStringToPixel (Widget widget, char *name)<br />
{<br />
XrmValue from_value, to_value; /* For resource conversion */<br />
from_value.addr = name;<br />
from_value.size = strlen(name) + 1;<br />
to_value.addr = NULL;<br />
XtConvertAndStore (widget, XmRString, &from_value, XmRPixel, &to_value);<br />
if (to_value.addr) {<br />
return (*((Pixel*) to_value.addr));<br />
}<br />
return XmUNSPECIFIED_PIXEL;<br />
}</p>
<p>/*<br />
** A convenient structure to hold the data<br />
** for creating various renditions<br />
*/<br />
typedef struct RenditionData_s<br />
{<br />
char *color;<br />
char *font;<br />
} RenditionData_t;</p>
<p>#define MAX_LINES 4</p>
<p>RenditionData_t rendition_data[MAX_LINES] =<br />
{<br />
{ "red", "fixed" },<br />
{ "green", "fixed" },<br />
{ "blue", "fixed" },<br />
{ "orange", "fixed" }<br />
};</p>
<p>char* appDefRenditions[MAX_LINES] =<br />
{"bold",<br />
 "oblique",<br />
 "bold",<br />
"oblique"<br />
};<br />
/*<br />
** Arbitrary data to display in the List.<br />
** Each line will appear in a different font/color.<br />
*/<br />
static char *poem[] =<br />
{<br />
"Mary had a little lamb",<br />
"Its fleece was white as snow",<br />
"And everywhere that Mary went",<br />
"The lamb was sure to follow",<br />
(char *) 0<br />
};</p>
<p>/*<br />
** CreateListData(): routine to convert the<br />
** poem into an array of compound strings<br />
*/<br />
XmStringTable CreateListData (int *count)<br />
{<br />
XmStringTable table = (XmStringTable) 0;<br />
int line = 0;</p>
<p>table = (XmStringTable) XtMalloc ((unsigned) MAX_LINES * sizeof (XmString)) ;</p>
<p>while (poem[line] != (char *) 0) {<br />
/* create a compound string, using the rendition tag */<br />
table[line] = XmStringGenerate ((XtPointer) poem[line],<br />
NULL,<br />
XmCHARSET_TEXT,<br />
appDefRenditions[line]);<br />
/*rendition_data[line].color);*/</p>
<p>line++;<br />
}</p>
<p>*count = line;</p>
<p>return table;<br />
}</p>
<p>main (int argc, char *argv[])<br />
{<br />
Widget toplevel, rowcol, list;<br />
XtAppContext app;<br />
Arg args[10];<br />
XmRendition renditions[MAX_LINES];<br />
XmRenderTable rendertable;<br />
XmStringTable xmstring_table;<br />
int xmstring_count;<br />
Pixel pixels[MAX_LINES];<br />
int n, i;</p>
<p>XtSetLanguageProc (NULL, NULL, NULL);<br />
toplevel = XtVaOpenApplication (&app, "ColoredList", NULL, 0, &argc, argv, NULL,<br />
sessionShellWidgetClass, NULL);</p>
<p>rowcol = XmCreateRowColumn (toplevel, "rowcol", NULL, 0);</p>
<p>/* Create some colors */<br />
for (i = 0; i < MAX_LINES; i++) {<br />
pixels[i] = ConvertStringToPixel (toplevel, rendition_data[i].color);<br />
if (pixels[i] == XmUNSPECIFIED_PIXEL)<br />
   printf("ERROR in converting color %s\n", rendition_data[i].color);<br />
}</p>
<p>/* Create some Renditions: one per line */<br />
for (i = 0 ; i < MAX_LINES ; i++) {<br />
n = 0;<br />
XtSetArg (args[n], XmNrenditionForeground, pixels[i]); n++;<br />
XtSetArg (args[n], XmNrenditionBackground, pixels[i]); n++;<br />
XtSetArg (args[n], XmNfontName, rendition_data[i].font); n++;<br />
XtSetArg (args[n], XmNfontType, XmFONT_IS_FONT); n++;<br />
renditions[i] = XmRenditionCreate (toplevel, rendition_data[i].color, args, n);<br />
}</p>
<p>/* Create the Render Table */<br />
rendertable = XmRenderTableAddRenditions<br />
      (NULL, renditions, XtNumber (renditions), XmMERGE_OLD);</p>
<p>/* Create the data for the list */<br />
xmstring_table = CreateListData (&xmstring_count);</p>
<p>/* Create the List, using the render table */<br />
n = 0;<br />
/*XtSetArg (args[n], XmNrenderTable, rendertable); n++;*/<br />
XtSetArg (args[n], XmNitems, xmstring_table); n++;<br />
XtSetArg (args[n], XmNitemCount, xmstring_count); n++;<br />
XtSetArg (args[n], XmNwidth, 400); n++;<br />
XtSetArg (args[n], XmNvisibleItemCount, xmstring_count + 1); n++;<br />
list = XmCreateList (rowcol, "list", args, n);<br />
XtManageChild (list);</p>
<p>/* Free the memory now the widget has copied the data */<br />
/* First, the compound strings */<br />
for (i = 0; i < xmstring_count; i++)<br />
XmStringFree (xmstring_table[i]);<br />
XtFree ((char *) xmstring_table);<br />
#if 0<br />
/* Secondly, the XmRendition objects */<br />
for (i = 0; i < XtNumber (renditions); i++)<br />
XmRenditionFree (renditions[i]);</p>
<p>/* Lastly, the XmRenderTable object */<br />
XmRenderTableFree (rendertable);<br />
#endif<br />
XtManageChild (rowcol);<br />
XtRealizeWidget (toplevel);<br />
XtAppMainLoop (app);<br />
} 

This document was prepared as a service to the NSWC/DD community. Neither the United States Government nor any of their employees, makes any warranty, expressed or implied, or assumes any legal liability or responsibility for the accuracy, completeness, or usefulness of any information, product, or process disclosed, or represents that its use would not infringe privately owned rights.

Reference herein to any specific commercial products, process, or service by trade name, trademark manufacturer, or otherwise, does not necessarily constitute or imply its endorsement, recommendation, or favoring by the United States Government. The opinions of the authors expressed herein do not necessarily state or reflect those of the United States Government, and shall not be used for advertising or product endorsement purposes.