Esempio n. 1
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_show(RTGUI_WIDGET(win));
	return;
}
Esempio n. 2
0
void rtgui_notebook_remove(struct rtgui_notebook* notebook, rt_uint16_t index)
{
	struct rtgui_notebook_tab tab;
    rt_bool_t need_update = RT_FALSE;

	RT_ASSERT(notebook != RT_NULL);

	if (index < notebook->count)
	{
		if (notebook->count == 1)
		{
			tab = notebook->childs[0];
			rtgui_free(notebook->childs);
			notebook->childs = RT_NULL;
			notebook->count = 0;
		}
		else
		{
            if (notebook->current == index)
                need_update = RT_TRUE;

			tab = notebook->childs[index];
			for (;index < notebook->count - 1; index++)
			{
				notebook->childs[index] = notebook->childs[index + 1];
			}

			notebook->count -= 1;
			notebook->childs = (struct rtgui_notebook_tab*) rtgui_realloc(notebook->childs, 
				sizeof(struct rtgui_notebook_tab) * notebook->count);
		}

		rt_free(tab.title);

		if (need_update)
		{
			if (notebook->current > notebook->count - 1)
				notebook->current = notebook->count - 1;

            rtgui_widget_hide(tab.widget);
            rtgui_widget_show(notebook->childs[notebook->current].widget);
			rtgui_widget_update(RTGUI_WIDGET(notebook));
            rtgui_widget_set_parent(tab.widget, RT_NULL);
		}
	}
}
Esempio n. 3
0
void rtgui_notebook_set_current_by_index(struct rtgui_notebook* notebook, rt_uint16_t index)
{
	RT_ASSERT(notebook != RT_NULL);

	if ((index < notebook->count) && (notebook->current != index))
	{
		struct rtgui_widget *widget;

		if (notebook->current != RTGUI_NOT_FOUND)
			rtgui_widget_hide(notebook->childs[notebook->current].widget);

		notebook->current = index;
		widget = notebook->childs[notebook->current].widget;
		rtgui_widget_show(widget);
        rtgui_widget_update_clip(widget);
		rtgui_widget_update(widget);
		rtgui_widget_focus(widget);
	}
}
Esempio n. 4
0
void rtgui_notebook_add_image(struct rtgui_notebook* notebook, const char* label, struct rtgui_widget* child, 
	struct rtgui_image *pressed_image, struct rtgui_image *unpressed_image)
{
	rtgui_rect_t rect;
	RT_ASSERT(notebook != RT_NULL);

	notebook->count += 1;
	notebook->childs = (struct rtgui_notebook_tab*)
		rtgui_realloc(notebook->childs,
		sizeof(struct rtgui_notebook_tab) * notebook->count);

	notebook->childs[notebook->count - 1].title = rt_strdup(label);
	notebook->childs[notebook->count - 1].widget = child;
	notebook->childs[notebook->count - 1].pressed_image = pressed_image;
	notebook->childs[notebook->count - 1].unpressed_image = unpressed_image;

	/* set parent */
	rtgui_widget_set_parent(child, RTGUI_WIDGET(notebook));

	_rtgui_notebook_get_page_rect(notebook, &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
	rtgui_widget_set_rect(child, &rect);

	if (notebook->count - 1 != notebook->current)
		rtgui_widget_hide(child);

	if (RTGUI_WIDGET(notebook)->toplevel != RT_NULL &&
		RTGUI_IS_WIN(RTGUI_WIDGET(notebook)->toplevel))
	{
		struct rtgui_event_update_toplvl eup;
		RTGUI_EVENT_UPDATE_TOPLVL_INIT(&eup);
		eup.toplvl = RTGUI_WIDGET(notebook)->toplevel;
		if (RTGUI_OBJECT(child)->event_handler)
			RTGUI_OBJECT(child)->event_handler(RTGUI_OBJECT(child), (struct rtgui_event*)&eup);
	}

	return;
}
Esempio n. 5
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;
	}
}
Esempio n. 6
0
rt_bool_t rtgui_combo_event_handler(pvoid wdt, rtgui_event_t* event)
{
	rtgui_widget_t *widget = RTGUI_WIDGET(wdt);
	rtgui_combo_t* cbo = RTGUI_COMBO(wdt);


	RT_ASSERT(widget != RT_NULL);

	switch(event->type)
	{
	case RTGUI_EVENT_PAINT:
		if(widget->on_draw != RT_NULL)
			widget->on_draw(widget, event);
		else
			rtgui_combo_ondraw(cbo);
		break;

	case RTGUI_EVENT_KBD:
		if(widget->on_key != RT_NULL)
			widget->on_key(widget, event);

		return RT_TRUE;

	case RTGUI_EVENT_MOUSE_BUTTON:
	{
		rtgui_rect_t rect;
		struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
		rt_bool_t inclip=RT_EOK;

		if(!RTGUI_WIDGET_IS_ENABLE(cbo)) break;

		if(cbo->tbox->isedit == RT_TRUE)
		{
			/* only detect textbox area */
			inclip = rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo),emouse->x,emouse->y,&rect);
		}
		else
		{
			/* detect all area */
			inclip = (rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo),emouse->x,emouse->y,&rect) &&
			          rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo->tbox),emouse->x,emouse->y,&rect));
		}

		if(inclip == RT_EOK)
		{
			rtgui_combo_get_downarrow_rect(cbo,&rect);
			if(emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
			{
				if(rtgui_rect_contains_point(&rect,emouse->x,emouse->y) == RT_EOK)
				{
					/* on pull-down button */
					cbo->style = RTGUI_COMBO_STYLE_DOWNARROW_DOWN;
					rtgui_combo_draw_downarrow(cbo);
				}

				if(cbo->lbox != RT_NULL)
				{
					if(RTGUI_WIDGET_IS_HIDE(cbo->lbox))
					{
						/* display pupup listbox */
						RTGUI_WIDGET_SHOW(cbo->lbox);
						rtgui_widget_focus(cbo->lbox);
						rtgui_widget_update_clip_pirate(RTGUI_WIDGET_PARENT(cbo->lbox),cbo->lbox);
						/* set listbox location is 0 */
						cbo->lbox->first_item=0;
						cbo->lbox->now_item = 0;
						if(cbo->lbox->scroll != RT_NULL)
						{
							if(!RTGUI_WIDGET_IS_HIDE(cbo->lbox->scroll))
							{
								rtgui_scrollbar_set_value(cbo->lbox->scroll,cbo->lbox->first_item);
							}
						}
						rtgui_widget_update(RTGUI_WIDGET_PARENT(cbo->lbox));
					}
					else
					{
						/* hide it */
						rtgui_widget_hide(cbo->lbox);
					}
				}
			}
			else if(emouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				if(rtgui_region_contains_point(&RTGUI_WIDGET_CLIP(cbo),emouse->x,emouse->y,&rect) == RT_EOK)
				{
					/* on upriver button */
					cbo->style = RTGUI_COMBO_STYLE_DOWNARROW_UP;
					rtgui_combo_draw_downarrow(cbo);
				}
			}
		}
		else
			rtgui_view_event_handler(widget,event);

		return RT_TRUE;
	}

	default:
		return rtgui_view_event_handler(widget,event);
	}

	return RT_FALSE;
}
Esempio n. 7
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;
}