PageRenderTime 41ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/dependencies/include/fltk/events.h

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