Esempio n. 1
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;
}
Esempio n. 2
0
rt_bool_t rtgui_slider_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
	struct rtgui_widget *widget;
	struct rtgui_slider* slider;

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

	widget = RTGUI_WIDGET(object);
	slider = RTGUI_SLIDER(object);

	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
		if (widget->on_draw != RT_NULL)
			widget->on_draw(RTGUI_OBJECT(widget), event);
		else
#endif
		{
			rtgui_theme_draw_slider(slider);
		}

		break;

	case RTGUI_EVENT_KBD:
		if (!RTGUI_WIDGET_IS_ENABLE(widget) || RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;

#ifndef RTGUI_USING_SMALL_SIZE
		if (widget->on_key != RT_NULL)
			return widget->on_key(RTGUI_OBJECT(widget), event);
		else
#endif
			return rtgui_slider_onkey(slider, (struct rtgui_event_kbd *)event);

	case RTGUI_EVENT_MOUSE_BUTTON:
		if (!RTGUI_WIDGET_IS_ENABLE(widget) || RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;

#ifndef RTGUI_USING_SMALL_SIZE
		if (widget->on_mouseclick != RT_NULL)
			widget->on_mouseclick(RTGUI_OBJECT(widget), event);
		else
#endif
		{
			rtgui_slider_onmouse(slider, (struct rtgui_event_mouse*)event);
		}
		break;

	default:
		return rtgui_widget_event_handler(object, event);
	}

	return RT_FALSE;
}
Esempio n. 3
0
rt_bool_t rtgui_scrollbar_event_handler(rtgui_object_t *object, rtgui_event_t *event)
{
	rtgui_widget_t *widget = RTGUI_WIDGET(object);
	rtgui_scrollbar_t* bar = RTGUI_SCROLLBAR(object);

	switch(event->type)
	{
	case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
		if(widget->on_draw != RT_NULL)
			widget->on_draw(object, event);
		else
#endif
		{
			if(!RTGUI_WIDGET_IS_HIDE(bar))
				rtgui_scrollbar_ondraw(bar);
		}
		break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		if(RTGUI_WIDGET_IS_ENABLE(widget))
		{
#ifndef RTGUI_USING_SMALL_SIZE
			if(widget->on_mouseclick != RT_NULL)
			{
				widget->on_mouseclick(object, event);
			}
			else
#endif
			{
				_rtgui_scrollbar_on_mouseclick(bar, event);
			}
		}
		break;
	case RTGUI_EVENT_MOUSE_MOTION:
		if(RTGUI_WIDGET_IS_ENABLE(widget))
		{
			_rtgui_scrollbar_on_mousemotion(bar, event);
		}

	default:
		return rtgui_widget_event_handler(object, event);
	}

	return RT_FALSE;
}
Esempio n. 4
0
rt_bool_t rtgui_label_event_handler(struct rtgui_object *object, struct rtgui_event* event)
{
	struct rtgui_label *label;
	RTGUI_WIDGET_EVENT_HANDLER_PREPARE

	label = RTGUI_LABEL(object);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		rtgui_theme_draw_label(label);
		break;
	default:
		return rtgui_widget_event_handler(object, event);
	}

	return RT_FALSE;
}
Esempio n. 5
0
rt_bool_t rtgui_progressbar_event_handler(struct rtgui_object *object,
        struct rtgui_event *event)
{
    struct rtgui_progressbar *bar;
    RTGUI_WIDGET_EVENT_HANDLER_PREPARE

    bar = RTGUI_PROGRESSBAR(object);

    switch (event->type)
    {
    case RTGUI_EVENT_PAINT:
        rtgui_theme_draw_progressbar(bar);
        break;
    default:
        return rtgui_widget_event_handler(object, event);
    }

