window.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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/list.h>
  19. #include <rtgui/widgets/widget.h>
  20. #include <rtgui/widgets/toplevel.h>
  21. #include <rtgui/widgets/box.h>
  22. DECLARE_CLASS_TYPE(win);
  23. /** Gets the type of a win */
  24. #define RTGUI_WIN_TYPE (RTGUI_TYPE(win))
  25. /** Casts the object to an rtgui_win */
  26. #define RTGUI_WIN(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_WIN_TYPE, rtgui_win_t))
  27. /** Checks if the object is an rtgui_win */
  28. #define RTGUI_IS_WIN(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_WIN_TYPE))
  29. #define RTGUI_WIN_STYLE_NO_FOCUS 0x001 /* non-focused window */
  30. #define RTGUI_WIN_STYLE_NO_TITLE 0x002 /* no title window */
  31. #define RTGUI_WIN_STYLE_NO_BORDER 0x004 /* no border window */
  32. #define RTGUI_WIN_STYLE_CLOSEBOX 0x008 /* window has the close button */
  33. #define RTGUI_WIN_STYLE_MINIBOX 0x010 /* window has the mini button */
  34. #define RTGUI_WIN_STYLE_DESTROY_ON_CLOSE 0x020 /* window is destroyed when closed */
  35. #define RTGUI_WIN_STYLE_ONTOP 0x040 /* window is in the top layer */
  36. #define RTGUI_WIN_STYLE_ONBTM 0x080 /* window is in the bottom layer */
  37. #define RTGUI_WIN_STYLE_DEFAULT (RTGUI_WIN_STYLE_CLOSEBOX | RTGUI_WIN_STYLE_MINIBOX)
  38. enum rtgui_win_flag
  39. {
  40. RTGUI_WIN_FLAG_INIT = 0x00, /* init state */
  41. RTGUI_WIN_FLAG_MODAL = 0x01, /* modal mode window */
  42. RTGUI_WIN_FLAG_CLOSED = 0x02, /* window is closed */
  43. RTGUI_WIN_FLAG_ACTIVATE = 0x04, /* window is activated */
  44. RTGUI_WIN_FLAG_UNDER_MODAL = 0x08, /* window is under modal
  45. show(modaled by other) */
  46. RTGUI_WIN_FLAG_CONNECTED = 0x10, /* connected to server */
  47. /* window is event_key dispatcher(dispatch it to the focused widget in
  48. * current window) _and_ a key handler(it should be able to handle keys
  49. * such as ESC). Both of dispatching and handling are in the same
  50. * function(rtgui_win_event_handler). So we have to distinguish between the
  51. * two modes.
  52. *
  53. * If this flag is set, we are in key-handling mode.
  54. */
  55. RTGUI_WIN_FLAG_HANDLE_KEY = 0x20
  56. };
  57. struct rtgui_win_title;
  58. struct rtgui_win_area;
  59. struct rtgui_win
  60. {
  61. /* inherit from toplevel */
  62. struct rtgui_toplevel parent;
  63. /* parent window. RT_NULL if the window is a top level window */
  64. struct rtgui_win *parent_window;
  65. /* the widget that will grab the focus in current window */
  66. struct rtgui_widget *focused_widget;
  67. /* window style */
  68. rt_uint16_t style;
  69. /* window state flag */
  70. enum rtgui_win_flag flag;
  71. rtgui_modal_code_t modal_code;
  72. /* last mouse event handled widget */
  73. rtgui_widget_t* last_mevent_widget;
  74. /* window title */
  75. char* title;
  76. /* call back */
  77. rt_bool_t (*on_activate) (struct rtgui_object* widget, struct rtgui_event* event);
  78. rt_bool_t (*on_deactivate) (struct rtgui_object* widget, struct rtgui_event* event);
  79. rt_bool_t (*on_close) (struct rtgui_object* widget, struct rtgui_event* event);
  80. /* the key is sent to the focused widget by default. If the focused widget
  81. * and all of it's parents didn't handle the key event, it will be handled
  82. * by @func on_key
  83. *
  84. * If you want to handle key event on your own, it's better to overload
  85. * this function other than handle EVENT_KBD in event_handler.
  86. */
  87. rt_bool_t (*on_key) (struct rtgui_object* widget, struct rtgui_event* event);
  88. /* reserved user data */
  89. rt_uint32_t user_data;
  90. };
  91. rtgui_win_t* rtgui_win_create(struct rtgui_win *parent_window, const char* title,
  92. rtgui_rect_t *rect, rt_uint16_t style);
  93. void rtgui_win_destroy(rtgui_win_t* win);
  94. /** Close window.
  95. *
  96. * @param win the window you want to close
  97. *
  98. * @return RT_TRUE if the window is closed. RT_FALSE if not. If the onclose
  99. * callback returns RT_FALSE, the window won't be closed.
  100. *
  101. * \sa rtgui_win_set_onclose .
  102. */
  103. rt_bool_t rtgui_win_close(struct rtgui_win* win);
  104. rt_base_t rtgui_win_show(struct rtgui_win *win, rt_bool_t is_modal);
  105. void rtgui_win_hiden(rtgui_win_t* win);
  106. void rtgui_win_end_modal(rtgui_win_t* win, rtgui_modal_code_t modal_code);
  107. rt_err_t rtgui_win_activate(struct rtgui_win *win);
  108. rt_bool_t rtgui_win_is_activated(struct rtgui_win* win);
  109. void rtgui_win_move(struct rtgui_win* win, int x, int y);
  110. /* reset extent of window */
  111. void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect);
  112. #ifndef RTGUI_USING_SMALL_SIZE
  113. void rtgui_win_set_box(rtgui_win_t* win, rtgui_box_t* box);
  114. #endif
  115. void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler);
  116. void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler);
  117. void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler);
  118. void rtgui_win_set_onkey(rtgui_win_t* win, rtgui_event_handler_ptr handler);
  119. rt_bool_t rtgui_win_event_handler(struct rtgui_object* win, struct rtgui_event* event);
  120. void rtgui_win_event_loop(rtgui_win_t* wnd);
  121. void rtgui_win_set_title(rtgui_win_t* win, const char *title);
  122. char* rtgui_win_get_title(rtgui_win_t* win);
  123. #endif