Exemplo n.º 1
0
void rtgui_combo_add_string(rtgui_combo_t* cbo,const char* string)
{
	if(cbo->lbox != RT_NULL)
	{
		rtgui_listbox_item_t item;
		rtgui_rect_t rect;
		rt_uint32_t h,count;

		item.name = (char*)string;
		item.image = RT_NULL;
		rtgui_listbox_add_item(cbo->lbox, &item, 1);

		rtgui_widget_get_rect(cbo->lbox, &rect);
		count = rtgui_listbox_get_count(cbo->lbox);

		h = RTGUI_WIDGET_BORDER_SIZE(cbo->lbox)*2+(RTGUI_SEL_H + 2)*count;

		if(h>RC_H(rect))
		{
			if(cbo->lbox->item_per_page<5)/* change when less than five */
			{
				rect.y2 = rect.y1+h;
				rtgui_widget_rect_to_device(cbo->lbox,&rect);
				rtgui_widget_set_rect(cbo->lbox,&rect);/* update listbox extent */
				cbo->lbox->item_per_page = RC_H(rect) / (RTGUI_SEL_H+2);

				if(cbo->lbox->scroll != RT_NULL)/* update scrollbar extent */
				{
					rtgui_widget_get_rect(cbo->lbox->scroll, &rect);
					rect.y2 = rect.y1+h-RTGUI_WIDGET_BORDER_SIZE(cbo->lbox)*2;
					rtgui_widget_rect_to_device(cbo->lbox->scroll,&rect);
					rtgui_widget_set_rect(cbo->lbox->scroll,&rect);

					if(cbo->lbox->item_count > cbo->lbox->item_per_page)
					{
						RTGUI_WIDGET_SHOW(cbo->lbox->scroll);
						rtgui_scrollbar_set_line_step(cbo->lbox->scroll, 1);
						rtgui_scrollbar_set_page_step(cbo->lbox->scroll, cbo->lbox->item_per_page);
						rtgui_scrollbar_set_range(cbo->lbox->scroll, cbo->lbox->item_count);
					}
					else
					{
						RTGUI_WIDGET_HIDE(cbo->lbox->scroll);
					}
					rtgui_widget_update_clip(cbo->lbox);
				}
			}
		}
	}
}
Exemplo n.º 2
0
static void _rtgui_listctrl_scrollbar_onmouse(struct rtgui_listctrl* ctrl, struct rtgui_event_mouse* mouse)
{
	rtgui_rect_t rect;
	rt_uint32_t height, y1;
	rt_uint16_t old_item;

	/* get scrollbar rect */
	_rtgui_listctrl_get_scrollbar_rect(ctrl, &rect);
	height = rtgui_rect_height(rect);
	height = height / ((ctrl->items_count + (ctrl->page_items - 1))/ctrl->page_items);
	y1 = (ctrl->current_item / ctrl->page_items) * height;

	rect.y1 = rect.y1 + y1; rect.y2 = rect.y1 + height;
	rtgui_widget_rect_to_device(RTGUI_WIDGET(ctrl), &rect);

	old_item = ctrl->current_item;
	if (mouse->y < rect.y1)
	{
		if (ctrl->current_item - ctrl->page_items >= 0)
			ctrl->current_item -= ctrl->page_items;
		rtgui_listctrl_update_current(ctrl, old_item);
	}
	else if (mouse->y > rect.y2)
	{
		if (ctrl->current_item + ctrl->page_items < ctrl->items_count - 1)
			ctrl->current_item += ctrl->page_items;
		else
			ctrl->current_item = ((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items;
		rtgui_listctrl_update_current(ctrl, old_item);
	}
}
Exemplo n.º 3
0
Arquivo: edit.c Projeto: amsl/RTGUI
static void rtgui_edit_init_caret(struct rtgui_edit *edit, rtgui_point_t visual)
{
	struct rtgui_gdev *grp = rtgui_gdev_get();
	int x, y;
	rtgui_color_t color;
	rtgui_rect_t rect;
	int ofs=0;

	RT_ASSERT(edit != RT_NULL);
	if(!RTGUI_WIDGET_IS_FOCUSED(edit)) return;

	rtgui_edit_get_caret_rect(edit, &edit->caret_rect, visual);
	rect = edit->caret_rect;
	rtgui_widget_rect_to_device(RTGUI_WIDGET(edit), &rect);

	if(edit->caret == RT_NULL)
		edit->caret = (rtgui_color_t*)rtgui_malloc(RC_W(rect) * RC_H(rect)*sizeof(rtgui_color_t));
	rtgui_timer_stop(edit->caret_timer);

	for(x=rect.x1; x<rect.x2; x++)
	{
		for(y=rect.y1; y<rect.y2; y++)
		{
			grp->ops->get_pixel(&color,x,y);
			*(edit->caret + ofs++) = color;
		}
	}

	rtgui_timer_start(edit->caret_timer);
}
Exemplo n.º 4
0
static void rtgui_textbox_init_caret(rtgui_textbox_t *box, rt_uint16_t position)
{
	int x, y;
	rtgui_color_t color;
	rtgui_rect_t rect;
	int ofs = 0;

	RT_ASSERT(box != RT_NULL);

	if (!RTGUI_WIDGET_IS_FOCUSED(box))
		return;

	rtgui_textbox_get_caret_rect(box, &box->caret_rect, position);
	rect = box->caret_rect;
	rtgui_widget_rect_to_device(RTGUI_WIDGET(box), &rect);

	if (box->caret == RT_NULL)
		box->caret = rtgui_malloc(rtgui_rect_width(rect) * rtgui_rect_height(rect) * sizeof(rtgui_color_t));

	for (x = rect.x1; x < rect.x2; x++)
	{
		for (y = rect.y1; y < rect.y2; y++)
		{
			rtgui_graphic_driver_get_default()->ops->get_pixel(&color, x, y);
			*(box->caret + ofs) = color;
			ofs++;
		}
	}
}
/* 鼠标事件处理函数 */
static void rtgui_mywidget_onmouse(struct rtgui_mywidget* me, struct rtgui_event_mouse* mouse)
{
	struct rtgui_rect rect;
	rt_uint16_t x, y;

	/* 仅对鼠标抬起动作进行处理 */
	if (!(mouse->button & RTGUI_MOUSE_BUTTON_UP)) return;

	/* 获得控件的位�?*/
	rtgui_widget_get_rect(RTGUI_WIDGET(me), &rect);
	/* get_rect函数获得是控件的相对位置,而鼠标事件给出的坐标是绝对坐标,需要做一个转�?*/
	rtgui_widget_rect_to_device(RTGUI_WIDGET(me), &rect);

	/* 计算中心原点 */
	x = (rect.x2 + rect.x1)/2;
	y = (rect.y2 + rect.y1)/2;

	/* 比较鼠标坐标是否在圈�?*/
	if ((mouse->x < x + 5 && mouse->x > x - 5) &&
			(mouse->y < y + 5 && mouse->y > y - 5))
	{
		/* 更改控件状�?*/
		if (me->status & MYWIDGET_STATUS_ON) me->status = MYWIDGET_STATUS_OFF;
		else me->status = MYWIDGET_STATUS_ON;

		/* 刷新(重新绘制)控件 */
		rtgui_mywidget_ondraw(me);
	}
}
Exemplo n.º 6
0
rtgui_terminal_t* rtgui_terminal_create(pvoid parent,const char* text, int left,int top,int w,int h)
{
	rtgui_container_t *container;
	rtgui_terminal_t* tma;

	RT_ASSERT(parent != RT_NULL);
	container = RTGUI_CONTAINER(parent);

	tma = rtgui_widget_create(RTGUI_TERMINAL_TYPE);
	if(tma != RT_NULL)
	{
		rtgui_rect_t rect;
		rtgui_widget_get_rect(container, &rect);
		rtgui_widget_rect_to_device(container,&rect);
		rect.x1 += left;
		rect.y1 += top;
		rect.x2 = rect.x1+w;
		rect.y2 = rect.y1+h;
		rtgui_widget_set_rect(tma,&rect);
		rtgui_container_add_child(container, tma);

		/* calculate line width and line page count */
		rtgui_terminal_calc_width(tma);
		/* set text */
		rtgui_terminal_calc_line(tma, text);
	}

	return tma;
}
Exemplo n.º 7
0
Arquivo: edit.c Projeto: amsl/RTGUI
void rtgui_edit_adjust_scroll(rtgui_scrollbar_t *bar)
{
	struct rtgui_edit *edit;
	
	RT_ASSERT(bar != RT_NULL);
	
	if(bar->WIDGET_GROUP != RT_NULL)
	{
		rtgui_rect_t rect;
		rt_uint32_t _left=0,_top=0,_width=RTGUI_DEFAULT_SB_WIDTH,_len=0;

		edit = bar->WIDGET_GROUP;
		rtgui_widget_get_rect(edit, &rect);
		rtgui_widget_rect_to_device(edit,&rect);
		if(bar->orient==RTGUI_HORIZONTAL)
		{
			if(RTGUI_WIDGET_IS_HIDE(edit->hscroll))
			{
				if(edit->max_rows > edit->row_per_page)
				{
					RTGUI_WIDGET_SHOW(edit->hscroll);
					rtgui_scrollbar_set_line_step(edit->hscroll, 1);
					rtgui_scrollbar_set_page_step(edit->hscroll, edit->row_per_page);
					rtgui_scrollbar_set_range(edit->hscroll, edit->max_rows);
				}
				else
					RTGUI_WIDGET_HIDE(edit->vscroll);
				rtgui_widget_update_clip(RTGUI_WIDGET(edit));
			}
			else
			{
				_left = RTGUI_WIDGET_BORDER_SIZE(edit);
				_top = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width;
				_len = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2;
				
				if(!RTGUI_WIDGET_IS_HIDE(edit->vscroll)) 
					_len -= _width;
				rect.x1 += _left;
				rect.y1 += _top;
				rect.x2 = rect.x1+_len;
				rect.y2 = rect.y1+_width;
			}
		}
		else if(bar->orient==RTGUI_VERTICAL)
		{
			_left = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width;
			_top = RTGUI_WIDGET_BORDER_SIZE(edit);
			_len = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2;
			
			if(!RTGUI_WIDGET_IS_HIDE(edit->hscroll))  
				_len -= _width;
			rect.x1 += _left;
			rect.y1 += _top;
			rect.x2 = rect.x1+_width;
			rect.y2 = rect.y1+_len;
		}
		rtgui_widget_set_rect(bar,&rect);
	}
}
Exemplo n.º 8
0
rt_bool_t rtgui_notebook_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
    int page_index;
    rtgui_rect_t rect;
    struct rtgui_notebook *notebook;

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

    notebook = RTGUI_NOTEBOOK(object);

    switch (event->type)
    {
	case RTGUI_EVENT_COMMAND:
		/* broadcast on each tab */
		_rtgui_notebook_ontab(notebook, event);
		break;
    case RTGUI_EVENT_PAINT:
        _rtgui_notebook_ondraw(notebook);
        break;
    case RTGUI_EVENT_MOUSE_BUTTON:
        _rtgui_notebook_onmouse(notebook, (struct rtgui_event_mouse *)event);
        break;
    case RTGUI_EVENT_SHOW:
        /* show myself */
        rtgui_widget_onshow(object, event);
        /* show the tab widget */
        return _rtgui_notebook_current_widget_handle(notebook, event);
    case RTGUI_EVENT_HIDE:
        /* hide myself */
        rtgui_widget_onhide(object, event);
        /* hide the tab widget */
        return _rtgui_notebook_current_widget_handle(notebook, event);
    case RTGUI_EVENT_KBD:
        return _rtgui_notebook_current_widget_handle(notebook, event);
    case RTGUI_EVENT_UPDATE_TOPLVL:
        /* update myself */
        rtgui_widget_onupdate_toplvl(object, event);
        /* update all the widgets in myself */
        _rtgui_notebook_all_widget_handle(notebook, event);
        return RT_FALSE;

    case RTGUI_EVENT_RESIZE:
        /* re-size page widget */
        _rtgui_notebook_get_page_rect(notebook, &rect);
        rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
        for (page_index = 0; page_index < notebook->count; page_index ++)
        {
            rtgui_widget_set_rect(notebook->childs[page_index].widget, &rect);
        }
        break;

    default:
        /* use parent event handler */
        return rtgui_widget_event_handler(object, event);
    }

    return RT_FALSE;
}
Exemplo n.º 9
0
/* 这个函数用于返回演示视图的对外可用区域 */
void demo_view_get_rect(rtgui_view_t* view, rtgui_rect_t *rect)
{
	RT_ASSERT(view != RT_NULL);
	RT_ASSERT(rect != RT_NULL);

	rtgui_widget_get_rect(RTGUI_WIDGET(view), rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(view), rect);
	/* 去除演示标题和下方按钮的区域 */
	rect->y1 += 45;
	rect->y2 -= 35;
}
Exemplo n.º 10
0
static void _rtgui_notebook_onmouse(struct rtgui_notebook *notebook, struct rtgui_event_mouse* emouse)
{
	rtgui_rect_t rect;

	/* handle notebook bar */
	_rtgui_notebook_get_bar_rect(notebook, &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
	if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
	{
		int index;
		struct rtgui_dc* dc;

		if (notebook->flag == RTGUI_NOTEBOOK_BOTTOM || notebook->flag == RTGUI_NOTEBOOK_TOP)
		{
			index = (emouse->x - rect.x1) / notebook->tab_w;
			if (index < notebook->count && index != notebook->current)
			{
				/* update tab bar */
				dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
				if (dc == RT_NULL) return;

				rtgui_notebook_set_current_by_index(notebook, index);

				_rtgui_notebook_draw_bar(notebook, dc);

				rtgui_dc_end_drawing(dc);
			}
		}
		else
		{
			index = (emouse->y - rect.y1) / notebook->tab_h;
			if (index < notebook->count && index != notebook->current)
			{
				/* update tab bar */
				dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
				if (dc == RT_NULL) return;

				rtgui_notebook_set_current_by_index(notebook, index);
				_rtgui_notebook_draw_bar(notebook, dc);
				
				rtgui_dc_end_drawing(dc);
			}
		}
	}
	else
	{
		/* handle on page */
		if (RTGUI_OBJECT(notebook->childs[notebook->current].widget)->event_handler != RT_NULL)
			RTGUI_OBJECT(notebook->childs[notebook->current].widget)->event_handler(
					RTGUI_OBJECT(notebook->childs[notebook->current].widget),
					&(emouse->parent));
	}
}
Exemplo n.º 11
0
rtgui_fileview_t* rtgui_fileview_create(pvoid parent, const char* directory, const char* pattern, int left, int top, int w, int h)
{
	rtgui_container_t *container;
	rtgui_fileview_t* fview = RT_NULL;

	RT_ASSERT(parent != RT_NULL);
	container = RTGUI_CONTAINER(parent);

	/* create a new view */
	fview = rtgui_widget_create(RTGUI_FILEVIEW_TYPE);

	if(fview != RT_NULL)
	{
		rtgui_rect_t rect;

		rtgui_widget_get_rect(container, &rect);
		rtgui_widget_rect_to_device(container,&rect);
		rect.x1 += left;
		rect.y1 += top;
		rect.x2 = rect.x1+w;
		rect.y2 = rect.y1+h;

		fview->items = RT_NULL;
		fview->pattern = rt_strdup(pattern);
		fview->item_per_page = RC_H(rect) / (1 + RTGUI_SEL_H);

		rtgui_widget_set_rect(fview,&rect);
		rtgui_container_add_child(container, fview);

		{
			/* create scrollbar */
			rt_uint32_t sLeft,sTop,sw=RTGUI_DEFAULT_SB_WIDTH,sLen;
			sLeft = RC_W(rect)-RTGUI_WIDGET_BORDER_SIZE(fview)-sw;
			sTop = RTGUI_WIDGET_BORDER_SIZE(fview);

			sLen = rect.y2-rect.y1-RTGUI_WIDGET_BORDER_SIZE(fview)*2;
			fview->sbar = rtgui_scrollbar_create(fview,sLeft,sTop,sw,sLen,RTGUI_VERTICAL);
			if(fview->sbar != RT_NULL)
			{
				fview->sbar->widget_link = fview;
				fview->sbar->on_scroll = rtgui_fileview_sbar_handle;
				RTGUI_WIDGET_HIDE(fview->sbar);/* default hid scrollbar */
			}
		}

		rtgui_fileview_set_directory(fview, directory);
	}

	return fview;
}
Exemplo n.º 12
0
static void rtgui_radiobox_onmouse(struct rtgui_radiobox *radiobox, struct rtgui_event_mouse *event)
{
    RT_ASSERT(radiobox != RT_NULL);
    RT_ASSERT(event  != RT_NULL);

    /* widget is hide, return */
    if (RTGUI_WIDGET_IS_HIDE(radiobox) ||
            !RTGUI_WIDGET_IS_ENABLE(radiobox)) return;

    if (event->button & RTGUI_MOUSE_BUTTON_DOWN &&
            event->button & RTGUI_MOUSE_BUTTON_LEFT)
    {
        int bord_size;
        struct rtgui_rect rect;

        /* focus widgets */
        rtgui_widget_focus(RTGUI_WIDGET(radiobox));

        /* get widget physical rect */
        rtgui_widget_get_rect(RTGUI_WIDGET(radiobox), &rect);
        rtgui_widget_rect_to_device(RTGUI_WIDGET(radiobox), &rect);

        /* get board size */
        if (radiobox->orient == RTGUI_VERTICAL)
            bord_size = radiobox->item_size;
        else
        {
            struct rtgui_rect bord_rect;

            rtgui_font_get_metrics(RTGUI_WIDGET_FONT(radiobox), "H", &bord_rect);
            bord_size = rtgui_rect_height(bord_rect);
        }
        rtgui_rect_inflate(&rect, - bord_size);
        if (rtgui_rect_contains_point(&rect, event->x, event->y) != RT_EOK) return;

        if (radiobox->orient == RTGUI_VERTICAL)
        {
            int delta_y = event->y - rect.y1;
            rtgui_radiobox_set_selection(radiobox, delta_y / radiobox->item_size);
        }
        else
        {
            int delta_x = event->x - rect.x1;
            rtgui_radiobox_set_selection(radiobox, delta_x / radiobox->item_size);
        }
    }
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
0
rtgui_scrollbar_t* rtgui_scrollbar_create(rtgui_container_t *container,int left,int top,int w,int len,int orient)
{
	rtgui_scrollbar_t* bar;

	RT_ASSERT(container != RT_NULL);

	bar = (rtgui_scrollbar_t *)rtgui_widget_create(RTGUI_SCROLLBAR_TYPE);
	if(bar != RT_NULL)
	{
		rtgui_rect_t rect;

		rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(container),&rect);
		rect.x1 += left;
		rect.y1 += top;

		bar->thumb_w = w;
		if(orient == RTGUI_VERTICAL)
		{
			rect.x2 = rect.x1+w;
			rect.y2 = rect.y1+len;
		}
		else
		{
			rect.x2 = rect.x1+len;
			rect.y2 = rect.y1+w;
		}

		rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);

		bar->orient = orient;

		rtgui_container_add_child(container, RTGUI_WIDGET(bar));
	}

	return bar;
}
Exemplo n.º 15
0
static void function_action_setup(struct rtgui_widget* widget, void* paramter)
{
    rtgui_view_t* view;
    rtgui_rect_t rect;
    rtgui_label_t* label;
    struct rtgui_button* cancel_button, *apply_button, *save_button;
    rtgui_workbench_t* workbench = father_workbench;

    /* create a demo view */
    view = rtgui_view_create("Slider View");
    /* 添加到父workbench中 */
    rtgui_workbench_add_view(workbench, view);

    //设置服务函数
    rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler);

    /* get demo view rect */
    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
    rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
    label = rtgui_label_create("默认音量:");
    rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
    rect.x1 += 5; rect.x2 -= 5;
    rect.y1 += 5; rect.y2 = rect.y1 + 18;
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);

    rect.y1 += 20; rect.y2 = rect.y1 + 18;
    slider_volume = rtgui_slider_create(0, 100, RTGUI_HORIZONTAL);
    rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(slider_volume));
    rtgui_widget_set_rect(RTGUI_WIDGET(slider_volume), &rect);
    rtgui_slider_set_value(slider_volume, radio_setup.default_volume);


    /* get demo view rect */
    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
    rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
    label = rtgui_label_create("LCD背光亮度:");
    rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
    rect.x1 += 5; rect.x2 -= 5;
    rect.y1 += 50; rect.y2 = rect.y1 + 18;
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);

    rect.y1 += 20; rect.y2 = rect.y1 + 18;
    slider_brightness = rtgui_slider_create(0, 100, RTGUI_HORIZONTAL);
    rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(slider_brightness));
    rtgui_widget_set_rect(RTGUI_WIDGET(slider_brightness), &rect);
    rtgui_slider_set_value(slider_brightness, radio_setup.lcd_brightness);

    //得到 "取消" 按键的位置
    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
    rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
    rect.x1 += 20;
    rect.x2 = rect.x1 + 60;
    rect.y2 -= 20;
    rect.y1 = rect.y2 - 20;

    //创建 "取消" 按钮(兼返回)
    cancel_button = rtgui_button_create("取消");
    /* 设置onbutton动作到demo_view_next函数 */
    rtgui_button_set_onbutton(cancel_button, cancel_handler);
    /* 设置按钮的位置信息 */
    rtgui_widget_set_rect(RTGUI_WIDGET(cancel_button), &rect);
    /* 添加按钮到视图中 */
    rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(cancel_button));


    rect.x1 = rect.x2 + 10;
    rect.x2 = rect.x1 + 60;
    apply_button = rtgui_button_create("应用");
    /* 设置onbutton动作到demo_view_next函数 */
    rtgui_button_set_onbutton(apply_button, apply_handler);
    /* 设置按钮的位置信息 */
    rtgui_widget_set_rect(RTGUI_WIDGET(apply_button), &rect);
    /* 添加按钮到视图中 */
    rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(apply_button));


    //得到 "保存" 按键的位置
    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
    rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
    rect.x2 -= 20;
    rect.x1 = rect.x2 - 60;
    rect.y2 -= 20;
    rect.y1 = rect.y2 - 20;

    /* 创建 "保存" 按钮 */
    save_button = rtgui_button_create("保存");
    /* 设置onbutton动作到demo_view_prev函数 */
    rtgui_button_set_onbutton(save_button, save_handler);
    /* 设置按钮的位置信息 */
    rtgui_widget_set_rect(RTGUI_WIDGET(save_button), &rect);
    /* 添加按钮到视图中 */
    rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(save_button));

    rtgui_view_show(view, RT_FALSE);
}
Exemplo n.º 16
0
static rt_bool_t rtgui_list_view_onmouse(struct rtgui_list_view* view, struct rtgui_event_mouse* emouse)
{
	rtgui_rect_t rect;

	/* calculate selected item */

	/* get physical extent information */
	rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);

	if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
	{
		rt_uint16_t index;
		rt_uint16_t old_item;

		/* get old item */
		old_item = view->current_item;

		switch (view->flag)
		{
		case RTGUI_LIST_VIEW_LIST:
			index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());

			if ((index < view->items_count) && (index < view->page_items))
			{
				/* set selected item */
				view->current_item = (view->current_item/view->page_items) * view->page_items + index;
				if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
				{
					/* down event */
					rtgui_list_view_update_list(view, old_item);
				}
				else
				{
					/* up event */
					if (view->items[view->current_item].action != RT_NULL)
					{
						view->items[view->current_item].action(view->items[view->current_item].parameter);
					}
				}
			}
			break;

		case RTGUI_LIST_VIEW_ICON:
			{
				rt_uint16_t x, y;
				rt_uint16_t item_height, item_width;
				rt_ubase_t current_page;

				item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN)/view->col_items;
				item_height = (rtgui_rect_height(rect) - 4)/view->row_items;
				x = emouse->x - rect.x1;
				y = emouse->y - rect.y1;

				index = (y / item_height * view->col_items) + x / item_width;
				current_page = view->current_item / view->page_items;

				if ((index + (current_page * view->page_items) < view->items_count))
				{
					if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
					{
						view->current_item = index + (current_page * view->page_items);

						/* down event */
						rtgui_list_view_update_icon(view, old_item);
					}
					else
					{
						/* up event */
						if (view->items[view->current_item].action != RT_NULL)
						{
							view->items[view->current_item].action(view->items[view->current_item].parameter);
						}
					}
				}
			}
			break;

		case RTGUI_LIST_VIEW_REPORT:
			break;
		}

		return RT_TRUE;
	}

	return RT_FALSE;
}
Exemplo n.º 17
0
rtgui_container_t *demo_view(const char *title)
{
    struct rtgui_container  *container;
    struct rtgui_label      *label;
    struct rtgui_staticline *line;
    struct rtgui_button     *next_btn, *prev_btn;
    struct rtgui_rect       rect;

    container = rtgui_container_create();
    if (container == RT_NULL)
        return RT_NULL;

    rtgui_notebook_add(the_notebook, title, RTGUI_WIDGET(container));

    /* 获得视图的位置信息(在加入到 notebook 中时,notebook 会自动调整 container
     * 的大小) */
    rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
    rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
    rect.x1 += 5;
    rect.y1 += 5;
    rect.x2 = rect.x1 + rt_strlen(title)*8;
    rect.y2 = rect.y1 + 20;

    /* 创建标题用的标签 */
    label = rtgui_label_create(title);
    /* 设置标签位置信息 */
    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
    /* 添加标签到视图中 */
    rtgui_container_add_child(container, RTGUI_WIDGET(label));
	
	rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
    rect.y1 += 20 + 5;
    rect.y2 = rect.y1 + 2;
    /* 创建一个水平的 staticline 线 */
    line = rtgui_staticline_create(RTGUI_HORIZONTAL);
    /* 设置静态线的位置信息 */
    rtgui_widget_set_rect(RTGUI_WIDGET(line), &rect);
    /* 添加静态线到视图中 */
    rtgui_container_add_child(container, RTGUI_WIDGET(line));

    /* 获得视图的位置信息 */
    rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
    rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
    rect.x2 -= 5;
    rect.y2 -= 5;
    rect.x1 = rect.x2 - 100;
    rect.y1 = rect.y2 - 25;

    /* 创建"下一个"按钮 */
    next_btn = rtgui_button_create("下一个");
    /* 设置onbutton动作到demo_view_next函数 */
    rtgui_button_set_onbutton(next_btn, demo_view_next);
    /* 设置按钮的位置信息 */
    rtgui_widget_set_rect(RTGUI_WIDGET(next_btn), &rect);
    /* 添加按钮到视图中 */
    rtgui_container_add_child(container, RTGUI_WIDGET(next_btn));

    /* 获得视图的位置信息 */
    rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
    rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
    rect.x1 += 5;
    rect.y2 -= 5;
    rect.x2 = rect.x1 + 100;
    rect.y1 = rect.y2 - 25;

    /* 创建"上一个"按钮 */
    prev_btn = rtgui_button_create("上一个");
    /* 设置onbutton动作到demo_view_prev函数 */
    rtgui_button_set_onbutton(prev_btn, demo_view_prev);
    /* 设置按钮的位置信息 */
    rtgui_widget_set_rect(RTGUI_WIDGET(prev_btn), &rect);
    /* 添加按钮到视图中 */
    rtgui_container_add_child(container, RTGUI_WIDGET(prev_btn));

    /* 返回创建的视图 */
    return container;
}
Exemplo n.º 18
0
rt_bool_t rtgui_listbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	struct rtgui_listbox* box = RT_NULL;

	box = RTGUI_LISTBOX(widget);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		rtgui_listbox_ondraw(box);
		return RT_FALSE;

    case RTGUI_EVENT_RESIZE:
        {
			struct rtgui_event_resize* resize;

			resize = (struct rtgui_event_resize*)event;

            /* recalculate page items */
			box->page_items = resize->h  / (2 + rtgui_theme_get_selected_height());
        }
        break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		{
			rtgui_rect_t rect;
			struct rtgui_event_mouse* emouse;

			emouse = (struct rtgui_event_mouse*)event;

			/* calculate selected item */

			/* get physical extent information */
			rtgui_widget_get_rect(widget, &rect);
			rtgui_widget_rect_to_device(widget, &rect);

			if ((rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK) && (box->items_count > 0))
			{
				rt_uint16_t index;
				index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());

				/* set focus */
				rtgui_widget_focus(widget);
				{
					struct rtgui_rect rect;
					struct rtgui_dc* dc;

					dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
					if (dc != RT_NULL)
					{
						/* get widget rect */
						rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
						/* update focus border */
						rect.x2 -= 1; rect.y2 -= 1;
						/* draw focused border */
						if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(box)))
							rtgui_dc_draw_focus_rect(dc, &rect);
						rtgui_dc_end_drawing(dc);
					}
				}

				if ((index < box->items_count) && (index < box->page_items))
				{
					rt_uint16_t old_item;

					old_item = box->current_item;

					/* set selected item */
					box->current_item = (box->current_item/box->page_items) * box->page_items + index;
					if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
					{
						/* down event */
						rtgui_listbox_update_current(box, old_item);
					}
					else
					{
						/* up event */
						if (box->on_item != RT_NULL)
						{
							box->on_item(RTGUI_WIDGET(box), RT_NULL);
						}
					}
				}
			}

			return RT_TRUE;
		}

    case RTGUI_EVENT_KBD:
        {
            struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
            if ((ekbd->type == RTGUI_KEYDOWN) && (box->items_count > 0))
            {
				rt_uint16_t old_item;

				old_item = box->current_item;
                switch (ekbd->key)
                {
				case RTGUIK_LEFT:
					if (box->current_item - box->page_items >= 0)
						box->current_item -= box->page_items;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

                case RTGUIK_UP:
					if (box->current_item > 0)
						box->current_item --;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

				case RTGUIK_RIGHT:
					if (box->current_item + box->page_items < box->items_count - 1)
						box->current_item += box->page_items;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

                case RTGUIK_DOWN:
					if (box->current_item < box->items_count - 1)
						box->current_item ++;
					rtgui_listbox_update_current(box, old_item);
					return RT_FALSE;

				case RTGUIK_RETURN:
                    if (box->on_item != RT_NULL)
					{
						box->on_item(RTGUI_WIDGET(box), RT_NULL);
					}
					return RT_FALSE;

                default:
                    break;
                }
            }
        }
		return RT_FALSE;
	}

    /* use box event handler */
    return rtgui_widget_event_handler(widget, event);
}
Exemplo n.º 19
0
/* blit a dc to another dc */
static void rtgui_dc_buffer_blit(struct rtgui_dc *self,
                                 struct rtgui_point *dc_pt,
                                 struct rtgui_dc *dest,
                                 rtgui_rect_t *rect)
{
    int pitch;
    rt_uint16_t rect_width, rect_height;
    struct rtgui_rect _rect, *dest_rect;
    struct rtgui_point dc_point;
    struct rtgui_dc_buffer *dc = (struct rtgui_dc_buffer *)self;

    if (rtgui_dc_get_visible(dest) == RT_FALSE)
        return;

    /* use the (0,0) origin point */
    if (dc_pt == RT_NULL)
        dc_point = rtgui_empty_point;
    else
    {
        dc_point = *dc_pt;
    }

    rtgui_dc_get_rect(dest, &_rect);
    /* use the rect of dest dc */
    if (rect == RT_NULL)
    {
        dest_rect = &_rect;
    }
    else
    {
        dest_rect = rect;
        if (dest_rect->x1 >= _rect.x2 || dest_rect->y1 >= _rect.y2)
            return;
        if (dest_rect->x1 < 0)
        {
            if (-dest_rect->x1 >= dc->width)
                return;
            dc_point.x += -dest_rect->x1;
            dest_rect->x1 = 0;
        }
        if (dest_rect->y1 < 0)
        {
            if (-dest_rect->y1 >= dc->height)
                return;
            dc_point.y += -dest_rect->y1;
            dest_rect->y1 = 0;
        }
        if (dest_rect->x2 > _rect.x2)
            dest_rect->x2 = _rect.x2;
        if (dest_rect->y2 > _rect.y2)
            dest_rect->y2 = _rect.y2;
    }

    if (dest_rect->x2 < dest_rect->x1 || dest_rect->y2 < dest_rect->y1) return;
    if (dc_point.x >= dc->width || dc_point.y >= dc->height) return;

    /* get the minimal width and height */
    rect_width  = _UI_MIN(rtgui_rect_width(*dest_rect), dc->width - dc_point.x);
    rect_height = _UI_MIN(rtgui_rect_height(*dest_rect), dc->height - dc_point.y);

    if ((dest->type == RTGUI_DC_HW) || (dest->type == RTGUI_DC_CLIENT))
    {
        int index;
        rt_uint8_t *line_ptr, *pixels;
        rtgui_blit_line_func blit_line;
        struct rtgui_graphic_driver *hw_driver;

        hw_driver = rtgui_graphic_driver_get_default();
        /* prepare pixel line */
        pixels = _dc_get_pixel(dc, dc_point.x, dc_point.y);

        if (dest->type == RTGUI_DC_HW && hw_driver->framebuffer != RT_NULL)
        {
            /* use rtgui_blit */

            struct rtgui_blit_info info = { 0 };
            struct rtgui_widget *owner;

            if (self->type == RTGUI_DC_BUFFER)
                info.a = dc->pixel_alpha;
            else
                info.a = 255;

            /* blit source */
            info.src = _dc_get_pixel(dc, dc_point.x, dc_point.y);
            info.src_fmt = dc->pixel_format;
            info.src_h = rect_height;
            info.src_w = rect_width;
            info.src_pitch = dc->pitch;
            info.src_skip = info.src_pitch - info.src_w * rtgui_color_get_bpp(dc->pixel_format);

            owner = ((struct rtgui_dc_hw*)dest)->owner;

            /* blit destination */
            info.dst = (rt_uint8_t*)hw_driver->framebuffer;
            info.dst = info.dst + (owner->extent.y1 + dest_rect->y1) * hw_driver->pitch +
                       (owner->extent.x1 + dest_rect->x1) * rtgui_color_get_bpp(hw_driver->pixel_format);
            info.dst_fmt = hw_driver->pixel_format;
            info.dst_h = rect_height;
            info.dst_w = rect_width;
            info.dst_pitch = hw_driver->pitch;
            info.dst_skip = info.dst_pitch - info.dst_w * rtgui_color_get_bpp(hw_driver->pixel_format);

            rtgui_blit(&info);
        }
        else if (dest->type == RTGUI_DC_CLIENT&& hw_driver->framebuffer != RT_NULL)
        {
            /* use rtgui_blit */
            rt_uint8_t bpp, hw_bpp;
            struct rtgui_blit_info info = { 0 };
            struct rtgui_widget *owner;
            struct rtgui_region dest_region;
            struct rtgui_rect dest_extent;
            int num_rects;
            struct rtgui_rect *rects;

            /* get owner */
            owner = RTGUI_CONTAINER_OF(dest, struct rtgui_widget, dc_type);

            dest_extent = *dest_rect;
            rtgui_widget_rect_to_device(owner, &dest_extent);

            rtgui_region_init_with_extents(&dest_region, &dest_extent);
            rtgui_region_intersect_rect(&dest_region, &(owner->clip), &dest_extent);
            bpp = rtgui_color_get_bpp(dc->pixel_format);
            hw_bpp = rtgui_color_get_bpp(hw_driver->pixel_format);

            num_rects = rtgui_region_num_rects(&dest_region);
            rects = rtgui_region_rects(&dest_region);

            /* common info */
            if (self->type == RTGUI_DC_BUFFER)
                info.a = dc->pixel_alpha;
            else
                info.a = 255;
            info.src_fmt = dc->pixel_format;
            info.src_pitch = dc->pitch;

            info.dst_fmt = hw_driver->pixel_format;
            info.dst_pitch = hw_driver->pitch;

            for (index = 0; index < num_rects; index ++)
            {
                struct rtgui_rect *r = &rects[index];

                /* blit source */
                info.src = _dc_get_pixel(dc, dc_point.x + (r->x1 - dest_extent.x1),
                                         dc_point.y + (r->y1 - dest_extent.y1));
                info.src_h = rtgui_rect_height(*r);
                info.src_w = rtgui_rect_width(*r);
                info.src_skip = info.src_pitch - info.src_w * bpp;

                /* blit destination */
                info.dst = (rt_uint8_t*)hw_driver->framebuffer + r->y1 * hw_driver->pitch +
                           r->x1 * hw_bpp;
                info.dst_h = rtgui_rect_height(*r);
                info.dst_w = rtgui_rect_width(*r);
                info.dst_skip = info.dst_pitch - info.dst_w * hw_bpp;

                rtgui_blit(&info);
            }

            rtgui_region_fini(&dest_region);
        }
Exemplo n.º 20
0
rtgui_combo_t* rtgui_combo_create(pvoid parent,const char* text,int left,int top,int w,int h)
{
	rtgui_container_t *container;
	rtgui_combo_t* cbo;

	RT_ASSERT(parent != RT_NULL);
	container = RTGUI_CONTAINER(parent);

	cbo = rtgui_widget_create(RTGUI_COMBO_TYPE);
	if(cbo != RT_NULL)
	{
		rtgui_rect_t rect;

		rtgui_widget_get_rect(container, &rect);
		rtgui_widget_rect_to_device(container,&rect);
		rect.x1 += left;
		rect.y1 += top;
		rect.x2 = rect.x1+w;
		rect.y2 = rect.y1+RTGUI_COMBO_HEIGHT;
		rtgui_widget_set_rect(cbo,&rect);

		rtgui_container_add_child(container, cbo);

		if(cbo->tbox == RT_NULL)
		{
			int tw,th;
			tw = w-RTGUI_COMBO_BUTTON_WIDTH-RTGUI_WIDGET_BORDER_SIZE(cbo)*2;
			th = h-RTGUI_WIDGET_BORDER_SIZE(cbo)*2;
			cbo->tbox = rtgui_textbox_create(cbo,text,
			                                 RTGUI_WIDGET_BORDER_SIZE(cbo),
			                                 RTGUI_WIDGET_BORDER_SIZE(cbo),
			                                 tw,th,RTGUI_TEXTBOX_NONE);

			if(cbo->tbox == RT_NULL) return RT_NULL;
			rtgui_widget_set_border_style(cbo->tbox,RTGUI_BORDER_NONE);
			cbo->tbox->isedit = RT_FALSE;/* default combo textbox cannot edit */
		}
		if(cbo->lbox == RT_NULL)
		{
			rtgui_point_t point;
			rt_uint32_t mleft,mtop,mwidth;

			rtgui_widget_get_position(cbo, &point);
			mleft = point.x;
			mtop = point.y+RTGUI_COMBO_HEIGHT;
			mwidth = rtgui_widget_get_width(cbo);

			/* create pull down listbox */
			cbo->lbox = rtgui_listbox_create(parent,mleft,mtop,mwidth,4);
			if(cbo->lbox == RT_NULL)return RT_NULL;
			rtgui_widget_set_border_style(cbo->lbox,RTGUI_BORDER_SIMPLE);
			cbo->lbox->ispopup = RT_TRUE;
			cbo->lbox->widget_link = cbo;
			rtgui_listbox_set_onitem(cbo->lbox,rtgui_combo_onitem);

			RTGUI_WIDGET_HIDE(cbo->lbox);
		}
	}

	return cbo;
}
Exemplo n.º 21
0
rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
    struct rtgui_widget *widget;
    struct rtgui_filelist_view *view = RT_NULL;

    widget = RTGUI_WIDGET(object);
    view = RTGUI_FILELIST_VIEW(widget);
    switch (event->type)
    {
    case RTGUI_EVENT_PAINT:
        rtgui_filelist_view_ondraw(view);
        return RT_FALSE;

    case RTGUI_EVENT_RESIZE:
    {
        struct rtgui_event_resize *resize;

        resize = (struct rtgui_event_resize *)event;

        /* recalculate page items */
        if (file_image != RT_NULL)
            view->page_items = resize->h  / (1 + rtgui_theme_get_selected_height());
        else
            view->page_items = resize->h / (2 + 14);
        if (view->page_items == 0)
            view->page_items = 1;
    }
    break;

    case RTGUI_EVENT_MOUSE_BUTTON:
    {
        rtgui_rect_t rect;
        struct rtgui_event_mouse *emouse;

        emouse = (struct rtgui_event_mouse *)event;

        /* calculate selected item */

        /* get physical extent information */
        rtgui_widget_get_rect(widget, &rect);
        rtgui_widget_rect_to_device(widget, &rect);

        if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
        {
            rt_uint16_t index;
            rt_uint16_t current_page;
            rt_uint16_t old_item;

            index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());

            /* get current page */
            current_page = view->current_item / view->page_items;
            old_item = view->current_item;

            if (index + current_page * view->page_items < view->items_count)
            {
                /* set selected item */
                view->current_item = index + current_page * view->page_items;
                if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
                {
                    rtgui_filelist_view_update_current(view, old_item);
                }
                else
                {
                    /* up event */
                    rtgui_filelist_view_onenturn(view);
                }
            }

            return RT_TRUE;
        }
    }
    break;

    case RTGUI_EVENT_KBD:
    {
        struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
        if (ekbd->type == RTGUI_KEYDOWN)
        {
            rt_uint16_t old_item;

            old_item = view->current_item;
            switch (ekbd->key)
            {
            case RTGUIK_UP:
                if (view->current_item > 0)
                    view->current_item --;
                rtgui_filelist_view_update_current(view, old_item);
                return RT_TRUE;

            case RTGUIK_DOWN:
                if (view->current_item < view->items_count - 1)
                    view->current_item ++;
                rtgui_filelist_view_update_current(view, old_item);
                return RT_TRUE;

            case RTGUIK_LEFT:
                if (view->current_item - view->page_items >= 0)
                    view->current_item -= view->page_items;
                rtgui_filelist_view_update_current(view, old_item);
                return RT_TRUE;

            case RTGUIK_RIGHT:
                if (view->current_item + view->page_items < view->items_count - 1)
                    view->current_item += view->page_items;
                rtgui_filelist_view_update_current(view, old_item);
                return RT_TRUE;

            case RTGUIK_RETURN:
                rtgui_filelist_view_onenturn(view);
                return RT_TRUE;

            default:
                break;
            }
        }
    }
    return RT_FALSE;
    }

    /* use view event handler */
    return rtgui_container_event_handler(object, event);
}
Exemplo n.º 22
0
/* 创建一个演示视图,需提供父workbench和演示用的标题 */
rtgui_view_t* demo_view(rtgui_workbench_t* workbench, const char* title)
{
	struct rtgui_view* view;

	/* 设置视图的名称 */
	view = rtgui_view_create(title);
	if (view == RT_NULL) return RT_NULL;

	/* 创建成功后,添加到数组中 */
	demo_view_list[demo_view_number] = view;
	demo_view_number ++;

	/* 添加到父workbench中 */
	rtgui_workbench_add_view(workbench, view);

	/* 添加下一个视图和前一个视图按钮 */
	{
		struct rtgui_rect rect;
		struct rtgui_button *next_btn, *prev_btn;
		struct rtgui_label *label;
		struct rtgui_staticline *line;

		/* 获得视图的位置信息(在加入到workbench中时,workbench会自动调整视图的大小) */
		rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
		rect.x1 += 5;
		rect.y1 += 5;
		rect.x2 -= 5;
		rect.y2 = rect.y1 + 20;

		/* 创建标题用的标签 */
		label = rtgui_label_create(title);
		/* 设置标签位置信息 */
		rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
		/* 添加标签到视图中 */
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));

		rect.y1 += 20;
		rect.y2 += 20;
		/* 创建一个水平的staticline线 */
		line = rtgui_staticline_create(RTGUI_HORIZONTAL);
		/* 设置静态线的位置信息 */
		rtgui_widget_set_rect(RTGUI_WIDGET(line), &rect);
		/* 添加静态线到视图中 */
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(line));

		/* 获得视图的位置信息 */
		rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
		rect.x2 -= 5;
		rect.y2 -= 5;
		rect.x1 = rect.x2 - 100;
		rect.y1 = rect.y2 - 25;

		/* 创建"下一个"按钮 */
		next_btn = rtgui_button_create("下一个");
		/* 设置onbutton动作到demo_view_next函数 */
		rtgui_button_set_onbutton(next_btn, demo_view_next);
		/* 设置按钮的位置信息 */
		rtgui_widget_set_rect(RTGUI_WIDGET(next_btn), &rect);
		/* 添加按钮到视图中 */
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(next_btn));

		/* 获得视图的位置信息 */
		rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
		rect.x1 += 5;
		rect.y2 -= 5;
		rect.x2 = rect.x1 + 100;
		rect.y1 = rect.y2 - 25;

		/* 创建"上一个"按钮 */
		prev_btn = rtgui_button_create("上一个");
		/* 设置onbutton动作到demo_view_prev函数 */
		rtgui_button_set_onbutton(prev_btn, demo_view_prev);
		/* 设置按钮的位置信息 */
		rtgui_widget_set_rect(RTGUI_WIDGET(prev_btn), &rect);
		/* 添加按钮到视图中 */
		rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(prev_btn));
	}

	/* 返回创建的视图 */
	return view;
}
Exemplo n.º 23
0
rt_bool_t rtgui_fileview_event_handler(pvoid wdt, rtgui_event_t* event)
{
	rtgui_widget_t *widget = RTGUI_WIDGET(wdt);
	rtgui_fileview_t* fview = RTGUI_FILEVIEW(wdt);

	switch(event->type)
	{
	case RTGUI_EVENT_PAINT:
		rtgui_fileview_ondraw(fview);
		return RT_FALSE;

	case RTGUI_EVENT_MOUSE_BUTTON:
	{
		rtgui_rect_t rect;
		struct rtgui_event_mouse* emouse;

		emouse = (struct rtgui_event_mouse*)event;

		rtgui_widget_focus(fview);
		/* get physical extent information */
		rtgui_widget_get_rect(fview, &rect);
		rtgui_widget_rect_to_device(fview, &rect);

		if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview->sbar))
			rect.x2 -= RC_W(fview->sbar->parent.extent);

		if((rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK) && fview->item_count>0)
		{
			rt_uint16_t i;

			/* set focus */
			rtgui_widget_focus(fview);

			i = (emouse->y - rect.y1) / (2 + RTGUI_SEL_H);

			if((i < fview->item_count) && (i < fview->item_per_page))
			{
				if(emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
				{
					fview->old_item = fview->now_item;
					fview->now_item = fview->first_item + i;
					rtgui_fileview_update_current(fview);
				}
				else if(emouse->button & RTGUI_MOUSE_BUTTON_UP)
				{
					if(fview->now_item==fview->old_item) return RT_FALSE;

					rtgui_fileview_update_current(fview);
				}
				if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview))
				{
					if(!RTGUI_WIDGET_IS_HIDE(fview->sbar))
						rtgui_scrollbar_set_value(fview->sbar,fview->first_item);
				}
			}
		}
		rtgui_container_dispatch_mouse_event(fview, emouse);
		return RT_TRUE;
	}

	case RTGUI_EVENT_KBD:
	{
		struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd*)event;
		if(RTGUI_KBD_IS_DOWN(ekbd))
		{
			switch(ekbd->key)
			{
			case RTGUIK_UP:
				if(fview->now_item > 0)
				{
					fview->old_item = fview->now_item;
					fview->now_item --;

					if(fview->now_item < fview->first_item)
					{
						/* turn up page */
						fview->first_item = fview->now_item;
						rtgui_fileview_ondraw(fview);
					}
					else
					{
						/* current page */
						rtgui_fileview_update_current(fview);
					}

					if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview))
					{
						if(!RTGUI_WIDGET_IS_HIDE(fview->sbar))
							rtgui_scrollbar_set_value(fview->sbar,fview->first_item);
					}
				}
				return RT_TRUE;

			case RTGUIK_DOWN:
				if(fview->now_item < fview->item_count-1)
				{
					fview->old_item = fview->now_item;
					fview->now_item ++;

					if(fview->now_item >= fview->first_item+fview->item_per_page)
					{
						/* turn down page */
						fview->first_item++;
						rtgui_fileview_ondraw(fview);
					}
					else
					{
						/* in current page */
						rtgui_fileview_update_current(fview);
					}
					if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview))
					{
						if(!RTGUI_WIDGET_IS_HIDE(fview->sbar))
							rtgui_scrollbar_set_value(fview->sbar,fview->first_item);
					}
				}
				return RT_TRUE;

			case RTGUIK_LEFT:
				if(fview->item_count==0)return RT_FALSE;
				fview->old_item = fview->now_item;
				fview->now_item -= fview->item_per_page;

				if(fview->now_item < 0)
					fview->now_item = 0;

				if(fview->now_item < fview->first_item)
				{
					fview->first_item = fview->now_item;
					rtgui_fileview_ondraw(fview);
				}
				else
				{
					rtgui_fileview_update_current(fview);
				}
				if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview))
				{
					if(!RTGUI_WIDGET_IS_HIDE(fview->sbar))
						rtgui_scrollbar_set_value(fview->sbar,fview->first_item);
				}
				return RT_TRUE;

			case RTGUIK_RIGHT:
				if(fview->item_count==0)return RT_FALSE;
				fview->old_item = fview->now_item;
				fview->now_item += fview->item_per_page;

				if(fview->now_item > fview->item_count-1)
					fview->now_item = fview->item_count-1;

				if(fview->now_item >= fview->first_item+fview->item_per_page)
				{
					fview->first_item += fview->item_per_page;
					if(fview->first_item >fview->item_count-fview->item_per_page)
					{
						fview->first_item = fview->item_count-fview->item_per_page;
						fview->now_item = fview->first_item;
					}
					rtgui_fileview_ondraw(fview);
				}
				else
				{
					rtgui_fileview_update_current(fview);
				}
				if(fview->sbar && !RTGUI_WIDGET_IS_HIDE(fview))
				{
					if(!RTGUI_WIDGET_IS_HIDE(fview->sbar))
						rtgui_scrollbar_set_value(fview->sbar,fview->first_item);
				}
				return RT_TRUE;

			case RTGUIK_RETURN:
				rtgui_fileview_on_enter(fview, event);
				return RT_TRUE;
			case RTGUIK_BACKSPACE:
				rtgui_fileview_goto_topfolder(fview);
				return RT_TRUE;
			default:
				break;
			}
		}
	}
	return RT_FALSE;
	default:
		return rtgui_container_event_handler(widget, event);
	}
}
Exemplo n.º 24
0
Arquivo: edit.c Projeto: amsl/RTGUI
struct rtgui_edit* rtgui_edit_create(pvoid parent, int left, int top, int w, int h)
{
	struct rtgui_container* container;
	struct rtgui_edit* edit;

