event.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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/rtgui_system.h>
  18. /* Use new name & namespace */
  19. typedef struct rtgui_event rtgui_event_t;
  20. typedef struct rtgui_event_win rtgui_event_win_t;
  21. typedef struct rtgui_event_win_move rtgui_event_win_move_t;
  22. typedef struct rtgui_event_win_resize rtgui_event_win_resize_t;
  23. typedef struct rtgui_event_set_wm rtgui_event_set_wm_t;
  24. typedef struct rtgui_event_update rtgui_event_update_t;
  25. typedef struct rtgui_event_monitor rtgui_event_monitor_t;
  26. typedef struct rtgui_event_paint rtgui_event_paint_t;
  27. typedef struct rtgui_event_timer rtgui_event_timer_t;
  28. typedef struct rtgui_event_clip rtgui_event_clip_t;
  29. typedef struct rtgui_event_mouse rtgui_event_mouse_t;
  30. typedef struct rtgui_event_kbd rtgui_event_kbd_t;
  31. typedef struct rtgui_event_current_pos rtgui_event_current_pos_t;//坐标点更新事件
  32. typedef struct rtgui_event_backlight rtgui_event_backlight_t;//LCD背光
  33. typedef struct rtgui_event_command rtgui_event_command_t;
  34. typedef struct rtgui_event_scrollbar rtgui_event_scrollbar_t;
  35. typedef struct rtgui_event_focused rtgui_event_focused_t;
  36. typedef struct rtgui_event_resize rtgui_event_resize_t;
  37. /* panel event NULL */
  38. /* window event */
  39. #define RTGUI_EVENT_PANEL_ATTACH 0 /* attach to a panel */
  40. #define RTGUI_EVENT_PANEL_DETACH 1 /* detach from a panel */
  41. #define RTGUI_EVENT_PANEL_SHOW 2 /* show in a panel */
  42. #define RTGUI_EVENT_PANEL_HIDE 3 /* hide from a panel */
  43. #define RTGUI_EVENT_PANEL_INFO 4 /* panel information */
  44. #define RTGUI_EVENT_PANEL_RESIZE 5 /* resize panel */
  45. #define RTGUI_EVENT_PANEL_FULLSCREEN 6 /* to full screen */
  46. #define RTGUI_EVENT_PANEL_NORMAL 7 /* to normal screen */
  47. #define RTGUI_EVENT_WIN_CREATE 8 /* create a window */
  48. #define RTGUI_EVENT_WIN_DESTROY 9 /* destroy a window */
  49. #define RTGUI_EVENT_WIN_SHOW 10 /* show a window */
  50. #define RTGUI_EVENT_WIN_HIDE 11 /* hide a window */
  51. #define RTGUI_EVENT_WIN_ACTIVATE 12 /* activate a window */
  52. #define RTGUI_EVENT_WIN_DEACTIVATE 13 /* deactivate a window */
  53. #define RTGUI_EVENT_WIN_CLOSE 14 /* close a window */
  54. #define RTGUI_EVENT_WIN_MAX 15 /* max a window */
  55. #define RTGUI_EVENT_WIN_MIN 16 /* min a window */
  56. #define RTGUI_EVENT_WIN_MOVE 17 /* move a window */
  57. #define RTGUI_EVENT_WIN_RESIZE 18 /* resize a window */
  58. #define RTGUI_EVENT_UPDATE 19 /* update a rect */
  59. #define RTGUI_EVENT_PAINT 23 /* paint on screen */
  60. #define RTGUI_EVENT_TIMER 24 /* timer 0x17 */
  61. /* clip rect information */
  62. #define RTGUI_EVENT_CLIP 25 /* 剪切域信息 */
  63. /* mouse and keyboard event */
  64. #define RTGUI_EVENT_MOUSE_MOTION 26 /* 鼠标手势 */
  65. #define RTGUI_EVENT_MOUSE_BUTTON 27 /* 鼠标点击 */
  66. #define RTGUI_EVENT_KBD 28 /* keyboard info 0x1B*/
  67. /* user command event */
  68. #define RTGUI_EVENT_COMMAND 29 /* 用户命令 */
  69. /* widget event */
  70. #define RTGUI_EVENT_FOCUSED 30 /* 控件焦点 */
  71. #define RTGUI_EVENT_SCROLLED 31 /* scroll bar scrolled */
  72. #define RTGUI_EVENT_RESIZE 32 /* widget resize */
  73. #define RTGUI_EVENT_CURRENT_POS 33 /* 更新当前坐标点 */
  74. #define RTGUI_EVENT_BACKLIGHT 34 /* 液晶屏背光 */
  75. enum {
  76. RTGUI_STATUS_OK = 0, /* status ok */
  77. RTGUI_STATUS_ERROR, /* generic error */
  78. RTGUI_STATUS_NRC, /* no resource */
  79. };
  80. struct rtgui_event
  81. {
  82. /* the event type */
  83. rt_uint16_t type;
  84. /* user field of event */
  85. rt_uint16_t user;
  86. /* the event sender */
  87. struct rt_thread* sender;
  88. /* mailbox to acknowledge request */
  89. struct rt_mailbox* ack;
  90. };
  91. #define RTGUI_EVENT(e) ((rtgui_event_t*)(e))
  92. #define RTGUI_EVENT_INIT(e, t) do \
  93. { \
  94. (e)->type = (t); \
  95. (e)->user = 0; \
  96. (e)->sender = rt_thread_self(); \
  97. (e)->ack = RT_NULL; \
  98. } while(0)
  99. /*
  100. * RTGUI Window Event
  101. */
  102. struct rtgui_event_win
  103. {
  104. rtgui_event_t parent;
  105. /* the window id */
  106. rtgui_win_t* wid;
  107. };
  108. struct rtgui_event_win_move
  109. {
  110. rtgui_event_t parent;
  111. /* the window id */
  112. rtgui_win_t* wid;
  113. rt_int16_t x, y;
  114. };
  115. struct rtgui_event_win_resize
  116. {
  117. rtgui_event_t parent;
  118. /* the window id */
  119. rtgui_win_t* wid;
  120. rtgui_rect_t rect;
  121. };
  122. /* window event init */
  123. #define RTGUI_EVENT_WIN_CREATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CREATE)
  124. #define RTGUI_EVENT_WIN_DESTROY_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DESTROY)
  125. #define RTGUI_EVENT_WIN_SHOW_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_SHOW)
  126. #define RTGUI_EVENT_WIN_HIDE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_HIDE)
  127. #define RTGUI_EVENT_WIN_ACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_ACTIVATE)
  128. #define RTGUI_EVENT_WIN_DEACTIVATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_DEACTIVATE)
  129. #define RTGUI_EVENT_WIN_CLOSE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_CLOSE)
  130. #define RTGUI_EVENT_WIN_MAX_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MAX)
  131. #define RTGUI_EVENT_WIN_MIN_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MIN)
  132. #define RTGUI_EVENT_WIN_MOVE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_MOVE)
  133. #define RTGUI_EVENT_WIN_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_WIN_RESIZE)
  134. /*
  135. * RTGUI Other Event
  136. */
  137. struct rtgui_event_update
  138. {
  139. rtgui_event_t parent;
  140. /* the update rect */
  141. rtgui_rect_t rect;
  142. };
  143. struct rtgui_event_monitor
  144. {
  145. rtgui_event_t parent;
  146. /* the monitor rect */
  147. rtgui_rect_t rect;
  148. /* under panel */
  149. rtgui_panel_t* panel;
  150. /* or under window */
  151. rtgui_win_t* wid;
  152. };
  153. struct rtgui_event_paint
  154. {
  155. rtgui_event_t parent;
  156. rtgui_win_t* wid; /* destination window */
  157. rt_bool_t bfull;//更新全部,还是更新子控件
  158. };
  159. struct rtgui_event_timer
  160. {
  161. rtgui_event_t parent;
  162. rtgui_timer_t *timer;
  163. };
  164. struct rtgui_event_clip
  165. {
  166. rtgui_event_t parent;
  167. /* destination window */
  168. rtgui_win_t* wid;
  169. /* the number of rects */
  170. rt_uint32_t num_rect;
  171. /* rtgui_rect_t *rects */
  172. };
  173. #define RTGUI_EVENT_GET_RECT(e, i) &(((rtgui_rect_t*)(e + 1))[i])
  174. #define RTGUI_EVENT_UPDATE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_UPDATE)
  175. #define RTGUI_EVENT_CLIP_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_CLIP)
  176. #define RTGUI_EVENT_PAINT_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_PAINT)
  177. #define RTGUI_EVENT_TIMER_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_TIMER)
  178. /*
  179. * RTGUI Mouse and Keyboard Event
  180. */
  181. struct rtgui_event_mouse
  182. {
  183. rtgui_event_t parent;
  184. rtgui_win_t* wid; /* destination window */
  185. rt_uint16_t x, y;
  186. rt_uint16_t button;
  187. };
  188. #define RTGUI_MOUSE_BUTTON_RIGHT 0x01
  189. #define RTGUI_MOUSE_BUTTON_LEFT 0x02
  190. #define RTGUI_MOUSE_BUTTON_MIDDLE 0x03
  191. #define RTGUI_MOUSE_BUTTON_WHEELUP 0x04
  192. #define RTGUI_MOUSE_BUTTON_WHEELDOWN 0x08
  193. #define RTGUI_MOUSE_BUTTON_DOWN 0x10
  194. #define RTGUI_MOUSE_BUTTON_UP 0x20
  195. struct rtgui_event_kbd
  196. {
  197. rtgui_event_t parent;
  198. rtgui_win_t* wid; /* destination window */
  199. rt_uint16_t type; /* key down or up */
  200. rt_uint16_t key; /* current key */
  201. rt_uint16_t mod; /* current key modifiers */
  202. rt_uint16_t unicode; /* translated character */
  203. };
  204. struct rtgui_event_current_pos
  205. {
  206. rtgui_event_t parent;
  207. };
  208. //液晶屏背光
  209. struct rtgui_event_backlight
  210. {
  211. rtgui_event_t parent;
  212. rt_uint16_t light;
  213. };
  214. #define RTGUI_KBD_IS_SET_CTRL(e) ((e)->mod & (RTGUI_KMOD_LCTRL | RTGUI_KMOD_RCTRL))
  215. #define RTGUI_KBD_IS_SET_ALT(e) ((e)->mod & (RTGUI_KMOD_LALT | RTGUI_KMOD_RALT))
  216. #define RTGUI_KBD_IS_SET_SHIFT(e) ((e)->mod & (RTGUI_KMOD_LSHIFT| RTGUI_KMOD_RSHIFT))
  217. #define RTGUI_KBD_IS_UP(e) ((e)->type == RTGUI_KEYUP)
  218. #define RTGUI_KBD_IS_DOWN(e) ((e)->type == RTGUI_KEYDOWN)
  219. #define RTGUI_EVENT_MOUSE_MOTION_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_MOTION)
  220. #define RTGUI_EVENT_MOUSE_BUTTON_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_MOUSE_BUTTON)
  221. #define RTGUI_EVENT_KBD_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_KBD)
  222. #define RTGUI_EVENT_CURRENT_POS_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_CURRENT_POS)
  223. #define RTGUI_EVENT_BACKLIGHT_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_BACKLIGHT)
  224. struct rtgui_event_command
  225. {
  226. rtgui_event_t parent;
  227. /* command type */
  228. rt_int32_t type;
  229. /* command id */
  230. rt_int32_t command;
  231. /* command string */
  232. char command_string[RTGUI_NAME_MAX];
  233. };
  234. #define RTGUI_EVENT_COMMAND_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_COMMAND)
  235. #define RTGUI_CMD_UNKNOWN 0x00
  236. #define RTGUI_CMD_WM_CLOSE 0x10
  237. #define RTGUI_CMD_USER_INT 0x20
  238. #define RTGUI_CMD_USER_STRING 0x21
  239. /************************************************************************/
  240. /* Widget Event */
  241. /************************************************************************/
  242. #define RTGUI_WIDGET_EVENT_INIT(e, t) do \
  243. { \
  244. (e)->type = (t); \
  245. (e)->sender = RT_NULL; \
  246. (e)->ack = RT_NULL; \
  247. } while(0)
  248. /*
  249. * RTGUI Scrollbar Event
  250. */
  251. struct rtgui_event_scrollbar
  252. {
  253. rtgui_event_t parent;
  254. rt_uint8_t event;
  255. };
  256. #define RTGUI_SCROLL_LINEUP 0x01
  257. #define RTGUI_SCROLL_LINEDOWN 0x02
  258. #define RTGUI_SCROLL_PAGEUP 0x03
  259. #define RTGUI_SCROLL_PAGEDOWN 0x04
  260. #define RTGUI_EVENT_SCROLLED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_SCROLLED)
  261. /*
  262. * RTGUI Widget Focused Event
  263. */
  264. struct rtgui_event_focused
  265. {
  266. rtgui_event_t parent;
  267. rtgui_widget_t* widget;
  268. };
  269. #define RTGUI_EVENT_FOCUSED_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_FOCUSED)
  270. /*
  271. * RTGUI Widget Resize Event
  272. */
  273. struct rtgui_event_resize
  274. {
  275. rtgui_event_t parent;
  276. rt_int16_t x, y;
  277. rt_int16_t w, h;
  278. };
  279. #define RTGUI_EVENT_RESIZE_INIT(e) RTGUI_EVENT_INIT(&((e)->parent), RTGUI_EVENT_RESIZE)
  280. #endif