color scheme

This forum is read only. No new submissions are accepted.

Questions about motif? Contact us

6 posts / 0 new
Last post
color scheme

Hi,
I have a scrolled list wherein I require to display some of the entries in color(say RED).
Would appreciate help in this regard.
Cheers
‹ Problem with UxPopUpInterface How can I get a Xt resource manual or source codes? ›

Yuriy Syrota

 

Here is a chapter from Motif Programming Manual about Render Tables.

http://docs.mandragor.org/files/Operating_systems/Linux/Motif_Programmin...

The chapter contains an example that creates a multi-column, multi-color, multi-font List widget.

 

tinnie

 

Hi,
I tried a lot of things but it did not work.
Basically what I m trying to do:

for(i=0;i<2;i++)
pixels[i] = ConvertStringToPixel (UxGetWidget(scrolledList2), rendition_data[i].color);

for (i = 0 ; i < 2 ; i++) {
n = 0;
XtSetArg (arg[n], XmNrenditionForeground, pixels[i]); n++;
XtSetArg (arg[n], XmNfontName, rendition_data[i].font); n++;
XtSetArg (arg[n], XmNfontType, XmFONT_IS_FONT); n++;
renditions[i] = XmRenditionCreate (UxGetWidget(scrolledList2), rendition_data[i].color, arg, n);
}
rendertable = XmRenderTableAddRenditions (NULL, renditions, XtNumber (renditions), XmMERGE_NEW);\

if(sl->session.status==FAILED)
temp=XmStringGenerate ((XtPointer)buf,NULL,XmCHARSET_TEXT,rendition_data[0].color);
else
temp=XmStringGenerate ((XtPointer)buf,NULL,XmCHARSET_TEXT,rendition_data[1].color);

XtSetArg (arg[0], XmNfontList, (XmFontList) 0);
XtSetArg (arg[1], XmNrenderTable, rendertable);
XtSetArg(arg[2], XmNitems, temp);
XtSetArg(arg[3], XmNitemCount, 1);

XtSetValues(UxGetWidget(scrolledList2), arg, 4);

This is a recusive function call.I get the data one by one and I try to render it according to condition. Rest of the stuff can be assumed.
However this does not work and coredumps.Kindly help.
Thankx in advance.

 

 

Hi,

I am able to render my scrolledist accordingly however the selection part is not working properly. If I select some row in the list the selection color which is black generally changes to some color.When I quit my application and launch it again, a different color for row selection results. I want to keep the selection color as black only.
Kindly help.

Yuriy Syrota

 

It seems you assing some uninitialized data somewhere, could you show your code?

The following example draws colored text in XmList and has black color of selection cursor.