	RT_ASSERT(parent != RT_NULL);
	container = RTGUI_CONTAINER(parent);

	edit = (struct rtgui_edit*)rtgui_widget_create(RTGUI_EDIT_TYPE);
	if(edit != RT_NULL)
	{
		rtgui_rect_t rect;
		int effe;
		rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(container),&rect);
		rect.x1 += left;
		rect.y1 += top;
		rect.x2 = rect.x1+w;
		rect.y2 = rect.y1+h;
		rtgui_widget_set_rect(RTGUI_WIDGET(edit),&rect);
		rtgui_container_add_child(container, RTGUI_WIDGET(edit));

		/* set character number */
		edit->item_height = edit->font_height; /* the same height */
		effe = h-(edit->margin + RTGUI_WIDGET_BORDER_SIZE(edit))*2;
		edit->row_per_page = effe / edit->item_height;
		if(effe % edit->item_height)
			edit->row_per_page += 1;
		
		effe = w-(edit->margin + RTGUI_WIDGET_BORDER_SIZE(edit))*2;
		edit->col_per_page = effe / edit->font_width;
		if(effe % edit->font_width)
			edit->col_per_page += 1;
		edit->update_buf = rtgui_malloc(edit->col_per_page + 1);

#ifdef RTGUI_EDIT_USING_SCROLL
		if(edit->hscroll == RT_NULL && edit->flag & RTGUI_EDIT_HSCROLL)
		{
			/* create horizontal scrollbar */
			rt_uint32_t _left,_top,_width=RTGUI_DEFAULT_SB_WIDTH,_len;
			_left = RTGUI_WIDGET_BORDER_SIZE(edit);
			_top = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width;
			_len = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2;
			if(edit->max_rows > edit->row_per_page)	_len -= _width;

			edit->hscroll = rtgui_scrollbar_create(edit,_left,_top,_width,_len,RTGUI_HORIZONTAL);

			if(edit->hscroll != RT_NULL)
			{
				edit->hscroll->WIDGET_GROUP = (pvoid)edit;
				edit->hscroll->on_scroll = rtgui_edit_hscroll_handle;
				RTGUI_WIDGET_HIDE(edit->hscroll);
			}
		}
		if(edit->vscroll == RT_NULL && edit->flag & RTGUI_EDIT_VSCROLL)
		{
			/* create vertical scrollbar */
			rt_uint32_t _left,_top,_width=RTGUI_DEFAULT_SB_WIDTH,_len;
			_left = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)-_width;
			_top = RTGUI_WIDGET_BORDER_SIZE(edit);
			_len = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER_SIZE(edit)*2;
			if(edit->max_cols > edit->col_per_page) _len -= _width;

