|
|
1.1 ! root 1: #ifndef lint ! 2: static char rcsid[] = "$Header: Resources.c,v 1.15 87/09/13 20:49:22 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: /* Converted to classing toolkit on 28 August 1987 by Joel McCormack */ ! 28: ! 29: /* XtResourceList.c -- compile and process resource lists. */ ! 30: ! 31: ! 32: #include "Intrinsic.h" ! 33: #include "Atoms.h" ! 34: /*#include "Xresource.h"*/ ! 35: #include <stdio.h> ! 36: ! 37: ! 38: #ifdef reverseVideoHack ! 39: static XrmName QreverseVideo; ! 40: #endif ! 41: static XrmClass QBoolean, QString; ! 42: ! 43: extern void bcopy(); ! 44: ! 45: static void CopyFromArg(src, dst, size) ! 46: XtArgVal src, dst; ! 47: register unsigned int size; ! 48: { ! 49: if (size == sizeof(XtArgVal)) ! 50: *(XtArgVal *)dst = src; ! 51: #ifdef BIGENDIAN ! 52: else if (size == sizeof(short)) ! 53: *(short *)dst = (short)src; ! 54: #endif BIGENDIAN ! 55: else if (size < sizeof(XtArgVal)) ! 56: bcopy((char *) &src, (char *) dst, (int) size); ! 57: else ! 58: bcopy((char *) src, (char *) dst, (int) size); ! 59: ! 60: } ! 61: ! 62: static void CopyToArg(src, dst, size) ! 63: XtArgVal src, *dst; ! 64: register unsigned int size; ! 65: { ! 66: if (size == sizeof(XtArgVal)) ! 67: *dst = *(XtArgVal *)src; ! 68: #ifdef BIGENDIAN ! 69: else if (size == sizeof(short)) ! 70: *dst = (XtArgVal) *((short *) src); ! 71: #endif BIGENDIAN ! 72: else if (size < sizeof(XtArgVal)) ! 73: bcopy((char *) src, (char *) dst, (int) size); ! 74: else ! 75: bcopy((char *) src, (char *) *dst, (int) size); ! 76: ! 77: } ! 78: ! 79: static void PrintResourceList(list, count) ! 80: register XtResourceList list; ! 81: register int count; ! 82: { ! 83: for (; --count >= 0; list++) { ! 84: (void) printf(" name: %s, class: %s, type: %s,\n", ! 85: list->resource_name, list->resource_class, list->resource_type); ! 86: (void) printf(" size: %d, offset: %x, def_type: %s, def_addr: %x\n", ! 87: list->resource_size, list->resource_offset, ! 88: list->default_type, list->default_addr); ! 89: } ! 90: } ! 91: ! 92: static Cardinal GetNamesAndClasses(w, names, classes) ! 93: register Widget w; ! 94: register XrmNameList names; ! 95: register XrmClassList classes; ! 96: { ! 97: register Cardinal length, j; ! 98: register XrmQuark t; ! 99: ! 100: for (length = 0; w != NULL; w = (Widget) w->core.parent) { ! 101: names[length] = w->core.xrm_name; ! 102: classes[length] = w->core.widget_class->core_class.xrm_class; ! 103: length++; ! 104: } ! 105: /* They're in backwards order, flop them around */ ! 106: for (j = 0; j < length/2; j++) { ! 107: t = names[j]; ! 108: names[j] = names[length-j-1]; ! 109: names[length-j-1] = t; ! 110: t = classes[j]; ! 111: classes[j] = classes[length-j-1]; ! 112: classes[length-j-1] = t; ! 113: } ! 114: return length; ! 115: } ! 116: ! 117: ! 118: /* Spiffy fast compiled form of resource list. */ ! 119: /* XtResourceLists are compiled in-place into XrmResourceLists */ ! 120: /* All atoms are replaced by quarks, and offsets are -offset-1 to */ ! 121: /* indicate that this list has been compiled already */ ! 122: ! 123: typedef struct { ! 124: XrmQuark xrm_name; /* Resource name quark */ ! 125: XrmQuark xrm_class; /* Resource class quark */ ! 126: XrmQuark xrm_type; /* Resource representation type quark */ ! 127: Cardinal xrm_size; /* Size in bytes of representation */ ! 128: long int xrm_offset; /* -offset-1 */ ! 129: XrmQuark xrm_default_type; /* Default representation type quark */ ! 130: caddr_t xrm_default_addr; /* Default resource address */ ! 131: } XrmResource, *XrmResourceList; ! 132: ! 133: static XrmCompileResourceList(resources, num_resources) ! 134: register XtResourceList resources; ! 135: Cardinal num_resources; ! 136: { ! 137: register XrmResourceList xrmres; ! 138: register Cardinal count; ! 139: ! 140: for (xrmres = (XrmResourceList) resources, count = 0; ! 141: count < num_resources; ! 142: xrmres++, resources++, count++) { ! 143: xrmres->xrm_name = StringToName(resources->resource_name); ! 144: xrmres->xrm_class = StringToClass(resources->resource_class); ! 145: xrmres->xrm_type = StringToQuark(resources->resource_type); ! 146: xrmres->xrm_size = resources->resource_size; ! 147: xrmres->xrm_offset = -resources->resource_offset - 1; ! 148: xrmres->xrm_default_type = StringToQuark(resources->default_type); ! 149: xrmres->xrm_default_addr = resources->default_addr; ! 150: } ! 151: ! 152: } /* XrmCompileResourceList */ ! 153: ! 154: /* ||| References to display should be references to screen */ ! 155: ! 156: static void XrmGetResources( ! 157: dpy, base, names, classes, length, resources, num_resources, args, num_args) ! 158: ! 159: Display *dpy; /* The widget's display connection */ ! 160: caddr_t base; /* Base address of memory to write to */ ! 161: register XrmNameList names; /* Full inheritance name of widget */ ! 162: register XrmClassList classes; /* Full inheritance class of widget */ ! 163: Cardinal length; /* Number of entries in names, classes */ ! 164: XtResourceList resources; /* The list of resources required. */ ! 165: Cardinal num_resources; /* number of items in resource list */ ! 166: ArgList args; /* ArgList to override resources */ ! 167: Cardinal num_args; /* number of items in arg list */ ! 168: { ! 169: register ArgList arg; ! 170: register XrmName argName; ! 171: XrmResourceList xrmres; ! 172: register XrmResourceList res; ! 173: XrmValue val, defaultVal; ! 174: register int j; ! 175: int i; ! 176: XrmHashTable searchList[100]; ! 177: static Boolean found[1000]; ! 178: ! 179: #ifdef reverseVideoHack ! 180: Boolean reverseVideo, getReverseVideo; ! 181: ! 182: reverseVideo = FALSE; ! 183: getReverseVideo = TRUE; ! 184: #endif ! 185: ! 186: /* ||| This should be passed a compiled arg list, too, but such has to ! 187: be allocated dynamically */ ! 188: ! 189: /* ||| Should be warnings? or error? */ ! 190: if ((args == NULL) && (num_args != 0)) { ! 191: XtError("argument count > 0 on NULL argument list"); ! 192: num_args = 0; ! 193: } ! 194: if ((resources == NULL) && (num_resources != 0)) { ! 195: XtError("resource count > 0 on NULL resource list"); ! 196: return; ! 197: } ! 198: ! 199: if (num_resources != 0) { ! 200: /* Compile resource list if needed */ ! 201: if (((int)resources->resource_offset) >= 0) { ! 202: XrmCompileResourceList(resources, num_resources); ! 203: } ! 204: xrmres = (XrmResourceList) resources; ! 205: ! 206: /* Mark each resource as not found on arg list */ ! 207: for (j = 0; j < num_resources; j++) { ! 208: found[j] = FALSE; ! 209: } ! 210: ! 211: /* Copy the args into the resources, mark each as found */ ! 212: for (arg = args, i = 0; i < num_args; i++, arg++) { ! 213: argName = StringToName(arg->name); ! 214: #ifdef reverseVideoHack ! 215: if (argName == QreverseVideo) { ! 216: reverseVideo = (Boolean) arg->value; ! 217: getReverseVideo = FALSE; ! 218: } else ! 219: #endif ! 220: for (j = 0, res = xrmres; j < num_resources; j++, res++) { ! 221: if (argName == res->xrm_name) { ! 222: CopyFromArg( ! 223: arg->value, ! 224: (XtArgVal) base - res->xrm_offset - 1, ! 225: res->xrm_size); ! 226: found[j] = TRUE; ! 227: break; ! 228: } ! 229: } ! 230: } ! 231: } ! 232: ! 233: /* Resources name and class will go into names[length], classes[length] */ ! 234: names[length+1] = NULLQUARK; ! 235: classes[length+1] = NULLQUARK; ! 236: ! 237: #ifdef reverseVideoHack ! 238: if (XDisplayCells(dpy, DefaultScreen(dpy)) > 2) { ! 239: /* Color box, ignore ReverseVideo */ ! 240: reverseVideo = FALSE; ! 241: } else if (getReverseVideo) { ! 242: names[length] = QreverseVideo; ! 243: classes[length] = QBoolean; ! 244: XrmGetResource(dpy, names, classes, QBoolean, &val); ! 245: if (val.addr) ! 246: reverseVideo = *((Boolean *) val.addr); ! 247: } ! 248: /* ||| Nothing is done w/reverseVideo now, but something should be! */ ! 249: #endif ! 250: ! 251: names[length] = NULLQUARK; ! 252: classes[length] = NULLQUARK; ! 253: ! 254: if (num_resources != 0) { ! 255: ! 256: /* Ask resource manager for a list of database levels that we can ! 257: do a single-level search on each resource */ ! 258: ! 259: XrmGetSearchList(names, classes, searchList); ! 260: ! 261: /* go to the resource manager for those resources not found yet */ ! 262: /* if it's not in the resource database use the default value */ ! 263: ! 264: for (res = xrmres, j = 0; j < num_resources; j++, res++) { ! 265: if (! found[j]) { ! 266: XrmGetSearchResource(dpy, searchList, res->xrm_name, ! 267: res->xrm_class, res->xrm_type, &val); ! 268: /* ! 269: if (val.addr == NULL && res->xrm_default_addr != NULL) { ! 270: */ ! 271: if (val.addr == NULL) { ! 272: /* Convert default value to proper type */ ! 273: defaultVal.addr = res->xrm_default_addr; ! 274: defaultVal.size = sizeof(caddr_t); ! 275: _XrmConvert(dpy, res->xrm_default_type, defaultVal, ! 276: res->xrm_type, &val); ! 277: } ! 278: if (val.addr) { ! 279: if (res->xrm_type == QString) { ! 280: *((caddr_t *)(base - res->xrm_offset - 1)) = val.addr; ! 281: #ifdef BIGENDIAN ! 282: /* ||| Why? This should be handled by string to short, etc. conversions */ ! 283: } else if (res->xrm_size == sizeof(short)) { ! 284: *(short *) (base - res->xrm_offset - 1) = ! 285: (short)*((int *)val.addr); ! 286: #endif BIGENDIAN ! 287: } else { ! 288: bcopy( ! 289: (char *) val.addr, ! 290: (char *) (base - res->xrm_offset - 1), ! 291: (int) res->xrm_size); ! 292: } ! 293: } else if (res->xrm_default_addr != NULL) { ! 294: bcopy( ! 295: (char *) res->xrm_default_addr, ! 296: (char *) (base - res->xrm_offset - 1), ! 297: (int) res->xrm_size); ! 298: } else { ! 299: /* didn't find a default value, initialize to NULL... */ ! 300: bzero( ! 301: (char *) (base - res->xrm_offset - 1), ! 302: (int) res->xrm_size); ! 303: } ! 304: } ! 305: } ! 306: } ! 307: } ! 308: ! 309: static void GetResources(widgetClass, w, names, classes, length, args, num_args) ! 310: WidgetClass widgetClass; ! 311: Widget w; ! 312: XrmNameList names; ! 313: XrmClassList classes; ! 314: Cardinal length; ! 315: ArgList args; ! 316: Cardinal num_args; ! 317: { ! 318: /* First get resources for superclasses */ ! 319: if (widgetClass->core_class.superclass != NULL) { ! 320: GetResources(widgetClass->core_class.superclass, ! 321: w, names, classes, length, args, num_args); ! 322: } ! 323: /* Then for this class */ ! 324: XrmGetResources(XtDisplay(w), (caddr_t) w, names, classes, length, ! 325: widgetClass->core_class.resources, widgetClass->core_class.num_resources, ! 326: args, num_args); ! 327: } /* GetResources */ ! 328: ! 329: ! 330: void XtGetResources(w, args, num_args) ! 331: register Widget w; ! 332: ArgList args; ! 333: Cardinal num_args; ! 334: { ! 335: XrmName names[100]; ! 336: XrmClass classes[100]; ! 337: Cardinal length; ! 338: ! 339: /* Make sure xrm_class, xrm_name are valid */ ! 340: if (w->core.widget_class->core_class.xrm_class == NULLQUARK) { ! 341: w->core.widget_class->core_class.xrm_class = ! 342: StringToClass(w->core.widget_class->core_class.class_name); ! 343: } ! 344: w->core.xrm_name = StringToName(w->core.name); ! 345: ! 346: /* Get names, classes for widget on up */ ! 347: length = GetNamesAndClasses(w, names, classes); ! 348: ! 349: /* Get resources starting at CorePart on down to this widget */ ! 350: GetResources(w->core.widget_class, w, names, classes, length, ! 351: args, num_args); ! 352: } /* XtGetResources */ ! 353: ! 354: void XtGetSubresources ! 355: (w, base, name, class, resources, num_resources, args, num_args) ! 356: Widget w; /* Widget "parent" of subobject */ ! 357: caddr_t base; /* Base address to write to */ ! 358: String name; /* name of subobject */ ! 359: String class; /* class of subobject */ ! 360: XtResourceList resources; /* resource list for subobject */ ! 361: Cardinal num_resources; ! 362: ArgList args; /* arg list to override resources */ ! 363: Cardinal num_args; ! 364: { ! 365: XrmName names[100]; ! 366: XrmClass classes[100]; ! 367: Cardinal length; ! 368: ! 369: /* Get full name, class of subobject */ ! 370: length = GetNamesAndClasses(w, names, classes); ! 371: names[length] = StringToName(name); ! 372: classes[length] = StringToClass(class); ! 373: length++; ! 374: ! 375: /* Fetch resources */ ! 376: XrmGetResources(XtDisplay(w), base, names, classes, length, ! 377: resources, num_resources, args, num_args); ! 378: } ! 379: ! 380: ! 381: static void XrmGetValues(base, resources, num_resources, args, num_args) ! 382: caddr_t base; /* Base address to fetch values from */ ! 383: register XtResourceList resources; /* The current resource values. */ ! 384: register Cardinal num_resources; /* number of items in resources */ ! 385: ArgList args; /* The resource values requested */ ! 386: Cardinal num_args; /* number of items in arg list */ ! 387: { ! 388: register ArgList arg; ! 389: register XrmResourceList xrmres; ! 390: register int i; ! 391: register XrmName argName; ! 392: ! 393: if (num_resources == 0) return; ! 394: ! 395: /* Resource lists are assumed to be in compiled form already via the ! 396: initial XtGetResources, XtGetSubresources calls */ ! 397: ! 398: for (arg = args ; num_args != 0; num_args--, arg++) { ! 399: argName = StringToName(arg->name); ! 400: for (xrmres = (XrmResourceList) resources, i = 0; ! 401: i < num_resources; ! 402: i++, xrmres++) { ! 403: if (argName == xrmres->xrm_name) { ! 404: CopyToArg( ! 405: (XtArgVal) base - xrmres->xrm_offset - 1, ! 406: &arg->value, ! 407: xrmres->xrm_size); ! 408: break; ! 409: } ! 410: } ! 411: } ! 412: } ! 413: ! 414: static void GetValues(widgetClass, w, args, num_args) ! 415: WidgetClass widgetClass; ! 416: Widget w; ! 417: ArgList args; ! 418: Cardinal num_args; ! 419: { ! 420: /* First get resource values for superclass */ ! 421: if (widgetClass->core_class.superclass != NULL) { ! 422: GetValues(widgetClass->core_class.superclass, w, args, num_args); ! 423: } ! 424: /* Then for this class */ ! 425: XrmGetValues( ! 426: (caddr_t) w, ! 427: widgetClass->core_class.resources, ! 428: widgetClass->core_class.num_resources, ! 429: args, num_args); ! 430: } /* GetValues */ ! 431: ! 432: void XtGetValues(w, args, num_args) ! 433: Widget w; ! 434: ArgList args; ! 435: Cardinal num_args; ! 436: { ! 437: if (num_args == 0) return; ! 438: if ((args == NULL) && (num_args != 0)) { ! 439: XtError("argument count > 0 on NULL argument list"); ! 440: return; ! 441: } ! 442: /* Get resource values starting at CorePart on down to this widget */ ! 443: GetValues(w->core.widget_class, w, args, num_args); ! 444: } /* XtGetValues */ ! 445: ! 446: static void XrmSetValues(base, resources, num_resources, args, num_args) ! 447: caddr_t base; /* Base address to write values to */ ! 448: register XtResourceList resources; /* The current resource values. */ ! 449: register Cardinal num_resources; /* number of items in resources */ ! 450: ArgList args; /* The resource values to set */ ! 451: Cardinal num_args; /* number of items in arg list */ ! 452: { ! 453: register ArgList arg; ! 454: register XrmResourceList xrmres; ! 455: register int i; ! 456: register XrmName argName; ! 457: ! 458: if (num_resources == 0) return; ! 459: ! 460: /* Resource lists are assumed to be in compiled form already via the ! 461: initial XtGetResources, XtGetSubresources calls */ ! 462: ! 463: for (arg = args ; num_args != 0; num_args--, arg++) { ! 464: argName = StringToName(arg->name); ! 465: for (xrmres = (XrmResourceList) resources, i = 0; ! 466: i < num_resources; ! 467: i++, xrmres++) { ! 468: if (argName == xrmres->xrm_name) { ! 469: CopyFromArg(arg->value, ! 470: (XtArgVal) base - xrmres->xrm_offset - 1, ! 471: xrmres->xrm_size); ! 472: break; ! 473: } ! 474: } ! 475: } ! 476: } /* XrmSetValues */ ! 477: ! 478: static void SetValues(widgetClass, w, args, num_args) ! 479: WidgetClass widgetClass; ! 480: Widget w; ! 481: ArgList args; ! 482: Cardinal num_args; ! 483: { ! 484: /* First set resource values for superclass */ ! 485: if (widgetClass->core_class.superclass != NULL) { ! 486: SetValues(widgetClass->core_class.superclass, w, args, num_args); ! 487: } ! 488: /* Then for this class */ ! 489: XrmSetValues((caddr_t) w, ! 490: widgetClass->core_class.resources, ! 491: widgetClass->core_class.num_resources, ! 492: args, num_args); ! 493: } /* SetValues */ ! 494: ! 495: static Boolean RecurseSetValues (current, request, new, last, class) ! 496: Widget current, request, new; ! 497: Boolean last; ! 498: WidgetClass class; ! 499: { ! 500: Boolean redisplay = FALSE; ! 501: if (class->core_class.superclass) ! 502: redisplay = RecurseSetValues (current, request, new, FALSE, ! 503: class->core_class.superclass); ! 504: if (class->core_class.set_values) ! 505: redisplay |= (*class->core_class.set_values) (current, request, new, ! 506: last, class); ! 507: return (redisplay); ! 508: } ! 509: ! 510: void XtSetValues(w, args, num_args) ! 511: Widget w; ! 512: ArgList args; ! 513: Cardinal num_args; ! 514: { ! 515: Widget requestWidget, newWidget; ! 516: Cardinal widgetSize; ! 517: Boolean redisplay; ! 518: ! 519: if (num_args == 0) return; ! 520: if ((args == NULL) && (num_args != 0)) { ! 521: XtError("argument count > 0 on NULL argument list"); ! 522: return; ! 523: } ! 524: ! 525: /* Allocate and copy current widget into newWidget */ ! 526: widgetSize = w->core.widget_class->core_class.widget_size; ! 527: requestWidget = (Widget) XtMalloc (widgetSize); ! 528: newWidget = (Widget) XtMalloc(widgetSize); ! 529: bcopy((char *) w, (char *) requestWidget, widgetSize); ! 530: ! 531: /* Set resource values starting at CorePart on down to this widget */ ! 532: SetValues(w->core.widget_class, requestWidget, args, num_args); ! 533: bcopy ((char *) requestWidget, (char *) newWidget, widgetSize); ! 534: ! 535: /* Inform widget of changes and deallocate newWidget */ ! 536: redisplay = RecurseSetValues (w, requestWidget, newWidget, TRUE, ! 537: w->core.widget_class); ! 538: ! 539: /* If a SetValues proc made a successful geometry request, ! 540: then "w" contains the new, correct x, y, width, height fields. ! 541: Make sure not to smash them when copying "new" back into "w". */ ! 542: newWidget->core.x = w->core.x; ! 543: newWidget->core.y = w->core.y; ! 544: newWidget->core.width = w->core.width; ! 545: newWidget->core.height = w->core.height; ! 546: newWidget->core.border_width = w->core.border_width; ! 547: ! 548: bcopy ((char *) newWidget, (char *) w, widgetSize); ! 549: XtFree((char *) requestWidget); ! 550: XtFree((char *) newWidget); ! 551: ! 552: if (redisplay) ! 553: /* repaint background of window, and force a full exposure event */ ! 554: XClearArea (XtDisplay(w), XtWindow(w), 0, 0, 0, 0, TRUE); ! 555: ! 556: } /* XtSetValues */ ! 557: ! 558: ! 559: static Boolean initialized = FALSE; ! 560: ! 561: extern void ResourceListInitialize() ! 562: { ! 563: if (initialized) ! 564: return; ! 565: initialized = TRUE; ! 566: ! 567: #ifdef reverseVideoHack ! 568: QreverseVideo = StringToName(XtNreverseVideo); ! 569: #endif ! 570: QBoolean = StringToClass(XtCBoolean); ! 571: QString = StringToClass(XtCString); ! 572: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.