Esempio n. 1
0
void rtgui_win_destroy(struct rtgui_win* win)
{
	/* close the window first if it's not. */
	if (!(win->flag & RTGUI_WIN_FLAG_CLOSED))
	{
		struct rtgui_event_win_close eclose;

		RTGUI_EVENT_WIN_CLOSE_INIT(&eclose);
		eclose.wid = win;

		if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
		{
			_rtgui_win_deal_close(win,
					(struct rtgui_event*)&eclose,
					RT_TRUE);
			return;
		}
		else
			_rtgui_win_deal_close(win,
					(struct rtgui_event*)&eclose,
					RT_TRUE);
	}

	if (win->flag & RTGUI_WIN_FLAG_MODAL)
	{
		/* set the RTGUI_WIN_STYLE_DESTROY_ON_CLOSE flag so the window will be
		 * destroyed after the event_loop */
		win->style |= RTGUI_WIN_STYLE_DESTROY_ON_CLOSE;
		rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
	}
	else
	{
		rtgui_widget_destroy(RTGUI_WIDGET(win));
	}
}
Esempio n. 2
0
/* send a close event to myself to get a consistent behavior */
rt_bool_t rtgui_win_close(struct rtgui_win* win)
{
    struct rtgui_event_win_close eclose;

    RTGUI_EVENT_WIN_CLOSE_INIT(&eclose);
    eclose.wid = win;
    return _rtgui_win_deal_close(win,
                                 (struct rtgui_event*)&eclose);
}
Esempio n. 3
0
rt_bool_t rtgui_win_event_handler(struct rtgui_object* object, struct rtgui_event* event)
{
    struct rtgui_win* win;

    RT_ASSERT(object != RT_NULL);
    RT_ASSERT(event != RT_NULL);

    win = RTGUI_WIN(object);

    switch (event->type)
    {
    case RTGUI_EVENT_WIN_SHOW:
        rtgui_win_show(win, RT_FALSE);
        break;

    case RTGUI_EVENT_WIN_HIDE:
        rtgui_win_hiden(win);
        break;

    case RTGUI_EVENT_WIN_CLOSE:
        _rtgui_win_deal_close(win, event);
        /* don't broadcast WIN_CLOSE event to others */
        return RT_TRUE;

    case RTGUI_EVENT_WIN_MOVE:
    {
        struct rtgui_event_win_move* emove = (struct rtgui_event_win_move*)event;

        /* move window */
        rtgui_win_move(win, emove->x, emove->y);
    }
    break;

    case RTGUI_EVENT_WIN_ACTIVATE:
        if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)))
        {
            /* activate a hide window */
            return RT_TRUE;
        }

        win->flag |= RTGUI_WIN_FLAG_ACTIVATE;
#ifndef RTGUI_USING_SMALL_SIZE
        if (RTGUI_WIDGET(object)->on_draw != RT_NULL)
            RTGUI_WIDGET(object)->on_draw(object, event);
        else
#endif
            rtgui_widget_update(RTGUI_WIDGET(win));

        if (win->on_activate != RT_NULL)
        {
            win->on_activate(RTGUI_OBJECT(object), event);
        }
        break;

    case RTGUI_EVENT_WIN_DEACTIVATE:
        if (win->flag & RTGUI_WIN_FLAG_MODAL)
        {
            /* FIXME: make modal concept clear and easy. See the comment of
             * rtgui_topwin_modal_enter. */
            /* There are various reason that a modal window got deactivated:
             *     1, it has child windows and the user activate one of them.
             *     2, the application has more than one root window and the
             *     user switched to one of the others.
             *
             * In any of the cases, we have nothing to do here.
             */
        }
        else
        {
            win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
#ifndef RTGUI_USING_SMALL_SIZE
            if (RTGUI_WIDGET(object)->on_draw != RT_NULL)
                RTGUI_WIDGET(object)->on_draw(object, event);
            else
#endif
                rtgui_widget_update(RTGUI_WIDGET(win));

            if (win->on_deactivate != RT_NULL)
            {
                win->on_deactivate(RTGUI_OBJECT(object), event);
            }
        }
        break;

    case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
        if (RTGUI_WIDGET(object)->on_draw != RT_NULL)
            RTGUI_WIDGET(object)->on_draw(object, event);
        else
#endif
            rtgui_win_ondraw(win);
        break;

    case RTGUI_EVENT_MOUSE_BUTTON:
        /* check whether has widget which handled mouse event before */
        if (win->last_mevent_widget != RT_NULL)
        {
            RTGUI_OBJECT(win->last_mevent_widget)->event_handler(
                RTGUI_OBJECT(win->last_mevent_widget),
                event);

            /* clean last mouse event handled widget */
            win->last_mevent_widget = RT_NULL;
        }
        else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win),
                 (struct rtgui_event_mouse*)event) == RT_FALSE)
        {
#ifndef RTGUI_USING_SMALL_SIZE
            if (RTGUI_WIDGET(object)->on_mouseclick != RT_NULL)
            {
                return RTGUI_WIDGET(object)->on_mouseclick(object, event);
            }
#endif
        }
        break;

    case RTGUI_EVENT_MOUSE_MOTION:
#if 0
        if (rtgui_widget_dispatch_mouse_event(widget,
                                              (struct rtgui_event_mouse*)event) == RT_FALSE)
        {
#ifndef RTGUI_USING_SMALL_SIZE
            /* handle event in current widget */
            if (widget->on_mousemotion != RT_NULL)
            {
                return widget->on_mousemotion(widget, event);
            }
#endif
        }
        else return RT_TRUE;
#endif
        break;

    case RTGUI_EVENT_KBD:
        /* we should dispatch key event firstly */
        if (!(win->flag & RTGUI_WIN_FLAG_HANDLE_KEY))
        {
            rt_bool_t res = RT_FALSE;
            /* we should dispatch the key event just once. Once entered the
             * dispatch mode, we should swtich to key handling mode. */
            win->flag |= RTGUI_WIN_FLAG_HANDLE_KEY;

            /* dispatch the key event */
            if (win->focused_widget != RT_NULL &&
                    RTGUI_OBJECT(win->focused_widget)->event_handler != RT_NULL)
                res = RTGUI_OBJECT(win->focused_widget)->event_handler(
                          RTGUI_OBJECT(win->focused_widget), event);

            /* if the focused widget doesn't handle it, I will handle it. */
            if (res != RT_TRUE && win->on_key != RT_NULL)
                res = win->on_key(RTGUI_OBJECT(win), event);

            win->flag &= ~RTGUI_WIN_FLAG_HANDLE_KEY;
            return res;
        }
        else
        {
            /* in key handling mode(it may reach here in
             * win->focused_widget->event_handler call) */
            if (win->on_key != RT_NULL)
                return win->on_key(RTGUI_OBJECT(win), event);
        }
        break;

    default:
        /* call parent event handler */
        return rtgui_toplevel_event_handler(object, event);
    }

    return RT_FALSE;
}