Fix PROCDURE -> PROCEDURE.
[dragonfly.git] / contrib / ncurses-5.4 / Ada95 / samples / sample-curses_demo.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                       GNAT ncurses Binding Samples                       --
4 --                                                                          --
5 --                            Sample.Curses_Demo                            --
6 --                                                                          --
7 --                                 B O D Y                                  --
8 --                                                                          --
9 ------------------------------------------------------------------------------
10 -- Copyright (c) 1998 Free Software Foundation, Inc.                        --
11 --                                                                          --
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:                 --
19 --                                                                          --
20 -- The above copyright notice and this permission notice shall be included  --
21 -- in all copies or substantial portions of the Software.                   --
22 --                                                                          --
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.                               --
30 --                                                                          --
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       --
34 -- authorization.                                                           --
35 ------------------------------------------------------------------------------
36 --  Author:  Juergen Pfeifer, 1996
37 --  Version Control
38 --  $Revision: 1.12 $
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;
46
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;
50
51 with Sample.Explanation; use Sample.Explanation;
52
53 with Sample.Menu_Demo.Handler;
54 with Sample.Curses_Demo.Mouse;
55 with Sample.Curses_Demo.Attributes;
56
57 package body Sample.Curses_Demo is
58
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.
64
65    procedure Demo
66    is
67       function My_Driver (M : Menu;
68                           K : Key_Code;
69                           Pan : Panel) return Boolean;
70       package Mh is new Sample.Menu_Demo.Handler (My_Driver);
71
72       Itm : Item_Array_Access := new Item_Array'
73         (New_Item ("Attributes Demo"),
74          New_Item ("Mouse Demo"),
75          Null_Item);
76       M  : Menu := New_Menu (Itm);
77       U1 : User_Data_Access := new User_Data'(4711);
78       U2 : User_Data_Access;
79
80       function My_Driver (M : Menu;
81                           K : Key_Code;
82                           Pan : Panel) return Boolean
83       is
84          Idx : constant Positive := Get_Index (Current (M));
85          Result : Boolean := False;
86       begin
87          PUD.Set_User_Data (Pan, U1); --  set some user data, just for fun
88          if K in User_Key_Code'Range then
89             if K = QUIT then
90                Result := True;
91             elsif K = SELECT_ITEM then
92                if Idx in Itm'Range then
93                   Hide (Pan);
94                   Update_Panels;
95                end if;
96                case Idx is
97                   when 1 => Sample.Curses_Demo.Attributes.Demo;
98                   when 2 => Sample.Curses_Demo.Mouse.Demo;
99                   when others => Not_Implemented;
100                end case;
101                if Idx in Itm'Range then
102                   Top (Pan);
103                   Show (Pan);
104                   Update_Panels;
105                   Update_Screen;
106                end if;
107             end if;
108          end if;
109          PUD.Get_User_Data (Pan, U2); --  get the user data
110          pragma Assert (U1.all = U2.all and then U1 = U2);
111          return Result;
112       end My_Driver;
113
114    begin
115
116       if (1 + Item_Count (M)) /= Itm'Length then
117          raise Constraint_Error;
118       end if;
119
120       if not Has_Mouse then
121          declare
122             O : Item_Option_Set;
123          begin
124             Get_Options (Itm (2), O);
125             O.Selectable := False;
126             Set_Options (Itm (2), O);
127          end;
128       end if;
129
130       Push_Environment ("CURSES00");
131       Notepad ("CURSES-PAD00");
132       Default_Labels;
133       Refresh_Soft_Label_Keys_Without_Update;
134
135       Mh.Drive_Me (M, " Demo ");
136       Pop_Environment;
137
138       Delete (M);
139       Free (Itm, True);
140    end Demo;
141
142 end Sample.Curses_Demo;