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
37 -- Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en
40 -- Binding Version 01.00
41 ------------------------------------------------------------------------------
42 with Terminal_Interface.Curses; use Terminal_Interface.Curses;
43 with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
44 with Terminal_Interface.Curses.Menus; use Terminal_Interface.Curses.Menus;
45 with Terminal_Interface.Curses.Menus.Menu_User_Data;
46 with Terminal_Interface.Curses.Menus.Item_User_Data;
48 with Sample.Manifest; use Sample.Manifest;
49 with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
50 with Sample.Menu_Demo.Handler;
51 with Sample.Helpers; use Sample.Helpers;
52 with Sample.Explanation; use Sample.Explanation;
54 package body Sample.Menu_Demo is
56 package Spacing_Demo is
57 procedure Spacing_Test;
60 package body Spacing_Demo is
62 procedure Spacing_Test
64 function My_Driver (M : Menu;
66 P : Panel) return Boolean;
68 procedure Set_Option_Key;
69 procedure Set_Select_Key;
70 procedure Set_Description_Key;
71 procedure Set_Hide_Key;
73 package Mh is new Sample.Menu_Demo.Handler (My_Driver);
75 I : Item_Array_Access := new Item_Array'
76 (New_Item ("January", "31 Days"),
77 New_Item ("February", "28/29 Days"),
78 New_Item ("March", "31 Days"),
79 New_Item ("April", "30 Days"),
80 New_Item ("May", "31 Days"),
81 New_Item ("June", "30 Days"),
82 New_Item ("July", "31 Days"),
83 New_Item ("August", "31 Days"),
84 New_Item ("September", "30 Days"),
85 New_Item ("October", "31 Days"),
86 New_Item ("November", "30 Days"),
87 New_Item ("December", "31 Days"),
90 M : Menu := New_Menu (I);
91 Flip_State : Boolean := True;
92 Hide_Long : Boolean := False;
94 type Format_Code is (Four_By_1, Four_By_2, Four_By_3);
95 type Operations is (Flip, Reorder, Reformat, Reselect, Describe);
97 type Change is array (Operations) of Boolean;
99 No_Change : constant Change := Change'(others => False);
101 Current_Format : Format_Code := Four_By_1;
102 To_Change : Change := No_Change;
104 function My_Driver (M : Menu;
106 P : Panel) return Boolean
109 To_Change := No_Change;
110 if K in User_Key_Code'Range then
115 if K in Special_Key_Code'Range then
118 To_Change (Flip) := True;
121 To_Change (Reformat) := True;
122 Current_Format := Four_By_1;
125 To_Change (Reformat) := True;
126 Current_Format := Four_By_2;
129 To_Change (Reformat) := True;
130 Current_Format := Four_By_3;
133 To_Change (Reorder) := True;
136 To_Change (Reselect) := True;
139 if Current_Format /= Four_By_3 then
140 To_Change (Describe) := True;
146 Hide_Long := not Hide_Long;
150 for J in I'Range loop
151 Get_Options (I (J), O);
152 O.Selectable := True;
155 when 1 | 3 | 5 | 7 | 8 | 10 | 12 =>
156 O.Selectable := False;
160 Set_Options (I (J), O);
170 procedure Set_Option_Key
174 if Current_Format = Four_By_1 then
175 Set_Soft_Label_Key (8, "");
178 if O.Row_Major_Order then
179 Set_Soft_Label_Key (8, "O-Col");
181 Set_Soft_Label_Key (8, "O-Row");
184 Refresh_Soft_Label_Keys_Without_Update;
187 procedure Set_Select_Key
193 Set_Soft_Label_Key (9, "Multi");
195 Set_Soft_Label_Key (9, "Singl");
197 Refresh_Soft_Label_Keys_Without_Update;
200 procedure Set_Description_Key
204 if Current_Format = Four_By_3 then
205 Set_Soft_Label_Key (10, "");
208 if O.Show_Descriptions then
209 Set_Soft_Label_Key (10, "-Desc");
211 Set_Soft_Label_Key (10, "+Desc");
214 Refresh_Soft_Label_Keys_Without_Update;
215 end Set_Description_Key;
217 procedure Set_Hide_Key
221 Set_Soft_Label_Key (11, "Enab");
223 Set_Soft_Label_Key (11, "Disab");
225 Refresh_Soft_Label_Keys_Without_Update;
229 Push_Environment ("MENU01");
230 Notepad ("MENU-PAD01");
232 Set_Soft_Label_Key (4, "Flip");
233 Set_Soft_Label_Key (5, "4x1");
234 Set_Soft_Label_Key (6, "4x2");
235 Set_Soft_Label_Key (7, "4x3");
241 Set_Format (M, 4, 1);
244 exit when To_Change = No_Change;
245 if To_Change (Flip) then
248 Set_Spacing (M, 3, 2, 0);
253 elsif To_Change (Reformat) then
254 case Current_Format is
255 when Four_By_1 => Set_Format (M, 4, 1);
256 when Four_By_2 => Set_Format (M, 4, 2);
262 O.Show_Descriptions := False;
264 Set_Format (M, 4, 3);
269 elsif To_Change (Reorder) then
274 O.Row_Major_Order := not O.Row_Major_Order;
278 elsif To_Change (Reselect) then
283 O.One_Valued := not O.One_Valued;
287 elsif To_Change (Describe) then
292 O.Show_Descriptions := not O.Show_Descriptions;
304 pragma Assert (Get_Index (Items (M, 1)) = Get_Index (I (1)));
312 -- We use this datatype only to test the instantiation of
313 -- the Menu_User_Data generic package. No functionality
315 type User_Data is new Integer;
316 type User_Data_Access is access User_Data;
318 -- Those packages are only instantiated to test the usability.
319 -- No real functionality is shown in the demo.
320 package MUD is new Menu_User_Data (User_Data, User_Data_Access);
321 package IUD is new Item_User_Data (User_Data, User_Data_Access);
323 function My_Driver (M : Menu;
325 P : Panel) return Boolean;
327 package Mh is new Sample.Menu_Demo.Handler (My_Driver);
329 Itm : Item_Array_Access := new Item_Array'
330 (New_Item ("Menu Layout Options"),
331 New_Item ("Demo of Hook functions"),
333 M : Menu := New_Menu (Itm);
335 U1 : User_Data_Access := new User_Data'(4711);
336 U2 : User_Data_Access;
337 U3 : User_Data_Access := new User_Data'(4712);
338 U4 : User_Data_Access;
340 function My_Driver (M : Menu;
342 P : Panel) return Boolean
344 Idx : constant Positive := Get_Index (Current (M));
346 if K in User_Key_Code'Range then
349 elsif K = SELECT_ITEM then
350 if Idx in Itm'Range then
355 when 1 => Spacing_Demo.Spacing_Test;
356 when others => Not_Implemented;
358 if Idx in Itm'Range then
369 Push_Environment ("MENU00");
370 Notepad ("MENU-PAD00");
372 Refresh_Soft_Label_Keys_Without_Update;
373 Set_Pad_Character (M, '|');
375 MUD.Set_User_Data (M, U1);
376 IUD.Set_User_Data (Itm (1), U3);
380 MUD.Get_User_Data (M, U2);
381 pragma Assert (U1 = U2 and U1.all = 4711);
383 IUD.Get_User_Data (Itm (1), U4);
384 pragma Assert (U3 = U4 and U3.all = 4712);
391 end Sample.Menu_Demo;