1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding --
5 -- Terminal_Interface.Curses.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@T-Online.de> 1996
39 -- Binding Version 00.93
40 ------------------------------------------------------------------------------
43 with Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux;
46 with Unchecked_Conversion;
48 package body Terminal_Interface.Curses.Mouse is
50 use type System.Bit_Order;
51 use type Interfaces.C.int;
53 function CInt_To_Mask is new
54 Unchecked_Conversion (Source => C_Int,
55 Target => Event_Mask);
57 function Mask_To_CInt is new
58 Unchecked_Conversion (Source => Event_Mask,
61 function Has_Mouse return Boolean
63 function Mouse_Avail return C_Int;
64 pragma Import (C, Mouse_Avail, "_nc_has_mouse");
66 if Has_Key (Key_Mouse) or else Mouse_Avail /= 0 then
73 function Get_Mouse return Mouse_Event
75 type Event_Access is access all Mouse_Event;
77 function Getmouse (Ev : Event_Access) return C_Int;
78 pragma Import (C, Getmouse, "getmouse");
80 Event : aliased Mouse_Event;
82 if Getmouse (Event'Access) = Curses_Err then
83 raise Curses_Exception;
88 procedure Register_Reportable_Event (B : in Mouse_Button;
90 Mask : in out Event_Mask)
92 type Evt_Access is access all Event_Mask;
93 function Register (B : C_Int;
95 M : Evt_Access) return C_Int;
96 pragma Import (C, Register, "_nc_ada_mouse_mask");
98 T : aliased Event_Mask := Mask;
99 M : Evt_Access := T'Access;
100 R : constant C_Int := Register (C_Int (Mouse_Button'Pos (B)),
101 C_Int (Button_State'Pos (S)),
104 if R = Curses_Err then
105 raise Curses_Exception;
108 end Register_Reportable_Event;
110 function Start_Mouse (Mask : Event_Mask := All_Events)
113 type Int_Access is access all C_Int;
114 function MMask (M : C_Int; O : Int_Access := null) return C_Int;
115 pragma Import (C, MMask, "mousemask");
118 R := MMask (Mask_To_CInt (Mask));
119 return CInt_To_Mask (R);
124 Old : constant Event_Mask := Start_Mouse (No_Events);
129 procedure Get_Event (Event : in Mouse_Event;
130 Y : out Line_Position;
131 X : out Column_Position;
132 Button : out Mouse_Button;
133 State : out Button_State)
135 procedure Dispatch_Event (M : in C_Int;
138 pragma Import (C, Dispatch_Event, "_nc_ada_mouse_event");
140 Mask : constant Interfaces.C.int := Mask_To_CInt (Event.Bstate);
143 X := Column_Position (Event.X);
144 Y := Line_Position (Event.Y);
145 Dispatch_Event (Mask, B, S);
146 Button := Mouse_Button'Val (B);
147 State := Button_State'Val (S);
150 procedure Unget_Mouse (Event : in Mouse_Event)
152 function Ungetmouse (Ev : Mouse_Event) return C_Int;
153 pragma Import (C, Ungetmouse, "ungetmouse");
155 if Ungetmouse (Event) = Curses_Err then
156 raise Curses_Exception;
160 function Enclosed_In_Window (Win : Window := Standard_Window;
161 Event : Mouse_Event) return Boolean
163 function Wenclose (Win : Window; Y : C_Int; X : C_Int) return C_Int;
164 pragma Import (C, Wenclose, "wenclose");
166 if Wenclose (Win, C_Int (Event.Y), C_Int (Event.X)) = Curses_False then
171 end Enclosed_In_Window;
173 function Mouse_Interval (Msec : Natural := 200) return Natural
175 function Mouseinterval (Msec : C_Int) return C_Int;
176 pragma Import (C, Mouseinterval, "mouseinterval");
178 return Natural (Mouseinterval (C_Int (Msec)));
181 end Terminal_Interface.Curses.Mouse;