1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding Samples --
9 ------------------------------------------------------------------------------
10 -- Copyright (c) 1998-2004,2008 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 -- $Date: 2008/07/26 18:48:30 $
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 if M = Null_Menu then
110 raise Menu_Exception;
112 if P = Null_Panel then
113 raise Panel_Exception;
115 To_Change := No_Change;
116 if K in User_Key_Code'Range then
121 if K in Special_Key_Code'Range then
124 To_Change (Flip) := True;
127 To_Change (Reformat) := True;
128 Current_Format := Four_By_1;
131 To_Change (Reformat) := True;
132 Current_Format := Four_By_2;
135 To_Change (Reformat) := True;
136 Current_Format := Four_By_3;
139 To_Change (Reorder) := True;
142 To_Change (Reselect) := True;
145 if Current_Format /= Four_By_3 then
146 To_Change (Describe) := True;
152 Hide_Long := not Hide_Long;
156 for J in I'Range loop
157 Get_Options (I (J), O);
158 O.Selectable := True;
161 when 1 | 3 | 5 | 7 | 8 | 10 | 12 =>
162 O.Selectable := False;
166 Set_Options (I (J), O);
176 procedure Set_Option_Key
180 if Current_Format = Four_By_1 then
181 Set_Soft_Label_Key (8, "");
184 if O.Row_Major_Order then
185 Set_Soft_Label_Key (8, "O-Col");
187 Set_Soft_Label_Key (8, "O-Row");
190 Refresh_Soft_Label_Keys_Without_Update;
193 procedure Set_Select_Key
199 Set_Soft_Label_Key (9, "Multi");
201 Set_Soft_Label_Key (9, "Singl");
203 Refresh_Soft_Label_Keys_Without_Update;
206 procedure Set_Description_Key
210 if Current_Format = Four_By_3 then
211 Set_Soft_Label_Key (10, "");
214 if O.Show_Descriptions then
215 Set_Soft_Label_Key (10, "-Desc");
217 Set_Soft_Label_Key (10, "+Desc");
220 Refresh_Soft_Label_Keys_Without_Update;
221 end Set_Description_Key;
223 procedure Set_Hide_Key
227 Set_Soft_Label_Key (11, "Enab");
229 Set_Soft_Label_Key (11, "Disab");
231 Refresh_Soft_Label_Keys_Without_Update;
235 Push_Environment ("MENU01");
236 Notepad ("MENU-PAD01");
238 Set_Soft_Label_Key (4, "Flip");
239 Set_Soft_Label_Key (5, "4x1");
240 Set_Soft_Label_Key (6, "4x2");
241 Set_Soft_Label_Key (7, "4x3");
247 Set_Format (M, 4, 1);
250 exit when To_Change = No_Change;
251 if To_Change (Flip) then
254 Set_Spacing (M, 3, 2, 0);
259 elsif To_Change (Reformat) then
260 case Current_Format is
261 when Four_By_1 => Set_Format (M, 4, 1);
262 when Four_By_2 => Set_Format (M, 4, 2);
268 O.Show_Descriptions := False;
270 Set_Format (M, 4, 3);
275 elsif To_Change (Reorder) then
280 O.Row_Major_Order := not O.Row_Major_Order;
284 elsif To_Change (Reselect) then
289 O.One_Valued := not O.One_Valued;
293 elsif To_Change (Describe) then
298 O.Show_Descriptions := not O.Show_Descriptions;
309 pragma Assert (Get_Index (Items (M, 1)) = Get_Index (I (1)));
317 -- We use this datatype only to test the instantiation of
318 -- the Menu_User_Data generic package. No functionality
320 type User_Data is new Integer;
321 type User_Data_Access is access User_Data;
323 -- Those packages are only instantiated to test the usability.
324 -- No real functionality is shown in the demo.
325 package MUD is new Menu_User_Data (User_Data, User_Data_Access);
326 package IUD is new Item_User_Data (User_Data, User_Data_Access);
328 function My_Driver (M : Menu;
330 P : Panel) return Boolean;
332 package Mh is new Sample.Menu_Demo.Handler (My_Driver);
334 Itm : Item_Array_Access := new Item_Array'
335 (New_Item ("Menu Layout Options"),
336 New_Item ("Demo of Hook functions"),
338 M : Menu := New_Menu (Itm);
340 U1 : constant User_Data_Access := new User_Data'(4711);
341 U2 : User_Data_Access;
342 U3 : constant User_Data_Access := new User_Data'(4712);
343 U4 : User_Data_Access;
345 function My_Driver (M : Menu;
347 P : Panel) return Boolean
349 Idx : constant Positive := Get_Index (Current (M));
351 if K in User_Key_Code'Range then
354 elsif K = SELECT_ITEM then
355 if Idx in Itm'Range then
360 when 1 => Spacing_Demo.Spacing_Test;
361 when others => Not_Implemented;
363 if Idx in Itm'Range then
374 Push_Environment ("MENU00");
375 Notepad ("MENU-PAD00");
377 Refresh_Soft_Label_Keys_Without_Update;
378 Set_Pad_Character (M, '|');
380 MUD.Set_User_Data (M, U1);
381 IUD.Set_User_Data (Itm (1), U3);
385 MUD.Get_User_Data (M, U2);
386 pragma Assert (U1 = U2 and U1.all = 4711);
388 IUD.Get_User_Data (Itm (1), U4);
389 pragma Assert (U3 = U4 and U3.all = 4712);
396 end Sample.Menu_Demo;