Exemplo n.º 1
0
void rtgui_listbox_ondraw(struct rtgui_listbox* box)
{
	struct rtgui_rect rect, item_rect;
	struct rtgui_dc* dc;
	rt_uint16_t page_index, index;
	const struct rtgui_listbox_item* item;

	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
	if (dc == RT_NULL) return;

	rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
	rtgui_dc_fill_rect(dc, &rect);

	rect.x2 -= 1; rect.y2 -= 1;
	/* draw focused border */
	if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(box)))
		rtgui_dc_draw_focus_rect(dc, &rect);

	/* get item base rect */
	item_rect = rect;
	item_rect.x1 += 1; item_rect.x2 -= 1;
	item_rect.y1 += 2;
	item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

	/* get current page */
	page_index = (box->current_item / box->page_items) * box->page_items;
	for (index = 0; index < box->page_items; index ++)
	{
		if (page_index + index >= box->items_count) break;

		item = &(box->items[page_index + index]);

		if (page_index + index == box->current_item)
		{
			rtgui_theme_draw_selected(dc, &item_rect);
		}
		item_rect.x1 += LIST_MARGIN;

		if (item->image != RT_NULL)
		{
			rtgui_image_blit(item->image, dc, &item_rect);
			item_rect.x1 += item->image->w + 2;
		}
        /* draw text */
		rtgui_dc_draw_text(dc, item->name, &item_rect);

        if (item->image != RT_NULL)
            item_rect.x1 -= (item->image->w + 2);
		item_rect.x1 -= LIST_MARGIN;

        /* move to next item position */
		item_rect.y1 += (rtgui_theme_get_selected_height() + 2);
		item_rect.y2 += (rtgui_theme_get_selected_height() + 2);
	}
	rtgui_dc_end_drawing(dc);
}
Exemplo n.º 2
0
static void rtgui_list_view_onlistdraw(struct rtgui_list_view *view, struct rtgui_dc *dc)
{
    rt_ubase_t index, page_index;
    rtgui_rect_t rect, item_rect, image_rect;
    const struct rtgui_list_item *item;

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

    /* get item base rect */
    item_rect = rect;
    item_rect.y1 += 2;
    item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

    /* get current page */
    page_index = (view->current_item / view->page_items) * view->page_items;
    for (index = 0; index < view->page_items; index ++)
    {
        if (page_index + index >= view->items_count) break;

        item = &(view->items[page_index + index]);

        if (page_index + index == view->current_item)
        {
            rtgui_theme_draw_selected(dc, &item_rect);
        }
        item_rect.x1 += LIST_MARGIN;

        if (item->image != RT_NULL)
        {
            /* blit on center */
            image_rect.x1 = 0;
            image_rect.y1 = 0;
            image_rect.x2 = item->image->w;
            image_rect.y2 = item->image->h;

            rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
            rtgui_image_blit(item->image, dc, &image_rect);
            item_rect.x1 += item->image->w + 2;
        }
        /* draw text */
        rtgui_dc_draw_text(dc, item->name, &item_rect);

        if (item->image != RT_NULL)
            item_rect.x1 -= (item->image->w + 2);
        item_rect.x1 -= LIST_MARGIN;

        /* move to next item position */
        item_rect.y1 += (rtgui_theme_get_selected_height() + 2);
        item_rect.y2 += (rtgui_theme_get_selected_height() + 2);
    }
}
Exemplo n.º 3
0
void rtgui_menu_pop(struct rtgui_menu* menu, int x, int y)
{
	rtgui_rect_t rect;
	struct rtgui_event_resize eresize;

	if (menu == RT_NULL) return;

	/* set window extent */
	rect.x1 = 0; rect.y1 = 0;
	rect.x2 = 100; rect.y2 = menu->items_count * (rtgui_theme_get_selected_height() + 2) + 5;
	rtgui_rect_moveto(&rect, x, y);
	rtgui_win_set_rect(RTGUI_WIN(menu), &rect);
	rtgui_rect_inflate(&rect, -1);
	rtgui_widget_set_rect(RTGUI_WIDGET(menu->items_list), &rect);

	eresize.parent.type = RTGUI_EVENT_RESIZE;
	eresize.x = rect.x1; eresize.y = rect.y1;
	eresize.h = rect.y2 - rect.y1; eresize.w = rect.x2 - rect.x1;
	rtgui_listctrl_event_handler(RTGUI_WIDGET(menu->items_list), &(eresize.parent));

	/* on menu pop handler */
	if (menu->on_menupop != RT_NULL)
	{
		menu->on_menupop(RTGUI_WIDGET(menu), RT_NULL);
	}

	/* show menu window */
	rtgui_win_show(RTGUI_WIN(menu), RT_FALSE);
}
Exemplo n.º 4
0
static void _rtgui_listctrl_get_rect(struct rtgui_listctrl* ctrl, rtgui_rect_t* rect)
{
	rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), rect);
	if (ctrl->items_count > rtgui_rect_height(*rect)/rtgui_theme_get_selected_height())
	{
		rect->x2 = rect->x2 - 8;
	}
}
Exemplo n.º 5
0
void rtgui_listctrl_update_current(struct rtgui_listctrl* ctrl, rt_uint16_t old_item)
{
	struct rtgui_dc* dc;
	rtgui_rect_t rect, item_rect;

	if (old_item/ctrl->page_items != ctrl->current_item/ctrl->page_items)
	{
		/* it's not a same page, update all */
		rtgui_widget_update(RTGUI_WIDGET(ctrl));
		return;
	}

	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(ctrl));
	if (dc == RT_NULL) return;

	_rtgui_listctrl_get_rect(ctrl, &rect);
	rect.x2 -= 1; rect.y2 -= 1;

	item_rect = rect;
	/* get old item's rect */
	item_rect.x1 += 1; item_rect.x2 -= 1;
	item_rect.y1 += 2;
	item_rect.y1 += (old_item % ctrl->page_items) * (2 + rtgui_theme_get_selected_height());
	item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

	/* draw old item */
	rtgui_dc_fill_rect(dc, &item_rect);
	if (ctrl->on_item_draw != RT_NULL)
		ctrl->on_item_draw(ctrl, dc, &item_rect, old_item);

	/* draw current item */
	item_rect = rect;
	/* get current item's rect */
	item_rect.x1 += 1; item_rect.x2 -= 1;
	item_rect.y1 += 2;
	item_rect.y1 += (ctrl->current_item % ctrl->page_items) * (2 + rtgui_theme_get_selected_height());
	item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

	/* draw current item */
	rtgui_theme_draw_selected(dc, &item_rect);
	if (ctrl->on_item_draw != RT_NULL)
		ctrl->on_item_draw(ctrl, dc, &item_rect, ctrl->current_item);

	rtgui_dc_end_drawing(dc);
}
Exemplo n.º 6
0
static void _rtgui_listctrl_ondraw(struct rtgui_listctrl* ctrl)
{
	struct rtgui_rect rect, item_rect;
	struct rtgui_dc* dc;
	rt_uint16_t page_index, index;

	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(ctrl));
	if (dc == RT_NULL) return;

	_rtgui_listctrl_get_rect(ctrl, &rect);
	rtgui_dc_fill_rect(dc, &rect);

	rect.x2 -= 1; rect.y2 -= 1;

	/* get item base rect */
	item_rect = rect;
	item_rect.x1 += 1; item_rect.x2 -= 1;
	item_rect.y1 += 2;
	item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

	/* get current page */
	page_index = (ctrl->current_item / ctrl->page_items) * ctrl->page_items;
	for (index = 0; index < ctrl->page_items; index ++)
	{
		if (page_index + index >= ctrl->items_count) break;

		if (page_index + index == ctrl->current_item)
		{
			rtgui_theme_draw_selected(dc, &item_rect);
		}

		if (ctrl->on_item_draw != RT_NULL)
		{
			ctrl->on_item_draw(ctrl, dc, &item_rect, page_index + index);
		}

        /* move to next item position */
		item_rect.y1 += (rtgui_theme_get_selected_height() + 2);
		item_rect.y2 += (rtgui_theme_get_selected_height() + 2);
	}

	/* draw scrollbar */
	_rtgui_listctrl_scrollbar_ondraw(ctrl, dc);
	rtgui_dc_end_drawing(dc);
}
Exemplo n.º 7
0
static rt_bool_t rtgui_combobox_onmouse_button(struct rtgui_combobox* box, struct rtgui_event_mouse* event)
{
	struct rtgui_rect rect;

	/* get widget rect */
	rect = RTGUI_WIDGET(box)->extent;

	/* move to the pull down button */
	rect.x1 = rect.x2 - RTGUI_COMBOBOX_BUTTON_WIDTH;
	if (rtgui_rect_contains_point(&rect, event->x, event->y) == RT_EOK)
	{
		/* handle mouse button on pull down button */
		if (event->button & RTGUI_MOUSE_BUTTON_LEFT &&
			event->button & RTGUI_MOUSE_BUTTON_DOWN)
		{
			box->pd_pressed = RT_TRUE;
			rtgui_widget_update(RTGUI_WIDGET(box));
		}
		else if (event->button & RTGUI_MOUSE_BUTTON_LEFT &&
			event->button & RTGUI_MOUSE_BUTTON_UP)
		{
			box->pd_pressed = RT_FALSE;
			rtgui_widget_update(RTGUI_WIDGET(box));

			/* pop pull down window */
			if (box->pd_win == RT_NULL)
			{
				rtgui_listbox_t  *list;

				/* create pull down window */
				rect = RTGUI_WIDGET(box)->extent;
				rect.y1 = rect.y2;
				rect.y2 = rect.y1 + 5 * (2 + rtgui_theme_get_selected_height());
				box->pd_win = rtgui_win_create(RT_NULL, "combo", &rect, RTGUI_WIN_STYLE_NO_TITLE);
				rtgui_win_set_ondeactivate(RTGUI_WIN(box->pd_win), rtgui_combobox_pulldown_hide);
				/* set user data to parent combobox */
				box->pd_win->user_data = (rt_uint32_t)box;

				/* create list box */
				rtgui_rect_inflate(&rect, -1);
				list = rtgui_listbox_create(box->items, box->items_count, &rect);
				rtgui_container_add_child(RTGUI_CONTAINER(box->pd_win), RTGUI_WIDGET(list));
				rtgui_widget_focus(RTGUI_WIDGET(list));

				rtgui_listbox_set_onitem(list, rtgui_combobox_pdwin_onitem);
				rtgui_win_set_ondeactivate(box->pd_win, rtgui_combobox_pdwin_ondeactive);
			}

			/* show combo box pull down window */
			rtgui_win_show(RTGUI_WIN(box->pd_win), RT_FALSE);
		}

		return RT_TRUE;
	}

	return RT_FALSE;
}
Exemplo n.º 8
0
rt_bool_t rtgui_listctrl_get_item_rect(rtgui_listctrl_t* ctrl, rt_uint16_t item, rtgui_rect_t* item_rect)
{
	if (item < ctrl->items_count)
	{
		rt_uint16_t index;

		/* check whether this item in current page */
		index = (ctrl->current_item / ctrl->page_items) * ctrl->page_items;
		if (index > item || index + ctrl->page_items <= item) return RT_FALSE;

		rtgui_widget_get_extent(RTGUI_WIDGET(ctrl), item_rect);
		item_rect->y1 -= 2;
		item_rect->y1 += (item % ctrl->page_items) * (2 + rtgui_theme_get_selected_height());
		item_rect->y2 = item_rect->y1 + (2 + rtgui_theme_get_selected_height());
		return RT_TRUE;
	}

	return RT_FALSE;
}
Exemplo n.º 9
0
void rtgui_listctrl_set_items(rtgui_listctrl_t* ctrl, rt_uint32_t items, rt_uint16_t count)
{
	rtgui_rect_t rect;
	
	ctrl->items = items;
	ctrl->items_count = count;
	ctrl->current_item = 0;

	rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), &rect);
	ctrl->page_items = rtgui_rect_height(rect) / (2 + rtgui_theme_get_selected_height());

	rtgui_widget_update(RTGUI_WIDGET(ctrl));
}
Exemplo n.º 10
0
static void _rtgui_listctrl_get_scrollbar_rect(struct rtgui_listctrl* ctrl, rtgui_rect_t* rect)
{
	rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), rect);
	if (ctrl->items_count > rtgui_rect_height(*rect)/rtgui_theme_get_selected_height())
	{
		rect->x1 = rect->x2 - 8;
	}
	else
	{
		/* no scrollbar */
		rt_memset(rect, 0, sizeof(rtgui_rect_t));
	}
}
Exemplo n.º 11
0
void rtgui_listbox_set_items(rtgui_listbox_t* box, struct rtgui_listbox_item* items, rt_uint16_t count)
{
	rtgui_rect_t rect;
	
	box->items = items;
	box->items_count = count;
	box->current_item = 0;

	rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
	box->page_items = rtgui_rect_height(rect) / (2 + rtgui_theme_get_selected_height());

	rtgui_widget_update(RTGUI_WIDGET(box));
}
Exemplo n.º 12
0
static void _rtgui_listctrl_constructor(struct rtgui_listctrl *ctrl)
{
    /* set default widget rect and set event handler */
    rtgui_object_set_event_handler(RTGUI_OBJECT(ctrl), rtgui_listctrl_event_handler);

    RTGUI_WIDGET(ctrl)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;

    ctrl->current_item = -1;
    ctrl->item_height = rtgui_theme_get_selected_height();
    ctrl->items_count = 0;
    ctrl->page_items = 0;
    ctrl->on_item = 0;
    ctrl->on_item_draw = RT_NULL;

    RTGUI_WIDGET_BACKGROUND(ctrl) = white;
    RTGUI_WIDGET_TEXTALIGN(ctrl) = RTGUI_ALIGN_CENTER_VERTICAL;
}
Exemplo n.º 13
0
rtgui_listbox_t* rtgui_listbox_create(const struct rtgui_listbox_item* items, rt_uint16_t count, rtgui_rect_t *rect)
{
	struct rtgui_listbox* box = RT_NULL;

	box = (struct rtgui_listbox*) rtgui_widget_create(RTGUI_LISTBOX_TYPE);
	if (box != RT_NULL)
	{
	    box->items = items;
	    box->items_count = count;

		box->page_items = rtgui_rect_height(*rect) / (2 + rtgui_theme_get_selected_height());
		if (box->page_items == 0) box->page_items = 1;
		rtgui_widget_set_rect(RTGUI_WIDGET(box), rect);
	}

	return box;
}
Exemplo n.º 14
0
rtgui_filelist_view_t* rtgui_filelist_view_create(const char* directory,
												  const char* pattern,
												  const rtgui_rect_t* rect)
{
	struct rtgui_filelist_view* view = RT_NULL;

	/* create a new view */
	view = (struct rtgui_filelist_view*) rtgui_widget_create(RTGUI_FILELIST_VIEW_TYPE);
	if (view != RT_NULL)
	{
		view->items = RT_NULL;
		view->pattern = rt_strdup(pattern);
		view->page_items = rtgui_rect_height(*rect) / (1 + rtgui_theme_get_selected_height());
		rtgui_filelist_view_set_directory(view, directory);
	}

	return view;
}
Exemplo n.º 15
0
rtgui_listctrl_t* rtgui_listctrl_create(rt_uint32_t items, rt_uint16_t count, rtgui_rect_t *rect, 
										rtgui_onitem_draw_t ondraw)
{
	struct rtgui_listctrl* ctrl = RT_NULL;

	ctrl = (struct rtgui_listctrl*) rtgui_widget_create(RTGUI_LISTCTRL_TYPE);
	if (ctrl != RT_NULL)
	{
	    ctrl->items = items;
	    ctrl->items_count = count;
		ctrl->on_item_draw = ondraw;

		ctrl->page_items = rtgui_rect_height(*rect) / (2 + rtgui_theme_get_selected_height());
		rtgui_widget_set_rect(RTGUI_WIDGET(ctrl), rect);
	}

	return ctrl;
}
Exemplo n.º 16
0
rtgui_filelist_view_t *rtgui_filelist_view_create(const char *directory,
                                                  const char *pattern,
                                                  const rtgui_rect_t *rect)
{
    struct rtgui_filelist_view *view = RT_NULL;

    /* create a new view */
    view = (struct rtgui_filelist_view *) rtgui_widget_create(RTGUI_FILELIST_VIEW_TYPE);
    if (view != RT_NULL)
    {
        rtgui_widget_set_rect(RTGUI_WIDGET(view), rect);
        view->items = RT_NULL;
        view->pattern = rt_strdup(pattern);
        view->page_items = rtgui_rect_height(*rect) / (1 + rtgui_theme_get_selected_height());
        /* Avoid divide by 0 error, display at least one item. */
        if (view->page_items == 0)
            view->page_items = 1;
        rtgui_filelist_view_set_directory(view, directory);
    }

    return view;
}
Exemplo n.º 17
0
rtgui_list_view_t* rtgui_list_view_create(const struct rtgui_list_item* items, rt_uint16_t count,
        rtgui_rect_t *rect, rt_uint16_t flag)
{
    struct rtgui_list_view* view = RT_NULL;

    view = (struct rtgui_list_view*) rtgui_widget_create(RTGUI_LIST_VIEW_TYPE);
    if (view != RT_NULL) {
        view->items = items;
        view->items_count = count;

        view->flag = flag;
        rtgui_widget_set_rect(RTGUI_WIDGET(view), rect);

        if (flag == RTGUI_LIST_VIEW_LIST)
            view->page_items = rtgui_rect_height(*rect) / (2 + rtgui_theme_get_selected_height());
        else if ((flag == RTGUI_LIST_VIEW_ICON) && (count > 0)) {
            rtgui_list_view_calc(view);
        }
    }

    return view;
}
Exemplo n.º 18
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.º 19
0
rt_bool_t rtgui_list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	struct rtgui_list_view* view = RT_NULL;

	view = RTGUI_LIST_VIEW(widget);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		rtgui_list_view_ondraw(view);
		return RT_FALSE;

    case RTGUI_EVENT_RESIZE:
        {
			struct rtgui_event_resize* resize;

			resize = (struct rtgui_event_resize*)event;

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

	case RTGUI_EVENT_MOUSE_BUTTON:
		{
			struct rtgui_event_mouse* emouse;

			emouse = (struct rtgui_event_mouse*)event;
			return rtgui_list_view_onmouse(view, emouse);
		}

    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_LEFT:
					if (view->flag == RTGUI_LIST_VIEW_LIST)
					{
						if (view->current_item - view->page_items >= 0)
							view->current_item -= view->page_items;
						
						rtgui_list_view_update_list(view, old_item);
					}
					else if (view->flag == RTGUI_LIST_VIEW_ICON)
					{
						if (view->current_item > 0)
							view->current_item --;
						rtgui_list_view_update_icon(view, old_item);
					}
					return RT_FALSE;

                case RTGUIK_UP:
					if (view->flag == RTGUI_LIST_VIEW_LIST)
					{
						if (view->current_item > 0)
							view->current_item --;
						rtgui_list_view_update_list(view, old_item);
					}
					else if (view->flag == RTGUI_LIST_VIEW_ICON)
					{
						if (view->current_item >= view->col_items)
							view->current_item -= view->col_items;
						else 
							view->current_item = 0;
						
						rtgui_list_view_update_icon(view, old_item);
					}
					return RT_FALSE;

				case RTGUIK_RIGHT:
					if (view->flag == RTGUI_LIST_VIEW_LIST)
					{
						if (view->current_item + view->page_items < view->items_count - 1)
							view->current_item += view->page_items;
						
						rtgui_list_view_update_list(view, old_item);
					}
					else if (view->flag == RTGUI_LIST_VIEW_ICON)
					{
						if (view->current_item < view->items_count - 1)
							view->current_item ++;
						
						rtgui_list_view_update_icon(view, old_item);
					}
					return RT_FALSE;

                case RTGUIK_DOWN:
					if (view->flag == RTGUI_LIST_VIEW_LIST)
					{
						if (view->current_item < view->items_count - 1)
							view->current_item ++;
						
						rtgui_list_view_update_list(view, old_item);
					}
					else if (view->flag == RTGUI_LIST_VIEW_ICON)
					{
						if (view->current_item + view->col_items <= (view->items_count - 1))
							view->current_item += view->col_items;
						else 
							view->current_item = view->items_count - 1;

						rtgui_list_view_update_icon(view, old_item);
					}
					return RT_FALSE;

				case RTGUIK_RETURN:
                    if (view->items[view->current_item].action != RT_NULL)
					{
					    view->items[view->current_item].action(view->items[view->current_item].parameter);
					}
					return RT_FALSE;

                default:
                    break;
                }
            }
        }
		return RT_FALSE;
	}

    /* use view event handler */
    return rtgui_view_event_handler(widget, event);
}
Exemplo n.º 20
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.º 21
0
void rtgui_list_view_update_list(struct rtgui_list_view* view, rt_uint16_t old_item)
{
	struct rtgui_dc* dc;
	const struct rtgui_list_item* item;
	rtgui_rect_t rect, item_rect;

	if (old_item/view->page_items != view->current_item/view->page_items)
	{
		/* it's not a same page, update all */
		rtgui_widget_update(RTGUI_WIDGET(view));
		return;
	}

	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
	if (dc == RT_NULL) return;

	rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

	/* get old item's rect and draw old item */
	item_rect.x1 = rect.x1; item_rect.x2 = rect.x2;
	item_rect.y1 = rect.y1 + 2;
	item_rect.y1 += (old_item % view->page_items) * (2 + rtgui_theme_get_selected_height());
	item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
	rtgui_dc_fill_rect(dc, &item_rect);

	item_rect.x1 += LIST_MARGIN;

	item = &(view->items[old_item]);
	if (item->image != RT_NULL)
	{
		struct rtgui_rect image_rect;

		/* blit on center */
		image_rect.x1 = 0; image_rect.y1 = 0;
		image_rect.x2 = item->image->w;
		image_rect.y2 = item->image->h;

		rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_image_blit(item->image, dc, &image_rect);
		item_rect.x1 += item->image->w + 2;
	}
	rtgui_dc_draw_text(dc, item->name, &item_rect);

	/* draw current item */
	item_rect = rect;
	/* get current item's rect */
	item_rect.y1 += 2;
	item_rect.y1 += (view->current_item % view->page_items) * (2 + rtgui_theme_get_selected_height());
	item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

	/* draw current item */
	rtgui_theme_draw_selected(dc, &item_rect);

	item_rect.x1 += LIST_MARGIN;

	item = &(view->items[view->current_item]);
	if (item->image != RT_NULL)
	{
		struct rtgui_rect image_rect;

		/* blit on center */
		image_rect.x1 = 0; image_rect.y1 = 0;
		image_rect.x2 = item->image->w;
		image_rect.y2 = item->image->h;

		rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
		rtgui_image_blit(item->image, dc, &image_rect);
		item_rect.x1 += (item->image->w + 2);
	}
	rtgui_dc_draw_text(dc, item->name, &item_rect);

	rtgui_dc_end_drawing(dc);
}
Exemplo n.º 22
0
void rtgui_filelist_view_ondraw(struct rtgui_filelist_view *view)
{
    struct rtgui_dc *dc;
    rt_uint16_t page_index, index;
    struct rtgui_file_item *item;
    struct rtgui_rect rect, item_rect, image_rect;

    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
    if (dc == RT_NULL) return;

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
    rtgui_dc_fill_rect(dc, &rect);

    /* get item base rect */
    item_rect = rect;
    item_rect.y1 += 1;
    item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());

    /* get image base rect */
    image_rect.x1 = RTGUI_FILELIST_MARGIN;
    image_rect.y1 = 0;
    image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w;
    image_rect.y2 = file_image->h;
    rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

    /* get current page */
    page_index = (view->current_item / view->page_items) * view->page_items;
    for (index = 0; index < view->page_items; index ++)
    {
        if (page_index + index >= view->items_count) break;

        item = &(view->items[page_index + index]);

        if (page_index + index == view->current_item)
        {
            rtgui_theme_draw_selected(dc, &item_rect);
        }
        else
        {
            /* draw background */
            rtgui_dc_fill_rect(dc, &item_rect);
        }

        /* draw item */
        if (item->type == RTGUI_FITEM_FILE)
            rtgui_image_blit(file_image, dc, &image_rect);
        else
            rtgui_image_blit(folder_image, dc, &image_rect);

        /* draw text */
        item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2;
        rtgui_dc_draw_text(dc, item->name, &item_rect);
        item_rect.x1 -= RTGUI_FILELIST_MARGIN + file_image->w + 2;

        /* move to next item position */
        item_rect.y1 += (rtgui_theme_get_selected_height() + 1);
        item_rect.y2 += (rtgui_theme_get_selected_height() + 1);

        image_rect.y1 += (rtgui_theme_get_selected_height() + 1);
        image_rect.y2 += (rtgui_theme_get_selected_height() + 1);
    }

    rtgui_dc_end_drawing(dc);
}
Exemplo n.º 23
0
void rtgui_filelist_view_update_current(struct rtgui_filelist_view *view, rt_uint16_t old_item)
{
    struct rtgui_dc *dc;
    struct rtgui_file_item *item;
    rtgui_rect_t rect, item_rect, image_rect;

    if (old_item / view->page_items != view->current_item / view->page_items)
    {
        /* it's not a same page, update all */
        rtgui_widget_update(RTGUI_WIDGET(view));
        return;
    }

    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
    if (dc == RT_NULL) return;

    rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);

    /* get old item rect */
    item_rect = rect;
    item_rect.y1 += 1;
    item_rect.y1 += (old_item % view->page_items) * (1 + rtgui_theme_get_selected_height());
    item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());

    /* get image rect */
    image_rect.x1 = RTGUI_FILELIST_MARGIN;
    image_rect.y1 = 0;
    image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w;
    image_rect.y2 = file_image->h;
    rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

    /* draw old item */
    rtgui_dc_fill_rect(dc, &item_rect);

    item = &(view->items[old_item]);
    if (item->type == RTGUI_FITEM_FILE) /* draw item image */
        rtgui_image_blit(file_image, dc, &image_rect);
    else
        rtgui_image_blit(folder_image, dc, &image_rect);

    item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2;
    rtgui_dc_draw_text(dc, item->name, &item_rect);

    /* draw current item */
    item_rect = rect;
    item_rect.y1 += 1;
    item_rect.y1 += (view->current_item % view->page_items) * (1 + rtgui_theme_get_selected_height());
    item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());

    rtgui_theme_draw_selected(dc, &item_rect);

    /* get image base rect */
    image_rect.x1 = RTGUI_FILELIST_MARGIN;
    image_rect.y1 = 0;
    image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w;
    image_rect.y2 = file_image->h;
    rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);

    item = &(view->items[view->current_item]);
    if (item->type == RTGUI_FITEM_FILE) /* draw item image */
        rtgui_image_blit(file_image, dc, &image_rect);
    else
        rtgui_image_blit(folder_image, dc, &image_rect);

    item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2;
    rtgui_dc_draw_text(dc, item->name, &item_rect);
    if(view->on_changed!=RT_NULL)
   {
    view->on_changed(RTGUI_OBJECT(view),RT_NULL);
   }
    rtgui_dc_end_drawing(dc);
}
Exemplo n.º 24
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.º 25
0
void rtgui_listbox_update_current(struct rtgui_listbox* box, rt_uint16_t old_item)
{
	struct rtgui_dc* dc;
	const struct rtgui_listbox_item* item;
	rtgui_rect_t rect, item_rect;

	if (old_item/box->page_items != box->current_item/box->page_items)
	{
		/* it's not a same page, update all */
		rtgui_widget_update(RTGUI_WIDGET(box));
		return;
	}

	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
	if (dc == RT_NULL) return;

	rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
	rect.x2 -= 1; rect.y2 -= 1;

	item_rect = rect;
	/* get old item's rect */
	item_rect.x1 += 1; item_rect.x2 -= 1;
	item_rect.y1 += 2;
	item_rect.y1 += (old_item % box->page_items) * (2 + rtgui_theme_get_selected_height());
	item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

	/* draw old item */
	rtgui_dc_fill_rect(dc, &item_rect);

	item_rect.x1 += LIST_MARGIN;

	item = &(box->items[old_item]);
	if (item->image != RT_NULL)
	{
		rtgui_image_blit(item->image, dc, &item_rect);
		item_rect.x1 += item->image->w + 2;
	}
	rtgui_dc_draw_text(dc, item->name, &item_rect);

	/* draw current item */
	item_rect = rect;
	/* get current item's rect */
	item_rect.x1 += 1; item_rect.x2 -= 1;
	item_rect.y1 += 2;
	item_rect.y1 += (box->current_item % box->page_items) * (2 + rtgui_theme_get_selected_height());
	item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());

	/* draw current item */
	rtgui_theme_draw_selected(dc, &item_rect);

	item_rect.x1 += LIST_MARGIN;

	item = &(box->items[box->current_item]);
	if (item->image != RT_NULL)
	{
		rtgui_image_blit(item->image, dc, &item_rect);
        item_rect.x1 += (item->image->w + 2);
	}
	rtgui_dc_draw_text(dc, item->name, &item_rect);

	rtgui_dc_end_drawing(dc);
}
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);
}