Exemplo n.º 1
0
void rtgui_app_destroy(struct rtgui_app *app)
{
    struct rtgui_app *srv_app;
    _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_app = rtgui_get_server();
    if (srv_app != rtgui_app_self())
    {
        struct rtgui_event_application event;
        RTGUI_EVENT_APP_DESTROY_INIT(&event);
        event.app = app;

        if (rtgui_send_sync(srv_app, 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));
}
Exemplo n.º 2
0
static void app_mainmenu_init(void)
{
    struct rtgui_image *bg_image;
    rtgui_rect_t rect;

    /* create main window of Application Manager */
    win = rtgui_mainwin_create(RT_NULL, "mainmenu", RTGUI_WIN_STYLE_MAINWIN);
    if (win != RT_NULL)
    {
        rtgui_object_set_event_handler(RTGUI_OBJECT(win), mainmenu_event_handler);
        rtgui_widget_get_rect(RTGUI_WIDGET(win), &rect);

#ifdef RT_USING_MODULE 
        mainmenu_scan_apps();
#endif
        /* create background image */
        bg_image = rtgui_image_create("/resource/bg_image.jpg", RT_TRUE);
        if (bg_image == RT_NULL)
        {
            rt_kprintf("open \"/resource/bg_image.jpg\" failed\n");
        }
        ycircle_image = rtgui_image_create("/resource/ycircle.png", RT_TRUE);
        gcircle_image = rtgui_image_create("/resource/gcircle.png", RT_TRUE);
        app_list = app_list_create(&rect, items, ITEM_MAX, 2, 5, bg_image);
        rtgui_image_destroy(bg_image);
        app_list_draw(app_list);
        app_list_draw_pagemark(app_list);
        app_list->on_select = exec_internal_app;
        rtgui_win_show(win, RT_FALSE);
        /* set as main window */
        rtgui_app_set_main_win(rtgui_app_self(), win);
    }
}
Exemplo n.º 3
0
void rtgui_app_set_onidle(rtgui_idle_func_t onidle)
{
	struct rtgui_app *app;

	app = rtgui_app_self();
	if (app != RT_NULL)
		app->on_idle = onidle;
}
Exemplo n.º 4
0
void rtgui_app_set_main_win(struct rtgui_win* win)
{
	struct rtgui_app *app;

	app = rtgui_app_self();
	if (app != RT_NULL)
	{
		app->main_object = RTGUI_OBJECT(win);
	}
}
Exemplo n.º 5
0
rtgui_idle_func_t rtgui_app_get_onidle(void)
{
	struct rtgui_app *app;

	app = rtgui_app_self();
	if (app != RT_NULL)
		return app->on_idle;
	else
		return RT_NULL;
}
Exemplo n.º 6
0
void rtgui_win_end_modal(struct rtgui_win* win, rtgui_modal_code_t modal_code)
{
	if (win == RT_NULL || !(win->flag & RTGUI_WIN_FLAG_MODAL))
		return;

	rtgui_app_exit(rtgui_app_self(), modal_code);

	/* remove modal mode */
	win->flag &= ~RTGUI_WIN_FLAG_MODAL;
}
Exemplo n.º 7
0
rtgui_timer_t *rtgui_timer_create(rt_int32_t time, rt_int32_t flag, rtgui_timeout_func timeout, void *parameter)
{
    rtgui_timer_t *timer;

    timer = (rtgui_timer_t *) rtgui_malloc(sizeof(rtgui_timer_t));
    timer->app = rtgui_app_self();
    timer->timeout = timeout;
    timer->user_data = parameter;

    /* init rt-thread timer */
    rt_timer_init(&(timer->timer), "rtgui", rtgui_time_out, timer, time, (rt_uint8_t)flag);

    return timer;
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
0
void app_mgr_win_init(void)
{
	struct rtgui_win* win;
	rtgui_rect_t rect;
	struct rtgui_notebook *notebook;
	rtgui_listbox_t* box;
	struct rtgui_image* pressed_image;
	struct rtgui_image* unpressed_image;
	int font_size;
	struct block_panel* block;
	int angle_y;
	
	/* create main window of Application Manager */
	win = rtgui_mainwin_create(RT_NULL, "AppMgr", RTGUI_WIN_STYLE_MAINWIN);
	RTGUI_WIDGET_BACKGROUND(win) = RTGUI_RGB(241, 241, 241);

	/* create icon image */
	pressed_image = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)home_xpm, sizeof(home_xpm), RT_FALSE);
	unpressed_image = rtgui_image_create_from_mem("xpm", (const rt_uint8_t*)home_gray_xpm, sizeof(home_gray_xpm), RT_FALSE);
	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(win), "AppMgr", &rect);
	font_size = rtgui_rect_height(rect);

	/* create notebook */
	rtgui_widget_get_extent(RTGUI_WIDGET(win), &rect);
	notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_LEFT);
	RTGUI_WIDGET_BACKGROUND(notebook) = RTGUI_RGB(241, 241, 241);
	rtgui_notebook_set_tab_height(notebook, pressed_image->h + font_size + 3 * RTGUI_WIDGET_DEFAULT_MARGIN);
	rtgui_notebook_set_tab_width(notebook, 65);
	angle_y = rect.x1;

	/* create navigation */
	rtgui_notebook_get_client_rect(notebook, &rect);
	block = block_panel_create(angle_y + notebook->tab_h/2, &rect);
	RTGUI_WIDGET_BACKGROUND(block) = RTGUI_RGB(241, 241, 241);
	rtgui_notebook_add_image(notebook, "AppTask", RTGUI_WIDGET(block),
		pressed_image, unpressed_image);
	apps_list_create(RTGUI_PANEL(block));
	angle_y += notebook->tab_h;

	block = block_panel_create(angle_y + notebook->tab_h/2, &rect);
	RTGUI_WIDGET_BACKGROUND(block) = RTGUI_RGB(241, 241, 241);
	rtgui_notebook_add_image(notebook, "Tab 1", RTGUI_WIDGET(block),
		pressed_image, unpressed_image);
	{
		struct rtgui_rect box_rect;
		block_panel_get_client_extent(block, &box_rect);
		// rtgui_widget_get_extent(RTGUI_WIDGET(block), &box_rect);
		// rtgui_rect_inflate(&box_rect, -15);
		box = rtgui_listbox_create(items, sizeof(items)/sizeof(struct rtgui_listbox_item), &box_rect);
		rtgui_container_add_child(RTGUI_CONTAINER(block), RTGUI_WIDGET(box));
	}
	angle_y += notebook->tab_h;

	block = block_panel_create(angle_y + notebook->tab_h/2, &rect);
	RTGUI_WIDGET_BACKGROUND(block) = RTGUI_RGB(241, 241, 241);
	rtgui_notebook_add_image(notebook, "Tab 2", RTGUI_WIDGET(block), 
		pressed_image, unpressed_image);
	angle_y += notebook->tab_h;

	rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(notebook));

	rtgui_win_show(win, RT_FALSE);

	/* set as main window */
	rtgui_app_set_main_win(rtgui_app_self(), win);
}