event.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  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. /* widget event */
  58. RTGUI_EVENT_FOCUSED, /* widget focused */
  59. RTGUI_EVENT_SCROLLED, /* scroll bar scrolled */
  60. RTGUI_EVENT_RESIZE, /* widget resize */
  61. RTGUI_EVENT_SELECTED, /* widget selected */
  62. RTGUI_EVENT_UNSELECTED, /* widget un-selected */
  63. RTGUI_EVENT_MV_MODEL, /* data of a model has been changed */
  64. /* user command event. It should always be the last command type. */
  65. RTGUI_EVENT_COMMAND = 0x0100, /* user command */
  66. };
  67. typedef enum _rtgui_event_type rtgui_event_type;
  68. enum
  69. {
  70. RTGUI_STATUS_OK = 0, /* status ok */
  71. RTGUI_STATUS_ERROR, /* generic error */
  72. RTGUI_STATUS_NRC, /* no resource */
  73. };
  74. struct rtgui_event
  75. {
  76. /* the event type */
  77. enum _rtgui_event_type type;
  78. /* user field of event */
  79. rt_uint16_t user;
  80. /* the event sender */
  81. rt_thread_t sender;
  82. /* mailbox to acknowledge request */
  83. rt_mailbox_t ack;
  84. };
  85. typedef struct rtgui_event rtgui_event_t;
  86. #define RTGUI_EVENT(e) ((struct rtgui_event*)(e))
  87. #define RTGUI_EVENT_INIT(e, t) do \
  88. { \
  89. (e)->type = (t); \
  90. (e)->user = 0; \
  91. (e)->sender = rt_thread_self(); \
  92. (e)->ack = RT_NULL; \
  93. } while (0)
  94. /*
  95. * RTGUI Application Event
  96. */
  97. struct rtgui_event_application
  98. {
  99. struct rtgui_event parent;
  100. struct rtgui_app *app;
  101. };
  102. /* gui application init */
  103. #define RTGUI_EVENT_APP_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_APP_CREATE)
  104. #define RTGUI_EVENT_APP_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_APP_DESTROY)
  105. #define RTGUI_EVENT_APP_ACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_APP_ACTIVATE)
  106. /*
  107. * RTGUI Window Event
  108. */
  109. #define _RTGUI_EVENT_WIN_ELEMENTS \
  110. struct rtgui_event parent; \
  111. struct rtgui_win *wid;
  112. /*
  113. * RTGUI Window Event
  114. */
  115. struct rtgui_event_win
  116. {
  117. _RTGUI_EVENT_WIN_ELEMENTS
  118. };
  119. struct rtgui_event_win_create
  120. {
  121. _RTGUI_EVENT_WIN_ELEMENTS
  122. struct rtgui_win *parent_window;
  123. #ifndef RTGUI_USING_SMALL_SIZE
  124. /* the window title */
  125. rt_uint8_t title[RTGUI_NAME_MAX];
  126. /* the window extent */
  127. struct rtgui_rect extent;
  128. #endif
  129. };
  130. struct rtgui_event_win_move
  131. {
  132. _RTGUI_EVENT_WIN_ELEMENTS
  133. rt_int16_t x, y;
  134. };
  135. struct rtgui_event_win_resize
  136. {
  137. _RTGUI_EVENT_WIN_ELEMENTS
  138. rtgui_rect_t rect;
  139. };
  140. #define rtgui_event_win_destroy rtgui_event_win
  141. #define rtgui_event_win_show rtgui_event_win
  142. #define rtgui_event_win_hide rtgui_event_win
  143. #define rtgui_event_win_activate rtgui_event_win
  144. #define rtgui_event_win_deactivate rtgui_event_win
  145. #define rtgui_event_win_close rtgui_event_win
  146. #define rtgui_event_win_modal_enter rtgui_event_win
  147. /* window event init */
  148. #define RTGUI_EVENT_WIN_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CREATE)
  149. #define RTGUI_EVENT_WIN_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DESTROY)
  150. #define RTGUI_EVENT_WIN_SHOW_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_SHOW)
  151. #define RTGUI_EVENT_WIN_HIDE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_HIDE)
  152. #define RTGUI_EVENT_WIN_ACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_ACTIVATE)
  153. #define RTGUI_EVENT_WIN_DEACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DEACTIVATE)
  154. #define RTGUI_EVENT_WIN_CLOSE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CLOSE)
  155. #define RTGUI_EVENT_WIN_MOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MOVE)
  156. #define RTGUI_EVENT_WIN_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_RESIZE)
  157. #define RTGUI_EVENT_WIN_MODAL_ENTER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MODAL_ENTER)
  158. /*
  159. * RTGUI set window manager
  160. */
  161. struct rtgui_event_set_wm
  162. {
  163. struct rtgui_event parent;
  164. struct rtgui_app *app;
  165. };
  166. #define RTGUI_EVENT_SET_WM_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SET_WM);
  167. /*
  168. * RTGUI Other Event
  169. */
  170. struct rtgui_event_update_begin
  171. {
  172. struct rtgui_event parent;
  173. /* the update rect */
  174. rtgui_rect_t rect;
  175. };
  176. struct rtgui_event_update_end
  177. {
  178. struct rtgui_event parent;
  179. /* the update rect */
  180. rtgui_rect_t rect;
  181. };
  182. struct rtgui_event_monitor
  183. {
  184. _RTGUI_EVENT_WIN_ELEMENTS
  185. /* the monitor rect */
  186. rtgui_rect_t rect;
  187. };
  188. struct rtgui_event_paint
  189. {
  190. _RTGUI_EVENT_WIN_ELEMENTS
  191. rtgui_rect_t rect; /* rect to be updated */
  192. };
  193. struct rtgui_timer;
  194. struct rtgui_event_timer
  195. {
  196. struct rtgui_event parent;
  197. struct rtgui_timer *timer;
  198. };
  199. typedef struct rtgui_event_timer rtgui_event_timer_t;
  200. struct rtgui_event_clip_info
  201. {
  202. _RTGUI_EVENT_WIN_ELEMENTS
  203. /* the number of rects */
  204. //rt_uint32_t num_rect;
  205. /* rtgui_rect_t *rects */
  206. };
  207. #define RTGUI_EVENT_GET_RECT(e, i) &(((rtgui_rect_t*)(e + 1))[i])
  208. #define RTGUI_EVENT_UPDATE_BEGIN_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_BEGIN)
  209. #define RTGUI_EVENT_UPDATE_END_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_END)
  210. #define RTGUI_EVENT_MONITOR_ADD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_ADD)
  211. #define RTGUI_EVENT_MONITOR_REMOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_REMOVE)
  212. #define RTGUI_EVENT_CLIP_INFO_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_CLIP_INFO)
  213. #define RTGUI_EVENT_PAINT_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PAINT)
  214. #define RTGUI_EVENT_TIMER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_TIMER)
  215. #define rtgui_event_show rtgui_event
  216. #define rtgui_event_hide rtgui_event
  217. #define RTGUI_EVENT_SHOW_INIT(e) RTGUI_EVENT_INIT((e), RTGUI_EVENT_SHOW)
  218. #define RTGUI_EVENT_HIDE_INIT(e) RTGUI_EVENT_INIT((e), RTGUI_EVENT_HIDE)
  219. struct rtgui_event_update_toplvl
  220. {
  221. struct rtgui_event parent;
  222. struct rtgui_win *toplvl;
  223. };
  224. #define RTGUI_EVENT_UPDATE_TOPLVL_INIT(e) \
  225. do { \
  226. RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_TOPLVL); \
  227. (e)->toplvl = RT_NULL; \
  228. } while (0)
  229. /*
  230. * RTGUI Mouse and Keyboard Event
  231. */
  232. struct rtgui_event_mouse
  233. {
  234. _RTGUI_EVENT_WIN_ELEMENTS
  235. rt_uint16_t x, y;
  236. rt_uint16_t button;
  237. };
  238. #define RTGUI_MOUSE_BUTTON_LEFT 0x01
  239. #define RTGUI_MOUSE_BUTTON_RIGHT 0x02
  240. #define RTGUI_MOUSE_BUTTON_MIDDLE 0x03
  241. #define RTGUI_MOUSE_BUTTON_WHEELUP 0x04
  242. #define RTGUI_MOUSE_BUTTON_WHEELDOWN 0x08
  243. #define RTGUI_MOUSE_BUTTON_DOWN 0x10
  244. #define RTGUI_MOUSE_BUTTON_UP 0x20
  245. struct rtgui_event_kbd
  246. {
  247. _RTGUI_EVENT_WIN_ELEMENTS
  248. rt_uint16_t type; /* key down or up */
  249. rt_uint16_t key; /* current key */
  250. rt_uint16_t mod; /* current key modifiers */
  251. rt_uint16_t unicode; /* translated character */
  252. };
  253. #define RTGUI_KBD_IS_SET_CTRL(e) ((e)->mod & (RTGUI_KMOD_LCTRL | RTGUI_KMOD_RCTRL)))
  254. #define RTGUI_KBD_IS_SET_ALT(e) ((e)->mod & (RTGUI_KMOD_LALT | RTGUI_KMOD_RALT))
  255. #define RTGUI_KBD_IS_SET_SHIFT(e) ((e)->mod & (RTGUI_KMOD_LSHIFT| RTGUI_KMOD_RSHIFT))
  256. #define RTGUI_KBD_IS_UP(e) ((e)->type == RTGUI_KEYUP)
  257. #define RTGUI_KBD_IS_DOWN(e) ((e)->type == RTGUI_KEYDOWN)
  258. #define RTGUI_EVENT_MOUSE_MOTION_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_MOTION)
  259. #define RTGUI_EVENT_MOUSE_BUTTON_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_BUTTON)
  260. #define RTGUI_EVENT_KBD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_KBD)
  261. struct rtgui_event_command
  262. {
  263. _RTGUI_EVENT_WIN_ELEMENTS
  264. /* command type */
  265. rt_int32_t type;
  266. /* command id */
  267. rt_int32_t command_id;
  268. /* command string */
  269. char command_string[RTGUI_NAME_MAX];
  270. };
  271. #define RTGUI_EVENT_COMMAND_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_COMMAND)
  272. #define RTGUI_CMD_UNKNOWN 0x00
  273. #define RTGUI_CMD_WM_CLOSE 0x10
  274. #define RTGUI_CMD_USER_INT 0x20
  275. #define RTGUI_CMD_USER_STRING 0x21
  276. /************************************************************************/
  277. /* Widget Event */
  278. /************************************************************************/
  279. #define RTGUI_WIDGET_EVENT_INIT(e, t) do \
  280. { \
  281. (e)->type = (t); \
  282. (e)->sender = RT_NULL; \
  283. (e)->ack = RT_NULL; \
  284. } while (0)
  285. /*
  286. * RTGUI Scrollbar Event
  287. */
  288. struct rtgui_event_scrollbar
  289. {
  290. struct rtgui_event parent;
  291. rt_uint8_t event;
  292. };
  293. #define RTGUI_SCROLL_LINEUP 0x01
  294. #define RTGUI_SCROLL_LINEDOWN 0x02
  295. #define RTGUI_SCROLL_PAGEUP 0x03
  296. #define RTGUI_SCROLL_PAGEDOWN 0x04
  297. #define RTGUI_EVENT_SCROLLED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SCROLLED)
  298. /*
  299. * RTGUI Widget Focused Event
  300. */
  301. struct rtgui_event_focused
  302. {
  303. struct rtgui_event parent;
  304. struct rtgui_widget *widget;
  305. };
  306. #define RTGUI_EVENT_FOCUSED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_FOCUSED)
  307. /*
  308. * RTGUI Widget Resize Event
  309. */
  310. struct rtgui_event_resize
  311. {
  312. struct rtgui_event parent;
  313. rt_int16_t x, y;
  314. rt_int16_t w, h;
  315. };
  316. #define RTGUI_EVENT_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_RESIZE)
  317. /*
  318. * RTGUI Model/View Event
  319. */
  320. enum rtgui_event_model_mode
  321. {
  322. RTGUI_MV_DATA_ADDED,
  323. RTGUI_MV_DATA_CHANGED,
  324. RTGUI_MV_DATA_DELETED,
  325. };
  326. struct rtgui_event_mv_model
  327. {
  328. struct rtgui_event parent;
  329. struct rtgui_mv_model *model;
  330. struct rtgui_mv_view *view;
  331. rt_size_t first_data_changed_idx;
  332. rt_size_t last_data_changed_idx;
  333. };
  334. #define _RTGUI_EVENT_MV_INIT_TYPE(T) \
  335. rt_inline void RTGUI_EVENT_MV_MODEL_##T##_INIT(struct rtgui_event_mv_model *e) \
  336. { \
  337. RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MV_MODEL); \
  338. (e)->parent.user = RTGUI_MV_DATA_##T; \
  339. } \
  340. /* useless struct to allow trailing semicolon */ \
  341. struct dummy
  342. _RTGUI_EVENT_MV_INIT_TYPE(ADDED);
  343. _RTGUI_EVENT_MV_INIT_TYPE(CHANGED);
  344. _RTGUI_EVENT_MV_INIT_TYPE(DELETED);
  345. #undef _RTGUI_EVENT_MV_INIT_TYPE
  346. #define _RTGUI_EVENT_MV_IS_TYPE(T) \
  347. rt_inline rt_bool_t RTGUI_EVENT_MV_MODEL_IS_##T(struct rtgui_event_mv_model *e) \
  348. { \
  349. return e->parent.user == RTGUI_MV_DATA_##T; \
  350. } \
  351. /* useless struct to allow trailing semicolon */ \
  352. struct dummy
  353. _RTGUI_EVENT_MV_IS_TYPE(ADDED);
  354. _RTGUI_EVENT_MV_IS_TYPE(CHANGED);
  355. _RTGUI_EVENT_MV_IS_TYPE(DELETED);
  356. #undef _RTGUI_EVENT_MV_IS_TYPE
  357. #undef _RTGUI_EVENT_WIN_ELEMENTS
  358. union rtgui_event_generic
  359. {
  360. struct rtgui_event base;
  361. struct rtgui_event_application app_create;
  362. struct rtgui_event_application app_destroy;
  363. struct rtgui_event_application app_activate;
  364. struct rtgui_event_set_wm set_wm;
  365. struct rtgui_event_win win_base;
  366. struct rtgui_event_win_create win_create;
  367. struct rtgui_event_win_move win_move;
  368. struct rtgui_event_win_resize win_resize;
  369. struct rtgui_event_win_destroy win_destroy;
  370. struct rtgui_event_win_show win_show;
  371. struct rtgui_event_win_hide win_hide;
  372. struct rtgui_event_win_activate win_activate;
  373. struct rtgui_event_win_deactivate win_deactivate;
  374. struct rtgui_event_win_close win_close;
  375. struct rtgui_event_win_modal_enter win_modal_enter;
  376. struct rtgui_event_update_begin update_begin;
  377. struct rtgui_event_update_end update_end;
  378. struct rtgui_event_monitor monitor;
  379. struct rtgui_event_paint paint;
  380. struct rtgui_event_timer timer;
  381. struct rtgui_event_update_toplvl update_toplvl;
  382. struct rtgui_event_clip_info clip_info;
  383. struct rtgui_event_mouse mouse;
  384. struct rtgui_event_kbd kbd;
  385. struct rtgui_event_scrollbar scrollbar;
  386. struct rtgui_event_focused focused;
  387. struct rtgui_event_resize resize;
  388. struct rtgui_event_mv_model model;
  389. struct rtgui_event_command command;
  390. };
  391. #endif