event.h 11 KB

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