2 define(`HTMLNAME',`terminal_interface-curses-menus_s.html')dnl
4 ------------------------------------------------------------------------------
6 -- GNAT ncurses Binding --
8 -- Terminal_Interface.Curses.Menu --
14 -- The ncurses Ada95 binding is copyrighted 1996 by --
15 -- Juergen Pfeifer, Email: Juergen.Pfeifer@T-Online.de --
17 -- Permission is hereby granted to reproduce and distribute this --
18 -- binding by any means and for any fee, whether alone or as part --
19 -- of a larger distribution, in source or in binary form, PROVIDED --
20 -- this notice is included with any such distribution, and is not --
21 -- removed from any of its header files. Mention of ncurses and the --
22 -- author of this binding in any applications linked with it is --
23 -- highly appreciated. --
25 -- This binding comes AS IS with no warranty, implied or expressed. --
26 ------------------------------------------------------------------------------
29 ------------------------------------------------------------------------------
30 include(`Menu_Base_Defs')
33 with Ada.Characters.Latin_1;
35 package Terminal_Interface.Curses.Menus is
37 include(`Menu_Linker_Options')
40 Space : Character renames Ada.Characters.Latin_1.Space;
45 ---------------------------
46 -- Interface constants --
47 ---------------------------
48 Null_Item : constant Item;
49 Null_Menu : constant Menu;
51 subtype Menu_Request_Code is Key_Code
52 range (Key_Max + 1) .. (Key_Max + 17);
54 -- The prefix M_ stands for "Menu Request"
55 M_Left_Item : constant Menu_Request_Code := Key_Max + 1;
56 M_Right_Item : constant Menu_Request_Code := Key_Max + 2;
57 M_Up_Item : constant Menu_Request_Code := Key_Max + 3;
58 M_Down_Item : constant Menu_Request_Code := Key_Max + 4;
59 M_ScrollUp_Line : constant Menu_Request_Code := Key_Max + 5;
60 M_ScrollDown_Line : constant Menu_Request_Code := Key_Max + 6;
61 M_ScrollDown_Page : constant Menu_Request_Code := Key_Max + 7;
62 M_ScrollUp_Page : constant Menu_Request_Code := Key_Max + 8;
63 M_First_Item : constant Menu_Request_Code := Key_Max + 9;
64 M_Last_Item : constant Menu_Request_Code := Key_Max + 10;
65 M_Next_Item : constant Menu_Request_Code := Key_Max + 11;
66 M_Previous_Item : constant Menu_Request_Code := Key_Max + 12;
67 M_Toggle_Item : constant Menu_Request_Code := Key_Max + 13;
68 M_Clear_Pattern : constant Menu_Request_Code := Key_Max + 14;
69 M_Back_Pattern : constant Menu_Request_Code := Key_Max + 15;
70 M_Next_Match : constant Menu_Request_Code := Key_Max + 16;
71 M_Previous_Match : constant Menu_Request_Code := Key_Max + 17;
73 -- For those who like the old 'C' names for the request codes
74 REQ_LEFT_ITEM : Menu_Request_Code renames M_Left_Item;
75 REQ_RIGHT_ITEM : Menu_Request_Code renames M_Right_Item;
76 REQ_UP_ITEM : Menu_Request_Code renames M_Up_Item;
77 REQ_DOWN_ITEM : Menu_Request_Code renames M_Down_Item;
78 REQ_SCR_ULINE : Menu_Request_Code renames M_ScrollUp_Line;
79 REQ_SCR_DLINE : Menu_Request_Code renames M_ScrollDown_Line;
80 REQ_SCR_DPAGE : Menu_Request_Code renames M_ScrollDown_Page;
81 REQ_SCR_UPAGE : Menu_Request_Code renames M_ScrollUp_Page;
82 REQ_FIRST_ITEM : Menu_Request_Code renames M_First_Item;
83 REQ_LAST_ITEM : Menu_Request_Code renames M_Last_Item;
84 REQ_NEXT_ITEM : Menu_Request_Code renames M_Next_Item;
85 REQ_PREV_ITEM : Menu_Request_Code renames M_Previous_Item;
86 REQ_TOGGLE_ITEM : Menu_Request_Code renames M_Toggle_Item;
87 REQ_CLEAR_PATTERN : Menu_Request_Code renames M_Clear_Pattern;
88 REQ_BACK_PATTERN : Menu_Request_Code renames M_Back_Pattern;
89 REQ_NEXT_MATCH : Menu_Request_Code renames M_Next_Match;
90 REQ_PREV_MATCH : Menu_Request_Code renames M_Previous_Match;
92 procedure Request_Name (Key : in Menu_Request_Code;
99 Menu_Exception : exception;
104 include(`Menu_Opt_Rep')
106 Default_Menu_Options : Menu_Option_Set;
107 -- Initial default options for a menu.
114 Default_Item_Options : Item_Option_Set;
115 -- Initial default options for an item.
120 type Item_Array is array (Positive range <>) of aliased Item;
121 pragma Convention (C, Item_Array);
123 type Item_Array_Access is access all Item_Array;
125 -- MANPAGE(`mitem_new.3x')
127 -- ANCHOR(`new_item()',`Create')
128 function Create (Name : String;
129 Description : String := "") return Item;
132 -- ANCHOR(`new_item()',`New_Item')
133 function New_Item (Name : String;
134 Description : String := "") return Item
138 -- ANCHOR(`free_item()',`Delete')
139 procedure Delete (Itm : in out Item);
141 -- Resets Itm to Null_Item
143 -- MANPAGE(`mitem_value.3x')
145 -- ANCHOR(`set_item_value()',`Set_Value')
146 procedure Set_Value (Itm : in Item;
147 Value : in Boolean := True);
150 -- ANCHOR(`item_value()',`Value')
151 function Value (Itm : Item) return Boolean;
154 -- MANPAGE(`mitem_visible.3x')
156 -- ANCHOR(`item_visible()',`Visible')
157 function Visible (Itm : Item) return Boolean;
160 -- MANPAGE(`mitem_opts.3x')
162 -- ANCHOR(`set_item_opts()',`Set_Options')
163 procedure Set_Options (Itm : in Item;
164 Options : in Item_Option_Set);
167 -- ANCHOR(`item_opts_on()',`Switch_Options')
168 procedure Switch_Options (Itm : in Item;
169 Options : in Item_Option_Set;
170 On : Boolean := True);
172 -- ALIAS(`item_opts_off()')
174 -- ANCHOR(`item_opts()',`Get_Options')
175 procedure Get_Options (Itm : in Item;
176 Options : out Item_Option_Set);
179 -- ANCHOR(`item_opts()',`Get_Options')
180 function Get_Options (Itm : Item := Null_Item) return Item_Option_Set;
183 -- MANPAGE(`mitem_name.3x')
185 -- ANCHOR(`item_name()',`Name')
186 procedure Name (Itm : in Item;
190 -- ANCHOR(`item_description();',`Description')
191 procedure Description (Itm : in Item;
192 Description : out String);
195 -- MANPAGE(`mitem_current.3x')
197 -- ANCHOR(`set_current_item()',`Set_Current')
198 procedure Set_Current (Men : in Menu;
202 -- ANCHOR(`current_item()',`Current')
203 function Current (Men : Menu) return Item;
206 -- ANCHOR(`set_top_row()',`Set_Top_Row')
207 procedure Set_Top_Row (Men : in Menu;
208 Line : in Line_Position);
211 -- ANCHOR(`top_row()',`Top_Row')
212 function Top_Row (Men : Menu) return Line_Position;
215 -- ANCHOR(`item_index()',`Get_Index')
216 function Get_Index (Itm : Item) return Positive;
218 -- Please note that in this binding we start the numbering of items
219 -- with 1. So this is number is one more than you get from the low
222 -- MANPAGE(`menu_post.3x')
224 -- ANCHOR(`post_menu()',`Post')
225 procedure Post (Men : in Menu;
226 Post : in Boolean := True);
228 -- ALIAS(`unpost_menu()')
230 -- MANPAGE(`menu_opts.3x')
232 -- ANCHOR(`set_menu_opts()',`Set_Options')
233 procedure Set_Options (Men : in Menu;
234 Options : in Menu_Option_Set);
237 -- ANCHOR(`menu_opts_on()',`Switch_Options')
238 procedure Switch_Options (Men : in Menu;
239 Options : in Menu_Option_Set;
240 On : Boolean := True);
242 -- ALIAS(`menu_opts_off()')
244 -- ANCHOR(`menu_opts()',`Get_Options')
245 procedure Get_Options (Men : in Menu;
246 Options : out Menu_Option_Set);
249 -- ANCHOR(`menu_opts()',`Get_Options')
250 function Get_Options (Men : Menu := Null_Menu) return Menu_Option_Set;
253 -- MANPAGE(`menu_win.3x')
255 -- ANCHOR(`set_menu_win()',`Set_Window')
256 procedure Set_Window (Men : in Menu;
260 -- ANCHOR(`menu_win()',`Get_Window')
261 function Get_Window (Men : Menu) return Window;
264 -- ANCHOR(`set_menu_sub()',`Set_Sub_Window')
265 procedure Set_Sub_Window (Men : in Menu;
269 -- ANCHOR(`menu_sub()',`Get_Sub_Window')
270 function Get_Sub_Window (Men : Menu) return Window;
273 -- ANCHOR(`scale_menu()',`Scale')
274 procedure Scale (Men : in Menu;
275 Lines : out Line_Count;
276 Columns : out Column_Count);
279 -- MANPAGE(`menu_cursor.3x')
281 -- ANCHOR(`pos_menu_cursor()',`Position_Cursor')
282 procedure Position_Cursor (Men : Menu);
285 -- MANPAGE(`menu_mark.3x')
287 -- ANCHOR(`set_menu_mark()',`Set_Mark')
288 procedure Set_Mark (Men : in Menu;
292 -- ANCHOR(`menu_mark()',`Mark')
293 procedure Mark (Men : in Menu;
297 -- MANPAGE(`menu_attribs.3x')
299 -- ANCHOR(`set_menu_fore()',`Set_Foreground')
300 procedure Set_Foreground
302 Fore : in Character_Attribute_Set := Normal_Video;
303 Color : in Color_Pair := Color_Pair'First);
306 -- ANCHOR(`menu_fore()',`Foreground')
307 procedure Foreground (Men : in Menu;
308 Fore : out Character_Attribute_Set);
311 -- ANCHOR(`menu_fore()',`Foreground')
312 procedure Foreground (Men : in Menu;
313 Fore : out Character_Attribute_Set;
314 Color : out Color_Pair);
317 -- ANCHOR(`set_menu_back()',`Set_Background')
318 procedure Set_Background
320 Back : in Character_Attribute_Set := Normal_Video;
321 Color : in Color_Pair := Color_Pair'First);
324 -- ANCHOR(`menu_back()',`Background')
325 procedure Background (Men : in Menu;
326 Back : out Character_Attribute_Set);
328 -- ANCHOR(`menu_back()',`Background')
330 procedure Background (Men : in Menu;
331 Back : out Character_Attribute_Set;
332 Color : out Color_Pair);
335 -- ANCHOR(`set_menu_grey()',`Set_Grey')
338 Grey : in Character_Attribute_Set := Normal_Video;
339 Color : in Color_Pair := Color_Pair'First);
342 -- ANCHOR(`menu_grey()',`Grey')
343 procedure Grey (Men : in Menu;
344 Grey : out Character_Attribute_Set);
347 -- ANCHOR(`menu_grey()',`Grey')
350 Grey : out Character_Attribute_Set;
351 Color : out Color_Pair);
354 -- ANCHOR(`set_menu_pad()',`Set_Pad_Character')
355 procedure Set_Pad_Character (Men : in Menu;
356 Pad : in Character := Space);
359 -- ANCHOR(`menu_pad()',`Pad_Character')
360 procedure Pad_Character (Men : in Menu;
361 Pad : out Character);
364 -- MANPAGE(`menu_spacing.3x')
366 -- ANCHOR(`set_menu_spacing()',`Set_Spacing')
367 procedure Set_Spacing (Men : in Menu;
368 Descr : in Column_Position := 0;
369 Row : in Line_Position := 0;
370 Col : in Column_Position := 0);
373 -- ANCHOR(`menu_spacing()',`Spacing')
374 procedure Spacing (Men : in Menu;
375 Descr : out Column_Position;
376 Row : out Line_Position;
377 Col : out Column_Position);
380 -- MANPAGE(`menu_pattern.3x')
382 -- ANCHOR(`set_menu_pattern()',`Set_Pattern')
383 function Set_Pattern (Men : Menu;
384 Text : String) return Boolean;
386 -- Return TRUE if the pattern matches, FALSE otherwise
388 -- ANCHOR(`menu_pattern()',`Pattern')
389 procedure Pattern (Men : in Menu;
393 -- MANPAGE(`menu_format.3x')
395 -- ANCHOR(`set_menu_format()',`Set_Format')
396 procedure Set_Format (Men : in Menu;
397 Lines : in Line_Count;
398 Columns : in Column_Count);
401 -- ANCHOR(`menu_format()',`Format')
402 procedure Format (Men : in Menu;
403 Lines : out Line_Count;
404 Columns : out Column_Count);
407 -- MANPAGE(`menu_hook.3x')
409 type Menu_Hook_Function is access procedure (Men : in Menu);
410 pragma Convention (C, Menu_Hook_Function);
412 -- ANCHOR(`set_item_init()',`Set_Item_Init_Hook')
413 procedure Set_Item_Init_Hook (Men : in Menu;
414 Proc : in Menu_Hook_Function);
417 -- ANCHOR(`set_item_term()',`Set_Item_Term_Hook')
418 procedure Set_Item_Term_Hook (Men : in Menu;
419 Proc : in Menu_Hook_Function);
422 -- ANCHOR(`set_menu_init()',`Set_Menu_Init_Hook')
423 procedure Set_Menu_Init_Hook (Men : in Menu;
424 Proc : in Menu_Hook_Function);
427 -- ANCHOR(`set_menu_term()',`Set_Menu_Term_Hook')
428 procedure Set_Menu_Term_Hook (Men : in Menu;
429 Proc : in Menu_Hook_Function);
432 -- ANCHOR(`item_init()',`Get_Item_Init_Hook')
433 function Get_Item_Init_Hook (Men : Menu) return Menu_Hook_Function;
436 -- ANCHOR(`item_term()',`Get_Item_Term_Hook')
437 function Get_Item_Term_Hook (Men : Menu) return Menu_Hook_Function;
440 -- ANCHOR(`menu_init()',`Get_Menu_Init_Hook')
441 function Get_Menu_Init_Hook (Men : Menu) return Menu_Hook_Function;
444 -- ANCHOR(`menu_term()',`Get_Menu_Term_Hook')
445 function Get_Menu_Term_Hook (Men : Menu) return Menu_Hook_Function;
448 -- MANPAGE(`menu_items.3x')
450 -- ANCHOR(`set_menu_items()',`Redefine')
451 procedure Redefine (Men : in Menu;
452 Items : in Item_Array);
454 -- With a bit more comfort. You donĀ“t need to terminate the Item_Array
455 -- with a null entry. This is handled internally in the binding.
457 procedure Set_Items (Men : in Menu;
458 Items : in Item_Array) renames Redefine;
460 -- ANCHOR(`menu_items()',`Items')
461 function Items (Men : Menu) return Item_Array_Access;
464 -- ANCHOR(`item_count()',`Item_Count')
465 function Item_Count (Men : Menu) return Natural;
468 -- MANPAGE(`menu_new.3x')
470 -- ANCHOR(`new_menu()',`Create')
471 function Create (Items : Item_Array) return Menu;
474 function New_Menu (Items : Item_Array) return Menu renames Create;
476 -- ANCHOR(`free_menu()',`Delete')
477 procedure Delete (Men : in out Menu);
479 -- Reset Men to Null_Menu
481 -- MANPAGE(`menu_new.3x')
483 type Driver_Result is (Menu_Ok,
488 -- ANCHOR(`menu_driver()',`Driver')
489 function Driver (Men : Menu;
490 Key : Key_Code) return Driver_Result;
493 -------------------------------------------------------------------------------
495 type Item is new System.Address;
496 type Menu is new System.Address;
498 Null_Item : constant Item := Item (System.Null_Address);
499 Null_Menu : constant Menu := Menu (System.Null_Address);
501 -- This binding uses the original user pointer mechanism of a menu to store
502 -- specific informations about a menu. This wrapper record carries this
503 -- specifics and contains a field to maintain a new user pointer. Please
504 -- note that you must take this into account if you wan't to use the user
505 -- pointer mechanism of a menu created with this binding in low-level C
507 type Ada_User_Wrapper is
510 I : Item_Array_Access;
512 pragma Convention (C, Ada_User_Wrapper);
513 type Ada_User_Wrapper_Access is access all Ada_User_Wrapper;
514 pragma Controlled (Ada_User_Wrapper_Access);
516 Generation_Bit_Order : constant System.Bit_Order := System.M4_BIT_ORDER;
517 -- This constant may be different on your system.
519 end Terminal_Interface.Curses.Menus;