event.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. enum _rtgui_event_type
  19. {
  20. /* panel event */
  21. RTGUI_EVENT_PANEL_ATTACH = 0, /* attach to a panel */
  22. RTGUI_EVENT_PANEL_DETACH, /* detach from a panel */
  23. RTGUI_EVENT_PANEL_SHOW, /* show in a panel */
  24. RTGUI_EVENT_PANEL_HIDE, /* hide from a panel */
  25. RTGUI_EVENT_PANEL_INFO, /* panel information */
  26. RTGUI_EVENT_PANEL_RESIZE, /* resize panel */
  27. RTGUI_EVENT_PANEL_FULLSCREEN, /* to full screen */
  28. RTGUI_EVENT_PANEL_NORMAL, /* to normal screen */
  29. /* window event */
  30. RTGUI_EVENT_WIN_CREATE, /* create a window */
  31. RTGUI_EVENT_WIN_DESTROY, /* destroy a window */
  32. RTGUI_EVENT_WIN_SHOW, /* show a window */
  33. RTGUI_EVENT_WIN_HIDE, /* hide a window */
  34. RTGUI_EVENT_WIN_ACTIVATE, /* activate a window */
  35. RTGUI_EVENT_WIN_DEACTIVATE, /* deactivate a window */
  36. RTGUI_EVENT_WIN_CLOSE, /* close a window */
  37. RTGUI_EVENT_WIN_MOVE, /* move a window */
  38. RTGUI_EVENT_WIN_RESIZE, /* resize a window */
  39. /* WM event */
  40. RTGUI_EVENT_SET_WM, /* set window manager */
  41. RTGUI_EVENT_UPDATE_BEGIN, /* update a rect */
  42. RTGUI_EVENT_UPDATE_END, /* update a rect */
  43. RTGUI_EVENT_MONITOR_ADD, /* add a monitor rect */
  44. RTGUI_EVENT_MONITOR_REMOVE, /* remove a monitor rect*/
  45. RTGUI_EVENT_PAINT, /* paint on screen */
  46. RTGUI_EVENT_TIMER, /* timer */
  47. /* clip rect information */
  48. RTGUI_EVENT_CLIP_INFO, /* clip rect info */
  49. /* mouse and keyboard event */
  50. RTGUI_EVENT_MOUSE_MOTION, /* mouse motion */
  51. RTGUI_EVENT_MOUSE_BUTTON, /* mouse button info */
  52. RTGUI_EVENT_KBD, /* keyboard info */
  53. /* user command event */
  54. RTGUI_EVENT_COMMAND, /* user command */
  55. /* widget event */
  56. RTGUI_EVENT_FOCUSED, /* widget focused */
  57. RTGUI_EVENT_SCROLLED, /* scroll bar scrolled */
  58. RTGUI_EVENT_RESIZE, /* widget resize */
  59. };
  60. typedef enum _rtgui_event_type rtgui_event_type;
  61. enum {
  62. RTGUI_STATUS_OK = 0, /* status ok */
  63. RTGUI_STATUS_ERROR, /* generic error */
  64. RTGUI_STATUS_NRC, /* no resource */
  65. };
  66. struct rtgui_event
  67. {
  68. /* the event type */
  69. rt_uint32_t type;
  70. /* the event sender */
  71. rt_thread_t sender;
  72. /* mailbox to acknowledge request */
  73. rt_mailbox_t ack;
  74. };
  75. typedef struct rtgui_event rtgui_event_t;
  76. #define RTGUI_EVENT(e) ((struct rtgui_event*)(e))
  77. #define RTGUI_EVENT_INIT(e, t) do \
  78. { \
  79. (e)->type = (t); \
  80. (e)->sender = rt_thread_self(); \
  81. (e)->ack = RT_NULL; \
  82. } while (0)
  83. /*
  84. * RTGUI Panel Event
  85. */
  86. struct rtgui_event_panel_attach
  87. {
  88. struct rtgui_event parent;
  89. /* the panel name to be attached */
  90. char panel_name[RTGUI_NAME_MAX];
  91. /* workbench, wm field */
  92. rtgui_workbench_t* workbench;
  93. };
  94. struct rtgui_event_panel_detach
  95. {
  96. struct rtgui_event parent;
  97. /* the panel which thread belong to */
  98. rtgui_panel_t* panel;
  99. /* workbench, wm field */
  100. rtgui_workbench_t* workbench;
  101. };
  102. struct rtgui_event_panel_show
  103. {
  104. struct rtgui_event parent;
  105. /* the panel which thread belong to */
  106. rtgui_panel_t* panel;
  107. /* workbench, wm field */
  108. rtgui_workbench_t* workbench;
  109. };
  110. struct rtgui_event_panel_hide
  111. {
  112. struct rtgui_event parent;
  113. /* the panel which thread belong to */
  114. rtgui_panel_t* panel;
  115. /* workbench, wm field */
  116. rtgui_workbench_t* workbench;
  117. };
  118. struct rtgui_event_panel_info
  119. {
  120. struct rtgui_event parent;
  121. /* panel info */
  122. rtgui_panel_t* panel;
  123. rtgui_rect_t extent;
  124. };
  125. #define RTGUI_EVENT_PANEL_ATTACH_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PANEL_ATTACH)
  126. #define RTGUI_EVENT_PANEL_DETACH_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PANEL_DETACH)
  127. #define RTGUI_EVENT_PANEL_SHOW_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PANEL_SHOW)
  128. #define RTGUI_EVENT_PANEL_HIDE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PANEL_HIDE)
  129. #define RTGUI_EVENT_PANEL_INFO_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PANEL_INFO)
  130. /*
  131. * RTGUI Window Event
  132. */
  133. struct rtgui_event_win
  134. {
  135. struct rtgui_event parent;
  136. /* the window id */
  137. rtgui_win_t* wid;
  138. };
  139. struct rtgui_event_win_create
  140. {
  141. struct rtgui_event parent;
  142. /* the window event mask */
  143. rt_uint32_t mask;
  144. /* the window flag */
  145. rt_uint32_t flag;
  146. /* the window title */
  147. rt_uint8_t title[RTGUI_NAME_MAX];
  148. /* the window id */
  149. rtgui_win_t* wid;
  150. /* the window extent */
  151. struct rtgui_rect extent;
  152. };
  153. struct rtgui_event_win_move
  154. {
  155. struct rtgui_event parent;
  156. /* the window id */
  157. rtgui_win_t* wid;
  158. rt_int16_t x, y;
  159. };
  160. struct rtgui_event_win_resize
  161. {
  162. struct rtgui_event parent;
  163. /* the window id */
  164. rtgui_win_t* wid;
  165. rtgui_rect_t rect;
  166. };
  167. #define rtgui_event_win_destroy rtgui_event_win
  168. #define rtgui_event_win_show rtgui_event_win
  169. #define rtgui_event_win_hide rtgui_event_win
  170. #define rtgui_event_win_activate rtgui_event_win
  171. #define rtgui_event_win_deactivate rtgui_event_win
  172. #define rtgui_event_win_close rtgui_event_win
  173. /* window event init */
  174. #define RTGUI_EVENT_WIN_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CREATE)
  175. #define RTGUI_EVENT_WIN_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DESTROY)
  176. #define RTGUI_EVENT_WIN_SHOW_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_SHOW)
  177. #define RTGUI_EVENT_WIN_HIDE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_HIDE)
  178. #define RTGUI_EVENT_WIN_ACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_ACTIVATE)
  179. #define RTGUI_EVENT_WIN_DEACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DEACTIVATE)
  180. #define RTGUI_EVENT_WIN_CLOSE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CLOSE)
  181. #define RTGUI_EVENT_WIN_MOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MOVE)
  182. #define RTGUI_EVENT_WIN_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_RESIZE)
  183. /*
  184. * RTGUI Workbench Manager Event
  185. */
  186. struct rtgui_event_set_wm
  187. {
  188. struct rtgui_event parent;
  189. /* the panel name to be managed */
  190. char panel_name[RTGUI_NAME_MAX];
  191. };
  192. /* window event init */
  193. #define RTGUI_EVENT_SET_WM_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SET_WM)
  194. /*
  195. * RTGUI Other Event
  196. */
  197. struct rtgui_event_update_begin
  198. {
  199. struct rtgui_event parent;
  200. /* the update rect */
  201. rtgui_rect_t rect;
  202. };
  203. struct rtgui_event_update_end
  204. {
  205. struct rtgui_event parent;
  206. /* the update rect */
  207. rtgui_rect_t rect;
  208. };
  209. struct rtgui_event_monitor
  210. {
  211. struct rtgui_event parent;
  212. /* the monitor rect */
  213. rtgui_rect_t rect;
  214. /* under panel */
  215. rtgui_panel_t* panel;
  216. /* or under window */
  217. rtgui_win_t* wid;
  218. };
  219. struct rtgui_event_paint
  220. {
  221. struct rtgui_event parent;
  222. rtgui_win_t* wid; /* destination window */
  223. };
  224. struct rtgui_timer;
  225. struct rtgui_event_timer
  226. {
  227. struct rtgui_event parent;
  228. struct rtgui_timer *timer;
  229. };
  230. struct rtgui_event_clip_info
  231. {
  232. struct rtgui_event parent;
  233. /* destination window */
  234. rtgui_win_t* wid;
  235. /* the number of rects */
  236. rt_uint32_t num_rect;
  237. /* rtgui_rect_t *rects */
  238. };
  239. #define RTGUI_EVENT_GET_RECT(e, i) &(((rtgui_rect_t*)(e + 1))[i])
  240. #define RTGUI_EVENT_UPDATE_BEGIN_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_BEGIN)
  241. #define RTGUI_EVENT_UPDATE_END_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE_END)
  242. #define RTGUI_EVENT_MONITOR_ADD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_ADD)
  243. #define RTGUI_EVENT_MONITOR_REMOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MONITOR_REMOVE)
  244. #define RTGUI_EVENT_CLIP_INFO_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_CLIP_INFO)
  245. #define RTGUI_EVENT_PAINT_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PAINT)
  246. #define RTGUI_EVENT_TIMER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_TIMER)
  247. /*
  248. * RTGUI Mouse and Keyboard Event
  249. */
  250. struct rtgui_event_mouse
  251. {
  252. struct rtgui_event parent;
  253. rtgui_win_t* wid; /* destination window */
  254. rt_uint16_t x, y;
  255. rt_uint16_t button;
  256. };
  257. #define RTGUI_MOUSE_BUTTON_LEFT 0x01
  258. #define RTGUI_MOUSE_BUTTON_RIGHT 0x02
  259. #define RTGUI_MOUSE_BUTTON_MIDDLE 0x03
  260. #define RTGUI_MOUSE_BUTTON_WHEELUP 0x04
  261. #define RTGUI_MOUSE_BUTTON_WHEELDOWN 0x08
  262. #define RTGUI_MOUSE_BUTTON_DOWN 0x10
  263. #define RTGUI_MOUSE_BUTTON_UP 0x20
  264. struct rtgui_event_kbd
  265. {
  266. struct rtgui_event parent;
  267. rtgui_win_t* wid; /* destination window */
  268. RTGUI_KBD_TYPE type; /* key down or up */
  269. RTGUI_KBD_KEY key; /* current key */
  270. RTGUI_KBD_MOD mod; /* current key modifiers */
  271. rt_uint16_t unicode; /* translated character */
  272. };
  273. #define RTGUI_KBD_IS_SET_CTRL(e) ((e)->mod & (RTGUI_KMOD_LCTRL | RTGUI_KMOD_RCTRL)))
  274. #define RTGUI_KBD_IS_SET_ALT(e) ((e)->mod & (RTGUI_KMOD_LALT | RTGUI_KMOD_RALT))
  275. #define RTGUI_KBD_IS_SET_SHIFT(e) ((e)->mod & (RTGUI_KMOD_LSHIFT| RTGUI_KMOD_RSHIFT))
  276. #define RTGUI_KBD_IS_UP(e) ((e)->type == RTGUI_KEYUP)
  277. #define RTGUI_KBD_IS_DOWN(e) ((e)->type == RTGUI_KEYDOWN)
  278. #define RTGUI_EVENT_MOUSE_MOTION_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_MOTION)
  279. #define RTGUI_EVENT_MOUSE_BUTTON_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_BUTTON)
  280. #define RTGUI_EVENT_KBD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_KBD)
  281. struct rtgui_event_command
  282. {
  283. struct rtgui_event parent;
  284. /* command type */
  285. rt_int32_t type;
  286. /* command id */
  287. rt_int32_t command_id;
  288. /* command integer */
  289. rt_int32_t command_int;
  290. /* command string */
  291. char command_string[RTGUI_NAME_MAX];
  292. };
  293. #define RTGUI_EVENT_COMMAND_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_COMMAND)
  294. #define RTGUI_CMD_UNKNOWN 0x00
  295. #define RTGUI_CMD_WM_CLOSE 0x10
  296. #define RTGUI_CMD_USER_INT 0x20
  297. #define RTGUI_CMD_USER_STRING 0x21
  298. /************************************************************************/
  299. /* Widget Event */
  300. /************************************************************************/
  301. #define RTGUI_WIDGET_EVENT_INIT(e, t) do \
  302. { \
  303. (e)->type = (t); \
  304. (e)->sender = RT_NULL; \
  305. (e)->ack = RT_NULL; \
  306. } while (0)
  307. /*
  308. * RTGUI Scrollbar Event
  309. */
  310. struct rtgui_event_scrollbar
  311. {
  312. struct rtgui_event parent;
  313. rt_uint8_t event;
  314. };
  315. #define RTGUI_SCROLL_LINEUP 0x01
  316. #define RTGUI_SCROLL_LINEDOWN 0x02
  317. #define RTGUI_SCROLL_PAGEUP 0x03
  318. #define RTGUI_SCROLL_PAGEDOWN 0x04
  319. #define RTGUI_EVENT_SCROLLED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SCROLLED)
  320. /*
  321. * RTGUI Widget Focused Event
  322. */
  323. struct rtgui_event_focused
  324. {
  325. struct rtgui_event parent;
  326. struct rtgui_widget* widget;
  327. };
  328. #define RTGUI_EVENT_FOCUSED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_FOCUSED)
  329. /*
  330. * RTGUI Widget Resize Event
  331. */
  332. struct rtgui_event_resize
  333. {
  334. struct rtgui_event parent;
  335. rt_int16_t x, y;
  336. rt_int16_t w, h;
  337. };
  338. #define RTGUI_EVENT_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_RESIZE)
  339. #endif