			edit->vscroll = rtgui_scrollbar_create(edit,_left,_top,_width,_len,RTGUI_VERTICAL);

			if(edit->vscroll != RT_NULL)
			{
				edit->vscroll->WIDGET_GROUP = (pvoid)edit;
				edit->vscroll->on_scroll = rtgui_edit_vscroll_handle;
				RTGUI_WIDGET_HIDE(edit->vscroll);
			}
		}
#endif
	}

	return edit;
}
Exemplo n.º 25
0
static void _rtgui_scrollbar_on_mouseclick(rtgui_scrollbar_t *bar, rtgui_event_t * event)
{
	rtgui_rect_t btn_rect, bar_rect,rect;
	rt_uint32_t pos;
	struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event;

	RT_ASSERT(bar != RT_NULL);

	/* get value */
	pos = get_scrollbar_pos(bar);

	rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&rect);

	if(bar->orient == RTGUI_VERTICAL)
	{
		/* arrange vertical */
		/* get up arrow button rect */
		btn_rect.x1 = rect.x1;
		btn_rect.x2 = rect.x2;
		btn_rect.y1 = rect.y1;
		btn_rect.y2 = rect.y1 + rtgui_rect_width(rect);

		if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
		{
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_UPARROW;
				if(bar->value==0)
				{
					rtgui_scrollbar_ondraw(bar);
					return;
				}
				/* line step */
				bar->value -= bar->line_step;
				if(bar->value < 0) bar->value = 0;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				bar->status = 0;
			}
			goto __exit;
		}
		/* click on the thumb chunk, be going to dragging */
		rtgui_scrollbar_get_thumb_rect(bar, &bar_rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&bar_rect);
		if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
		{
			/* on thumb */
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				/* changed status into drag */
				bar->status |= SBS_VERTTHUMB;
				sbar_mouse_move_size.x = mouse->x;
				sbar_mouse_move_size.y = mouse->y;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				bar->status = 0;
			}
			goto __exit;
		}
		else
		{
			/* click on space without thumb */
			/* get bar rect */
			bar_rect.y1 = rect.y1 + rtgui_rect_width(rect);
			bar_rect.y2 = rect.y2 - rtgui_rect_width(rect);
			if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
			{
				if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
				{
					/* page step */
					if(mouse->y < bar_rect.y1 + pos)
					{
						bar->status |= SBS_UPSPACE;
						bar->value -= bar->page_step;
						if(bar->value < 0) bar->value = 0;
					}
					else if(mouse->y > pos + bar->thumb_len)
					{
						bar->status |= SBS_DOWNSPACE;
						bar->value += bar->page_step;
						if(bar->value > bar->count) bar->value = bar->count;
					}
				}
				goto __exit;
			}
		}
		/* likewise foregoing */
		/* get down arrow button rect */
		bar_rect.x1 = rect.x1;
		bar_rect.x2 = rect.x2;
		btn_rect.y1 = rect.y2 - rtgui_rect_width(rect);
		btn_rect.y2 = rect.y2;
		if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
		{
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_DOWNARROW;
				if(bar->value==bar->count)
				{
					rtgui_scrollbar_ondraw(bar);
					return;
				}
				/* line step */
				bar->value += bar->line_step;
				if(bar->value > bar->count) bar->value = bar->count;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
				bar->status = 0;
			goto __exit;
		}
	}
	else
	{
		/* get left arrow button rect */
		btn_rect.x1 = rect.x1;
		btn_rect.x2 = rect.x1 + rtgui_rect_height(rect);
		btn_rect.y1 = rect.y1;
		btn_rect.y2 = rect.y2;
		if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
		{
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_LEFTARROW;
				if(bar->value==0)
				{
					rtgui_scrollbar_ondraw(bar);
					return;
				}
				/* line step */
				bar->value -= bar->line_step;
				if(bar->value < 0) bar->value = 0;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
				bar->status = 0;
			goto __exit;
		}

		rtgui_scrollbar_get_thumb_rect(bar, &bar_rect);
		rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&bar_rect);
		if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
		{
			/* on the thumb */
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_HORZTHUMB;
				sbar_mouse_move_size.x = mouse->x;
				sbar_mouse_move_size.y = mouse->y;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
			{
				bar->status = 0;
			}
			goto __exit;
		}
		else
		{
			/* get bar rect */
			bar_rect.x1 = rect.x1 + rtgui_rect_height(rect);
			bar_rect.x2 = rect.x2 - rtgui_rect_height(rect);
			bar_rect.y1 = rect.y1;
			bar_rect.y2 = rect.y2;
			if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
			{
				if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
				{
					/* page step */
					if(mouse->x <  bar_rect.x1 + pos)
					{
						bar->status |= SBS_LEFTSPACE;
						bar->value -= bar->page_step;
						if(bar->value < 0) bar->value = 0;
					}
					else if(mouse->x > pos + bar->thumb_len)
					{
						bar->status |= SBS_RIGHTSPACE;
						bar->value += bar->page_step;
						if(bar->value > bar->count) bar->value = bar->count;
					}
				}
				else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
				{
					bar->status = 0;
				}
				goto __exit;
			}
		}
		/* get right arrow button rect */
		btn_rect.x1 = rect.x2 - rtgui_rect_height(rect);
		btn_rect.x2 = rect.x2;
		bar_rect.y1 = rect.y1;
		bar_rect.y2 = rect.y2;
		if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
		{
			if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
			{
				bar->status |= SBS_RIGHTARROW;
				if(bar->value==bar->count)
				{
					rtgui_scrollbar_ondraw(bar);
					return;
				}
				/* line step */
				bar->value += bar->line_step;
				if(bar->value > bar->count) bar->value = bar->count;
			}
			else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
				bar->status = 0;
			goto __exit;
		}
	}

