Annotation of 43BSDTahoe/new/X/Xlib/XCreate.c, revision 1.1

1.1     ! root        1: #include <X/mit-copyright.h>
        !             2: 
        !             3: /* $Header: XCreate.c,v 10.10 86/08/11 12:55:45 wesommer Rel $ */
        !             4: /* Copyright 1985, Massachusetts Institute of Technology */
        !             5: /* stolen from CLU routine x_cons, redone by J. Gettys */
        !             6: 
        !             7: #include "XlibInternal.h"
        !             8: #include <stdio.h>
        !             9: #define TRUE  1
        !            10: #define FALSE 0
        !            11: #define max(a,b) ( (a) > (b) ? (a) : (b) )
        !            12: #define min(a,b) ( (a) > (b) ? (b) : (a) )
        !            13: #define abs(a) ( (a) > 0 ? (a) : -(a))
        !            14: 
        !            15: #define DCOUNT 2
        !            16: #define VCOUNT 1 + (4  * 2 * DCOUNT)
        !            17: #define FCOUNT 1 + 4
        !            18: 
        !            19: #define CURSOR_LL 0
        !            20: #include "../cursors/ll_angle.cursor"
        !            21: #include "../cursors/ll_angle_mask.cursor"
        !            22: #define CURSOR_LR 1
        !            23: #include "../cursors/lr_angle.cursor"
        !            24: #include "../cursors/lr_angle_mask.cursor"
        !            25: #define CURSOR_UL 2
        !            26: #include "../cursors/ul_angle.cursor"
        !            27: #include "../cursors/ul_angle_mask.cursor"
        !            28: #define CURSOR_UR 3
        !            29: #include "../cursors/ur_angle.cursor"
        !            30: #include "../cursors/ur_angle_mask.cursor"
        !            31: 
        !            32: 
        !            33: Window XCreate(prompt, name, geometry, def, frame, minwidth, minheight)
        !            34:        char *prompt, *name;
        !            35:        register OpaqueFrame *frame;
        !            36:        int minwidth, minheight;
        !            37:        char *geometry, *def;
        !            38:        {
        !            39:        char *fn = "8x13";              /* default default font */
        !            40:        FontInfo *pfninfo;              /* font info on prompt */
        !            41:        Window pop;                     /* pop up window */
        !            42:        char *opt;
        !            43:        int pfore, pback;               /* prompt window colors */
        !            44:        int bpix;                       /* border color */
        !            45:        int mfore, mback;               /* mouse colors */
        !            46:        int pbw = 1;                    /* prompt window border width */
        !            47:        int ibw = 1;                    /* internal border width */
        !            48:        int freeze = 0;                 /* should we freeze the server */
        !            49:        Color cdef;                     /* color structure for lookup */
        !            50:        Cursor ur,ul,lr,ll;             /* cursors for rubber banding    */
        !            51:        int events;                     /* event mask */
        !            52:        int popw, poph;                 /* prompt window height and width */
        !            53:        int count = VCOUNT;             /* vertex count */
        !            54:        Pixmap save = 0;                /* saved pixmap */
        !            55:        Pixmap backmap, bdrmap;         /* background and border pixmaps */
        !            56:        Vertex box[VCOUNT];             /* vertex list for box */
        !            57:        int x1, y1;                     /* location of mouse */
        !            58:        int x2, y2;                     /* other corner of box */
        !            59:        Window subw;                    /* subwindow it is in */
        !            60:        int mindim;                     /* minimum dimension */
        !            61:        int width, height;              /* width and height of box */
        !            62:        int left, stop;
        !            63:        int mouse;
        !            64:        int force;                      /* force default window to track */
        !            65:        int xa, ya, xb, yb;
        !            66:        int doit;
        !            67:        XButtonEvent event;             /* someplace to put the event */
        !            68:        register int i;                 /* ye olde indexe variabel */
        !            69:        int fx, fy, fw, fh;             /* frame from parse... */
        !            70:        int pr;                         /* parse geometry result */
        !            71:        int change_cursor = FALSE;
        !            72:        int current_cursor = CURSOR_UL;
        !            73: 
        !            74:        int HereButton = LeftButton;    /* make window at locator */
        !            75:        int ResizeButton = MiddleButton;/* make window of specified size */
        !            76:        int DefaultButton = RightButton;/* make window at default location */
        !            77: 
        !            78:        pr = XGeometry (geometry, def, frame->bdrwidth, 1, 1, 0, 0,
        !            79:                &fx, &fy, &fw, &fh);
        !            80:        /*
        !            81:         * none of this nonsense would be necessary if I hadn't blown
        !            82:         * the frame structure definition.
        !            83:         */
        !            84:        frame->x = fx;
        !            85:        frame->y = fy;
        !            86:        frame->width = fw;
        !            87:        frame->height = fh;
        !            88:        if (geometry != NULL) {
        !            89:                /*
        !            90:                 * if x or y offsets are specified, then we should autoplace
        !            91:                 */
        !            92:                if ( (pr & XValue ) || (pr & YValue) ) {
        !            93:                    if (frame->width < minwidth) frame->width = minwidth;
        !            94:                    if (frame->height < minheight) frame->height = minheight;
        !            95:                    goto makeit;
        !            96:                }
        !            97:        }
        !            98: 
        !            99:        if ((opt = XGetDefault(name, "MakeWindow.BodyFont")) != NULL) fn = opt;
        !           100: 
        !           101:        if ((pfninfo = XOpenFont(fn)) == NULL) {
        !           102:                fprintf(stderr, "Can't open font %s!\n", fn);
        !           103:                return(0);
        !           104:                }
        !           105: 
        !           106:        pfore = mback = WhitePixel;
        !           107:        pback = bpix = mfore = BlackPixel;
        !           108:        if ((opt = XGetDefault(name, "MakeWindow.ReverseVideo")) != NULL)
        !           109:                if (strcmp (opt, "on") == 0) {
        !           110:                        pfore = BlackPixel;
        !           111:                        pback = WhitePixel;
        !           112:                        }
        !           113: 
        !           114:        if ((opt = XGetDefault(name, "MakeWindow.BorderWidth")) != NULL)
        !           115:                pbw = atoi (opt);
        !           116: 
        !           117:        if ((opt = XGetDefault(name, "MakeWindow.InternalBorder")) != NULL)
        !           118:                ibw = atoi (opt);
        !           119: 
        !           120:        if ((opt = XGetDefault(name, "MakeWindow.Freeze")) != NULL)
        !           121:                if (strcmp (opt, "on") == 0) freeze = 1;
        !           122: 
        !           123:        if (DisplayPlanes() > 2) { /* on color display, do color stuff */
        !           124:        
        !           125:                if ((opt = XGetDefault(name,"MakeWindow.Foreground")) != NULL)
        !           126:                    if (XParseColor(opt, &cdef) && XGetHardwareColor(&cdef))
        !           127:                        pfore = cdef.pixel;
        !           128: 
        !           129:                if ((opt = XGetDefault(name,"MakeWindow.Background")) != NULL)
        !           130:                    if (XParseColor(opt, &cdef) && XGetHardwareColor(&cdef))
        !           131:                        pback = cdef.pixel;
        !           132: 
        !           133:                if ((opt = XGetDefault(name,"MakeWindow.Border")) != NULL)
        !           134:                    if (XParseColor(opt, &cdef) && XGetHardwareColor(&cdef))
        !           135:                        bpix = cdef.pixel;
        !           136: 
        !           137:                if ((opt = XGetDefault(name,"MakeWindow.Mouse")) != NULL)
        !           138:                    if (XParseColor(opt, &cdef) && XGetHardwareColor(&cdef))
        !           139:                        mfore = cdef.pixel;
        !           140: 
        !           141:                if ((opt = XGetDefault(name,"MakeWindow.MouseMask")) != NULL)
        !           142:                    if (XParseColor(opt, &cdef) && XGetHardwareColor(&cdef))
        !           143:                        mback = cdef.pixel;
        !           144: 
        !           145:                        }
        !           146: 
        !           147:        if ((opt = XGetDefault(name, "MakeWindow.Here")) != NULL) {
        !           148:                switch (*opt) {
        !           149:                case 'L':
        !           150:                case 'l':
        !           151:                        HereButton = LeftButton;
        !           152:                        break;
        !           153: 
        !           154:                case 'M':
        !           155:                case 'm':
        !           156:                        HereButton = MiddleButton;
        !           157:                        break;
        !           158: 
        !           159:                case 'R':
        !           160:                case 'r':
        !           161:                        HereButton = RightButton;
        !           162:                        break;
        !           163:                /*
        !           164:                 * Should have a default case, to check for invalid
        !           165:                 * specification, but what should be done in that case?
        !           166:                 */
        !           167:                }
        !           168:        }
        !           169: 
        !           170:        if ((opt = XGetDefault(name, "MakeWindow.Resize")) != NULL) {
        !           171:                switch (*opt) {
        !           172:                case 'L':
        !           173:                case 'l':
        !           174:                        ResizeButton = LeftButton;
        !           175:                        break;
        !           176: 
        !           177:                case 'M':
        !           178:                case 'm':
        !           179:                        ResizeButton = MiddleButton;
        !           180:                        break;
        !           181: 
        !           182:                case 'R':
        !           183:                case 'r':
        !           184:                        ResizeButton = RightButton;
        !           185:                        break;
        !           186:                /*
        !           187:                 * Should have a default case, to check for invalid
        !           188:                 * specification, but what should be done in that case?
        !           189:                 */
        !           190:                }
        !           191:        }
        !           192: 
        !           193:        if ((opt = XGetDefault(name, "MakeWindow.Default")) != NULL) {
        !           194:                switch (*opt) {
        !           195:                case 'L':
        !           196:                case 'l':
        !           197:                        DefaultButton = LeftButton;
        !           198:                        break;
        !           199: 
        !           200:                case 'M':
        !           201:                case 'm':
        !           202:                        DefaultButton = MiddleButton;
        !           203:                        break;
        !           204: 
        !           205:                case 'R':
        !           206:                case 'r':
        !           207:                        DefaultButton = RightButton;
        !           208:                        break;
        !           209:                /*
        !           210:                 * Should have a default case, to check for invalid
        !           211:                 * specification, but what should be done in that case?
        !           212:                 */
        !           213:                }
        !           214:        }
        !           215: 
        !           216:        /*
        !           217:         * Should verify that HereButton != ResizeButton != DefaultButton,
        !           218:         * but what should be done if that's false?
        !           219:         */
        !           220: 
        !           221:        ur = XCreateCursor (ur_angle_width, ur_angle_height, ur_angle_bits, 
        !           222:                ur_angle_mask_bits, ur_angle_x_hot, ur_angle_y_hot,
        !           223:                mfore, mback, GXcopy);
        !           224:        ul = XCreateCursor (ul_angle_width, ul_angle_height, ul_angle_bits, 
        !           225:                ul_angle_mask_bits, ul_angle_x_hot, ul_angle_y_hot,
        !           226:                mfore, mback, GXcopy);
        !           227:        ll = XCreateCursor (ll_angle_width, ll_angle_height, ll_angle_bits, 
        !           228:                ll_angle_mask_bits, ll_angle_x_hot, ll_angle_y_hot,
        !           229:                mfore, mback, GXcopy);
        !           230:        lr = XCreateCursor (lr_angle_width, lr_angle_height, lr_angle_bits, 
        !           231:                lr_angle_mask_bits, lr_angle_x_hot, lr_angle_y_hot,
        !           232:                mfore, mback, GXcopy);
        !           233: 
        !           234:        events = ButtonPressed | ButtonReleased;
        !           235: 
        !           236:        if (freeze) events |= MouseMoved;
        !           237: 
        !           238:        /* 
        !           239:         * go get the mouse as soon as you can 
        !           240:         */
        !           241: 
        !           242:        while (1) {
        !           243:                if (XGrabMouse ( RootWindow, ul, events ) != 0) break;
        !           244:                sleep (1);
        !           245:                }
        !           246:        popw = XStringWidth (prompt, pfninfo, 0, 0) + 2 * ibw;
        !           247:        poph = pfninfo->height + 2 * ibw;
        !           248: 
        !           249:        if (freeze) {
        !           250:                XGrabServer();
        !           251:                count = FCOUNT;
        !           252:                save = XPixmapSave (RootWindow, 0, 0, 
        !           253:                        popw + 2 * pbw, poph +2 * pbw);
        !           254:                }
        !           255: 
        !           256:        backmap = XMakeTile (pback);
        !           257:        bdrmap = XMakeTile (bpix);
        !           258: 
        !           259:        pop = XCreateWindow (RootWindow, 
        !           260:                0, 0, popw, poph, pbw, bdrmap, backmap);
        !           261:        XMapWindow( pop);
        !           262:        XText (pop, ibw, ibw, prompt, strlen(prompt), 
        !           263:                pfninfo->id, pfore, pback);
        !           264: 
        !           265:        XQueryMouse (RootWindow, &x1, &y1, &subw);
        !           266: 
        !           267:        mindim = 2 * frame->bdrwidth - 1;
        !           268:        minwidth  = minwidth  + mindim;
        !           269:        minheight = minheight + mindim;
        !           270: 
        !           271:        x2 = x1 + minwidth;
        !           272:        y2 = y1 + minheight;
        !           273: 
        !           274:        width  = minwidth;
        !           275:        height = minheight;
        !           276: 
        !           277:        left = TRUE;
        !           278:        force = FALSE;
        !           279:        stop = FALSE;
        !           280:        mouse = TRUE;
        !           281: 
        !           282:        xa = ya = xb = yb = -1;
        !           283: 
        !           284:        doit = TRUE;
        !           285: 
        !           286:        while (stop == FALSE) {
        !           287:            if (  (xb != max (x1, x2)) || (yb != max(y1, y2))
        !           288:                ||(xa != min (x1, x2)) || (ya != min(y1, y2))) {
        !           289:                if (freeze && (doit == FALSE)) {
        !           290:                        XDraw (RootWindow, box, count, 1, 1, 0, GXinvert, 1);
        !           291:                        }
        !           292:                xa = min (x1, x2);
        !           293:                ya = min (y1, y2);
        !           294:                xb = max (x1, x2);
        !           295:                yb = max (y1, y2);
        !           296:                for ( i = 0; i < count; i += 4) {
        !           297:                    box[i].x = xa; box[i].y = ya; box[i].flags = 0;
        !           298:                    if (i+1 == count) break;
        !           299:                    box[i+1].x = xb; box[i+1].y = ya, box[i+1].flags = 0;
        !           300:                    box[i+2].x = xb; box[i+2].y = yb, box[i+2].flags = 0;
        !           301:                    box[i+3].x = xa; box[i+3].y = yb, box[i+3].flags = 0;
        !           302:                    }
        !           303:                doit = TRUE;
        !           304:                }
        !           305:            if (doit) {
        !           306:                XDraw(RootWindow, box, count, 1, 1, 0, GXinvert, 1);
        !           307:                doit = !freeze;
        !           308:                }
        !           309:            if (freeze || XPending() ) {
        !           310:                register int button;
        !           311:                XNextEvent(&event);
        !           312:                button = event.detail & ValueMask;
        !           313:                if (mouse) {
        !           314:                        x2 = event.x;
        !           315:                        y2 = event.y;
        !           316:                        }
        !           317:                if ( (left == TRUE) && ( event.type == ButtonPressed ) && 
        !           318:                        ( button == ResizeButton ) ) {
        !           319:                        x1 = x2;
        !           320:                        y1 = y2;
        !           321:                        left = FALSE;
        !           322:                        change_cursor = TRUE;
        !           323:                        }
        !           324:                else if ( (left == FALSE) && (event.type == ButtonReleased) &&
        !           325:                        ( button == ResizeButton))
        !           326:                                        stop = TRUE;
        !           327:                else if ( (left == TRUE) && (event.type == ButtonPressed) &&
        !           328:                        ( button == DefaultButton)) {
        !           329:                        x1 = frame->x;
        !           330:                        y1 = frame->y;
        !           331:                        x2 = x1 + frame->width + mindim;
        !           332:                        y2 = y1 + frame->height + mindim;
        !           333:                        mouse = FALSE;
        !           334:                        left = FALSE;
        !           335:                        }
        !           336:                else if ( (left == FALSE) && (event.type == ButtonReleased) &&
        !           337:                        ( button == DefaultButton)) {
        !           338:                        x1 = frame->x;
        !           339:                        y1 = frame->y;
        !           340:                        x2 = x1 + frame->width + mindim;
        !           341:                        y2 = y1 + frame->height + mindim;
        !           342:                        stop = TRUE;
        !           343:                        }
        !           344:                else if ( (left == TRUE) && (event.type == ButtonPressed) &&
        !           345:                        ( button == HereButton)) {
        !           346:                        force = TRUE;
        !           347:                        left = FALSE;
        !           348:                        }
        !           349:                else if ( (left == FALSE) && (event.type == ButtonReleased) &&
        !           350:                        ( button == HereButton)) {
        !           351:                        stop = TRUE;
        !           352:                        }
        !           353:                else if (mouse) XQueryMouse (RootWindow, &x2, &y2, &subw);
        !           354:                }
        !           355:            else if (mouse) XQueryMouse (RootWindow, &x2, &y2, &subw);
        !           356:            if (change_cursor) {
        !           357:                if ((x2 >= x1) && (y2 >= y1) &&
        !           358:                    current_cursor != CURSOR_LR) {
        !           359:                    XGrabMouse ( RootWindow, lr, events );
        !           360:                    current_cursor = CURSOR_LR;
        !           361:                }
        !           362:                else if ((x2 >= x1) && (y2 < y1) &&
        !           363:                         current_cursor != CURSOR_UR) {
        !           364:                    XGrabMouse ( RootWindow, ur, events);
        !           365:                    current_cursor = CURSOR_UR;
        !           366:                }
        !           367:                else if ((x2 < x1) && (y2 >= y1) &&
        !           368:                         current_cursor != CURSOR_LL) {
        !           369:                    XGrabMouse ( RootWindow, ll, events);
        !           370:                    current_cursor = CURSOR_LL;
        !           371:                }
        !           372:                else if ((x2 < x1) && (y2 < y1) &&
        !           373:                         (current_cursor != CURSOR_UL)) {
        !           374:                    XGrabMouse ( RootWindow, ul, events);
        !           375:                    current_cursor = CURSOR_UL;
        !           376:                }
        !           377:            }
        !           378:            if (force) {        /* we force the default box */
        !           379:                x1 = x2;
        !           380:                y1 = y2;
        !           381:                x2 = x1 + frame->width + mindim;
        !           382:                y2 = y1 + frame->height + mindim;
        !           383:                }
        !           384: 
        !           385:            if (left) {
        !           386:                x1 = x2;
        !           387:                y1 = y2;
        !           388:                }
        !           389:            width = max (abs (x2 - x1), minwidth);
        !           390: 
        !           391:            if (x2 < x1) x2 = x1 - width;
        !           392:            else         x2 = x1 + width;
        !           393: 
        !           394:            height = max (abs (y2 - y1), minheight);
        !           395:            if (y2 < y1) y2 = y1 - height;
        !           396:            else         y2 = y1 + height;
        !           397:        }
        !           398:        if (freeze) XDraw (RootWindow, box, count, 1, 1, 0, GXinvert, 1);
        !           399:        XUngrabMouse();
        !           400: 
        !           401:        if (save != 0) {
        !           402:                XUnmapTransparent (pop);
        !           403:                XPixmapPut (RootWindow, 0, 0, 0, 0,
        !           404:                        popw + 2 * pbw, poph + 2 * pbw,
        !           405:                        save, GXcopy, AllPlanes);
        !           406:                XFreePixmap (save);
        !           407:                }
        !           408:        XDestroyWindow (pop);
        !           409:        if (freeze) XUngrabServer();
        !           410:        XCloseFont (pfninfo);
        !           411:        XFreeCursor (ur);
        !           412:        XFreeCursor (ul);
        !           413:        XFreeCursor (lr);
        !           414:        XFreeCursor (ll);
        !           415:        XFreePixmap (backmap);
        !           416:        XFreePixmap (bdrmap);
        !           417:        frame->x = min(x1, x2);
        !           418:        frame->y = min(y1, y2);
        !           419:        frame->width = width - mindim;
        !           420:        frame->height = height - mindim;
        !           421: makeit:        XCreateWindows(RootWindow, frame, 1);
        !           422:        /* store default name of the window and set the resize hint */
        !           423:        XStoreName(frame->self, prompt);
        !           424:        XSetResizeHint(frame->self, minwidth, minheight, 1, 1);
        !           425:        XSync(1);               /* get rid of any extraneous events */
        !           426:        return (frame->self);
        !           427:        }
        !           428: 

unix.superglobalmegacorp.com

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