summaryrefslogtreecommitdiff
path: root/rtgui/widgets
diff options
context:
space:
mode:
authorbernard.xiong <[email protected]>2010-01-04 00:05:01 +0000
committerbernard.xiong <[email protected]>2010-01-04 00:05:01 +0000
commit5950b02b04255dda8e5f9c6bd67f94e803a18fd6 (patch)
tree3e0195c85346b8a6f6d30d6b8e90535c06c05643 /rtgui/widgets
parent238b6b89ea489668b7c7c872e99354575318e400 (diff)
add more optimization options, remove caret implementation.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@278 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'rtgui/widgets')
-rw-r--r--rtgui/widgets/box.c3
-rw-r--r--rtgui/widgets/button.c19
-rw-r--r--rtgui/widgets/container.c12
-rw-r--r--rtgui/widgets/iconbox.c4
-rw-r--r--rtgui/widgets/textbox.c49
-rw-r--r--rtgui/widgets/toplevel.c4
-rw-r--r--rtgui/widgets/view.c2
-rw-r--r--rtgui/widgets/widget.c36
-rw-r--r--rtgui/widgets/window.c19
9 files changed, 114 insertions, 34 deletions
diff --git a/rtgui/widgets/box.c b/rtgui/widgets/box.c
index 798f6b8171..4f29fbc595 100644
--- a/rtgui/widgets/box.c
+++ b/rtgui/widgets/box.c
@@ -14,6 +14,7 @@
#include <rtgui/dc.h>
#include <rtgui/widgets/box.h>
+#ifndef RTGUI_USING_SMALL_SIZE
static void _rtgui_box_constructor(rtgui_box_t *box)
{
/* init widget and set event handler */
@@ -338,3 +339,5 @@ rt_uint32_t rtgui_box_get_height(rtgui_box_t* box)
return height;
}
+#endif
+
diff --git a/rtgui/widgets/button.c b/rtgui/widgets/button.c
index 1a563f0dbb..e7c84581cd 100644
--- a/rtgui/widgets/button.c
+++ b/rtgui/widgets/button.c
@@ -75,8 +75,11 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_e
switch (event->type)
{
case RTGUI_EVENT_PAINT:
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_draw != RT_NULL ) widget->on_draw(widget, event);
- else rtgui_theme_draw_button(btn);
+ else
+#endif
+ rtgui_theme_draw_button(btn);
break;
case RTGUI_EVENT_MOUSE_BUTTON:
@@ -94,13 +97,18 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_e
btn->flag |= RTGUI_BUTTON_FLAG_PRESS;
/* draw button */
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_draw != RT_NULL ) widget->on_draw(widget, event);
- else rtgui_theme_draw_button(btn);
+ else
+#endif
+ rtgui_theme_draw_button(btn);
+#ifndef RTGUI_USING_SMALL_SIZE
/* invokes call back */
if (widget->on_mouseclick != RT_NULL &&
emouse->button & RTGUI_MOUSE_BUTTON_UP)
return widget->on_mouseclick(widget, event);
+#endif
}
}
else
@@ -118,13 +126,18 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_e
}
/* draw button */
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_draw != RT_NULL ) widget->on_draw(widget, event);
- else rtgui_theme_draw_button(btn);
+ else
+#endif
+ rtgui_theme_draw_button(btn);
+#ifndef RTGUI_USING_SMALL_SIZE
/* invokes call back */
if (widget->on_mouseclick != RT_NULL &&
emouse->button & RTGUI_MOUSE_BUTTON_UP)
return widget->on_mouseclick(widget, event);
+#endif
}
}
diff --git a/rtgui/widgets/container.c b/rtgui/widgets/container.c
index 8771f70b77..76084f09cb 100644
--- a/rtgui/widgets/container.c
+++ b/rtgui/widgets/container.c
@@ -105,20 +105,24 @@ rt_bool_t rtgui_container_event_handler(rtgui_widget_t* widget, rtgui_event_t* e
switch (event->type)
{
case RTGUI_EVENT_PAINT:
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_draw != RT_NULL)
{
return widget->on_draw(widget, event);
}
+#endif
rtgui_container_dispatch_event(container, event);
break;
case RTGUI_EVENT_KBD:
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_key != RT_NULL)
{
return widget->on_key(widget, event);
}
else
+#endif
{
/* let parent to handle keyboard event */
if (widget->parent != RT_NULL && widget->parent != widget->toplevel)
@@ -133,11 +137,13 @@ rt_bool_t rtgui_container_event_handler(rtgui_widget_t* widget, rtgui_event_t* e
if (rtgui_container_dispatch_mouse_event(container,
(struct rtgui_event_mouse*)event) == RT_FALSE)
{
+#ifndef RTGUI_USING_SMALL_SIZE
/* handle event in current widget */
if (widget->on_mouseclick != RT_NULL)
{
return widget->on_mouseclick(widget, event);
}
+#endif
}
else return RT_TRUE;
break;
@@ -146,7 +152,7 @@ rt_bool_t rtgui_container_event_handler(rtgui_widget_t* widget, rtgui_event_t* e
if (rtgui_container_dispatch_mouse_event(container,
(struct rtgui_event_mouse*)event) == RT_FALSE)
{
-#if 0
+#ifndef RTGUI_USING_SMALL_SIZE
/* handle event in current widget */
if (widget->on_mousemotion != RT_NULL)
{
@@ -160,10 +166,12 @@ rt_bool_t rtgui_container_event_handler(rtgui_widget_t* widget, rtgui_event_t* e
case RTGUI_EVENT_COMMAND:
if (rtgui_container_dispatch_event(container, event) == RT_FALSE)
{
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_command != RT_NULL)
{
return widget->on_command(widget, event);
}
+#endif
}
else return RT_TRUE;
break;
@@ -171,8 +179,10 @@ rt_bool_t rtgui_container_event_handler(rtgui_widget_t* widget, rtgui_event_t* e
case RTGUI_EVENT_RESIZE:
if (rtgui_container_dispatch_event(container, event) == RT_FALSE)
{
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_size != RT_NULL)
return widget->on_size(widget, event);
+#endif
}
else return RT_TRUE;
break;
diff --git a/rtgui/widgets/iconbox.c b/rtgui/widgets/iconbox.c
index c141e81988..65f094e64f 100644
--- a/rtgui/widgets/iconbox.c
+++ b/rtgui/widgets/iconbox.c
@@ -61,8 +61,10 @@ rt_bool_t rtgui_iconbox_event_handler(struct rtgui_widget* widget, struct rtgui_
switch (event->type)
{
case RTGUI_EVENT_PAINT:
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
else
+#endif
{
rtgui_theme_draw_iconbox(iconbox);
}
@@ -162,6 +164,8 @@ void rtgui_iconbox_set_text_position(struct rtgui_iconbox* iconbox, int position
}
}
+#ifndef RTGUI_USING_SMALL_SIZE
rtgui_widget_set_miniwidth(RTGUI_WIDGET(iconbox), rect.x2);
rtgui_widget_set_miniheight(RTGUI_WIDGET(iconbox), rect.y2);
+#endif
}
diff --git a/rtgui/widgets/textbox.c b/rtgui/widgets/textbox.c
index 2f1e79227b..63b4483a10 100644
--- a/rtgui/widgets/textbox.c
+++ b/rtgui/widgets/textbox.c
@@ -26,6 +26,15 @@ static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kb
static rt_bool_t rtgui_textbox_onfocus(struct rtgui_widget* widget, struct rtgui_event* event);
static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_widget* widget, struct rtgui_event* event);
+static void _rtgui_textbox_caret_timeout(void *parameter)
+{
+ rtgui_textbox_t* box;
+
+ box = (rtgui_textbox_t*)parameter;
+
+ return ;
+}
+
static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
{
rtgui_rect_t rect = {0, 0, RTGUI_TEXTBOX_DEFAULT_WIDTH, RTGUI_TEXTBOX_DEFAULT_HEIGHT};
@@ -40,8 +49,8 @@ static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(box)) = RTGUI_ALIGN_CENTER_VERTICAL;
/* set proper of control */
- box->caret_x = box->caret_y = 0;
- box->caret = rtgui_caret_create(RTGUI_WIDGET(box));
+ box->caret_timer = rtgui_timer_create(RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC,
+ _rtgui_textbox_caret_timeout, box);
box->line = box->line_begin = box->position = 0;
box->type = RTGUI_TEXTBOX_SINGLE;
@@ -61,11 +70,8 @@ static void _rtgui_textbox_deconstructor(rtgui_textbox_t *box)
box->text = RT_NULL;
}
- if (box->caret != RT_NULL)
- {
- rtgui_caret_destroy(box->caret);
- box->caret = RT_NULL;
- }
+ rtgui_timer_destory(box->caret_timer);
+ box->caret_timer = RT_NULL;
}
rtgui_type_t *rtgui_textbox_type_get(void)
@@ -112,9 +118,6 @@ static void rtgui_textbox_onmouse(struct rtgui_textbox* box, struct rtgui_event_
box->position = x / box->font_width;
}
- rtgui_caret_set_point(box->caret, RTGUI_TEXTBOX_MARGIN + box->position * box->font_width, 2);
- rtgui_caret_set_box(box->caret, 2, rtgui_rect_height(RTGUI_WIDGET(box)->extent) - 4);
-
/* set widget focus */
rtgui_widget_focus(RTGUI_WIDGET(box));
}
@@ -215,17 +218,14 @@ static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kb
/* re-draw text box */
rtgui_theme_draw_textbox(box);
- rtgui_caret_set_point(box->caret,
- RTGUI_TEXTBOX_MARGIN + box->position * box->font_width , 2);
- rtgui_caret_set_box(box->caret, 2, rtgui_rect_height(RTGUI_WIDGET(box)->extent) - 4);
}
static rt_bool_t rtgui_textbox_onfocus(struct rtgui_widget* widget, struct rtgui_event* event)
{
struct rtgui_textbox* box = (struct rtgui_textbox*)widget;
- /* show caret */
- rtgui_caret_show(box->caret, box->caret_x, box->caret_y);
+ /* start caret timer */
+ rtgui_timer_start(box->caret_timer);
return RT_TRUE;
}
@@ -234,8 +234,9 @@ static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_widget* widget, struct rtg
{
struct rtgui_textbox* box = (struct rtgui_textbox*)widget;
+ /* stop caret timer */
+ rtgui_timer_stop(box->caret_timer);
/* hide caret */
- rtgui_caret_hide(box->caret);
return RT_TRUE;
}
@@ -247,18 +248,27 @@ rt_bool_t rtgui_textbox_event_handler(struct rtgui_widget* widget, struct rtgui_
switch (event->type)
{
case RTGUI_EVENT_PAINT:
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else rtgui_theme_draw_textbox(box);
+ else
+#endif
+ rtgui_theme_draw_textbox(box);
break;
case RTGUI_EVENT_MOUSE_BUTTON:
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_mouseclick != RT_NULL) widget->on_mouseclick(widget, event);
- else rtgui_textbox_onmouse(box, (struct rtgui_event_mouse*)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(widget, event);
- else rtgui_textbox_onkey(box, (struct rtgui_event_kbd*)event);
+ else
+#endif
+ rtgui_textbox_onkey(box, (struct rtgui_event_kbd*)event);
return RT_TRUE;
}
@@ -348,3 +358,4 @@ void rtgui_widget_set_line_length(struct rtgui_textbox* box, rt_size_t length)
/* set line length */
box->line_length = length;
}
+
diff --git a/rtgui/widgets/toplevel.c b/rtgui/widgets/toplevel.c
index 1c7da78517..953ee506c5 100644
--- a/rtgui/widgets/toplevel.c
+++ b/rtgui/widgets/toplevel.c
@@ -98,10 +98,12 @@ rt_bool_t rtgui_toplevel_event_handler(rtgui_widget_t* widget, rtgui_event_t* ev
case RTGUI_EVENT_COMMAND:
if (rtgui_container_dispatch_event(RTGUI_CONTAINER(widget), event) != RT_TRUE)
{
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_command != RT_NULL)
{
widget->on_command(widget, event);
}
+#endif
}
else return RT_TRUE;
break;
@@ -151,7 +153,9 @@ void rtgui_toplevel_update_clip(rtgui_toplevel_t* top)
/* reset toplevel widget clip to extent */
rtgui_region_reset(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->extent));
+#ifndef RTGUI_USING_SMALL_SIZE
RTGUI_WIDGET(top)->clip_sync ++;
+#endif
/* subtract the screen rect */
screen_rect.x1 = screen_rect.y1 = 0;
diff --git a/rtgui/widgets/view.c b/rtgui/widgets/view.c
index fdc301ae45..ed436d5282 100644
--- a/rtgui/widgets/view.c
+++ b/rtgui/widgets/view.c
@@ -70,8 +70,10 @@ rt_bool_t rtgui_view_event_handler(struct rtgui_widget* widget, struct rtgui_eve
switch (event->type)
{
case RTGUI_EVENT_PAINT:
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
else
+#endif
{
struct rtgui_dc* dc;
struct rtgui_rect rect;
diff --git a/rtgui/widgets/widget.c b/rtgui/widgets/widget.c
index f3c876b290..7b0a606e27 100644
--- a/rtgui/widgets/widget.c
+++ b/rtgui/widgets/widget.c
@@ -37,6 +37,7 @@ static void _rtgui_widget_constructor(rtgui_widget_t *widget)
widget->toplevel = RT_NULL;
/* some common event handler */
+#ifndef RTGUI_USING_SMALL_SIZE
widget->on_draw = RT_NULL;
widget->on_focus_in = RT_NULL;
widget->on_focus_out = RT_NULL;
@@ -44,13 +45,16 @@ static void _rtgui_widget_constructor(rtgui_widget_t *widget)
widget->on_key = RT_NULL;
widget->on_size = RT_NULL;
widget->on_command = RT_NULL;
+#endif
/* set default event handler */
widget->event_handler = rtgui_widget_event_handler;
/* does not set widget extent and only set clip_sync to zero */
rtgui_region_init(&(widget->clip));
+#ifndef RTGUI_USING_SMALL_SIZE
widget->clip_sync = 0;
+#endif
}
/* Destroys the widget */
@@ -68,7 +72,9 @@ static void _rtgui_widget_destructor(rtgui_widget_t *widget)
/* fini clip region */
rtgui_region_fini(&(widget->clip));
+#ifndef RTGUI_USING_SMALL_SIZE
widget->clip_sync = 0;
+#endif
}
rtgui_type_t *rtgui_widget_type_get(void)
@@ -105,9 +111,11 @@ void rtgui_widget_set_rect(rtgui_widget_t* widget, rtgui_rect_t* rect)
widget->extent = *rect;
+#ifndef RTGUI_USING_SMALL_SIZE
/* reset mini width and height */
widget->mini_width = rtgui_rect_width(widget->extent);
widget->mini_height = rtgui_rect_height(widget->extent);
+#endif
/* it's not empty, fini it */
if (rtgui_region_not_empty(&(widget->clip)))
@@ -119,6 +127,7 @@ void rtgui_widget_set_rect(rtgui_widget_t* widget, rtgui_rect_t* rect)
rtgui_region_init_with_extents(&(widget->clip), rect);
}
+#ifndef RTGUI_USING_SMALL_SIZE
void rtgui_widget_set_miniwidth(rtgui_widget_t* widget, int width)
{
RT_ASSERT(widget != RT_NULL);
@@ -132,6 +141,7 @@ void rtgui_widget_set_miniheight(rtgui_widget_t* widget, int height)
widget->mini_height = height;
}
+#endif
/*
* This function moves widget and its children to a logic point
@@ -176,25 +186,26 @@ void rtgui_widget_get_rect(rtgui_widget_t* widget, rtgui_rect_t *rect)
}
}
-void rtgui_widget_set_ondraw(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
+void rtgui_widget_set_onfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{
RT_ASSERT(widget != RT_NULL);
- widget->on_draw = handler;
+ widget->on_focus_in = handler;
}
-void rtgui_widget_set_onfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
+void rtgui_widget_set_onunfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{
RT_ASSERT(widget != RT_NULL);
- widget->on_focus_in = handler;
+ widget->on_focus_out = handler;
}
-void rtgui_widget_set_onunfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
+#ifndef RTGUI_USING_SMALL_SIZE
+void rtgui_widget_set_ondraw(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
{
RT_ASSERT(widget != RT_NULL);
- widget->on_focus_out = handler;
+ widget->on_draw = handler;
}
void rtgui_widget_set_onmouseclick(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
@@ -224,6 +235,7 @@ void rtgui_widget_set_oncommand(rtgui_widget_t* widget, rtgui_event_handler_ptr
widget->on_command = handler;
}
+#endif
/**
* @brief Focuses the widget. The focused widget is the widget which can receive the keyboard events
@@ -264,9 +276,11 @@ void rtgui_widget_focus(rtgui_widget_t *widget)
if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(parent))) break;
}
+#ifndef RTGUI_USING_SMALL_SIZE
/* invoke on focus in call back */
- if (widget->on_focus_in)
+ if (widget->on_focus_in != RT_NULL)
widget->on_focus_in(widget, RT_NULL);
+#endif
}
/**
@@ -282,8 +296,10 @@ void rtgui_widget_unfocus(rtgui_widget_t *widget)
if (!widget->toplevel || !RTGUI_WIDGET_IS_FOCUS(widget))
return;
- if (widget->on_focus_out)
+#ifndef RTGUI_USING_SMALL_SIZE
+ if (widget->on_focus_out != RT_NULL)
widget->on_focus_out(widget, RT_NULL);
+#endif
}
void rtgui_widget_point_to_device(rtgui_widget_t* widget, rtgui_point_t* point)
@@ -356,6 +372,7 @@ rtgui_widget_t* rtgui_widget_get_toplevel(rtgui_widget_t* widget)
rt_bool_t rtgui_widget_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
{
+#ifndef RTGUI_USING_SMALL_SIZE
switch (event->type)
{
case RTGUI_EVENT_PAINT:
@@ -378,6 +395,7 @@ rt_bool_t rtgui_widget_event_handler(rtgui_widget_t* widget, rtgui_event_t* even
if (widget->on_size != RT_NULL) return widget->on_size(widget, event);
break;
}
+#endif
return RT_FALSE;
}
@@ -397,8 +415,10 @@ void rtgui_widget_update_clip(rtgui_widget_t* widget)
/* if there is no parent, do not update clip (please use toplevel widget API) */
if (parent == RT_NULL) return;
+#ifndef RTGUI_USING_SMALL_SIZE
/* increase clip sync */
widget->clip_sync ++;
+#endif
/* reset clip to extent */
rtgui_region_reset(&(widget->clip), &(widget->extent));
diff --git a/rtgui/widgets/window.c b/rtgui/widgets/window.c
index b006b2e75d..32e95a2ffd 100644
--- a/rtgui/widgets/window.c
+++ b/rtgui/widgets/window.c
@@ -380,8 +380,11 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_even
}
win->style |= RTGUI_WIN_STYLE_ACTIVATE;
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else rtgui_win_ondraw(win);
+ else
+#endif
+ rtgui_win_ondraw(win);
if (win->on_activate != RT_NULL)
{
@@ -391,8 +394,11 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_even
case RTGUI_EVENT_WIN_DEACTIVATE:
win->style &= ~RTGUI_WIN_STYLE_ACTIVATE;
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else rtgui_win_ondraw(win);
+ else
+#endif
+ rtgui_win_ondraw(win);
if (win->on_deactivate != RT_NULL)
{
@@ -401,17 +407,22 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_even
break;
case RTGUI_EVENT_PAINT:
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else rtgui_win_ondraw(win);
+ else
+#endif
+ rtgui_win_ondraw(win);
break;
case RTGUI_EVENT_MOUSE_BUTTON:
if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win), (struct rtgui_event_mouse*)event) == RT_FALSE)
{
+#ifndef RTGUI_USING_SMALL_SIZE
if (widget->on_mouseclick != RT_NULL)
{
return widget->on_mouseclick(widget, event);
}
+#endif
}
break;
@@ -420,11 +431,13 @@ rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_even
if (rtgui_widget_dispatch_mouse_event(widget,
(struct rtgui_event_mouse*)event) == RT_FALSE)
{
+#ifndef RTGUI_USING_SMALL_SIZE
/* handle event in current widget */
if (widget->on_mousemotion != RT_NULL)
{
return widget->on_mousemotion(widget, event);
}
+#endif
}
else return RT_TRUE;
#endif