Beispiel #1
0
void rtgui_server_create_application(struct rtgui_event_panel_attach* event)
{
	struct rtgui_panel* panel = rtgui_panel_find(event->panel_name);

	if (panel != RT_NULL)
	{
		struct rtgui_event_panel_info ep;
		RTGUI_EVENT_PANEL_INFO_INIT(&ep);

		if (panel->wm_thread != RT_NULL)
		{
			/* notify to workbench */
			rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_attach));
		}

		/* send the responses - ok */
		rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK);

		/* send the panel info */
		ep.panel = panel;
		ep.extent = panel->extent;
		rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&ep, sizeof(ep));

		rtgui_panel_thread_add(event->panel_name, event->parent.sender);
	}
	else
	{
		/* send the responses - failure */
		rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC);
	}
}
Beispiel #2
0
void rtgui_server_destroy_application(struct rtgui_event_panel_detach* event)
{
	struct rtgui_panel* panel = event->panel;

	if (panel != RT_NULL)
	{
		if (panel->wm_thread != RT_NULL)
		{
			/* notify to workbench */
			rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_detach));
		}

		/* send the responses */
		rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK);

		rtgui_panel_thread_remove(panel, event->parent.sender);

		{
			/* get next thread and active it */
			rt_thread_t tid = rtgui_panel_get_active_thread(panel);

			/* let this thread repaint */
			struct rtgui_event_paint epaint;
			RTGUI_EVENT_PAINT_INIT(&epaint);
			epaint.wid = RT_NULL;
			rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint));
		}
	}
	else
	{
		/* send the responses - failure */
		rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_NRC);
	}
}
Beispiel #3
0
void rtgui_server_thread_panel_show(struct rtgui_event_panel_show* event)
{
	struct rtgui_panel* panel = event->panel;

	if (panel != RT_NULL)
	{
		struct rtgui_event_paint epaint;

		/* send the responses */
		rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK);

		if (panel->wm_thread != RT_NULL)
		{
			/* notify to workbench */
			rtgui_thread_send(panel->wm_thread, &(event->parent), sizeof(struct rtgui_event_panel_show));
		}

		rtgui_panel_set_active_thread(panel, event->parent.sender);

		/* send all topwin clip info */
		rtgui_topwin_update_clip_to_panel(panel);

		/* send paint event */
		RTGUI_EVENT_PAINT_INIT(&epaint);
		epaint.wid = RT_NULL;
		rtgui_thread_send(event->parent.sender, (struct rtgui_event*)&epaint,
			sizeof(epaint));
	}
	else
	{
		/* send failed */
		rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR);
	}
}
Beispiel #4
0
void rtgui_app_destroy(struct rtgui_app *app)
{
	rt_thread_t srv_tid;
    _rtgui_application_check(app);

	if (!(app->state_flag & RTGUI_APP_FLAG_EXITED))
	{
		rt_kprintf("cannot destroy a running application: %s.\n",
				   app->name);
		return;
	}

	/* send a message to notify rtgui server */
	srv_tid = rtgui_get_server();
	if (srv_tid != rt_thread_self()) /* must not the server thread */
	{
		struct rtgui_event_application event;
		RTGUI_EVENT_APP_DESTROY_INIT(&event);
		event.app = app;

		if (rtgui_send_sync(srv_tid, RTGUI_EVENT(&event), sizeof(event)) != RT_EOK)
		{
			rt_kprintf("destroy an application in server failed\n");
			return ;
		}
	}

	app->tid->user_data = 0;
	rt_mq_delete(app->mq);
	rtgui_object_destroy(RTGUI_OBJECT(app));
}
Beispiel #5
0
void rtgui_win_move(struct rtgui_win* win, int x, int y)
{
    struct rtgui_event_win_move emove;
    RTGUI_EVENT_WIN_MOVE_INIT(&emove);

    if (win == RT_NULL)
        return;

    /* move window to logic position */
    rtgui_widget_move_to_logic(RTGUI_WIDGET(win),
                               x - RTGUI_WIDGET(win)->extent.x1,
                               y - RTGUI_WIDGET(win)->extent.y1);

    if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
    {
        /* set win hide firstly */
        RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));

        emove.wid	= win;
        emove.x		= x;
        emove.y		= y;
        if (rtgui_server_post_event_sync(RTGUI_EVENT(&emove),
                                         sizeof(struct rtgui_event_win_move)) != RT_EOK)
        {
            return;
        }
    }

    /* set window visible */
    RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win));
    return;
}
Beispiel #6
0
static rt_bool_t _rtgui_win_create_in_server(struct rtgui_win *win)
{
    if (!(win->flag & RTGUI_WIN_FLAG_CONNECTED))
    {
        struct rtgui_event_win_create ecreate;
        RTGUI_EVENT_WIN_CREATE_INIT(&ecreate);

        /* send win create event to server */
        ecreate.parent_window = win->parent_window;
        ecreate.wid           = win;
        ecreate.parent.user	  = win->style;
#ifndef RTGUI_USING_SMALL_SIZE
        ecreate.extent        = RTGUI_WIDGET(win)->extent;
        rt_strncpy((char*)ecreate.title, (char*)win->title, RTGUI_NAME_MAX);
#endif

        if (rtgui_server_post_event_sync(RTGUI_EVENT(&ecreate),
                                         sizeof(struct rtgui_event_win_create)
                                        ) != RT_EOK)
        {
            rt_kprintf("create win: %s failed\n", win->title);
            return RT_FALSE;
        }

        win->flag |= RTGUI_WIN_FLAG_CONNECTED;
    }

    return RT_TRUE;
}
Beispiel #7
0
void rtgui_server_thread_panel_hide(struct rtgui_event_panel_hide* event)
{
	struct rtgui_panel* panel = event->panel;

	if (panel != RT_NULL)
	{
		rt_thread_t tid;
		struct rtgui_event_paint epaint;

		/* send the responses */
		rtgui_thread_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK);

		if (panel->thread_list.next != RT_NULL)
		{
			struct rtgui_panel_thread* thread;
			thread = rtgui_list_entry(panel->thread_list.next, struct rtgui_panel_thread, list);

			/* remove it */
			panel->thread_list.next = thread->list.next;

			/* append to the tail of thread list */
			rtgui_list_append(&(panel->thread_list), &(thread->list));
		}

		/* get new active thread */
		tid = rtgui_panel_get_active_thread(panel);
		/* send all topwin clip info */
		rtgui_topwin_update_clip_to_panel(panel);

		/* send paint event */
		RTGUI_EVENT_PAINT_INIT(&epaint);
		epaint.wid = RT_NULL;
		rtgui_thread_send(tid, (struct rtgui_event*)&epaint, sizeof(epaint));
	}
