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