menu.pp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. unit menu;
  2. {---------------------------------------------------------------------------
  3. CncWare
  4. ----------------------------------------------------------------------------
  5. Filename..: menu.pp
  6. Programmer: Ken J. Wright
  7. Date......: 07/12/2000
  8. Purpose - Link to the Linux 'menu' library for ncurses menuing
  9. functions.
  10. -------------------------------< Revisions >---------------------------------
  11. Revision| Date | Prog| Description
  12. -----------------------------------------------------------------------------
  13. 1.00 | 07/12/00 | kjw | Initial release.
  14. -----------------------------------------------------------------------------
  15. }
  16. { Automatically converted by H2PAS.EXE from menu.h
  17. Utility made by Florian Klaempfl 25th-28th september 96
  18. Improvements made by Mark A. Malakanov 22nd-25th may 97
  19. Further improvements by Michael Van Canneyt, April 1998
  20. define handling and error recovery by Pierre Muller, June 1998 }
  21. interface
  22. { C default packing is dword }
  23. {$PACKRECORDS 4}
  24. {
  25. Copyright (c) 1998 Free Software Foundation, Inc.
  26. Permission is hereby granted, free of charge, to any person obtaining a
  27. copy of this software and associated documentation files (the
  28. "Software"), to deal in the Software without restriction, including
  29. without limitation the rights to use, copy, modify, merge, publish,
  30. distribute, distribute with modifications, sublicense, and/or sell
  31. copies of the Software, and to permit persons to whom the Software is
  32. furnished to do so, subject to the following conditions:
  33. The above copyright notice and this permission notice shall be included
  34. in all copies or substantial portions of the Software.
  35. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  36. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  37. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  38. IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  39. DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  40. OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
  41. THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  42. Except as contained in this notice, the name(s) of the above copyright
  43. holders shall not be used in advertising or otherwise to promote the
  44. sale, use or other dealings in this Software without prior written
  45. authorization.
  46. }
  47. {
  48. Author: Juergen Pfeifer <[email protected]> 1995,1997
  49. }
  50. {$linklib menu}
  51. uses ncurses;
  52. {$include eti.inc}
  53. type
  54. Menu_Options = longint;
  55. Item_Options = longint;
  56. const
  57. { Menu options: }
  58. O_ONEVALUE = $01;
  59. O_SHOWDESC = $02;
  60. O_ROWMAJOR = $04;
  61. O_IGNORECASE = $08;
  62. O_SHOWMATCH = $10;
  63. O_NONCYCLIC = $20;
  64. { Item options: }
  65. O_SELECTABLE = $01;
  66. type
  67. tTEXT = record
  68. str : pchar;
  69. length : word;
  70. end;
  71. tITEM = record
  72. name : tTEXT; { name of menu item }
  73. description : tTEXT; { description of item, optional in display }
  74. imenu : ^tagMENU; { Pointer to parent menu }
  75. userptr : pointer; { Pointer to user defined per item data }
  76. opt : Item_Options; { Item options }
  77. index : integer; { Item number if connected to a menu }
  78. y : integer; { y and x location of item in menu }
  79. x : integer;
  80. value : bool; { Selection value }
  81. left : ^tagITEM; { neighbour items }
  82. right : ^tagITEM;
  83. up : ^tagITEM;
  84. down : ^tagITEM;
  85. end;
  86. pITEM = ^tITEM;
  87. ppITEM = ^pITEM;
  88. tagITEM = tITEM;
  89. Menu_Hook = procedure;cdecl;
  90. tMENU = record
  91. height : integer; { Nr. of chars high }
  92. width : integer; { Nr. of chars wide }
  93. rows : integer; { Nr. of items high }
  94. cols : integer; { Nr. of items wide }
  95. frows : integer; { Nr. of formatted items high }
  96. fcols : integer; { Nr. of formatted items wide }
  97. arows : integer; { Nr. of items high (actual) }
  98. namelen : integer; { Max. name length }
  99. desclen : integer; { Max. description length }
  100. marklen : integer; { Length of mark, if any }
  101. itemlen : integer; { Length of one item }
  102. spc_desc : integer; { Spacing for descriptor }
  103. spc_cols : integer; { Spacing for columns }
  104. spc_rows : integer; { Spacing for rows }
  105. pattern : ^char; { Buffer to store match chars }
  106. pindex : integer; { Index into pattern buffer }
  107. win : ^WINDOW; { Window containing menu }
  108. sub : ^WINDOW; { Subwindow for menu display }
  109. userwin : ^WINDOW; { User's window }
  110. usersub : ^WINDOW; { User's subwindow }
  111. items : ^pITEM; { array of items }
  112. nitems : integer; { Nr. of items in menu }
  113. curitem : pITEM; { Current item }
  114. toprow : integer; { Top row of menu }
  115. fore : chtype; { Selection attribute }
  116. back : chtype; { Nonselection attribute }
  117. grey : chtype; { Inactive attribute }
  118. pad : byte; { Pad character }
  119. menuinit : Menu_Hook; { User hooks }
  120. menuterm : Menu_Hook;
  121. iteminit : Menu_Hook;
  122. itemterm : Menu_Hook;
  123. userptr : pointer; { Pointer to menus user data }
  124. mark : pchar; { Pointer to marker string }
  125. opt : Menu_Options; { Menu options }
  126. status : word; { Internal state of menu }
  127. end;
  128. pMENU = ^tMENU;
  129. ppMENU = ^pMENU;
  130. tagMENU = tMENU;
  131. const
  132. { Define keys }
  133. REQ_LEFT_ITEM = KEY_MAX + 1;
  134. REQ_RIGHT_ITEM = KEY_MAX + 2;
  135. REQ_UP_ITEM = KEY_MAX + 3;
  136. REQ_DOWN_ITEM = KEY_MAX + 4;
  137. REQ_SCR_ULINE = KEY_MAX + 5;
  138. REQ_SCR_DLINE = KEY_MAX + 6;
  139. REQ_SCR_DPAGE = KEY_MAX + 7;
  140. REQ_SCR_UPAGE = KEY_MAX + 8;
  141. REQ_FIRST_ITEM = KEY_MAX + 9;
  142. REQ_LAST_ITEM = KEY_MAX + 10;
  143. REQ_NEXT_ITEM = KEY_MAX + 11;
  144. REQ_PREV_ITEM = KEY_MAX + 12;
  145. REQ_TOGGLE_ITEM = KEY_MAX + 13;
  146. REQ_CLEAR_PATTERN = KEY_MAX + 14;
  147. REQ_BACK_PATTERN = KEY_MAX + 15;
  148. REQ_NEXT_MATCH = KEY_MAX + 16;
  149. REQ_PREV_MATCH = KEY_MAX + 17;
  150. MIN_MENU_COMMAND = KEY_MAX + 1;
  151. MAX_MENU_COMMAND = KEY_MAX + 17;
  152. {
  153. Some AT&T code expects MAX_COMMAND to be out-of-band not
  154. just for menu commands but for forms ones as well.
  155. /
  156. #if defined(MAX_COMMAND)
  157. # if (MAX_MENU_COMMAND > MAX_COMMAND)
  158. # error Something is wrong -- MAX_MENU_COMMAND is greater than MAX_COMMAND
  159. # elif (MAX_COMMAND != (KEY_MAX + 128))
  160. # error Something is wrong -- MAX_COMMAND is already inconsistently defined.
  161. # endif
  162. #else
  163. # define MAX_COMMAND (KEY_MAX + 128)
  164. #endif
  165. }
  166. { --------- prototypes for libmenu functions ----------------------------- }
  167. function menu_items(_para1:pMENU):ppITEM;cdecl;
  168. function current_item(_para1:pMENU):pITEM;cdecl;
  169. function new_item(_para1:pchar; _para2:pchar):pITEM;cdecl;
  170. function new_menu(_para1:ppITEM):pMENU;cdecl;
  171. function item_opts(_para1:pITEM):Item_Options;cdecl;
  172. function menu_opts(_para1:pMENU):Menu_Options;cdecl;
  173. (*
  174. function item_init(_para1:pMENU):Menu_Hook;
  175. function item_term(_para1:pMENU):Menu_Hook;
  176. function menu_init(_para1:pMENU):Menu_Hook;
  177. function menu_term(_para1:pMENU):Menu_Hook;
  178. *)
  179. function menu_sub(_para1:pMENU):pWINDOW;cdecl;
  180. function menu_win(_para1:pMENU):pWINDOW;cdecl;
  181. function item_description(_para1:pITEM):pchar;cdecl;
  182. function item_name(_para1:pITEM):pchar;cdecl;
  183. function menu_mark(_para1:pMENU):pchar;cdecl;
  184. function menu_request_name(_para1:longint):pchar;cdecl;
  185. function menu_pattern(_para1:pMENU):pchar;cdecl;
  186. function menu_userptr(_para1:pMENU):pointer;cdecl;
  187. function item_userptr(_para1:pITEM):pointer;cdecl;
  188. function menu_back(_para1:pMENU):chtype;cdecl;
  189. function menu_fore(_para1:pMENU):chtype;cdecl;
  190. function menu_grey(_para1:pMENU):chtype;cdecl;
  191. function free_item(_para1:pITEM):longint;cdecl;
  192. function free_menu(_para1:pMENU):longint;cdecl;
  193. function item_count(_para1:pMENU):longint;cdecl;
  194. function item_index(_para1:pITEM):longint;cdecl;
  195. function item_opts_off(_para1:pITEM; _para2:Item_Options):longint;cdecl;
  196. function item_opts_on(_para1:pITEM; _para2:Item_Options):longint;cdecl;
  197. function menu_driver(_para1:pMENU; _para2:longint):longint;cdecl;
  198. function menu_opts_off(_para1:pMENU; _para2:Menu_Options):longint;cdecl;
  199. function menu_opts_on(_para1:pMENU; _para2:Menu_Options):longint;cdecl;
  200. function menu_pad(_para1:pMENU):longint;cdecl;
  201. function pos_menu_cursor(_para1:pMENU):longint;cdecl;
  202. function post_menu(_para1:pMENU):longint;cdecl;
  203. function scale_menu(_para1:pMENU; _para2:plongint; _para3:plongint):longint;cdecl;
  204. function set_current_item(menu:pMENU; item:pITEM):longint;cdecl;
  205. { function set_item_init(_para1:pMENU; _para2:Menu_Hook):longint;cdecl;}
  206. function set_item_opts(_para1:pITEM; _para2:Item_Options):longint;cdecl;
  207. { function set_item_term(_para1:pMENU; _para2:Menu_Hook):longint;cdecl;}
  208. function set_item_userptr(_para1:pITEM; _para2:pointer):longint;cdecl;
  209. function set_item_value(_para1:pITEM; _para2:bool):longint;cdecl;
  210. function set_menu_back(_para1:pMENU; _para2:chtype):longint;cdecl;
  211. function set_menu_fore(_para1:pMENU; _para2:chtype):longint;cdecl;
  212. function set_menu_format(_para1:pMENU; _para2:longint; _para3:longint):longint;cdecl;
  213. function set_menu_grey(_para1:pMENU; _para2:chtype):longint;cdecl;
  214. { function set_menu_init(_para1:pMENU; _para2:Menu_Hook):longint;cdecl;}
  215. function set_menu_items(_para1:pMENU; _para2:ppITEM):longint;cdecl;
  216. function set_menu_mark(_para1:pMENU; _para2:pchar):longint;cdecl;
  217. function set_menu_opts(_para1:pMENU; _para2:Menu_Options):longint;cdecl;
  218. function set_menu_pad(_para1:pMENU; _para2:longint):longint;cdecl;
  219. function set_menu_pattern(_para1:pMENU; _para2:pchar):longint;cdecl;
  220. function set_menu_sub(_para1:pMENU; _para2:pWINDOW):longint;cdecl;
  221. { function set_menu_term(_para1:pMENU; _para2:Menu_Hook):longint;cdecl;}
  222. function set_menu_userptr(_para1:pMENU; _para2:pointer):longint;cdecl;
  223. function set_menu_win(_para1:pMENU; _para2:pWINDOW):longint;cdecl;
  224. function set_top_row(_para1:pMENU; _para2:longint):longint;cdecl;
  225. function top_row(_para1:pMENU):longint;cdecl;
  226. function unpost_menu(_para1:pMENU):longint;cdecl;
  227. function menu_request_by_name(_para1:pchar):longint;cdecl;
  228. function set_menu_spacing(_para1:pMENU; _para2:longint; _para3:longint; _para4:longint):longint;cdecl;
  229. function menu_spacing(_para1:pMENU; _para2:plongint; _para3:plongint; _para4:plongint):longint;cdecl;
  230. function item_value(_para1:pITEM):bool;cdecl;
  231. function item_visible(_para1:pITEM):bool;cdecl;
  232. { procedure menu_format(_para1:pMENU; _para2:plongint; _para3:plongint);}
  233. implementation
  234. {const External_library=''; Setup as you need!}
  235. function menu_items(_para1:pMENU):ppITEM;cdecl;external;
  236. function current_item(_para1:pMENU):pITEM;cdecl;external;
  237. function new_item(_para1:pchar; _para2:pchar):pITEM;cdecl;external;
  238. function new_menu(_para1:ppITEM):pMENU;cdecl;external;
  239. function item_opts(_para1:pITEM):Item_Options;cdecl;external;
  240. function menu_opts(_para1:pMENU):Menu_Options;cdecl;external;
  241. (*
  242. function item_init(_para1:pMENU):Menu_Hook;
  243. begin
  244. { You must implemented this function }
  245. end;
  246. function item_term(_para1:pMENU):Menu_Hook;
  247. begin
  248. { You must implemented this function }
  249. end;
  250. function menu_init(_para1:pMENU):Menu_Hook;
  251. begin
  252. { You must implemented this function }
  253. end;
  254. function menu_term(_para1:pMENU):Menu_Hook;
  255. begin
  256. { You must implemented this function }
  257. end;
  258. *)
  259. function menu_sub(_para1:pMENU):pWINDOW;cdecl;external;
  260. function menu_win(_para1:pMENU):pWINDOW;cdecl;external;
  261. function item_description(_para1:pITEM):pchar;cdecl;external;
  262. function item_name(_para1:pITEM):pchar;cdecl;external;
  263. function menu_mark(_para1:pMENU):pchar;cdecl;external;
  264. function menu_request_name(_para1:longint):pchar;cdecl;external;
  265. function menu_pattern(_para1:pMENU):pchar;cdecl;external;
  266. function menu_userptr(_para1:pMENU):pointer;cdecl;external;
  267. function item_userptr(_para1:pITEM):pointer;cdecl;external;
  268. function menu_back(_para1:pMENU):chtype;cdecl;external;
  269. function menu_fore(_para1:pMENU):chtype;cdecl;external;
  270. function menu_grey(_para1:pMENU):chtype;cdecl;external;
  271. function free_item(_para1:pITEM):longint;cdecl;external;
  272. function free_menu(_para1:pMENU):longint;cdecl;external;
  273. function item_count(_para1:pMENU):longint;cdecl;external;
  274. function item_index(_para1:pITEM):longint;cdecl;external;
  275. function item_opts_off(_para1:pITEM; _para2:Item_Options):longint;cdecl;external;
  276. function item_opts_on(_para1:pITEM; _para2:Item_Options):longint;cdecl;external;
  277. function menu_driver(_para1:pMENU; _para2:longint):longint;cdecl;external;
  278. function menu_opts_off(_para1:pMENU; _para2:Menu_Options):longint;cdecl;external;
  279. function menu_opts_on(_para1:pMENU; _para2:Menu_Options):longint;cdecl;external;
  280. function menu_pad(_para1:pMENU):longint;cdecl;external;
  281. function pos_menu_cursor(_para1:pMENU):longint;cdecl;external;
  282. function post_menu(_para1:pMENU):longint;cdecl;external;
  283. function scale_menu(_para1:pMENU; _para2:plongint; _para3:plongint):longint;cdecl;external;
  284. function set_current_item(menu:pMENU; item:pITEM):longint;cdecl;external;
  285. { function set_item_init(_para1:pMENU; _para2:Menu_Hook):longint;cdecl;external;}
  286. function set_item_opts(_para1:pITEM; _para2:Item_Options):longint;cdecl;external;
  287. { function set_item_term(_para1:pMENU; _para2:Menu_Hook):longint;cdecl;external;}
  288. function set_item_userptr(_para1:pITEM; _para2:pointer):longint;cdecl;external;
  289. function set_item_value(_para1:pITEM; _para2:bool):longint;cdecl;external;
  290. function set_menu_back(_para1:pMENU; _para2:chtype):longint;cdecl;external;
  291. function set_menu_fore(_para1:pMENU; _para2:chtype):longint;cdecl;external;
  292. function set_menu_format(_para1:pMENU; _para2:longint; _para3:longint):longint;cdecl;external;
  293. function set_menu_grey(_para1:pMENU; _para2:chtype):longint;cdecl;external;
  294. { function set_menu_init(_para1:pMENU; _para2:Menu_Hook):longint;cdecl;external;}
  295. function set_menu_items(_para1:pMENU; _para2:ppITEM):longint;cdecl;external;
  296. function set_menu_mark(_para1:pMENU; _para2:pchar):longint;cdecl;external;
  297. function set_menu_opts(_para1:pMENU; _para2:Menu_Options):longint;cdecl;external;
  298. function set_menu_pad(_para1:pMENU; _para2:longint):longint;cdecl;external;
  299. function set_menu_pattern(_para1:pMENU; _para2:pchar):longint;cdecl;external;
  300. function set_menu_sub(_para1:pMENU; _para2:pWINDOW):longint;cdecl;external;
  301. { function set_menu_term(_para1:pMENU; _para2:Menu_Hook):longint;cdecl;external;}
  302. function set_menu_userptr(_para1:pMENU; _para2:pointer):longint;cdecl;external;
  303. function set_menu_win(_para1:pMENU; _para2:pWINDOW):longint;cdecl;external;
  304. function set_top_row(_para1:pMENU; _para2:longint):longint;cdecl;external;
  305. function top_row(_para1:pMENU):longint;cdecl;external;
  306. function unpost_menu(_para1:pMENU):longint;cdecl;external;
  307. function menu_request_by_name(_para1:pchar):longint;cdecl;external;
  308. function set_menu_spacing(_para1:pMENU; _para2:longint; _para3:longint; _para4:longint):longint;cdecl;external;
  309. function menu_spacing(_para1:pMENU; _para2:plongint; _para3:plongint; _para4:plongint):longint;cdecl;external;
  310. function item_value(_para1:pITEM):bool;cdecl;external;
  311. function item_visible(_para1:pITEM):bool;cdecl;external;
  312. (*
  313. procedure menu_format(_para1:pMENU; _para2:plongint; _para3:plongint);
  314. begin
  315. { You must implemented this function }
  316. end;
  317. *)
  318. begin
  319. end.