Beispiel #1
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;
}
Beispiel #2
0
rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	struct rtgui_win* win = (struct rtgui_win*)widget;

	RT_ASSERT((win != RT_NULL) && (event != RT_NULL));

	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:
		if (win->on_close != RT_NULL)
		{
			if (win->on_close(widget, event) == RT_FALSE) return RT_TRUE;
		}

		if (win->style & RTGUI_WIN_STYLE_MODAL)
		{
			rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
		}
		else
		{
			/* destroy window */
			rtgui_win_destroy(win);
		}

		/* exit event loop */
		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->style |= RTGUI_WIN_STYLE_ACTIVATE;
#ifndef RTGUI_USING_SMALL_SIZE
		if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
		else 
#endif
		rtgui_widget_update(RTGUI_WIDGET(win));

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

	case RTGUI_EVENT_WIN_DEACTIVATE:
		if (win->style & RTGUI_WIN_STYLE_MODAL)
		{
			/* do not deactivate a modal win, re-send win-show event */
			struct rtgui_event_win_show eshow;
			RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
			eshow.wid = win;

			rtgui_thread_send(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow),
				sizeof(struct rtgui_event_win_show));
		}
		else
		{
			win->style &= ~RTGUI_WIN_STYLE_ACTIVATE;
#ifndef RTGUI_USING_SMALL_SIZE
			if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
			else 
#endif
				rtgui_win_ondraw(win);

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

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

	case RTGUI_EVENT_MOUSE_BUTTON:
		if (win->style & RTGUI_WIN_STYLE_UNDER_MODAL)
		{
			if (win->modal_widget != RT_NULL)
				return win->modal_widget->event_handler(win->modal_widget, event);
		}
 		else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win), 
			(struct rtgui_event_mouse*)event) == RT_FALSE)
		{
#ifndef RTGUI_USING_SMALL_SIZE
			if (widget->on_mouseclick != RT_NULL)
			{
				return widget->on_mouseclick(widget, 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:
		if (win->style & RTGUI_WIN_STYLE_UNDER_MODAL)
		{
			if (win->modal_widget != RT_NULL)
				return win->modal_widget->event_handler(win->modal_widget, event);
		}
		else if (RTGUI_CONTAINER(win)->focused != widget)
		{
			RTGUI_CONTAINER(win)->focused->event_handler(RTGUI_CONTAINER(win)->focused, event);
		}
        break;

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

	return RT_FALSE;
}