]> ncurses.scripts.mit.edu Git - ncurses.git/blob - Ada95/samples/sample-menu_demo-handler.adb
e7b1bf8a0ac5105c7da51b27028279beb2faeebd
[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@gmx.net> 1996
37 --  Version Control
38 --  $Revision: 1.10 $
39 --  Binding Version 01.00
40 ------------------------------------------------------------------------------
41 with Sample.Menu_Demo.Aux;
42 with Sample.Manifest; use Sample.Manifest;
43 with Terminal_Interface.Curses.Mouse;  use Terminal_Interface.Curses.Mouse;
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       Mask : Event_Mask := No_Events;
67       Old  : Event_Mask;
68       Pan  : Panel := Aux.Create (M, Title, Lin, Col);
69       V    : Cursor_Visibility := Invisible;
70    begin
71       --  We are only interested in Clicks with the left button
72       Register_Reportable_Events (Left, All_Clicks, Mask);
73       Old := Start_Mouse (Mask);
74       Set_Cursor_Visibility (V);
75       loop
76          declare
77             K : Key_Code := Aux.Get_Request (M, Pan);
78             R : Driver_Result := Driver (M, K);
79          begin
80             case R is
81                when Menu_Ok => null;
82                when Unknown_Request =>
83                   declare
84                      I : constant Item := Current (M);
85                      O : Item_Option_Set;
86                   begin
87                      if K = Key_Mouse then
88                         K := SELECT_ITEM;
89                      end if;
90                      Get_Options (I, O);
91                      if K = SELECT_ITEM and then not O.Selectable then
92                         Beep;
93                      else
94                         if My_Driver (M, K, Pan) then
95                            exit;
96                         end if;
97                      end if;
98                   end;
99                when others => Beep;
100             end case;
101          end;
102       end loop;
103       End_Mouse (Old);
104       Aux.Destroy (M, Pan);
105    end Drive_Me;
106
107 end Sample.Menu_Demo.Handler;