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

1.1     ! root        1: #ifndef lint
        !             2: static char rcsid[] = "$Header: Initialize.c,v 1.44 87/09/13 22:55:11 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: /* Make sure all wm properties can make it out of the resource manager */
        !            28: 
        !            29: #include <stdio.h>
        !            30: #include <pwd.h>
        !            31: #include <sys/param.h>
        !            32: 
        !            33:  /* Xlib definitions  */
        !            34:  /* things like Window, Display, XEvent are defined herein */
        !            35: #include "Intrinsic.h"
        !            36: #include <X11/Xutil.h>
        !            37: #include "Atoms.h"
        !            38: #include "TopLevel.h"
        !            39: 
        !            40: extern char *index();
        !            41: extern char *strcat();
        !            42: extern char *strncpy();
        !            43: extern char *strcpy();
        !            44: 
        !            45: /*
        !            46:  This is a set of default records describing the command line arguments that
        !            47:  Xlib will parse and set into the resource data base.
        !            48:  
        !            49:  This list is applied before the users list to enforce these defaults.  This is
        !            50:  policy, which the toolkit avoids but I hate differing programs at this level.
        !            51: */
        !            52: 
        !            53: static XrmOptionDescRec opTable[] = {
        !            54: {"=",          XtNgeometry,    XrmoptionIsArg,         (caddr_t) NULL},
        !            55: {"-bd",                XtNborder,      XrmoptionSepArg,        (caddr_t) NULL},
        !            56: {"-bordercolor",XtNborder,     XrmoptionSepArg,        (caddr_t) NULL},
        !            57: {"-bg",                XtNbackground,  XrmoptionSepArg,        (caddr_t) NULL},
        !            58: {"-background",        XtNbackground,  XrmoptionSepArg,        (caddr_t) NULL},
        !            59: {"-bw",                XtNborderWidth, XrmoptionSepArg,        (caddr_t) NULL},
        !            60: {"-border",    XtNborderWidth, XrmoptionSepArg,        (caddr_t) NULL},
        !            61: {"-fg",                XtNforeground,  XrmoptionSepArg,        (caddr_t) NULL},
        !            62: {"-foreground",        XtNforeground,  XrmoptionSepArg,        (caddr_t) NULL},
        !            63: {"-fn",                XtNfont,        XrmoptionSepArg,        (caddr_t) NULL},
        !            64: {"-font",      XtNfont,        XrmoptionSepArg,        (caddr_t) NULL},
        !            65: {"-rv",                XtNreverseVideo, XrmoptionNoArg,        (caddr_t) "on"},
        !            66: {"-reverse",   XtNreverseVideo, XrmoptionNoArg,        (caddr_t) "on"},
        !            67: {"+rv",                XtNreverseVideo, XrmoptionNoArg,        (caddr_t) "off"},
        !            68: {"-n",         XtNname,        XrmoptionSepArg,        (caddr_t) NULL},
        !            69: {"-name",      XtNname,        XrmoptionSepArg,        (caddr_t) NULL},
        !            70: {"-title",     XtNtitle,       XrmoptionSepArg,        (caddr_t) NULL},
        !            71: {"-t",         XtNtitle,       XrmoptionSepArg,        (caddr_t) NULL}
        !            72: };
        !            73: 
        !            74: typedef struct {
        !            75:        int         argc;
        !            76:        char      **argv;
        !            77:        char       *classname;
        !            78:        char       *icon_name;
        !            79:        char       *title;
        !            80:        Pixmap      icon_pixmap;
        !            81:        Window      icon_window;
        !            82:        Boolean     iconic;
        !            83:        Boolean     input;
        !            84:        Boolean     resizeable;
        !            85:        char       *geostr;
        !            86:        int         initial;
        !            87:        XSizeHints  hints;
        !            88: } TopLevelPart;
        !            89: 
        !            90: /****************************************************************
        !            91:  *
        !            92:  * Full instance record declaration
        !            93:  *
        !            94:  ****************************************************************/
        !            95: 
        !            96: typedef  struct {
        !            97:        CorePart        core;
        !            98:        CompositePart   composite;
        !            99:        TopLevelPart    top;
        !           100: } TopLevelRec, *TopLevelWidget;
        !           101: 
        !           102: static XtResource resources[]=
        !           103: {
        !           104:        { XtNiconName, XtCIconPixmap, XrmRString, sizeof(caddr_t),
        !           105:            XtOffset(TopLevelWidget, top.icon_name), XrmRString, (caddr_t) NULL},
        !           106:        { XtNiconPixmap, XtCIconPixmap, XrmRPixmap, sizeof(caddr_t),
        !           107:            XtOffset(TopLevelWidget, top.icon_pixmap), XrmRPixmap, 
        !           108:            (caddr_t) NULL},
        !           109:        { XtNiconWindow, XtCIconWindow, XrmRWindow, sizeof(caddr_t),
        !           110:            XtOffset(TopLevelWidget, top.icon_window), XrmRWindow, 
        !           111:            (caddr_t) NULL},
        !           112:        { XtNallowtopresize, XtCAllowtopresize, XrmRBoolean, sizeof(Boolean),
        !           113:            XtOffset(TopLevelWidget, top.resizeable), XrmRString, "FALSE"},
        !           114:        { XtNgeometry, XtCGeometry, XrmRString, sizeof(caddr_t), 
        !           115:            XtOffset(TopLevelWidget, top.geostr), XrmRString, (caddr_t) NULL},
        !           116:        { XtNinput, XtCInput, XrmRBoolean, sizeof(Boolean),
        !           117:            XtOffset(TopLevelWidget, top.input), XrmRString, "FALSE"},
        !           118:        { XtNiconic, XtCIconic, XrmRBoolean, sizeof(Boolean),
        !           119:            XtOffset(TopLevelWidget, top.iconic), XrmRBoolean, "FALSE"},
        !           120:        { XtNtitle, XtCTitle, XrmRString, sizeof(char *),
        !           121:            XtOffset(TopLevelWidget, top.title), XrmRString, NULL},
        !           122: /*     { XtNinitial, XtCInitial, XrmRInitialstate, sizeof(int),
        !           123:            XtOffset(TopLevelWidget, top.initial), XrmRString, "Normal"} */
        !           124:        { XtNinitial, XtCInitial, XrmRInt, sizeof(int),
        !           125:            XtOffset(TopLevelWidget, top.initial), XrmRString, "0"}
        !           126:                        /* ||| Temp hack to provide initialization. */
        !           127: };
        !           128: static void Initialize();
        !           129: static void Realize();
        !           130: static Boolean SetValues();
        !           131: static void Destroy();
        !           132: static void InsertChild();
        !           133: static void ChangeManaged(); /* XXX */
        !           134: static XtGeometryResult GeometryManager();
        !           135: static void EventHandler();
        !           136: static void ClassInitialize();
        !           137: 
        !           138: typedef struct _TopLevelClassRec {
        !           139:        CoreClassPart      core_class;
        !           140:        CompositeClassPart composite_class;
        !           141: } TopLevelClassRec;
        !           142: 
        !           143: 
        !           144: TopLevelClassRec topLevelClassRec = {
        !           145:     /* superclass         */    (WidgetClass) &compositeClassRec,
        !           146:     /* class_name         */    "No Name",
        !           147:                                /* toplevel doesn't have a name it is pass
        !           148:                                         * to XtInitialize
        !           149:                                 */
        !           150:     /* size               */    sizeof(TopLevelRec),
        !           151:     /* Class Initializer  */   ClassInitialize,
        !           152:     /* Class init'ed ?    */   FALSE,
        !           153:     /* initialize         */    Initialize,
        !           154:     /* realize            */    Realize,
        !           155:     /* actions            */    NULL,
        !           156:     /* num_actions        */    0,
        !           157:     /* resources          */    resources,
        !           158:     /* resource_count     */   XtNumber(resources),
        !           159:     /* xrm_class          */    NULLQUARK,
        !           160:     /* compress_motion    */    FALSE,
        !           161:     /* compress_exposure  */    TRUE,
        !           162:     /* visible_interest   */    FALSE,
        !           163:     /* destroy            */    Destroy,
        !           164:     /* resize             */    NULL,
        !           165:     /* expose             */    NULL,
        !           166:     /* set_values         */    SetValues,
        !           167:     /* accept_focus       */    NULL,
        !           168:     /* geometry_manager   */    GeometryManager,
        !           169:     /* change_managed     */    ChangeManaged,
        !           170:     /* insert_child      */    InsertChild,
        !           171:     /* delete_child      */    NULL,         /* ||| Inherit from Composite */
        !           172:     /* move_focus_to_next */    NULL,
        !           173:     /* move_focus_to_prev */    NULL
        !           174: };
        !           175: 
        !           176: WidgetClass topLevelWidgetClass = (WidgetClass) (&topLevelClassRec);
        !           177: 
        !           178: /****************************************************************
        !           179:  *
        !           180:  * Private Procedures
        !           181:  *
        !           182:  ****************************************************************/
        !           183: 
        !           184: /* this is the old initialize routine */
        !           185: /* This needs to be updated to reflect the new world. */
        !           186: static void
        !           187: DO_Initialize() {
        !           188: 
        !           189: extern void QuarkInitialize();
        !           190: extern void ResourceListInitialize();
        !           191: extern void EventInitialize();
        !           192: extern void TranslateInitialize();
        !           193: extern void CursorsInitialize();
        !           194: 
        !           195:     /* Resource management initialization */
        !           196:     QuarkInitialize();
        !           197:     XrmInitialize();
        !           198:     ResourceListInitialize();
        !           199: 
        !           200:     /* Other intrinsic intialization */
        !           201:     EventInitialize();
        !           202:     TranslateInitialize();
        !           203:     CursorsInitialize();
        !           204:     InitializeCallbackTable();
        !           205: 
        !           206: 
        !           207: }
        !           208: Atom XtHasInput;
        !           209: Atom XtTimerExpired;
        !           210: 
        !           211: static void
        !           212: init_atoms(dpy)
        !           213: Display *dpy;
        !           214: {
        !           215:        XtHasInput = XInternAtom(dpy, "XtHasInput", False);
        !           216:        XtTimerExpired = XInternAtom(dpy, "XtTimerExpired", False);
        !           217: }
        !           218: 
        !           219: 
        !           220: static void ClassInitialize()
        !           221: {
        !           222:     CompositeWidgetClass superclass;
        !           223:     TopLevelWidgetClass myclass;
        !           224: 
        !           225:     myclass = (TopLevelWidgetClass) topLevelWidgetClass;
        !           226:     superclass = (CompositeWidgetClass) myclass->core_class.superclass;
        !           227: 
        !           228:     /* Inherit  delete_child from Composite */
        !           229:     /* I have a insert_child that calls my parents superclasses insert_child */
        !           230:     /* I can't inherit this one because of the implied add that Joel wants */
        !           231: 
        !           232:     myclass->composite_class.delete_child =
        !           233:         superclass->composite_class.delete_child;
        !           234: }
        !           235: 
        !           236: /*
        !           237:     What this routine does load the resource data base.
        !           238: 
        !           239:     The order that things are loaded into the database follows,
        !           240:     1) an optional application specific file.
        !           241:     2) server defaults, generic.
        !           242:     3) server defaults for machine.
        !           243:     4) .Xdefaults
        !           244: 
        !           245:  */
        !           246: 
        !           247: static XrmResourceDataBase
        !           248: XGetUsersDataBase(dpy, name)
        !           249: Display *dpy;
        !           250: char *name;
        !           251: {
        !           252:        XrmResourceDataBase userResources = NULL;
        !           253:        XrmResourceDataBase resources = NULL;
        !           254:        int uid;
        !           255:        extern struct passwd *getpwuid();
        !           256:        struct passwd *pw;
        !           257:        char filename[1024];
        !           258:        FILE *f;
        !           259:        static Boolean first = TRUE;
        !           260:        
        !           261:        if(name != NULL) { /* application provided a file */
        !           262:                f = fopen(name, "r");
        !           263:                if (f) {
        !           264:                        XrmGetCurrentDataBase(&resources);
        !           265:                        XrmGetDataBase(f, &userResources);
        !           266:                        XrmMergeDataBases(userResources, &resources);
        !           267:                        XrmSetCurrentDataBase(userResources);
        !           268:                        (void) fclose(f);
        !           269:                }
        !           270:        } 
        !           271:        if (first) {
        !           272:                first = FALSE;
        !           273:                /*
        !           274:                  MERGE server defaults
        !           275:                 */
        !           276:        /* Open .Xdefaults file and merge into existing data base */
        !           277:        
        !           278:                uid = getuid();
        !           279:                pw = getpwuid(uid);
        !           280:                if (pw) {
        !           281:                        (void) strcpy(filename, pw->pw_dir);
        !           282:                        (void) strcat(filename, "/.Xdefaults");
        !           283:                        f = fopen(filename, "r");
        !           284:                        if (f) {
        !           285:                                XrmGetCurrentDataBase(&resources);
        !           286:                                XrmGetDataBase(f, &userResources);
        !           287:                                XrmMergeDataBases(userResources, &resources);
        !           288:                                XrmSetCurrentDataBase(userResources);
        !           289:                                (void) fclose(f);
        !           290:                        }
        !           291:                }
        !           292:        }
        !           293:     return userResources;
        !           294: }
        !           295: 
        !           296: static void
        !           297: Initialize(request, new) 
        !           298: Widget request, new;
        !           299: {
        !           300:        TopLevelWidget w = (TopLevelWidget) new;
        !           301:        
        !           302:        int flag;
        !           303: 
        !           304:        if(w->top.icon_name == NULL) {
        !           305:                w->top.icon_name = w->core.name;
        !           306:        }
        !           307:        if(w->top.title == NULL) {
        !           308:                w->top.title = w->top.icon_name;
        !           309:        }
        !           310:        w->top.hints.flags = 0;
        !           311:        w->core.background_pixmap = None;
        !           312: /*
        !           313:        w->core.border_width = 0;
        !           314:        w->core.border_pixmap = NULL;
        !           315: */
        !           316:        if(w->top.geostr != NULL) {
        !           317:                flag = XParseGeometry(w->top.geostr, &w->core.x, &w->core.y,
        !           318:                               &w->core.width, &w->core.height);
        !           319:                
        !           320:                w->top.hints.flags |= USPosition | USSize;
        !           321:                if(flag & XNegative) 
        !           322:                        w->core.x =
        !           323:                          w->core.screen->width - w->core.width - w->core.x;
        !           324:                if(flag & YNegative) 
        !           325:                        w->core.y = 
        !           326:                         w->core.screen->height - w->core.height - w->core.y;
        !           327:        }
        !           328: 
        !           329:        XtAddEventHandler(
        !           330:            new, (EventMask) StructureNotifyMask,
        !           331:            FALSE, EventHandler, (Opaque) NULL);
        !           332: }
        !           333: 
        !           334: static void
        !           335: Realize(wid, mask, attr)
        !           336: Widget wid;
        !           337: Mask mask;
        !           338: XSetWindowAttributes *attr;
        !           339: {
        !           340:        TopLevelWidget w = (TopLevelWidget) wid;
        !           341:        Window win;
        !           342:        Display *dpy = XtDisplay(w);
        !           343: /*
        !           344:        char hostname[1024];
        !           345: */
        !           346:        XWMHints wmhints;
        !           347:        
        !           348: 
        !           349:        mask &= ~(CWBackPixel);
        !           350:        mask |= CWBackPixmap;
        !           351:        attr->background_pixmap = None; /* I must have a background pixmap of
        !           352:                                           none, and no background pixel. 
        !           353:                                           This should give me a transparent
        !           354:                                           background so that if there is
        !           355:                                           latency from when I get resized and
        !           356:                                           when my child is resized it won't be
        !           357:                                           as obvious.
        !           358:                                           */
        !           359:        win = w->core.window = XCreateWindow( dpy,
        !           360:            w->core.screen->root, w->core.x, w->core.y,
        !           361:            w->core.width, w->core.height,
        !           362:            w->core.border_width, w->core.depth, CopyFromParent,
        !           363:            CopyFromParent, mask, attr);
        !           364: 
        !           365:        XStoreName(dpy, win, w->top.title);
        !           366:        XSetIconName(dpy, win, w->top.icon_name);
        !           367:        XSetCommand(dpy, win, w->top.argv, w->top.argc);
        !           368: #ifdef UNIX
        !           369:        gethostname(hostname, sizeof(hostname));
        !           370: #endif
        !           371: 
        !           372: /* now hide everything needed to set the properties until realize is called */
        !           373:        wmhints.flags = 0;
        !           374:        wmhints.flags |= InputHint ;
        !           375:        if(w->top.input)
        !           376:          wmhints.input = TRUE;
        !           377:        else
        !           378:          wmhints.input = FALSE;
        !           379: 
        !           380:        /* Should I tell the window manager to bring me up iconfied */
        !           381:        wmhints.initial_state = w->top.initial;
        !           382:        if(w->top.iconic)
        !           383:          wmhints.initial_state = IconicState;
        !           384:        if(w->top.icon_pixmap != NULL) {
        !           385:                wmhints.flags |=  IconPixmapHint;
        !           386:                wmhints.icon_pixmap = w->top.icon_pixmap;
        !           387:        }
        !           388:        if(w->top.icon_window != NULL) {
        !           389:                wmhints.flags |=  IconWindowHint;
        !           390:                wmhints.icon_window = w->top.icon_window;
        !           391:        }
        !           392:        XSetWMHints(dpy, win, &wmhints);
        !           393: /* |||
        !           394:        XSetHostName(dpy, win, hostname);
        !           395:        XSetClass(dpy, win, w->top.classname);/* And w->core.name XXX*/
        !           396: 
        !           397:        w->top.hints.x = w->core.x;
        !           398:        w->top.hints.y = w->core.y;
        !           399:        w->top.hints.width = w->core.width;
        !           400:        w->top.hints.height = w->core.height;
        !           401:        XSetNormalHints(dpy, win, &w->top.hints);
        !           402: }
        !           403: 
        !           404: /* ARGSUSED */
        !           405: static void
        !           406: EventHandler(wid, closure, event)
        !           407: Widget wid;
        !           408: Opaque closure;
        !           409: XEvent *event;
        !           410: {
        !           411:        Widget childwid;
        !           412:        int i;
        !           413:        TopLevelWidget w = (TopLevelWidget) wid;
        !           414: 
        !           415:        if(w->core.window != event->xany.window) {
        !           416:                XtError("Event with wrong window");
        !           417:                  return;
        !           418:        }
        !           419:        /* I am only interested in resize */
        !           420:        switch(event->type) {
        !           421:              case ConfigureNotify:
        !           422:                w->core.width = event->xconfigure.width;
        !           423:                w->core.height = event->xconfigure.height;
        !           424:                w->core.border_width = event->xconfigure.border_width;
        !           425:                w->core.x = event->xconfigure.x;
        !           426:                w->core.y = event->xconfigure.y;
        !           427: 
        !           428:                for(i = 0; i < w->composite.num_children; i++) {
        !           429:                    if(w->composite.children[i]->core.managed) {
        !           430:                          childwid = w->composite.children[i];
        !           431:                          XtResizeWidget(
        !           432:                              childwid,
        !           433:                              w->core.width,
        !           434:                              w->core.height,
        !           435:                              w->core.border_width);
        !           436:                          break;
        !           437:                    }
        !           438:                }
        !           439:                break;
        !           440:              default:
        !           441:                return;
        !           442:        }  
        !           443: }
        !           444: 
        !           445: static void
        !           446: Destroy(wid)
        !           447: Widget wid;
        !           448: {
        !           449:        TopLevelWidget w = (TopLevelWidget) wid;
        !           450: 
        !           451:        if(w->top.argv != NULL)
        !           452:                XtFree((char *)w->top.argv);
        !           453:        w->top.argv = NULL;
        !           454:        if(w->top.classname != NULL)
        !           455:                XtFree(w->top.classname);
        !           456: }
        !           457: 
        !           458: /* ARGSUSED */
        !           459: static void InsertChild(w, args, num_args)
        !           460:     Widget w;
        !           461:     ArgList args;
        !           462:     Cardinal num_args;
        !           463: {
        !           464:     ((CompositeWidgetClass) XtSuperclass(w->core.parent))
        !           465:        ->composite_class.insert_child(w, args, num_args);
        !           466:     XtManageChild(w);  /* Add to managed set now */
        !           467: }
        !           468: 
        !           469: /*
        !           470:  * There is some real ugliness here.  If I have a width and a height which are
        !           471:  * zero, and as such suspect, and I have not yet been realized then I will 
        !           472:  * grow to match my child.
        !           473:  *
        !           474:  */
        !           475: static void 
        !           476: ChangeManaged(wid)
        !           477: CompositeWidget wid;
        !           478: {
        !           479:     TopLevelWidget w = (TopLevelWidget) wid;
        !           480:     int     i;
        !           481:     Widget childwid;
        !           482: 
        !           483:     for (i = 0; i < w->composite.num_children; i++) {
        !           484:        if (w->composite.children[i]->core.managed) {
        !           485:            childwid = w->composite.children[i];
        !           486:            if (!XtIsRealized ((Widget) wid)) {
        !           487:                if (w->core.border_width == 0) {
        !           488:                    w->core.border_width = childwid->core.border_width;
        !           489:                } else {
        !           490:                    childwid->core.border_width = w->core.border_width;
        !           491:                }
        !           492:                if (w->core.width == 0
        !           493:                        && w->core.height == 0) {
        !           494:                    /* we inherit our child's attributes */
        !           495:                    w->core.width = childwid->core.width;
        !           496:                    w->core.height = childwid->core.height;
        !           497:                    w->top.hints.flags |= PSize;
        !           498:                } else {
        !           499:                    /* our child gets our attributes */
        !           500:                    XtResizeWidget (
        !           501:                        childwid,
        !           502:                        w->core.width,
        !           503:                        w->core.height,
        !           504:                        w->core.border_width);
        !           505:                }
        !           506:            }
        !           507:            if (childwid->core.x != -(w->core.border_width) ||
        !           508:                childwid->core.y != -(w->core.border_width)) {
        !           509:                XtMoveWidget (childwid,
        !           510:                              -(w->core.border_width),
        !           511:                              -(w->core.border_width));
        !           512:            }
        !           513:        }
        !           514:     }
        !           515: 
        !           516: }
        !           517: 
        !           518: /*
        !           519:  * This is gross, I can't wait to see if the change happened so I will ask
        !           520:  * the window manager to change my size and do the appropriate X work.
        !           521:  * I will then tell the requester that he can't.  Care must be taken because
        !           522:  * it is possible that some time in the future the request will be
        !           523:  * asynchronusly granted.
        !           524:  */
        !           525:  
        !           526: static XtGeometryResult
        !           527: GeometryManager( wid, request, reply )
        !           528: Widget wid;
        !           529: XtWidgetGeometry *request;
        !           530: XtWidgetGeometry *reply;
        !           531: {
        !           532:        XWindowChanges values;
        !           533:        XSizeHints      oldhints;
        !           534:        TopLevelWidget w = (TopLevelWidget)(wid->core.parent);
        !           535: 
        !           536:        if(w->top.resizeable == FALSE)
        !           537:                return(XtGeometryNo);
        !           538:        if(!XtIsRealized((Widget)w)){
        !           539:                if (request->request_mode & (CWX|CWY)) {
        !           540:                        if(request->request_mode & (CWX|CWY) == 
        !           541:                           request->request_mode) {
        !           542:                                return(XtGeometryNo);
        !           543:                        } else {
        !           544:                                *reply = *request;
        !           545:                                reply->request_mode = request->request_mode &
        !           546:                                  ~(CWX|CWY);
        !           547:                                return(XtGeometryAlmost);
        !           548:                        }
        !           549:                }
        !           550:                *reply = *request;
        !           551:                if(request->request_mode & CWWidth)
        !           552:                   w->core.width = request->width;
        !           553:                if(request->request_mode & CWHeight) 
        !           554:                   w->core.height = request->height;
        !           555:                if(request->request_mode & CWBorderWidth)
        !           556:                   w->core.border_width = request->border_width;
        !           557:                return(XtGeometryYes);
        !           558:        }
        !           559:        values = *(XWindowChanges *) (&(request->x));
        !           560:        XGrabServer(XtDisplay(w));
        !           561:        XGetNormalHints(XtDisplay(w), w->core.window, &oldhints);
        !           562:         if(request->request_mode & CWWidth) {
        !           563:                 oldhints.flags &= ~USSize;
        !           564:                 oldhints.flags |= PSize;
        !           565:                 oldhints.width = request->width;
        !           566:         }
        !           567:         if(request->request_mode & CWHeight) {
        !           568:                 oldhints.flags &= ~USSize;
        !           569:                 oldhints.flags |= PSize;
        !           570:                 oldhints.height = request->height;
        !           571:         }
        !           572:         XSetNormalHints(XtDisplay(w), w->core.window, &oldhints);
        !           573: /* ||| this code depends on the core x,y,width,height,borderwidth fields */
        !           574: /* being the same size and same order as an XWindowChanges record. Yechh!!! */
        !           575:        XConfigureWindow(XtDisplay(w), w->core.window,
        !           576:                 request->request_mode, (XWindowChanges *)&(request->x));
        !           577:        XUngrabServer(XtDisplay(w));
        !           578:        return(XtGeometryNo);
        !           579: }
        !           580: 
        !           581: static Boolean SetValues (current, request, new, last)
        !           582: Widget current, request, new;
        !           583: Boolean last;
        !           584: {
        !           585:        XWMHints wmhints, *oldhints;
        !           586:        TopLevelWidget cur = (TopLevelWidget) current;
        !           587:         TopLevelWidget req = (TopLevelWidget) request;
        !           588:        TopLevelWidget tnew = (TopLevelWidget) new;
        !           589:        Boolean name = FALSE;
        !           590:        Boolean pixmap = FALSE;
        !           591:        Boolean window = FALSE;
        !           592:        Boolean title = FALSE;
        !           593:        
        !           594:         /* I don't let people play with most of my values */
        !           595:         tnew->top = cur->top;
        !           596: 
        !           597:         /* except these few.... */
        !           598:         
        !           599:        tnew-> top.resizeable =  req->top.resizeable;
        !           600:        if(req ->top.icon_name != cur->top.icon_name) {
        !           601:                tnew ->top.icon_name = req->top.icon_name;
        !           602:                name = TRUE;
        !           603:        }
        !           604: /*XXX Leak allert  These should be copied and freed but I am lazy */
        !           605:        if(req ->top.icon_pixmap != cur->top.icon_pixmap) {
        !           606:                tnew ->top.icon_pixmap = req->top.icon_pixmap;
        !           607:                pixmap = TRUE;
        !           608:        }
        !           609:        if(req ->top.icon_window != cur->top.icon_window) {
        !           610:                tnew ->top.icon_window = req->top.icon_window;
        !           611:                window = TRUE;
        !           612:        }
        !           613:        if(req ->top.title != cur->top.title) {
        !           614:                tnew ->top.title = req->top.title;
        !           615:                name = TRUE;
        !           616:        }
        !           617:        if((name || pixmap || window || title) && XtIsRealized((Widget)tnew)) {
        !           618:                if(name) {
        !           619:                        XSetIconName(XtDisplay(tnew), tnew->core.window, tnew->top.icon_name);
        !           620:                }
        !           621:                if( title ) {
        !           622:                        XStoreName(XtDisplay(tnew), tnew->core.window, tnew->top.title);
        !           623:                }
        !           624:                if(pixmap || window) {
        !           625:                        oldhints = XGetWMHints(XtDisplay(tnew), tnew->core.window);
        !           626:                        wmhints = *oldhints;
        !           627:                        XtFree((char *)oldhints);
        !           628:                        if(pixmap) {
        !           629:                                wmhints.flags |= IconPixmapHint;
        !           630:                                wmhints.icon_pixmap = tnew->top.icon_pixmap;
        !           631:                        }
        !           632:                        if(window) {
        !           633:                                wmhints.flags |= IconWindowHint;
        !           634:                                wmhints.icon_window = tnew->top.icon_window;
        !           635:                        }
        !           636:                        XSetWMHints( XtDisplay(tnew), tnew->core.window, &wmhints);
        !           637:                }
        !           638:        }
        !           639: 
        !           640: return (FALSE);  /* redisplay is never needed */
        !           641:        
        !           642: }
        !           643: 
        !           644: /*
        !           645:  * This routine creates the desired widget and does the "Right Thing" for
        !           646:  * the toolkit and for window managers.
        !           647:  */
        !           648: 
        !           649: Widget
        !           650: XtInitialize(name, classname, urlist, urlistCount, argc, argv)
        !           651: char *name;
        !           652: char *classname;
        !           653: XrmOptionDescRec *urlist;
        !           654: Cardinal urlistCount;
        !           655: Cardinal *argc;
        !           656: char *argv[];
        !           657: {
        !           658:        char  displayName[256];
        !           659: /*
        !           660:        char *displayName_ptr = displayName;
        !           661: */
        !           662:        Arg   args[8];
        !           663:        Cardinal num_args = 0;
        !           664:        int i;
        !           665: /*
        !           666:        int val;
        !           667:        int flags = 0;
        !           668: */
        !           669:        char filename[MAXPATHLEN];
        !           670:        char **saved_argv;
        !           671:        int    saved_argc = *argc;
        !           672:        Display *dpy;
        !           673:        char *ptr, *rindex();
        !           674:        TopLevelWidget w;
        !           675:        Widget root;
        !           676:        int squish = -1;
        !           677:        Boolean dosync = FALSE;
        !           678: 
        !           679: 
        !           680:        if( name == NULL) {
        !           681:                ptr = rindex(argv[0], '/');
        !           682:                if(ptr)
        !           683:                  name = ++ ptr;
        !           684:                else
        !           685:                  name = argv[0];
        !           686:        }
        !           687: 
        !           688:        /* save away argv and argc so I can set the properties latter */
        !           689: 
        !           690:        saved_argv = (char **) XtCalloc(
        !           691:            (unsigned) ((*argc) + 1) , (unsigned)sizeof(*saved_argv));
        !           692:        for (i = 0 ; i < *argc ; i++)
        !           693:          saved_argv[i] = argv[i];
        !           694:        saved_argv[i] = NULL;
        !           695:        /*
        !           696:           Find the display name and open it
        !           697:           While we are at it we look for name because that is needed 
        !           698:           soon after to do the arguement parsing.
        !           699:         */
        !           700:        displayName[0] = 0;
        !           701: 
        !           702:        for(i = 1; i < *argc; i++) {
        !           703:          if (index(argv[i], ':') != NULL) {
        !           704:                  (void) strncpy(displayName, argv[i], sizeof(displayName));
        !           705:                  if( *argc == i + 1) {
        !           706:                    (*argc)--;
        !           707:                  } else {  /* need to squish this one out of the list */
        !           708:                    squish = i;
        !           709:                  }
        !           710:                  continue;
        !           711:          }
        !           712:          if(!strcmp("-name", argv[i]) || ! strcmp("-n", argv[i])) {
        !           713:                  i++;
        !           714:                  if(i == *argc) break;
        !           715:                  name = argv[i];
        !           716:                  continue;
        !           717:          }
        !           718:          if (!strcmp("-sync", argv[i])) {
        !           719:                  dosync = TRUE;
        !           720:                  continue;
        !           721:          }
        !           722:        }
        !           723:        if(squish != -1) {
        !           724:                (*argc)--;
        !           725:                for(i = squish; i < *argc; i++) {
        !           726:                        argv[i] = argv[i+1];
        !           727:                }
        !           728:        }
        !           729:        /* Open display  */
        !           730:        if (!(dpy = XOpenDisplay(displayName))) {
        !           731:                char buf[1024];
        !           732:                (void) strcpy(buf, "Can't Open display: ");
        !           733:                (void) strcat(buf, displayName);
        !           734:                XtError(buf);
        !           735:        }
        !           736:         toplevelDisplay = dpy;
        !           737:        if (dosync) XSynchronize(dpy, TRUE);
        !           738: 
        !           739:         XtSetArg(args[num_args], "display", dpy);
        !           740:         num_args++;
        !           741:         XtSetArg(args[num_args], "screen", dpy->default_screen);
        !           742:         num_args++;
        !           743:            
        !           744:        /* initialize the toolkit */
        !           745:        DO_Initialize();
        !           746: #define UNIX
        !           747: #ifdef UNIX
        !           748: #define XAPPLOADDIR  "/usr/lib/Xapps/"
        !           749: #endif 
        !           750:        (void) strcpy(filename, XAPPLOADDIR);
        !           751:        (void) strcat(filename, classname);
        !           752: 
        !           753: 
        !           754:        /*set up resource database */
        !           755:        XGetUsersDataBase(dpy, filename);
        !           756: 
        !           757:        /*
        !           758:           This routine parses the command line arguments and removes them from
        !           759:           argv.
        !           760:         */
        !           761:        XrmParseCommand( opTable, XtNumber(opTable), name, argc, argv);
        !           762:        
        !           763:        if(urlistCount >0) {
        !           764:                /* the application has some more defaults */
        !           765:                XrmParseCommand( urlist, urlistCount, name, argc, argv);
        !           766:        }
        !           767:        /* Resources are initialize and loaded */
        !           768:        /* I now must handle geometry specs a compond resource */
        !           769: 
        !           770:        /*
        !           771:             Create the top level widget.
        !           772:             Unlike most classes the toplevel widget class has no classname
        !           773:             The name is supplied in the call to XtInitialize.
        !           774:         */
        !           775:        (void) strcpy(
        !           776:            ((TopLevelClassRec *)(topLevelWidgetClass))->core_class.class_name
        !           777:                = (String)XtMalloc((unsigned)strlen(classname)+1),
        !           778:               classname);
        !           779:        root = TopLevelCreate(name, topLevelWidgetClass,
        !           780:                              &(dpy->screens[dpy->default_screen]),
        !           781:                               args, num_args);
        !           782: 
        !           783:        w = (TopLevelWidget) root;
        !           784:        w->top.argc = saved_argc;
        !           785:        w->top.argv = saved_argv;
        !           786:        (void) strcpy(w->top.classname = (char *)XtMalloc((unsigned)strlen(classname)+1)
        !           787:               ,classname);
        !           788: 
        !           789:        init_atoms(dpy);
        !           790: 
        !           791:        return(root);
        !           792: }
        !           793: 

unix.superglobalmegacorp.com

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