widget.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * File : widget.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_WIDGET_H__
  15. #define __RTGUI_WIDGET_H__
  16. #include <rtgui/rtgui.h>
  17. #include <rtgui/color.h>
  18. #include <rtgui/font.h>
  19. #include <rtgui/list.h>
  20. #include <rtgui/region.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. typedef struct rtgui_widget rtgui_widget_t;
  25. /** Gets the type of a widget */
  26. #define RTGUI_WIDGET_TYPE (rtgui_widget_type_get())
  27. /** Casts the object to a rtgui_widget */
  28. #define RTGUI_WIDGET(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_WIDGET_TYPE, rtgui_widget_t))
  29. /** Check if the object is a rtgui_widget */
  30. #define RTGUI_IS_WIDGET(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_WIDGET_TYPE))
  31. /*
  32. * the base widget object
  33. */
  34. struct rtgui_widget
  35. {
  36. rtgui_object_t object; /* inherit from rtgui_object_t */
  37. rtgui_widget_t *parent, *toplevel; /* the parent and root widget */
  38. rtgui_list_t sibling; /* the widget child and sibling */
  39. rt_uint32_t flag; /* widget flag */
  40. rt_uint32_t dc_type; /* hardware device context */
  41. const struct rtgui_dc_engine* dc_engine;
  42. rtgui_gc_t gc; /* the graphic context of widget */
  43. rt_uint16_t tab_index; /* table detect order */
  44. rt_uint16_t tab_stop;
  45. rtgui_rect_t extent; /* the widget extent */
  46. rt_uint32_t align; /* widget align */
  47. rt_uint16_t border,border_style;
  48. rtgui_region_t clip; /* the rect clip */
  49. rt_bool_t (*event_handler)(PVOID wdt, rtgui_event_t* event);/* the event handler */
  50. rt_bool_t (*on_focus_in)(PVOID wdt, rtgui_event_t* event);/* call back */
  51. rt_bool_t (*on_focus_out)(PVOID wdt, rtgui_event_t* event);
  52. rt_bool_t (*on_draw)(PVOID wdt, rtgui_event_t* event);
  53. rt_bool_t (*on_mouseclick)(PVOID wdt, rtgui_event_t* event);
  54. rt_bool_t (*on_key)(PVOID wdt, rtgui_event_t* event);
  55. rt_bool_t (*on_size)(PVOID wdt, rtgui_event_t* event);
  56. rt_bool_t (*on_command)(PVOID wdt, rtgui_event_t* event);
  57. rt_uint32_t user_data; /* reserved user data */
  58. };
  59. #define RTGUI_WIDGET_FOREGROUND(w) (RTGUI_WIDGET(w))->gc.foreground
  60. #define RTGUI_WIDGET_BACKGROUND(w) (RTGUI_WIDGET(w))->gc.background
  61. #define RTGUI_WIDGET_FONT(w) (RTGUI_WIDGET(w))->gc.font
  62. #define RTGUI_WIDGET_TEXTALIGN(w) (RTGUI_WIDGET(w))->gc.textalign
  63. #define RTGUI_WIDGET_FLAG(w) (RTGUI_WIDGET(w))->flag
  64. #define RTGUI_WIDGET_ALIGN(w) (RTGUI_WIDGET(w))->align
  65. #define RTGUI_WIDGET_EVENT_HANDLE(w) (RTGUI_WIDGET(w))->event_handler
  66. #define RTGUI_WIDGET_EVENT_CALL(w,e) (RTGUI_WIDGET(w))->event_handler(w,e)
  67. #define RTGUI_WIDGET_PARENT(w) (RTGUI_WIDGET(w))->parent
  68. #define RTGUI_WIDGET_EXTENT(w) (RTGUI_WIDGET(w))->extent
  69. #define RTGUI_WIDGET_BORDER(w) (RTGUI_WIDGET(w))->border
  70. #define RTGUI_WIDGET_BORDER_STYLE(w) (RTGUI_WIDGET(w))->border_style
  71. #define RTGUI_WIDGET_CLIP(w) (RTGUI_WIDGET(w))->clip
  72. #define RTGUI_WIDGET_FLAG_DEFAULT 0x0000 //默认
  73. #define RTGUI_WIDGET_FLAG_HIDE 0x0001 //隐藏的
  74. #define RTGUI_WIDGET_FLAG_DISABLE 0x0002 //无效的
  75. #define RTGUI_WIDGET_FLAG_FOCUS 0x0004 //焦点的
  76. #define RTGUI_WIDGET_FLAG_TRANSPARENT 0x0008 //透明的
  77. #define RTGUI_WIDGET_FLAG_FOCUSABLE 0x0010 //可获得焦点的
  78. #define RTGUI_WIDGET_FLAG_DC_VISIBLE 0x0100
  79. #define RTGUI_WIDGET_UNHIDE(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_HIDE
  80. #define RTGUI_WIDGET_HIDE(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_HIDE
  81. #define RTGUI_WIDGET_IS_HIDE(w) (RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_HIDE)
  82. #define RTGUI_WIDGET_ENABLE(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_DISABLE
  83. #define RTGUI_WIDGET_DISABLE(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_DISABLE
  84. #define RTGUI_WIDGET_IS_ENABLE(w) !(RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_DISABLE)
  85. #define RTGUI_WIDGET_UNFOCUS(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_FOCUS
  86. #define RTGUI_WIDGET_FOCUS(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_FOCUS
  87. #define RTGUI_WIDGET_IS_FOCUSED(w) (RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_FOCUS)
  88. #define RTGUI_WIDGET_IS_FOCUSABLE(w) (RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_FOCUSABLE)
  89. #define RTGUI_WIDGET_IS_DC_VISIBLE(w) (RTGUI_WIDGET_FLAG(w) & RTGUI_WIDGET_FLAG_DC_VISIBLE)
  90. #define RTGUI_WIDGET_DC_SET_VISIBLE(w) RTGUI_WIDGET_FLAG(w) |= RTGUI_WIDGET_FLAG_DC_VISIBLE
  91. #define RTGUI_WIDGET_DC_SET_UNVISIBLE(w) RTGUI_WIDGET_FLAG(w) &= ~RTGUI_WIDGET_FLAG_DC_VISIBLE
  92. #define RTGUI_WIDGET_DC(w) ((rtgui_dc_t*)&(RTGUI_WIDGET(w)->dc_type))
  93. rtgui_type_t *rtgui_widget_type_get(void);
  94. PVOID rtgui_widget_create(rtgui_type_t *widget_type);
  95. void rtgui_widget_destroy(PVOID wdt);
  96. /* set the event handler of widget */
  97. void rtgui_widget_set_event_handler(PVOID wdt, rtgui_event_handler_ptr handler);
  98. /* widget default event handler */
  99. rt_bool_t rtgui_widget_event_handler(PVOID wdt, rtgui_event_t* event);
  100. /* focus and unfocus */
  101. PVOID rtgui_widget_get_focus(PVOID wdt);
  102. void rtgui_widget_focus(PVOID wdt);
  103. void rtgui_widget_unfocus(PVOID wdt);
  104. /* event handler for each command */
  105. void rtgui_widget_set_onfocus(PVOID wdt, rtgui_event_handler_ptr handler);
  106. void rtgui_widget_set_onunfocus(PVOID wdt, rtgui_event_handler_ptr handler);
  107. void rtgui_widget_set_ondraw(PVOID wdt, rtgui_event_handler_ptr handler);
  108. void rtgui_widget_set_onmouseclick(PVOID wdt, rtgui_event_handler_ptr handler);
  109. void rtgui_widget_set_onkey(PVOID wdt, rtgui_event_handler_ptr handler);
  110. void rtgui_widget_set_onsize(PVOID wdt, rtgui_event_handler_ptr handler);
  111. void rtgui_widget_set_oncommand(PVOID wdt, rtgui_event_handler_ptr handler);
  112. void rtgui_widget_get_rect(PVOID wdt, rtgui_rect_t *rect);/* get and set rect of widget */
  113. void rtgui_widget_set_rect(PVOID wdt, rtgui_rect_t* rect);
  114. void rtgui_widget_get_position(PVOID wdt, rtgui_point_t *p);
  115. rt_uint16_t rtgui_widget_get_width(PVOID wdt);
  116. rt_uint16_t rtgui_widget_get_height(PVOID wdt);
  117. void rtgui_widget_set_style(PVOID wdt, rt_uint32_t style);
  118. void rtgui_widget_point_to_device(PVOID wdt, rtgui_point_t *point);/* get the physical position of a logic point on widget */
  119. void rtgui_widget_rect_to_device(PVOID wdt, rtgui_rect_t *rect);/* get the physical position of a logic rect on widget */
  120. void rtgui_widget_point_to_logic(PVOID wdt, rtgui_point_t *point);/* get the logic position of a physical point on widget */
  121. void rtgui_widget_rect_to_logic(PVOID wdt, rtgui_rect_t *rect);/* get the logic position of a physical rect on widget */
  122. void rtgui_widget_move_to_logic(PVOID wdt, int dx, int dy);/* move widget and its child to a logic point */
  123. /* update the clip info of widget */
  124. void rtgui_widget_update_clip(PVOID wdt);
  125. void rtgui_widget_update_clip_pirate(PVOID wdt,PVOID topwdt);
  126. PVOID rtgui_widget_get_toplevel(PVOID wdt); /* get the toplevel widget of widget */
  127. void rtgui_widget_show(PVOID wdt);
  128. void rtgui_widget_hide(PVOID wdt);
  129. void rtgui_widget_update(PVOID wdt);
  130. /* get parent color */
  131. rtgui_color_t rtgui_widget_get_parent_foreground(PVOID wdt);
  132. rtgui_color_t rtgui_widget_get_parent_background(PVOID wdt);
  133. /* get the next sibling of widget */
  134. rtgui_widget_t* rtgui_widget_get_next_sibling(PVOID wdt);
  135. /* get the prev sibling of widget */
  136. rtgui_widget_t* rtgui_widget_get_prev_sibling(PVOID wdt);
  137. #ifdef __cplusplus
  138. }
  139. #endif
  140. #endif