1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding Samples --
5 -- Sample.Curses_Demo --
9 ------------------------------------------------------------------------------
10 -- Copyright 2020 Thomas E. Dickey --
11 -- Copyright 1998-2004,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.Menus; use Terminal_Interface.Curses.Menus;
45 with Terminal_Interface.Curses.Mouse; use Terminal_Interface.Curses.Mouse;
46 with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
47 with Terminal_Interface.Curses.Panels.User_Data;
49 with Sample.Manifest; use Sample.Manifest;
50 with Sample.Helpers; use Sample.Helpers;
51 with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
53 with Sample.Explanation; use Sample.Explanation;
55 with Sample.Menu_Demo.Handler;
56 with Sample.Curses_Demo.Mouse;
57 with Sample.Curses_Demo.Attributes;
59 package body Sample.Curses_Demo is
61 type User_Data is new Integer;
62 type User_Data_Access is access all User_Data;
63 package PUD is new Panels.User_Data (User_Data, User_Data_Access);
64 -- We use above instantiation of the generic User_Data package to
65 -- demonstrate and test the use of the user data mechanism.
69 function My_Driver (M : Menu;
71 Pan : Panel) return Boolean;
72 package Mh is new Sample.Menu_Demo.Handler (My_Driver);
74 Itm : Item_Array_Access := new Item_Array'
75 (New_Item ("Attributes Demo"),
76 New_Item ("Mouse Demo"),
78 M : Menu := New_Menu (Itm);
79 U1 : constant User_Data_Access := new User_Data'(4711);
80 U2 : User_Data_Access;
82 function My_Driver (M : Menu;
84 Pan : Panel) return Boolean
86 Idx : constant Positive := Get_Index (Current (M));
87 Result : Boolean := False;
89 PUD.Set_User_Data (Pan, U1); -- set some user data, just for fun
90 if K in User_Key_Code'Range then
93 elsif K = SELECT_ITEM then
94 if Idx in Itm'Range then
99 when 1 => Sample.Curses_Demo.Attributes.Demo;
100 when 2 => Sample.Curses_Demo.Mouse.Demo;
101 when others => Not_Implemented;
103 if Idx in Itm'Range then
111 PUD.Get_User_Data (Pan, U2); -- get the user data
112 pragma Assert (U1.all = U2.all and then U1 = U2);
118 if (1 + Item_Count (M)) /= Itm'Length then
119 raise Constraint_Error;
122 if not Has_Mouse then
126 Get_Options (Itm.all (2), O);
127 O.Selectable := False;
128 Set_Options (Itm.all (2), O);
132 Push_Environment ("CURSES00");
133 Notepad ("CURSES-PAD00");
135 Refresh_Soft_Label_Keys_Without_Update;
137 Mh.Drive_Me (M, " Demo ");
144 end Sample.Curses_Demo;