|
|
1.1 ! root 1: .ds ZZ DEVELOPMENT PACKAGE ! 2: .TH TMENUHIT 3R "630 MTG" ! 3: .XE "tmenuhit()" ! 4: .XE "tm_ret()" ! 5: .SH NAME ! 6: tmenuhit \- present user with menu and get selection ! 7: .SH SYNOPSIS ! 8: .ft B ! 9: #include <dmd.h> ! 10: .br ! 11: #include <menu.h> ! 12: .sp ! 13: Titem \(**tmenuhit (m, n, flags [, p]) ! 14: .br ! 15: Tmenu \(**m; ! 16: .br ! 17: int n; ! 18: .br ! 19: int flags; ! 20: .br ! 21: Point p; ! 22: .sp ! 23: void tm_ret() ! 24: .PP ! 25: .nf ! 26: \s-1 ! 27: .ft CM ! 28: typedef struct Titem ! 29: { ! 30: char *text; /* string for menu */ ! 31: struct { ! 32: unsigned short uval; /* user field */ ! 33: unsigned short grey; /* grey this selection */ ! 34: } ufield; ! 35: struct Tmenu *next; /* ptr to sub-menu */ ! 36: Bitmap *icon; /* ptr to the icons bitmap */ ! 37: struct Font *font; /* font defined for this item */ ! 38: void (*dfn)(); /* execute function before sub-menu */ ! 39: void (*bfn)(); /* execute function after sub-menu */ ! 40: void (*hfn)(); /* execute function on selection */ ! 41: } Titem; ! 42: ! 43: typedef struct Tmenu ! 44: { ! 45: Titem *item; /* Titem array */ ! 46: short prevhit; /* index to current item */ ! 47: short prevtop; /* index to top item */ ! 48: Titem *(*generator)(); /* used if item == 0 */ ! 49: short menumap; /* bit definition of structure */ ! 50: } Tmenu; ! 51: ! 52: /* bit definitions in menumap */ ! 53: #define TM_TEXT 0x0001 /* defines the text field */ ! 54: #define TM_UFIELD 0x0002 /* defines the ufield field */ ! 55: #define TM_NEXT 0x0004 /* defines the next field */ ! 56: #define TM_ICON 0x0008 /* defines the icon field */ ! 57: #define TM_FONT 0x0010 /* defines the font field */ ! 58: #define TM_DFN 0x0020 /* defines the dfn field */ ! 59: #define TM_BFN 0x0040 /* defines the bfn field */ ! 60: #define TM_HFN 0x0080 /* defines the hfn field */ ! 61: .ft R ! 62: .fi ! 63: \s+1 ! 64: .SH DESCRIPTION ! 65: The \fItmenuhit\fP function ! 66: is an enhanced version of menuhit. It adds such features as ! 67: expanding menus, use of icons and various fonts within a menu item, ! 68: greying non-selectable items, and extended control over invocation and ! 69: specification of the menu facility. ! 70: .SS "Menu Trees" ! 71: Menu trees allow the presentation of several menus in a hierarchical ! 72: format. Each menu is specified by a \fITmenu\fP structure. ! 73: Each \fITmenu\fP structure contains a array of one or more \fITitem\fP ! 74: structures which specify the menu items. Each item of a menu may then, ! 75: in turn, point to a submenu. Submenus appear to the right ! 76: of the parent menu. The presence of a submenu for a menu item is indicated ! 77: by an arrow icon pointing to the right. Moving the cursor to the ! 78: arrow icon allows the user to preview the submenu. Sliding further to the ! 79: right moves the cursor into the submenu and allows the user to make a ! 80: selection in this menu. Moving the cursor back to the left exits the ! 81: submenu and moves the cursor back into the parent menu. ! 82: .SS Usage ! 83: The \fItmenuhit\fP function ! 84: presents the user with a menu tree specified by the root \fITmenu\fP pointer ! 85: \fIm\fP ! 86: and returns a pointer to a \fITitem\fP structure indicating which item was ! 87: selected. If no item was selected \fItmenuhit\fP returns a 0. ! 88: The \fIn\fP argument is an integer which ! 89: specifies the mouse button for user interaction: 1, 2, 3 or 0 for all ! 90: the buttons.. ! 91: The \fIflags\fP ! 92: argument is a bit vector which indicates various ! 93: modes of function in \fItmenuhit\fP. ! 94: These flags include: ! 95: .TP ! 96: .B (flags & TM_EXPAND) ! 97: If true, the menu tree will be expanded (according to the previous selection) ! 98: down to the lowest leaf on invocation of \fItmenuhit\fP. ! 99: .TP ! 100: .B (flags & TM_NORET) ! 101: If true, \fItmenuhit\fP will not return when a valid selection is made. This ! 102: feature is useful if a lot of selections are to be made from a large menu. ! 103: .TP ! 104: .B (flags & TM_STATIC) ! 105: If true, \fItmenuhit\fP assumes that no button is depressed when it is called. ! 106: In this case, the user makes a selection by depressing the button specified ! 107: when the cursor points to the item desired. If this is false, ! 108: \fItmenuhit\fP assumes that the button is depressed when called. The user ! 109: makes a selection by lifting the button when the cursor points to the ! 110: desired item. ! 111: .TP ! 112: .B (flags & TM_POINT) ! 113: If true, the argument \fIp\fP must be present and the origin of the root ! 114: menu will appear at this point on the display. ! 115: .P ! 116: The user may define one or more of these flags by or'ing them together ! 117: within the function call (e.g. (TM_EXPAND|TM_POINT) ). ! 118: .SS "Structure and Functional Description" ! 119: This section describes the structure fields of the \fITmenu\fP and the ! 120: \fITitem\fP structures and the functions of \fItmenuhit\fP they serve. ! 121: .P ! 122: The ! 123: .B Tmenu ! 124: structure defines a menu. It has the following fields: ! 125: .TP ! 126: .B item ! 127: This is an array of \fITitem\fP structures which defines each item in the ! 128: menu. The last item in the array must have its \fITitem\fP text ! 129: field equal to 0. ! 130: .TP ! 131: .B prevhit ! 132: \fIprevhit\fR is used to store the menu's previous selection. ! 133: When \fItmenuhit\fP ! 134: is called the menu is displayed such that, if possible, the mouse cursor ! 135: will be displayed over the previous selection. This might not be possible ! 136: if the menu is near the border of the screen. ! 137: \fIPrevhit\fR holds the index from ! 138: the top of the displayed menu. ! 139: The \fIprevhit\fR value is initialized to 0 and ! 140: normally does not need to be ! 141: manipulated by the application program. ! 142: .TP ! 143: .B prevtop ! 144: \fIprevtop\fR is used to store the topmost item ! 145: displayed in the menu when more ! 146: than sixteen menu items are defined. The maximum number of items which ! 147: may be displayed within a menu is sixteen. When there are more than sixteen ! 148: the menu becomes a ! 149: .B scrolling menu. ! 150: In this case, ! 151: the left portion of the menu contains a scroll bar that is ! 152: used for scrolling quickly through the menu selections. ! 153: The vertical size of the scroll bar is an indication of the size ! 154: of the user's view of the menu (16 items) relative to the number ! 155: of selections in the entire menu. ! 156: .sp ! 157: There are two ways to scroll through the menu items. ! 158: The first is to move the mouse cursor to the left side of the menu ! 159: into the scroll bar area. ! 160: By moving the mouse cursor up or down within the scroll bar area, the menu ! 161: items will scroll accordingly. ! 162: The second method used to scroll through the menu ! 163: items is to place the mouse cursor on the top or bottom entry of the menu ! 164: list. The menu will scroll up or down by one item at a time if ! 165: there are additional items to be displayed in that direction. ! 166: .sp ! 167: Like prevhit, the value of prevtop is initialized to 0 and ! 168: normally does not need to be manipulated by the application program. ! 169: .TP ! 170: .B generator ! 171: Menu items may be generated dynamically from a program by specifying ! 172: a generator function in the \fITmenu\fP structure. ! 173: If the item field in the \fITmenu\fP data structure ! 174: is 0 when a menu is entered, ! 175: either by calling \fItmenuhit\fP or through the sub-menu mechanism, ! 176: then the routine specified by \fIgenerator\fR ! 177: is called with two parameters that are ! 178: an integer index beginning at 0 and the address of the current \fITmenu\fP. ! 179: The generator must return a pointer to a \fITitem\fP ! 180: structure containing the text for the corresponding menu item. ! 181: This generator function is called repeatedly ! 182: with the index increasing by 1 until the generator returns a \s-1NULL\s+1 ! 183: for the text field in the \fITitem\fP structure, ! 184: indicating the end of the menu selections. ! 185: .TP ! 186: .B menumap ! 187: In applications where many menus are to be used, ! 188: the programmer can re-define the \fITitem\fP structure to include ! 189: only those fields that are actually used. ! 190: This has the advantage of requiring less data initialization ! 191: on the part of the programmer. It is done with a ! 192: bit vector called \fImenumap\fP in the \fITmenu\fP structure. ! 193: If used, the user defined structure replacing \fITitem\fP must contain ! 194: the specified member variables in the same order. ! 195: For example, if one wishes to use only the text, ufield, and next fields ! 196: of a \fITitem\fP structure, he may define a \fITitem\fP structure with ! 197: only those fields, and then set the menumap field of the \fITmenu\fP ! 198: structure to the value of (TM_TEXT|TM_UFIELD|TMNEXT). ! 199: Normally, this variable has the value zero when the standard \fITitem\fP ! 200: structure is used. ! 201: .PP ! 202: Each menu item is defined by a structure of the type \fITitem\fP. ! 203: The ! 204: .B Titem ! 205: structure has the following fields: ! 206: .TP ! 207: .B text ! 208: The text field is a pointer to a NULL terminated character string. This ! 209: is the character string that is displayed within the menu. ! 210: .sp ! 211: A facility provided by ! 212: .I tmenuhit ! 213: is that of a spread character. ! 214: A spread character is any ascii character with the high-order bit set ! 215: (e.g., an ascii space character defined as a spread character would have ! 216: the value of \'\\240\'). ! 217: The spread character acts somewhat like a spring pushing against ! 218: the adjacent text and borders within a menu entry. ! 219: The spread character can be placed at the beginning, middle, or end ! 220: of the string defining the menu entry. ! 221: If placed at the beginning of the string, ! 222: the text in the menu item will be right-justified. ! 223: If placed at the end of the string, ! 224: the text will be left justified. ! 225: If placed in the middle of the string, the text on each ! 226: side of the spread character will be pushed against the corresponding ! 227: menu border. In each case, ! 228: the space created by the spread character will be filled in with ! 229: the ascii character contained in the spread character. ! 230: For entries without a spread character, ! 231: the default is to have the text centered. ! 232: .TP ! 233: .B uval ! 234: This is an integer to be used for any purpose the user wishes. ! 235: It is typically used to store a constant that is used by the application ! 236: to identify \fITitem\fP structures. ! 237: For instance, this field could be set to a unique value for each menu ! 238: item in the menu tree. In this way, a switch statement ! 239: can easily determine the menu item selection regardless of the menu used ! 240: and the difference in size of different \fITitem\fP structures. ! 241: .TP ! 242: .B grey ! 243: If this field is set to 1, the item will be displayed in ! 244: the menu with a grey background. This item is non-selectable and, if ! 245: selected, the value \fItmenuhit\fP returns is 0. ! 246: .TP ! 247: .B next ! 248: The \fInext\fP variable points to another menu structure of type \fITmenu\fP ! 249: which defines a submenu for this particular item. ! 250: .TP ! 251: .B icon ! 252: The icon field is a pointer to a Bitmap structure that is ! 253: displayed to the left of the menu item. The size of the bitmap is ! 254: specified within the Bitmap structure and can vary from one menu item to ! 255: the next. ! 256: The icon can be displayed with or without a text string. ! 257: However, if icons are to be used without text strings, the value of \fItext\fP ! 258: field cannot be NULL, but must point to a NULL string. ! 259: .sp ! 260: When the icon field is used to display a bitmap, ! 261: all \fITitem\fP structures for the specific menu are scanned to find the largest ! 262: bitmap. This is used to determine the vertical spacing of all the menu ! 263: items within that menu. Smaller bitmaps on other menu entries will be ! 264: centered within the icon area. ! 265: .TP ! 266: .B font ! 267: The font field is a pointer to a font to be used for the text ! 268: is this menu item. Proportional ! 269: characters and different point size fonts will be positioned appropriately. ! 270: If a NULL value is specified, the 630 resident medium font is used. ! 271: .TP ! 272: .B dfn, bfn, hfn ! 273: These three fields may be initialized to point to functions that will ! 274: be executed by \fItmenuhit\fP before entering ! 275: a submenu (sliding \fIdown\fP), ! 276: after returning from a submenu (sliding \fIback\fP), ! 277: and upon making a selection in the current menu (a \fIhit\fP), respectively. ! 278: Each function is passed, as an argument, ! 279: the address of the \fITitem\fP structure from which it is called. ! 280: The hfn function provides an alternative method to using the return value of ! 281: .I tmenuhit. ! 282: .sp ! 283: In the special case of (flags & TM_NORET), ! 284: when a selection is made, the submenu the item ! 285: was in will be erased. Then ! 286: the hfn function ! 287: will be called with the selected item. If there is a parent ! 288: to this menu ! 289: the bfn and dfn functions will also be called in that order (if they ! 290: are initialized) ! 291: after which the menu will be redrawn. ! 292: This is due to the recursiveness of ! 293: .I tmenuhit. ! 294: .sp ! 295: If any of the dfn, bfn, or hfn functions execute calls to the ! 296: function ! 297: .I tmret(), tmenuhit ! 298: will ignore the TM_NORET flag and will return the selection made. ! 299: .SH EXAMPLE ! 300: The following example is a comprehensive example of how one may use ! 301: .I tmenuhit. ! 302: The example presents a menu tree when button 3 is depressed and, ! 303: upon selection of a menu item, it ! 304: prints the text of that item at the bottom of the screen. ! 305: The top level menu contains six items each pointing to a submenu. ! 306: They are ! 307: .I font, test, bttn3, icons, spread, ! 308: and ! 309: .I scroll. ! 310: The following is a brief explanation of each submenu and the functions it ! 311: intends to demonstrate. ! 312: .TP ! 313: .I font ! 314: The font submenu demonstrates the use of fonts and icons ! 315: (within the menu item) and the use of the hfn and dfn functions. ! 316: An hfn function called setfont is executed on selection and ! 317: sets the font to the selected font. Before the font submenu ! 318: is displayed, a dfn function called setmark will place a checkmark icon ! 319: next to the current font in use. ! 320: .TP ! 321: .I test ! 322: This submenu contains various sized ! 323: strings to demonstrate how \fItmenuhit\fP alters its menu item size ! 324: according to the size of ! 325: the string. ! 326: .TP ! 327: .I bttn3 ! 328: This is a replica of the button3 menu ! 329: on the 630MTG. It demonstrates the menu greying capability. This item also ! 330: demonstrates how one may use \fItmenuhit\fP to achieve the ! 331: simple functionality of \fImenuhit\fP plus the added capability ! 332: of greying items. ! 333: .TP ! 334: .I icons ! 335: This submenu demonstrates the use ! 336: of icons within menu items. ! 337: .TP ! 338: .I spread ! 339: This submenu ! 340: demonstrates the spread character facility. ! 341: .TP ! 342: .I scroll ! 343: This submenu ! 344: demonstrates the use of generators and presents the scrolling menu. ! 345: .P ! 346: Another thing to notice is the use of the abbreviated \fITitem\fP ! 347: structures. There are six different types of \fITitem\fP structures. Each ! 348: one corresponds to a menumap vector which defines the fields being used. ! 349: .PP ! 350: .RS 0 ! 351: \s-1 ! 352: .nf ! 353: .ft CM ! 354: #include <dmd.h> ! 355: #include <font.h> ! 356: #include <menu.h> ! 357: ! 358: void setmark(), setfont(); ! 359: Titem *scrllist(); ! 360: extern Tmenu menu20, menu21, menu22, menu23, menu24, menu25; ! 361: extern Tmenu menu30; ! 362: ! 363: Word strawberry[] = { ! 364: 0x0000,0x0000,0x0000, ! 365: 0x0000,0x0000,0x0000, ! 366: 0x0000,0x0000,0x0000, ! 367: 0x0000,0x1B80,0x0000, ! 368: 0x0000,0x3D80,0x0000, ! 369: 0x01F8,0x7E80,0x0000, ! 370: 0x03FE,0x7D80,0x0000, ! 371: 0x07AF,0xFB80,0x0000, ! 372: 0x0EF9,0xF780,0x0000, ! 373: 0x1F57,0xFFFE,0x0000, ! 374: 0x1FFB,0xFEAB,0x8000, ! 375: 0x1DAD,0xF77D,0xC000, ! 376: 0x3FFA,0x65B7,0x4000, ! 377: 0x3AAF,0x8FDE,0xE000, ! 378: 0x3FFD,0xFECB,0xA000, ! 379: 0x3BB7,0x5FEE,0xE000, ! 380: 0x3EFD,0xFAAB,0xA000, ! 381: 0x3FAF,0xAFEE,0xE000, ! 382: 0x3AFA,0xFD6B,0xA000, ! 383: 0x3FAF,0xD7DF,0xE000, ! 384: 0x3EFA,0xFED5,0x4000, ! 385: 0x1FAF,0xABBF,0xC000, ! 386: 0x1EFA,0xFFAA,0x8000, ! 387: 0x1FAF,0xD77F,0x8000, ! 388: 0x1FFD,0x7ED5,0x0000, ! 389: 0x0F57,0xD9FE,0x0000, ! 390: 0x0FFE,0xF754,0x0000, ! 391: 0x07AB,0xCDFC,0x0000, ! 392: 0x03FF,0x7EA8,0x0000, ! 393: 0x00F8,0x3BF0,0x0000, ! 394: 0x0000,0x1EE0,0x0000, ! 395: 0x0000,0x0F80,0x0000, ! 396: 0x0000,0x0000,0x0000, ! 397: 0x0000,0x0000,0x0000, ! 398: }; ! 399: ! 400: Word help_icon[] = { ! 401: 0x0000, 0x0000, 0x0000, 0x0000, ! 402: 0xE0E0, 0x6060, 0x7F7E, 0x7DFF, ! 403: 0x6FFB, 0x6C7B, 0x6FFE, 0xFFF8, ! 404: 0x003C, 0x0000, 0x0000, 0x0000, ! 405: }; ! 406: ! 407: ! 408: /* initialize Bitmap structures */ ! 409: Bitmap bm_strawberry = { ! 410: (Word*) strawberry, 3, 2, 0, 36, 34, 0 ! 411: }; ! 412: Bitmap bm_help = { ! 413: (Word*) help_icon, 1, 0, 0, 16, 16, 0 ! 414: }; ! 415: ! 416: /*******************************/ ! 417: /* definitions for menumap */ ! 418: /*******************************/ ! 419: #define TYPE1 TM_TEXT | TM_NEXT | TM_DFN ! 420: #define TYPE2 TM_TEXT ! 421: #define TYPE3 TM_TEXT | TM_NEXT ! 422: #define TYPE4 TM_TEXT | TM_UFIELD ! 423: #define TYPE5 TM_TEXT | TM_ICON ! 424: #define TYPE6 TM_TEXT | TM_ICON | TM_FONT | TM_HFN ! 425: ! 426: /*******************************/ ! 427: /* define Titem typedef's */ ! 428: /*******************************/ ! 429: ! 430: /* ! 431: * define a Titem structure with only text, next, and dfn fields ! 432: */ ! 433: typedef struct Titem01 ! 434: { ! 435: char *text; /* string for menu */ ! 436: struct Tmenu *next; /* pointer to sub-menu */ ! 437: void (*dfn)(); /* pointer function to execute on submenu */ ! 438: } Titem01; ! 439: ! 440: /* ! 441: * define a Titem structure with only text field ! 442: */ ! 443: typedef struct Titem2 ! 444: { ! 445: char *text; /* string for menu */ ! 446: } Titem2; ! 447: ! 448: /* ! 449: * define a Titem structure with only text and next fields ! 450: */ ! 451: typedef struct Titem3 ! 452: { ! 453: char *text; /* string for menu */ ! 454: struct Tmenu *next; /* pointer to sub-menu */ ! 455: } Titem3; ! 456: ! 457: /* ! 458: * define a Titem structure with only text and ufield fields ! 459: */ ! 460: typedef struct Titem4 ! 461: { ! 462: char *text; /* string for menu */ ! 463: struct { ! 464: unsigned short uval; /* user field */ ! 465: unsigned short grey; /* flag indicates invalid selection */ ! 466: } ufield; ! 467: } Titem4; ! 468: ! 469: ! 470: /* ! 471: * define a Titem structure with only text and icon fields ! 472: */ ! 473: typedef struct Titem5 ! 474: { ! 475: char *text; /* string for menu */ ! 476: Bitmap *icon; /* pointer to the icons bitmap */ ! 477: } Titem5; ! 478: ! 479: ! 480: /* ! 481: * define a Titem structure with only text, icon, font and hfn fields ! 482: */ ! 483: typedef struct Titem6 ! 484: { ! 485: char *text; /* string for menu */ ! 486: Bitmap *icon; /* pointer to the icons bitmap */ ! 487: Font *font; /* pointer to font structure */ ! 488: void (*hfn)(); /* function to execute on selection */ ! 489: } Titem6; ! 490: ! 491: /*******************************/ ! 492: /* initialize Titem structures */ ! 493: /*******************************/ ! 494: ! 495: /* ! 496: * initialize the Titem structure for the main menu ! 497: * has only text, next and dfn fields ! 498: */ ! 499: Titem01 L1_root[] = ! 500: { ! 501: "font", &menu20, setmark, ! 502: "test", &menu21, 0, ! 503: "bttn3", &menu22, 0, ! 504: "icons", &menu23, 0, ! 505: "spread", &menu24, 0, ! 506: "scroll", &menu25, 0, ! 507: 0 ! 508: }; ! 509: ! 510: ! 511: /* ! 512: * initialize the Titem structure for menu20 ! 513: * has only text, icon, font, hfn fields ! 514: */ ! 515: Titem6 L2_font[] = ! 516: { ! 517: "smallfont", 0, 0, setfont, ! 518: "mediumfont", 0, 0, setfont, ! 519: "largefont", 0, 0, setfont, ! 520: 0 ! 521: }; ! 522: ! 523: /* ! 524: * initialize the Titem structure for menu21 ! 525: * has only text and next fields ! 526: */ ! 527: Titem3 L2_test[] = ! 528: { ! 529: "A long test string so we can see what happens", 0, ! 530: "Short strings", &menu30, ! 531: 0 ! 532: }; ! 533: ! 534: /* ! 535: * initialize the Titem structure for menu22 ! 536: * has only text and ufield fields ! 537: */ ! 538: Titem4 L2_bttn3[] = ! 539: { ! 540: "New", 0, 1, ! 541: "Reshape", 0, 1, ! 542: "Top", 0, 1, ! 543: "Bottom", 0, 1, ! 544: "Current", 0, 1, ! 545: "Delete", 0, 1, ! 546: "Exit", 0, 0, ! 547: 0 ! 548: }; ! 549: ! 550: /* ! 551: * initialize the Titem structure for menu23 ! 552: * has only text and icon fields ! 553: */ ! 554: Titem5 L2_icons[] = ! 555: { ! 556: "strawberry", &bm_strawberry, ! 557: "help", &bm_help, ! 558: 0 ! 559: }; ! 560: ! 561: ! 562: /* ! 563: * initialize the Titem structure for menu24 ! 564: * has only text field ! 565: */ ! 566: Titem2 L2_spread[] = ! 567: { ! 568: "left\\240", /* space character with high bit set */ ! 569: "\\256right", /* . char with high bit set */ ! 570: "middle", ! 571: "left\\337right", /* _ char with high bit set */ ! 572: "a very long string", ! 573: 0 ! 574: }; ! 575: ! 576: /* ! 577: * initialize the Titem structure for menu30 ! 578: * has only text field ! 579: */ ! 580: Titem2 L3_shorts[] = ! 581: { ! 582: "abc", ! 583: "xyz", ! 584: "123", ! 585: "XYZ", ! 586: "ABC", ! 587: 0 ! 588: }; ! 589: ! 590: ! 591: /*******************************/ ! 592: /* initialize Tmenu structures */ ! 593: /*******************************/ ! 594: /* ! 595: * menu(xy), where x is the level and y is the menu number ! 596: */ ! 597: Tmenu menu10 = { (Titem *) L1_root, 0, 0, 0, TYPE1 }; ! 598: Tmenu menu20 = { (Titem *) L2_font, 2, 0, 0, TYPE6 }; ! 599: Tmenu menu21 = { (Titem *) L2_test, 0, 0, 0, TYPE3 }; ! 600: Tmenu menu22 = { (Titem *) L2_bttn3, 0, 0, 0, TYPE4 }; ! 601: Tmenu menu23 = { (Titem *) L2_icons, 0, 0, 0, TYPE5 }; ! 602: Tmenu menu24 = { (Titem *) L2_spread, 0, 0, 0, TYPE2 }; ! 603: Tmenu menu25 = { (Titem *) 0, 0, 0, scrllist, 0 }; ! 604: Tmenu menu30 = { (Titem *) L3_shorts, 0, 0, 0, TYPE2 }; ! 605: ! 606: char noselect[] = "no selection"; ! 607: Font *font; ! 608: ! 609: main() ! 610: { ! 611: Titem *ret; ! 612: ! 613: /* set the font and icon fields in the proper menu */ ! 614: L2_font[0].font = &smallfont; ! 615: L2_font[1].font = &mediumfont; ! 616: L2_font[2].font = &largefont; ! 617: L2_font[1].icon = &B_checkmark; ! 618: font = &largefont /* use the medium font to start with */ ! 619: request(MOUSE); ! 620: while(wait(MOUSE)) { ! 621: if (button3()) { ! 622: /* clear the text area for writing strings */ ! 623: cursinhibit(); ! 624: rectf(&display, ! 625: Rpt(Pt(Drect.origin.x, Drect.corner.y-18), Drect.corner), ! 626: F_CLR); ! 627: cursallow(); ! 628: if(ret = tmenuhit (&menu10, 3, TM_EXPAND)) { ! 629: /* write the menu string in text area */ ! 630: string(font, ret->text, &display, ! 631: Pt(Drect.origin.x+5, Drect.corner.y-18), ! 632: F_XOR); ! 633: } ! 634: else { /* no selection was made */ ! 635: string(font, noselect, &display, ! 636: Pt(Drect.origin.x+5, Drect.corner.y-18), ! 637: F_XOR); ! 638: } ! 639: } ! 640: else if (button1()) ! 641: exit(); ! 642: } ! 643: } ! 644: ! 645: char digits[10]; ! 646: Titem scrlitem; ! 647: char scrlstr[] = "scroll"; ! 648: ! 649: /* ! 650: * generator for scroll menu ! 651: * generate 99 menu items ! 652: */ ! 653: Titem *scrllist(i, m) ! 654: int i; ! 655: Tmenu *m; ! 656: { ! 657: int j; ! 658: ! 659: if (i > 99) { /* generator stopping condition */ ! 660: scrlitem.text = 0; ! 661: } ! 662: else { /* generate text for items (i.e. "scroll56") */ ! 663: scrlitem.text = digits; ! 664: for (j=0; scrlstr[j] != '\\0'; j++) digits[j] = scrlstr[j]; ! 665: digits[j++] = i/10 + '0'; ! 666: digits[j++] = i - (i/10 * 10) + '0'; ! 667: digits[j] = '\\0'; ! 668: } ! 669: return ( &scrlitem ); ! 670: } ! 671: ! 672: /* ! 673: * a dfn function. ! 674: * This is executed before the font submenu is entered ! 675: * place the checkmark by the proper font ! 676: */ ! 677: void setmark(mi) ! 678: Titem01 *mi; ! 679: { ! 680: Tmenu *tm; ! 681: Titem6 *tmi; ! 682: int index; ! 683: int hit; ! 684: ! 685: tm = mi->next; ! 686: hit = tm->prevhit + tm->prevtop; ! 687: for (index=0, tmi=(Titem6 *)tm->item; tmi->text; index++, tmi++) { ! 688: tmi->icon = (index == hit) ? &B_checkmark:0; ! 689: } ! 690: } ! 691: ! 692: /* ! 693: * an hfn function ! 694: * this is executed after a selection is made ! 695: */ ! 696: void setfont(mi) ! 697: Titem6 *mi; ! 698: { ! 699: /* set the font to the selected font */ ! 700: font = mi->font; ! 701: } ! 702: \fR ! 703: .fi ! 704: .RE ! 705: \s+1 ! 706: .SH SEE ALSO ! 707: menuhit(3L), structures(3R). ! 708: .SH WARNINGS ! 709: Common uses for user-provided functions in the \fITitem\fP structure ! 710: include modifying the members of menu data structures ! 711: such as the \fIicon\fP ! 712: and \fIgrey\fP fields. The user must be careful that such menu structures are ! 713: properly initialized. ! 714: .PP ! 715: Whenever a menu is displayed, the screen image obscured by the menu is ! 716: saved in a bitmap and then later restored when the menu disappears. ! 717: If the terminal is ! 718: out of memory and therefore cannot save the screen image, ! 719: then the menu will be displayed in \s-1XOR\s+1 (exclusive or) ! 720: mode on top of the existing screen image. ! 721: Menu items may still be selected in this mode but ! 722: may be difficult to read. ! 723: To remedy this problem, ! 724: memory may be freed up by either deleting or ! 725: reshaping windows before the menu is displayed. ! 726: .PP ! 727: Because the \fItmenuhit\fR code is recursive, ! 728: an arbitrary limit to a depth of eight ! 729: menus is defined to avoid stack overflow. ! 730: .PP ! 731: The user should be careful not to perform screen writes from within the ! 732: dfn, bfn, or hfn functions. Any writes to the screen from within these ! 733: functions can corrupt the displayed menu.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.