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

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

unix.superglobalmegacorp.com

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