x11_simple_menu.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /* =============================================================================
  2. * PROGRAM: CODE LIBRARY
  3. * FILENAME: x11_simple_menu.h
  4. *
  5. * DESCRIPTION:
  6. * This module provides a simple menu capability for X11 programs.
  7. * It can currently only handle a single window/menu at a time.
  8. * To use this library in an application:
  9. * 1. Create the widow to contain the menu.
  10. * 2. Call XMENU_SetMenu to set the menu to be displayed in that window
  11. * This must provide a pointer to a function to repaint the windows
  12. * that may be obscured by the menu.
  13. * 3. Call XMENU_GetMenuHeight to get the height of the menu bar.
  14. * The application should be acreful not to draw in this area.
  15. * 4. Add XMENU_EVENT_MASK to the menu window's X event mask.
  16. * 5. When processing an X event the main event loop should call
  17. * XMENU_HandleEvent.
  18. * This function will return either:
  19. * . -1 if the menu didn't handle this event, in which case the
  20. * application needs to handle it, or
  21. * . The selected menu item id if the event was handled by the menu.
  22. * In this case the application shouldn't process this event, but should
  23. * act on the returned menu selection id.
  24. * 6. Call XMENU_Redraw whenever the window containing the menu gets an
  25. * expose event.
  26. *
  27. * =============================================================================
  28. * COPYRIGHT:
  29. *
  30. * Copyright (c) 2003, Julian Olds
  31. * All rights reserved.
  32. *
  33. * Redistribution and use in source and binary forms, with or without
  34. * modification, are permitted provided that the following conditions
  35. * are met:
  36. *
  37. * . Redistributions of source code must retain the above copyright notice,
  38. * this list of conditions and the following disclaimer.
  39. *
  40. * . Redistributions in binary form must reproduce the above copyright
  41. * notice, this list of conditions and the following disclaimer in the
  42. * documentation and/or other materials provided with the distribution.
  43. *
  44. * The name of the author may not be used to endorse or promote products
  45. * derived from this software without specific prior written permission.
  46. *
  47. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  48. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  49. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  51. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  52. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  53. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  54. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  55. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  56. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  57. * THE POSSIBILITY OF SUCH DAMAGE.
  58. *
  59. * =============================================================================
  60. * EXPORTED VARIABLES
  61. *
  62. * None.
  63. *
  64. * =============================================================================
  65. * EXPORTED FUNCTIONS
  66. *
  67. * XMENU_SetMenu - Set the menu and menu dislay window
  68. * XMENU_SetCheck - Set the checkmark state for a menu item
  69. * XMENU_GetMenuHeight - Get the menu height in pixels
  70. * XMENU_Redraw - Redraw the menu
  71. * XMENU_HandleEvent - Process input events for the menu selection
  72. *
  73. * =============================================================================
  74. */
  75. #ifndef __X11_SIMPLE_MENU_H
  76. #define __X11_SIMPLE_MENU_H
  77. #include <X11/Xlib.h>
  78. #define XMENU_NULLID 0
  79. #define XMENU_SEPARATOR 1
  80. typedef enum { XMENU_UNCHECKED, XMENU_CHECKED } XMENU_CheckState;
  81. /*
  82. * The X events the menu handler requires its window to handle
  83. */
  84. #define XMENU_EVENT_MASK \
  85. (ButtonPressMask | ButtonReleaseMask | Button1MotionMask)
  86. struct XMENU_Item {
  87. char *Text;
  88. int ItemId;
  89. XMENU_CheckState Checked;
  90. struct XMENU_Item *Next;
  91. };
  92. struct XMENU_Menu {
  93. char *Text;
  94. struct XMENU_Menu *Next;
  95. struct XMENU_Item *ItemList;
  96. int HitLeft; /* Hit region. Filled out by menu handler. */
  97. int HitTop; /* These values are for internal use only. */
  98. int HitWidth;
  99. int HitHeight;
  100. };
  101. /* =============================================================================
  102. * FUNCTION: XMENU_SetMenu
  103. *
  104. * DESCRIPTION:
  105. * Set the menu to be dislayed in a window.
  106. *
  107. * PARAMETERS:
  108. *
  109. * dpy : A pointer to the display containing the window
  110. *
  111. * win : The window to contain the menu
  112. *
  113. * FontSpec : The X font specified string for the menu, or NULL for the
  114. * default menu font (Helvetica 12).
  115. *
  116. * Repaint : A pointer to the function that performs the repainting of
  117. * windows that may be obscured by the popup menus.
  118. *
  119. * RETURN VALUE:
  120. *
  121. * None.
  122. */
  123. void XMENU_SetMenu(Display *dpy, Window win, struct XMENU_Menu *Menu,
  124. char *FontSpec, void (*Repaint)(void));
  125. /* =============================================================================
  126. * FUNCTION: XMENU_SetCheck
  127. *
  128. * DESCRIPTION:
  129. * Set the checkmark state of a menu item.
  130. *
  131. * PARAMETERS:
  132. *
  133. * ItemId : The ItemId of the menu item.
  134. *
  135. * CheckState : The new check state for the menu item.
  136. *
  137. * RETURN VALUE:
  138. *
  139. * None.
  140. */
  141. void XMENU_SetCheck(int ItemId, XMENU_CheckState CheckState);
  142. /* =============================================================================
  143. * FUNCTION: XMENU_GetMenuHeight
  144. *
  145. * DESCRIPTION:
  146. * Get the height of the currently managed menu bar in pixels.
  147. *
  148. * PARAMETERS:
  149. *
  150. * None.
  151. *
  152. * RETURN VALUE:
  153. *
  154. * The menu bar height in pixels.
  155. */
  156. int XMENU_GetMenuHeight(void);
  157. /* =============================================================================
  158. * FUNCTION: XMENU_Redraw
  159. *
  160. * DESCRIPTION:
  161. * Redraw the menu bar.
  162. *
  163. * PARAMETERS:
  164. *
  165. * None.
  166. *
  167. * RETURN VALUE:
  168. *
  169. * None.
  170. */
  171. void XMENU_Redraw(void);
  172. /* =============================================================================
  173. * FUNCTION: XMENU_HandleEvent
  174. *
  175. * DESCRIPTION:
  176. * Perform event handling for the menu.
  177. * If the X event activates the menu then further X events will be processed
  178. * until an item is selected or the menu is deactivated.
  179. *
  180. * PARAMETERS:
  181. *
  182. * Event : The X event to be handled.
  183. *
  184. * RETURN VALUE:
  185. *
  186. * Returns The selected Menu Item or XMENU_NULLID if the event is handled
  187. * by the menu.
  188. * Returns -1 if the event is not handled by the menu.
  189. */
  190. int XMENU_HandleEvent(XEvent *Event);
  191. #endif