Annotation of researchv9/X11/src/X.V11R1/lib/Xtk/GCManager.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char rcsid[] = "$Header: GCManager.c,v 1.12 87/09/13 16:44:10 newman Exp $";
        !             3: #endif lint
        !             4: 
        !             5: /*
        !             6:  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
        !             7:  * 
        !             8:  *                         All Rights Reserved
        !             9:  * 
        !            10:  * Permission to use, copy, modify, and distribute this software and its 
        !            11:  * documentation for any purpose and without fee is hereby granted, 
        !            12:  * provided that the above copyright notice appear in all copies and that
        !            13:  * both that copyright notice and this permission notice appear in 
        !            14:  * supporting documentation, and that the name of Digital Equipment
        !            15:  * Corporation not be used in advertising or publicity pertaining to
        !            16:  * distribution of the software without specific, written prior permission.  
        !            17:  * 
        !            18:  * 
        !            19:  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
        !            20:  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
        !            21:  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
        !            22:  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
        !            23:  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
        !            24:  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
        !            25:  * SOFTWARE.
        !            26:  */
        !            27: #include "Intrinsic.h"
        !            28: 
        !            29: typedef struct _GCrec {
        !            30:     Display    *dpy;           /* Display for GC */
        !            31:     Screen     *screen;        /* Screen for GC */
        !            32:     int                depth;          /* Depth for GC */
        !            33:     int         ref_count;      /* # of shareholders */
        !            34:     GC                 gc;             /* The GC itself. */
        !            35:     int        valueMask;      /* What fields are being used right now. */
        !            36:     XGCValues  values;         /* What values those fields have. */
        !            37:     struct _GCrec *next;       /* Next GC for this widgetkind. */
        !            38: } GCrec, *GCptr;
        !            39: 
        !            40: 
        !            41: static GCrec *GClist = NULL;
        !            42: 
        !            43: static int Matches(ptr,widget, valueMask, v)
        !            44:     GCptr              ptr;
        !            45:     Widget             widget;
        !            46:     unsigned long      valueMask;
        !            47:     register XGCValues *v;
        !            48: {
        !            49: #define CheckGCField(MaskBit,fieldName) \
        !            50:     if (m & MaskBit) if (p->fieldName != v->fieldName) return 0
        !            51: 
        !            52:     register int m = ptr->valueMask & valueMask;
        !            53:     register XGCValues *p = &(ptr->values);
        !            54: 
        !            55:     if (ptr->valueMask != valueMask) return 0;
        !            56:     if (ptr->depth != widget->core.depth) return 0;
        !            57:     if (ptr->screen != XtScreen(widget)) return 0;
        !            58: 
        !            59:     CheckGCField( GCFunction,          function);
        !            60:     CheckGCField( GCPlaneMask,         plane_mask);
        !            61:     CheckGCField( GCForeground,                foreground);
        !            62:     CheckGCField( GCBackground,                background);
        !            63:     CheckGCField( GCLineWidth,         line_width);
        !            64:     CheckGCField( GCLineStyle,         line_style);
        !            65:     CheckGCField( GCCapStyle,          cap_style);
        !            66:     CheckGCField( GCJoinStyle,         join_style);
        !            67:     CheckGCField( GCFillStyle,         fill_style);
        !            68:     CheckGCField( GCFillRule,          fill_rule);
        !            69:     CheckGCField( GCArcMode,           arc_mode);
        !            70:     CheckGCField( GCTile,              tile);
        !            71:     CheckGCField( GCStipple,           stipple);
        !            72:     CheckGCField( GCTileStipXOrigin,   ts_x_origin);
        !            73:     CheckGCField( GCTileStipYOrigin,   ts_y_origin);
        !            74:     CheckGCField( GCFont,              font);
        !            75:     CheckGCField( GCSubwindowMode,     subwindow_mode);
        !            76:     CheckGCField( GCGraphicsExposures, graphics_exposures);
        !            77:     CheckGCField( GCClipXOrigin,       clip_x_origin);
        !            78:     CheckGCField( GCClipYOrigin,       clip_y_origin);
        !            79:     CheckGCField( GCClipMask,          clip_mask);
        !            80:     CheckGCField( GCDashOffset,                dash_offset);
        !            81:     CheckGCField( GCDashList,          dashes);
        !            82: #undef CheckGCField
        !            83:     return 1;
        !            84: }
        !            85: 
        !            86: static void SetFields(ptr, valueMask, v)
        !            87: GCptr ptr;
        !            88:     register unsigned long valueMask;
        !            89:     register XGCValues    *v;
        !            90: {
        !            91: #define SetGCField(MaskBit,fieldName) \
        !            92:     if (valueMask & MaskBit) p->fieldName = v->fieldName
        !            93: 
        !            94:     register XGCValues *p = &(ptr->values);
        !            95: 
        !            96:     SetGCField( GCFunction,            function);
        !            97:     SetGCField( GCPlaneMask,           plane_mask);
        !            98:     SetGCField( GCForeground,          foreground);
        !            99:     SetGCField( GCBackground,          background);
        !           100:     SetGCField( GCLineWidth,           line_width);
        !           101:     SetGCField( GCLineStyle,           line_style);
        !           102:     SetGCField( GCCapStyle,            cap_style);
        !           103:     SetGCField( GCJoinStyle,           join_style);
        !           104:     SetGCField( GCFillStyle,           fill_style);
        !           105:     SetGCField( GCFillRule,            fill_rule);
        !           106:     SetGCField( GCArcMode,             arc_mode);
        !           107:     SetGCField( GCTile,                        tile);
        !           108:     SetGCField( GCStipple,             stipple);
        !           109:     SetGCField( GCTileStipXOrigin,     ts_x_origin);
        !           110:     SetGCField( GCTileStipYOrigin,     ts_y_origin);
        !           111:     SetGCField( GCFont,                        font);
        !           112:     SetGCField( GCSubwindowMode,       subwindow_mode);
        !           113:     SetGCField( GCGraphicsExposures,   graphics_exposures);
        !           114:     SetGCField( GCClipXOrigin,         clip_x_origin);
        !           115:     SetGCField( GCClipYOrigin,         clip_y_origin);
        !           116:     SetGCField( GCClipMask,            clip_mask);
        !           117:     SetGCField( GCDashOffset,          dash_offset);
        !           118:     SetGCField( GCDashList,            dashes);
        !           119:     ptr->valueMask |= valueMask;
        !           120:     XChangeGC(ptr->dpy, ptr->gc, valueMask, p);
        !           121: #undef SetGCField
        !           122: }
        !           123: 
        !           124: 
        !           125: /* 
        !           126:  * Return a read-only GC with the given values.  
        !           127:  */
        !           128: 
        !           129: GC XtGetGC(widget, valueMask, values)
        !           130:     Widget     widget;
        !           131:     XtGCMask   valueMask;
        !           132:     XGCValues  *values;
        !           133: {
        !           134:     GCptr first=GClist;
        !           135:     register GCptr cur;
        !           136:     Drawable drawable;
        !           137: 
        !           138:     for (cur = first; cur != NULL; cur = cur->next) {
        !           139:        if (Matches(cur, widget,valueMask, values)) {
        !           140:            valueMask &= ~cur->valueMask;
        !           141:            if (valueMask) SetFields(cur, valueMask, values);
        !           142:             cur->ref_count++;
        !           143:            return cur->gc;
        !           144:        }
        !           145:     }
        !           146:     cur = (GCptr) XtMalloc((unsigned)sizeof(GCrec));
        !           147:     cur->dpy = XtDisplay(widget);
        !           148:     cur->screen = XtScreen(widget);
        !           149:     cur->depth = widget->core.depth;
        !           150:     cur->ref_count = 1;
        !           151:     if (XtWindow(widget) == NULL)
        !           152:        drawable = XCreatePixmap(XtDisplay(widget), XtScreen(widget)->root,
        !           153:                        1,1,widget->core.depth);
        !           154:     else drawable = XtWindow(widget);
        !           155:     cur->gc = XCreateGC(XtDisplay(widget), drawable, valueMask, values);
        !           156:     cur->valueMask = valueMask;
        !           157:     cur->values = *values;
        !           158:     cur->next = first;
        !           159:     GClist = cur;
        !           160:     return cur->gc;
        !           161: }
        !           162: 
        !           163: void  XtDestroyGC(gc)
        !           164:     GC gc;
        !           165: {
        !           166:     GCptr first=GClist;
        !           167:     GCptr cur;
        !           168:     
        !           169:     for (cur = first; cur != NULL; cur = cur->next) 
        !           170:       if (cur->gc == gc) 
        !           171:          if (--(cur->ref_count) == 0) XFreeGC(cur->dpy, gc);     
        !           172:     return;
        !           173: }
        !           174: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.