    return RT_FALSE;
}
rt_bool_t rtgui_combobox_event_handler(struct rtgui_object* object, struct rtgui_event* event)
{
    struct rtgui_combobox *box;
    RTGUI_WIDGET_EVENT_HANDLER_PREPARE

    box = RTGUI_COMBOBOX(object);

    switch (event->type)
    {
    case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
        if (widget->on_draw != RT_NULL)
            widget->on_draw(RTGUI_OBJECT(widget), event);
        else
#endif
            rtgui_combobox_ondraw(box);

        break;

    case RTGUI_EVENT_MOUSE_BUTTON:
        return rtgui_combobox_onmouse_button(box, (struct rtgui_event_mouse*)event);

    case RTGUI_EVENT_FOCUSED:
    {
        /* item focused */
        struct rtgui_event_focused* focused;

        focused = (struct rtgui_event_focused*) event;

        if (focused->widget != RT_NULL)
        {
            /* hide pull down window */
            rtgui_win_hiden(RTGUI_WIN(box->pd_win));
            rtgui_combobox_ondraw(box);
        }
    }
    break;
    default:
        return rtgui_widget_event_handler(object, event);
    }

    return RT_FALSE;
}
Esempio n. 7
0
rt_bool_t rtgui_plot_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
    struct rtgui_plot *plot;

    RTGUI_WIDGET_EVENT_HANDLER_PREPARE;

    plot = RTGUI_PLOT(object);

    switch (event->type)
    {
    case RTGUI_EVENT_PAINT:
        _rtgui_plot_update_scale(RTGUI_PLOT(object));
        return rtgui_plot_ondraw(plot, event);
    case RTGUI_EVENT_MV_MODEL:
        return rtgui_plot_onmvmodel(plot, event);
    default:
        return rtgui_widget_event_handler(object, event);
    }
}
Esempio n. 8
0
rt_bool_t rtgui_notebook_event_handler(struct rtgui_object* object, struct rtgui_event* event)
{
	struct rtgui_notebook* notebook;

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

	notebook = RTGUI_NOTEBOOK(object);

	switch (event->type)
	{
	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;
	default:
		/* use parent event handler */
		return rtgui_widget_event_handler(object, event);
	}

	return RT_FALSE;
}
Esempio n. 9
0
rt_bool_t rtgui_textbox_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
	rtgui_widget_t *widget = RTGUI_WIDGET(object);
	rtgui_textbox_t *box = RTGUI_TEXTBOX(object);

	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
		if (widget->on_draw != RT_NULL)
			widget->on_draw(RTGUI_OBJECT(widget), event);
		else
#endif
			rtgui_textbox_ondraw(box);
		break;

	case RTGUI_EVENT_MOUSE_BUTTON:
#ifndef RTGUI_USING_SMALL_SIZE
		if (widget->on_mouseclick != RT_NULL)
			widget->on_mouseclick(RTGUI_OBJECT(widget), event);
		else
#endif
			rtgui_textbox_onmouse(box, (struct rtgui_event_mouse *)event);
		return RT_TRUE;

	case RTGUI_EVENT_KBD:
#ifndef RTGUI_USING_SMALL_SIZE
		if (widget->on_key != RT_NULL)
			widget->on_key(RTGUI_OBJECT(widget), event);
		else
