window.h 7.5 KB
Newer Older
1 2
/*
 * File      : window.h
3 4
 * This file is part of RT-Thread GUI Engine
 * COPYRIGHT (C) 2006 - 2017, RT-Thread Development Team
5
 *
6 7 8 9 10 11 12 13 14 15 16 17 18
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
 *
 * Change Logs:
 * Date           Author       Notes
 * 2009-10-04     Bernard      first version
 * 2010-05-03     Bernard      add win close function
 */
#ifndef __RTGUI_WINDOW_H__
#define __RTGUI_WINDOW_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <rtgui/rtgui.h>
#include <rtgui/list.h>
#include <rtgui/dc.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/box.h>

DECLARE_CLASS_TYPE(win);
/** Gets the type of a win */
#define RTGUI_WIN_TYPE       (RTGUI_TYPE(win))
/** Casts the object to an rtgui_win */
#define RTGUI_WIN(obj)       (RTGUI_OBJECT_CAST((obj), RTGUI_WIN_TYPE, rtgui_win_t))
/** Checks if the object is an rtgui_win */
#define RTGUI_IS_WIN(obj)    (RTGUI_OBJECT_CHECK_TYPE((obj), RTGUI_WIN_TYPE))

#define RTGUI_WIN_STYLE_NO_FOCUS            0x0001  /* non-focused window            */
#define RTGUI_WIN_STYLE_NO_TITLE            0x0002  /* no title window               */
#define RTGUI_WIN_STYLE_NO_BORDER           0x0004  /* no border window              */
#define RTGUI_WIN_STYLE_CLOSEBOX            0x0008  /* window has the close button   */
#define RTGUI_WIN_STYLE_MINIBOX             0x0010  /* window has the mini button    */

#define RTGUI_WIN_STYLE_DESTROY_ON_CLOSE    0x0020  /* window is destroyed when closed */
#define RTGUI_WIN_STYLE_ONTOP               0x0040  /* window is in the top layer    */
#define RTGUI_WIN_STYLE_ONBTM               0x0080  /* window is in the bottom layer */
#define RTGUI_WIN_STYLE_MAINWIN             0x0106  /* window is a main window       */

#define RTGUI_WIN_STYLE_DEFAULT     (RTGUI_WIN_STYLE_CLOSEBOX | RTGUI_WIN_STYLE_MINIBOX)

#define WINTITLE_HEIGHT         20
#define WINTITLE_CB_WIDTH       16
#define WINTITLE_CB_HEIGHT      16
#define WINTITLE_BORDER_SIZE    2

enum rtgui_win_flag
{
    RTGUI_WIN_FLAG_INIT        = 0x00,  /* init state              */
    RTGUI_WIN_FLAG_MODAL       = 0x01,  /* modal mode window       */
    RTGUI_WIN_FLAG_CLOSED      = 0x02,  /* window is closed        */
    RTGUI_WIN_FLAG_ACTIVATE    = 0x04,  /* window is activated     */
    RTGUI_WIN_FLAG_UNDER_MODAL = 0x08,  /* window is under modal
                                           show(modaled by other)  */
    RTGUI_WIN_FLAG_CONNECTED   = 0x10,  /* connected to server */
    /* window is event_key dispatcher(dispatch it to the focused widget in
     * current window) _and_ a key handler(it should be able to handle keys
     * such as ESC). Both of dispatching and handling are in the same
     * function(rtgui_win_event_handler). So we have to distinguish between the
     * two modes.
     *
     * If this flag is set, we are in key-handling mode.
     */
    RTGUI_WIN_FLAG_HANDLE_KEY  = 0x20,

    RTGUI_WIN_FLAG_CB_PRESSED  = 0x40,
};

struct rtgui_win
{
    /* inherit from container */
    rtgui_container_t parent;

Y
yangfasheng 已提交
91 92 93
	/* update count */
	rt_base_t update;

94 95
    /* drawing count */
    rt_base_t drawing;
96
    struct rtgui_rect drawing_rect;
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142

    /* parent window. RT_NULL if the window is a top level window */
    struct rtgui_win *parent_window;

    struct rtgui_region outer_clip;
    struct rtgui_rect outer_extent;

    /* the widget that will grab the focus in current window */
    struct rtgui_widget *focused_widget;

    /* which app I belong */
    struct rtgui_app *app;