Beispiel #8
0
void rtgui_win_hiden(struct rtgui_win* win)
{
    RT_ASSERT(win != RT_NULL);
#ifdef RTGUI_USING_DESKTOP_WINDOW
    RT_ASSERT(win != the_desktop_window);
#endif

    if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)) &&
            win->flag & RTGUI_WIN_FLAG_CONNECTED)
    {
        /* send hidden message to server */
        struct rtgui_event_win_hide ehide;
        RTGUI_EVENT_WIN_HIDE_INIT(&ehide);
        ehide.wid = win;

        if (rtgui_server_post_event_sync(RTGUI_EVENT(&ehide),
                                         sizeof(struct rtgui_event_win_hide)) != RT_EOK)
        {
            rt_kprintf("hide win: %s failed\n", win->title);
            return;
        }

        /* set window hide and deactivated */
        RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
        win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
    }
}
struct rtgui_app *rtgui_app_create(const char *title)
{
    rt_thread_t tid = rt_thread_self();
    struct rtgui_app *app;
    struct rtgui_app *srv_app;
    struct rtgui_event_application event;
    char mq_name[RT_NAME_MAX];

    RT_ASSERT(tid != RT_NULL);
    RT_ASSERT(title != RT_NULL);

    /* create application */
    app = RTGUI_APP(rtgui_object_create(RTGUI_APP_TYPE));
    if (app == RT_NULL)
        return RT_NULL;

    /* one thread only can create one rtgui application */
    RT_ASSERT(tid->user_data == 0);
    app->tid = tid;

    rt_snprintf(mq_name, RT_NAME_MAX, "g%s", title);
    app->mq = rt_mq_create(mq_name, sizeof(union rtgui_event_generic), 32, RT_IPC_FLAG_FIFO);
    if (app->mq == RT_NULL)
    {
        rt_kprintf("create msgq failed.\n");
        goto __mq_err;
    }

    /* set application title */
    app->name = (unsigned char *)rt_strdup((char *)title);
    if (app->name == RT_NULL)
        goto __err;

    /* the first app should be the server */
    srv_app = rtgui_get_server();
    if (srv_app == RT_NULL)
    {
        /* set user thread */
        tid->user_data = (rt_uint32_t)app;
        return app;
    }

    RTGUI_EVENT_APP_CREATE_INIT(&event);
    event.app = app;

