| > I'm using Xlib and I want to change the back- and
> foreground color of (all) my widgets.
> Can I change the default GC to do this (I don't want
> to explicitely set these attributes for each widget
> over and over...)
> If possible, can I have a small code fragment ?
Have you tried XChangeGC() ? You can change a GC with this after
it is created.
The function looks like...
XChangeGC(display, gc, mask, &values)
The 'mask' and 'values' arguments are the same as the ones used
in XCreateGC()
Caution: It is advised that GCs created with XtGetGC (allowing
applications to share GCs) should not be modified.
Kris...
|
| RE .0
>>Can I change the default GC to do this
>If possible, can I have a small code fragment ?
The following is some code fragment that shows the use of
XChangeGC().
#include <Xm/Xm.h>
extern Boolean fillMode;
extern int which_fill, npoints;
Pixmap tile_pix[3];
int line_thick = 1;
unsigned int line_type = LineSolid;
XGCValues gcval;
Position oldX, oldY;
Boolean drawing = False;
XPoint xy[1000];
/*
* ChangeLineThick() - given a widget, a GC and an integer representing
* the line width, set the line width attribute
* of the GC using the Xlib call
XSetLineAttributes.
*/
void ChangeLineThick(w, gc, lt)
Widget w;
GC gc;
int lt;
{
if (lt == 1) lt = 0; /* 0 uses fast algorithm for line thickness 1
*/
gcval.line_width = line_thick = lt;
XChangeGC(XtDisplay(w), gc, GCLineWidth, &gcval);
}
/*
* ChangeLineType() - set the line type as follows:
* 0 = solid
* 1 = dashes
* 2 = long dashes
*/
void ChangeLineType(w, gc, lt)
Widget w;
GC gc;
unsigned int lt;
{ if (lt == 1) lt = 0; /* 0 uses fast algorithm for line thickness
1 */
gcval.line_width = line_thick = lt;
XChangeGC(XtDisplay(w), gc, GCLineWidth, &gcval);
}
/*
* ChangeLineType() - set the line type as follows:
* 0 = solid
* 1 = dashes
* 2 = long dashes
*/
void ChangeLineType(w, gc, lt)
Widget w;
GC gc;
unsigned int lt;
{
int dashval;
switch (lt) {
case 1:
gcval.line_style = LineOnOffDash;
gcval.dashes = (char) 6;
break;
case 2:
gcval.line_style = LineOnOffDash;
gcval.dashes = (char) 2;
break;
default:
printf("Default solid lines used\n");
case 0:
gcval.line_style = LineSolid;
gcval.dashes = (char) 1;
break;
}
XChangeGC(XtDisplay(w), gc, GCLineStyle | GCDashList, &gcval
}
Kris..
|