home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c070 / 1.ddi / TOOLS.1 / INCLUDE / BMENU.H < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-31  |  13.3 KB  |  387 lines

  1. /**
  2. *
  3. *  BMENU.H    Header file for Turbo C TOOLS Menu Functions
  4. *
  5. *  Version    6.00 (C)Copyright Blaise Computing Inc.  1987,1989
  6. *
  7. **/
  8.  
  9.  
  10. #ifndef DEF_BMENU        /* Prevent redefinition.        */
  11.  
  12. #define DEF_BMENU  1        /* Prevent second reading of        */
  13.                 /* these definitions.            */
  14. #include <bkeybrd.h>
  15. #include <bwindow.h>
  16.  
  17. /* Error constants specific to MENU operations.             */
  18. #define MN_BAD_MENU    100    /* Menu failed test by MNVALMNU.    */
  19. #define MN_NONE_SELECT    101    /* No selectable item on menu.        */
  20. #define MN_KEY_CONFLICT 102    /* A key not bound to a location    */
  21.                 /* already exists with the given    */
  22.                 /* character and key codes.        */
  23. #define MN_NO_ITEM    103    /* No item exists at the given        */
  24.                 /* coordinates.             */
  25. #define MN_BAD_KEY    104    /* Invalid keymap entry encountered.*/
  26. #define MN_BAD_ITEM    105    /* Invalid item encountered.        */
  27. #define MN_NO_EXIT    106    /* No enabled key has either the    */
  28.                 /* transmit or abort bit set.        */
  29.  
  30. #define MN_READ_AB    110    /* User pressed a key with MN_ABORT */
  31.                 /* action associated with it.        */
  32. #define MN_UNKNOWN_AB    111    /* User pressed a key unknown to    */
  33.                 /* the menu, and MN_UNKNOWN_TRANSMIT*/
  34.                 /* was an option passed to a menu   */
  35.                 /* reader function.            */
  36. #define MN_NO_MOU_EVENT 120    /* No matching mouse event found.   */
  37. #define MN_MOU_CONFLICT 121    /* Cannot add an existing mouse     */
  38.                 /* event.                */
  39. #define MN_BAD_MOUSE    122    /* Invalid mouse node.            */
  40. #define MN_XMIT_NOBAR    130    /* Transmit without highlight bar.  */
  41.  
  42.  
  43. #define MN_KEY_SIGN  0x0123    /* Arbitrary signature words.        */
  44. #define MN_ITEM_SIGN 0x0320
  45. #define MN_MOU_SIGN  0x4567
  46.  
  47. #define MN_DEAD_KEY  0xffef    /* Arbitrary "deleted" signature    */
  48. #define MN_DEAD_ITEM 0x0000    /* words for same.            */
  49. #define MN_DEAD_MOUSE 0x6745
  50.  
  51.  
  52. /* Constants for use with MNKEY (the "howchange" argument).         */
  53. #define MN_ADD       0
  54. #define MN_CHANGE  1
  55. #define MN_DELETE  2
  56.  
  57. /* Constants for use with MNKEY (the "action" argument).            */
  58. #define MN_NOMOVE     0x000
  59. #define MN_UP         0x001
  60. #define MN_DOWN      0x002
  61. #define MN_RIGHT     0x003
  62. #define MN_LEFT      0x004
  63. #define MN_NEXT      0x005
  64. #define MN_PREVIOUS     0x006
  65. #define MN_FIRST     0x007
  66. #define MN_LAST      0x008
  67. #define MN_SELECT     0x009
  68. #define MN_PGUP      0x00a
  69. #define MN_PGDN      0x00b
  70. #define MN_PGRIGHT     0x00c
  71. #define MN_PGLEFT     0x00d
  72.  
  73. #define MN_TRANSMIT     0x010
  74. #define MN_BEEP      0x020
  75. #define MN_TEMP_DISABLE  0x040
  76. #define MN_DISABLE     0x080
  77. #define MN_ABORT     0x100
  78.  
  79. #define MN_KBIGNORE     0x200        /* Also duplicated below.        */
  80. #define MN_HIDE_BAR     0x800        /* Also duplicated below.        */
  81. #define MN_SHOW_BAR    0x1000        /* Also duplicated below.        */
  82.  
  83. #define MN_NOWRAP    0x0400
  84.  
  85. #define MN_MOVE_MASK 0x00f
  86. #define MNMOVE(action) ((action) & MN_MOVE_MASK)
  87.  
  88. #define MN_INVALID_ACTION 0x4f3
  89.  
  90.  
  91. /* Constants for use with adding/changing of items.            */
  92. #define MN_PROTECT    0x0001
  93. #define MN_NOPROTECT    0x0000
  94. #define MN_CHAR_ATTR    0x0002
  95. #define MN_CHARS_ONLY    0x0000
  96.  
  97.  
  98. /* Constants for use with MNREAD (the "option" value).              */
  99. #define MN_REMOVE         0x01
  100. #define MN_DESTROY         0x03
  101. #define MN_KEEP_HIGHLIGHT    0x04
  102. #define MN_ALL_TRANSMIT      0x08
  103. #define MN_UNKNOWN_BEEP      0x10
  104. #define MN_UNKNOWN_TRANSMIT  0x20
  105. #define MN_KEEP_DESCRIPTION  0x40
  106. #define MN_HOLD_BEEP         0x80
  107.  
  108. #define MN_KBIGNORE        0x200   /* Also duplicated above.        */
  109. #define MN_KBDISCARD        0x400   /* Internal use only.        */
  110. #define MN_HIDE_BAR        0x800   /* Also duplicated above.        */
  111. #define MN_SHOW_BAR       0x1000   /* Also duplicated above.        */
  112. #define MN_PREV_BAR       0x2000
  113. #define MN_USE_DESCRIPTION 0x4000
  114.  
  115.  
  116. /* Constants for use with MNATR, MNHILITE.                */
  117. #define MN_UNHIGHLIGHT         0x00
  118. #define MN_HIGHLIGHT         0x01
  119.  
  120. /* Menu mouse styles.                            */
  121. #define MN_MOU_CLICK        1
  122. #define MN_MOU_DRAG        2
  123. #define MN_MOU_ALT_DRAG     3
  124.  
  125.  
  126. /* Definitive signature for signature field in BMENU structure.     */
  127. #define BMENU_SIGN       0xf001
  128. #define BMENU_DEAD        0
  129.  
  130. /* Mouse events in addition to those defined in BMOUSE.H.        */
  131. #define MN_OUT_MENU    0x0100
  132. #define MN_ITEMS    0x0200
  133. #define MN_OFF_ITEMS    0x0400
  134.  
  135.  
  136. /* User macros.                             */
  137.  
  138. #define mncreate(height,width,textattr,hilattr,proattr,longattr)     \
  139.        (mncreat0((height),(width),(textattr),(hilattr),          \
  140.          (proattr),(longattr),(BMENU_SIGN)))
  141.  
  142. #define mndsplay(pmenu,pwhere,pbord)                     \
  143.        (mnvdisp((pmenu),(pwhere),                     \
  144.         wndata_h((pmenu)->pwin),wndata_w((pmenu)->pwin),     \
  145.         0,0,(pbord)))
  146.  
  147. #define mnlread(pmenu,srow,scol,prow,pcol,pch,pscan,option)         \
  148.        (mnread((pmenu),(srow),(scol),(prow),(pcol),(pch),(pscan),    \
  149.            (option) | MN_USE_DESCRIPTION))
  150.  
  151.  
  152. /* Internal Macros.                            */
  153. #define mnvalidm(pmenu)                          \
  154.     {                                     \
  155.     if (mnvalmnu (pmenu) == NIL)                     \
  156.         wnreterr (MN_BAD_MENU);                     \
  157.     }
  158.  
  159. #define mntrunc(pmenu, length, col)                     \
  160.         (((length + col) > pmenu->pwin->img.dim.w)         \
  161.         ? (pmenu->pwin->img.dim.w - col)             \
  162.         : (length))
  163.  
  164. #define mnvalmnu(pmenu)  (mnvalmn0((pmenu),(BMENU_SIGN)))
  165.  
  166. /* Definitions of data types.                        */
  167.  
  168.         /* BITEM -- data structure for an item in a menu.   */
  169. typedef struct bitem
  170. {
  171.     unsigned signature;     /* Characteristic signature.        */
  172.     int      row, col;        /* Coordinates (relative to window) */
  173.                 /* of menu item text.            */
  174.     int      lrow, lcol;    /* Row and column at which to put   */
  175.                 /* long description.            */
  176.     int      attr;        /* Attribute of this item.        */
  177.     int      len;        /* Length of ASCII text of menu     */
  178.                 /* item.                */
  179.     int      llen;        /* Length of ASCII text of menu     */
  180.                 /* description.             */
  181.     int      option;        /* Bitwise OR-ing of:            */
  182.                 /*   MN_PROTECT (protected item)    */
  183.                 /*   MN_NOPROTECT (unprotected item)*/
  184.     char    *plstring;        /* Long description of item.  Used  */
  185.                 /* by "Lotus" menu functions.       */
  186.     char    *pcharattr;     /* Pointer to mixed character/        */
  187.                 /*   attribute item string.        */
  188.     struct   bitem *next;    /* Pointer to next item         */
  189. } BITEM;            /* specification in linked list.    */
  190.  
  191.  
  192.         /* BKEYMAP -- data structure for a key associated   */
  193.         /*          with a menu.                */
  194. typedef struct bkeymap
  195. {
  196.     unsigned signature;     /* Characteristic signature.        */
  197.     int      ch;        /* Character and scan code with     */
  198.     int      scan;        /* which the following action is to */
  199.                 /* be associated with.            */
  200.                 /*                    */
  201.     int      row, col;        /* The row and column this keycode  */
  202.                 /* is associated with.            */
  203.                 /*                    */
  204.     int      action;        /* The action which should be taken */
  205.                 /* when (ch,scan) is received by    */
  206.                 /* MNREAD:                */
  207.                 /*                    */
  208.                 /* The bitwise OR-ing of the        */
  209.                 /* following:                */
  210.                 /*     MN_TRANSMIT, MN_BEEP,        */
  211.                 /*     MN_SELECT, MN_DISABLE,        */
  212.                 /*     and MN_ABORT,            */
  213.                 /*                    */
  214.                 /*   OR-ed with only one of:        */
  215.                 /*                    */
  216.                 /*     MN_UP, MN_DOWN, MN_RIGHT,    */
  217.                 /*     MN_LEFT, MN_NEXT,        */
  218.                 /*     MN_PREVIOUS, MN_FIRST,        */
  219.                 /*     MN_LAST, or MN_NOMOVE.        */
  220.                 /*                    */
  221.     struct   bkeymap *next;    /* Pointer to next key in keymap.   */
  222. } BKEYMAP;
  223.  
  224.  
  225.         /* BKEYTAB -- data structure for a default key table*/
  226.         /*          entry.                    */
  227. typedef struct bkeytab
  228. {
  229.     int      ch;        /* Character and scan code with     */
  230.     int      scan;        /* which the following action is to */
  231.                 /* be associated with.            */
  232.                 /*                    */
  233.     int      action;        /* The action which should be taken */
  234.                 /* when (ch,scan) is received by    */
  235.                 /* MNREAD: (see above).         */
  236. } BKEYTAB;
  237.  
  238. typedef struct bmnmouse_node    /* BMNMOUSE:  Menu mouse event.     */
  239. {
  240.     unsigned      signature;
  241.     unsigned long event;
  242.     unsigned long ignore;
  243.     int       action;
  244.     struct bmnmouse_node *pnext;
  245.     struct bmnmouse_node *pprev;
  246. } BMNMOUSE;
  247.  
  248.  
  249.         /* BMENU -- Data structure which governs behavior   */
  250.         /*        and appearance of a menu.            */
  251. typedef struct
  252. {
  253.     unsigned   signature;    /* Characteristic signature.        */
  254.                 /*                    */
  255.     BWINDOW   *pwin;        /* The window we use.            */
  256.                 /*                    */
  257.     BITEM     *pitems;        /* The items to display in the        */
  258.                 /* window.                */
  259.                 /*                    */
  260.     BKEYMAP   *pkeys;        /* The key definitions used.        */
  261.                 /*                    */
  262.     int        hilattr;     /* Highlight bar attributes.        */
  263.     int        proattr;     /* Protected attributes.        */
  264.     int        longattr;    /* Description attributes.        */
  265.     BMNMOUSE  *pmouse;        /* List of mouse events.        */
  266.     BITEM     *pbar_item;    /* Currently highlighted item, or   */
  267.                 /* NIL if none.             */
  268.     BITEM     *pbar_prev;    /* Previously highlighted item if   */
  269.                 /* pbar_item is NIL.            */
  270.  
  271.     struct            /* Internal items.            */
  272.     {                /*                    */
  273.     unsigned desc_shown: 1; /* Lotus description shown.        */
  274.     unsigned _dummy    :15; /* Pad to word boundary.        */
  275.     } internals;
  276. } BMENU;
  277.  
  278.  
  279.         /* Most recent mouse menu event.            */
  280. extern unsigned long b_mnmoevent; /* Event, or OL if none.        */
  281. extern unsigned      b_mnmovert;  /* Row and column where event took*/
  282. extern unsigned      b_mnmohoriz; /*  place, or 0xffff if none.     */
  283.  
  284.         /* Pointer to current default key map.            */
  285. extern BKEYTAB *b_mnkeytab;
  286.  
  287.         /* Original default key map.                */
  288. extern BKEYTAB b_mndefkey [];
  289.  
  290.  
  291. /* Function declarations -- User functions.                */
  292. BMENU *cdecl mnvdisp(BMENU *,    /* Display a menu.  Necessary        */
  293.   const WHERE *,int,int,int,int,/* before using MNREAD.         */
  294.   const BORDER *);        /*                    */
  295.                 /*                    */
  296. int cdecl mndstroy (BMENU *);    /* Release menu data structures,    */
  297.                 /* undisplay if necessary.        */
  298.                 /*                    */
  299. BMENU *cdecl mnitem (BMENU *,    /* Add/Change/Delete item in menu.  */
  300.          int, int, int, /*                    */
  301.          const char *); /*                    */
  302.                 /*                    */
  303. BMENU *cdecl mnitmkey (BMENU *, /* Add item and key bindings for    */
  304.          int, int, int, /* that item to menu.            */
  305.        const char *,    /*                    */
  306.        const char *, int);    /*                    */
  307.                 /*                    */
  308. BMENU *cdecl mnkey (BMENU *,    /* Add a key binding to a menu.     */
  309.          int, int, int, /*                    */
  310.          int, int, int);/*                    */
  311.                 /*                    */
  312. BMENU *cdecl mnlitem  (BMENU *, /* Add/Change/Delete item in        */
  313.          int, int, int, /* "Lotus"-style menu.              */
  314.        const char *,    /*                    */
  315.          int, int,    /*                    */
  316.        const char *);    /*                    */
  317.                 /*                    */
  318. BMENU *cdecl mnlitkey (BMENU *, /* Add "Lotus" item and key         */
  319.          int, int, int, /* bindings for that item to menu.  */
  320.        const char *,    /*                    */
  321.          int, int,    /*                    */
  322.        const char *,    /*                    */
  323.        const char *, int);    /*                    */
  324.                 /*                    */
  325. BMENU *cdecl mnmstyle(BMENU *,    /* Install a mouse style.        */
  326.     int,unsigned);        /*                    */
  327.                 /*                    */
  328. BMENU *cdecl mnmouse(BMENU *,    /* Add, change, or delete a menu    */
  329.     unsigned long,unsigned long,/* mouse event.             */
  330.     int,int);            /*                    */
  331.                 /*                    */
  332. BMENU *cdecl mnhilite(BMENU *,    /* Move or remove highlight bar     */
  333.     int,int,int);        /* or item description.         */
  334.                 /*                    */
  335. int cdecl mnread (BMENU *, int, /* Request user input from a menu.  */
  336.          int, int *,    /*                    */
  337.          int *, int *,    /*                    */
  338.          int *, int);    /*                    */
  339.  
  340.  
  341. /* Function declarations -- Internal functions.             */
  342. BMENU *cdecl mnatr (BMENU *,    /* Change attributes on an item in  */
  343.       const BITEM *, int);    /* a menu.                */
  344.                 /*                    */
  345. BMENU *cdecl mncreat0 (int,    /* Create menu data structures,     */
  346.     int, int, int,        /* set up default key bindings and  */
  347.     int, int, unsigned);    /* attributes.                */
  348.                 /*                    */
  349. BMENU *cdecl mndefkey (BMENU *);/* Set up default keys for a menu.  */
  350.                 /* Internal function -- redefine if */
  351.                 /* you want different default key   */
  352.                 /* bindings.                */
  353.                 /*                    */
  354. BMENU *cdecl mndisabl (BMENU *);/* Disable all keys which are bound */
  355.                 /* to locations for which no items  */
  356.                 /* exist -- disable unbound keys.   */
  357.                 /*                    */
  358. int cdecl mndlitms (BMENU *);    /* Delete all items from a menu     */
  359.                 /* item list data structure.        */
  360.                 /*                    */
  361. int cdecl mndlkeys (BMENU *);    /* Delete all keys from a menu key  */
  362.                 /* list data structure.         */
  363.                 /*                    */
  364. BITEM *cdecl mnfindsl (BMENU *, /* Find the first selectable item   */
  365.          BITEM *,    /* in a menu, given starting        */
  366.          int, int,    /* coordinates and menu item.        */
  367.          int *);    /*                    */
  368.                 /*                    */
  369. BMENU *cdecl mnhilit0(BMENU *,    /* Move or remove highlight bar     */
  370.     BITEM *,int);        /* or item description.         */
  371.                 /*                    */
  372. BITEM *cdecl mnmchitm (BMENU *, /* Match a menu item to a (row,col) */
  373.          BITEM *,    /* specification.            */
  374.          int, int,    /*                    */
  375.          int, int *);    /*                    */
  376.                 /*                    */
  377. const BKEYMAP *cdecl mnmchkey ( /* Match a menu keymap entry to a   */
  378.          const BMENU *,    /* (ch,scan) specification.        */
  379.          const BKEYMAP *,    /*                    */
  380.            int, int,    /*                    */
  381.            int *);    /*                    */
  382.                 /*                    */
  383. BMENU *cdecl mnvalmn0 (BMENU *, /* Validate a menu data structure.  */
  384.              unsigned); /*                    */
  385.  
  386. #endif                /* Ends "#ifndef DEF_BMENU"         */
  387.