event.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. /*
  2. * File : event.h
  3. * This file is part of RTGUI in RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-10-04 Bernard first version
  13. */
  14. #ifndef __RTGUI_EVENT_H__
  15. #define __RTGUI_EVENT_H__
  16. #include <rtgui/rtgui.h>
  17. #include <rtgui/kbddef.h>
  18. /* NOTE: if you create a new event type, remember to add it into the union
  19. * rtgui_event_generic */
  20. enum _rtgui_event_type
  21. {
  22. /* applications event */
  23. RTGUI_EVENT_APP_CREATE, /* create an application */
  24. RTGUI_EVENT_APP_DESTROY, /* destroy an application */
  25. RTGUI_EVENT_APP_ACTIVATE, /* activate an application */
  26. /* window event */
  27. RTGUI_EVENT_WIN_CREATE, /* create a window */
  28. RTGUI_EVENT_WIN_DESTROY, /* destroy a window */
  29. RTGUI_EVENT_WIN_SHOW, /* show a window */
  30. RTGUI_EVENT_WIN_HIDE, /* hide a window */
  31. RTGUI_EVENT_WIN_ACTIVATE, /* activate a window */
  32. RTGUI_EVENT_WIN_DEACTIVATE, /* deactivate a window */
  33. RTGUI_EVENT_WIN_CLOSE, /* close a window */
  34. RTGUI_EVENT_WIN_MOVE, /* move a window */
  35. RTGUI_EVENT_WIN_RESIZE, /* resize a window */
  36. RTGUI_EVENT_WIN_MODAL_ENTER, /* the window is entering modal mode.
  37. This event should be sent after the
  38. window got setup and before the
  39. application got setup. */
  40. /* WM event */
  41. RTGUI_EVENT_SET_WM, /* set window manager */
  42. RTGUI_EVENT_UPDATE_BEGIN, /* update a rect */
  43. RTGUI_EVENT_UPDATE_END, /* update a rect */
  44. RTGUI_EVENT_MONITOR_ADD, /* add a monitor rect */
  45. RTGUI_EVENT_MONITOR_REMOVE, /* remove a monitor rect */
  46. RTGUI_EVENT_SHOW, /* the widget is going to be shown */
  47. RTGUI_EVENT_HIDE, /* the widget is going to be hidden */
  48. RTGUI_EVENT_PAINT, /* paint on screen */
  49. RTGUI_EVENT_TIMER, /* timer */
  50. RTGUI_EVENT_UPDATE_TOPLVL, /* update the toplevel */
  51. /* clip rect information */
  52. RTGUI_EVENT_CLIP_INFO, /* clip rect info */
  53. /* mouse and keyboard event */
  54. RTGUI_EVENT_MOUSE_MOTION, /* mouse motion */
  55. RTGUI_EVENT_MOUSE_BUTTON, /* mouse button info */
  56. RTGUI_EVENT_KBD, /* keyboard info */
  57. /* user command event */
  58. RTGUI_EVENT_COMMAND=0x0100, /* user command */
  59. /* widget event */
  60. RTGUI_EVENT_FOCUSED, /* widget focused */
  61. RTGUI_EVENT_SCROLLED, /* scroll bar scrolled */
  62. RTGUI_EVENT_RESIZE, /* widget resize */
  63. RTGUI_EVENT_SELECTED, /* widget selected */
  64. RTGUI_EVENT_UNSELECTED, /* widget un-selected */
  65. };
  66. typedef enum _rtgui_event_type rtgui_event_type;
  67. enum {
  68. RTGUI_STATUS_OK = 0, /* status ok */
  69. RTGUI_STATUS_ERROR, /* generic error */
  70. RTGUI_STATUS_NRC, /* no resource */
  71. };
  72. struct rtgui_event
  73. {
  74. /* the event type */
  75. rt_uint16_t type;
  76. /* user field of event */
  77. rt_uint16_t user;
  78. /* the event sender */
  79. rt_thread_t sender;
  80. /* mailbox to acknowledge request */
  81. rt_mailbox_t ack;
  82. };
  83. typedef struct rtgui_event rtgui_event_t;
  84. #define RTGUI_EVENT(e) ((struct rtgui_event*)(e))
  85. #define RTGUI_EVENT_INIT(e, t) do \
  86. { \
  87. (e)->type = (t); \
  88. (e)->user = 0; \
  89. (e)->sender = rt_thread_self(); \
  90. (e)->ack = RT_NULL; \
  91. } while (0)
  92. /*
  93. * RTGUI Application Event
  94. */
  95. struct rtgui_event_application
  96. {
  97. struct rtgui_event parent;
  98. struct rtgui_app* app;
  99. };
  100. /* gui application init */
  101. #define RTGUI_EVENT_APP_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_APP_CREATE)
  102. #define RTGUI_EVENT_APP_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_APP_DESTROY)
  103. #define RTGUI_EVENT_APP_ACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_APP_ACTIVATE)
  104. /*
  105. * RTGUI Window Event
  106. */
  107. #define _RTGUI_EVENT_WIN_ELEMENTS \
  108. struct rtgui_event parent; \
  109. struct rtgui_win *wid;
  110. /*
  111. * RTGUI Window Event
  112. */
  113. struct rtgui_event_win
  114. {
  115. _RTGUI_EVENT_WIN_ELEMENTS
  116. };
  117. struct rtgui_event_win_create
  118. {
  119. _RTGUI_EVENT_WIN_ELEMENTS
  120. struct rtgui_win *parent_window;
  121. #ifndef RTGUI_USING_SMALL_SIZE
  122. /* the window title */
  123. rt_uint8_t title[RTGUI_NAME_MAX];
  124. /* the window extent */
  125. struct rtgui_rect extent;
  126. #endif
  127. };
  128. struct rtgui_event_win_move
  129. {
  130. _RTGUI_EVENT_WIN_ELEMENTS
  131. rt_int16_t x, y;
  132. };
  133. struct rtgui_event_win_resize
  134. {
  135. _RTGUI_EVENT_WIN_ELEMENTS
  136. rtgui_rect_t rect;
  137. };
  138. #define rtgui_event_win_destroy rtgui_event_win
  139. #define rtgui_event_win_show rtgui_event_win
  140. #define rtgui_event_win_hide rtgui_event_win
  141. #define rtgui_event_win_activate rtgui_event_win
  142. #define rtgui_event_win_deactivate rtgui_event_win
  143. #define rtgui_event_win_close rtgui_event_win
  144. #define rtgui_event_win_modal_enter rtgui_event_win
  145. /* window event init */
  146. #define RTGUI_EVENT_WIN_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CREATE)
  147. #define RTGUI_EVENT_WIN_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DESTROY)
  148. #define RTGUI_EVENT_WIN_SHOW_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_SHOW)
  149. #define RTGUI_EVENT_WIN_HIDE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_HIDE)
  150. #define RTGUI_EVENT_WIN_ACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_ACTIVATE)
  151. #define RTGUI_EVENT_WIN_DEACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DEACTIVATE)
  152. #define RTGUI_EVENT_WIN_CLOSE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CLOSE)
  153. #define RTGUI_EVENT_WIN_MOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MOVE)
  154. #define RTGUI_EVENT_WIN_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_RESIZE)
  155. #define RTGUI_EVENT_WIN_MODAL_ENTER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MODAL_ENTER)
  156. /*
  157. * RTGUI set window manager
  158. */
  159. struct rtgui_event_set_wm
  160. {
  161. struct rtgui_event parent;
  162. struct rtgui_app *app;
  163. };
  164. #define RTGUI_EVENT_SET_WM_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SET_WM);
  165. /*
  166. * RTGUI Other Event
  167. */
  168. struct rtgui_event_update_begin
  169. {
  170. struct rtgui_event parent;
  171. /* the update rect */
  172. rtgui_rect_t rect;
  173. };
  174. struct rtgui_event_update_end
  175. {
  176. struct rtgui_event parent;
  177. /* the update rect */
  178. rtgui_rect_t rect;
  179. };
  180. struct rtgui_event_monitor
  181. {
  182. _RTGUI_EVENT_WIN_ELEMENTS
  183. /* the monitor rect */
  184. rtgui_rect_t rect;
  185. };
  186. struct rtgui_event_paint
  187. {
  188. _RTGUI_EVENT_WIN_ELEMENTS
  189. rtgui_rect_t rect; /* rect to be updated */
  190. };
  191. struct rtgui_timer;
  192. struct rtgui_event_timer
  193. {
  194. struct rtgui_event parent;
  195. struct rtgui_timer *timer;
  196. };
  197. typedef struct rtgui_event_timer rtgui_event_timer_t;
  198. struct rtgui_event_clip_info
  199. {
  200. _RTGUI_EVENT_WIN_ELEMENTS
  201. /* the number of rects */
  202. //rt_uint32_t num_rect;
  203. /* rtgui_rect_t *rects */
  204. };
  205. #define RTGUI_EVENT_GET_RECT(e, i) &(((rtgui_rect_t*)(e + 1))[i])
  206. #define RTGUI_EVENT_UPDATE_BEGIN_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_BEGIN)
  207. #define RTGUI_EVENT_UPDATE_END_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_END)
  208. #define RTGUI_EVENT_MONITOR_ADD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_ADD)
  209. #define RTGUI_EVENT_MONITOR_REMOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_REMOVE)
  210. #define RTGUI_EVENT_CLIP_INFO_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_CLIP_INFO)
  211. #define RTGUI_EVENT_PAINT_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PAINT)
  212. #define RTGUI_EVENT_TIMER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_TIMER)
  213. #define rtgui_event_show rtgui_event
  214. #define rtgui_event_hide rtgui_event
  215. #define RTGUI_EVENT_SHOW_INIT(e) RTGUI_EVENT_INIT((e), RTGUI_EVENT_SHOW)
  216. #define RTGUI_EVENT_HIDE_INIT(e) RTGUI_EVENT_INIT((e), RTGUI_EVENT_HIDE)
  217. struct rtgui_event_update_toplvl
  218. {
  219. struct rtgui_event parent;
  220. struct rtgui_win *toplvl;
  221. };
  222. #define RTGUI_EVENT_UPDATE_TOPLVL_INIT(e) \
  223. do { \
  224. RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_TOPLVL); \
  225. (e)->toplvl = RT_NULL; \
  226. } while (0)
  227. /*
  228. * RTGUI Mouse and Keyboard Event
  229. */
  230. struct rtgui_event_mouse
  231. {
  232. _RTGUI_EVENT_WIN_ELEMENTS
  233. rt_uint16_t x, y;
  234. rt_uint16_t button;
  235. };
  236. #define RTGUI_MOUSE_BUTTON_LEFT 0x01
  237. #define RTGUI_MOUSE_BUTTON_RIGHT 0x02
  238. #define RTGUI_MOUSE_BUTTON_MIDDLE 0x03
  239. #define RTGUI_MOUSE_BUTTON_WHEELUP 0x04
  240. #define RTGUI_MOUSE_BUTTON_WHEELDOWN 0x08
  241. #define RTGUI_MOUSE_BUTTON_DOWN 0x10
  242. #define RTGUI_MOUSE_BUTTON_UP 0x20
  243. struct rtgui_event_kbd
  244. {
  245. _RTGUI_EVENT_WIN_ELEMENTS
  246. rt_uint16_t type; /* key down or up */
  247. rt_uint16_t key; /* current key */
  248. rt_uint16_t mod; /* current key modifiers */
  249. rt_uint16_t unicode; /* translated character */
  250. };
  251. #define RTGUI_KBD_IS_SET_CTRL(e) ((e)->mod & (RTGUI_KMOD_LCTRL | RTGUI_KMOD_RCTRL)))
  252. #define RTGUI_KBD_IS_SET_ALT(e) ((e)->mod & (RTGUI_KMOD_LALT | RTGUI_KMOD_RALT))
  253. #define RTGUI_KBD_IS_SET_SHIFT(e) ((e)->mod & (RTGUI_KMOD_LSHIFT| RTGUI_KMOD_RSHIFT))
  254. #define RTGUI_KBD_IS_UP(e) ((e)->type == RTGUI_KEYUP)
  255. #define RTGUI_KBD_IS_DOWN(e) ((e)->type == RTGUI_KEYDOWN)
  256. #define RTGUI_EVENT_MOUSE_MOTION_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_MOTION)
  257. #define RTGUI_EVENT_MOUSE_BUTTON_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_BUTTON)
  258. #define RTGUI_EVENT_KBD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_KBD)
  259. struct rtgui_event_command
  260. {
  261. _RTGUI_EVENT_WIN_ELEMENTS
  262. /* command type */
  263. rt_int32_t type;
  264. /* command id */
  265. rt_int32_t command_id;
  266. /* command string */
  267. char command_string[RTGUI_NAME_MAX];
  268. };
  269. #define RTGUI_EVENT_COMMAND_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_COMMAND)
  270. #define RTGUI_CMD_UNKNOWN 0x00
  271. #define RTGUI_CMD_WM_CLOSE 0x10
  272. #define RTGUI_CMD_USER_INT 0x20
  273. #define RTGUI_CMD_USER_STRING 0x21
  274. /************************************************************************/
  275. /* Widget Event */
  276. /************************************************************************/
  277. #define RTGUI_WIDGET_EVENT_INIT(e, t) do \
  278. { \
  279. (e)->type = (t); \
  280. (e)->sender = RT_NULL; \
  281. (e)->ack = RT_NULL; \
  282. } while (0)
  283. /*
  284. * RTGUI Scrollbar Event
  285. */
  286. struct rtgui_event_scrollbar
  287. {
  288. struct rtgui_event parent;
  289. rt_uint8_t event;
  290. };
  291. #define RTGUI_SCROLL_LINEUP 0x01
  292. #define RTGUI_SCROLL_LINEDOWN 0x02
  293. #define RTGUI_SCROLL_PAGEUP 0x03
  294. #define RTGUI_SCROLL_PAGEDOWN 0x04
  295. #define RTGUI_EVENT_SCROLLED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SCROLLED)
  296. /*
  297. * RTGUI Widget Focused Event
  298. */
  299. struct rtgui_event_focused
  300. {
  301. struct rtgui_event parent;
  302. struct rtgui_widget* widget;
  303. };
  304. #define RTGUI_EVENT_FOCUSED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_FOCUSED)
  305. /*
  306. * RTGUI Widget Resize Event
  307. */
  308. struct rtgui_event_resize
  309. {
  310. struct rtgui_event parent;
  311. rt_int16_t x, y;
  312. rt_int16_t w, h;
  313. };
  314. #define RTGUI_EVENT_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_RESIZE)
  315. #undef _RTGUI_EVENT_WIN_ELEMENTS
  316. union rtgui_event_generic
  317. {
  318. struct rtgui_event base;
  319. struct rtgui_event_application app_create;
  320. struct rtgui_event_application app_destroy;
  321. struct rtgui_event_application app_activate;
  322. struct rtgui_event_set_wm set_wm;
  323. struct rtgui_event_win win_base;
  324. struct rtgui_event_win_create win_create;
  325. struct rtgui_event_win_move win_move;
  326. struct rtgui_event_win_resize win_resize;
  327. struct rtgui_event_win_destroy win_destroy;
  328. struct rtgui_event_win_show win_show;
  329. struct rtgui_event_win_hide win_hide;
  330. struct rtgui_event_win_activate win_activate;
  331. struct rtgui_event_win_deactivate win_deactivate;
  332. struct rtgui_event_win_close win_close;
  333. struct rtgui_event_win_modal_enter win_modal_enter;
  334. struct rtgui_event_update_begin update_begin;
  335. struct rtgui_event_update_end update_end;
  336. struct rtgui_event_monitor monitor;
  337. struct rtgui_event_paint paint;
  338. struct rtgui_event_timer timer;
  339. struct rtgui_event_update_toplvl update_toplvl;
  340. struct rtgui_event_clip_info clip_info;
  341. struct rtgui_event_mouse mouse;
  342. struct rtgui_event_kbd kbd;
  343. struct rtgui_event_command command;
  344. struct rtgui_event_scrollbar scrollbar;
  345. struct rtgui_event_focused focused;
  346. struct rtgui_event_resize resize;
  347. };
  348. #endif