[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

3254.0. "How to change the default GC ?" by BACHUS::RIJMENANTS (Dirk Rijmenants) Fri Aug 24 1990 05:59



         Hi, 


              A customer asked me the following question:


                   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 ?

                    Thanks in advance.

                                             Dirk
T.RTitleUserPersonal
Name
DateLines
3254.1XChangeGC()SUBWAY::GRAHAMThe revolution will be televisedThu Aug 30 1990 05:4423
    >             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...
3254.2XChangeGC() Example....SUBWAY::GRAHAMThe revolution will be televisedMon Sep 03 1990 08:4290
    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..