menu.h 12 KB

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