Annotation of 43BSDTahoe/new/X/XMenu/XMenuCreate.c, revision 1.1.1.1

1.1       root        1: #include <X/mit-copyright.h>
                      2: 
                      3: /* $Header: XMenuCreate.c,v 10.12 86/07/11 16:59:46 tony Rel $ */
                      4: /* Copyright    Massachusetts Institute of Technology    1985  */
                      5: 
                      6: /*
                      7:  * XMenu:      MIT Project Athena, X Window system menu package
                      8:  *
                      9:  *     XMenuCreate -   Creates an X window system menu object.
                     10:  *
                     11:  *     Author:         Tony Della Fera, DEC
                     12:  *                     January 23, 1986
                     13:  *
                     14:  */
                     15: 
                     16: #include "XMenuInternal.h"
                     17: 
                     18: #include "../bitmaps/dimple1.bitmap"
                     19: #include "../bitmaps/dimple3.bitmap"
                     20: #include "../bitmaps/gray1.bitmap"
                     21: #include "../bitmaps/gray3.bitmap"
                     22: #include "../bitmaps/cross_weave.bitmap"
                     23: 
                     24: #include "../cursors/left_ptr.cursor"
                     25: #include "../cursors/left_ptr_mask.cursor"
                     26: #include "../cursors/right_ptr.cursor"
                     27: #include "../cursors/right_ptr_mask.cursor"
                     28: #include "../cursors/center_ptr.cursor"
                     29: #include "../cursors/center_ptr_mask.cursor"
                     30: 
                     31: #define DEF_FREEZE             0
                     32: #define DEF_REVERSE            0
                     33: #define DEF_MENU_STYLE         RIGHT
                     34: #define DEF_MENU_MODE          INVERT
                     35: #define DEF_INACT_PNUM         3
                     36: #define MAX_INACT_PNUM         4
                     37: 
                     38: #define DEF_P_STYLE            CENTER
                     39: #define DEF_P_EVENTS           (EnterWindow | ExposeWindow)
                     40: #define DEF_P_FNT_NAME         "8x13"
                     41: #define DEF_P_SPREAD           0.5
                     42: #define DEF_P_BDR_WIDTH                2
                     43: 
                     44: #define DEF_S_STYLE            LEFT
                     45: #define DEF_S_EVENTS           (EnterWindow | LeaveWindow)
                     46: #define DEF_S_FNT_NAME         "6x10"
                     47: #define DEF_S_SPREAD           0.10
                     48: #define DEF_S_BDR_WIDTH                1
                     49: 
                     50: #define XASSOC_TABLE_SIZE      64
                     51: 
                     52: #define TILE_BUF_SIZE          5
                     53: 
                     54: int atoi();
                     55: double atof();
                     56: 
                     57: XMenu *
                     58: XMenuCreate(parent, def_env)
                     59:     Window parent;             /* Window ID of the menu's parent window. */
                     60:     register char *def_env;    /* X Defaults program environment name. */
                     61: {
                     62:     register int i;            /* Loop counter. */
                     63:     register int j;            /* Loop counter. */
                     64:     register char *def_val;    /* X Default value temp variable. */
                     65: 
                     66:     register XMenu *menu;      /* Pointer to the new menu. */
                     67:     XMStyle menu_style;                /* Menu display style. */
                     68:     XMMode menu_mode;          /* Menu display mode. */
                     69:     XMPane *pane;              /* Pane list header. */
                     70:     XAssocTable *assoc_tab;    /* XAssocTable pointer. */
                     71:     Cursor mouse_cursor;       /* Mouse cursor. */
                     72:     int freeze;                        /* Freeze server mode. */
                     73:     int reverse;               /* Reverse video mode. */
                     74:     int tile_count;            /* Number of tiles created by XMakeTiles. */
                     75: 
                     76:     XMStyle p_style;           /* Pane display style. */
                     77:     char *p_fnt_name;          /* Flag font name. */
                     78:     FontInfo *p_fnt_info;      /* Flag font information. */
                     79:     int p_fnt_pad;             /* Flag font padding in pixels. */
                     80:     double p_spread;           /* Pane spread in flag height fractions. */
                     81:     int p_bdr_width;           /* Pane border width. */
                     82:     int flag_height;           /* Flag window height. */
                     83:     int p_height;              /* Pane window height. */
                     84:     int p_x_off;               /* Pane X offset. */
                     85:     int p_y_off;               /* Pane Y offset. */
                     86: 
                     87:     XMStyle s_style;           /* Selection display style. */
                     88:     char *s_fnt_name;          /* Selection font name. */
                     89:     FontInfo *s_fnt_info;      /* Selection font information. */
                     90:     int s_fnt_pad;             /* Selection font padding in pixels. */
                     91:     double s_spread;           /* Select spread in line height fractions. */
                     92:     int s_bdr_width;           /* Highlight border width. */
                     93:     int s_height;              /* Selection window height. */
                     94:     int s_x_off;               /* Selection window X offset. */
                     95:     int s_y_off;               /* Selection window Y offset. */
                     96: 
                     97:     Color color_def;           /* Color definition holder. */
                     98:     int p_bdr_color;           /* Color of border pixmap. */
                     99:     int s_bdr_color;           /* Color of highlight pixmap. */
                    100:     int p_frg_color;           /* Color of pane foreground pixmap. */
                    101:     int s_frg_color;           /* Color of selection foreground pixmap. */
                    102:     int bkgnd_color;           /* Color of background pixmap. */
                    103:     int mouse_color;           /* Color of mouse cursor. */
                    104: 
                    105:     Bitmap inact_bitmap;       /* Inactive background pattern bitmap. */
                    106:     int inact_pnum;            /* Inactive background pattern number. */
                    107: 
                    108:     Pixmap p_bdr_pixmap;       /* Pane border pixmap. */
                    109:     Pixmap s_bdr_pixmap;       /* Selection border pixmap. */
                    110:     Pixmap p_frg_pixmap;       /* Pane forground pixmap. */
                    111:     Pixmap s_frg_pixmap;       /* Selection forground pixmap. */
                    112:     Pixmap bkgnd_pixmap;       /* Menu background pixmap. */
                    113:     Pixmap inact_pixmap;       /* Menu inactive pixmap. */
                    114: 
                    115:     TileFrame tile_buf[TILE_BUF_SIZE]; /* XMakeTiles buffer. */
                    116: 
                    117:     /*
                    118:      * Calloc the XMenu structure and the initial pane.
                    119:      */
                    120:     menu = (XMenu *)calloc(1, sizeof(XMenu));
                    121:     if (menu == NULL) {
                    122:        _XMErrorCode = XME_CALLOC;
                    123:        return(NULL);
                    124:     }
                    125:     pane = (XMPane *)calloc(1, sizeof(XMPane));
                    126:     if (pane == NULL) {
                    127:        _XMErrorCode = XME_CALLOC;
                    128:        return(NULL);
                    129:     }
                    130: 
                    131:     /*
                    132:      * Create the XAssocTable.
                    133:      */
                    134:     assoc_tab = (XAssocTable *)XCreateAssocTable(XASSOC_TABLE_SIZE);
                    135:     if (assoc_tab == NULL) {
                    136:        _XMErrorCode = XME_CREATE_ASSOC;
                    137:        return(NULL);
                    138:     }
                    139: 
                    140:     /*
                    141:      * Set up the default environment name.
                    142:      */
                    143:     if (def_env == NULL || *def_env == '\0') def_env = "XMenu";
                    144: 
                    145:     /*
                    146:      * Set up internal fail-safe defaults.
                    147:      */
                    148:     freeze = DEF_FREEZE;
                    149:     reverse = DEF_REVERSE;
                    150:     menu_style = DEF_MENU_STYLE;
                    151:     menu_mode = DEF_MENU_MODE;
                    152:     inact_pnum = DEF_INACT_PNUM;
                    153: 
                    154:     p_style = DEF_P_STYLE;
                    155:     p_spread = DEF_P_SPREAD;
                    156:     p_fnt_name = DEF_P_FNT_NAME;
                    157:     p_bdr_width = DEF_P_BDR_WIDTH;
                    158: 
                    159:     s_style = DEF_S_STYLE;
                    160:     s_spread = DEF_S_SPREAD;
                    161:     s_fnt_name = DEF_S_FNT_NAME;
                    162:     s_bdr_width = DEF_S_BDR_WIDTH;
                    163: 
                    164:     /*
                    165:      * Get default values from X.
                    166:      */
                    167:     def_val = XGetDefault(def_env, "MenuFreeze");
                    168:     if (def_val != NULL) {
                    169:        if (strcmp(def_val, "on") == 0) freeze = 1;
                    170:        else if (strcmp(def_val, "off") == 0) freeze = 0;
                    171:     }
                    172: 
                    173:     def_val = XGetDefault(def_env, "MenuReverseVideo");
                    174:     if (def_val != NULL) {
                    175:        if (strcmp(def_val, "on") == 0) reverse = 1;
                    176:        else if (strcmp(def_val, "off") == 0) reverse = 0;
                    177:     }
                    178: 
                    179:     def_val = XGetDefault(def_env, "MenuStyle");
                    180:     if (def_val != NULL) {
                    181:        if (strcmp(def_val, "right_hand") == 0) menu_style = RIGHT;
                    182:        else if (strcmp(def_val, "left_hand") == 0) menu_style = LEFT;
                    183:        else if (strcmp(def_val, "center") == 0) menu_style = CENTER;
                    184:     }
                    185: 
                    186:     def_val = XGetDefault(def_env, "MenuMode");
                    187:     if (def_val != NULL) {
                    188:        if (strcmp(def_val, "box") == 0) menu_mode = BOX;
                    189:        else if (strcmp(def_val, "invert") == 0) menu_mode = INVERT;
                    190:     }
                    191: 
                    192:     def_val = XGetDefault(def_env, "MenuMouse");
                    193:     if (
                    194:        def_val != NULL &&
                    195:        DisplayCells() > 2 &&
                    196:        XParseColor(def_val, &color_def) &&
                    197:        XGetHardwareColor(&color_def)
                    198:     ) mouse_color = color_def.pixel;
                    199:     else if (reverse) mouse_color = WhitePixel;
                    200:     else mouse_color = BlackPixel;
                    201: 
                    202:     def_val = XGetDefault(def_env, "MenuBackground");
                    203:     if (
                    204:        def_val != NULL &&
                    205:        DisplayCells() > 2 &&
                    206:        XParseColor(def_val, &color_def) &&
                    207:        XGetHardwareColor(&color_def)
                    208:     ) bkgnd_color = color_def.pixel;
                    209:     else if (reverse) bkgnd_color = BlackPixel;
                    210:     else bkgnd_color = WhitePixel;
                    211:     
                    212:     def_val = XGetDefault(def_env, "MenuInactivePattern");
                    213:     if (def_val != NULL) {
                    214:        if (strcmp(def_val, "dimple1") == 0) inact_pnum = 0;
                    215:        else if (strcmp(def_val, "dimple3") == 0) inact_pnum = 1;
                    216:        else if (strcmp(def_val, "gray1") == 0) inact_pnum = 2;
                    217:        else if (strcmp(def_val, "gray3") == 0) inact_pnum = 3;
                    218:        else if (strcmp(def_val, "cross_weave") == 0) inact_pnum = 4;
                    219:     }
                    220: 
                    221:     def_val = XGetDefault(def_env, "PaneStyle");
                    222:     if (def_val != NULL) {
                    223:        if (strcmp(def_val, "flush_left") == 0) p_style = LEFT;
                    224:        else if (strcmp(def_val, "flush_right") == 0) p_style = RIGHT;
                    225:        else if (strcmp(def_val, "center") == 0) p_style = CENTER;
                    226:     }
                    227: 
                    228:     def_val = XGetDefault(def_env, "PaneFont");
                    229:     if (def_val != NULL) p_fnt_name = def_val;
                    230: 
                    231:     def_val = XGetDefault(def_env, "PaneForeground");
                    232:     if (
                    233:        def_val != NULL &&
                    234:        DisplayCells() > 2 &&
                    235:        XParseColor(def_val, &color_def) &&
                    236:        XGetHardwareColor(&color_def)
                    237:     ) p_frg_color = color_def.pixel;
                    238:     else if (reverse) p_frg_color = WhitePixel;
                    239:     else p_frg_color = BlackPixel;
                    240: 
                    241:     def_val = XGetDefault(def_env, "PaneBorder");
                    242:     if (
                    243:        def_val != NULL &&
                    244:        DisplayCells() > 2 &&
                    245:        XParseColor(def_val, &color_def) &&
                    246:        XGetHardwareColor(&color_def)
                    247:     ) p_bdr_color = color_def.pixel;
                    248:     else if (reverse) p_bdr_color = WhitePixel;
                    249:     else p_bdr_color = BlackPixel;
                    250:     
                    251:     def_val = XGetDefault(def_env, "PaneBorderWidth");
                    252:     if (def_val != NULL) p_bdr_width = atoi(def_val);
                    253:     
                    254:     def_val = XGetDefault(def_env, "PaneSpread");
                    255:     if (def_val != NULL) p_spread = atof(def_val);
                    256: 
                    257:     def_val = XGetDefault(def_env, "SelectionStyle");
                    258:     if (def_val != NULL) {
                    259:        if (strcmp(def_val, "flush_left") == 0) s_style = LEFT;
                    260:        else if (strcmp(def_val, "flush_right") == 0) s_style = RIGHT;
                    261:        else if (strcmp(def_val, "center") == 0) s_style = CENTER;
                    262:     }
                    263: 
                    264:     def_val = XGetDefault(def_env, "SelectionFont");
                    265:     if (def_val != NULL) s_fnt_name = def_val;
                    266: 
                    267:     def_val = XGetDefault(def_env, "SelectionForeground");
                    268:     if (
                    269:        def_val != NULL &&
                    270:        DisplayCells() > 2 &&
                    271:        XParseColor(def_val, &color_def) &&
                    272:        XGetHardwareColor(&color_def)
                    273:     ) s_frg_color = color_def.pixel;
                    274:     else if (reverse) s_frg_color = WhitePixel;
                    275:     else s_frg_color = BlackPixel;
                    276: 
                    277:     def_val = XGetDefault(def_env, "SelectionBorder");
                    278:     if (
                    279:        def_val != NULL &&
                    280:        DisplayCells() > 2 &&
                    281:        XParseColor(def_val, &color_def) &&
                    282:        XGetHardwareColor(&color_def)
                    283:     ) s_bdr_color = color_def.pixel;
                    284:     else if (reverse) s_bdr_color = WhitePixel;
                    285:     else s_bdr_color = BlackPixel;
                    286: 
                    287:     def_val = XGetDefault(def_env, "SelectionBorderWidth");
                    288:     if (def_val != NULL) s_bdr_width = atoi(def_val);
                    289:     
                    290:     def_val = XGetDefault(def_env, "SelectionSpread");
                    291:     if (def_val != NULL) s_spread = atof(def_val);
                    292: 
                    293:     /*
                    294:      * Create and store the inactive pattern pixmap.
                    295:      */
                    296:     switch (inact_pnum) {
                    297:        case 0:
                    298:            inact_bitmap = XStoreBitmap(16, 16, dimple1_bits);
                    299:            break;
                    300:        case 1:
                    301:            inact_bitmap = XStoreBitmap(16, 16, dimple3_bits);
                    302:            break;
                    303:        case 2:
                    304:            inact_bitmap = XStoreBitmap(16, 16, gray1_bits);
                    305:            break;
                    306:        case 3:
                    307:            inact_bitmap = XStoreBitmap(16, 16, gray3_bits);
                    308:            break;
                    309:        case 4:
                    310:            inact_bitmap = XStoreBitmap(16, 16, cross_weave_bits);
                    311:            break;
                    312:     }
                    313:     if (inact_bitmap == _X_FAILURE) {
                    314:        _XMErrorCode = XME_STORE_BITMAP;
                    315:        return(NULL);
                    316:     }
                    317: 
                    318:     /*
                    319:      * Generate the pixmaps from the background and forground colors.
                    320:      */
                    321:     tile_buf[0].pixel = p_bdr_color;
                    322:     tile_buf[1].pixel = s_bdr_color;
                    323:     tile_buf[2].pixel = p_frg_color;
                    324:     tile_buf[3].pixel = s_frg_color;
                    325:     tile_buf[4].pixel = bkgnd_color;
                    326: 
                    327:     tile_count = XMakeTiles(tile_buf, TILE_BUF_SIZE);
                    328:     if (tile_count != TILE_BUF_SIZE) {
                    329:        _XMErrorCode = XME_MAKE_TILES;
                    330:        return(NULL);
                    331:     }
                    332: 
                    333:     p_bdr_pixmap = tile_buf[0].pixmap;
                    334:     s_bdr_pixmap = tile_buf[1].pixmap;
                    335:     p_frg_pixmap = tile_buf[2].pixmap;
                    336:     s_frg_pixmap = tile_buf[3].pixmap;
                    337:     bkgnd_pixmap = tile_buf[4].pixmap;
                    338: 
                    339:     /*
                    340:      * Generate the inactive pixmap.
                    341:      */
                    342:     inact_pixmap = XMakePixmap(inact_bitmap, p_frg_color, bkgnd_color);
                    343:     if (inact_pixmap == _X_FAILURE) {
                    344:        _XMErrorCode = XME_MAKE_PIXMAP;
                    345:        return(NULL);
                    346:     }
                    347: 
                    348:     /*
                    349:      * Free the inactive pattern bitmap since we no longer need it.
                    350:      */
                    351:     XFreeBitmap(inact_bitmap);
                    352: 
                    353:     /*
                    354:      * Load the mouse cursor.
                    355:      */
                    356:     switch (menu_style) {
                    357:        case LEFT:
                    358:            mouse_cursor = XCreateCursor(
                    359:                right_ptr_width, right_ptr_height, 
                    360:                right_ptr_bits, right_ptr_mask_bits, 
                    361:                right_ptr_x_hot, right_ptr_y_hot,
                    362:                mouse_color, bkgnd_color,
                    363:                GXcopy
                    364:            );
                    365:            break;
                    366:        case RIGHT:
                    367:            mouse_cursor = XCreateCursor(
                    368:                left_ptr_width, left_ptr_height, 
                    369:                left_ptr_bits, left_ptr_mask_bits, 
                    370:                left_ptr_x_hot, left_ptr_y_hot,
                    371:                mouse_color, bkgnd_color,
                    372:                GXcopy
                    373:            );
                    374:            break;
                    375:        case CENTER:
                    376:            mouse_cursor = XCreateCursor(
                    377:                center_ptr_width, center_ptr_height, 
                    378:                center_ptr_bits, center_ptr_mask_bits, 
                    379:                center_ptr_x_hot, center_ptr_y_hot,
                    380:                mouse_color, bkgnd_color,
                    381:                GXcopy
                    382:            );
                    383:            break;
                    384:        default:
                    385:            /* Error! Invalid style parameter. */
                    386:            _XMErrorCode = XME_STYLE_PARAM;
                    387:            return(NULL);
                    388:     }
                    389:     if (mouse_cursor == _X_FAILURE) {
                    390:        _XMErrorCode = XME_CREATE_CURSOR;
                    391:        return(NULL);
                    392:     }
                    393: 
                    394:     /*
                    395:      * Open the pane and selection fonts.
                    396:      */
                    397:     p_fnt_info = XOpenFont(p_fnt_name);
                    398:     if (p_fnt_info == NULL) {
                    399:        _XMErrorCode = XME_OPEN_FONT;
                    400:        return(NULL);
                    401:     }
                    402:     s_fnt_info = XOpenFont(s_fnt_name);
                    403:     if (s_fnt_info == NULL) {
                    404:        _XMErrorCode = XME_OPEN_FONT;
                    405:        return(NULL);
                    406:     }
                    407:      
                    408:     /*
                    409:      * Calculate the fixed padding value in pixels for each font.
                    410:      */
                    411:     p_fnt_pad = s_spread * p_fnt_info->height;
                    412:     s_fnt_pad = s_spread * s_fnt_info->height;
                    413: 
                    414:     /*
                    415:      * Calculate fixed height and offset requirements.
                    416:      */
                    417:     flag_height = p_fnt_info->height + (p_fnt_pad << 1);
                    418: 
                    419:     p_height = 0;
                    420:     p_y_off = flag_height + p_bdr_width;
                    421:     p_x_off = p_y_off * p_spread;
                    422: 
                    423:     s_height = s_fnt_info->height + (s_fnt_pad << 1) + (s_bdr_width << 1);
                    424:     s_y_off = s_height;
                    425:     s_x_off = p_x_off;
                    426: 
                    427:     /*
                    428:      * Set up the pane list header.
                    429:      */
                    430:     pane->next = pane;
                    431:     pane->prev = pane;
                    432:     pane->type = PL_HEADER;
                    433:     pane->serial = -1;
                    434: 
                    435:     /*
                    436:      * Initialize the internal pane and selection creation queues.
                    437:      */
                    438:     _XMWinQueInit();
                    439: 
                    440:     /*
                    441:      * Construct the XMenu object.
                    442:      */
                    443:     /* -------------------- Menu data -------------------- */
                    444:     menu->menu_style = menu_style;
                    445:     menu->menu_mode = menu_mode;
                    446:     menu->freeze = freeze;
                    447:     menu->aeq = 0;
                    448:     menu->recompute = 1;
                    449:     menu->parent = parent;
                    450:     menu->height = 0;
                    451:     menu->width = 0;
                    452:     menu->mouse_cursor = mouse_cursor;
                    453:     menu->assoc_tab = assoc_tab;
                    454:     menu->p_list = pane;
                    455:     /* -------------------- Pane window data -------------------- */
                    456:     menu->p_style = p_style;
                    457:     menu->p_events = DEF_P_EVENTS;
                    458:     menu->p_fnt_info = p_fnt_info;
                    459:     menu->p_fnt_pad = p_fnt_pad;
                    460:     menu->p_spread = p_spread;
                    461:     menu->p_bdr_width = p_bdr_width;
                    462:     menu->flag_height = flag_height;
                    463:     menu->p_width = 0;
                    464:     menu->p_height = p_height;
                    465:     menu->p_x_off = p_x_off;
                    466:     menu->p_y_off = p_y_off;
                    467:     menu->p_count = 0;
                    468:     /* -------------------- Selection window data -------------------- */
                    469:     menu->s_style = s_style;
                    470:     menu->s_events = DEF_S_EVENTS;
                    471:     menu->s_fnt_info = s_fnt_info;
                    472:     menu->s_fnt_pad = s_fnt_pad;
                    473:     menu->s_spread = s_spread;
                    474:     menu->s_bdr_width = s_bdr_width;
                    475:     menu->s_width = 0;
                    476:     menu->s_height = s_height;
                    477:     menu->s_x_off = s_x_off;
                    478:     menu->s_y_off = s_y_off;
                    479:     menu->s_count = 0;
                    480:     /* -------------------- Color data -------------------- */
                    481:     menu->p_bdr_color = p_bdr_color;
                    482:     menu->s_bdr_color = s_bdr_color;
                    483:     menu->p_frg_color = p_frg_color;
                    484:     menu->s_frg_color = s_frg_color;
                    485:     menu->bkgnd_color = bkgnd_color;
                    486:     /* -------------------- Pixmap data -------------------- */
                    487:     menu->p_bdr_pixmap = p_bdr_pixmap;
                    488:     menu->s_bdr_pixmap = s_bdr_pixmap;
                    489:     menu->p_frg_pixmap = p_frg_pixmap;
                    490:     menu->s_frg_pixmap = s_frg_pixmap;
                    491:     menu->bkgnd_pixmap = bkgnd_pixmap;
                    492:     menu->inact_pixmap = inact_pixmap;
                    493: 
                    494:     /*
                    495:      * Return the completed XMenu.
                    496:      */
                    497:     _XMErrorCode = XME_NO_ERROR;
                    498:     return(menu);
                    499: }

unix.superglobalmegacorp.com

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