    /* notify rtgui server to one application has been created */
    if (rtgui_send_sync(srv_app, RTGUI_EVENT(&event), sizeof(event)) == RT_EOK)
    {
        /* set user thread */
        tid->user_data = (rt_uint32_t)app;
        return app;
    }

__err:
__mq_err:
    rtgui_object_destroy(RTGUI_OBJECT(app));
    return RT_NULL;
}
Beispiel #10
0
void rtgui_app_close(struct rtgui_app *app)
{
	struct rtgui_event_application event;

	RTGUI_EVENT_APP_DESTROY_INIT(&event);
	event.app = app;

	rtgui_send(app->tid, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application));
}
Beispiel #11
0
void rtgui_app_activate(struct rtgui_app *app)
{
	struct rtgui_event_application event;

	RTGUI_EVENT_APP_ACTIVATE_INIT(&event);
	event.app = app;

	rtgui_send(app->tid, RTGUI_EVENT(&event), sizeof(struct rtgui_event_application));
}
Beispiel #12
0
rt_err_t rtgui_win_activate(struct rtgui_win *win)
{
	struct rtgui_event_win_activate eact;
	RTGUI_EVENT_WIN_ACTIVATE_INIT(&eact);
	eact.wid = win;

	return rtgui_server_post_event_sync(RTGUI_EVENT(&eact),
									    sizeof(eact));
}
Beispiel #13
0
static void _handle_app_destroy(struct rtgui_event_application* event)
{
	rt_uint32_t index;
	struct rtgui_app* app;

	for (index = 0; index < app_count; index ++)
	{
		app = (struct rtgui_app*)app_items[index].app;
		if (app == event->app)
		{
			/* remove this application */
			app_count --;
			if (app_count == 0) 
			{
				rtgui_free(app_items);
				app_items = RT_NULL;
			}
			else if (index == app_count)
			{
				app_items = rtgui_realloc(app_items, app_count * sizeof(struct rtgui_application_item));
			}
			else
			{
				rt_uint32_t j;
				for (j = index; j < app_count; j ++)
				{
					app_items[j] = app_items[j + 1];
				}
				app_items = rtgui_realloc(app_items, app_count * sizeof(struct rtgui_application_item));
			}
			rtgui_listctrl_set_items(app_list, (rt_uint32_t)app_items, app_count);
			rtgui_ack(RTGUI_EVENT(event), RTGUI_STATUS_OK);
			return ;
		}
	}

	/* send ack to the application */
	rtgui_ack(RTGUI_EVENT(event), RTGUI_STATUS_ERROR);
	return;
}
Beispiel #14
0
static void _rtgui_win_destructor(rtgui_win_t* win)
{
    struct rtgui_event_win_destroy edestroy;

    if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
    {
        /* destroy in server */
        RTGUI_EVENT_WIN_DESTROY_INIT(&edestroy);
        edestroy.wid = win;
        if (rtgui_server_post_event_sync(RTGUI_EVENT(&edestroy),
                                         sizeof(struct rtgui_event_win_destroy)) != RT_EOK)
        {
            /* destroy in server failed */
            return;
        }
    }

    /* release field */
    rt_free(win->title);
}
Beispiel #15
0
/**
 * set this application as window manager
 */
rt_err_t rtgui_app_set_as_wm(void)
{
	rt_thread_t srv_tid;
	struct rtgui_event_set_wm event;
	struct rtgui_app* app;

	srv_tid = rtgui_get_server();
	app = rtgui_app_self();
	if (app != RT_NULL && srv_tid != RT_NULL)
	{
		/* notify rtgui server, this is a window manager */
		RTGUI_EVENT_SET_WM_INIT(&event);
		event.app = app;

		rtgui_send_sync(srv_tid, RTGUI_EVENT(&event), sizeof(event));
		return RT_EOK;
	}

	return RT_ERROR;
}
Beispiel #16
0
/**
 * set this application as window manager
 */