#endif
			rtgui_textbox_onkey(RTGUI_OBJECT(box), (struct rtgui_event *)event);
		return RT_TRUE;

	default:
		return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
	}

	return RT_FALSE;
}
Esempio n. 10
0
rt_bool_t rtgui_staticline_event_handler(struct rtgui_object* object, struct rtgui_event* event)
{
	struct rtgui_staticline* staticline;
	RTGUI_WIDGET_EVENT_HANDLER_PREPARE

	staticline = RTGUI_STATICLINE(object);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
		if (widget->on_draw != RT_NULL)
			widget->on_draw(RTGUI_OBJECT(widget), event);
		else
#endif
			rtgui_theme_draw_staticline(staticline);
		break;
	default:
		return rtgui_widget_event_handler(object, event);
	}

	return RT_FALSE;
}
Esempio n. 11
0
static rt_bool_t rtgui_form_event_handler(struct rtgui_widget *widget, struct rtgui_event *event)
{
	struct rtgui_form* form;
	//struct rtgui_event_command* ecmd;

	form = RTGUI_FORM(widget);

	switch (event->type) {
	case RTGUI_EVENT_PAINT:
		rtgui_form_ondraw(form);
		break;
#if 0
	case RTGUI_EVENT_COMMAND:
		ecmd = (struct rtgui_event_command*)event;
		switch (ecmd->command_id) {
		case SE_FORM_UPDATE:
			if (RTGUI_WIDGET_IS_FOCUSED(RTGUI_WIDGET(se_form)))
				rtgui_widget_update(RTGUI_WIDGET(se_form));
			break;

		case RE_FORM_UPDATE:
			rtgui_widget_update(RTGUI_WIDGET(re_form));
			break;

		case SYS_FORM_UPDATE:
			rtgui_widget_update(RTGUI_WIDGET(sys_form));
			break;
		}
		break;
#endif
	default:
		/* use form event handler */
		return rtgui_widget_event_handler(widget, event);
	}

	return RT_FALSE;
}
/* mywidget控件的事件处理函�?*/
rt_bool_t rtgui_mywidget_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
	/* 调用事件处理函数时,widget指针指向控件本身,所以先获得相应控件对象的指�?*/
	struct rtgui_mywidget* me = RTGUI_MYWIDGET(widget);

	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		/* 绘制事件,调用绘图函数绘�?*/
		rtgui_mywidget_ondraw(me);
		break;

	case RTGUI_EVENT_MOUSE_BUTTON:
		/* 鼠标事件 */
		rtgui_mywidget_onmouse(RTGUI_MYWIDGET(me), (struct rtgui_event_mouse*) event);
		break;

		/* 其他事件调用父类的事件处理函�?*/
	default:
		return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
	}

	return RT_FALSE;
}
Esempio n. 13
0
rt_bool_t rtgui_radiobox_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
    struct rtgui_radiobox *radiobox;
    RTGUI_WIDGET_EVENT_HANDLER_PREPARE

    radiobox = RTGUI_RADIOBOX(object);
    switch (event->type)
    {
    case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
        if (widget->on_draw != RT_NULL)
            widget->on_draw(RTGUI_OBJECT(widget), event);
        else
#endif
        {
            rtgui_theme_draw_radiobox(radiobox);
        }

        break;

    case RTGUI_EVENT_KBD:
        if (RTGUI_WIDGET_IS_HIDE(radiobox)) return RT_FALSE;

#ifndef RTGUI_USING_SMALL_SIZE
        if (widget->on_key != RT_NULL)
            return widget->on_key(RTGUI_OBJECT(widget), event);
        else
#endif
        {
            struct rtgui_event_kbd *e = (struct rtgui_event_kbd *)event;

            /* set focused */
            rtgui_widget_focus(RTGUI_WIDGET(radiobox));
            if (!(RTGUI_KBD_IS_UP(e))) return RT_FALSE;

            if (radiobox->orient == RTGUI_VERTICAL)
            {
                if (e->key == RTGUIK_UP)
                {
                    if (radiobox->item_selection > 0)
                    {
                        rtgui_radiobox_set_selection(radiobox, radiobox->item_selection - 1);
                        return RT_TRUE;
                    }
                }
                else if (e->key == RTGUIK_DOWN)
                {
                    if (radiobox->item_selection < radiobox->item_count - 1)
                    {
                        rtgui_radiobox_set_selection(radiobox, radiobox->item_selection + 1);
                        return RT_TRUE;
                    }
                }
            }
            else
            {
                if (e->key == RTGUIK_LEFT)
                {
                    if (radiobox->item_selection > 0)
                    {
                        rtgui_radiobox_set_selection(radiobox, radiobox->item_selection - 1);
                        return RT_TRUE;
                    }
                }
                else if (e->key == RTGUIK_RIGHT)
                {
                    if (radiobox->item_selection < radiobox->item_count - 1)
                    {
                        rtgui_radiobox_set_selection(radiobox, radiobox->item_selection + 1);
                        return RT_TRUE;
                    }
                }
            }
        }
        break;

    case RTGUI_EVENT_MOUSE_BUTTON:
#ifndef RTGUI_USING_SMALL_SIZE
        if (widget->on_mouseclick != RT_NULL)
            widget->on_mouseclick(RTGUI_OBJECT(widget), event);
        else
#endif
        {
            rtgui_radiobox_onmouse(radiobox, (struct rtgui_event_mouse *)event);
        }
        break;
    default:
        return rtgui_widget_event_handler(object, event);
    }

    return RT_FALSE;
}
Esempio n. 14
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);
}
Esempio n. 15
0
rt_bool_t rtgui_terminal_event_handler(pvoid wdt, rtgui_event_t* event)
{
	rtgui_widget_t *widget;
	rtgui_terminal_t* tma;

	RT_ASSERT(wdt != RT_NULL);

	widget = RTGUI_WIDGET(wdt);
	tma = RTGUI_TERMINAL(widget);

	switch(event->type)
	{
	case RTGUI_EVENT_PAINT:
		if(widget->on_draw != RT_NULL)
			widget->on_draw(wdt, event);
		else
			rtgui_terminal_ondraw(tma);
		return RT_FALSE;

	case RTGUI_EVENT_KBD:
	{
		struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
		if(ekbd->type == RTGUI_KEYDOWN)
		{
			rt_int16_t line_current_update;
			line_current_update = tma->now_item;
			if(ekbd->key == RTGUIK_LEFT)
			{
				if(tma->now_item > tma->item_per_page)
				{
					line_current_update -= tma->item_per_page;
				}
				else if(tma->now_item > 0)
				{
					line_current_update = 0;
				}
			}
			else if(ekbd->key == RTGUIK_RIGHT)
			{
				if(tma->now_item + tma->item_per_page < tma->item_count - 1)
				{
					line_current_update += tma->item_per_page;
				}
			}
			else if(ekbd->key == RTGUIK_UP)
			{
				if(tma->now_item > 0)
				{
					line_current_update --;
				}
			}
			else if(ekbd->key == RTGUIK_DOWN)
			{
				if(tma->now_item + tma->item_per_page < tma->item_count - 1)
				{
					line_current_update ++;
				}
			}

			if(tma->now_item != line_current_update)
			{
				tma->now_item = line_current_update;
				rtgui_widget_update(wdt);
				return RT_TRUE;
			}
		}
		return RT_TRUE;
	}
	default:
		return rtgui_widget_event_handler(widget,event);
	}
}
Esempio n. 16
0
rt_bool_t rtgui_digtube_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
	struct rtgui_digtube *digtube;
    struct rtgui_dc *dc;
    rtgui_rect_t rect;
    rtgui_rect_t text_rect;
	rtgui_color_t color = 0;
	char * disbuf;
	char tempbuf[8];
	int i;

	RTGUI_WIDGET_EVENT_HANDLER_PREPARE

	digtube = RTGUI_DIGTUBE(object);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:

	    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(object));
		if (dc == RT_NULL)
			break;
		rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
		rtgui_dc_fill_rect(dc, &rect);

		if (! (digtube->tube_style & RTGUI_DIGTUBE_STYLE_NOBACKFONT))
		{
			color = RTGUI_DC_BC(dc);
			RTGUI_DC_BC(dc) = digtube->digit_bc;
		}
		
		if (digtube->tube_style & RTGUI_DIGTUBE_STYLE_DISCODES)
			disbuf = (char *) (digtube->value);
		else
		{
			const char * format =  
				digtube->tube_style & RTGUI_DIGTUBE_STYLE_DISHEXNUM ? 
				"%7x" : "%7d";

			disbuf = &tempbuf[0];
			rt_snprintf(disbuf, 8, format, digtube->value);
			
			/* */
			for (i=0; i<7; i++)
			{
				if (disbuf[i] == ' ')
					disbuf[i] = 0;
				else
				{
					disbuf[i] = (disbuf[i] >= '0' && disbuf[i] <= '9') ? disbuf[i] - '0':
						disbuf[i] - 'a' + 10;

					disbuf[i] = digtube_code_table[disbuf[i]];
				}
			}

			disbuf = tempbuf + 7 - digtube->tube_count;
		}

		text_rect.x1 = 0;
		text_rect.y1 = 0;
		text_rect.x2 = (digtube->digit_width + digtube->digit_space) * digtube->tube_count
		                -digtube->digit_space;
		text_rect.y2 = digtube->digit_hight;

		rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_DC_TEXTALIGN(dc));
		for (i=0; i<digtube->tube_count; i++)
		{
			rtgui_dc_draw_digitfont_code(dc, &digtube->digitfont, &text_rect, disbuf[i]);
			text_rect.x1 += digtube->digit_width + digtube->digit_space;
		}

		if (! (digtube->tube_style & RTGUI_DIGTUBE_STYLE_NOBACKFONT))
			RTGUI_DC_BC(dc) = color;
		rtgui_dc_end_drawing(dc);
		break;
	default:
		return rtgui_widget_event_handler(object, event);
	}

	return RT_FALSE;
}
Esempio n. 17
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);
}
rt_bool_t rtgui_textview_event_handler(struct rtgui_object* object, struct rtgui_event* event)
{
	struct rtgui_textview* textview;
	RTGUI_WIDGET_EVENT_HANDLER_PREPARE

	textview = RTGUI_TEXTVIEW(object);
	switch (event->type)
	{
	case RTGUI_EVENT_PAINT:
		_draw_textview(textview);
		break;

	case RTGUI_EVENT_KBD:
		{
		struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
		if (ekbd->type == RTGUI_KEYDOWN)
		{
			rt_int16_t line_current_update;
			line_current_update = textview->line_current;
			if (ekbd->key == RTGUIK_LEFT)
			{
				if (textview->line_current > textview->line_page_count)
				{
					line_current_update -= textview->line_page_count;
				}
				else if (textview->line_current > 0)
				{
					line_current_update = 0;
				}
			}
			else if (ekbd->key == RTGUIK_RIGHT)
			{
				if (textview->line_current + textview->line_page_count < textview->line_count - 1)
				{
					line_current_update += textview->line_page_count;
				}
			}
			else if (ekbd->key == RTGUIK_UP)
			{
				if (textview->line_current > 0)
				{
					line_current_update --;
				}
			}
			else if (ekbd->key == RTGUIK_DOWN)
			{
				if (textview->line_current + textview->line_page_count < textview->line_count - 1)
				{
					line_current_update ++;
				}
			}

			if (textview->line_current != line_current_update)
			{
				textview->line_current = line_current_update;
				rtgui_widget_update(widget);
				return RT_TRUE;
			}
		}
		break;
		}
	default:
		return rtgui_widget_event_handler(RTGUI_OBJECT(widget),event);
	}

	return RT_FALSE;
}