1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding Samples --
9 ------------------------------------------------------------------------------
10 -- Copyright (c) 1998 Free Software Foundation, Inc. --
12 -- Permission is hereby granted, free of charge, to any person obtaining a --
13 -- copy of this software and associated documentation files (the --
14 -- "Software"), to deal in the Software without restriction, including --
15 -- without limitation the rights to use, copy, modify, merge, publish, --
16 -- distribute, distribute with modifications, sublicense, and/or sell --
17 -- copies of the Software, and to permit persons to whom the Software is --
18 -- furnished to do so, subject to the following conditions: --
20 -- The above copyright notice and this permission notice shall be included --
21 -- in all copies or substantial portions of the Software. --
23 -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
24 -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
25 -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. --
26 -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
27 -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
28 -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR --
29 -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. --
31 -- Except as contained in this notice, the name(s) of the above copyright --
32 -- holders shall not be used in advertising or otherwise to promote the --
33 -- sale, use or other dealings in this Software without prior written --
35 ------------------------------------------------------------------------------
36 -- Author: Juergen Pfeifer, 1996
39 -- Binding Version 01.00
40 ------------------------------------------------------------------------------
41 with Terminal_Interface.Curses; use Terminal_Interface.Curses;
42 with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
43 with Terminal_Interface.Curses.Menus; use Terminal_Interface.Curses.Menus;
44 with Terminal_Interface.Curses.Menus.Menu_User_Data;
45 with Terminal_Interface.Curses.Menus.Item_User_Data;
47 with Sample.Manifest; use Sample.Manifest;
48 with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
49 with Sample.Menu_Demo.Handler;
50 with Sample.Helpers; use Sample.Helpers;
51 with Sample.Explanation; use Sample.Explanation;
53 package body Sample.Menu_Demo is
55 package Spacing_Demo is
56 procedure Spacing_Test;
59 package body Spacing_Demo is
61 procedure Spacing_Test
63 function My_Driver (M : Menu;
65 P : Panel) return Boolean;
67 procedure Set_Option_Key;
68 procedure Set_Select_Key;
69 procedure Set_Description_Key;
70 procedure Set_Hide_Key;
72 package Mh is new Sample.Menu_Demo.Handler (My_Driver);
74 I : Item_Array_Access := new Item_Array'
75 (New_Item ("January", "31 Days"),
76 New_Item ("February", "28/29 Days"),
77 New_Item ("March", "31 Days"),
78 New_Item ("April", "30 Days"),
79 New_Item ("May", "31 Days"),
80 New_Item ("June", "30 Days"),
81 New_Item ("July", "31 Days"),
82 New_Item ("August", "31 Days"),
83 New_Item ("September", "30 Days"),
84 New_Item ("October", "31 Days"),
85 New_Item ("November", "30 Days"),
86 New_Item ("December", "31 Days"),
89 M : Menu := New_Menu (I);
90 Flip_State : Boolean := True;
91 Hide_Long : Boolean := False;
93 type Format_Code is (Four_By_1, Four_By_2, Four_By_3);
94 type Operations is (Flip, Reorder, Reformat, Reselect, Describe);
96 type Change is array (Operations) of Boolean;
98 No_Change : constant Change := Change'(others => False);
100 Current_Format : Format_Code := Four_By_1;
101 To_Change : Change := No_Change;
103 function My_Driver (M : Menu;
105 P : Panel) return Boolean
108 To_Change := No_Change;
109 if K in User_Key_Code'Range then
114 if K in Special_Key_Code'Range then
117 To_Change (Flip) := True;
120 To_Change (Reformat) := True;
121 Current_Format := Four_By_1;
124 To_Change (Reformat) := True;
125 Current_Format := Four_By_2;
128 To_Change (Reformat) := True;
129 Current_Format := Four_By_3;
132 To_Change (Reorder) := True;
135 To_Change (Reselect) := True;
138 if Current_Format /= Four_By_3 then
139 To_Change (Describe) := True;
145 Hide_Long := not Hide_Long;
149 for J in I'Range loop
150 Get_Options (I (J), O);
151 O.Selectable := True;
154 when 1 | 3 | 5 | 7 | 8 | 10 | 12 =>
155 O.Selectable := False;
159 Set_Options (I (J), O);
169 procedure Set_Option_Key
173 if Current_Format = Four_By_1 then
174 Set_Soft_Label_Key (8, "");
177 if O.Row_Major_Order then
178 Set_Soft_Label_Key (8, "O-Col");
180 Set_Soft_Label_Key (8, "O-Row");
183 Refresh_Soft_Label_Keys_Without_Update;
186 procedure Set_Select_Key
192 Set_Soft_Label_Key (9, "Multi");
194 Set_Soft_Label_Key (9, "Singl");
196 Refresh_Soft_Label_Keys_Without_Update;
199 procedure Set_Description_Key
203 if Current_Format = Four_By_3 then
204 Set_Soft_Label_Key (10, "");
207 if O.Show_Descriptions then
208 Set_Soft_Label_Key (10, "-Desc");
210 Set_Soft_Label_Key (10, "+Desc");
213 Refresh_Soft_Label_Keys_Without_Update;
214 end Set_Description_Key;
216 procedure Set_Hide_Key
220 Set_Soft_Label_Key (11, "Enab");
222 Set_Soft_Label_Key (11, "Disab");
224 Refresh_Soft_Label_Keys_Without_Update;
228 Push_Environment ("MENU01");
229 Notepad ("MENU-PAD01");
231 Set_Soft_Label_Key (4, "Flip");
232 Set_Soft_Label_Key (5, "4x1");
233 Set_Soft_Label_Key (6, "4x2");
234 Set_Soft_Label_Key (7, "4x3");
240 Set_Format (M, 4, 1);
243 exit when To_Change = No_Change;
244 if To_Change (Flip) then
247 Set_Spacing (M, 3, 2, 0);
252 elsif To_Change (Reformat) then
253 case Current_Format is
254 when Four_By_1 => Set_Format (M, 4, 1);
255 when Four_By_2 => Set_Format (M, 4, 2);
261 O.Show_Descriptions := False;
263 Set_Format (M, 4, 3);
268 elsif To_Change (Reorder) then
273 O.Row_Major_Order := not O.Row_Major_Order;
277 elsif To_Change (Reselect) then
282 O.One_Valued := not O.One_Valued;
286 elsif To_Change (Describe) then
291 O.Show_Descriptions := not O.Show_Descriptions;
303 pragma Assert (Get_Index (Items (M, 1)) = Get_Index (I (1)));
311 -- We use this datatype only to test the instantiation of
312 -- the Menu_User_Data generic package. No functionality
314 type User_Data is new Integer;
315 type User_Data_Access is access User_Data;
317 -- Those packages are only instantiated to test the usability.
318 -- No real functionality is shown in the demo.
319 package MUD is new Menu_User_Data (User_Data, User_Data_Access);
320 package IUD is new Item_User_Data (User_Data, User_Data_Access);
322 function My_Driver (M : Menu;
324 P : Panel) return Boolean;
326 package Mh is new Sample.Menu_Demo.Handler (My_Driver);
328 Itm : Item_Array_Access := new Item_Array'
329 (New_Item ("Menu Layout Options"),
330 New_Item ("Demo of Hook functions"),
332 M : Menu := New_Menu (Itm);
334 U1 : User_Data_Access := new User_Data'(4711);
335 U2 : User_Data_Access;
336 U3 : User_Data_Access := new User_Data'(4712);
337 U4 : User_Data_Access;
339 function My_Driver (M : Menu;
341 P : Panel) return Boolean
343 Idx : constant Positive := Get_Index (Current (M));
345 if K in User_Key_Code'Range then
348 elsif K = SELECT_ITEM then
349 if Idx in Itm'Range then
354 when 1 => Spacing_Demo.Spacing_Test;
355 when others => Not_Implemented;
357 if Idx in Itm'Range then
368 Push_Environment ("MENU00");
369 Notepad ("MENU-PAD00");
371 Refresh_Soft_Label_Keys_Without_Update;
372 Set_Pad_Character (M, '|');
374 MUD.Set_User_Data (M, U1);
375 IUD.Set_User_Data (Itm (1), U3);
379 MUD.Get_User_Data (M, U2);
380 pragma Assert (U1 = U2 and U1.all = 4711);
382 IUD.Get_User_Data (Itm (1), U4);
383 pragma Assert (U3 = U4 and U3.all = 4712);
390 end Sample.Menu_Demo;