[comp.windows.x] Setting widget colors within the application ?

Luis@postgres.Berkeley.EDU (Luis Miguel) (12/08/88)

I have written an application using HP Widgets, and although I
can set the foreground and background colors from my app-defaults
and .Xdefaults file, I have beeen unable to do so within the applicattion
itself using  XtSetArg (wargs[i], XtNforeground, COLOR).

Thanks for your help,

/Luis

Luis Miguel. Computer Science Division, UC Berkeley.
arpanet: luis@postgres.Berkeley.EDU         
uucp: {ihnp4,decvax}!ucbvax!ingres!luis                    
at&t: (415) 642-9585 (Work)

jack@hpcvlx.HP.COM (Jack Peterson) (12/09/88)

/ hpcvlx:comp.windows.x / Luis@postgres.Berkeley.EDU (Luis Miguel) /  9:52 am  Dec  7, 1988 /
I have written an application using HP Widgets, and although I
can set the foreground and background colors from my app-defaults
and .Xdefaults file, I have beeen unable to do so within the applicattion
itself using  XtSetArg (wargs[i], XtNforeground, COLOR).

Thanks for your help,

/Luis

Luis Miguel. Computer Science Division, UC Berkeley.
arpanet: luis@postgres.Berkeley.EDU         
uucp: {ihnp4,decvax}!ucbvax!ingres!luis                    
at&t: (415) 642-9585 (Work)
----------

Perhaps you are not giving it the pixel value of the color but the name 
of the color? If you are attempting to accomplish this task after creation
of the widget you need to make a SetValues call after the SetArg.
There really shouldn't be any problem doing this. Here is a little conversion
routine I use so I can use the color name.

Pixel Str2Pix(color)
  char *color;
{
  Colormap cmap;
  XColor color_struct;
  int scr = 0;

  cmap = XDefaultColormap(display, scr);
  XParseColor(display, cmap, color, &color_struct);
  XAllocColor(display, cmap, &color_struct);
  return(color_struct.pixel);
}

I then make the SetArg call like the following:

 XtSetArg(myArgs[i], XtNforeground, Str2Pix("blue")); i++;

Jack Peterson 
HP Corvallis Workstation Operation
Support Engineer