Annotation of researchv9/X11/src/X.V11R1/lib/oldXtk/Resources.c, revision 1.1

1.1     ! root        1: /* $Header: Resources.c,v 1.1 87/09/11 07:59:15 toddb Exp $ */
        !             2: #ifndef lint
        !             3: static char *sccsid = "@(#)ResourceList.c      1.10    2/25/87";
        !             4: #endif lint
        !             5: 
        !             6: /*
        !             7:  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
        !             8:  * 
        !             9:  *                         All Rights Reserved
        !            10:  * 
        !            11:  * Permission to use, copy, modify, and distribute this software and its 
        !            12:  * documentation for any purpose and without fee is hereby granted, 
        !            13:  * provided that the above copyright notice appear in all copies and that
        !            14:  * both that copyright notice and this permission notice appear in 
        !            15:  * supporting documentation, and that the name of Digital Equipment
        !            16:  * Corporation not be used in advertising or publicity pertaining to
        !            17:  * distribution of the software without specific, written prior permission.  
        !            18:  * 
        !            19:  * 
        !            20:  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
        !            21:  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
        !            22:  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
        !            23:  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
        !            24:  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
        !            25:  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
        !            26:  * SOFTWARE.
        !            27:  */
        !            28: 
        !            29: 
        !            30: /* XtResourceList.c -- compile and process resource lists. */
        !            31: 
        !            32: #include "Xlib.h"
        !            33: #include "Intrinsic.h"
        !            34: #include "Atoms.h"
        !            35: #include "Xresource.h"
        !            36: #include <stdio.h>
        !            37: 
        !            38: 
        !            39: #define XtNewNameList()                        ((XrmNameList) XrmNewQuarkList())
        !            40: #define XtCopyNameList(names)          ((XrmNameList) XrmCopyQuarkList(names))
        !            41: 
        !            42: #define XtNewClassList()               ((XrmClassList) XrmNewQuarkList())
        !            43: #define XtCopyClassList(classes)       ((XrmClassList) XrmCopyQuarkList(classes))
        !            44: 
        !            45: int    XtDefaultFGPixel, XtDefaultBGPixel;
        !            46: Pixmap XtDefaultFGPixmap, XtDefaultBGPixmap;
        !            47: 
        !            48: static XrmName Qname, QreverseVideo;
        !            49: static XrmClass        QBoolean, QString;
        !            50: 
        !            51: static XContext nameListContext;    /* Context to attach NameList to window  */
        !            52: static XContext classListContext;   /* Context to attach ClassList to window */
        !            53: 
        !            54: extern void bcopy();
        !            55: 
        !            56: static void CopyFromArg(src, dst, size)
        !            57:     XtArgVal src, dst;
        !            58:     register unsigned int size;
        !            59: {
        !            60:     if (size == sizeof(XtArgVal))
        !            61:        *(XtArgVal *)dst = src;
        !            62: #ifdef BIGENDIAN
        !            63:     else if (size == sizeof(short)) 
        !            64:        *(short *)dst = (short)src;
        !            65: #endif BIGENDIAN
        !            66:     else if (size < sizeof(XtArgVal))
        !            67:        bcopy((char *) &src, (char *) dst, (int) size);
        !            68:     else
        !            69:        bcopy((char *) src, (char *) dst, (int) size);
        !            70: 
        !            71: }
        !            72: 
        !            73: static void CopyToArg(src, dst, size)
        !            74:     XtArgVal src, *dst;
        !            75:     register unsigned int size;
        !            76: {
        !            77:     if (size == sizeof(XtArgVal))
        !            78:        *dst = *(XtArgVal *)src;
        !            79: #ifdef BIGENDIAN
        !            80:     else if (size == sizeof(short)) 
        !            81:        *dst = (XtArgVal) *((short *) src);
        !            82: #endif BIGENDIAN
        !            83:     else if (size < sizeof(XtArgVal))
        !            84:        bcopy((char *) src, (char *) dst, (int) size);
        !            85:     else
        !            86:        bcopy((char *) src, (char *) *dst, (int) size);
        !            87: 
        !            88: }
        !            89: 
        !            90: void PrintResourceList(list, count)
        !            91:     register ResourceList list;
        !            92:     register int count;
        !            93: {
        !            94:     for (; --count >= 0; list++) {
        !            95:         (void) printf("    name: %s, class, %s, type: %s,\n",
        !            96:            list->name, list->class, list->type);
        !            97:        (void) printf("    size: %d, addr: 0x%x, defaddr: 0x%x\n",
        !            98:            list->size, list->addr, list->defaultaddr);
        !            99:     }
        !           100: }
        !           101: 
        !           102: static void GetNameAndClass(dpy, w, names, classes)
        !           103:     register Display   *dpy;
        !           104:     register Window     w;
        !           105:             XrmNameList  *names;
        !           106:             XrmClassList *classes;
        !           107: {
        !           108:     if (XFindContext(dpy, w, nameListContext,  (caddr_t *)names))
        !           109:        *names = XtNewNameList();
        !           110:     if (XFindContext(dpy, w, classListContext, (caddr_t *)classes))
        !           111:         *classes = XtNewClassList();
        !           112: }
        !           113: 
        !           114: void XtSetNameAndClass(dpy, w, names, classes)
        !           115:     register Display   *dpy;
        !           116:     register Window     w;
        !           117:             XrmNameList         names;
        !           118:             XrmClassList classes;
        !           119: {
        !           120:     (void)XSaveContext(
        !           121:        dpy, w, nameListContext,  (caddr_t)XtCopyNameList(names));
        !           122:     (void)XSaveContext(
        !           123:        dpy, w, classListContext, (caddr_t)XtCopyClassList(classes));
        !           124: }
        !           125: 
        !           126: static XrmName         resourceNames[1000];
        !           127: 
        !           128: void XtGetResources(
        !           129:   dpy,
        !           130:   resources, resourceCount, args, argCount,
        !           131:   parent, widgetName, widgetClass, names, classes)
        !           132: 
        !           133:   Display      *dpy;           /* The widget's display connection         */
        !           134:   ResourceList resources;      /* The list of resources required.         */
        !           135:   int          resourceCount;  /* number of items in resource list        */
        !           136:   ArgList      args;           /* ArgList to override resources           */
        !           137:   int          argCount;       /* number of items in arg list             */
        !           138:   Window       parent;         /* Parent window for computing inheritance */
        !           139:   XrmAtom      widgetName;     /* name of this widget (may be overridden) */
        !           140:   XrmAtom      widgetClass;    /* class of this widget                    */
        !           141:   register XrmNameList *names; /* Full inheritance name of widget window  */
        !           142:   register XrmClassList *classes;/* Full inheritance class of widget window */
        !           143: {
        !           144:     register   ArgList         arg;
        !           145:     register   XrmName         argName;
        !           146:     register   ResourceList    res;
        !           147:                XrmNameList     parentNames;
        !           148:                XrmClassList    parentClasses;
        !           149:                XrmValue        val;
        !           150:     register   int             j;
        !           151:                int             length, i;
        !           152:                Boolean          reverseVideo, getReverseVideo;
        !           153:                XrmHashTable    searchList[100];
        !           154:     static     Boolean         found[1000];
        !           155: 
        !           156:     reverseVideo    = FALSE;
        !           157:     getReverseVideo = TRUE;
        !           158: 
        !           159:     if (((args == NULL) && (argCount != 0)) ||
        !           160:         ((resources == NULL) && (resourceCount != 0))) {
        !           161:        /* ||| call warning handler here */
        !           162:        return;
        !           163:     }
        !           164: 
        !           165:     if (resourceCount != 0) {
        !           166:        for (res = resources, j = 0; j < resourceCount; j++, res++) {
        !           167:            found[j] = FALSE;
        !           168:            resourceNames[j] = XrmAtomToName(res->name);
        !           169:        }
        !           170: 
        !           171:        /* find the widget name and copy the args into the resources */
        !           172:        for (arg = args, i = 0; i < argCount; i++, arg++) {
        !           173:            argName = XrmAtomToName(arg->name);
        !           174:            if (argName == Qname) {
        !           175:                widgetName = (XrmAtom) arg->value;
        !           176:            } else if (argName == QreverseVideo) {
        !           177:                reverseVideo = (Boolean) arg->value;
        !           178:                getReverseVideo = FALSE;
        !           179:            } else {
        !           180:                for (j = 0, res = resources; j < resourceCount; j++, res++) {
        !           181:                    if (argName == resourceNames[j]) {
        !           182:                        CopyFromArg(arg->value, res->addr, res->size);
        !           183:                        found[j] = TRUE;
        !           184:                        break;
        !           185:                    }
        !           186:                }
        !           187:            }
        !           188:        }
        !           189:     }
        !           190: 
        !           191:     /* set up the name of the widget */
        !           192:     GetNameAndClass(dpy, parent, &parentNames, &parentClasses);
        !           193:     length = XrmNameListLength(parentNames);
        !           194:     *names = (XrmNameList) XtCalloc((unsigned) length+3, sizeof(XrmName));
        !           195:     *classes = (XrmClassList) XtCalloc((unsigned) length+3, sizeof(XrmClass));
        !           196:     for (i=0; i<length; i++) {
        !           197:        (*names)[i] = parentNames[i];
        !           198:        (*classes)[i] = parentClasses[i];
        !           199:     }
        !           200:     (*names)[length]     = XrmAtomToName(widgetName);
        !           201:     (*classes)[length]   = XrmAtomToClass(widgetClass);
        !           202:     (*names)[length+1]   = NULLQUARK;
        !           203:     (*classes)[length+1] = NULLQUARK;
        !           204:     (*names)[length+2]   = NULLQUARK;
        !           205:     (*classes)[length+2] = NULLQUARK;
        !           206: 
        !           207:     if (XDisplayCells(dpy, DefaultScreen(dpy)) > 2) {
        !           208:        /* Color box, ignore ReverseVideo */
        !           209:        reverseVideo = FALSE;
        !           210:     } else if (getReverseVideo) {
        !           211:        (*names)[length+1] = QreverseVideo;
        !           212:        (*classes)[length+1] = QBoolean;
        !           213:        XrmGetResource(dpy, *names, *classes, QBoolean, &val);
        !           214:        if (val.addr)
        !           215:            reverseVideo = *((Boolean *) val.addr);
        !           216:     }
        !           217:     if (reverseVideo) {
        !           218:        XtDefaultFGPixel = WhitePixel(dpy, DefaultScreen(dpy));
        !           219:        XtDefaultBGPixel = BlackPixel(dpy, DefaultScreen(dpy));
        !           220:     } else {
        !           221:        XtDefaultFGPixel = BlackPixel(dpy, DefaultScreen(dpy));
        !           222:        XtDefaultBGPixel = WhitePixel(dpy, DefaultScreen(dpy));
        !           223:     }
        !           224: 
        !           225:     (*names)[length+1] = NULLQUARK;
        !           226:     (*classes)[length+1] = NULLQUARK;
        !           227: 
        !           228:     if (resourceCount != 0) {
        !           229: 
        !           230:        /* Ask resource manager for a list of database levels that we can
        !           231:           do a single-level search on each resource */
        !           232: 
        !           233:        XrmGetSearchList(*names, *classes, searchList);
        !           234:        
        !           235:        /* go to the resource manager for those resources not found yet */
        !           236:        /* if it's not in the resource database copy the default value in */
        !           237:     
        !           238:        for (res = resources, j = 0; j < resourceCount; j++, res++) {
        !           239:            if (! found[j]) {
        !           240:                XrmGetSearchResource(dpy, searchList, resourceNames[j],
        !           241:                 XrmAtomToClass(res->class), res->type, &val);
        !           242:                if (val.addr) {
        !           243: /* ||| Kludgy */
        !           244:                    if (XrmAtomToQuark(res->type) == QString) {
        !           245:                        *((caddr_t *)(res->addr)) = val.addr;
        !           246: #ifdef BIGENDIAN
        !           247: /* ||| Why? This should be handled by string to short, etc. conversions */
        !           248:                    } else if (res->size == sizeof(short)) {
        !           249:                        *(short *) (res->addr) = (short)*((int *)val.addr);
        !           250: #endif BIGENDIAN
        !           251:                    } else {
        !           252:                        bcopy(
        !           253:                            (char *) val.addr,
        !           254:                            (char *) res->addr, 
        !           255:                            (int) res->size);
        !           256:                    }
        !           257:                } else if (res->defaultaddr != NULL) {
        !           258:                    bcopy(
        !           259:                        (char *)res->defaultaddr,
        !           260:                        (char *)res->addr,
        !           261:                        (int) res->size);
        !           262:                }
        !           263:            }
        !           264:        }
        !           265:     }
        !           266: }
        !           267: 
        !           268: void XtGetValues(resources, resourceCount, args, argCount)
        !           269:   register ResourceList resources;     /* The current resource values. */
        !           270:   int                  resourceCount;  /* number of items in resources */
        !           271:   ArgList              args;           /* The resource values requested */
        !           272:   int                  argCount;       /* number of items in arg list */
        !           273: {
        !           274:     register ArgList           arg;
        !           275:     register ResourceList      res;
        !           276:     register int               i;
        !           277:     register XrmName           argName;
        !           278: 
        !           279:     if (argCount == 0) return;
        !           280:     if (((args == NULL) && (argCount != 0)) ||
        !           281:         ((resources == NULL) && (resourceCount != 0))) {
        !           282:        /* call warning handler here */
        !           283:        return;
        !           284:     }
        !           285: 
        !           286:     for (res = resources, i = 0; i < resourceCount; i++, res++) {
        !           287:        resourceNames[i] = XrmAtomToName(res->name);
        !           288:     }
        !           289:     for (arg = args ; --argCount >= 0; arg++) {
        !           290:        argName = XrmAtomToName(arg->name);
        !           291:        for (res = resources, i = 0; i < resourceCount; i++, res++) {
        !           292:            if (argName == resourceNames[i]) {
        !           293:                CopyToArg(res->addr, &arg->value, res->size);
        !           294:                break;
        !           295:            }
        !           296:        }
        !           297:     }
        !           298: }
        !           299: 
        !           300: void XtSetValues(resources, resourceCount, args, argCount)
        !           301:   register ResourceList resources;     /* The current resource values. */
        !           302:   int                  resourceCount;  /* number of items in resources */
        !           303:   ArgList              args;           /* The resource values to set */
        !           304:   int                  argCount;       /* number of items in arg list */
        !           305: {
        !           306:     register ArgList           arg;
        !           307:     register ResourceList      res;
        !           308:     register int               i;
        !           309:     register XrmName           argName;
        !           310: 
        !           311:     if (argCount == 0) return;
        !           312:     if (((args == NULL) && (argCount != 0)) ||
        !           313:         ((resources == NULL) && (resourceCount != 0))) {
        !           314:        /* call warning handler here */
        !           315:        return;
        !           316:     }
        !           317: 
        !           318:     for (res = resources, i = 0; i < resourceCount; i++, res++) {
        !           319:        resourceNames[i] = XrmAtomToQuark(res->name);
        !           320:     }
        !           321:     for (arg = args ; --argCount >= 0; arg++) {
        !           322:        argName = XrmAtomToName(arg->name);
        !           323:        for (res = resources, i = 0; i < resourceCount; i++, res++) {
        !           324:            if (argName == resourceNames[i]) {
        !           325:                CopyFromArg(arg->value, res->addr, res->size);
        !           326:                break;
        !           327:            }
        !           328:        }
        !           329:     }
        !           330: }
        !           331: 
        !           332: static Boolean initialized = FALSE;
        !           333: 
        !           334: extern void ResourceListInitialize()
        !           335: {
        !           336:     if (initialized)
        !           337:        return;
        !           338:     initialized = TRUE;
        !           339: 
        !           340:     nameListContext  = XUniqueContext();
        !           341:     classListContext = XUniqueContext();
        !           342: 
        !           343:     Qname = XrmAtomToName(XtNname);
        !           344:     QreverseVideo = XrmAtomToName(XtNreverseVideo);
        !           345:     QBoolean = XrmAtomToClass(XtCBoolean);
        !           346:     QString = XrmAtomToClass(XtCString);
        !           347: }

unix.superglobalmegacorp.com

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