Annotation of 43BSDTahoe/new/X/uwm/GetButton.c, revision 1.1

1.1     ! root        1: #ifndef lint
        !             2: static char *rcsid_GetButton_c = "$Header: GetButton.c,v 10.5 86/11/19 16:23:39 jg Rel $";
        !             3: #endif lint
        !             4: 
        !             5: /*
        !             6:  *                     COPYRIGHT 1985, 1986
        !             7:  *                DIGITAL EQUIPMENT CORPORATION
        !             8:  *                    MAYNARD, MASSACHUSETTS
        !             9:  *                     ALL RIGHTS RESERVED.
        !            10:  *
        !            11:  * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
        !            12:  * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
        !            13:  * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITIBILITY OF THIS SOFTWARE FOR
        !            14:  * ANY PURPOSE.  IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
        !            15:  *
        !            16:  * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT RIGHTS,
        !            17:  * APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN ADDITION TO THAT
        !            18:  * SET FORTH ABOVE.
        !            19:  *
        !            20:  *
        !            21:  * Permission to use, copy, modify, and distribute this software and its
        !            22:  * documentation for any purpose and without fee is hereby granted, provided
        !            23:  * that the above copyright notice appear in all copies and that both that
        !            24:  * copyright notice and this permission notice appear in supporting documentation,
        !            25:  * and that the name of Digital Equipment Corporation not be used in advertising
        !            26:  * or publicity pertaining to distribution of the software without specific, 
        !            27:  * written prior permission.
        !            28:  *
        !            29:  */
        !            30: 
        !            31: 
        !            32: /*
        !            33:  * MODIFICATION HISTORY
        !            34:  *
        !            35:  * 000 -- M. Gancarz, DEC Ultrix Engineering Group
        !            36:  */
        !            37: 
        !            38: #ifndef lint
        !            39: static char *sccsid = "@(#)GetButton.c 3.8     1/24/86";
        !            40: #endif
        !            41: /*
        !            42:  *     GetButton - This subroutine is used by the Ultrix Window Manager (uwm)
        !            43:  *     to acquire button events.  It waits for a button event to occur
        !            44:  *     and handles all event traffic in the interim.
        !            45:  *
        !            46:  *     File:           GetButton.c
        !            47:  */
        !            48: 
        !            49: #include "uwm.h"
        !            50: 
        !            51: Bool GetButton(button_event)
        !            52:     XButtonEvent *button_event;        /* Button event packet. */
        !            53: {
        !            54:     XKeyPressedEvent *kp_event;        /* Key pressed event. */
        !            55:     char *icon_str;            /* Icon's name string. */
        !            56:     register int icon_str_len; /* Icon name string lenght.  */
        !            57:     register int key_char;     /* Key press character code. */
        !            58:     register int icon_x;       /* Icon window X coordinate. */
        !            59:     register int icon_y;       /* Icon window Y coordinate. */
        !            60:     register int icon_w;       /* Icon window width. */
        !            61:     register int icon_h;       /* Icon window height. */    
        !            62:     int status;                        /* Routine call return status. */
        !            63:     Window icon;               /* Icon window. */
        !            64:     WindowInfo icon_info;      /* Icon window info structure. */
        !            65:     char *kbd_str;              /* Keyboard string. */
        !            66:     int nbytes;                 /* Keyboard string length. */
        !            67:     int i;                      /* Iteration counter. */
        !            68: 
        !            69: 
        !            70:     /*
        !            71:      * Get next event from input queue and store it in the event packet
        !            72:      * passed to GetButton.
        !            73:      */
        !            74:     XNextEvent(button_event);
        !            75: 
        !            76:     /*
        !            77:      * The event occured on the root window, it must be a mouse
        !            78:      * button event. 
        !            79:      */
        !            80:     if (button_event->window == RootWindow) {
        !            81:        return(TRUE);
        !            82:     }
        !            83: 
        !            84:     /*
        !            85:      * Ok, if the event is not on the root window it must be an event on
        !            86:      * one of the icons owned by uwm.
        !            87:      */
        !            88:     icon = button_event->window;
        !            89: 
        !            90:     /*
        !            91:      * Find out current information about the icon window.
        !            92:      */
        !            93:     status = XQueryWindow(icon, &icon_info);
        !            94:     if (status == FAILURE) return(FALSE);
        !            95: 
        !            96:     /*
        !            97:      * If the icon's normal window is gone, then
        !            98:      * destroy the icon window and return FALSE.
        !            99:      */
        !           100:     if (icon_info.assoc_wind == 0) {
        !           101:         XDestroyWindow(icon);
        !           102:         return(FALSE);
        !           103:     }
        !           104: 
        !           105:     /*
        !           106:      * If the event is an UnmapWindow event,
        !           107:      * then return FALSE.
        !           108:      */
        !           109:     if (button_event->type == UnmapWindow)
        !           110:         return(FALSE);
        !           111: 
        !           112:     /*
        !           113:      * Initialize the icon position variables.
        !           114:      */
        !           115:     icon_x = icon_info.x;
        !           116:     icon_y = icon_info.y;
        !           117: 
        !           118:     /*
        !           119:      * Get the name of the window associated with the icon and
        !           120:      * determine its length.
        !           121:      */
        !           122:     status = XFetchName(icon_info.assoc_wind, &icon_str);
        !           123:     if (status == FAILURE) return(FALSE);
        !           124:     icon_str_len = icon_str ? strlen(icon_str) : 0;
        !           125: 
        !           126:     /*
        !           127:      * If the event is a window exposure event and the icon's name string
        !           128:      * is not of zero length, simply repaint the text in the icon window
        !           129:      * and return FALSE.
        !           130:      */
        !           131:     if (button_event->type == ExposeWindow && Frozen == 0) {
        !           132:         XClear(icon);
        !           133:         if (icon_str_len != 0) {
        !           134:             XTextPad(icon,
        !           135:                      HIconPad, VIconPad,
        !           136:                      icon_str, icon_str_len,
        !           137:                     IFont, 0, 0,
        !           138:                      ITextForground, ITextBackground,
        !           139:                      GXcopy, AllPlanes);
        !           140:            /*
        !           141:             * Remember to free the icon name string.
        !           142:             */
        !           143:            free(icon_str);
        !           144:         }
        !           145:        return(FALSE);
        !           146:     }
        !           147: 
        !           148:     /*
        !           149:      * If we have gotten this far event can only be a key pressed event.
        !           150:      */
        !           151:     kp_event = (XKeyPressedEvent *) button_event;
        !           152: 
        !           153:     /* 
        !           154:      * We convert the key pressed event to ascii.
        !           155:      */
        !           156:     kbd_str = XLookupMapping(kp_event, &nbytes);
        !           157: 
        !           158:     /*
        !           159:      * If kbd_str is a "non-string", then don't do anything.
        !           160:      */
        !           161:     if (nbytes == 0) {
        !           162:         if (icon_str) free(icon_str);
        !           163:         return(FALSE);
        !           164:     }
        !           165:     for (i = 0; i < nbytes; i++) {
        !           166:         key_char = kbd_str[i];
        !           167:         /*
        !           168:          * If the key was <DELETE>, then delete a character from the end of
        !           169:          * the name, return FALSE.
        !           170:          *
        !           171:          * If the key was <CTRL-U>, then wipe out the entire window name
        !           172:          * and return FALSE.
        !           173:          *
        !           174:          * All other ctrl keys are squashed and we return FALSE.
        !           175:          *
        !           176:          * All printable characters are appended to the window's name, which
        !           177:          * may have to be grown to allow for the extra length.
        !           178:          */
        !           179:         if (key_char == '\177') {
        !           180:             /*
        !           181:              * <DELETE>
        !           182:              */
        !           183:             if (icon_str_len > 0) {
        !           184:                icon_str_len--;
        !           185:                icon_str[icon_str_len] = '\0';
        !           186:            }
        !           187:         }
        !           188:         else if (key_char == '\025') {
        !           189:             /*
        !           190:              * <CTRL-U>
        !           191:              */
        !           192:             if (icon_str_len > 0) {
        !           193:                icon_str_len = 0;
        !           194:                icon_str = '\0';
        !           195:            }
        !           196:         }
        !           197:         else if (key_char < IFontInfo.firstchar ||
        !           198:                  key_char > IFontInfo.lastchar) {
        !           199:             /*
        !           200:              * Any other random (non-printable) key; ignore it.
        !           201:              */
        !           202:            /* do nothing */ ;
        !           203:         }
        !           204:         else {
        !           205:             /*
        !           206:              * ASCII Alphanumerics.
        !           207:              */
        !           208:            if (icon_str == NULL)
        !           209:                icon_str = (char *) malloc (icon_str_len + 2);
        !           210:            else
        !           211:                icon_str = (char *)realloc(icon_str, (icon_str_len + 2));
        !           212:             if (icon_str == NULL) {
        !           213:                 errno = ENOMEM;
        !           214:                 Error("GetButton -> Realloc of window name string memory failed.");
        !           215:             }
        !           216:             icon_str[icon_str_len] = key_char;
        !           217:             icon_str[icon_str_len + 1] = '\0';
        !           218:             icon_str_len += 1;
        !           219:         }
        !           220:     }
        !           221: 
        !           222:     /*
        !           223:      * Now that we have changed the size of the icon we have to reconfigure
        !           224:      * it so that everything looks good.  Oh yes, don't forget to move the
        !           225:      * mouse so that it stays in the window!
        !           226:      */
        !           227: 
        !           228:     /*
        !           229:      * Set the window name to the new string.
        !           230:      */
        !           231:     XStoreName(icon_info.assoc_wind, icon_str);
        !           232: 
        !           233:     /*
        !           234:      * Determine the new icon window configuration.
        !           235:      */
        !           236:     icon_h = IFontInfo.height + (VIconPad << 1);
        !           237:     icon_w = XQueryWidth(icon_str, IFont);
        !           238:     if (icon_w == 0) {
        !           239:         icon_w = icon_h;
        !           240:     }
        !           241:     else {
        !           242:        icon_w += (HIconPad << 1);
        !           243:     }
        !           244: 
        !           245:     if (icon_x < 0) icon_x = 0;
        !           246:     if (icon_y < 0) icon_y = 0;
        !           247:     if (icon_x - 1 + icon_w + (IBorderWidth << 1) > ScreenWidth) {
        !           248:        icon_x = ScreenWidth - icon_w - (IBorderWidth << 1) + 1;
        !           249:     }
        !           250:     if (icon_y - 1 + icon_h + (IBorderWidth << 1) > ScreenHeight) {
        !           251:        icon_y = ScreenHeight - icon_h - (IBorderWidth << 1) + 1;
        !           252:     }
        !           253: 
        !           254:     XConfigureWindow(icon, icon_x, icon_y, icon_w, icon_h);
        !           255:     XWarpMouse(icon, (icon_w >> 1), (icon_h >> 1));
        !           256: 
        !           257:     /* 
        !           258:      * Free the local storage and return FALSE.
        !           259:      */
        !           260:     if (icon_str) free(icon_str);
        !           261:     return(FALSE);
        !           262: }

unix.superglobalmegacorp.com

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