source: NonGTP/FLTK/include/fltk/events.h @ 773

Revision 773, 11.3 KB checked in by gumbau, 19 years ago (diff)

FLTK imported to SVN repository to be linked agains the GeoTool? application

Line 
1//
2// "$Id: events.h 4571 2005-09-16 08:02:58Z spitzak $"
3//
4// Event types and data. A Widget::handle() method needs this.
5//
6// Copyright 1998-2003 by Bill Spitzak and others.
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public
10// License as published by the Free Software Foundation; either
11// version 2 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16// Library General Public License for more details.
17//
18// You should have received a copy of the GNU Library General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21// USA.
22//
23// Please report all bugs and problems to "fltk-bugs@fltk.org".
24//
25
26#ifndef fltk_events_h
27#define fltk_events_h
28
29#include "FL_API.h"
30
31namespace fltk {
32
33/*! \addtogroup events
34  \{
35*/
36
37/*! Numbers passed to Widget::handle() and returned by event(). */
38enum {
39  NO_EVENT      = 0,
40  PUSH          = 1,
41  RELEASE       = 2,
42  ENTER         = 3,
43  LEAVE         = 4,
44  DRAG          = 5,
45  FOCUS         = 6,
46  UNFOCUS       = 7,
47  KEY           = 8,
48  KEYUP         = 9,
49  FOCUS_CHANGE  = 10,
50  MOVE          = 11,
51  SHORTCUT      = 12,
52  DEACTIVATE    = 13,
53  ACTIVATE      = 14,
54  HIDE          = 15,
55  SHOW          = 16,
56  PASTE         = 17,
57  TIMEOUT       = 18,
58  MOUSEWHEEL    = 19,
59  DND_ENTER     = 20,
60  DND_DRAG      = 21,
61  DND_LEAVE     = 22,
62  DND_RELEASE   = 23,
63  TOOLTIP       = 24
64};
65
66/*! Values returned by event_key(), passed to event_key_state() and
67  get_key_state(), and used for the low 16 bits of add_shortcut().
68
69  The actual values returned are based on X11 keysym values, though
70  fltk always returns "unshifted" values much like Windows does. A
71  given key always returns the same value no matter what shift keys
72  are held down. Use event_text() to see the results of any shift
73  keys.
74
75  The lowercase letters 'a' through 'z' and the ascii symbols
76  '`', '-', '=', '[', ']', '\\', ',', '.', '/', ';', '\'' and space
77  are used to identify the keys in the main keyboard.
78
79  On X systems unrecognized keys are returned unchanged as their
80  X keysym value. If they have no keysym it uses the scan code
81  or'd with 0x8000, this is what all those blue buttons on a
82  Microsoft keyboard will do. I don't know how to get those
83  buttons on Windows.
84*/
85enum {
86  LeftButton    = 1,            /*!< PUSH/RELEASE set event_key to this */
87  MiddleButton  = 2,            /*!< PUSH/RELEASE set event_key to this */
88  RightButton   = 3,            /*!< PUSH/RELEASE set event_key to this */
89  SpaceKey      = 32,           /*!< Same as ' ' or 32 */
90  // 'a'-'z', and all punctuation go here in numerical order
91  BackSpaceKey  = 0xff08,       /*!< Backspace */
92  TabKey        = 0xff09,       /*!< Tab */
93  ClearKey      = 0xff0b,       /*!< On some systems with NumLock off '5' produces this */
94  ReturnKey     = 0xff0d,       /*!< Main Enter key, Windows and X documentation calls this "Return" */
95  PauseKey      = 0xff13,       /*!< Pause + Break button */
96  ScrollLockKey = 0xff14,       /*!< Scroll Lock button */
97  EscapeKey     = 0xff1b,       /*!< Esc */
98  HomeKey       = 0xff50,       /*!< Home */
99  LeftKey       = 0xff51,       /*!< Left */
100  UpKey         = 0xff52,       /*!< Up arrow */
101  RightKey      = 0xff53,       /*!< Right arrow */
102  DownKey       = 0xff54,       /*!< Down arrow */
103  PageUpKey     = 0xff55,       /*!< Page Up */
104  PageDownKey   = 0xff56,       /*!< Page Down */
105  EndKey        = 0xff57,       /*!< End */
106  PrintKey      = 0xff61,       /*!< Print Scrn key + SysRq key */
107  InsertKey     = 0xff63,       /*!< Insert */
108  MenuKey       = 0xff67,       /*!< Key in lower-right with picture of popup menu */
109  HelpKey       = 0xff68,       /*!< Help key on Macintosh keyboards */
110  NumLockKey    = 0xff7f,       /*!< NumLock key */
111  Keypad        = 0xff80,       /*!< Add ASCII to get keypad keys */
112  KeypadEnter   = Keypad+'\r',  /*!< Keypad+'\\r' */
113  MultiplyKey   = Keypad+'*',   /*!< Keypad+'*' */
114  AddKey        = Keypad+'+',   /*!< Keypad+'+' */
115  SubtractKey   = Keypad+'-',   /*!< Keypad+'-' */
116  DecimalKey    = Keypad+'.',   /*!< Keypad+'.' */
117  DivideKey     = Keypad+'/',   /*!< Keypad+'/' */
118  Keypad0       = Keypad+'0',   /*!< Keypad+'0' */
119  Keypad1       = Keypad+'1',   /*!< Keypad+'1' */
120  Keypad2       = Keypad+'2',   /*!< Keypad+'2' */
121  Keypad3       = Keypad+'3',   /*!< Keypad+'3' */
122  Keypad4       = Keypad+'4',   /*!< Keypad+'4' */
123  Keypad5       = Keypad+'5',   /*!< Keypad+'5' */
124  Keypad6       = Keypad+'6',   /*!< Keypad+'6' */
125  Keypad7       = Keypad+'7',   /*!< Keypad+'7' */
126  Keypad8       = Keypad+'8',   /*!< Keypad+'8' */
127  Keypad9       = Keypad+'9',   /*!< Keypad+'9' */
128  KeypadLast    = 0xffbd,       /*!< Keypad+'=', largest legal keypad key */
129  F0Key         = 0xffbd,       /*!< Add a number to get function key */
130  F1Key         = F0Key+1,      /*!< F0Key+1 */
131  F2Key         = F0Key+2,      /*!< F0Key+2 */
132  F3Key         = F0Key+3,      /*!< F0Key+3 */
133  F4Key         = F0Key+4,      /*!< F0Key+4 */
134  F5Key         = F0Key+5,      /*!< F0Key+5 */
135  F6Key         = F0Key+6,      /*!< F0Key+6 */
136  F7Key         = F0Key+7,      /*!< F0Key+7 */
137  F8Key         = F0Key+8,      /*!< F0Key+8 */
138  F9Key         = F0Key+9,      /*!< F0Key+9 */
139  F10Key        = F0Key+10,     /*!< F0Key+10 */
140  F11Key        = F0Key+11,     /*!< F0Key+11 */
141  F12Key        = F0Key+12,     /*!< F0Key+12 */
142  // use F0Key+n to get function key n
143  LastFunctionKey = F0Key+35,   /*!< F0Key+35, largest legal function key */
144  LeftShiftKey  = 0xffe1,       /*!< Left-hand Shift */
145  RightShiftKey = 0xffe2,       /*!< Right-hand Shift */
146  LeftCtrlKey   = 0xffe3,       /*!< Left-hand Ctrl */
147  RightCtrlKey  = 0xffe4,       /*!< Right-hand Ctrl */
148  CapsLockKey   = 0xffe5,       /*!< Caps Lock */
149  LeftMetaKey   = 0xffe7,       /*!< The left "Windows" or the "Apple" key */
150  RightMetaKey  = 0xffe8,       /*!< The right "Windows" or the "Apple" key */
151  LeftAltKey    = 0xffe9,       /*!< Left-hand Alt (option on Mac) */
152  RightAltKey   = 0xffea,       /*!< Right-hand Alt (option on Mac) */
153  DeleteKey     = 0xffff        /*!< Delete */
154};
155
156/*! Flags returned by event_state(), and used as the high 16 bits
157  of Widget::add_shortcut() values (the low 16 bits are all zero, so these
158  may be or'd with key values).
159
160  The inline function BUTTON(n) will turn n (1-8) into the flag for a
161  mouse button.
162*/
163enum {
164  SHIFT         = 0x00010000,   /*!< Either shift key held down */
165  CAPSLOCK      = 0x00020000,   /*!< Caps lock is toggled on */
166  CTRL          = 0x00040000,   /*!< Either ctrl key held down */
167  ALT           = 0x00080000,   /*!< Either alt key held down */
168  NUMLOCK       = 0x00100000,   /*!< Num Lock turned on */
169  META          = 0x00400000,   /*!< "Windows" or the "Apple" keys held down */
170  SCROLLLOCK    = 0x00800000,   /*!< Scroll Lock turned on */
171  BUTTON1       = 0x01000000,   /*!< Left mouse button held down */
172  BUTTON2       = 0x02000000,   /*!< Middle mouse button held down */
173  BUTTON3       = 0x04000000,   /*!< Right mouse button held down */
174  ANY_BUTTON    = 0x7f000000, /*!< Any mouse button (up to 8) */
175#ifdef __APPLE__
176  COMMAND = META /*!< On Apple it is the same as META, on other platforms CTRL. */
177#else
178  COMMAND = CTRL /*!< On Apple it is the same as META, on other platforms CTRL. */
179#endif // __APPLE__
180};
181
182inline unsigned BUTTON(int n) {return 0x00800000 << n;}
183
184/*! Device identifier returned by event_device(). This enumeration
185  is useful to get the device type that caused a PUSH, RELEASE,
186  DRAG or MOVE event
187*/
188enum {
189  DEVICE_MOUSE    = 0, /*!< Event triggered by the system mouse */
190  DEVICE_STYLUS   = 1, /*!< Event triggered by a pen on a tablet, givin pressure and tilt information */
191  DEVICE_ERASER   = 2, /*!< Event triggered by an eraser on a tablet, givin pressure and tilt information */
192  DEVICE_CURSOR   = 3, /*!< Event triggered by a puck style device on a tablet */
193  DEVICE_AIRBRUSH = 4, /*!< Event triggered by an airbrush on a tablet, giving pressure and tilt information */
194  DEVICE_TOUCH    = 5  /*!< Event triggered by touch a touch screen device */
195};
196
197/*! \} */
198
199class Rectangle;
200class Widget;
201class Window;
202
203////////////////////////////////////////////////////////////////
204// Do not use these variables, they may not exist in future versions:
205
206extern FL_API int e_type;
207extern FL_API int e_x;
208extern FL_API int e_y;
209extern FL_API int e_dx;
210extern FL_API int e_dy;
211extern FL_API int e_x_root;
212extern FL_API int e_y_root;
213extern FL_API unsigned e_state;
214extern FL_API int e_clicks;
215extern FL_API unsigned e_is_click;
216extern FL_API unsigned e_keysym;
217extern FL_API unsigned e_length;
218extern FL_API const char* e_text;
219extern FL_API float e_pressure;
220extern FL_API float e_x_tilt;
221extern FL_API float e_y_tilt;
222extern FL_API int e_device;
223extern FL_API int compose_state;
224extern FL_API Widget* belowmouse_;
225extern FL_API Widget* pushed_;
226extern FL_API Widget* focus_;
227extern FL_API Widget* modal_;
228extern FL_API bool grab_;
229extern FL_API bool exit_modal_;
230
231////////////////////////////////////////////////////////////////
232
233/*! \addtogroup events
234  \{
235*/
236// event information:
237inline int  event()                     {return e_type;}
238inline int  event_x()                   {return e_x;}
239inline int  event_y()                   {return e_y;}
240inline int  event_dx()                  {return e_dx;}
241inline int  event_dy()                  {return e_dy;}
242inline int  event_x_root()              {return e_x_root;}
243inline int  event_y_root()              {return e_y_root;}
244inline int  event_clicks()              {return e_clicks;}
245inline void event_clicks(int i)         {e_clicks = i;}
246inline bool event_is_click()            {return e_is_click != 0;}
247inline void event_is_click(bool)        {e_is_click = 0;} // only false works!
248inline unsigned event_state()           {return e_state;}
249inline bool event_state(unsigned i)     {return (e_state&i) != 0;}
250inline unsigned event_key()             {return e_keysym;}
251inline unsigned event_button()          {return e_keysym;}
252FL_API bool event_key_state(unsigned);
253inline const char* event_text()         {return e_text;}
254inline unsigned event_length()          {return e_length;}
255inline float event_pressure()   {return e_pressure;}
256inline float event_x_tilt()     {return e_x_tilt;}
257inline float event_y_tilt()     {return e_y_tilt;}
258inline int  event_device()      {return e_device;}
259
260// tests on current event:
261FL_API bool event_inside(const Rectangle&);
262FL_API bool compose(int &del);
263inline void compose_reset()             {compose_state = 0;}
264
265// shortcuts:
266/*! Structure created by Widget::add_shortcut() and returned by list_shortcuts(). */
267struct ShortcutAssignment {Widget* widget; unsigned key;};
268FL_API const ShortcutAssignment* list_shortcuts(unsigned key, unsigned& count);
269FL_API const ShortcutAssignment* list_shortcuts(const Widget*,unsigned& count);
270FL_API const ShortcutAssignment* list_shortcuts(unsigned& count);
271FL_API const ShortcutAssignment* list_matching_shortcuts(unsigned& count);
272FL_API bool try_shortcut();
273FL_API const char* key_name(unsigned key);
274FL_API unsigned key(const char* name);
275
276// get current information, not info from last event:
277FL_API bool get_key_state(unsigned);
278FL_API void get_mouse(int &,int &);
279
280// event destinations:
281FL_API bool handle(int, Window*);
282FL_API void add_event_handler(int (*h)(int, Window*));
283inline Widget* belowmouse()             {return belowmouse_;}
284FL_API void belowmouse(Widget*);
285inline void belowmouse(Widget& w)       {belowmouse(&w);}
286inline Widget* pushed()                 {return pushed_;}
287FL_API void pushed(Widget*);
288inline void pushed(Widget& w)           {pushed(&w);}
289inline Widget* focus()                  {return focus_;}
290FL_API void focus(Widget*);
291inline void focus(Widget& w)            {focus(&w);}
292
293// cut/paste/dnd:
294FL_API void copy(const char* stuff, int len, bool clipboard = false);
295FL_API void paste(Widget &receiver, bool clipboard = false);
296FL_API bool dnd();
297
298// Modal widgets (block events going to any other widgets):
299FL_API void modal(Widget*, bool grab = false);
300inline Widget* modal()                  {return modal_;}
301inline bool grab()                      {return grab_;}
302inline void exit_modal()                {exit_modal_ = true;}
303inline bool exit_modal_flag()           {return exit_modal_;}
304
305/*! \} */
306
307}
308
309#endif
310
311//
312// $Id: events.h 4571 2005-09-16 08:02:58Z spitzak $
313//
Note: See TracBrowser for help on using the repository browser.