    /* window style */
    rt_uint16_t style;

    /* window state flag */
    enum rtgui_win_flag flag;

    rtgui_modal_code_t modal_code;

    /* last mouse event handled widget */
    rtgui_widget_t *last_mevent_widget;

    /* window title */
    char *title;
    struct rtgui_wintitle *_title_wgt;

    /* call back */
    rt_bool_t (*on_activate)(struct rtgui_object *widget, struct rtgui_event *event);
    rt_bool_t (*on_deactivate)(struct rtgui_object *widget, struct rtgui_event *event);
    rt_bool_t (*on_close)(struct rtgui_object *widget, struct rtgui_event *event);
    /* the key is sent to the focused widget by default. If the focused widget
     * and all of it's parents didn't handle the key event, it will be handled
     * by @func on_key
     *
     * If you want to handle key event on your own, it's better to overload
     * this function other than handle EVENT_KBD in event_handler.
     */
    rt_bool_t (*on_key)(struct rtgui_object *widget, struct rtgui_event *event);

    /* reserved user data */
    void *user_data;

    /* Private data. */
    rt_base_t (*_do_show)(struct rtgui_win *win);
Y
yangfasheng 已提交
143 144 145 146 147
	
	/* app ref_count */
	rt_uint16_t app_ref_count;
	/* win magic flag, magic value is 0xA5A55A5A */
	rt_uint32_t	magic;
148 149 150 151 152 153 154 155 156
};

rtgui_win_t *rtgui_win_create(struct rtgui_win *parent_window, const char *title,
                              rtgui_rect_t *rect, rt_uint16_t style);
rtgui_win_t *rtgui_mainwin_create(struct rtgui_win *parent_window, const char *title, rt_uint16_t style);

void rtgui_win_destroy(rtgui_win_t *win);

int rtgui_win_init(struct rtgui_win *win, struct rtgui_win *parent_window,
157 158 159
                   const char *title,
                   rtgui_rect_t *rect,
                   rt_uint16_t style);
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
int rtgui_win_fini(struct rtgui_win* win);

/** Close window.
 *
 * @param win the window you want to close
 *
 * @return RT_TRUE if the window is closed. RT_FALSE if not. If the onclose
 * callback returns RT_FALSE, the window won't be closed.
 *
 * \sa rtgui_win_set_onclose .
 */
rt_bool_t rtgui_win_close(struct rtgui_win *win);

rt_base_t rtgui_win_show(struct rtgui_win *win, rt_bool_t is_modal);
rt_base_t rtgui_win_do_show(struct rtgui_win *win);
rt_base_t rtgui_win_enter_modal(struct rtgui_win *win);

void rtgui_win_hide(rtgui_win_t *win);
void rtgui_win_end_modal(rtgui_win_t *win, rtgui_modal_code_t modal_code);
rt_err_t rtgui_win_activate(struct rtgui_win *win);
rt_bool_t rtgui_win_is_activated(struct rtgui_win *win);

void rtgui_win_move(struct rtgui_win *win, int x, int y);

/* reset extent of window */
void rtgui_win_set_rect(rtgui_win_t *win, rtgui_rect_t *rect);
void rtgui_win_update_clip(struct rtgui_win *win);

void rtgui_win_set_onactivate(rtgui_win_t *win, rtgui_event_handler_ptr handler);
void rtgui_win_set_ondeactivate(rtgui_win_t *win, rtgui_event_handler_ptr handler);
void rtgui_win_set_onclose(rtgui_win_t *win, rtgui_event_handler_ptr handler);
void rtgui_win_set_onkey(rtgui_win_t *win, rtgui_event_handler_ptr handler);

rt_bool_t rtgui_win_event_handler(struct rtgui_object *win, struct rtgui_event *event);

void rtgui_win_event_loop(rtgui_win_t *wnd);

void rtgui_win_set_title(rtgui_win_t *win, const char *title);
char *rtgui_win_get_title(rtgui_win_t *win);

struct rtgui_dc *rtgui_win_get_drawing(rtgui_win_t * win);

struct rtgui_win* rtgui_win_get_topmost_shown(void);
struct rtgui_win* rtgui_win_get_next_shown(void);

205 206
void rtgui_theme_draw_win(struct rtgui_wintitle *wint);

207 208 209 210 211 212
#ifdef __cplusplus
}
#endif

#endif