<br />
/* rendered_list.c: illustrates all the features of<br />
** render tables and renditions by creating a<br />
** multi-column, multi-font, multi-color List widget.<br />
*/</p>
<p>#include <Xm/Xm.h><br />
#include <Xm/RowColumn.h><br />
#include <Xm/List.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 */</p>
<p> from_value.addr = name;<br />
from_value.size = strlen(name) + 1;<br />
to_value.addr = NULL;<br />
XtConvertAndStore (widget,<br />
XmRString, &from_value,<br />
XmRPixel, &to_value);</p>
<p> if (to_value.addr) {<br />
return (*((Pixel*) to_value.addr));<br />
}</p>
<p> 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 *tag;<br />
char *color;<br />
char *font;<br />
} RenditionData_t;</p>
<p>#define MAX_COLUMNS 4</p>
<p>RenditionData_t rendition_data[MAX_COLUMNS] =<br />
{<br />
{ "one", "red", "fixed" },<br />
{ "two", "green",<br />
"-adobe-helvetica-bold-r-normal--10-100-75-75-*-*-iso8859-1" },<br />
{ "three", "blue", "bembo-bold" },<br />
{ "four", "orange",<br />
"-adobe-*-medium-i-normal--24-240-75-75-*-*-iso8859-1" }<br />
};</p>
<p>/*<br />
** Arbitrary data to display in the List<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;<br />
int column = 0;<br />
int index = 0;<br />
XmString entry = (XmString) 0;<br />
XmString row = (XmString) 0;<br />
XmString tmp = (XmString) 0;<br />
XmString tab;</p>
<p> tab = XmStringComponentCreate (XmSTRING_COMPONENT_TAB, NULL, 0);</p>
<p> while (poem

!= (char *) 0) {<br /> /* create a compound string, using the rendition tag */<br /> entry = XmStringGenerate ((XtPointer) poem,<br /> NULL,<br /> XmCHARSET_TEXT,<br /> rendition_data[column].tag);</p> <p> if (row != (XmString) 0) {<br /> tmp = XmStringConcat (row, tab);<br /> XmStringFree (row);<br /> row = XmStringConcatAndFree (tmp, entry);<br /> }<br /> else {<br /> row = entry;<br /> }</p> <p> ++column;</p> <p> if (column == MAX_COLUMNS) {<br /> if (table == (XmStringTable) 0) {<br /> table = (XmStringTable) XtMalloc ((unsigned)<br /> sizeof (XmString));<br /> }<br /> else {<br /> table = (XmStringTable) XtRealloc ((char *) table,<br /> (unsigned) (line + 1) * sizeof (XmString));<br /> }</p> <p> table[line++] = row;<br /> row = (XmString) 0;<br /> column = 0;<br /> }</p> <p> index++;<br /> }</p> <p> XmStringFree (tab);</p> <p> table[line] = (XmString) 0;</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 /> XmTab tabs[MAX_COLUMNS];<br /> XmTabList tablist;<br /> XmRendition renditions[MAX_COLUMNS];<br /> XmRenderTable rendertable;<br /> XmStringTable xmstring_table;<br /> int xmstring_count;<br /> Pixel pixels[MAX_COLUMNS];<br /> int n, i;</p> <p> XtSetLanguageProc (NULL, NULL, NULL);<br /> toplevel = XtVaOpenApplication (&app, "Demos", NULL, 0, &argc, argv, NULL,<br /> sessionShellWidgetClass, NULL);<br /> rowcol = XmCreateRowColumn (toplevel, "rowcol", NULL, 0);</p> <p> /* Create some colors */<br /> for (i = 0; i < MAX_COLUMNS; i++) {<br /> pixels[i] = ConvertStringToPixel (toplevel,<br /> rendition_data[i].color);<br /> }</p> <p> /* Create tab stops for columnar output */<br /> for (i = 0; i < MAX_COLUMNS; i++) {<br /> tabs[i] = XmTabCreate ((float) 1.5,<br /> XmINCHES,<br /> ((i == 0) ? XmABSOLUTE : XmRELATIVE),<br /> XmALIGNMENT_BEGINNING,<br /> ".");<br /> }</p> <p> /* Create a tablist table which contains the tabs */<br /> tablist = XmTabListInsertTabs (NULL, tabs, XtNumber (tabs), 0);</p> <p> /* Create some multi-font/color renditions, and use the tablist */<br /> /* This will be inherited if we use it on the first rendition */<br /> for (i = 0; i < MAX_COLUMNS; i++) {<br /> n = 0;</p> <p> if (i == 0) {<br /> XtSetArg (args[n], XmNtabList, tablist); n++;<br /> }</p> <p> XtSetArg (args[n], XmNrenditionForeground, 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,<br /> rendition_data[i].tag,<br /> args, n);<br /> }</p> <p> /* Create the Render Table */<br /> rendertable = XmRenderTableAddRenditions ( NULL,<br /> renditions,<br /> XtNumber (renditions),<br /> XmMERGE_NEW);</p> <p> /* Create the multi-column data for the list */</p> <p> 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 = XmCreateScrolledList (rowcol, "list", args, n);<br /> XtManageChild (list);</p> <p> /* Free the memory now the widget has 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);</p> <p> /* Secondly, the XmTab objects */<br /> for (i = 0; i < XtNumber (tabs); i++)<br /> XmTabFree (tabs[i]);</p> <p> /* Thirdly, the XmTabList object */<br /> XmTabListFree (tablist);</p> <p> /* Fourthly, the XmRendition objects */<br /> for (i = 0; i < XtNumber (renditions); i++)<br /> XmRenditionFree (renditions[i]);</p> <p> /* Lastly, the XmRenderTable object */<br /> XmRenderTableFree (rendertable);</p> <p> XtManageChild (rowcol);<br /> XtRealizeWidget (toplevel);<br /> XtAppMainLoop (app);<br /> }<br />

tinnie

 

Hi,
My code is basically like this:

/*to convert color string into corresponding pixel value*/\
for(i=0;i<2;i++)\
pixels[i] = ConvertStringToPixel (UxGetWidget(scrolledList2), rendition_data[i].color);\
\
for (i = 0 ; i < 2 ; i++) {\
n = 0;\
XtSetArg (arg[n], XmNrenditionForeground, pixels[i]); n++;\
XtSetArg (arg[n], XmNfontName, rendition_data[i].font); n++;\
XtSetArg (arg[n], XmNfontType, XmFONT_IS_FONT); n++;\
renditions[i] = XmRenditionCreate (UxGetWidget(scrolledList2), rendition_data[i].color, arg, n);\
}\
rendertable = XmRenderTableAddRenditions (NULL, renditions, XtNumber (renditions), XmMERGE_NEW);\

if(sl->session.status==FAILED){\
temp=XmStringGenerate ((XtPointer)buf,NULL,XmCHARSET_TEXT,rendition_data[0].color);\
XtVaSetValues(UxGetWidget(scrolledList2), XtNforeground,temp,XmNrenderTable, rendertable,NULL);\
\
}\
else{\
temp=XmStringGenerate ((XtPointer)buf,NULL,XmCHARSET_TEXT,rendition_data[1].color);\
XtVaSetValues(UxGetWidget(scrolledList2), XtNforeground,temp,XmNrenderTable, rendertable,NULL);\
}\
\
\
XmListAddItem(UxGetWidget(sl->session.status<=INACTIVE?scrolledList2:scrolledList1),temp,0);\

This is inside a recursive function call .
Using this I am able to render the list accordingly however the select cursor always chages color.
Kindly help.