Browse Source

add more optimization options, remove caret implementation.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@278 bbd45198-f89e-11dd-88c7-29a3b14d5316
bernard.xiong 15 years ago
parent
commit
5950b02b04

+ 0 - 2
rtgui/SConscript

@@ -9,7 +9,6 @@ common/rtgui_theme.c
 common/asc12font.c
 common/asc16font.c
 common/color.c
-common/caret.c
 common/dc.c
 common/dc_buffer.c
 common/dc_hw.c
@@ -47,7 +46,6 @@ widgets/window.c
 widgets/workbench.c
 """)
 
-
 # The set of source files associated with this SConscript file.
 src_local = common_src + server_src + widgets_src
 

+ 0 - 214
rtgui/common/caret.c

@@ -1,214 +0,0 @@
-/*
- * File      : caret.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date           Author       Notes
- * 2009-10-16     Bernard      first version
- */
-#include <rtgui/dc.h>
-#include <rtgui/caret.h>
-#include <rtgui/rtgui_system.h>
-
-#define RTGUI_CARET_WIDTH	2
-
-#ifdef __WIN32__
-#define RTGUI_CARET_BLINK	300
-#else
-#define RTGUI_CARET_BLINK	30
-#endif
-
-static void rtgui_caret_blink(struct rtgui_timer* timer, void* parameter)
-{
-	struct rtgui_caret* caret;
-	rtgui_widget_t* widget;
-
-	caret = (struct rtgui_caret*)parameter;
-
-	RT_ASSERT(caret != RT_NULL);
-
-	if (caret->owner == RT_NULL) return;
-
-	/* caret's owner is visible? */
-	widget = caret->owner;
-	do
-	{
-		if (RTGUI_WIDGET_IS_HIDE(widget) == RT_TRUE) return;
-
-		widget = widget->parent;
-	} while (widget != RT_NULL);
-
-	if (caret->is_show == RT_TRUE)
-	{
-		/* set to false */
-		caret->is_show = RT_FALSE;
-
-		/* update owner widget */
-		if (caret->owner != RT_NULL)
-		{
-			rtgui_widget_update(caret->owner);
-		}
-	}
-	else
-	{
-		/* set to true */
-		caret->is_show = RT_TRUE;
-
-		/* draw caret */
-		rtgui_caret_draw(caret);
-	}
-}
-
-struct rtgui_caret* rtgui_caret_create(struct rtgui_widget* owner)
-{
-	struct rtgui_caret* caret;
-
-	RT_ASSERT(owner != RT_NULL);
-
-	caret = (struct rtgui_caret*)rtgui_malloc(sizeof(struct rtgui_caret));
-	if (caret != RT_NULL)
-	{
-		caret->is_show = RT_FALSE;
-
-		caret->extent.x1 = 0;
-		caret->extent.y1 = 0;
-		caret->extent.x2 = RTGUI_CARET_WIDTH;
-		caret->extent.y2 = owner->gc.font->height;
-		caret->owner = owner;
-
-		caret->dc = (struct rtgui_dc*)rtgui_dc_buffer_create(RTGUI_CARET_WIDTH, caret->extent.y2);
-		if (caret->dc == RT_NULL) goto __exit;
-
-		rtgui_dc_set_color(caret->dc, black);
-		rtgui_dc_fill_rect(caret->dc, &(caret->extent));
-
-		caret->timer_period = RTGUI_CARET_BLINK;
-		caret->timer = rtgui_timer_create(caret->timer_period,
-			RT_TIMER_FLAG_PERIODIC,
-			rtgui_caret_blink, caret);
-		if (caret->timer == RT_NULL) goto __exit_dc;
-
-		caret->show_point.x = 0;
-		caret->show_point.y = 0;
-	}
-
-	return caret;
-
-__exit_dc:
-	rtgui_dc_destory(caret->dc);
-__exit:
-	rtgui_free(caret);
-	return RT_NULL;
-}
-
-void rtgui_caret_destroy(struct rtgui_caret* caret)
-{
-	RT_ASSERT(caret != RT_NULL);
-
-	if (caret->is_show == RT_TRUE)
-	{
-		/* stop timer */
-		rtgui_timer_stop(caret->timer);
-	}
-
-	caret->owner = RT_NULL;
-	rtgui_dc_destory(caret->dc);
-	rtgui_timer_destory(caret->timer);
-
-	rtgui_free(caret);
-}
-
-/* show caret on owner widget logic position */
-void rtgui_caret_show(struct rtgui_caret* caret, rt_base_t x, rt_base_t y)
-{
-	if (caret->is_show == RT_TRUE)
-	{
-		/* set show flag and stop blink timer */
-		caret->is_show = RT_FALSE;
-		rtgui_timer_stop(caret->timer);
-	}
-
-	/* set show x and y */
-	caret->show_point.x = x;
-	caret->show_point.y = y;
-
-	/* set show flag and start blink timer */
-	caret->is_show = RT_TRUE;
-
-	/* draw caret */
-	rtgui_caret_draw(caret);
-
-	/* start blink timer */
-	rtgui_timer_start(caret->timer);
-}
-
-void rtgui_caret_hide(struct rtgui_caret* caret)
-{
-	RT_ASSERT(caret != RT_NULL);
-
-	/* set show flag and stop blink timer */
-	caret->is_show = RT_FALSE;
-	rtgui_timer_stop(caret->timer);
-
-	/* update owner widget */
-	if (caret->owner != RT_NULL)
-	{
-		rtgui_widget_update(caret->owner);
-	}
-}
-
-void rtgui_caret_set_point(struct rtgui_caret* caret, int x, int y)
-{
-	RT_ASSERT(caret != RT_NULL);
-
-	if (caret->is_show == RT_TRUE)
-	{
-		/* stop the old caret */
-		rtgui_timer_stop(caret->timer);
-		/* update owner widget */
-		if (caret->owner != RT_NULL && caret->is_show)
-		{
-			rtgui_widget_update(caret->owner);
-		}
-	}
-
-	caret->show_point.x = x;
-	caret->show_point.y = y;
-
-	/* draw caret */
-	rtgui_caret_draw(caret);
-
-	/* start blink timer */
-	rtgui_timer_start(caret->timer);
-}
-
-void rtgui_caret_set_box(struct rtgui_caret* caret, int w, int h)
-{
-	RT_ASSERT(caret != RT_NULL);
-
-	caret->extent.x2 = caret->extent.x1 + w;
-	caret->extent.y2 = caret->extent.y1 + h;
-}
-
-void rtgui_caret_draw(struct rtgui_caret* caret)
-{
-	RT_ASSERT(caret != RT_NULL);
-
-	if (caret->is_show == RT_TRUE && caret->owner->toplevel != RT_NULL)
-	{
-		struct rtgui_rect rect = caret->extent;
-		struct rtgui_point point = {0, 0};
-		struct rtgui_dc* hw_dc;
-
-		rtgui_rect_moveto(&rect, caret->show_point.x, caret->show_point.y);
-		hw_dc = rtgui_dc_begin_drawing(caret->owner);
-		rtgui_dc_blit(caret->dc, &point, hw_dc, &rect);
-		rtgui_dc_end_drawing(hw_dc);
-	}
-}
-

+ 3 - 0
rtgui/common/dc_buffer.c

@@ -16,6 +16,7 @@
 #include <rtgui/color.h>
 #include <rtgui/rtgui_system.h>
 
+#ifndef RTGUI_USING_SMALL_SIZE
 struct rtgui_dc_buffer
 {
 	struct rtgui_dc parent;
@@ -390,3 +391,5 @@ static void rtgui_dc_buffer_get_rect(struct rtgui_dc* self, rtgui_rect_t* rect)
 	rect->x2 = dc->width;
 	rect->y2 = dc->height;
 }
+#endif
+

+ 0 - 53
rtgui/include/rtgui/caret.h

@@ -1,53 +0,0 @@
-/*
- * File      : caret.h
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date           Author       Notes
- * 2009-10-16     Bernard      first version
- */
-#ifndef __RTGUI_CARET_H__
-#define __RTGUI_CARET_H__
-
-#include <rtgui/dc.h>
-#include <rtgui/rtgui_system.h>
-#include <rtgui/widgets/widget.h>
-
-struct rtgui_caret
-{
-	/* show flag */
-	rt_bool_t is_show;
-	/* the show point of caret */
-	struct rtgui_point show_point;
-
-	/* widget owner */
-	struct rtgui_widget* owner;
-
-	/* caret buffer dc */
-	struct rtgui_dc *dc;
-
-	/* caret extent */
-	struct rtgui_rect extent;
-
-	/* the blink timer */
-	struct rtgui_timer* timer;
-	rt_int32_t timer_period;
-};
-typedef struct rtgui_caret rtgui_caret_t;
-
-struct rtgui_caret* rtgui_caret_create(struct rtgui_widget* owner);
-void rtgui_caret_destroy(struct rtgui_caret* caret);
-
-void rtgui_caret_show(struct rtgui_caret* caret, rt_base_t x, rt_base_t y);
-void rtgui_caret_hide(struct rtgui_caret* caret);
-void rtgui_caret_draw(struct rtgui_caret* caret);
-
-void rtgui_caret_set_point(struct rtgui_caret* caret, int x, int y);
-void rtgui_caret_set_box(struct rtgui_caret* caret, int w, int h);
-
-#endif

+ 2 - 0
rtgui/include/rtgui/rtgui_config.h

@@ -36,6 +36,8 @@
 #define RTGUI_USING_HZ_FILE
 #endif
 
+#define RTGUI_USING_SMALL_SIZE
+
 #define RTGUI_SVR_THREAD_PRIORITY		15
 #define RTGUI_SVR_THREAD_TIMESLICE		5
 #define RTGUI_SVR_THREAD_STACK_SIZE		2048

+ 1 - 2
rtgui/include/rtgui/widgets/textbox.h

@@ -52,8 +52,7 @@ struct rtgui_textbox
 	rt_uint8_t* text;
 	rt_size_t font_width;
 
-	int caret_x, caret_y;
-	struct rtgui_caret* caret;
+	struct rtgui_timer* caret_timer;
 
 	/* widget private data */
 	rt_bool_t (*on_enter) 	(struct rtgui_widget* widget, struct rtgui_event* event);

+ 12 - 2
rtgui/include/rtgui/widgets/widget.h

@@ -96,24 +96,30 @@ struct rtgui_widget
 
 	/* the widget extent */
 	rtgui_rect_t extent;
+#ifndef RTGUI_USING_SMALL_SIZE
 	rt_int16_t mini_width, mini_height;
 	rt_int16_t margin, margin_style;
+#endif
 
 	/* the rect clip */
 	rtgui_region_t clip;
+#ifndef RTGUI_USING_SMALL_SIZE
 	rt_uint32_t clip_sync;
+#endif
 
 	/* the event handler */
 	rt_bool_t (*event_handler)	(struct rtgui_widget* widget, struct rtgui_event* event);
 
 	/* call back */
-	rt_bool_t (*on_draw)		(struct rtgui_widget* widget, struct rtgui_event* event);
 	rt_bool_t (*on_focus_in)	(struct rtgui_widget* widget, struct rtgui_event* event);
 	rt_bool_t (*on_focus_out)	(struct rtgui_widget* widget, struct rtgui_event* event);
+#ifndef RTGUI_USING_SMALL_SIZE
+	rt_bool_t (*on_draw)		(struct rtgui_widget* widget, struct rtgui_event* event);
 	rt_bool_t (*on_mouseclick)	(struct rtgui_widget* widget, struct rtgui_event* event);
 	rt_bool_t (*on_key)			(struct rtgui_widget* widget, struct rtgui_event* event);
 	rt_bool_t (*on_size)		(struct rtgui_widget* widget, struct rtgui_event* event);
 	rt_bool_t (*on_command)		(struct rtgui_widget* widget, struct rtgui_event* event);
+#endif
 };
 typedef struct rtgui_widget rtgui_widget_t;
 
@@ -147,20 +153,24 @@ void rtgui_widget_focus(rtgui_widget_t * widget);
 void rtgui_widget_unfocus(rtgui_widget_t *widget);
 
 /* event handler for each command */
-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);
 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);
 void rtgui_widget_set_onmouseclick(rtgui_widget_t* widget, rtgui_event_handler_ptr handler);
 void rtgui_widget_set_onkey(rtgui_widget_t* widget, rtgui_event_handler_ptr handler);
 void rtgui_widget_set_onsize(rtgui_widget_t* widget, rtgui_event_handler_ptr handler);
 void rtgui_widget_set_oncommand(rtgui_widget_t* widget, rtgui_event_handler_ptr handler);
+#endif
 
 /* get and set rect of widget */
 void rtgui_widget_get_rect(rtgui_widget_t* widget, rtgui_rect_t *rect);
 void rtgui_widget_set_rect(rtgui_widget_t* widget, rtgui_rect_t* rect);
 
+#ifndef RTGUI_USING_SMALL_SIZE
 void rtgui_widget_set_miniwidth(rtgui_widget_t* widget, int width);
 void rtgui_widget_set_miniheight(rtgui_widget_t* widget, int height);
+#endif
 
 /* get the physical position of a logic point on widget */
 void rtgui_widget_point_to_device(rtgui_widget_t * widget, rtgui_point_t * point);

+ 3 - 0
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
+

+ 16 - 3
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
 				}
 
 			}

+ 11 - 1
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;

+ 4 - 0
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
 }

+ 30 - 19
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;
 }
+

+ 4 - 0
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;

+ 2 - 0
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;

+ 28 - 8
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));

+ 16 - 3
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