Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | -- -*- ada -*- |
| 2 | define(`HTMLNAME',`terminal_interface-curses-mouse__ads.htm')dnl |
| 3 | include(M4MACRO)dnl |
| 4 | ------------------------------------------------------------------------------ |
| 5 | -- -- |
| 6 | -- GNAT ncurses Binding -- |
| 7 | -- -- |
| 8 | -- Terminal_Interface.Curses.Mouse -- |
| 9 | -- -- |
| 10 | -- S P E C -- |
| 11 | -- -- |
| 12 | ------------------------------------------------------------------------------ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 13 | -- Copyright (c) 1998-2014,2015 Free Software Foundation, Inc. -- |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 14 | -- -- |
| 15 | -- Permission is hereby granted, free of charge, to any person obtaining a -- |
| 16 | -- copy of this software and associated documentation files (the -- |
| 17 | -- "Software"), to deal in the Software without restriction, including -- |
| 18 | -- without limitation the rights to use, copy, modify, merge, publish, -- |
| 19 | -- distribute, distribute with modifications, sublicense, and/or sell -- |
| 20 | -- copies of the Software, and to permit persons to whom the Software is -- |
| 21 | -- furnished to do so, subject to the following conditions: -- |
| 22 | -- -- |
| 23 | -- The above copyright notice and this permission notice shall be included -- |
| 24 | -- in all copies or substantial portions of the Software. -- |
| 25 | -- -- |
| 26 | -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -- |
| 27 | -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -- |
| 28 | -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -- |
| 29 | -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -- |
| 30 | -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -- |
| 31 | -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR -- |
| 32 | -- THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- |
| 33 | -- -- |
| 34 | -- Except as contained in this notice, the name(s) of the above copyright -- |
| 35 | -- holders shall not be used in advertising or otherwise to promote the -- |
| 36 | -- sale, use or other dealings in this Software without prior written -- |
| 37 | -- authorization. -- |
| 38 | ------------------------------------------------------------------------------ |
| 39 | -- Author: Juergen Pfeifer, 1996 |
| 40 | -- Version Control: |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 41 | -- $Revision: 1.32 $ |
| 42 | -- $Date: 2015/05/30 23:19:19 $ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 43 | -- Binding Version 01.00 |
| 44 | ------------------------------------------------------------------------------ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 45 | with System; |
| 46 | |
| 47 | package Terminal_Interface.Curses.Mouse is |
| 48 | pragma Preelaborate (Terminal_Interface.Curses.Mouse); |
| 49 | |
| 50 | -- MANPAGE(`curs_mouse.3x') |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 51 | -- mouse_trafo, wmouse_trafo are implemented as Transform_Coordinates |
| 52 | -- in the parent package. |
| 53 | -- |
| 54 | -- Not implemented: |
| 55 | -- REPORT_MOUSE_POSITION (i.e. as a parameter to Register_Reportable_Event |
| 56 | -- or Start_Mouse) |
| 57 | type Event_Mask is private; |
| 58 | No_Events : constant Event_Mask; |
| 59 | All_Events : constant Event_Mask; |
| 60 | |
| 61 | type Mouse_Button is (Left, -- aka: Button 1 |
| 62 | Middle, -- aka: Button 2 |
| 63 | Right, -- aka: Button 3 |
| 64 | Button4, -- aka: Button 4 |
| 65 | Control, -- Control Key |
| 66 | Shift, -- Shift Key |
| 67 | Alt); -- ALT Key |
| 68 | |
| 69 | subtype Real_Buttons is Mouse_Button range Left .. Button4; |
| 70 | subtype Modifier_Keys is Mouse_Button range Control .. Alt; |
| 71 | |
| 72 | type Button_State is (Released, |
| 73 | Pressed, |
| 74 | Clicked, |
| 75 | Double_Clicked, |
| 76 | Triple_Clicked); |
| 77 | |
| 78 | type Button_States is array (Button_State) of Boolean; |
| 79 | pragma Pack (Button_States); |
| 80 | |
| 81 | All_Clicks : constant Button_States := (Clicked .. Triple_Clicked => True, |
| 82 | others => False); |
| 83 | All_States : constant Button_States := (others => True); |
| 84 | |
| 85 | type Mouse_Event is private; |
| 86 | |
| 87 | -- MANPAGE(`curs_mouse.3x') |
| 88 | |
| 89 | function Has_Mouse return Boolean; |
| 90 | -- Return true if a mouse device is supported, false otherwise. |
| 91 | |
| 92 | procedure Register_Reportable_Event |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 93 | (Button : Mouse_Button; |
| 94 | State : Button_State; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 95 | Mask : in out Event_Mask); |
| 96 | -- Stores the event described by the button and the state in the mask. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 97 | -- Before you call this the first time, you should initialize the mask |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 98 | -- with the Empty_Mask constant |
| 99 | pragma Inline (Register_Reportable_Event); |
| 100 | |
| 101 | procedure Register_Reportable_Events |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 102 | (Button : Mouse_Button; |
| 103 | State : Button_States; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 104 | Mask : in out Event_Mask); |
| 105 | -- Register all events described by the Button and the State bitmap. |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 106 | -- Before you call this the first time, you should initialize the mask |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 107 | -- with the Empty_Mask constant |
| 108 | |
| 109 | -- ANCHOR(`mousemask()',`Start_Mouse') |
| 110 | -- There is one difference to mousmask(): we return the value of the |
| 111 | -- old mask, that means the event mask value before this call. |
| 112 | -- Not Implemented: The library version |
| 113 | -- returns a Mouse_Mask that tells which events are reported. |
| 114 | function Start_Mouse (Mask : Event_Mask := All_Events) |
| 115 | return Event_Mask; |
| 116 | -- AKA |
| 117 | pragma Inline (Start_Mouse); |
| 118 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 119 | procedure End_Mouse (Mask : Event_Mask := No_Events); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 120 | -- Terminates the mouse, restores the specified event mask |
| 121 | pragma Inline (End_Mouse); |
| 122 | |
| 123 | -- ANCHOR(`getmouse()',`Get_Mouse') |
| 124 | function Get_Mouse return Mouse_Event; |
| 125 | -- AKA |
| 126 | pragma Inline (Get_Mouse); |
| 127 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 128 | procedure Get_Event (Event : Mouse_Event; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 129 | Y : out Line_Position; |
| 130 | X : out Column_Position; |
| 131 | Button : out Mouse_Button; |
| 132 | State : out Button_State); |
| 133 | -- !!! Warning: X and Y are screen coordinates. Due to ripped of lines they |
| 134 | -- may not be identical to window coordinates. |
| 135 | -- Not Implemented: Get_Event only reports one event, the C library |
| 136 | -- version supports multiple events, e.g. {click-1, click-3} |
| 137 | pragma Inline (Get_Event); |
| 138 | |
| 139 | -- ANCHOR(`ungetmouse()',`Unget_Mouse') |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 140 | procedure Unget_Mouse (Event : Mouse_Event); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 141 | -- AKA |
| 142 | pragma Inline (Unget_Mouse); |
| 143 | |
| 144 | -- ANCHOR(`wenclose()',`Enclosed_In_Window') |
| 145 | function Enclosed_In_Window (Win : Window := Standard_Window; |
| 146 | Event : Mouse_Event) return Boolean; |
| 147 | -- AKA |
| 148 | -- But : use event instead of screen coordinates. |
| 149 | pragma Inline (Enclosed_In_Window); |
| 150 | |
| 151 | -- ANCHOR(`mouseinterval()',`Mouse_Interval') |
| 152 | function Mouse_Interval (Msec : Natural := 200) return Natural; |
| 153 | -- AKA |
| 154 | pragma Inline (Mouse_Interval); |
| 155 | |
| 156 | private |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 157 | -- This can be as little as 32 bits (unsigned), or as long as the system's |
| 158 | -- unsigned long. Declare it as the minimum size to handle all valid |
| 159 | -- sizes. |
| 160 | type Event_Mask is mod 4294967296; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 161 | |
| 162 | type Mouse_Event is |
| 163 | record |
| 164 | Id : Integer range Integer (Interfaces.C.short'First) .. |
| 165 | Integer (Interfaces.C.short'Last); |
| 166 | X, Y, Z : Integer range Integer (Interfaces.C.int'First) .. |
| 167 | Integer (Interfaces.C.int'Last); |
| 168 | Bstate : Event_Mask; |
| 169 | end record; |
| 170 | pragma Convention (C, Mouse_Event); |
| 171 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 172 | for Mouse_Event use |
| 173 | record |
| 174 | Id at 0 range Curses_Constants.MEVENT_id_First |
| 175 | .. Curses_Constants.MEVENT_id_Last; |
| 176 | X at 0 range Curses_Constants.MEVENT_x_First |
| 177 | .. Curses_Constants.MEVENT_x_Last; |
| 178 | Y at 0 range Curses_Constants.MEVENT_y_First |
| 179 | .. Curses_Constants.MEVENT_y_Last; |
| 180 | Z at 0 range Curses_Constants.MEVENT_z_First |
| 181 | .. Curses_Constants.MEVENT_z_Last; |
| 182 | Bstate at 0 range Curses_Constants.MEVENT_bstate_First |
| 183 | .. Curses_Constants.MEVENT_bstate_Last; |
| 184 | end record; |
| 185 | for Mouse_Event'Size use Curses_Constants.MEVENT_Size; |
| 186 | Generation_Bit_Order : System.Bit_Order renames Curses_Constants.Bit_Order; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 187 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 188 | BUTTON_CTRL : constant Event_Mask := Curses_Constants.BUTTON_CTRL; |
| 189 | BUTTON_SHIFT : constant Event_Mask := Curses_Constants.BUTTON_SHIFT; |
| 190 | BUTTON_ALT : constant Event_Mask := Curses_Constants.BUTTON_ALT; |
| 191 | BUTTON1_EVENTS : constant Event_Mask |
| 192 | := Curses_Constants.all_events_button_1; |
| 193 | BUTTON2_EVENTS : constant Event_Mask |
| 194 | := Curses_Constants.all_events_button_2; |
| 195 | BUTTON3_EVENTS : constant Event_Mask |
| 196 | := Curses_Constants.all_events_button_3; |
| 197 | BUTTON4_EVENTS : constant Event_Mask |
| 198 | := Curses_Constants.all_events_button_4; |
| 199 | ALL_MOUSE_EVENTS : constant Event_Mask := Curses_Constants.ALL_MOUSE_EVENTS; |
| 200 | No_Events : constant Event_Mask := 0; |
| 201 | All_Events : constant Event_Mask := ALL_MOUSE_EVENTS; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 202 | |
| 203 | end Terminal_Interface.Curses.Mouse; |