__exit:
	rtgui_scrollbar_ondraw(bar);
	if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
	{
		if(bar->widget_link != RT_NULL && bar->on_scroll != RT_NULL)
		{
			rtgui_widget_focus(bar->widget_link);
			bar->on_scroll(RTGUI_OBJECT(bar->widget_link), event);
		}
	}
}
Exemplo n.º 26
0
rt_bool_t rtgui_listctrl_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	struct rtgui_listctrl* ctrl = RT_NULL;

	ctrl = RTGUI_LISTCTRL(widget);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		_rtgui_listctrl_ondraw(ctrl);
		return RT_FALSE;

    case RTGUI_EVENT_RESIZE:
        {
			struct rtgui_event_resize* resize;

			resize = (struct rtgui_event_resize*)event;

            /* recalculate page items */
			ctrl->page_items = resize->h  / (2 + rtgui_theme_get_selected_height());
        }
        break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		{
			rtgui_rect_t rect;
			struct rtgui_event_mouse* emouse;

			emouse = (struct rtgui_event_mouse*)event;

			/* get scrollbar rect */
			_rtgui_listctrl_get_scrollbar_rect(ctrl, &rect);
			rtgui_widget_rect_to_device(RTGUI_WIDGET(ctrl), &rect);
			if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
			{
				_rtgui_listctrl_scrollbar_onmouse(ctrl, emouse);
				return RT_TRUE;
			}

			/* calculate selected item */

			/* get physical extent information */
			_rtgui_listctrl_get_rect(ctrl, &rect);
			rtgui_widget_rect_to_device(widget, &rect);

			if ((rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK) &&
					(ctrl->items_count > 0))
			{
				rt_uint16_t index;
				index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());

				/* set focus */
				rtgui_widget_focus(widget);
				{
					struct rtgui_rect rect;
					struct rtgui_dc* dc;

					dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(ctrl));
					if (dc != RT_NULL)
					{
						/* get widget rect */
						rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), &rect);
						/* update focus border */
						rect.x2 -= 1; rect.y2 -= 1;
						rtgui_dc_end_drawing(dc);
					}
				}

				if ((index < ctrl->page_items) &&
					(ctrl->current_item/ctrl->page_items)* ctrl->page_items + index < ctrl->items_count)
				{
					rt_uint16_t old_item;

					old_item = ctrl->current_item;

					/* set selected item */
					ctrl->current_item = (ctrl->current_item/ctrl->page_items) * ctrl->page_items + index;
					if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
					{
						/* down event */
						rtgui_listctrl_update_current(ctrl, old_item);
					}
					else
					{
						/* up event */
						if (ctrl->on_item != RT_NULL)
						{
							ctrl->on_item(RTGUI_WIDGET(ctrl), RT_NULL);
						}
					}
				}
			}

			return RT_TRUE;
		}

    case RTGUI_EVENT_KBD:
        {
            struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
            if ((ekbd->type == RTGUI_KEYDOWN) && (ctrl->items_count > 0))
            {
				rt_uint16_t old_item;

				old_item = ctrl->current_item;
                switch (ekbd->key)
                {
				case RTGUIK_LEFT:
					if (ctrl->current_item - ctrl->page_items >= 0)
						ctrl->current_item -= ctrl->page_items;
					rtgui_listctrl_update_current(ctrl, old_item);
					return RT_FALSE;

                case RTGUIK_UP:
					if (ctrl->current_item > 0)
						ctrl->current_item --;
					rtgui_listctrl_update_current(ctrl, old_item);
					return RT_FALSE;

				case RTGUIK_RIGHT:
					if (ctrl->current_item + ctrl->page_items < ctrl->items_count - 1)
						ctrl->current_item += ctrl->page_items;
					else
					{
						if ((((ctrl->current_item/ctrl->page_items) + 1) * ctrl->page_items) < ctrl->items_count - 1)
							ctrl->current_item = ((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items;
					}
					rtgui_listctrl_update_current(ctrl, old_item);
					return RT_FALSE;

                case RTGUIK_DOWN:
					if (ctrl->current_item < ctrl->items_count - 1)
						ctrl->current_item ++;
					rtgui_listctrl_update_current(ctrl, old_item);
					return RT_FALSE;

				case RTGUIK_RETURN:
                    if (ctrl->on_item != RT_NULL)
					{
						ctrl->on_item(RTGUI_WIDGET(ctrl), RT_NULL);
					}
					return RT_FALSE;

                default:
                    break;
                }
            }
        }
		return RT_FALSE;
	}

    /* use ctrl event handler */
    return rtgui_widget_event_handler(widget, event);
}
Exemplo n.º 27
0
rt_bool_t window_focus(void)
{
	rtgui_label_t *label;

	rtgui_button_t* start_btn;
	rtgui_button_t* stop_btn;
    rtgui_win_t *picture_win;
	rtgui_rect_t rect = {0, 20, 240, 320};

	/* 创建一个窗口 */
	main_win = rtgui_win_create(RT_NULL,
			"主窗口",
			&rect,
			RTGUI_WIN_STYLE_DEFAULT | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
	/* 获得视图的位置信息 */
	rtgui_widget_get_rect(RTGUI_WIDGET(main_win), &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(main_win), &rect);
	rect.x1 += 10;
	rect.x2 -= 5;
	rect.y2 = rect.y1 + 20;

	/* 创建标题用的标签 */
	label = rtgui_label_create("主窗口");
	/* 设置标签位置信息 */
	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
	/* 添加标签到视图中 */
	rtgui_container_add_child(RTGUI_CONTAINER(main_win),
			RTGUI_WIDGET(label));

	/* 获得视图的位置信息 */
	rtgui_widget_get_rect(RTGUI_WIDGET(main_win), &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(main_win), &rect);
	rect.x1 += 10;
	rect.y2 -= 10;
	rect.y1 = rect.y2 - 25;
	rect.x2 = rect.x1 + 50;

	/* 创建"启动"按钮 */
	start_btn = rtgui_button_create("按钮1");
	/* 设置按钮的位置信息 */
	rtgui_widget_set_rect(RTGUI_WIDGET(start_btn), &rect);

	rtgui_button_set_onbutton(start_btn, show_modal_info);

	/* 添加按钮到视图中 */
	rtgui_container_add_child(RTGUI_CONTAINER(main_win),
			RTGUI_WIDGET(start_btn));

	/* 添加停止按钮*/
	rtgui_widget_get_rect(RTGUI_WIDGET(main_win), &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(main_win), &rect);
	rect.x2 -= 10;
	rect.y2 -= 10;
	rect.x1 = rect.x2 - 50;
	rect.y1 = rect.y2 - 25;

	/* 创建"停止"按钮 */
	stop_btn = rtgui_button_create("按钮2");
	/* 设置按钮的位置信息 */
	rtgui_widget_set_rect(RTGUI_WIDGET(stop_btn), &rect);

	rtgui_button_set_onbutton(stop_btn, echo_btn_pressed);

	/* 添加按钮到视图中 */
	rtgui_container_add_child(RTGUI_CONTAINER(main_win),
			RTGUI_WIDGET(stop_btn));

	/*创建一个绘图Windows控件*/
	rtgui_widget_get_rect(RTGUI_WIDGET(main_win), &rect);
	rtgui_widget_rect_to_device(RTGUI_WIDGET(main_win), &rect);
	rect.x1 += 10;
	rect.y1 += 20;
	rect.x2 = rect.x1 + 200;
	rect.y2 = rect.y1 + 150;
	picture_win = rtgui_win_create(main_win, "绘图窗口", &rect,
            RTGUI_WIN_STYLE_NO_TITLE|RTGUI_WIN_STYLE_NO_BORDER|RTGUI_WIN_STYLE_NO_FOCUS);
    //创建窗口,没有标题栏,没有最小化窗口,也不能获取焦点
	/* 添加windows的事件*/
	/* all of the windows are managed by topwin. Never set a window as other
	 * window's child.
	 *
	 *rtgui_container_add_child(RTGUI_CONTAINER(main_win),
	 *        RTGUI_WIDGET(picture_win));
     */
	rtgui_object_set_event_handler(RTGUI_OBJECT(picture_win),
			picture_win_onpaint);

	/* 非模态显示窗口 */
	rtgui_widget_focus(RTGUI_WIDGET(main_win));//设定主窗体获取焦点
	rtgui_win_show(main_win, RT_FALSE);
	rtgui_win_show(picture_win,RT_FALSE);

	return RT_TRUE;
}