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 <Juergen.Pfeifer@T-Online.de> 1996
39 -- Binding Version 00.93
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 Ada.Characters.Latin_1; use Ada.Characters.Latin_1;
49 with Sample.Manifest; use Sample.Manifest;
50 with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
51 with Sample.Keyboard_Handler; use Sample.Keyboard_Handler;
52 with Sample.Menu_Demo.Handler;
53 with Sample.Helpers; use Sample.Helpers;
54 with Sample.Explanation; use Sample.Explanation;
56 package body Sample.Menu_Demo is
58 package Spacing_Demo is
59 procedure Spacing_Test;
62 package body Spacing_Demo is
64 procedure Spacing_Test
66 function My_Driver (M : Menu;
68 P : Panel) return Boolean;
70 procedure Set_Option_Key;
71 procedure Set_Select_Key;
72 procedure Set_Description_Key;
73 procedure Set_Hide_Key;
75 package Mh is new Sample.Menu_Demo.Handler (My_Driver);
77 I : Item_Array_Access := new Item_Array'
78 (New_Item ("January", "31 Days"),
79 New_Item ("February", "28/29 Days"),
80 New_Item ("March", "31 Days"),
81 New_Item ("April", "30 Days"),
82 New_Item ("May", "31 Days"),
83 New_Item ("June", "30 Days"),
84 New_Item ("July", "31 Days"),
85 New_Item ("August", "31 Days"),
86 New_Item ("September", "30 Days"),
87 New_Item ("October", "31 Days"),
88 New_Item ("November", "30 Days"),
89 New_Item ("December", "31 Days"),
92 M : Menu := New_Menu (I);
93 Flip_State : Boolean := True;
94 Hide_Long : Boolean := False;
96 type Format_Code is (Four_By_1, Four_By_2, Four_By_3);
97 type Operations is (Flip, Reorder, Reformat, Reselect, Describe);
99 type Change is array (Operations) of Boolean;
100 pragma Pack (Change);
101 No_Change : constant Change := Change'(others => False);
103 Current_Format : Format_Code := Four_By_1;
104 To_Change : Change := No_Change;
106 function My_Driver (M : Menu;
108 P : Panel) return Boolean
111 To_Change := No_Change;
112 if K in User_Key_Code'Range then
117 if K in Special_Key_Code'Range then
120 To_Change (Flip) := True;
123 To_Change (Reformat) := True;
124 Current_Format := Four_By_1;
127 To_Change (Reformat) := True;
128 Current_Format := Four_By_2;
131 To_Change (Reformat) := True;
132 Current_Format := Four_By_3;
135 To_Change (Reorder) := True;
138 To_Change (Reselect) := True;
141 if Current_Format /= Four_By_3 then
142 To_Change (Describe) := True;
148 Hide_Long := not Hide_Long;
152 for J in I'Range loop
153 Get_Options (I (J), O);
154 O.Selectable := True;
157 when 1 | 3 | 5 | 7 | 8 | 10 | 12 =>
158 O.Selectable := False;
162 Set_Options (I (J), O);
172 procedure Set_Option_Key
176 if Current_Format = Four_By_1 then
177 Set_Soft_Label_Key (8, "");
180 if O.Row_Major_Order then
181 Set_Soft_Label_Key (8, "O-Col");
183 Set_Soft_Label_Key (8, "O-Row");
186 Refresh_Soft_Label_Keys_Without_Update;
189 procedure Set_Select_Key
195 Set_Soft_Label_Key (9, "Multi");
197 Set_Soft_Label_Key (9, "Singl");
199 Refresh_Soft_Label_Keys_Without_Update;
202 procedure Set_Description_Key
206 if Current_Format = Four_By_3 then
207 Set_Soft_Label_Key (10, "");
210 if O.Show_Descriptions then
211 Set_Soft_Label_Key (10, "-Desc");
213 Set_Soft_Label_Key (10, "+Desc");
216 Refresh_Soft_Label_Keys_Without_Update;
217 end Set_Description_Key;
219 procedure Set_Hide_Key
223 Set_Soft_Label_Key (11, "Enab");
225 Set_Soft_Label_Key (11, "Disab");
227 Refresh_Soft_Label_Keys_Without_Update;
231 Push_Environment ("MENU01");
232 Notepad ("MENU-PAD01");
234 Set_Soft_Label_Key (4, "Flip");
235 Set_Soft_Label_Key (5, "4x1");
236 Set_Soft_Label_Key (6, "4x2");
237 Set_Soft_Label_Key (7, "4x3");
243 Set_Format (M, 4, 1);
246 exit when To_Change = No_Change;
247 if To_Change (Flip) then
250 Set_Spacing (M, 3, 2, 0);
255 elsif To_Change (Reformat) then
256 case Current_Format is
257 when Four_By_1 => Set_Format (M, 4, 1);
258 when Four_By_2 => Set_Format (M, 4, 2);
264 O.Show_Descriptions := False;
266 Set_Format (M, 4, 3);
271 elsif To_Change (Reorder) then
276 O.Row_Major_Order := not O.Row_Major_Order;
280 elsif To_Change (Reselect) then
285 O.One_Valued := not O.One_Valued;
289 elsif To_Change (Describe) then
294 O.Show_Descriptions := not O.Show_Descriptions;
313 -- We use this datatype only to test the instantiation of
314 -- the Menu_User_Data generic package. No functionality
316 type User_Data is new Integer;
317 type User_Data_Access is access User_Data;
319 -- Those packages are only instantiated to test the usability.
320 -- No real functionality is shown in the demo.
321 package MUD is new Menu_User_Data (User_Data, User_Data_Access);
322 package IUD is new Item_User_Data (User_Data, User_Data_Access);
324 function My_Driver (M : Menu;
326 P : Panel) return Boolean;
328 package Mh is new Sample.Menu_Demo.Handler (My_Driver);
330 Itm : Item_Array_Access := new Item_Array'
331 (New_Item ("Menu Layout Options"),
332 New_Item ("Demo of Hook functions"),
334 M : Menu := New_Menu (Itm);
336 U1 : User_Data_Access := new User_Data'(4711);
337 U2 : User_Data_Access;
338 U3 : User_Data_Access := new User_Data'(4712);
339 U4 : User_Data_Access;
341 function My_Driver (M : Menu;
343 P : Panel) return Boolean
345 Idx : constant Positive := Get_Index (Current (M));
347 if K in User_Key_Code'Range then
350 elsif K = SELECT_ITEM then
351 if Idx in Itm'Range then
356 when 1 => Spacing_Demo.Spacing_Test;
357 when others => Not_Implemented;
359 if Idx in Itm'Range then
370 Push_Environment ("MENU00");
371 Notepad ("MENU-PAD00");
373 Refresh_Soft_Label_Keys_Without_Update;
374 Set_Pad_Character (M, '|');
376 MUD.Set_User_Data (M, U1);
377 IUD.Set_User_Data (Itm (1), U3);
381 MUD.Get_User_Data (M, U2);
382 pragma Assert (U1 = U2 and U1.all = 4711);
384 IUD.Get_User_Data (Itm (1), U4);
385 pragma Assert (U3 = U4 and U3.all = 4712);
392 end Sample.Menu_Demo;