1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding Samples --
5 -- Sample.Curses_Demo.Mouse --
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 <juergen.pfeifer@gmx.net> 1996
39 -- Binding Version 01.00
40 ------------------------------------------------------------------------------
41 with Terminal_Interface.Curses; use Terminal_Interface.Curses;
42 with Terminal_Interface.Curses.Panels; use Terminal_Interface.Curses.Panels;
43 with Terminal_Interface.Curses.Mouse; use Terminal_Interface.Curses.Mouse;
44 with Terminal_Interface.Curses.Text_IO; use Terminal_Interface.Curses.Text_IO;
45 with Terminal_Interface.Curses.Text_IO.Integer_IO;
46 with Terminal_Interface.Curses.Text_IO.Enumeration_IO;
48 with Sample.Helpers; use Sample.Helpers;
49 with Sample.Manifest; use Sample.Manifest;
50 with Sample.Keyboard_Handler; use Sample.Keyboard_Handler;
51 with Sample.Function_Key_Setting; use Sample.Function_Key_Setting;
52 with Sample.Explanation; use Sample.Explanation;
54 package body Sample.Curses_Demo.Mouse is
57 Terminal_Interface.Curses.Text_IO.Integer_IO (Integer);
60 package Button_IO is new
61 Terminal_Interface.Curses.Text_IO.Enumeration_IO (Mouse_Button);
64 package State_IO is new
65 Terminal_Interface.Curses.Text_IO.Enumeration_IO (Button_State);
70 type Controls is array (1 .. 3) of Panel;
77 V : Cursor_Visibility := Invisible;
80 Msg_L : constant Line_Count := 8;
81 Lins : Line_Position := Lines;
82 Cols : Column_Position;
84 procedure Show_Mouse_Event;
86 procedure Show_Mouse_Event
88 Evt : constant Mouse_Event := Get_Mouse;
91 Button : Mouse_Button;
95 Get_Event (Evt, Y, X, Button, State);
96 Put (Msg, "Event at");
97 Put (Msg, " X="); Put (Msg, Integer (X), 3);
98 Put (Msg, ", Y="); Put (Msg, Integer (Y), 3);
99 Put (Msg, ", Btn="); Put (Msg, Button, 10);
100 Put (Msg, ", Stat="); Put (Msg, State, 15);
101 for I in Ctl'Range loop
102 W := Get_Window (Ctl (I));
103 if Enclosed_In_Window (W, Evt) then
104 Transform_Coordinates (W, Y, X, From_Screen);
106 Put (Msg, Integer (I), 1); Put (Msg, ",");
107 Put (Msg, Integer (Y), 1); Put (Msg, ",");
108 Put (Msg, Integer (X), 1); Put (Msg, ")");
113 Update_Panels; Update_Screen;
114 end Show_Mouse_Event;
117 Push_Environment ("MOUSE00");
118 Notepad ("MOUSE-PAD00");
120 Set_Cursor_Visibility (V);
122 Note := Notepad_Window;
123 if Note /= Null_Window then
124 Get_Window_Position (Note, Lins, Cols);
126 Frame := Create (Msg_L, Columns, Lins - Msg_L, 0);
128 Set_Background (Win => Frame,
129 Ch => (Color => Default_Colors,
130 Attr => Normal_Video,
132 Set_Character_Attributes (Win => Frame,
133 Attr => Normal_Video,
134 Color => Default_Colors);
137 Msg := Derived_Window (Frame, Msg_L - 2, Columns - 2, 1, 1);
138 Pan := Create (Frame);
145 Window_Title (Frame, "Mouse Protocol");
146 Refresh_Without_Update (Frame);
147 Allow_Scrolling (Msg, True);
150 Middle_Column : constant Integer := Integer (Columns) / 2;
151 Middle_Index : constant Natural := Ctl'First + (Ctl'Length / 2);
152 Width : constant Column_Count := 5;
153 Height : constant Line_Count := 3;
154 Half : constant Column_Count := Width / 2;
155 Space : constant Column_Count := 3;
159 for I in Ctl'Range loop
160 Position := (Integer (I) - Integer (Middle_Index)) *
161 Integer (Half + Space + Width) + Middle_Column;
165 Column_Position (Position));
167 Set_Background (Win => W,
168 Ch => (Color => Menu_Back_Color,
169 Attr => Normal_Video,
171 Set_Character_Attributes (Win => W,
172 Attr => Normal_Video,
173 Color => Menu_Fore_Color);
176 Ctl (I) := Create (W);
178 Move_Cursor (W, 1, Half);
179 Put (W, Integer (I), 1);
180 Refresh_Without_Update (W);
184 Update_Panels; Update_Screen;
188 if K in Special_Key_Code'Range then
190 when QUIT_CODE => exit;
191 when HELP_CODE => Explain_Context;
192 when EXPLAIN_CODE => Explain ("MOUSEKEYS");
193 when Key_Mouse => Show_Mouse_Event;
199 for I in Ctl'Range loop
200 W := Get_Window (Ctl (I));
211 Set_Cursor_Visibility (V);
215 Update_Panels; Update_Screen;
219 end Sample.Curses_Demo.Mouse;