menu.h 12 KB

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