rt_err_t rtgui_app_set_as_wm(struct rtgui_app *app)
{
    struct rtgui_app *srv_app;
    struct rtgui_event_set_wm event;

    _rtgui_application_check(app);

    srv_app = rtgui_get_server();
    if (srv_app != RT_NULL)
    {
        /* notify rtgui server, this is a window manager */
        RTGUI_EVENT_SET_WM_INIT(&event);
        event.app = app;

        rtgui_send_sync(srv_app, RTGUI_EVENT(&event), sizeof(event));
        return RT_EOK;
    }

    return RT_ERROR;
}
Beispiel #17
0
static void _rtgui_win_destructor(rtgui_win_t* win)
{
	struct rtgui_event_win_destroy edestroy;

	if (RTGUI_TOPLEVEL(win)->server != RT_NULL)
	{
		/* destroy in server */
		RTGUI_EVENT_WIN_DESTROY_INIT(&edestroy);
		edestroy.wid = win;
		if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&edestroy),
			sizeof(struct rtgui_event_win_destroy)) != RT_EOK)
		{
			/* destroy in server failed */
			return;
		}
	}

	/* release field */
	rt_free(win->title);
}
Beispiel #18
0
rt_err_t rtgui_workbench_hide(rtgui_workbench_t* workbench)
{
	if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL)
	{
		struct rtgui_event_panel_hide ehide;
		RTGUI_EVENT_PANEL_HIDE_INIT(&ehide);

		RT_ASSERT(workbench != RT_NULL);
		if (workbench->parent.server == RT_NULL) return -RT_ERROR;

		ehide.panel = workbench->panel;
		if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(workbench)->server, RTGUI_EVENT(&ehide),
			sizeof(struct rtgui_event_panel_hide)) != RT_EOK)
			return -RT_ERROR;

		RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench));
		rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
	}

	return RT_EOK;
}
Beispiel #19
0
static void _handle_app_create(struct rtgui_event_application* event)
{
	rt_uint32_t index;
	rt_int32_t status;
	struct rtgui_app* app;

	status = RTGUI_STATUS_OK;
	for (index = 0; index < app_count; index ++)
	{
		app = (struct rtgui_app*)app_items[index].app;
		if (app == event->app)
		{
			/* application is created already */
			status = RTGUI_STATUS_ERROR;
			goto __exit;
		}
	}

	app_count += 1;
	if (app_items == RT_NULL)
		app_items = (struct rtgui_application_item*) rtgui_malloc(sizeof(struct rtgui_application_item));
	else
		app_items = (struct rtgui_application_item*) rtgui_realloc(app_items, sizeof(struct rtgui_application_item) * app_count);

	if (app_items == RT_NULL) 
	{
		status = RTGUI_STATUS_ERROR;
		goto __exit;
	}

	app = event->app;

	app_items[app_count - 1].app = app;
	rtgui_listctrl_set_items(app_list, (rt_uint32_t)app_items, app_count);

__exit:
	/* send ack to the application */
	rtgui_ack(RTGUI_EVENT(event), status);
	return;
}
Beispiel #20
0
void rtgui_workbench_close(rtgui_workbench_t* workbench)
{
	/* detach workbench in server */
	if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL)
	{
		struct rtgui_event_panel_detach edetach;
		RTGUI_EVENT_PANEL_DETACH_INIT(&edetach);

		/* detach from panel */
		edetach.panel = workbench->panel;

		/* send PANEL DETACH to server */
		if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(workbench)->server,
			RTGUI_EVENT(&edetach), sizeof(struct rtgui_event_panel_detach)) != RT_EOK)
			return;

		RTGUI_TOPLEVEL(workbench)->server = RT_NULL;
	}

	/* set status to close */
	workbench->flag |= RTGUI_WORKBENCH_FLAG_CLOSED;
}
Beispiel #21
0
rt_err_t rtgui_workbench_show(rtgui_workbench_t* workbench)
{
	RT_ASSERT(workbench != RT_NULL);

	if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL)
	{
		struct rtgui_event_panel_show eraise;
		RTGUI_EVENT_PANEL_SHOW_INIT(&eraise);
		eraise.workbench = workbench;

		eraise.panel = workbench->panel;
		if (rtgui_thread_send_sync(workbench->parent.server, RTGUI_EVENT(&eraise),
			sizeof(struct rtgui_event_panel_show)) != RT_EOK)
			return -RT_ERROR;

		RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(workbench));
		rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
	}
	else return -RT_ERROR;

	return RT_EOK;
}
Beispiel #22
0
void rtgui_win_hiden(struct rtgui_win* win)
{
	RT_ASSERT(win != RT_NULL);

	if (!RTGUI_WIDGET_IS_HIDE(win) &&
		win->flag & RTGUI_WIN_FLAG_CONNECTED)
	{
		/* send hidden message to server */
		struct rtgui_event_win_hide ehide;
		RTGUI_EVENT_WIN_HIDE_INIT(&ehide);
		ehide.wid = win;

		if (rtgui_server_post_event_sync(RTGUI_EVENT(&ehide),
			sizeof(struct rtgui_event_win_hide)) != RT_EOK)
		{
			rt_kprintf("hide win: %s failed\n", win->title);
			return;
		}

		rtgui_widget_hide(RTGUI_WIDGET(win));
		win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
	}
}
Beispiel #23
0
static rt_bool_t _rtgui_win_create_in_server(rtgui_win_t* win)
{
	if (RTGUI_TOPLEVEL(win)->server == RT_NULL)
	{
		rt_thread_t server;
		struct rtgui_event_win_create ecreate;
		RTGUI_EVENT_WIN_CREATE_INIT(&ecreate);

		/* get server thread id */
		server = rtgui_thread_get_server();
		if (server == RT_NULL)
		{
			rt_kprintf("RTGUI server is not running...\n");
			return RT_FALSE;
		}

		/* send win create event to server */
		ecreate.wid 		= win;
		ecreate.parent.user	= win->style;
#ifndef RTGUI_USING_SMALL_SIZE
		ecreate.extent 		= RTGUI_WIDGET(win)->extent;
		rt_strncpy((char*)ecreate.title, (char*)win->title, RTGUI_NAME_MAX);
#endif

		if (rtgui_thread_send_sync(server, RTGUI_EVENT(&ecreate),
			sizeof(struct rtgui_event_win_create)) != RT_EOK)
		{
			rt_kprintf("create win: %s failed\n", win->title);
			return RT_FALSE;
		}

		/* set server */
		RTGUI_TOPLEVEL(win)->server = server;
	}

	return RT_TRUE;
}
Beispiel #24
0
static void _rtgui_workbench_destructor(rtgui_workbench_t *workbench)
{
	RT_ASSERT(workbench != RT_NULL);

	if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL)
	{
		struct rtgui_event_panel_detach edetach;
		RTGUI_EVENT_PANEL_DETACH_INIT(&edetach);

		/* detach from panel */
		edetach.panel = workbench->panel;

		/* send PANEL DETACH to server */
		if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(workbench)->server,
			RTGUI_EVENT(&edetach), sizeof(struct rtgui_event_panel_detach)) != RT_EOK)
			return;

		RTGUI_TOPLEVEL(workbench)->server = RT_NULL;
	}

	/* release title */
	rt_free(workbench->title);
	workbench->title = RT_NULL;
}
Beispiel #25
0
void rtgui_win_hiden(struct rtgui_win* win)
{
	RT_ASSERT(win != RT_NULL);

	if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)) &&
		RTGUI_TOPLEVEL(win)->server != RT_NULL)
	{
		/* send hidden message to server */
		struct rtgui_event_win_hide ehide;
		RTGUI_EVENT_WIN_HIDE_INIT(&ehide);
		ehide.wid = win;

		if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&ehide),
			sizeof(struct rtgui_event_win_hide)) != RT_EOK)
		{
			rt_kprintf("hide win: %s failed\n", win->title);
			return;
		}

		/* set window hide and deactivated */
		RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
		win->style &= ~RTGUI_WIN_STYLE_ACTIVATE;
	}
}
Beispiel #26
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;
}
Beispiel #27
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;
}
Beispiel #28
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;
}
Beispiel #29
0
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;
}
Beispiel #30
0
struct rtgui_app* rtgui_app_create(
        rt_thread_t tid,
        const char *title)
{
	rt_thread_t srv_tid;
	struct rtgui_app *app;
	struct rtgui_event_application event;

	RT_ASSERT(tid != RT_NULL);
	RT_ASSERT(title != RT_NULL);

	/* create application */
	app = RTGUI_APP(rtgui_object_create(RTGUI_APP_TYPE));
	if (app == RT_NULL)
		return RT_NULL;

	/* one thread only can create one rtgui application */
	RT_ASSERT(tid->user_data == 0);
	app->tid = tid;
	/* set user thread */
	tid->user_data = (rt_uint32_t)app;

	app->mq = rt_mq_create("rtgui", sizeof(union rtgui_event_generic), 32, RT_IPC_FLAG_FIFO);
	if (app->mq == RT_NULL)
	{
		rt_kprintf("create msgq failed.\n");
		goto __mq_err;
	}

	/* set application title */
	app->name = (unsigned char*)rt_strdup((char*)title);
	if (app->name == RT_NULL)
		goto __err;

	/* send a message to notify rtgui server */
	srv_tid = rtgui_get_server();
	if (srv_tid == RT_NULL)
	{
		rt_kprintf("gui server is not running.\n");
		goto __err;
	}

	/* create the rtgui server application */
	if (srv_tid == rt_thread_self())
		return app;

	RTGUI_EVENT_APP_CREATE_INIT(&event);
	event.app = app;

	/* notify rtgui server to one application has been created */
	if (rtgui_send_sync(srv_tid, RTGUI_EVENT(&event), sizeof(event)) == RT_EOK)
	{
		return app;
	}

__err:
__mq_err:
	rtgui_object_destroy(RTGUI_OBJECT(app));
	tid->user_data = 0;
	return RT_NULL;
}