home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / FACETV.ZIP / MENUBARS.H < prev    next >
C/C++ Source or Header  |  1993-12-09  |  6KB  |  225 lines

  1. /************************************************************************
  2. **
  3. ** @(#)menubars.h    04/01/93    Chris Ahlstrom
  4. **
  5. **  ------------------------
  6. **  73340.26!compuserve.com
  7. **  ------------------------
  8. **
  9. ** C++ version
  10. **
  11. **    Class for implementing generic menu bars and menu entries.
  12. **
  13. **    The structs were originally defined in tvmenus.h.
  14. **
  15. *************************************************************************/
  16.  
  17. #if !defined(MENUBARS_h)                // { MENUBARS_h
  18. #define MENUBARS_h
  19.  
  20.  
  21. /************************************************************************
  22. ** Turbo Vision setup section
  23. **
  24. **    Although we could strip out some unnecessary #defines below,
  25. ** it is likely that the main program will eventually use almost all of
  26. ** them anyway.
  27. **
  28. **    Note the two sections:  declarations needed only in the main
  29. ** module, and declarations needed in other modules.
  30. **
  31. *************************************************************************/
  32.  
  33. #define Uses_TApplication
  34. #define Uses_TDisplay
  35. #define Uses_TMenu
  36. #define Uses_TMenuBar
  37. #define Uses_TMenuItem
  38. #define Uses_TRect
  39. #define Uses_TScreen
  40. #define Uses_TStatusLine
  41. #define Uses_TStatusItem
  42. #define Uses_TStatusDef
  43. #define Uses_TSubMenu
  44. #include <tv.h>                // Turbo Vision code galore!!!
  45.  
  46.  
  47. #define MENU_TERMINATE    NULL    // ends the list of items or submenus
  48. #define MENU_END_NEST    NULL    // null "nest" indicates no nested menu
  49. #define MENU_NEWLINE    "\n"    // code for including a separator bar
  50. #define NEWLINE        '\n'    // code for including a separator bar
  51.  
  52.  
  53. /************************************************************************
  54. ** MenuItems
  55. **
  56. **    Each of these structures represents a single, selectable command
  57. ** in a menu.
  58. **
  59. ** Menus
  60. **
  61. **    Each of these structures represents a single submenu within
  62. ** a menu.  Each submenu then has at least one MenuItems structure
  63. ** associated with it.
  64. **
  65. ** MenuBar
  66. **
  67. **    Manages an array of main menu items.  Very simply just a list
  68. ** of Menus with a count of the number of them in the array.
  69. **
  70. *************************************************************************/
  71.  
  72. typedef struct
  73. {
  74.     char *item;            // name of the item, as in "~E~xit"
  75.     ushort cmcode;        // cmXXXXX command code for the item
  76.     ushort key;            // keystroke associated with the item
  77.     ushort help;        // specifies whether help is available
  78.     char *label;        // readable label for the keystroke
  79.  
  80. } MenuItems;
  81.  
  82. typedef struct
  83. {
  84.     char *submenu;        // name of an item in a submenu
  85.     ushort submenukey;        // the keystroke to bring up the submenu
  86.     int submenucount;        // number of items in the submenu
  87.     MenuItems *items;        // points to an array of items
  88.  
  89. } Menus;
  90.  
  91. typedef struct
  92. {
  93.     int barCount;        // number of items in the status bar
  94.     Menus *items;        // points to an array of items
  95.  
  96. } MenuBar;
  97.  
  98.  
  99. /************************************************************************
  100. ** NestItems
  101. **
  102. **    Very similar to MenuItems, but has one extra field that
  103. ** can optionally pointer to another NestItems list, to support
  104. ** nested menus in a fairly straightforward way.
  105. **
  106. **    For examples of MenuItems, see MIDI_EX.CPP; for examples of
  107. ** NestItems, see MT32APP.CPP.  Look at the initMenuBar() function
  108. ** in these two files.
  109. **
  110. ** Nests
  111. **
  112. **    Similar to Menus, but for NestItems.  I could have used
  113. ** a union, I suppose.
  114. **
  115. ** NestBar
  116. **
  117. **    Manages an array of main menu items.  Very simply just a list
  118. ** of Nests with a count of the number of them in the array.
  119. **
  120. *************************************************************************/
  121.  
  122. typedef const struct NestItems *NestPtr;
  123.  
  124. struct NestItems
  125. {
  126.     char *item;            // name of the item, as in "~E~xit"
  127.     ushort cmcode;        // cmXXXXX command code for the item
  128.     ushort key;            // keystroke associated with the item
  129.     ushort help;        // specifies whether help is available
  130.     char *label;        // readable label for the keystroke
  131.     NestPtr nest;        // next structure to hook into
  132. };
  133.  
  134. typedef struct
  135. {
  136.     char *submenu;        // name of an item in a submenu
  137.     ushort submenukey;        // the keystroke to bring up the submenu
  138.     int submenucount;        // number of items in the submenu
  139.     NestPtr items;        // points to an array of items
  140.  
  141. } Nests;
  142.  
  143. typedef struct
  144. {
  145.     int barCount;        // number of items in the status bar
  146.     const Nests *items;        // points to an array of items
  147.  
  148. } NestBar;
  149.  
  150.  
  151. /************************************************************************
  152. ** StatusItems
  153. **
  154. **    Each of these structures holds an item for the status line at
  155. ** the bottom of the screen.
  156. **
  157. ** StatusBar
  158. **
  159. **    A list of StatusItems.
  160. **
  161. *************************************************************************/
  162.  
  163. typedef struct
  164. {
  165.     char *item;            // name of the item, as in "~E~xit"
  166.     ushort cmcode;        // cmXXXXX command code for the item
  167.     ushort key;            // keystroke associated with the item
  168.  
  169. } StatusItems;
  170.  
  171. typedef struct
  172. {
  173.     int barCount;        // number of items in the status bar
  174.     const StatusItems *items;    // points to an array of items
  175.  
  176. } StatusBar;
  177.  
  178. /************************************************************************
  179. ** MenuBarApp
  180. **
  181. **    Not quite sure how to handle this... MenuBarApp needs to use its
  182. ** own version of initMenuBar() and initStatusLine(), but the main
  183. ** program needs to guarantee that they're called.
  184. **
  185. **    With the current setup, I'm not sure what to do if the program
  186. ** wants to temporarily set up some other menu-bars.
  187. **
  188. **    Note then, that MenuBarApp needs no destructor, since TApplication's
  189. ** (TProgram's) virtual destructor is sufficient.
  190. **
  191. *************************************************************************/
  192.  
  193. class MenuBarApp : public TApplication
  194. {
  195. public:
  196.  
  197.     MenuBarApp                // the constructor
  198.     (
  199.     //const Nests *menubar,        // structure describing menu-bar
  200.     //const StatusBar *statusbar    // structure describing status-bar
  201.     );
  202.  
  203.     static TMenuBar *initMenuBar    // overrides TProgram member
  204.     (
  205.     TRect r
  206.     );
  207.     static TStatusLine *initStatusLine    // overrides TProgram member
  208.     (
  209.     TRect r
  210.     );
  211.     static TMenuItem *menuBox        // recursively handles lists of menus
  212.     (
  213.     NestPtr n
  214.     );
  215.  
  216. //private:
  217.  
  218.     static const NestBar *menuBar;    // a hierarchy of menu-items
  219.     static const StatusBar *statusBar;    // a list of status-line items
  220.  
  221. };
  222.  
  223.  
  224. #endif                            // } MENUBARS_h
  225.