1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding Samples --
5 -- Sample.Curses_Demo --
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.Menus; use Terminal_Interface.Curses.Menus;
43 with Terminal_Interface.Curses.Mouse; use Terminal_Interface.Curses.Mouse;
44 with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
45 with Terminal_Interface.Curses.Panels.User_Data;
47 with Sample.Manifest; use Sample.Manifest;
48 with Sample.Helpers; use Sample.Helpers;
49 with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
51 with Sample.Explanation; use Sample.Explanation;
53 with Sample.Menu_Demo.Handler;
54 with Sample.Curses_Demo.Mouse;
55 with Sample.Curses_Demo.Attributes;
57 package body Sample.Curses_Demo is
59 type User_Data is new Integer;
60 type User_Data_Access is access all User_Data;
61 package PUD is new Panels.User_Data (User_Data, User_Data_Access);
62 -- We use above instantiation of the generic User_Data package to
63 -- demonstrate and test the use of the user data maechanism.
67 function My_Driver (M : Menu;
69 Pan : Panel) return Boolean;
70 package Mh is new Sample.Menu_Demo.Handler (My_Driver);
72 Itm : Item_Array_Access := new Item_Array'
73 (New_Item ("Attributes Demo"),
74 New_Item ("Mouse Demo"),
76 M : Menu := New_Menu (Itm);
77 U1 : User_Data_Access := new User_Data'(4711);
78 U2 : User_Data_Access;
80 function My_Driver (M : Menu;
82 Pan : Panel) return Boolean
84 Idx : constant Positive := Get_Index (Current (M));
85 Result : Boolean := False;
87 PUD.Set_User_Data (Pan, U1); -- set some user data, just for fun
88 if K in User_Key_Code'Range then
91 elsif K = SELECT_ITEM then
92 if Idx in Itm'Range then
97 when 1 => Sample.Curses_Demo.Attributes.Demo;
98 when 2 => Sample.Curses_Demo.Mouse.Demo;
99 when others => Not_Implemented;
101 if Idx in Itm'Range then
109 PUD.Get_User_Data (Pan, U2); -- get the user data
110 pragma Assert (U1.all = U2.all and then U1 = U2);
116 if (1 + Item_Count (M)) /= Itm'Length then
117 raise Constraint_Error;
120 if not Has_Mouse then
124 Get_Options (Itm (2), O);
125 O.Selectable := False;
126 Set_Options (Itm (2), O);
130 Push_Environment ("CURSES00");
131 Notepad ("CURSES-PAD00");
133 Refresh_Soft_Label_Keys_Without_Update;
135 Mh.Drive_Me (M, " Demo ");
142 end Sample.Curses_Demo;