]> ncurses.scripts.mit.edu Git - ncurses.git/blob - Ada95/samples/sample-menu_demo-handler.adb
ncurses 4.2
[ncurses.git] / Ada95 / samples / sample-menu_demo-handler.adb
1 ------------------------------------------------------------------------------
2 --                                                                          --
3 --                       GNAT ncurses Binding Samples                       --
4 --                                                                          --
5 --                          Sample.Menu_Demo.Handler                        --
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 <Juergen.Pfeifer@T-Online.de> 1996
37 --  Version Control
38 --  $Revision: 1.5 $
39 --  Binding Version 00.93
40 ------------------------------------------------------------------------------
41 with Sample.Menu_Demo.Aux;
42 with Sample.Explanation; use Sample.Explanation;
43 with Sample.Manifest; use Sample.Manifest;
44
45 package body Sample.Menu_Demo.Handler is
46
47    package Aux renames Sample.Menu_Demo.Aux;
48
49    procedure Drive_Me (M     : in Menu;
50                        Title : in String := "")
51    is
52       L : Line_Count;
53       C : Column_Count;
54       Y : Line_Position;
55       X : Column_Position;
56    begin
57       Aux.Geometry (M, L, C, Y, X);
58       Drive_Me (M, Y, X, Title);
59    end Drive_Me;
60
61    procedure Drive_Me (M     : in Menu;
62                        Lin   : in Line_Position;
63                        Col   : in Column_Position;
64                        Title : in String := "")
65    is
66       Pan : Panel := Aux.Create (M, Title, Lin, Col);
67       V   : Cursor_Visibility := Invisible;
68    begin
69       Set_Cursor_Visibility (V);
70       loop
71          declare
72             K : Key_Code := Aux.Get_Request (M, Pan);
73             R : Driver_Result := Driver (M, K);
74          begin
75             case R is
76                when Menu_Ok => null;
77                when Unknown_Request =>
78                   declare
79                      I : constant Item := Current (M);
80                      O : Item_Option_Set;
81                   begin
82                      Get_Options (I, O);
83                      if K = SELECT_ITEM and then not O.Selectable then
84                         Beep;
85                      else
86                         if My_Driver (M, K, Pan) then
87                            exit;
88                         end if;
89                      end if;
90                   end;
91                when others => Beep;
92             end case;
93          end;
94       end loop;
95       Set_Cursor_Visibility (V);
96       Aux.Destroy (M, Pan);
97    end Drive_Me;
98
99 end Sample.Menu_Demo.Handler;