1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding Samples --
9 ------------------------------------------------------------------------------
10 -- Copyright 2020 Thomas E. Dickey --
11 -- Copyright 1998-2008,2011 Free Software Foundation, Inc. --
13 -- Permission is hereby granted, free of charge, to any person obtaining a --
14 -- copy of this software and associated documentation files (the --
15 -- "Software"), to deal in the Software without restriction, including --
16 -- without limitation the rights to use, copy, modify, merge, publish, --
17 -- distribute, distribute with modifications, sublicense, and/or sell --
18 -- copies of the Software, and to permit persons to whom the Software is --
19 -- furnished to do so, subject to the following conditions: --
21 -- The above copyright notice and this permission notice shall be included --
22 -- in all copies or substantial portions of the Software. --
24 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
25 -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
26 -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
27 -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
28 -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
29 -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
30 -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
32 -- Except as contained in this notice, the name(s) of the above copyright --
33 -- holders shall not be used in advertising or otherwise to promote the --
34 -- sale, use or other dealings in this Software without prior written --
36 ------------------------------------------------------------------------------
37 -- Author: Juergen Pfeifer, 1996
40 -- $Date: 2020/02/02 23:34:34 $
41 -- Binding Version 01.00
42 ------------------------------------------------------------------------------
43 with Terminal_Interface.Curses; use Terminal_Interface.Curses;
44 with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
45 with Terminal_Interface.Curses.Menus; use Terminal_Interface.Curses.Menus;
46 with Terminal_Interface.Curses.Menus.Menu_User_Data;
47 with Terminal_Interface.Curses.Menus.Item_User_Data;
49 with Sample.Manifest; use Sample.Manifest;
50 with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
51 with Sample.Menu_Demo.Handler;
52 with Sample.Helpers; use Sample.Helpers;
53 with Sample.Explanation; use Sample.Explanation;
55 package body Sample.Menu_Demo is
57 package Spacing_Demo is
58 procedure Spacing_Test;
61 package body Spacing_Demo is
63 procedure Spacing_Test
65 function My_Driver (M : Menu;
67 P : Panel) return Boolean;
69 procedure Set_Option_Key;
70 procedure Set_Select_Key;
71 procedure Set_Description_Key;
72 procedure Set_Hide_Key;
74 package Mh is new Sample.Menu_Demo.Handler (My_Driver);
76 I : Item_Array_Access := new Item_Array'
77 (New_Item ("January", "31 Days"),
78 New_Item ("February", "28/29 Days"),
79 New_Item ("March", "31 Days"),
80 New_Item ("April", "30 Days"),
81 New_Item ("May", "31 Days"),
82 New_Item ("June", "30 Days"),
83 New_Item ("July", "31 Days"),
84 New_Item ("August", "31 Days"),
85 New_Item ("September", "30 Days"),
86 New_Item ("October", "31 Days"),
87 New_Item ("November", "30 Days"),
88 New_Item ("December", "31 Days"),
91 M : Menu := New_Menu (I);
92 Flip_State : Boolean := True;
93 Hide_Long : Boolean := False;
95 type Format_Code is (Four_By_1, Four_By_2, Four_By_3);
96 type Operations is (Flip, Reorder, Reformat, Reselect, Describe);
98 type Change is array (Operations) of Boolean;
100 No_Change : constant Change := Change'(others => False);
102 Current_Format : Format_Code := Four_By_1;
103 To_Change : Change := No_Change;
105 function My_Driver (M : Menu;
107 P : Panel) return Boolean
110 if M = Null_Menu then
111 raise Menu_Exception;
113 if P = Null_Panel then
114 raise Panel_Exception;
116 To_Change := No_Change;
117 if K in User_Key_Code'Range then
122 if K in Special_Key_Code'Range then
125 To_Change (Flip) := True;
128 To_Change (Reformat) := True;
129 Current_Format := Four_By_1;
132 To_Change (Reformat) := True;
133 Current_Format := Four_By_2;
136 To_Change (Reformat) := True;
137 Current_Format := Four_By_3;
140 To_Change (Reorder) := True;
143 To_Change (Reselect) := True;
146 if Current_Format /= Four_By_3 then
147 To_Change (Describe) := True;
153 Hide_Long := not Hide_Long;
157 for J in I'Range loop
158 Get_Options (I.all (J), O);
159 O.Selectable := True;
162 when 1 | 3 | 5 | 7 | 8 | 10 | 12 =>
163 O.Selectable := False;
167 Set_Options (I.all (J), O);
177 procedure Set_Option_Key
181 if Current_Format = Four_By_1 then
182 Set_Soft_Label_Key (8, "");
185 if O.Row_Major_Order then
186 Set_Soft_Label_Key (8, "O-Col");
188 Set_Soft_Label_Key (8, "O-Row");
191 Refresh_Soft_Label_Keys_Without_Update;
194 procedure Set_Select_Key
200 Set_Soft_Label_Key (9, "Multi");
202 Set_Soft_Label_Key (9, "Singl");
204 Refresh_Soft_Label_Keys_Without_Update;
207 procedure Set_Description_Key
211 if Current_Format = Four_By_3 then
212 Set_Soft_Label_Key (10, "");
215 if O.Show_Descriptions then
216 Set_Soft_Label_Key (10, "-Desc");
218 Set_Soft_Label_Key (10, "+Desc");
221 Refresh_Soft_Label_Keys_Without_Update;
222 end Set_Description_Key;
224 procedure Set_Hide_Key
228 Set_Soft_Label_Key (11, "Enab");
230 Set_Soft_Label_Key (11, "Disab");
232 Refresh_Soft_Label_Keys_Without_Update;
236 Push_Environment ("MENU01");
237 Notepad ("MENU-PAD01");
239 Set_Soft_Label_Key (4, "Flip");
240 Set_Soft_Label_Key (5, "4x1");
241 Set_Soft_Label_Key (6, "4x2");
242 Set_Soft_Label_Key (7, "4x3");
248 Set_Format (M, 4, 1);
251 exit when To_Change = No_Change;
252 if To_Change (Flip) then
255 Set_Spacing (M, 3, 2, 0);
260 elsif To_Change (Reformat) then
261 case Current_Format is
262 when Four_By_1 => Set_Format (M, 4, 1);
263 when Four_By_2 => Set_Format (M, 4, 2);
269 O.Show_Descriptions := False;
271 Set_Format (M, 4, 3);
276 elsif To_Change (Reorder) then
281 O.Row_Major_Order := not O.Row_Major_Order;
285 elsif To_Change (Reselect) then
290 O.One_Valued := not O.One_Valued;
294 elsif To_Change (Describe) then
299 O.Show_Descriptions := not O.Show_Descriptions;
310 pragma Assert (Get_Index (Items (M, 1)) = Get_Index (I (1)));
318 -- We use this datatype only to test the instantiation of
319 -- the Menu_User_Data generic package. No functionality
321 type User_Data is new Integer;
322 type User_Data_Access is access User_Data;
324 -- Those packages are only instantiated to test the usability.
325 -- No real functionality is shown in the demo.
326 package MUD is new Menu_User_Data (User_Data, User_Data_Access);
327 package IUD is new Item_User_Data (User_Data, User_Data_Access);
329 function My_Driver (M : Menu;
331 P : Panel) return Boolean;
333 package Mh is new Sample.Menu_Demo.Handler (My_Driver);
335 Itm : Item_Array_Access := new Item_Array'
336 (New_Item ("Menu Layout Options"),
337 New_Item ("Demo of Hook functions"),
339 M : Menu := New_Menu (Itm);
341 U1 : constant User_Data_Access := new User_Data'(4711);
342 U2 : User_Data_Access;
343 U3 : constant User_Data_Access := new User_Data'(4712);
344 U4 : User_Data_Access;
346 function My_Driver (M : Menu;
348 P : Panel) return Boolean
350 Idx : constant Positive := Get_Index (Current (M));
352 if K in User_Key_Code'Range then
355 elsif K = SELECT_ITEM then
356 if Idx in Itm'Range then
361 when 1 => Spacing_Demo.Spacing_Test;
362 when others => Not_Implemented;
364 if Idx in Itm'Range then
375 Push_Environment ("MENU00");
376 Notepad ("MENU-PAD00");
378 Refresh_Soft_Label_Keys_Without_Update;
379 Set_Pad_Character (M, '|');
381 MUD.Set_User_Data (M, U1);
382 IUD.Set_User_Data (Itm.all (1), U3);
386 MUD.Get_User_Data (M, U2);
387 pragma Assert (U1 = U2 and U1.all = 4711);
389 IUD.Get_User_Data (Itm.all (1), U4);
390 pragma Assert (U3 = U4 and U3.all = 4712);
397 end Sample.Menu_Demo;