window.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * File : window.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. * 2010-05-03 Bernard add win close function
  14. */
  15. #ifndef __RTGUI_WINDOW_H__
  16. #define __RTGUI_WINDOW_H__
  17. #include <rtgui/rtgui.h>
  18. #include <rtgui/widgets/container.h>
  19. /** Gets the type of a win */
  20. #define RTGUI_WIN_TYPE (rtgui_win_type_get())
  21. /** Casts the object to an rtgui_win_t */
  22. #define RTGUI_WIN(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_WIN_TYPE, rtgui_win_t))
  23. /** Checks if the object is an rtgui_win_t */
  24. #define RTGUI_IS_WIN(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_WIN_TYPE))
  25. #define RTGUI_WIN_CLOSEBOX_WIDTH 16
  26. #define RTGUI_WIN_CLOSEBOX_HEIGHT 16
  27. #define RTGUI_WIN_TITLE_HEIGHT 20 //标题栏高度
  28. #define RTGUI_WIN_STATUS_HEIGHT 20 //状态栏高度
  29. #define RTGUI_WIN_MENU_HEIGHT 20 //菜单栏高度
  30. //窗口的状态
  31. #define RTGUI_WIN_STATUS_MODAL (1ul << 0) //模式窗口
  32. #define RTGUI_WIN_STATUS_MIN (1ul << 1)
  33. #define RTGUI_WIN_STATUS_MAX (1ul << 2) //窗口处于最大化状态
  34. #define RTGUI_WIN_STATUS_CLOSED (1ul << 3) //关闭的
  35. #define RTGUI_WIN_STATUS_ACTIVATE (1ul << 4) //活动的
  36. #define RTGUI_WIN_STATUS_FOCUS (1ul << 5) //获得焦点的
  37. #define RTGUI_WIN_IS_MODAL_MODE(w) (w->status & RTGUI_WIN_STATUS_MODAL)
  38. //窗口的样式,属性
  39. #define RTGUI_WIN_TITLE (1ul << 1) //标题栏
  40. #define RTGUI_WIN_STATUS (1ul << 2) //状态栏
  41. #define RTGUI_WIN_MENU (1ul << 3) //菜单栏
  42. #define RTGUI_WIN_BORDER (1ul << 4) //边框
  43. #define RTGUI_WIN_MINBOX (1ul << 5) //最小化按钮
  44. #define RTGUI_WIN_MAXBOX (1ul << 6) //最大化按钮
  45. #define RTGUI_WIN_CLOSEBOX (1ul << 7) //关闭按钮
  46. #define RTGUI_WIN_MINBOX_PRESSED (1ul << 8)
  47. #define RTGUI_WIN_MAXBOX_PRESSED (1ul << 9)
  48. #define RTGUI_WIN_CLOSEBOX_PRESSED (1ul << 10) //关闭按钮被按下
  49. #define RTGUI_WIN_NOTITLE (0)
  50. #define RTGUI_WIN_DEFAULT (RTGUI_WIN_BORDER|RTGUI_WIN_TITLE|RTGUI_WIN_CLOSEBOX)
  51. #define RTGUI_WIN_DIALOG (RTGUI_WIN_BORDER|RTGUI_WIN_TITLE|RTGUI_WIN_CLOSEBOX|RTGUI_WIN_MINBOX)
  52. #define RTGUI_WIN_NORMAL (RTGUI_WIN_BORDER|RTGUI_WIN_TITLE|RTGUI_WIN_CLOSEBOX|RTGUI_WIN_MINBOX|RTGUI_WIN_MAXBOX)
  53. struct rtgui_win_title;
  54. struct rtgui_win_area;
  55. struct rtgui_win
  56. {
  57. /* inherit from top */
  58. rtgui_container_t parent;
  59. /* window title */
  60. char* title;
  61. /* parent top */
  62. PVOID modal_widget;
  63. rtgui_list_t list; /* window list */
  64. /* the thread id */
  65. struct rt_thread* tid; //所在线程
  66. rt_uint32_t style; //窗口的样式
  67. rt_uint32_t status; //窗口的状态
  68. rt_uint16_t title_height; //标题栏高度
  69. rt_uint16_t status_height; //状态栏高度
  70. rt_uint16_t menu_height; //菜单栏高度
  71. rt_uint16_t border_size; //窗体边框宽度
  72. /* call back */
  73. rt_bool_t (*on_activate)(PVOID wdt, rtgui_event_t* event);
  74. rt_bool_t (*on_deactivate)(PVOID wdt, rtgui_event_t* event);
  75. rt_bool_t (*on_close)(PVOID wdt, rtgui_event_t* event);
  76. /* reserved user data */
  77. void* user_data;
  78. };
  79. rtgui_type_t *rtgui_win_type_get(void);
  80. rtgui_win_t* rtgui_win_create(PVOID parent, const char* title, rtgui_rect_t *rect, rt_uint32_t flag);
  81. void rtgui_win_destroy(rtgui_win_t* win);
  82. rtgui_win_t* rtgui_win_get_win_by_widget(PVOID wdt);
  83. void rtgui_win_close(PVOID wdt, rtgui_event_t *event);
  84. rt_bool_t rtgui_win_ondraw(rtgui_win_t* win);
  85. void rtgui_win_show(rtgui_win_t* win, rt_bool_t modal);
  86. void rtgui_win_hiden(rtgui_win_t* win);
  87. void rtgui_win_end_modal(rtgui_win_t* win);
  88. rt_bool_t rtgui_win_is_activated(rtgui_win_t* win);
  89. void rtgui_win_move(rtgui_win_t* win, int x, int y);
  90. /* reset extent of window */
  91. void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect);
  92. void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler);
  93. void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler);
  94. void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler);
  95. rt_bool_t rtgui_win_event_handler(PVOID wdt, rtgui_event_t* event);
  96. void rtgui_win_event_loop(rtgui_win_t* win);
  97. void rtgui_win_set_title(rtgui_win_t* win, const char *title);
  98. char* rtgui_win_get_title(rtgui_win_t* win);
  99. rtgui_point_t rtgui_win_get_client_zero(rtgui_win_t *win);
  100. void rtgui_win_get_client_rect(rtgui_win_t *win, rtgui_rect_t *rect);
  101. void rtgui_win_get_title_rect(rtgui_win_t *win, rtgui_rect_t *rect);
  102. void rtgui_win_get_closebox_rect(rtgui_win_t *win, rtgui_rect_t *rect);
  103. void rtgui_win_get_maxbox_rect(rtgui_win_t *win, rtgui_rect_t *rect);
  104. void rtgui_win_get_minbox_rect(rtgui_win_t *win, rtgui_rect_t *rect);
  105. #endif