示例#1
0
rt_base_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
{
    struct rtgui_event_win_show eshow;
    rt_base_t exit_code = -1;

    RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
    eshow.wid = win;

    if (win == RT_NULL)
        return exit_code;

    /* if it does not register into server, create it in server */
    if (!(win->flag & RTGUI_WIN_FLAG_CONNECTED))
    {
        if (_rtgui_win_create_in_server(win) == RT_FALSE)
            return exit_code;
    }

    if (rtgui_server_post_event_sync(RTGUI_EVENT(&eshow),
                                     sizeof(struct rtgui_event_win_show)
                                    ) != RT_EOK)
    {
        rt_kprintf("show win failed\n");
        return exit_code;
    }

    /* set window unhidden */
    RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win));

    if (win->focused_widget == RT_NULL)
        rtgui_widget_focus(RTGUI_WIDGET(win));

    if (is_modal == RT_TRUE)
    {
        struct rtgui_application *app;
        struct rtgui_event_win_modal_enter emodal;

        RTGUI_EVENT_WIN_MODAL_ENTER_INIT(&emodal);
        emodal.wid = win;

        app = rtgui_application_self();
        RT_ASSERT(app != RT_NULL);

        win->flag |= RTGUI_WIN_FLAG_MODAL;

        if (rtgui_server_post_event_sync((struct rtgui_event*)&emodal,
                                         sizeof(emodal)) != RT_EOK)
            return exit_code;

        app->modal_object = RTGUI_OBJECT(win);

        exit_code = rtgui_application_run(app);

        app->modal_object = RT_NULL;
        win->flag &= ~RTGUI_WIN_FLAG_MODAL;

        if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
        {
            rtgui_win_destroy(win);
        }
    }

    return exit_code;
}
示例#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;
}
示例#3
0
rt_bool_t rtgui_app_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
    struct rtgui_app *app;

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

    app = RTGUI_APP(object);

    switch (event->type)
    {
    case RTGUI_EVENT_PAINT:
    case RTGUI_EVENT_VPAINT_REQ:
    case RTGUI_EVENT_MOUSE_BUTTON:
    case RTGUI_EVENT_MOUSE_MOTION:
    case RTGUI_EVENT_CLIP_INFO:
    case RTGUI_EVENT_WIN_ACTIVATE:
    case RTGUI_EVENT_WIN_DEACTIVATE:
    case RTGUI_EVENT_WIN_CLOSE:
    case RTGUI_EVENT_WIN_MOVE:
    case RTGUI_EVENT_WIN_SHOW:
    case RTGUI_EVENT_WIN_HIDE:
    case RTGUI_EVENT_KBD:
    case RTGUI_EVENT_GESTURE:
        _rtgui_application_dest_handle(app, event);
        break;

    case RTGUI_EVENT_APP_ACTIVATE:
        if (app->main_object != RT_NULL)
        {
            /* Let the polymorphism work. */
            struct rtgui_event_win_show wev;

            RTGUI_EVENT_WIN_SHOW_INIT(&wev);
            wev.wid = (struct rtgui_win*)app->main_object;

            rtgui_object_handle(app->main_object, &wev.parent);
        }
        break;

    case RTGUI_EVENT_APP_DESTROY:
        rtgui_app_exit(app, 0);
        break;

    case RTGUI_EVENT_TIMER:
    {
        struct rtgui_timer *timer;
        struct rtgui_event_timer *etimer = (struct rtgui_event_timer *) event;

        timer = etimer->timer;
        timer->pending_cnt--;
        RT_ASSERT(timer->pending_cnt >= 0);
        if (timer->state == RTGUI_TIMER_ST_DESTROY_PENDING)
        {
            /* Truly destroy the timer when there is no pending event. */
            if (timer->pending_cnt == 0)
                rtgui_timer_destory(timer);
        }
        else if (timer->state == RTGUI_TIMER_ST_RUNNING && timer->timeout != RT_NULL)
        {
            /* call timeout function */
            timer->timeout(timer, timer->user_data);
        }
    }
    break;

    case RTGUI_EVENT_MV_MODEL:
    {
        struct rtgui_event_mv_model *emodel = (struct rtgui_event_mv_model *)event;
        RT_ASSERT(emodel->view);
        return rtgui_object_handle(RTGUI_OBJECT(emodel->view), event);
    }

    case RTGUI_EVENT_COMMAND:
    {
        struct rtgui_event_command *ecmd = (struct rtgui_event_command *)event;

        if (ecmd->wid != RT_NULL)
            return _rtgui_application_dest_handle(app, event);
    }
    default:
        return rtgui_object_event_handler(object, event);
    }

    return RT_TRUE;
}
示例#4
0
rtgui_modal_code_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
{
	rtgui_modal_code_t result;

	RT_ASSERT(win != RT_NULL);
	result = RTGUI_MODAL_CANCEL;

	/* if it does not register into server, create it in server */
	if (RTGUI_TOPLEVEL(win)->server == RT_NULL)
	{
		if (_rtgui_win_create_in_server(win) == RT_FALSE)
			return result;
	}

	if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)))
	{
		/* send show message to server */
		struct rtgui_event_win_show eshow;
		RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
		eshow.wid = win;

		if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow),
			sizeof(struct rtgui_event_win_show)) != RT_EOK)
		{
			/* hide window failed */
			return result;
		}

		/* set window unhidden */
		RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win));
	}
	else rtgui_widget_update(RTGUI_WIDGET(win));

	if (is_modal == RT_TRUE)
	{
		if (win->parent_toplevel != RT_NULL)
		{
			rtgui_widget_t *parent_widget;

			/* set style */
			win->style |= RTGUI_WIN_STYLE_MODAL;

			/* get root toplevel */
			parent_widget = RTGUI_WIDGET(win->parent_toplevel);
			if (RTGUI_IS_WORKBENCH(parent_widget))
			{
				rtgui_workbench_t* workbench;
				workbench = RTGUI_WORKBENCH(win->parent_toplevel);
				workbench->flag |= RTGUI_WORKBENCH_FLAG_MODAL_MODE;
				workbench->modal_widget = RTGUI_WIDGET(win);

				rtgui_workbench_event_loop(workbench);
				result = workbench->modal_code;
				workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE;
				workbench->modal_widget = RT_NULL;
			}
			else if (RTGUI_IS_WIN(parent_widget))
			{
				rtgui_win_t* parent_win;
				parent_win = RTGUI_WIN(win->parent_toplevel);
				parent_win->style |= RTGUI_WIN_STYLE_UNDER_MODAL;
				parent_win->modal_widget = RTGUI_WIDGET(win);

				rtgui_win_event_loop(parent_win);
				result = parent_win->modal_code;
				parent_win->style &= ~RTGUI_WIN_STYLE_UNDER_MODAL;
				parent_win->modal_widget = RT_NULL;
			}
		}
		else
		{
			/* which is a root window */
			win->style |= RTGUI_WIN_STYLE_MODAL;
			rtgui_win_event_loop(win);

			result = win->modal_code;
			win->style &= ~RTGUI_WIN_STYLE_MODAL;
		}
	}

	return result;
}
示例#5
0
文件: window.c 项目: zdgaoyu/RTGUI
rt_base_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
{
	rt_base_t exit_code = -1;
	struct rtgui_app *app;
	struct rtgui_event_win_show eshow;

	app = rtgui_app_self();
	RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
	eshow.wid = win;

	if (win == RT_NULL)
		return exit_code;

	/* if it does not register into server, create it in server */
	if (!(win->flag & RTGUI_WIN_FLAG_CONNECTED))
	{
		if (_rtgui_win_create_in_server(win) == RT_FALSE)
			return exit_code;
	}

	/* set window unhidden before notify the server */
	rtgui_widget_show(RTGUI_WIDGET(win));

	if (rtgui_server_post_event_sync(RTGUI_EVENT(&eshow),
		sizeof(struct rtgui_event_win_show)) != RT_EOK)
	{
		/* It could not be shown if a parent window is hidden. */
		rtgui_widget_hide(RTGUI_WIDGET(win));
		return exit_code;
	}

	if (win->focused_widget == RT_NULL)
		rtgui_widget_focus(RTGUI_WIDGET(win));

	/* set main window */
	if (app->main_object == RT_NULL)
		rtgui_app_set_main_win(win);

    if (is_modal == RT_TRUE)
    {
		struct rtgui_app *app;
		struct rtgui_event_win_modal_enter emodal;

		RTGUI_EVENT_WIN_MODAL_ENTER_INIT(&emodal);
		emodal.wid = win;

		app = rtgui_app_self();
		RT_ASSERT(app != RT_NULL);

		win->flag |= RTGUI_WIN_FLAG_MODAL;

		if (rtgui_server_post_event_sync((struct rtgui_event*)&emodal,
										 sizeof(emodal)) != RT_EOK)
			return exit_code;

		app->modal_object = RTGUI_OBJECT(win);

		exit_code = rtgui_app_run(app);

		app->modal_object = RT_NULL;
		win->flag &= ~RTGUI_WIN_FLAG_MODAL;

		if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
		{
			rtgui_win_destroy(win);
		}
    }

	return exit_code;
}