menu.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /****************************************************************************
  2. * Copyright (c) 1998-2009,2016 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.21 2016/03/26 21:52:08 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. #define O_MOUSE_MENU (0x40)
  52. /* Item options: */
  53. #define O_SELECTABLE (0x01)
  54. typedef struct
  55. {
  56. const char* str;
  57. unsigned short length;
  58. } TEXT;
  59. typedef struct tagITEM
  60. {
  61. TEXT name; /* name of menu item */
  62. TEXT description; /* description of item, optional in display */
  63. struct tagMENU *imenu; /* Pointer to parent menu */
  64. void *userptr; /* Pointer to user defined per item data */
  65. Item_Options opt; /* Item options */
  66. short index; /* Item number if connected to a menu */
  67. short y; /* y and x location of item in menu */
  68. short x;
  69. bool value; /* Selection value */
  70. struct tagITEM *left; /* neighbor items */
  71. struct tagITEM *right;
  72. struct tagITEM *up;
  73. struct tagITEM *down;
  74. } ITEM;
  75. typedef void (*Menu_Hook)(struct tagMENU *);
  76. typedef struct tagMENU
  77. {
  78. short height; /* Nr. of chars high */
  79. short width; /* Nr. of chars wide */
  80. short rows; /* Nr. of items high */
  81. short cols; /* Nr. of items wide */
  82. short frows; /* Nr. of formatted items high */
  83. short fcols; /* Nr. of formatted items wide */
  84. short arows; /* Nr. of items high (actual) */
  85. short namelen; /* Max. name length */
  86. short desclen; /* Max. description length */
  87. short marklen; /* Length of mark, if any */
  88. short itemlen; /* Length of one item */
  89. short spc_desc; /* Spacing for descriptor */
  90. short spc_cols; /* Spacing for columns */
  91. short spc_rows; /* Spacing for rows */
  92. char *pattern; /* Buffer to store match chars */
  93. short pindex; /* Index into pattern buffer */
  94. WINDOW *win; /* Window containing menu */
  95. WINDOW *sub; /* Subwindow for menu display */
  96. WINDOW *userwin; /* User's window */
  97. WINDOW *usersub; /* User's subwindow */
  98. ITEM **items; /* array of items */
  99. short nitems; /* Nr. of items in menu */
  100. ITEM *curitem; /* Current item */
  101. short toprow; /* Top row of menu */
  102. chtype fore; /* Selection attribute */
  103. chtype back; /* Nonselection attribute */
  104. chtype grey; /* Inactive attribute */
  105. unsigned char pad; /* Pad character */
  106. Menu_Hook menuinit; /* User hooks */
  107. Menu_Hook menuterm;
  108. Menu_Hook iteminit;
  109. Menu_Hook itemterm;
  110. void *userptr; /* Pointer to menus user data */
  111. char *mark; /* Pointer to marker string */
  112. Menu_Options opt; /* Menu options */
  113. unsigned short status; /* Internal state of menu */
  114. } MENU;
  115. /* Define keys */
  116. #define REQ_LEFT_ITEM (KEY_MAX + 1)
  117. #define REQ_RIGHT_ITEM (KEY_MAX + 2)
  118. #define REQ_UP_ITEM (KEY_MAX + 3)
  119. #define REQ_DOWN_ITEM (KEY_MAX + 4)
  120. #define REQ_SCR_ULINE (KEY_MAX + 5)
  121. #define REQ_SCR_DLINE (KEY_MAX + 6)
  122. #define REQ_SCR_DPAGE (KEY_MAX + 7)
  123. #define REQ_SCR_UPAGE (KEY_MAX + 8)
  124. #define REQ_FIRST_ITEM (KEY_MAX + 9)
  125. #define REQ_LAST_ITEM (KEY_MAX + 10)
  126. #define REQ_NEXT_ITEM (KEY_MAX + 11)
  127. #define REQ_PREV_ITEM (KEY_MAX + 12)
  128. #define REQ_TOGGLE_ITEM (KEY_MAX + 13)
  129. #define REQ_CLEAR_PATTERN (KEY_MAX + 14)
  130. #define REQ_BACK_PATTERN (KEY_MAX + 15)
  131. #define REQ_NEXT_MATCH (KEY_MAX + 16)
  132. #define REQ_PREV_MATCH (KEY_MAX + 17)
  133. #define MIN_MENU_COMMAND (KEY_MAX + 1)
  134. #define MAX_MENU_COMMAND (KEY_MAX + 17)
  135. /*
  136. * Some AT&T code expects MAX_COMMAND to be out-of-band not
  137. * just for menu commands but for forms ones as well.
  138. */
  139. #if defined(MAX_COMMAND)
  140. # if (MAX_MENU_COMMAND > MAX_COMMAND)
  141. # error Something is wrong -- MAX_MENU_COMMAND is greater than MAX_COMMAND
  142. # elif (MAX_COMMAND != (KEY_MAX + 128))
  143. # error Something is wrong -- MAX_COMMAND is already inconsistently defined.
  144. # endif
  145. #else
  146. # define MAX_COMMAND (KEY_MAX + 128)
  147. #endif
  148. /* --------- prototypes for libmenu functions ----------------------------- */
  149. extern NCURSES_EXPORT(ITEM **) menu_items (const MENU *);
  150. extern NCURSES_EXPORT(ITEM *) current_item (const MENU *);
  151. extern NCURSES_EXPORT(ITEM *) new_item (const char *,const char *);
  152. extern NCURSES_EXPORT(MENU *) new_menu (ITEM **);
  153. extern NCURSES_EXPORT(Item_Options) item_opts (const ITEM *);
  154. extern NCURSES_EXPORT(Menu_Options) menu_opts (const MENU *);
  155. extern NCURSES_EXPORT(Menu_Hook) item_init (const MENU *);
  156. extern NCURSES_EXPORT(Menu_Hook) item_term (const MENU *);
  157. extern NCURSES_EXPORT(Menu_Hook) menu_init (const MENU *);
  158. extern NCURSES_EXPORT(Menu_Hook) menu_term (const MENU *);
  159. extern NCURSES_EXPORT(WINDOW *) menu_sub (const MENU *);
  160. extern NCURSES_EXPORT(WINDOW *) menu_win (const MENU *);
  161. extern NCURSES_EXPORT(const char *) item_description (const ITEM *);
  162. extern NCURSES_EXPORT(const char *) item_name (const ITEM *);
  163. extern NCURSES_EXPORT(const char *) menu_mark (const MENU *);
  164. extern NCURSES_EXPORT(const char *) menu_request_name (int);
  165. extern NCURSES_EXPORT(char *) menu_pattern (const MENU *);
  166. extern NCURSES_EXPORT(void *) menu_userptr (const MENU *);
  167. extern NCURSES_EXPORT(void *) item_userptr (const ITEM *);
  168. extern NCURSES_EXPORT(chtype) menu_back (const MENU *);
  169. extern NCURSES_EXPORT(chtype) menu_fore (const MENU *);
  170. extern NCURSES_EXPORT(chtype) menu_grey (const MENU *);
  171. extern NCURSES_EXPORT(int) free_item (ITEM *);
  172. extern NCURSES_EXPORT(int) free_menu (MENU *);
  173. extern NCURSES_EXPORT(int) item_count (const MENU *);
  174. extern NCURSES_EXPORT(int) item_index (const ITEM *);
  175. extern NCURSES_EXPORT(int) item_opts_off (ITEM *,Item_Options);
  176. extern NCURSES_EXPORT(int) item_opts_on (ITEM *,Item_Options);
  177. extern NCURSES_EXPORT(int) menu_driver (MENU *,int);
  178. extern NCURSES_EXPORT(int) menu_opts_off (MENU *,Menu_Options);
  179. extern NCURSES_EXPORT(int) menu_opts_on (MENU *,Menu_Options);
  180. extern NCURSES_EXPORT(int) menu_pad (const MENU *);
  181. extern NCURSES_EXPORT(int) pos_menu_cursor (const MENU *);
  182. extern NCURSES_EXPORT(int) post_menu (MENU *);
  183. extern NCURSES_EXPORT(int) scale_menu (const MENU *,int *,int *);
  184. extern NCURSES_EXPORT(int) set_current_item (MENU *menu,ITEM *item);
  185. extern NCURSES_EXPORT(int) set_item_init (MENU *, Menu_Hook);
  186. extern NCURSES_EXPORT(int) set_item_opts (ITEM *,Item_Options);
  187. extern NCURSES_EXPORT(int) set_item_term (MENU *, Menu_Hook);
  188. extern NCURSES_EXPORT(int) set_item_userptr (ITEM *, void *);
  189. extern NCURSES_EXPORT(int) set_item_value (ITEM *,bool);
  190. extern NCURSES_EXPORT(int) set_menu_back (MENU *,chtype);
  191. extern NCURSES_EXPORT(int) set_menu_fore (MENU *,chtype);
  192. extern NCURSES_EXPORT(int) set_menu_format (MENU *,int,int);
  193. extern NCURSES_EXPORT(int) set_menu_grey (MENU *,chtype);
  194. extern NCURSES_EXPORT(int) set_menu_init (MENU *, Menu_Hook);
  195. extern NCURSES_EXPORT(int) set_menu_items (MENU *,ITEM **);
  196. extern NCURSES_EXPORT(int) set_menu_mark (MENU *, const char *);
  197. extern NCURSES_EXPORT(int) set_menu_opts (MENU *,Menu_Options);
  198. extern NCURSES_EXPORT(int) set_menu_pad (MENU *,int);
  199. extern NCURSES_EXPORT(int) set_menu_pattern (MENU *,const char *);
  200. extern NCURSES_EXPORT(int) set_menu_sub (MENU *,WINDOW *);
  201. extern NCURSES_EXPORT(int) set_menu_term (MENU *, Menu_Hook);
  202. extern NCURSES_EXPORT(int) set_menu_userptr (MENU *,void *);
  203. extern NCURSES_EXPORT(int) set_menu_win (MENU *,WINDOW *);
  204. extern NCURSES_EXPORT(int) set_top_row (MENU *,int);
  205. extern NCURSES_EXPORT(int) top_row (const MENU *);
  206. extern NCURSES_EXPORT(int) unpost_menu (MENU *);
  207. extern NCURSES_EXPORT(int) menu_request_by_name (const char *);
  208. extern NCURSES_EXPORT(int) set_menu_spacing (MENU *,int,int,int);
  209. extern NCURSES_EXPORT(int) menu_spacing (const MENU *,int *,int *,int *);
  210. extern NCURSES_EXPORT(bool) item_value (const ITEM *);
  211. extern NCURSES_EXPORT(bool) item_visible (const ITEM *);
  212. extern NCURSES_EXPORT(void) menu_format (const MENU *,int *,int *);
  213. #if NCURSES_SP_FUNCS
  214. extern NCURSES_EXPORT(MENU *) NCURSES_SP_NAME(new_menu) (SCREEN*, ITEM **);
  215. #endif
  216. #ifdef __cplusplus
  217. }
  218. #endif
  219. #endif /* ETI_MENU */