menu.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /****************************************************************************
  2. * Copyright (c) 1998-2003,2007 Free Software Foundation, Inc. *
  3. * *
  4. * Permission is hereby granted, free of charge, to any person obtaining a *
  5. * copy of this software and associated documentation files (the *
  6. * "Software"), to deal in the Software without restriction, including *
  7. * without limitation the rights to use, copy, modify, merge, publish, *
  8. * distribute, distribute with modifications, sublicense, and/or sell *
  9. * copies of the Software, and to permit persons to whom the Software is *
  10. * furnished to do so, subject to the following conditions: *
  11. * *
  12. * The above copyright notice and this permission notice shall be included *
  13. * in all copies or substantial portions of the Software. *
  14. * *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  16. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  18. * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  19. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  20. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  21. * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  22. * *
  23. * Except as contained in this notice, the name(s) of the above copyright *
  24. * holders shall not be used in advertising or otherwise to promote the *
  25. * sale, use or other dealings in this Software without prior written *
  26. * authorization. *
  27. ****************************************************************************/
  28. /****************************************************************************
  29. * Author: Juergen Pfeifer, 1995,1997 *
  30. ****************************************************************************/
  31. /* $Id: menu.h,v 1.19 2007/02/24 17:32:13 tom Exp $ */
  32. #ifndef ETI_MENU
  33. #define ETI_MENU
  34. #ifdef AMIGA
  35. #define TEXT TEXT_ncurses
  36. #endif
  37. #include <curses.h>
  38. #include <eti.h>
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. typedef int Menu_Options;
  43. typedef int Item_Options;
  44. /* Menu options: */
  45. #define O_ONEVALUE (0x01)
  46. #define O_SHOWDESC (0x02)
  47. #define O_ROWMAJOR (0x04)
  48. #define O_IGNORECASE (0x08)
  49. #define O_SHOWMATCH (0x10)
  50. #define O_NONCYCLIC (0x20)
  51. /* Item options: */
  52. #define O_SELECTABLE (0x01)
  53. typedef struct
  54. {
  55. const char* str;
  56. unsigned short length;
  57. } TEXT;
  58. typedef struct tagITEM
  59. {
  60. TEXT name; /* name of menu item */
  61. TEXT description; /* description of item, optional in display */
  62. struct tagMENU *imenu; /* Pointer to parent menu */
  63. void *userptr; /* Pointer to user defined per item data */
  64. Item_Options opt; /* Item options */
  65. short index; /* Item number if connected to a menu */
  66. short y; /* y and x location of item in menu */
  67. short x;
  68. bool value; /* Selection value */
  69. struct tagITEM *left; /* neighbor items */
  70. struct tagITEM *right;
  71. struct tagITEM *up;
  72. struct tagITEM *down;
  73. } ITEM;
  74. typedef void (*Menu_Hook)(struct tagMENU *);
  75. typedef struct tagMENU
  76. {
  77. short height; /* Nr. of chars high */
  78. short width; /* Nr. of chars wide */
  79. short rows; /* Nr. of items high */
  80. short cols; /* Nr. of items wide */
  81. short frows; /* Nr. of formatted items high */
  82. short fcols; /* Nr. of formatted items wide */
  83. short arows; /* Nr. of items high (actual) */
  84. short namelen; /* Max. name length */
  85. short desclen; /* Max. description length */
  86. short marklen; /* Length of mark, if any */
  87. short itemlen; /* Length of one item */
  88. short spc_desc; /* Spacing for descriptor */
  89. short spc_cols; /* Spacing for columns */
  90. short spc_rows; /* Spacing for rows */
  91. char *pattern; /* Buffer to store match chars */
  92. short pindex; /* Index into pattern buffer */
  93. WINDOW *win; /* Window containing menu */
  94. WINDOW *sub; /* Subwindow for menu display */
  95. WINDOW *userwin; /* User's window */
  96. WINDOW *usersub; /* User's subwindow */
  97. ITEM **items; /* array of items */
  98. short nitems; /* Nr. of items in menu */
  99. ITEM *curitem; /* Current item */
  100. short toprow; /* Top row of menu */
  101. chtype fore; /* Selection attribute */
  102. chtype back; /* Nonselection attribute */
  103. chtype grey; /* Inactive attribute */
  104. unsigned char pad; /* Pad character */
  105. Menu_Hook menuinit; /* User hooks */
  106. Menu_Hook menuterm;
  107. Menu_Hook iteminit;
  108. Menu_Hook itemterm;
  109. void *userptr; /* Pointer to menus user data */
  110. char *mark; /* Pointer to marker string */
  111. Menu_Options opt; /* Menu options */
  112. unsigned short status; /* Internal state of menu */
  113. } MENU;
  114. /* Define keys */
  115. #define REQ_LEFT_ITEM (KEY_MAX + 1)
  116. #define REQ_RIGHT_ITEM (KEY_MAX + 2)
  117. #define REQ_UP_ITEM (KEY_MAX + 3)
  118. #define REQ_DOWN_ITEM (KEY_MAX + 4)
  119. #define REQ_SCR_ULINE (KEY_MAX + 5)
  120. #define REQ_SCR_DLINE (KEY_MAX + 6)
  121. #define REQ_SCR_DPAGE (KEY_MAX + 7)
  122. #define REQ_SCR_UPAGE (KEY_MAX + 8)
  123. #define REQ_FIRST_ITEM (KEY_MAX + 9)
  124. #define REQ_LAST_ITEM (KEY_MAX + 10)
  125. #define REQ_NEXT_ITEM (KEY_MAX + 11)
  126. #define REQ_PREV_ITEM (KEY_MAX + 12)
  127. #define REQ_TOGGLE_ITEM (KEY_MAX + 13)
  128. #define REQ_CLEAR_PATTERN (KEY_MAX + 14)
  129. #define REQ_BACK_PATTERN (KEY_MAX + 15)
  130. #define REQ_NEXT_MATCH (KEY_MAX + 16)
  131. #define REQ_PREV_MATCH (KEY_MAX + 17)
  132. #define MIN_MENU_COMMAND (KEY_MAX + 1)
  133. #define MAX_MENU_COMMAND (KEY_MAX + 17)
  134. /*
  135. * Some AT&T code expects MAX_COMMAND to be out-of-band not
  136. * just for menu commands but for forms ones as well.
  137. */
  138. #if defined(MAX_COMMAND)
  139. # if (MAX_MENU_COMMAND > MAX_COMMAND)
  140. # error Something is wrong -- MAX_MENU_COMMAND is greater than MAX_COMMAND
  141. # elif (MAX_COMMAND != (KEY_MAX + 128))
  142. # error Something is wrong -- MAX_COMMAND is already inconsistently defined.
  143. # endif
  144. #else
  145. # define MAX_COMMAND (KEY_MAX + 128)
  146. #endif
  147. /* --------- prototypes for libmenu functions ----------------------------- */
  148. extern NCURSES_EXPORT(ITEM **) menu_items (const MENU *);
  149. extern NCURSES_EXPORT(ITEM *) current_item (const MENU *);
  150. extern NCURSES_EXPORT(ITEM *) new_item (const char *,const char *);
  151. extern NCURSES_EXPORT(MENU *) new_menu (ITEM **);
  152. extern NCURSES_EXPORT(Item_Options) item_opts (const ITEM *);
  153. extern NCURSES_EXPORT(Menu_Options) menu_opts (const MENU *);
  154. extern NCURSES_EXPORT(Menu_Hook) item_init (const MENU *);
  155. extern NCURSES_EXPORT(Menu_Hook) item_term (const MENU *);
  156. extern NCURSES_EXPORT(Menu_Hook) menu_init (const MENU *);
  157. extern NCURSES_EXPORT(Menu_Hook) menu_term (const MENU *);
  158. extern NCURSES_EXPORT(WINDOW *) menu_sub (const MENU *);
  159. extern NCURSES_EXPORT(WINDOW *) menu_win (const MENU *);
  160. extern NCURSES_EXPORT(const char *) item_description (const ITEM *);
  161. extern NCURSES_EXPORT(const char *) item_name (const ITEM *);
  162. extern NCURSES_EXPORT(const char *) menu_mark (const MENU *);
  163. extern NCURSES_EXPORT(const char *) menu_request_name (int);
  164. extern NCURSES_EXPORT(char *) menu_pattern (const MENU *);
  165. extern NCURSES_EXPORT(void *) menu_userptr (const MENU *);
  166. extern NCURSES_EXPORT(void *) item_userptr (const ITEM *);
  167. extern NCURSES_EXPORT(chtype) menu_back (const MENU *);
  168. extern NCURSES_EXPORT(chtype) menu_fore (const MENU *);
  169. extern NCURSES_EXPORT(chtype) menu_grey (const MENU *);
  170. extern NCURSES_EXPORT(int) free_item (ITEM *);
  171. extern NCURSES_EXPORT(int) free_menu (MENU *);
  172. extern NCURSES_EXPORT(int) item_count (const MENU *);
  173. extern NCURSES_EXPORT(int) item_index (const ITEM *);
  174. extern NCURSES_EXPORT(int) item_opts_off (ITEM *,Item_Options);
  175. extern NCURSES_EXPORT(int) item_opts_on (ITEM *,Item_Options);
  176. extern NCURSES_EXPORT(int) menu_driver (MENU *,int);
  177. extern NCURSES_EXPORT(int) menu_opts_off (MENU *,Menu_Options);
  178. extern NCURSES_EXPORT(int) menu_opts_on (MENU *,Menu_Options);
  179. extern NCURSES_EXPORT(int) menu_pad (const MENU *);
  180. extern NCURSES_EXPORT(int) pos_menu_cursor (const MENU *);
  181. extern NCURSES_EXPORT(int) post_menu (MENU *);
  182. extern NCURSES_EXPORT(int) scale_menu (const MENU *,int *,int *);
  183. extern NCURSES_EXPORT(int) set_current_item (MENU *menu,ITEM *item);
  184. extern NCURSES_EXPORT(int) set_item_init (MENU *, Menu_Hook);
  185. extern NCURSES_EXPORT(int) set_item_opts (ITEM *,Item_Options);
  186. extern NCURSES_EXPORT(int) set_item_term (MENU *, Menu_Hook);
  187. extern NCURSES_EXPORT(int) set_item_userptr (ITEM *, void *);
  188. extern NCURSES_EXPORT(int) set_item_value (ITEM *,bool);
  189. extern NCURSES_EXPORT(int) set_menu_back (MENU *,chtype);
  190. extern NCURSES_EXPORT(int) set_menu_fore (MENU *,chtype);
  191. extern NCURSES_EXPORT(int) set_menu_format (MENU *,int,int);
  192. extern NCURSES_EXPORT(int) set_menu_grey (MENU *,chtype);
  193. extern NCURSES_EXPORT(int) set_menu_init (MENU *, Menu_Hook);
  194. extern NCURSES_EXPORT(int) set_menu_items (MENU *,ITEM **);
  195. extern NCURSES_EXPORT(int) set_menu_mark (MENU *, const char *);
  196. extern NCURSES_EXPORT(int) set_menu_opts (MENU *,Menu_Options);
  197. extern NCURSES_EXPORT(int) set_menu_pad (MENU *,int);
  198. extern NCURSES_EXPORT(int) set_menu_pattern (MENU *,const char *);
  199. extern NCURSES_EXPORT(int) set_menu_sub (MENU *,WINDOW *);
  200. extern NCURSES_EXPORT(int) set_menu_term (MENU *, Menu_Hook);
  201. extern NCURSES_EXPORT(int) set_menu_userptr (MENU *,void *);
  202. extern NCURSES_EXPORT(int) set_menu_win (MENU *,WINDOW *);
  203. extern NCURSES_EXPORT(int) set_top_row (MENU *,int);
  204. extern NCURSES_EXPORT(int) top_row (const MENU *);
  205. extern NCURSES_EXPORT(int) unpost_menu (MENU *);
  206. extern NCURSES_EXPORT(int) menu_request_by_name (const char *);
  207. extern NCURSES_EXPORT(int) set_menu_spacing (MENU *,int,int,int);
  208. extern NCURSES_EXPORT(int) menu_spacing (const MENU *,int *,int *,int *);
  209. extern NCURSES_EXPORT(bool) item_value (const ITEM *);
  210. extern NCURSES_EXPORT(bool) item_visible (const ITEM *);
  211. extern NCURSES_EXPORT(void) menu_format (const MENU *,int *,int *);
  212. #ifdef __cplusplus
  213. }
  214. #endif
  215. #endif /* ETI_MENU */