1 ------------------------------------------------------------------------------
3 -- GNAT ncurses Binding --
5 -- Terminal_Interface.Curses.Mouse --
11 -- The ncurses Ada95 binding is copyrighted 1996 by --
12 -- Juergen Pfeifer, Email: Juergen.Pfeifer@T-Online.de --
14 -- Permission is hereby granted to reproduce and distribute this --
15 -- binding by any means and for any fee, whether alone or as part --
16 -- of a larger distribution, in source or in binary form, PROVIDED --
17 -- this notice is included with any such distribution, and is not --
18 -- removed from any of its header files. Mention of ncurses and the --
19 -- author of this binding in any applications linked with it is --
20 -- highly appreciated. --
22 -- This binding comes AS IS with no warranty, implied or expressed. --
23 ------------------------------------------------------------------------------
26 ------------------------------------------------------------------------------
29 with Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux;
32 with Unchecked_Conversion;
34 package body Terminal_Interface.Curses.Mouse is
36 use type System.Bit_Order;
37 use type Interfaces.C.int;
39 function CInt_To_Mask is new
40 Unchecked_Conversion (Source => C_Int,
41 Target => Event_Mask);
43 function Mask_To_CInt is new
44 Unchecked_Conversion (Source => Event_Mask,
47 function Get_Mouse return Mouse_Event
49 type Event_Access is access all Mouse_Event;
51 function Getmouse (Ev : Event_Access) return C_Int;
52 pragma Import (C, Getmouse, "getmouse");
54 Event : aliased Mouse_Event;
56 if Getmouse (Event'Access) = Curses_Err then
57 raise Curses_Exception;
62 procedure Register_Reportable_Event (B : in Mouse_Button;
64 Mask : in out Event_Mask)
66 type Evt_Access is access all Event_Mask;
67 function Register (B : C_Int;
69 M : Evt_Access) return C_Int;
70 pragma Import (C, Register, "_nc_ada_mouse_mask");
72 T : aliased Event_Mask := Mask;
73 M : Evt_Access := T'Access;
74 R : constant C_Int := Register (C_Int (Mouse_Button'Pos (B)),
75 C_Int (Button_State'Pos (S)),
78 if R = Curses_Err then
79 raise Curses_Exception;
82 end Register_Reportable_Event;
84 function Start_Mouse (Mask : Event_Mask := All_Events)
87 type Int_Access is access all C_Int;
88 function MMask (M : C_Int; O : Int_Access := null) return C_Int;
89 pragma Import (C, MMask, "mousemask");
92 R := MMask (Mask_To_CInt (Mask));
93 return CInt_To_Mask (R);
96 procedure Get_Event (Event : in Mouse_Event;
97 Y : out Line_Position;
98 X : out Column_Position;
99 Button : out Mouse_Button;
100 State : out Button_State)
102 procedure Dispatch_Event (M : in C_Int;
105 pragma Import (C, Dispatch_Event, "_nc_ada_mouse_event");
107 Mask : constant Interfaces.C.int := Mask_To_CInt (Event.Bstate);
110 X := Column_Position (Event.X);
111 Y := Line_Position (Event.Y);
112 Dispatch_Event (Mask, B, S);
113 Button := Mouse_Button'Val (B);
114 State := Button_State'Val (S);
117 procedure Unget_Mouse (Event : in Mouse_Event)
119 function Ungetmouse (Ev : Mouse_Event) return C_Int;
120 pragma Import (C, Ungetmouse, "ungetmouse");
122 if Ungetmouse (Event) = Curses_Err then
123 raise Curses_Exception;
127 function Enclosed_In_Window (Win : Window := Standard_Window;
128 Event : Mouse_Event) return Boolean
130 function Wenclose (Win : Window; Y : C_Int; X : C_Int) return C_Int;
131 pragma Import (C, Wenclose, "wenclose");
133 if Wenclose (Win, C_Int (Event.Y), C_Int (Event.X)) = Curses_False then
138 end Enclosed_In_Window;
140 function Mouse_Interval (Msec : Natural := 200) return Natural
142 function Mouseinterval (Msec : C_Int) return C_Int;
143 pragma Import (C, Mouseinterval, "mouseinterval");
145 return Natural (Mouseinterval (C_Int (Msec)));
149 if Generation_Bit_Order /= System.Default_Bit_Order then
150 raise Constraint_Error;
152 end Terminal_Interface.Curses.Mouse;