smart_menu.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* =============================================================================
  2. * PROGRAM: CODE LIBRARY
  3. * FILENAME: smart_menu.h
  4. *
  5. * DESCRIPTION:
  6. * This module provides a set of functions to make menu handling for
  7. * Intuition easier.
  8. * A much simpler set of data structures for simple text menu are used.
  9. *
  10. * Each menu on is specified in an array of SmartMenuItem.
  11. * The last element of the array should have all fields set to NULL to mark
  12. * the end of the menu.
  13. * Each SmartMenuItem specifies the Text, colour and command sequence to use
  14. * for the menu item. It also specifies the function to be called when the
  15. * menu item is selected.
  16. * Note: The same structure is used for menus and submenus.
  17. *
  18. * The menus on the menu bar are specified in an array of SmartMenu.
  19. * This array should also be terminated with an entry with all elements set to
  20. * NULL.
  21. *
  22. * The menu structure specified in the array of SmartMenu is set to a window
  23. * using the MakeMenuStructure function. This function alocates and sets up the
  24. * Intuition structures required for the menu and then assigns the menu to the
  25. * specified window.
  26. *
  27. * The window containing the menu should have the IDCMP_MENUPICK flag set so
  28. * it will receive menu events.
  29. * When a menu event is received for the window, call DoMenuSelection to
  30. * with the Code field of the IntuiMessage handle the event. This will call
  31. * the specified callback function of the event picked.
  32. *
  33. * NOTE: This module can currently only handle the menu for one window at a
  34. * time.
  35. *
  36. * =============================================================================
  37. * COPYRIGHT:
  38. *
  39. * Copyright (c) 1995, 2004, Julian Olds
  40. * All rights reserved.
  41. *
  42. * Redistribution and use in source and binary forms, with or without
  43. * modification, are permitted provided that the following conditions
  44. * are met:
  45. *
  46. * . Redistributions of source code must retain the above copyright notice,
  47. * this list of conditions and the following disclaimer.
  48. *
  49. * . Redistributions in binary form must reproduce the above copyright
  50. * notice, this list of conditions and the following disclaimer in the
  51. * documentation and/or other materials provided with the distribution.
  52. *
  53. * The name of the author may not be used to endorse or promote products
  54. * derived from this software without specific prior written permission.
  55. *
  56. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  57. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  58. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  59. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  60. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  61. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  62. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  63. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  64. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  65. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  66. * THE POSSIBILITY OF SUCH DAMAGE.
  67. *
  68. * =============================================================================
  69. * EXPORTED VARIABLES
  70. *
  71. * Quit : This is set to true for the quit event.
  72. *
  73. * =============================================================================
  74. * EXPORTED FUNCTIONS
  75. *
  76. * MenuNil : The Null action event handler for menu items that do nothing.
  77. * MenuQuit : The default Quit application menu handler. Sets the Quit flag.
  78. * This should also be called when the application exits if it is not
  79. * used to handle the Quit menu item.
  80. * MakeMenuStructure : Makes the Intuition menu structure and assigns the menu
  81. * into a window.
  82. * DoMenuSelection : Handles the menu selection events.
  83. *
  84. * =============================================================================
  85. */
  86. #ifndef __SMART_MENU_H
  87. #define __SMART_MENU_H
  88. #include <intuition/intuition.h>
  89. extern int Quit;
  90. struct SmartMenuItem {
  91. char *Text;
  92. char ComSeq;
  93. UBYTE FrontPen;
  94. UBYTE BackPen;
  95. void (*SelectFunction)(void);
  96. struct SmartMenuItem *SubItem;
  97. };
  98. struct SmartMenu {
  99. char *Text;
  100. struct SmartMenuItem *FirstItem;
  101. };
  102. /* =============================================================================
  103. * FUNCTION: MenuNil
  104. *
  105. * DESCRIPTION:
  106. * This is the null callback function for menu events. This is to be used
  107. * for any items used as separators inthe menu structure.
  108. * It can also be used as a stub function for any menu item whose behaviour
  109. * is not yet defined.
  110. *
  111. * PARAMETERS:
  112. *
  113. * None.
  114. *
  115. * RETURN VALUE:
  116. *
  117. * None.
  118. */
  119. void MenuNil(void);
  120. /* =============================================================================
  121. * FUNCTION: MenuQuit
  122. *
  123. * DESCRIPTION:
  124. * The default Quit application menu handler.
  125. * This function frees any allcoated memory for menu structures and sets the
  126. * Quit flag.
  127. * This should also be called when the application exits if it is not used to
  128. * handle the Quit menu item.
  129. *
  130. * PARAMETERS:
  131. *
  132. * None.
  133. *
  134. * RETURN VALUE:
  135. *
  136. * None.
  137. */
  138. void MenuQuit(void);
  139. /* =============================================================================
  140. * FUNCTION: MakeMenuStructure
  141. *
  142. * DESCRIPTION:
  143. * This function build the Intuition Menu structures according to the
  144. * menu layout specified in WindowMenu and assigns the menu created to the
  145. * Window specified in MenuWindow.
  146. *
  147. * PARAMETERS:
  148. *
  149. * MWindow : The window to use the menu.
  150. *
  151. * WindowMenu : The SmartMenu specification of the menu structure.
  152. *
  153. * RETURN VALUE:
  154. *
  155. * int: TRUE if the menu was successfully created.
  156. */
  157. int MakeMenuStructure(struct Window *MWindow, struct SmartMenu *WindowMenu);
  158. /* =============================================================================
  159. * FUNCTION: DoMenuSelection
  160. *
  161. * DESCRIPTION:
  162. * This function handles the IDCMP_MENIPICK event, and calls the handler
  163. * function for the menu item picked.
  164. *
  165. * PARAMETERS:
  166. *
  167. * code : The Code field of the IntuiMessage.
  168. *
  169. * RETURN VALUE:
  170. *
  171. * None.
  172. */
  173. void DoMenuSelection(USHORT code);
  174. #endif