Example #1
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;
}
Example #2
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;
}
Example #3
0
rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
{
	struct rtgui_workbench* workbench = (struct rtgui_workbench*)widget;

	switch (event->type)
	{
	case RTGUI_EVENT_PANEL_DETACH:
		RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench));
		RTGUI_TOPLEVEL(workbench)->server = RT_NULL;
		return RT_TRUE;

	case RTGUI_EVENT_PANEL_SHOW:
		/* show workbench in server */
		rtgui_workbench_show(workbench);
		break;

	case RTGUI_EVENT_PANEL_HIDE:
		/* hide widget */
		RTGUI_WIDGET_HIDE(widget);
		break;

	case RTGUI_EVENT_MOUSE_MOTION:
		{
			struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(emouse->wid);

			/* check the destination window */
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
			else
			{
				/* let viewer to handle it */
				rtgui_view_t* view = workbench->current_view;
				if (view != RT_NULL &&
					RTGUI_WIDGET(view)->event_handler != RT_NULL)
				{
					RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
				}
			}
		}
		break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		{
			struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(emouse->wid);

			/* check the destination window */
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
			else
			{
				if (RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
				{
					/* let modal widget to handle it */
					if (workbench->modal_widget != RT_NULL &&
							workbench->modal_widget->event_handler != RT_NULL)
					{
						workbench->modal_widget->event_handler(workbench->modal_widget, event);
					}
				}
				else
				{
					/* let viewer to handle it */
					rtgui_view_t* view = workbench->current_view;
					if (view != RT_NULL &&
							RTGUI_WIDGET(view)->event_handler != RT_NULL)
					{
						RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
					}
				}
			}
		}
		break;

	case RTGUI_EVENT_KBD:
		{
			struct rtgui_event_kbd* kbd = (struct rtgui_event_kbd*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(kbd->wid);

			/* check the destination window */
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
			else
			{
				if (RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
				{
					/* let modal widget to handle it */
					if (workbench->modal_widget != RT_NULL &&
							workbench->modal_widget->event_handler != RT_NULL)
					{
						workbench->modal_widget->event_handler(workbench->modal_widget, event);
					}
				}
				else
				{
					if (RTGUI_CONTAINER(widget)->focused == widget)
					{
						/* set focused widget to the current view */
						if (workbench->current_view != RT_NULL)
							rtgui_widget_focus(RTGUI_WIDGET(RTGUI_CONTAINER(workbench->current_view)->focused));
					}

					return rtgui_toplevel_event_handler(widget, event);
				}
			}
		}
		break;

	case RTGUI_EVENT_PAINT:
		{
			struct rtgui_event_paint* epaint = (struct rtgui_event_paint*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(epaint->wid);

			/* check the destination window */
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
			else
			{
				rtgui_view_t* view;

				/* un-hide workbench */
				RTGUI_WIDGET_UNHIDE(widget);

				/* paint a view */
				view = workbench->current_view;
				if (view != RT_NULL)
				{
					/* remake a paint event */
					RTGUI_EVENT_PAINT_INIT(epaint);
					epaint->wid = RT_NULL;

					/* send this event to the view */
					if (RTGUI_WIDGET(view)->event_handler != RT_NULL)
					{
						RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
					}
				}
				else
				{
					struct rtgui_dc* dc;
					struct rtgui_rect rect;

					dc = rtgui_dc_begin_drawing(widget);
					rtgui_widget_get_rect(widget, &rect);
					rtgui_dc_fill_rect(dc, &rect);
					rtgui_dc_end_drawing(dc);
				}
			}
		}
		break;

	case RTGUI_EVENT_CLIP_INFO:
		{
			struct rtgui_event_clip_info* eclip = (struct rtgui_event_clip_info*)event;
			struct rtgui_widget* dest_widget = RTGUI_WIDGET(eclip->wid);

			if (dest_widget != RT_NULL && dest_widget->event_handler != RT_NULL)
			{
				dest_widget->event_handler(dest_widget, event);
			}
			else
			{
				return rtgui_toplevel_event_handler(widget, event);
			}
		}
		break;

	case RTGUI_EVENT_WIN_CLOSE:
	case RTGUI_EVENT_WIN_ACTIVATE:
	case RTGUI_EVENT_WIN_DEACTIVATE:
		{
			struct rtgui_event_win* wevent = (struct rtgui_event_win*)event;
			struct rtgui_widget* dest_widget = RTGUI_WIDGET(wevent->wid);
			if (dest_widget != RT_NULL && dest_widget->event_handler != RT_NULL)
			{
				dest_widget->event_handler(dest_widget, event);
			}
		}
		break;

	case RTGUI_EVENT_WIN_MOVE:
		{
			struct rtgui_event_win_move* wevent = (struct rtgui_event_win_move*)event;
			struct rtgui_toplevel* top = RTGUI_TOPLEVEL(wevent->wid);
			if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
			{
				RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
			}
		}
		break;

	default:
		return rtgui_toplevel_event_handler(widget, event);
	}

	return RT_TRUE;
}