window.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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/box.h>
  21. DECLARE_CLASS_TYPE(win);
  22. /** Gets the type of a win */
  23. #define RTGUI_WIN_TYPE (RTGUI_TYPE(win))
  24. /** Casts the object to an rtgui_win */
  25. #define RTGUI_WIN(obj) (RTGUI_OBJECT_CAST((obj), RTGUI_WIN_TYPE, rtgui_win_t))
  26. /** Checks if the object is an rtgui_win */
  27. #define RTGUI_IS_WIN(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_WIN_TYPE))
  28. #define RTGUI_WIN_STYLE_NO_FOCUS 0x0001 /* non-focused window */
  29. #define RTGUI_WIN_STYLE_NO_TITLE 0x0002 /* no title window */
  30. #define RTGUI_WIN_STYLE_NO_BORDER 0x0004 /* no border window */
  31. #define RTGUI_WIN_STYLE_CLOSEBOX 0x0008 /* window has the close button */
  32. #define RTGUI_WIN_STYLE_MINIBOX 0x0010 /* window has the mini button */
  33. #define RTGUI_WIN_STYLE_DESTROY_ON_CLOSE 0x0020 /* window is destroyed when closed */
  34. #define RTGUI_WIN_STYLE_ONTOP 0x0040 /* window is in the top layer */
  35. #define RTGUI_WIN_STYLE_ONBTM 0x0080 /* window is in the bottom layer */
  36. #define RTGUI_WIN_STYLE_MAINWIN 0x0106 /* window is a main window */
  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 container */
  62. rtgui_container_t parent;
  63. /* drawing count */
  64. rt_base_t drawing;
  65. /* parent window. RT_NULL if the window is a top level window */
  66. struct rtgui_win *parent_window;
  67. /* the widget that will grab the focus in current window */
  68. struct rtgui_widget *focused_widget;
  69. /* which app I belong */
  70. struct rtgui_app *app;
  71. /* window style */
  72. rt_uint16_t style;
  73. /* window state flag */
  74. enum rtgui_win_flag flag;
  75. rtgui_modal_code_t modal_code;
  76. /* last mouse event handled widget */
  77. rtgui_widget_t *last_mevent_widget;
  78. /* window title */
  79. char *title;
  80. /* call back */
  81. rt_bool_t (*on_activate)(struct rtgui_object *widget, struct rtgui_event *event);
  82. rt_bool_t (*on_deactivate)(struct rtgui_object *widget, struct rtgui_event *event);
  83. rt_bool_t (*on_close)(struct rtgui_object *widget, struct rtgui_event *event);
  84. /* the key is sent to the focused widget by default. If the focused widget
  85. * and all of it's parents didn't handle the key event, it will be handled
  86. * by @func on_key
  87. *
  88. * If you want to handle key event on your own, it's better to overload
  89. * this function other than handle EVENT_KBD in event_handler.
  90. */
  91. rt_bool_t (*on_key)(struct rtgui_object *widget, struct rtgui_event *event);
  92. /* reserved user data */
  93. rt_uint32_t user_data;
  94. };
  95. rtgui_win_t *rtgui_win_create(struct rtgui_win *parent_window, const char *title,
  96. rtgui_rect_t *rect, rt_uint16_t style);
  97. rtgui_win_t *rtgui_mainwin_create(struct rtgui_win *parent_window, const char *title, rt_uint16_t style);
  98. void rtgui_win_destroy(rtgui_win_t *win);
  99. /** Close window.
  100. *
  101. * @param win the window you want to close
  102. *
  103. * @return RT_TRUE if the window is closed. RT_FALSE if not. If the onclose
  104. * callback returns RT_FALSE, the window won't be closed.
  105. *
  106. * \sa rtgui_win_set_onclose .
  107. */
  108. rt_bool_t rtgui_win_close(struct rtgui_win *win);
  109. rt_base_t rtgui_win_show(struct rtgui_win *win, rt_bool_t is_modal);
  110. void rtgui_win_hiden(rtgui_win_t *win);
  111. void rtgui_win_end_modal(rtgui_win_t *win, rtgui_modal_code_t modal_code);
  112. rt_err_t rtgui_win_activate(struct rtgui_win *win);
  113. rt_bool_t rtgui_win_is_activated(struct rtgui_win *win);
  114. void rtgui_win_move(struct rtgui_win *win, int x, int y);
  115. /* reset extent of window */
  116. void rtgui_win_set_rect(rtgui_win_t *win, rtgui_rect_t *rect);
  117. void rtgui_win_update_clip(struct rtgui_win *win);
  118. void rtgui_win_set_onactivate(rtgui_win_t *win, rtgui_event_handler_ptr handler);
  119. void rtgui_win_set_ondeactivate(rtgui_win_t *win, rtgui_event_handler_ptr handler);
  120. void rtgui_win_set_onclose(rtgui_win_t *win, rtgui_event_handler_ptr handler);
  121. void rtgui_win_set_onkey(rtgui_win_t *win, rtgui_event_handler_ptr handler);
  122. rt_bool_t rtgui_win_event_handler(struct rtgui_object *win, struct rtgui_event *event);
  123. void rtgui_win_event_loop(rtgui_win_t *wnd);
  124. void rtgui_win_set_title(rtgui_win_t *win, const char *title);
  125. char *rtgui_win_get_title(rtgui_win_t *win);
  126. #endif