Jelajahi Sumber

sync gui examples with github 6cf0a8bc19c292ca810c917574895c8defa3922e
As always, full log is in GitHub.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2254 bbd45198-f89e-11dd-88c7-29a3b14d5316

dzzxzz@gmail.com 12 tahun lalu
induk
melakukan
9a99573152
38 mengubah file dengan 2896 tambahan dan 2762 penghapusan
  1. 3 0
      examples/gui/SConscript
  2. 89 88
      examples/gui/demo_application.c
  3. 55 55
      examples/gui/demo_fnview.c
  4. 63 63
      examples/gui/demo_listview.c
  5. 300 296
      examples/gui/demo_listview_icon.c
  6. 45 43
      examples/gui/demo_simple_workbench.c
  7. 101 122
      examples/gui/demo_view.c
  8. 3 8
      examples/gui/demo_view.h
  9. 78 76
      examples/gui/demo_view_animation.c
  10. 82 82
      examples/gui/demo_view_benchmark.c
  11. 22 22
      examples/gui/demo_view_box.c
  12. 97 91
      examples/gui/demo_view_buffer_animation.c
  13. 62 62
      examples/gui/demo_view_button.c
  14. 62 62
      examples/gui/demo_view_checkbox.c
  15. 22 22
      examples/gui/demo_view_combobox.c
  16. 157 155
      examples/gui/demo_view_dc.c
  17. 54 54
      examples/gui/demo_view_dc_buffer.c
  18. 120 0
      examples/gui/demo_view_edit.c
  19. 91 89
      examples/gui/demo_view_image.c
  20. 117 117
      examples/gui/demo_view_instrument_panel.c
  21. 85 85
      examples/gui/demo_view_label.c
  22. 168 166
      examples/gui/demo_view_listbox.c
  23. 224 217
      examples/gui/demo_view_listctrl.c
  24. 45 43
      examples/gui/demo_view_menu.c
  25. 46 45
      examples/gui/demo_view_module.c
  26. 26 26
      examples/gui/demo_view_mywidget.c
  27. 26 26
      examples/gui/demo_view_notebook.c
  28. 53 46
      examples/gui/demo_view_progressbar.c
  29. 47 47
      examples/gui/demo_view_radiobox.c
  30. 38 31
      examples/gui/demo_view_scrollbar.c
  31. 37 30
      examples/gui/demo_view_slider.c
  32. 83 83
      examples/gui/demo_view_textbox.c
  33. 73 73
      examples/gui/demo_view_ttf.c
  34. 198 194
      examples/gui/demo_view_window.c
  35. 10 10
      examples/gui/demo_xml.c
  36. 0 19
      examples/gui/gui_init.c
  37. 105 105
      examples/gui/mywidget.c
  38. 9 9
      examples/gui/mywidget.h

+ 3 - 0
examples/gui/SConscript

@@ -13,6 +13,8 @@ demo_view_module.c
 
 src = Split("""
 demo_application.c
+demo_listview.c
+demo_listview_icon.c
 demo_view.c
 demo_view_benchmark.c
 demo_view_dc.c
@@ -37,6 +39,7 @@ demo_view_slider.c
 demo_view_notebook.c
 demo_view_mywidget.c
 demo_view_box.c
+demo_view_edit.c
 mywidget.c
 """)
 

+ 89 - 88
examples/gui/demo_application.c

@@ -7,141 +7,142 @@
 
 struct rtgui_notebook *the_notebook;
 
-static rt_bool_t demo_handle_key(struct rtgui_object* object, struct rtgui_event* event)
+static rt_bool_t demo_handle_key(struct rtgui_object *object, struct rtgui_event *event)
 {
-	struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
-
-	if (ekbd->type == RTGUI_KEYUP)
-	{
-		if (ekbd->key == RTGUIK_RIGHT)
-		{
-			demo_view_next(RT_NULL, RT_NULL);
-			return RT_TRUE;
-		}
-		else if (ekbd->key == RTGUIK_LEFT)
-		{
-			demo_view_prev(RT_NULL, RT_NULL);
-			return RT_TRUE;
-		}
-	}
-	return RT_TRUE;
+    struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
+
+    if (ekbd->type == RTGUI_KEYUP)
+    {
+        if (ekbd->key == RTGUIK_RIGHT)
+        {
+            demo_view_next(RT_NULL, RT_NULL);
+            return RT_TRUE;
+        }
+        else if (ekbd->key == RTGUIK_LEFT)
+        {
+            demo_view_prev(RT_NULL, RT_NULL);
+            return RT_TRUE;
+        }
+    }
+    return RT_TRUE;
 }
 
 struct rtgui_win *main_win;
-static void application_entry(void* parameter)
+static void application_entry(void *parameter)
 {
-	struct rtgui_app *app;
-	struct rtgui_rect rect;
+    struct rtgui_app *app;
+    struct rtgui_rect rect;
 
-	app = rtgui_app_create(rt_thread_self(), "gui_demo");
-	if (app == RT_NULL)
-		return;
+    app = rtgui_app_create(rt_thread_self(), "gui_demo");
+    if (app == RT_NULL)
+        return;
 
-	/* create a full screen window */
-	rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect);
+    /* create a full screen window */
+    rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect);
 
-	main_win = rtgui_win_create(RT_NULL, "demo_win", &rect,
-                        RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE);
-	if (main_win == RT_NULL)
-	{
-		rtgui_app_destroy(app);
-		return;
-	}
+    main_win = rtgui_win_create(RT_NULL, "demo_win", &rect,
+                                RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE);
+    if (main_win == RT_NULL)
+    {
+        rtgui_app_destroy(app);
+        return;
+    }
 
-	rtgui_win_set_onkey(main_win, demo_handle_key);
+    rtgui_win_set_onkey(main_win, demo_handle_key);
 
-	/* create a no title notebook that we can switch demo on it easily. */
-	the_notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_NOTAB);
-	if (the_notebook == RT_NULL)
-	{
-		rtgui_win_destroy(main_win);
-		rtgui_app_destroy(app);
-		return;
-	}
+    /* create a no title notebook that we can switch demo on it easily. */
+    the_notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_NOTAB);
+    if (the_notebook == RT_NULL)
+    {
+        rtgui_win_destroy(main_win);
+        rtgui_app_destroy(app);
+        return;
+    }
 
-	rtgui_container_add_child(RTGUI_CONTAINER(main_win), RTGUI_WIDGET(the_notebook));
+    rtgui_container_add_child(RTGUI_CONTAINER(main_win), RTGUI_WIDGET(the_notebook));
 
-	demo_view_box();
+    //demo_view_box();
 
-	/* 初始化各个例子的视图 */
-	demo_view_benchmark();
+    /* 初始化各个例子的视图 */
+    demo_view_benchmark();
 
-	demo_view_dc();
+    demo_view_dc();
 #ifdef RTGUI_USING_TTF
-	demo_view_ttf();
+    demo_view_ttf();
 #endif
 
 #ifndef RTGUI_USING_SMALL_SIZE
-	demo_view_dc_buffer();
+    demo_view_dc_buffer();
 #endif
-	demo_view_animation();
+    demo_view_animation();
 #ifndef RTGUI_USING_SMALL_SIZE
-	demo_view_buffer_animation();
-	demo_view_instrument_panel();
+    demo_view_buffer_animation();
+    demo_view_instrument_panel();
 #endif
-	demo_view_window();
-	demo_view_label();
-	demo_view_button();
-	demo_view_checkbox();
-	demo_view_progressbar();
-	demo_view_scrollbar();
-	demo_view_radiobox();
-	demo_view_textbox();
-	demo_view_listbox();
-	demo_view_menu();
-	demo_view_listctrl();
-	demo_view_combobox();
-	demo_view_slider();
-	demo_view_notebook();
-	demo_view_mywidget();
+    demo_view_window();
+    demo_view_label();
+    demo_view_button();
+    demo_view_checkbox();
+    demo_view_progressbar();
+    demo_view_scrollbar();
+    demo_view_radiobox();
+    demo_view_textbox();
+    demo_view_listbox();
+    demo_view_menu();
+    demo_view_listctrl();
+    demo_view_combobox();
+    demo_view_slider();
+    demo_view_notebook();
+    demo_view_mywidget();
+    demo_view_edit();
 #if 0
 #if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
-	demo_view_image();
+    demo_view_image();
 #endif
-#ifdef RT_USING_MODULE	
+#ifdef RT_USING_MODULE
 #if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
-	demo_view_module();
+    demo_view_module();
 #endif
 #endif
-	demo_listview_view();
-	demo_listview_icon_view();
+    demo_listview_view();
+    demo_listview_icon_view();
 #if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
-	demo_fn_view();
+    demo_fn_view();
 #endif
 #endif
 
-	rtgui_win_show(main_win, RT_FALSE);
+    rtgui_win_show(main_win, RT_FALSE);
 
-	/* 执行工作台事件循环 */
-	rtgui_app_run(app);
+    /* 执行工作台事件循环 */
+    rtgui_app_run(app);
 
-	rtgui_app_destroy(app);
+    rtgui_app_destroy(app);
 }
 
 void application_init()
 {
-	static rt_bool_t inited = RT_FALSE;
+    static rt_bool_t inited = RT_FALSE;
 
-	if (inited == RT_FALSE) /* 避免重复初始化而做的保护 */
-	{
-		rt_thread_t tid;
+    if (inited == RT_FALSE) /* 避免重复初始化而做的保护 */
+    {
+        rt_thread_t tid;
 
-		tid = rt_thread_create("wb",
-			application_entry, RT_NULL,
-			2048 * 2, 25, 10);
+        tid = rt_thread_create("wb",
+                               application_entry, RT_NULL,
+                               2048 * 2, 25, 10);
 
-		if (tid != RT_NULL)
-			rt_thread_startup(tid);
+        if (tid != RT_NULL)
+            rt_thread_startup(tid);
 
-		inited = RT_TRUE;
-	}
+        inited = RT_TRUE;
+    }
 }
 
 #ifdef RT_USING_FINSH
 #include <finsh.h>
 void application()
 {
-	application_init();
+    application_init();
 }
 /* finsh的命令输出,可以直接执行application()函数以执行上面的函数 */
 FINSH_FUNCTION_EXPORT(application, application demo)

+ 55 - 55
examples/gui/demo_fnview.c

@@ -11,80 +11,80 @@
 
 #if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
 /* 用于显示选择文件名的文本标签 */
-static rtgui_label_t* label;
+static rtgui_label_t *label;
 /* 触发文件列表视图的按钮回调函数 */
-static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
+static void open_btn_onbutton(rtgui_widget_t *widget, struct rtgui_event *event)
 {
-	rtgui_filelist_view_t *view;
-	rtgui_workbench_t *workbench;
-	rtgui_rect_t rect;
+    rtgui_filelist_view_t *view;
+    rtgui_workbench_t *workbench;
+    rtgui_rect_t rect;
 
-	/* 获得顶层的workbench对象 */
-	workbench = RTGUI_APPLICATION(rtgui_widget_get_toplevel(widget));
-	rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
+    /* 获得顶层的workbench对象 */
+    workbench = RTGUI_APPLICATION(rtgui_widget_get_toplevel(widget));
+    rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
 
-	/* 针对Win32平台和其他平台做的不同的其实目录位置 */
+    /* 针对Win32平台和其他平台做的不同的其实目录位置 */
 #ifdef _WIN32
-	view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect);
+    view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect);
 #else
-	view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
+    view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
 #endif
 
-	/* 采用模式形式显示文件列表视图 */
-	if (rtgui_container_show(RTGUI_CONTAINER(view), RT_TRUE) == RTGUI_MODAL_OK)
-	{
-		char path[32];
+    /* 采用模式形式显示文件列表视图 */
+    if (rtgui_container_show(RTGUI_CONTAINER(view), RT_TRUE) == RTGUI_MODAL_OK)
+    {
+        char path[32];
 
-		/* 在文件列表视图中成功选择文件,这里获得相应的路径名 */
-		rtgui_filelist_view_get_fullpath(view, path, sizeof(path));
+        /* 在文件列表视图中成功选择文件,这里获得相应的路径名 */
+        rtgui_filelist_view_get_fullpath(view, path, sizeof(path));
 
-		/* 设置文件路径到文本标签 */
-		rtgui_label_set_text(label, path);
-	}
+        /* 设置文件路径到文本标签 */
+        rtgui_label_set_text(label, path);
+    }
 
-	/* 删除 文件列表 视图 */
-	rtgui_container_destroy(RTGUI_CONTAINER(view));
+    /* 删除 文件列表 视图 */
+    rtgui_container_destroy(RTGUI_CONTAINER(view));
 }
 
 /* 创建用于演示文件列表视图的视图 */
-rtgui_container_t* demo_fn_view(rtgui_workbench_t* workbench)
+rtgui_container_t *demo_fn_view(rtgui_workbench_t *workbench)
 {
-	rtgui_rect_t rect;
-	rtgui_container_t* view;
-	rtgui_button_t* open_btn;
-	rtgui_font_t* font;
+    rtgui_rect_t rect;
+    rtgui_container_t *view;
+    rtgui_button_t *open_btn;
+    rtgui_font_t *font;
 
-	/* 默认采用12字体的显示 */
-	font = rtgui_font_refer("asc", 12);
+    /* 默认采用12字体的显示 */
+    font = rtgui_font_refer("asc", 12);
 
-	/* 创建演示用的视图 */
-	view = demo_view(workbench, "FileList View");
-	/* 获得演示视图的位置信息 */
-	demo_view_get_rect(view, &rect);
+    /* 创建演示用的视图 */
+    view = demo_view(workbench, "FileList View");
+    /* 获得演示视图的位置信息 */
+    demo_view_get_rect(view, &rect);
 
-	rect.x1 += 5;
-	rect.x2 -= 5;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
-	/* 创建显示文件路径用的文本标签 */
-	label = rtgui_label_create("fn: ");
-	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
+    /* 创建显示文件路径用的文本标签 */
+    label = rtgui_label_create("fn: ");
+    rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
 
-	/* 获得演示视图的位置信息 */
-	demo_view_get_rect(view, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 80;
-	rect.y1 += 30;
-	rect.y2 = rect.y1 + 20;
-	/* 创建按钮以触发一个新的文件列表视图 */
-	open_btn = rtgui_button_create("Open File");
-	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn));
-	rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
-	RTGUI_WIDGET_FONT(RTGUI_WIDGET(open_btn)) = font;
-	rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
+    /* 获得演示视图的位置信息 */
+    demo_view_get_rect(view, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 80;
+    rect.y1 += 30;
+    rect.y2 = rect.y1 + 20;
+    /* 创建按钮以触发一个新的文件列表视图 */
+    open_btn = rtgui_button_create("Open File");
+    rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn));
+    rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
+    RTGUI_WIDGET_FONT(RTGUI_WIDGET(open_btn)) = font;
+    rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
 
-	return view;
+    return view;
 }
 #endif

+ 63 - 63
examples/gui/demo_listview.c

@@ -10,98 +10,98 @@
 #include <rtgui/widgets/window.h>
 #include <rtgui/widgets/list_view.h>
 
-static struct rtgui_app *application = RT_NULL;
-static rtgui_list_view_t* _view = RT_NULL;
+static struct rtgui_application *application = RT_NULL;
+static rtgui_list_view_t *_view = RT_NULL;
 // static rtgui_image_t* return_image = RT_NULL;
 
 /* 列表项的动作函数 */
-static void listitem_action(rtgui_widget_t *widget, void* parameter)
+static void listitem_action(rtgui_widget_t *widget, void *parameter)
 {
-	char label_text[32];
-	rtgui_win_t *win;
-	rtgui_label_t *label;
-	rtgui_rect_t rect = {0, 0, 150, 80};
-	int no = (int)parameter;
+    char label_text[32];
+    rtgui_win_t *win;
+    rtgui_label_t *label;
+    rtgui_rect_t rect = {0, 0, 150, 80};
+    int no = (int)parameter;
 
-	rtgui_rect_moveto(&rect, 20, 50);
+    rtgui_rect_moveto(&rect, 20, 50);
 
-	/* 显示消息窗口 */
-	win = rtgui_win_create(RTGUI_TOPLEVEL(application),
-		"窗口", &rect, RTGUI_WIN_STYLE_DEFAULT);
+    /* 显示消息窗口 */
+    win = rtgui_win_create(RTGUI_TOPLEVEL(application),
+                           "窗口", &rect, RTGUI_WIN_STYLE_DEFAULT);
 
-	rect.x1 += 20;
-	rect.x2 -= 5;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
+    rect.x1 += 20;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
 
-	/* 添加相应的标签 */
-	rt_sprintf(label_text, "动作 %d", no);
-	label = rtgui_label_create(label_text);
+    /* 添加相应的标签 */
+    rt_sprintf(label_text, "动作 %d", no);
+    label = rtgui_label_create(label_text);
 
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	rtgui_container_add_child(win, RTGUI_WIDGET(label));
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    rtgui_container_add_child(win, RTGUI_WIDGET(label));
 
-	/* 非模态显示窗口 */
-	rtgui_win_show(win, RT_FALSE);
+    /* 非模态显示窗口 */
+    rtgui_win_show(win, RT_FALSE);
 }
 
 /* 返回功能的动作函数 */
-static void return_action(rtgui_widget_t* widget, void* parameter)
+static void return_action(rtgui_widget_t *widget, void *parameter)
 {
-	rtgui_container_end_modal(RTGUI_CONTAINER(_view), RTGUI_MODAL_OK);
+    rtgui_container_end_modal(RTGUI_CONTAINER(_view), RTGUI_MODAL_OK);
 }
 
 /* 各个列表项定义 */
 static struct rtgui_list_item items[] =
 {
-	{"列表项1", RT_NULL, listitem_action, (void*)1},
-	{"列表项2", RT_NULL, listitem_action, (void*)2},
-	{"列表项3", RT_NULL, listitem_action, (void*)3},
-	{"列表项4", RT_NULL, listitem_action, (void*)4},
-	{"列表项5", RT_NULL, listitem_action, (void*)5},
-	{"返回",    RT_NULL, return_action,    RT_NULL},
+    {"列表项1", RT_NULL, listitem_action, (void *)1},
+    {"列表项2", RT_NULL, listitem_action, (void *)2},
+    {"列表项3", RT_NULL, listitem_action, (void *)3},
+    {"列表项4", RT_NULL, listitem_action, (void *)4},
+    {"列表项5", RT_NULL, listitem_action, (void *)5},
+    {"返回",    RT_NULL, return_action,    RT_NULL},
 };
 
 /* 打开列表视图用的按钮触发函数 */
-static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
+static void open_btn_onbutton(rtgui_widget_t *widget, struct rtgui_event *event)
 {
-	rtgui_rect_t rect;
+    rtgui_rect_t rect;
 
-	/* 获得顶层的application */
-	application = RTGUI_APPLICATION(rtgui_widget_get_toplevel(widget));
-	rtgui_widget_get_rect(RTGUI_WIDGET(application), &rect);
+    /* 获得顶层的application */
+    application = RTGUI_APPLICATION(rtgui_widget_get_toplevel(widget));
+    rtgui_widget_get_rect(RTGUI_WIDGET(application), &rect);
 
-	/* 创建一个列表视图, 项指定为items */
-	_view = rtgui_list_view_create(items, sizeof(items)/sizeof(struct rtgui_list_item),
-		&rect, RTGUI_LIST_VIEW_LIST);
+    /* 创建一个列表视图, 项指定为items */
+    _view = rtgui_list_view_create(items, sizeof(items) / sizeof(struct rtgui_list_item),
+                                   &rect, RTGUI_LIST_VIEW_LIST);
 
-	rtgui_application_add_container(application, RTGUI_CONTAINER(_view));
+    rtgui_application_add_container(application, RTGUI_CONTAINER(_view));
 
-	/* 模式显示视图 */
-	rtgui_container_show(RTGUI_CONTAINER(_view), RT_TRUE);
-	rtgui_container_destroy(RTGUI_CONTAINER(_view));
-	_view = RT_NULL;
+    /* 模式显示视图 */
+    rtgui_container_show(RTGUI_CONTAINER(_view), RT_TRUE);
+    rtgui_container_destroy(RTGUI_CONTAINER(_view));
+    _view = RT_NULL;
 }
 
 /* 创建用于演示列表视图的视图 */
-rtgui_container_t* demo_listview_view(void)
+rtgui_container_t *demo_listview_view(void)
 {
-	rtgui_rect_t rect;
-	rtgui_container_t *container;
-	rtgui_button_t* open_btn;
-
-	container = demo_view("列表视图演示");
-
-	/* 添加动作按钮 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 80;
-	rect.y1 += 30;
-	rect.y2 = rect.y1 + 20;
-	open_btn = rtgui_button_create("打开列表");
-	rtgui_container_add_child(container, RTGUI_WIDGET(open_btn));
-	rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
-	rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
-
-	return container;
+    rtgui_rect_t rect;
+    rtgui_container_t *container;
+    rtgui_button_t *open_btn;
+
+    container = demo_view("列表视图演示");
+
+    /* 添加动作按钮 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 80;
+    rect.y1 += 30;
+    rect.y2 = rect.y1 + 20;
+    open_btn = rtgui_button_create("打开列表");
+    rtgui_container_add_child(container, RTGUI_WIDGET(open_btn));
+    rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
+    rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
+
+    return container;
 }

+ 300 - 296
examples/gui/demo_listview_icon.c

@@ -10,337 +10,341 @@
 #include <rtgui/widgets/window.h>
 #include <rtgui/widgets/list_view.h>
 
-static struct rtgui_app *application = RT_NULL;
-static rtgui_list_view_t* _view = RT_NULL;
+static struct rtgui_application *application = RT_NULL;
+static rtgui_list_view_t *_view = RT_NULL;
 
 /* 列表项的动作函数 */
-static void listitem_action(rtgui_widget_t* widget, void* parameter)
+static void listitem_action(rtgui_widget_t *widget, void *parameter)
 {
-	char label_text[32];
-	rtgui_win_t *win;
-	rtgui_label_t *label;
-	rtgui_rect_t rect = {0, 0, 150, 80};
-	int no = (int)parameter;
+    char label_text[32];
+    rtgui_win_t *win;
+    rtgui_label_t *label;
+    rtgui_rect_t rect = {0, 0, 150, 80};
+    int no = (int)parameter;
 
-	rtgui_rect_moveto(&rect, 20, 50);
+    rtgui_rect_moveto(&rect, 20, 50);
 
-	/* 显示消息窗口 */
-	win = rtgui_win_create(RTGUI_TOPLEVEL(application),
-		"窗口", &rect, RTGUI_WIN_STYLE_DEFAULT);
+    /* 显示消息窗口 */
+    win = rtgui_win_create(RTGUI_TOPLEVEL(application),
+                           "窗口", &rect, RTGUI_WIN_STYLE_DEFAULT);
 
-	rect.x1 += 20;
-	rect.x2 -= 5;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
+    rect.x1 += 20;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
 
-	/* 添加相应的标签 */
-	rt_sprintf(label_text, "动作 %d", no);
-	label = rtgui_label_create(label_text);
+    /* 添加相应的标签 */
+    rt_sprintf(label_text, "动作 %d", no);
+    label = rtgui_label_create(label_text);
 
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
 
-	/* 非模态显示窗口 */
-	rtgui_win_show(win, RT_FALSE);
+    /* 非模态显示窗口 */
+    rtgui_win_show(win, RT_FALSE);
 }
 
 /* 返回功能的动作函数 */
-static void return_action(rtgui_widget_t* widget, void* parameter)
+static void return_action(rtgui_widget_t *widget, void *parameter)
 {
-	/* 退出模态显示 */
-	rtgui_container_end_modal(RTGUI_CONTAINER(_view), RTGUI_MODAL_OK);
+    /* 退出模态显示 */
+    rtgui_container_end_modal(RTGUI_CONTAINER(_view), RTGUI_MODAL_OK);
 }
 
 /* 列表项 */
-#define ITEM_MAX	50
+#define ITEM_MAX    50
 static struct rtgui_list_item *items = RT_NULL;
-static rtgui_image_t* item_icon = RT_NULL;
-static rtgui_image_t* exit_icon = RT_NULL;
+static rtgui_image_t *item_icon = RT_NULL;
+static rtgui_image_t *exit_icon = RT_NULL;
 
-static const char * image_xpm[] = {
-	"16 16 106 2",
-	"  	c None",
-	". 	c #D0C83F",
-	"+ 	c #D0C840",
-	"@ 	c #D0C030",
-	"# 	c #D0B820",
-	"$ 	c #D0B020",
-	"% 	c #D0B01F",
-	"& 	c #5F571F",
-	"* 	c #F0F0C0",
-	"= 	c #FFF8D0",
-	"- 	c #FFF8C0",
-	"; 	c #FFF8B0",
-	"> 	c #FFF8A0",
-	", 	c #F0E870",
-	"' 	c #707030",
-	") 	c #4F87EF",
-	"! 	c #4F78C0",
-	"~ 	c #5088E0",
-	"{ 	c #5078C0",
-	"] 	c #C0D0F0",
-	"^ 	c #FFF8E0",
-	"/ 	c #FFF090",
-	"( 	c #F0E070",
-	"_ 	c #6F97D0",
-	": 	c #C0D8FE",
-	"< 	c #80A8F0",
-	"[ 	c #7088D0",
-	"} 	c #B0D0FF",
-	"| 	c #90B0F0",
-	"1 	c #1040A0",
-	"2 	c #F0F080",
-	"3 	c #707040",
-	"4 	c #7098F0",
-	"5 	c #3068E0",
-	"6 	c #A0B8F0",
-	"7 	c #4070C0",
-	"8 	c #002880",
-	"9 	c #404040",
-	"0 	c #505050",
-	"a 	c #F0F090",
-	"b 	c #F0E860",
-	"c 	c #F0D860",
-	"d 	c #807840",
-	"e 	c #2F5FC0",
-	"f 	c #1050D0",
-	"g 	c #1048B0",
-	"h 	c #002870",
-	"i 	c #C0C080",
-	"j 	c #C0C070",
-	"k 	c #F0F070",
-	"l 	c #F0E060",
-	"m 	c #E0D050",
-	"n 	c #00277F",
-	"o 	c #00287F",
-	"p 	c #1F3F6F",
-	"q 	c #1048C0",
-	"r 	c #0040B0",
-	"s 	c #204080",
-	"t 	c #FFF890",
-	"u 	c #F0D850",
-	"v 	c #E0C840",
-	"w 	c #807040",
-	"x 	c #A0B06F",
-	"y 	c #204880",
-	"z 	c #2048A0",
-	"A 	c #90A8C0",
-	"B 	c #FFF080",
-	"C 	c #F0D050",
-	"D 	c #C0A830",
-	"E 	c #6F682F",
-	"F 	c #F0F0A0",
-	"G 	c #E0D060",
-	"H 	c #B0A040",
-	"I 	c #D0B840",
-	"J 	c #E0C040",
-	"K 	c #D0B030",
-	"L 	c #706820",
-	"M 	c #5F581F",
-	"N 	c #CFBF3F",
-	"O 	c #FFF0A0",
-	"P 	c #A09830",
-	"Q 	c #A08820",
-	"R 	c #908030",
-	"S 	c #807830",
-	"T 	c #707020",
-	"U 	c #605820",
-	"V 	c #6F672F",
-	"W 	c #D0C040",
-	"X 	c #F0E880",
-	"Y 	c #907820",
-	"Z 	c #B09820",
-	"` 	c #B09010",
-	" .	c #B08820",
-	"..	c #806820",
-	"+.	c #5F5F1F",
-	"@.	c #F0E080",
-	"#.	c #B09020",
-	"$.	c #C0B040",
-	"%.	c #A09030",
-	"&.	c #908020",
-	"*.	c #606020",
-	"=.	c #6F5F1F",
-	"-.	c #9F982F",
-	";.	c #A0872F",
-	">.	c #6F681F",
-	",.	c #706020",
-	"                                ",
-	"          . + + + @ @ # # $ % & ",
-	"          + * = = = = - ; > , ' ",
-	"  ) !     ~ { ] ^ = - - > / ( ' ",
-	"_ : < { [ } | 1 - ; > > / 2 ( 3 ",
-	"{ 4 5 1 6 7 5 8 9 0 a / , b c d ",
-	"e f g h 8 8 g h i j / k l c m d ",
-	"  n o   p q r s t 2 , l c u v w ",
-	"        x y z A B , l u C v D E ",
-	"        @ F > t k G H I J K L M ",
-	"      N @ O / 2 l P Q R S T U V ",
-	"      W m 2 X l I Y Z `  ...+.  ",
-	"      W @.l u I R #.Z Y U M     ",
-	"    $.G I $.%.R &.Y *.& =.      ",
-	"  -.;.>.,.L L ,.& M             ",
-	"                                "};
+static const char *image_xpm[] =
+{
+    "16 16 106 2",
+    "  	c None",
+    ". 	c #D0C83F",
+    "+ 	c #D0C840",
+    "@ 	c #D0C030",
+    "# 	c #D0B820",
+    "$ 	c #D0B020",
+    "% 	c #D0B01F",
+    "& 	c #5F571F",
+    "* 	c #F0F0C0",
+    "= 	c #FFF8D0",
+    "- 	c #FFF8C0",
+    "; 	c #FFF8B0",
+    "> 	c #FFF8A0",
+    ", 	c #F0E870",
+    "' 	c #707030",
+    ") 	c #4F87EF",
+    "! 	c #4F78C0",
+    "~ 	c #5088E0",
+    "{ 	c #5078C0",
+    "] 	c #C0D0F0",
+    "^ 	c #FFF8E0",
+    "/ 	c #FFF090",
+    "( 	c #F0E070",
+    "_ 	c #6F97D0",
+    ": 	c #C0D8FE",
+    "< 	c #80A8F0",
+    "[ 	c #7088D0",
+    "} 	c #B0D0FF",
+    "| 	c #90B0F0",
+    "1 	c #1040A0",
+    "2 	c #F0F080",
+    "3 	c #707040",
+    "4 	c #7098F0",
+    "5 	c #3068E0",
+    "6 	c #A0B8F0",
+    "7 	c #4070C0",
+    "8 	c #002880",
+    "9 	c #404040",
+    "0 	c #505050",
+    "a 	c #F0F090",
+    "b 	c #F0E860",
+    "c 	c #F0D860",
+    "d 	c #807840",
+    "e 	c #2F5FC0",
+    "f 	c #1050D0",
+    "g 	c #1048B0",
+    "h 	c #002870",
+    "i 	c #C0C080",
+    "j 	c #C0C070",
+    "k 	c #F0F070",
+    "l 	c #F0E060",
+    "m 	c #E0D050",
+    "n 	c #00277F",
+    "o 	c #00287F",
+    "p 	c #1F3F6F",
+    "q 	c #1048C0",
+    "r 	c #0040B0",
+    "s 	c #204080",
+    "t 	c #FFF890",
+    "u 	c #F0D850",
+    "v 	c #E0C840",
+    "w 	c #807040",
+    "x 	c #A0B06F",
+    "y 	c #204880",
+    "z 	c #2048A0",
+    "A 	c #90A8C0",
+    "B 	c #FFF080",
+    "C 	c #F0D050",
+    "D 	c #C0A830",
+    "E 	c #6F682F",
+    "F 	c #F0F0A0",
+    "G 	c #E0D060",
+    "H 	c #B0A040",
+    "I 	c #D0B840",
+    "J 	c #E0C040",
+    "K 	c #D0B030",
+    "L 	c #706820",
+    "M 	c #5F581F",
+    "N 	c #CFBF3F",
+    "O 	c #FFF0A0",
+    "P 	c #A09830",
+    "Q 	c #A08820",
+    "R 	c #908030",
+    "S 	c #807830",
+    "T 	c #707020",
+    "U 	c #605820",
+    "V 	c #6F672F",
+    "W 	c #D0C040",
+    "X 	c #F0E880",
+    "Y 	c #907820",
+    "Z 	c #B09820",
+    "` 	c #B09010",
+    " .	c #B08820",
+    "..	c #806820",
+    "+.	c #5F5F1F",
+    "@.	c #F0E080",
+    "#.	c #B09020",
+    "$.	c #C0B040",
+    "%.	c #A09030",
+    "&.	c #908020",
+    "*.	c #606020",
+    "=.	c #6F5F1F",
+    "-.	c #9F982F",
+    ";.	c #A0872F",
+    ">.	c #6F681F",
+    ",.	c #706020",
+    "                                ",
+    "          . + + + @ @ # # $ % & ",
+    "          + * = = = = - ; > , ' ",
+    "  ) !     ~ { ] ^ = - - > / ( ' ",
+    "_ : < { [ } | 1 - ; > > / 2 ( 3 ",
+    "{ 4 5 1 6 7 5 8 9 0 a / , b c d ",
+    "e f g h 8 8 g h i j / k l c m d ",
+    "  n o   p q r s t 2 , l c u v w ",
+    "        x y z A B , l u C v D E ",
+    "        @ F > t k G H I J K L M ",
+    "      N @ O / 2 l P Q R S T U V ",
+    "      W m 2 X l I Y Z `  ...+.  ",
+    "      W @.l u I R #.Z Y U M     ",
+    "    $.G I $.%.R &.Y *.& =.      ",
+    "  -.;.>.,.L L ,.& M             ",
+    "                                "
+};
 
-static const char * exit_xpm[] = {
-	"16 16 71 1",
-	" 	c None",
-	".	c #CF673F",
-	"+	c #D0673F",
-	"@	c #C05F3F",
-	"#	c #BF5F3F",
-	"$	c #D0674F",
-	"%	c #E07050",
-	"&	c #F07850",
-	"*	c #FF7040",
-	"=	c #F06830",
-	"-	c #E05830",
-	";	c #D05030",
-	">	c #B04F2F",
-	",	c #D06F4F",
-	"'	c #F08060",
-	")	c #FF9070",
-	"!	c #FF8860",
-	"~	c #FF8050",
-	"{	c #FF5820",
-	"]	c #FF4810",
-	"^	c #D04810",
-	"/	c #B0482F",
-	"(	c #FF9880",
-	"_	c #FF6030",
-	":	c #F04000",
-	"<	c #C04010",
-	"[	c #A03F2F",
-	"}	c #E06840",
-	"|	c #FF9870",
-	"1	c #FF7850",
-	"2	c #FF6840",
-	"3	c #F04010",
-	"4	c #E03800",
-	"5	c #A03820",
-	"6	c #8F372F",
-	"7	c #F06840",
-	"8	c #FF8060",
-	"9	c #FFFFFF",
-	"0	c #FFF8F0",
-	"a	c #FFF0F0",
-	"b	c #FFE8E0",
-	"c	c #FFD0C0",
-	"d	c #E04010",
-	"e	c #B03010",
-	"f	c #7F2F1F",
-	"g	c #FFD8D0",
-	"h	c #FFC8C0",
-	"i	c #C03000",
-	"j	c #6F281F",
-	"k	c #F04810",
-	"l	c #FF6830",
-	"m	c #FFE0D0",
-	"n	c #F0C0B0",
-	"o	c #D04010",
-	"p	c #5F1F1F",
-	"q	c #E04820",
-	"r	c #FF4000",
-	"s	c #FF5020",
-	"t	c #FF5010",
-	"u	c #D03800",
-	"v	c #D03000",
-	"w	c #B02800",
-	"x	c #5F170F",
-	"y	c #C05020",
-	"z	c #F03800",
-	"A	c #802010",
-	"B	c #4F0F0F",
-	"C	c #A02800",
-	"D	c #C03810",
-	"E	c #5F0F00",
-	"F	c #A03810",
-	"                ",
-	"     .+@@@#     ",
-	"    $%&*=-;>    ",
-	"   ,')!~*{]^/   ",
-	"  +&)()~*_]:<[  ",
-	" .}~!||!12{3456 ",
-	" +7899990abcdef ",
-	" @{19990bgchdij ",
-	" @kl0abmchcnoip ",
-	" @qr]stt]3duvwx ",
-	" #yz:::z44uvvAB ",
-	"  >o4444uvvvCB  ",
-	"   /DvvvvvvCE   ",
-	"    [FeiiwAB    ",
-	"     6fjpxB     ",
-	"                "};
+static const char *exit_xpm[] =
+{
+    "16 16 71 1",
+    " 	c None",
+    ".	c #CF673F",
+    "+	c #D0673F",
+    "@	c #C05F3F",
+    "#	c #BF5F3F",
+    "$	c #D0674F",
+    "%	c #E07050",
+    "&	c #F07850",
+    "*	c #FF7040",
+    "=	c #F06830",
+    "-	c #E05830",
+    ";	c #D05030",
+    ">	c #B04F2F",
+    ",	c #D06F4F",
+    "'	c #F08060",
+    ")	c #FF9070",
+    "!	c #FF8860",
+    "~	c #FF8050",
+    "{	c #FF5820",
+    "]	c #FF4810",
+    "^	c #D04810",
+    "/	c #B0482F",
+    "(	c #FF9880",
+    "_	c #FF6030",
+    ":	c #F04000",
+    "<	c #C04010",
+    "[	c #A03F2F",
+    "}	c #E06840",
+    "|	c #FF9870",
+    "1	c #FF7850",
+    "2	c #FF6840",
+    "3	c #F04010",
+    "4	c #E03800",
+    "5	c #A03820",
+    "6	c #8F372F",
+    "7	c #F06840",
+    "8	c #FF8060",
+    "9	c #FFFFFF",
+    "0	c #FFF8F0",
+    "a	c #FFF0F0",
+    "b	c #FFE8E0",
+    "c	c #FFD0C0",
+    "d	c #E04010",
+    "e	c #B03010",
+    "f	c #7F2F1F",
+    "g	c #FFD8D0",
+    "h	c #FFC8C0",
+    "i	c #C03000",
+    "j	c #6F281F",
+    "k	c #F04810",
+    "l	c #FF6830",
+    "m	c #FFE0D0",
+    "n	c #F0C0B0",
+    "o	c #D04010",
+    "p	c #5F1F1F",
+    "q	c #E04820",
+    "r	c #FF4000",
+    "s	c #FF5020",
+    "t	c #FF5010",
+    "u	c #D03800",
+    "v	c #D03000",
+    "w	c #B02800",
+    "x	c #5F170F",
+    "y	c #C05020",
+    "z	c #F03800",
+    "A	c #802010",
+    "B	c #4F0F0F",
+    "C	c #A02800",
+    "D	c #C03810",
+    "E	c #5F0F00",
+    "F	c #A03810",
+    "                ",
+    "     .+@@@#     ",
+    "    $%&*=-;>    ",
+    "   ,')!~*{]^/   ",
+    "  +&)()~*_]:<[  ",
+    " .}~!||!12{3456 ",
+    " +7899990abcdef ",
+    " @{19990bgchdij ",
+    " @kl0abmchcnoip ",
+    " @qr]stt]3duvwx ",
+    " #yz:::z44uvvAB ",
+    "  >o4444uvvvCB  ",
+    "   /DvvvvvvCE   ",
+    "    [FeiiwAB    ",
+    "     6fjpxB     ",
+    "                "
+};
 
 /* 打开列表视图用的按钮触发函数 */
-static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
+static void open_btn_onbutton(rtgui_widget_t *widget, struct rtgui_event *event)
 {
-	rtgui_rect_t rect;
-	rt_uint32_t index;
+    rtgui_rect_t rect;
+    rt_uint32_t index;
 
-	/* 获得顶层的application */
-	application = RTGUI_APPLICATION(rtgui_widget_get_toplevel(widget));
-	rtgui_widget_get_rect(RTGUI_WIDGET(application), &rect);
+    /* 获得顶层的application */
+    application = RTGUI_APPLICATION(rtgui_widget_get_toplevel(widget));
+    rtgui_widget_get_rect(RTGUI_WIDGET(application), &rect);
 
-	/* 初始化图标列表 */
-	if (items == RT_NULL)
-	{
-		char item_name[32];
+    /* 初始化图标列表 */
+    if (items == RT_NULL)
+    {
+        char item_name[32];
 
-		items = (struct rtgui_list_item *) rtgui_malloc((ITEM_MAX + 1) * sizeof(struct rtgui_list_item));
-		for (index = 0; index < ITEM_MAX; index ++)
-		{
-			rt_snprintf(item_name, sizeof(item_name), "图标%d", index);
-			items[index].action = listitem_action;
-			items[index].image = item_icon;
-			items[index].name = rt_strdup(item_name);
-			items[index].parameter = (void*) index;
-		}
+        items = (struct rtgui_list_item *) rtgui_malloc((ITEM_MAX + 1) * sizeof(struct rtgui_list_item));
+        for (index = 0; index < ITEM_MAX; index ++)
+        {
+            rt_snprintf(item_name, sizeof(item_name), "图标%d", index);
+            items[index].action = listitem_action;
+            items[index].image = item_icon;
+            items[index].name = rt_strdup(item_name);
+            items[index].parameter = (void *) index;
+        }
 
-		items[ITEM_MAX].action = return_action;
-		items[ITEM_MAX].image = exit_icon;
-		items[ITEM_MAX].name = "退出";
-		items[ITEM_MAX].parameter = RT_NULL;
-	}
+        items[ITEM_MAX].action = return_action;
+        items[ITEM_MAX].image = exit_icon;
+        items[ITEM_MAX].name = "退出";
+        items[ITEM_MAX].parameter = RT_NULL;
+    }
 
-	/* 创建一个列表视图, 项指定为items */
-	_view = rtgui_list_view_create(items, ITEM_MAX + 1, &rect, RTGUI_LIST_VIEW_ICON);
-	/* 在application中添加相应的视图 */
-	rtgui_application_add_container(application, RTGUI_CONTAINER(_view));
+    /* 创建一个列表视图, 项指定为items */
+    _view = rtgui_list_view_create(items, ITEM_MAX + 1, &rect, RTGUI_LIST_VIEW_ICON);
+    /* 在application中添加相应的视图 */
+    rtgui_application_add_container(application, RTGUI_CONTAINER(_view));
 
-	/* 模式显示视图 */
-	rtgui_container_show(RTGUI_CONTAINER(_view), RT_TRUE);
-	rtgui_container_destroy(RTGUI_CONTAINER(_view));
+    /* 模式显示视图 */
+    rtgui_container_show(RTGUI_CONTAINER(_view), RT_TRUE);
+    rtgui_container_destroy(RTGUI_CONTAINER(_view));
 
-	_view = RT_NULL;
+    _view = RT_NULL;
 }
 
 /* 创建用于演示列表视图的视图 */
-rtgui_container_t* demo_listview_icon_view(struct rtgui_app *app)
+rtgui_container_t *demo_listview_icon_view(struct rtgui_application *app)
 {
-	rtgui_rect_t rect;
-	rtgui_container_t *view;
-	rtgui_button_t* open_btn;
+    rtgui_rect_t rect;
+    rtgui_container_t *view;
+    rtgui_button_t *open_btn;
 
-	view = demo_view(app, "图标视图演示");
+    view = demo_view(app, "图标视图演示");
 
-	if (item_icon == RT_NULL)
-		item_icon = rtgui_image_create_from_mem("xpm",
-			(const rt_uint8_t*)image_xpm, sizeof(image_xpm), RT_TRUE);
-	if (exit_icon == RT_NULL)
-		exit_icon = rtgui_image_create_from_mem("xpm",
-			(const rt_uint8_t*)exit_xpm, sizeof(exit_xpm), RT_TRUE);
+    if (item_icon == RT_NULL)
+        item_icon = rtgui_image_create_from_mem("xpm",
+                                                (const rt_uint8_t *)image_xpm, sizeof(image_xpm), RT_TRUE);
+    if (exit_icon == RT_NULL)
+        exit_icon = rtgui_image_create_from_mem("xpm",
+                                                (const rt_uint8_t *)exit_xpm, sizeof(exit_xpm), RT_TRUE);
 
-	/* 添加动作按钮 */
-	demo_view_get_rect(view, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 80;
-	rect.y1 += 30;
-	rect.y2 = rect.y1 + 20;
-	open_btn = rtgui_button_create("打开图标列表");
-	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn));
-	rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
-	rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
+    /* 添加动作按钮 */
+    demo_view_get_rect(view, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 80;
+    rect.y1 += 30;
+    rect.y2 = rect.y1 + 20;
+    open_btn = rtgui_button_create("打开图标列表");
+    rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(open_btn));
+    rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
+    rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
 
-	return view;
+    return view;
 }

+ 45 - 43
examples/gui/demo_simple_workbench.c

@@ -7,54 +7,56 @@
 #include <rtgui/widgets/label.h>
 #include <rtgui/widgets/workbench.h>
 
-static void workbench_entry(void* parameter)
+static void workbench_entry(void *parameter)
 {
-	rt_mq_t mq;
-	rtgui_container_t* view;
-	rtgui_label_t* label;
-	struct rtgui_workbench* workbench;
-	rtgui_rect_t rect;
-
-	mq = rt_mq_create("wmq", 256, 8, RT_IPC_FLAG_FIFO);
-	/* 注册当前线程为GUI线程 */
-	rtgui_thread_register(rt_thread_self(), mq);
-	/* 创建一个工作台 */
-	workbench = rtgui_workbench_create("main", "workbench #1");
-	if (workbench == RT_NULL) return;
-
-	view = rtgui_container_create("view");
-	if (view == RT_NULL) return;
-	/* 指定视图的背景色 */
-	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
-
-	/* 添加一个label */
-	label = rtgui_label_create("你好!RT-Thread!");
-	rect.x1 = 10; rect.y1 = 10;
-	rect.x2 = 210; rect.y2 = 30;
-	/* 设置label的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
-
-	/* 添加到父workbench中 */
-	rtgui_workbench_add_view(workbench, view);
-	/* 非模式方式显示视图 */
-	rtgui_container_show(view, RT_FALSE);
-
-	/* 执行工作台事件循环 */
-	rtgui_workbench_event_loop(workbench);
-
-	/* 去注册GUI线程 */
-	rtgui_thread_deregister(rt_thread_self());
-
-	/* delete message queue */
-	rt_mq_delete(mq);
+    rt_mq_t mq;
+    rtgui_container_t *view;
+    rtgui_label_t *label;
+    struct rtgui_workbench *workbench;
+    rtgui_rect_t rect;
+
+    mq = rt_mq_create("wmq", 256, 8, RT_IPC_FLAG_FIFO);
+    /* 注册当前线程为GUI线程 */
+    rtgui_thread_register(rt_thread_self(), mq);
+    /* 创建一个工作台 */
+    workbench = rtgui_workbench_create("main", "workbench #1");
+    if (workbench == RT_NULL) return;
+
+    view = rtgui_container_create("view");
+    if (view == RT_NULL) return;
+    /* 指定视图的背景色 */
+    RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
+
+    /* 添加一个label */
+    label = rtgui_label_create("你好!RT-Thread!");
+    rect.x1 = 10;
+    rect.y1 = 10;
+    rect.x2 = 210;
+    rect.y2 = 30;
+    /* 设置label的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
+
+    /* 添加到父workbench中 */
+    rtgui_workbench_add_view(workbench, view);
+    /* 非模式方式显示视图 */
+    rtgui_container_show(view, RT_FALSE);
+
+    /* 执行工作台事件循环 */
+    rtgui_workbench_event_loop(workbench);
+
+    /* 去注册GUI线程 */
+    rtgui_thread_deregister(rt_thread_self());
+
+    /* delete message queue */
+    rt_mq_delete(mq);
 }
 
 /* 初始化workbench */
 void wb_init()
 {
-	rt_thread_t tid;
+    rt_thread_t tid;
 
-	tid = rt_thread_create("wb1", workbench_entry, RT_NULL, 2048, 20, 5);
-	if (tid != RT_NULL) rt_thread_startup(tid);
+    tid = rt_thread_create("wb1", workbench_entry, RT_NULL, 2048, 20, 5);
+    if (tid != RT_NULL) rt_thread_startup(tid);
 }

+ 101 - 122
examples/gui/demo_view.c

@@ -11,141 +11,120 @@ extern struct rtgui_notebook *the_notebook;
 
 void demo_view_next(struct rtgui_object *object, struct rtgui_event *event)
 {
-	rtgui_notebook_set_current_by_index(the_notebook,
-			(rtgui_notebook_get_current_index(the_notebook) + 1) %
-			rtgui_notebook_get_count(the_notebook));
+    rtgui_notebook_set_current_by_index(the_notebook,
+                                        (rtgui_notebook_get_current_index(the_notebook) + 1) %
+                                        rtgui_notebook_get_count(the_notebook));
 }
 
 void demo_view_prev(struct rtgui_object *object, struct rtgui_event *event)
 {
-	rt_int16_t cur_idx = rtgui_notebook_get_current_index(the_notebook);
-
-	if (cur_idx == 0)
-		rtgui_notebook_set_current_by_index(the_notebook,
-			rtgui_notebook_get_count(the_notebook) - 1);
-	else
-		rtgui_notebook_set_current_by_index(the_notebook,
-			--cur_idx);
+    rt_int16_t cur_idx = rtgui_notebook_get_current_index(the_notebook);
+
+    if (cur_idx == 0)
+        rtgui_notebook_set_current_by_index(the_notebook,
+                                            rtgui_notebook_get_count(the_notebook) - 1);
+    else
+        rtgui_notebook_set_current_by_index(the_notebook,
+                                            --cur_idx);
 }
 
-rtgui_container_t* demo_view(const char *title)
+rtgui_container_t *demo_view(const char *title)
 {
-	struct rtgui_container  *container;
-	struct rtgui_label      *label;
-	struct rtgui_staticline *line;
-	struct rtgui_button     *next_btn, *prev_btn;
-	struct rtgui_rect       rect;
-
-	container = rtgui_container_create();
-	if (container == RT_NULL)
-		return RT_NULL;
-
-	rtgui_notebook_add(the_notebook, title, RTGUI_WIDGET(container));
-
-	/* 获得视图的位置信息(在加入到 notebook 中时,notebook 会自动调整 container
-	 * 的大小) */
-	rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
-	rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
-	rect.x1 += 5;
-	rect.y1 += 5;
-	rect.x2 -= 5;
-	rect.y2 = rect.y1 + 20;
-
-	/* 创建标题用的标签 */
-	label = rtgui_label_create(title);
-	/* 设置标签位置信息 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	/* 添加标签到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
-
-	rect.y1 += 20;
-	rect.y2 += 20;
-	/* 创建一个水平的 staticline 线 */
-	line = rtgui_staticline_create(RTGUI_HORIZONTAL);
-	/* 设置静态线的位置信息 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(line), &rect);
-	/* 添加静态线到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(line));
-
-	/* 获得视图的位置信息 */
-	rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
-	rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
-	rect.x2 -= 5;
-	rect.y2 -= 5;
-	rect.x1 = rect.x2 - 100;
-	rect.y1 = rect.y2 - 25;
-
-	/* 创建"下一个"按钮 */
-	next_btn = rtgui_button_create("下一个");
-	/* 设置onbutton动作到demo_view_next函数 */
-	rtgui_button_set_onbutton(next_btn, demo_view_next);
-	/* 设置按钮的位置信息 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(next_btn), &rect);
-	/* 添加按钮到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(next_btn));
-
-	/* 获得视图的位置信息 */
-	rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
-	rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
-	rect.x1 += 5;
-	rect.y2 -= 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 = rect.y2 - 25;
-
-	/* 创建"上一个"按钮 */
-	prev_btn = rtgui_button_create("上一个");
-	/* 设置onbutton动作到demo_view_prev函数 */
-	rtgui_button_set_onbutton(prev_btn, demo_view_prev);
-	/* 设置按钮的位置信息 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(prev_btn), &rect);
-	/* 添加按钮到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(prev_btn));
-
-	/* 返回创建的视图 */
-	return container;
+    struct rtgui_container  *container;
+    struct rtgui_label      *label;
+    struct rtgui_staticline *line;
+    struct rtgui_button     *next_btn, *prev_btn;
+    struct rtgui_rect       rect;
+
+    container = rtgui_container_create();
+    if (container == RT_NULL)
+        return RT_NULL;
+
+    rtgui_notebook_add(the_notebook, title, RTGUI_WIDGET(container));
+
+    /* 获得视图的位置信息(在加入到 notebook 中时,notebook 会自动调整 container
+     * 的大小) */
+    rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
+    rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
+    rect.x1 += 5;
+    rect.y1 += 5;
+    rect.x2 -= 5;
+    rect.y2 = rect.y1 + 20;
+
+    /* 创建标题用的标签 */
+    label = rtgui_label_create(title);
+    /* 设置标签位置信息 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    /* 添加标签到视图中 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
+
+    rect.y1 += 20;
+    rect.y2 += 20;
+    /* 创建一个水平的 staticline 线 */
+    line = rtgui_staticline_create(RTGUI_HORIZONTAL);
+    /* 设置静态线的位置信息 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(line), &rect);
+    /* 添加静态线到视图中 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(line));
+
+    /* 获得视图的位置信息 */
+    rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
+    rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
+    rect.x2 -= 5;
+    rect.y2 -= 5;
+    rect.x1 = rect.x2 - 100;
+    rect.y1 = rect.y2 - 25;
+
+    /* 创建"下一个"按钮 */
+    next_btn = rtgui_button_create("下一个");
+    /* 设置onbutton动作到demo_view_next函数 */
+    rtgui_button_set_onbutton(next_btn, demo_view_next);
+    /* 设置按钮的位置信息 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(next_btn), &rect);
+    /* 添加按钮到视图中 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(next_btn));
+
+    /* 获得视图的位置信息 */
+    rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
+    rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
+    rect.x1 += 5;
+    rect.y2 -= 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 = rect.y2 - 25;
+
+    /* 创建"上一个"按钮 */
+    prev_btn = rtgui_button_create("上一个");
+    /* 设置onbutton动作到demo_view_prev函数 */
+    rtgui_button_set_onbutton(prev_btn, demo_view_prev);
+    /* 设置按钮的位置信息 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(prev_btn), &rect);
+    /* 添加按钮到视图中 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(prev_btn));
+
+    /* 返回创建的视图 */
+    return container;
 }
 
 /* 这个函数用于返回演示视图的对外可用区域 */
-void demo_view_get_rect(rtgui_container_t* container, rtgui_rect_t *rect)
+void demo_view_get_rect(rtgui_container_t *container, rtgui_rect_t *rect)
 {
-	RT_ASSERT(container != RT_NULL);
-	RT_ASSERT(rect != RT_NULL);
-
-	rtgui_widget_get_rect(RTGUI_WIDGET(container), rect);
-	rtgui_widget_rect_to_device(RTGUI_WIDGET(container), rect);
-	/* 去除演示标题和下方按钮的区域 */
-	rect->y1 += 45;
-	rect->y2 -= 35;
+    RT_ASSERT(container != RT_NULL);
+    RT_ASSERT(rect != RT_NULL);
+
+    rtgui_widget_get_rect(RTGUI_WIDGET(container), rect);
+    rtgui_widget_rect_to_device(RTGUI_WIDGET(container), rect);
+    /* 去除演示标题和下方按钮的区域 */
+    rect->y1 += 45;
+    rect->y2 -= 35;
 }
 
-void demo_view_get_logic_rect(rtgui_container_t* container, rtgui_rect_t *rect)
+void demo_view_get_logic_rect(rtgui_container_t *container, rtgui_rect_t *rect)
 {
-	RT_ASSERT(container != RT_NULL);
-	RT_ASSERT(rect != RT_NULL);
+    RT_ASSERT(container != RT_NULL);
+    RT_ASSERT(rect != RT_NULL);
 
-	rtgui_widget_get_rect(RTGUI_WIDGET(container), rect);
-	/* 去除演示标题和下方按钮的区域 */
-	rect->y1 += 45;
-	rect->y2 -= 35;
+    rtgui_widget_get_rect(RTGUI_WIDGET(container), rect);
+    /* 去除演示标题和下方按钮的区域 */
+    rect->y1 += 45;
+    rect->y2 -= 35;
 }
-
-/* 当是标准版本时,这个函数用于返回自动布局引擎box控件 */
-#ifndef RTGUI_USING_SMALL_SIZE
-struct rtgui_box* demo_view_create_box(struct rtgui_container *container, int orient)
-{
-	rtgui_rect_t rect;
-	struct rtgui_box* box;
-
-	/* 获得视图的位置信息 */
-	rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
-	rect.y1 += 45;
-	rect.y2 -= 25;
-
-	/* 创建一个自动布局引擎 */
-	box = rtgui_box_create(orient, 5);
-	/* 添加box控件到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(box));
-
-	return box;
-}
-#endif

+ 3 - 8
examples/gui/demo_view.h

@@ -24,16 +24,11 @@
 #endif
 
 /* 创建一个演示视图,需要给出这个视图的演示标题 */
-rtgui_container_t* demo_view(const char* title);
+rtgui_container_t *demo_view(const char *title);
 /* 获得演示视图提供给演示控件用的区域信息 */
-void demo_view_get_rect(rtgui_container_t* view, rtgui_rect_t *rect);
-void demo_view_get_logic_rect(rtgui_container_t* view, rtgui_rect_t *rect);
+void demo_view_get_rect(rtgui_container_t *view, rtgui_rect_t *rect);
+void demo_view_get_logic_rect(rtgui_container_t *view, rtgui_rect_t *rect);
 void demo_view_show(void);
 
-/* 如果是标准版,可以调用这个函数获得一个自动布局引擎 */
-#ifndef RTGUI_USING_SMALL_SIZE
-rtgui_box_t* demo_view_create_box(rtgui_container_t* view, int orient);
-#endif
-
 #endif
 

+ 78 - 76
examples/gui/demo_view_animation.c

@@ -13,120 +13,122 @@ static rt_int8_t dx = 1, dy = 1;
 static rtgui_rect_t text_rect;
 static rtgui_timer_t *timer;
 
-void timeout(struct rtgui_timer* timer, void* parameter)
+void timeout(struct rtgui_timer *timer, void *parameter)
 {
-	struct rtgui_dc* dc;
-	struct rtgui_rect rect;
-	struct rtgui_widget *widget;
-
-	/* 控件(container)通过parameter参数传递给定时器 */
-	widget = RTGUI_WIDGET(parameter);
-
-	/* 获得控件所属的DC */
-	dc = rtgui_dc_begin_drawing(widget);
-	if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
-		return ;
-
-	/* 获得demo container允许绘图的区域,主要用于判断边界 */
-	demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
-	rect.y2 -= 5;
-
-	/* 判断是否是第一次绘图 */
-	if ((text_rect.x1 == 0) && (text_rect.y1 == 0))
-	{
-		rtgui_rect_moveto(&text_rect, rect.x1, rect.y1);
-	}
-	else
-	{
-	    /* 擦除老的文字 */
-	    rtgui_dc_fill_rect(dc, &text_rect);
-	}
+    struct rtgui_dc *dc;
+    struct rtgui_rect rect;
+    struct rtgui_widget *widget;
+
+    /* 控件(container)通过parameter参数传递给定时器 */
+    widget = RTGUI_WIDGET(parameter);
+
+    /* 获得控件所属的DC */
+    dc = rtgui_dc_begin_drawing(widget);
+    if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
+        return ;
+
+    /* 获得demo container允许绘图的区域,主要用于判断边界 */
+    demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
+    rect.y2 -= 5;
+
+    /* 判断是否是第一次绘图 */
+    if ((text_rect.x1 == 0) && (text_rect.y1 == 0))
+    {
+        rtgui_rect_moveto(&text_rect, rect.x1, rect.y1);
+    }
+    else
+    {
+        /* 擦除老的文字 */
+        rtgui_dc_fill_rect(dc, &text_rect);
+    }
 
     /* 设置dx和dy */
-	if (text_rect.x2 >= rect.x2) dx = -1;
-	if (text_rect.x1 < rect.x1)  dx = 1;
-	if (text_rect.y2 >= rect.y2) dy = -1;
-	if (text_rect.y1 < rect.y1) dy = 1;
+    if (text_rect.x2 >= rect.x2) dx = -1;
+    if (text_rect.x1 < rect.x1)  dx = 1;
+    if (text_rect.y2 >= rect.y2) dy = -1;
+    if (text_rect.y1 < rect.y1) dy = 1;
 
     /* 移动文本框的位置 */
-	text_rect.x1 += dx; text_rect.x2 += dx;
-	text_rect.y1 += dy; text_rect.y2 += dy;
+    text_rect.x1 += dx;
+    text_rect.x2 += dx;
+    text_rect.y1 += dy;
+    text_rect.y2 += dy;
 
     /* 绘图 */
-	rtgui_dc_draw_text(dc, "飞线乱飞", &text_rect);
+    rtgui_dc_draw_text(dc, "飞线乱飞", &text_rect);
 
-	/* 绘图完成 */
-	rtgui_dc_end_drawing(dc);
+    /* 绘图完成 */
+    rtgui_dc_end_drawing(dc);
 }
 
-rt_bool_t animation_event_handler(struct rtgui_object* object, rtgui_event_t *event)
+rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *event)
 {
     struct rtgui_widget *widget = RTGUI_WIDGET(object);
 
-	if (event->type == RTGUI_EVENT_PAINT)
-	{
-		struct rtgui_dc* dc;
-		rtgui_rect_t rect;
+    if (event->type == RTGUI_EVENT_PAINT)
+    {
+        struct rtgui_dc *dc;
+        rtgui_rect_t rect;
 
-		/* 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container先绘图 */
-		rtgui_container_event_handler(object, event);
+        /* 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container先绘图 */
+        rtgui_container_event_handler(object, event);
 
-		/* 获得控件所属的DC */
-		dc = rtgui_dc_begin_drawing(widget);
-		if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
-			return RT_FALSE;
+        /* 获得控件所属的DC */
+        dc = rtgui_dc_begin_drawing(widget);
+        if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
+            return RT_FALSE;
 
         /* 获得demo container允许绘图的区域 */
         demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
 
-	    /* 擦除所有 */
-	    rtgui_dc_fill_rect(dc, &rect);
+        /* 擦除所有 */
+        rtgui_dc_fill_rect(dc, &rect);
 
         /* 绘图 */
         rtgui_dc_draw_text(dc, "飞线乱飞", &text_rect);
 
-		/* 绘图完成 */
-		rtgui_dc_end_drawing(dc);
-	}
-	else
-	{
-		/* 调用默认的事件处理函数 */
-		return rtgui_container_event_handler(object, event);
-	}
+        /* 绘图完成 */
+        rtgui_dc_end_drawing(dc);
+    }
+    else
+    {
+        /* 调用默认的事件处理函数 */
+        return rtgui_container_event_handler(object, event);
+    }
 
-	return RT_FALSE;
+    return RT_FALSE;
 }
 
 static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event)
 {
-	rt_kprintf("animation on show\n");
-	if (timer != RT_NULL)
-		rtgui_timer_start(timer);
-	return RT_TRUE;
+    rt_kprintf("animation on show\n");
+    if (timer != RT_NULL)
+        rtgui_timer_start(timer);
+    return RT_TRUE;
 }
 
 static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event)
 {
-	rt_kprintf("animation on hide\n");
-	if (timer != RT_NULL)
-		rtgui_timer_stop(timer);
-	return RT_TRUE;
+    rt_kprintf("animation on hide\n");
+    if (timer != RT_NULL)
+        rtgui_timer_stop(timer);
+    return RT_TRUE;
 }
 
 rtgui_container_t *demo_view_animation()
 {
-	rtgui_container_t *container;
+    rtgui_container_t *container;
 
-	container = demo_view("DC 动画");
-	if (container != RT_NULL)
-		rtgui_object_set_event_handler(RTGUI_OBJECT(container), animation_event_handler);
+    container = demo_view("DC 动画");
+    if (container != RT_NULL)
+        rtgui_object_set_event_handler(RTGUI_OBJECT(container), animation_event_handler);
 
-	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(container)), "飞线乱飞", &text_rect);
-	rtgui_rect_moveto(&text_rect, 0, 45);
-	timer = rtgui_timer_create(2, RT_TIMER_FLAG_PERIODIC, timeout, (void*)container);
+    rtgui_font_get_metrics(RTGUI_WIDGET_FONT(container), "飞线乱飞", &text_rect);
+    rtgui_rect_moveto(&text_rect, 0, 45);
+    timer = rtgui_timer_create(2, RT_TIMER_FLAG_PERIODIC, timeout, (void *)container);
 
-	rtgui_widget_set_onshow(RTGUI_WIDGET(container), animation_on_show);
-	rtgui_widget_set_onhide(RTGUI_WIDGET(container), animation_on_hide);
+    rtgui_widget_set_onshow(RTGUI_WIDGET(container), animation_on_show);
+    rtgui_widget_set_onhide(RTGUI_WIDGET(container), animation_on_hide);
 
-	return container;
+    return container;
 }

+ 82 - 82
examples/gui/demo_view_benchmark.c

@@ -11,112 +11,112 @@ static int running = 0;
 
 void _onidle(struct rtgui_object *object, rtgui_event_t *event)
 {
-	rtgui_color_t color;
-	rtgui_rect_t rect, draw_rect;
-	struct rtgui_dc *dc;
+    rtgui_color_t color;
+    rtgui_rect_t rect, draw_rect;
+    struct rtgui_dc *dc;
 
-	/* 获得控件所属的DC */
-	// dc = rtgui_dc_hw_create(RTGUI_WIDGET(container)); 
-	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(container));
-	if (dc == RT_NULL)
-		return;
+    /* 获得控件所属的DC */
+    // dc = rtgui_dc_hw_create(RTGUI_WIDGET(container));
+    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(container));
+    if (dc == RT_NULL)
+        return;
 
-	demo_view_get_logic_rect(RTGUI_CONTAINER(container), &rect);
-	draw_rect.x1 = RAND(rect.x1, rect.x2);
-	draw_rect.y1 = RAND(rect.y1, rect.y2);
-	draw_rect.x2 = RAND(draw_rect.x1, rect.x2);
-	draw_rect.y2 = RAND(draw_rect.y1, rect.y2);
+    demo_view_get_logic_rect(RTGUI_CONTAINER(container), &rect);
+    draw_rect.x1 = RAND(rect.x1, rect.x2);
+    draw_rect.y1 = RAND(rect.y1, rect.y2);
+    draw_rect.x2 = RAND(draw_rect.x1, rect.x2);
+    draw_rect.y2 = RAND(draw_rect.y1, rect.y2);
 
-	color = RTGUI_RGB(rand() % 255, rand() % 255, rand() % 255);
-	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(container)) = color;
+    color = RTGUI_RGB(rand() % 255, rand() % 255, rand() % 255);
+    RTGUI_WIDGET_BACKGROUND(container) = color;
 
-	rtgui_dc_fill_rect(dc, &draw_rect);
+    rtgui_dc_fill_rect(dc, &draw_rect);
 
-	/* 绘图完成 */
-	rtgui_dc_end_drawing(dc);
+    /* 绘图完成 */
+    rtgui_dc_end_drawing(dc);
 }
 
-void _draw_default(struct rtgui_object *object, rtgui_event_t* event)
+void _draw_default(struct rtgui_object *object, rtgui_event_t *event)
 {
-	struct rtgui_widget *widget = RTGUI_WIDGET(object);
-	struct rtgui_dc* dc;
-	rtgui_rect_t rect;
+    struct rtgui_widget *widget = RTGUI_WIDGET(object);
+    struct rtgui_dc *dc;
+    rtgui_rect_t rect;
 
-	/* 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container先绘图 */
-	rtgui_container_event_handler(object, event);
+    /* 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container先绘图 */
+    rtgui_container_event_handler(object, event);
 
-	/* 获得控件所属的DC */
-	dc = rtgui_dc_begin_drawing(widget);
-	if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
-		return;
+    /* 获得控件所属的DC */
+    dc = rtgui_dc_begin_drawing(widget);
+    if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
+        return;
 
-	/* 获得demo container允许绘图的区域 */
-	demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
+    /* 获得demo container允许绘图的区域 */
+    demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
 
-	/* 擦除所有 */
-	RTGUI_WIDGET_BACKGROUND(widget) = default_background;
-	rtgui_dc_fill_rect(dc, &rect);
+    /* 擦除所有 */
+    RTGUI_WIDGET_BACKGROUND(widget) = default_background;
+    rtgui_dc_fill_rect(dc, &rect);
 
-	/* 显示提示 */
-	rtgui_dc_draw_text(dc, "按任意键开始/停止测试...", &rect);
+    /* 显示提示 */
+    rtgui_dc_draw_text(dc, "按任意键开始/停止测试...", &rect);
 
-	/* 绘图完成 */
-	rtgui_dc_end_drawing(dc);
+    /* 绘图完成 */
+    rtgui_dc_end_drawing(dc);
 }
 
 rt_bool_t benchmark_event_handler(struct rtgui_object *object, rtgui_event_t *event)
 {
-	if (event->type == RTGUI_EVENT_PAINT)
-	{
-		_draw_default(object, event);
-	}
-	else if (event->type == RTGUI_EVENT_KBD)
-	{
-		struct rtgui_event_kbd *kbd = (struct rtgui_event_kbd*)event;
-
-		if (kbd->key == RTGUIK_LEFT || kbd->key == RTGUIK_RIGHT)
-			return RT_FALSE;
-
-		if (RTGUI_KBD_IS_UP(kbd))
-		{
-			if (running)
-			{
-				/* stop */
-				rtgui_app_set_onidle(RT_NULL);
-				_draw_default(object, event);
-			}
-			else
-			{
-				/* run */
-				rtgui_app_set_onidle(_onidle);
-			}
-
-			running = !running;
-		}
-		return RT_TRUE;
-	}
-	else
-	{
-		/* 调用默认的事件处理函数 */
-		return rtgui_container_event_handler(object, event);
-	}
-
-	return RT_FALSE;
+    if (event->type == RTGUI_EVENT_PAINT)
+    {
+        _draw_default(object, event);
+    }
+    else if (event->type == RTGUI_EVENT_KBD)
+    {
+        struct rtgui_event_kbd *kbd = (struct rtgui_event_kbd *)event;
+
+        if (kbd->key == RTGUIK_LEFT || kbd->key == RTGUIK_RIGHT)
+            return RT_FALSE;
+
+        if (RTGUI_KBD_IS_UP(kbd))
+        {
+            if (running)
+            {
+                /* stop */
+                rtgui_app_set_onidle(RT_NULL);
+                _draw_default(object, event);
+            }
+            else
+            {
+                /* run */
+                rtgui_app_set_onidle(_onidle);
+            }
+
+            running = !running;
+        }
+        return RT_TRUE;
+    }
+    else
+    {
+        /* 调用默认的事件处理函数 */
+        return rtgui_container_event_handler(object, event);
+    }
+
+    return RT_FALSE;
 }
 
-static rt_bool_t _benchmark_onshow(struct rtgui_object *obj, struct rtgui_event* ev)
+static rt_bool_t _benchmark_onshow(struct rtgui_object *obj, struct rtgui_event *ev)
 {
-	rtgui_widget_focus(RTGUI_WIDGET(obj));
-	return RT_TRUE;
+    rtgui_widget_focus(RTGUI_WIDGET(obj));
+    return RT_TRUE;
 }
 
 rtgui_container_t *demo_view_benchmark(void)
 {
-	srand(100);
-	container = demo_view("绘图测试");
-	RTGUI_WIDGET(container)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
-	rtgui_object_set_event_handler(RTGUI_OBJECT(container), benchmark_event_handler);
-	rtgui_widget_set_onshow(RTGUI_WIDGET(container), _benchmark_onshow);
+    srand(100);
+    container = demo_view("绘图测试");
+    RTGUI_WIDGET(container)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+    rtgui_object_set_event_handler(RTGUI_OBJECT(container), benchmark_event_handler);
+    rtgui_widget_set_onshow(RTGUI_WIDGET(container), _benchmark_onshow);
 
-	return container;
+    return container;
 }

+ 22 - 22
examples/gui/demo_view_box.c

@@ -4,40 +4,40 @@
 #include <rtgui/widgets/label.h>
 #include <rtgui/widgets/button.h>
 
-rtgui_container_t* demo_view_box(void)
+rtgui_container_t *demo_view_box(void)
 {
     rtgui_rect_t  rect;
-    rtgui_container_t* view;
-	struct rtgui_panel *panel;
-	struct rtgui_box *box;
+    rtgui_container_t *view;
+    struct rtgui_panel *panel;
+    struct rtgui_box *box;
 
-	struct rtgui_label *label;
-	struct rtgui_button *button;
+    struct rtgui_label *label;
+    struct rtgui_button *button;
 
     view = demo_view("Box View");
     demo_view_get_rect(view, &rect);
 
-	panel = rtgui_panel_create(RTGUI_BORDER_NONE);
-	rtgui_widget_set_rect(RTGUI_WIDGET(panel), &rect);
-	rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(panel));
+    panel = rtgui_panel_create(RTGUI_BORDER_NONE);
+    rtgui_widget_set_rect(RTGUI_WIDGET(panel), &rect);
+    rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(panel));
 
-	box = rtgui_box_create(RTGUI_VERTICAL, 5);
-	rtgui_container_set_box(RTGUI_CONTAINER(panel), box);
+    box = rtgui_box_create(RTGUI_VERTICAL, 5);
+    rtgui_container_set_box(RTGUI_CONTAINER(panel), box);
 
-	label = rtgui_label_create("label 1");
-	rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(label));
-	label = rtgui_label_create("label 2");
-	rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(label));
+    label = rtgui_label_create("label 1");
+    rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(label));
+    label = rtgui_label_create("label 2");
+    rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(label));
 
-	button = rtgui_button_create("button 1");
-	rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(button));
+    button = rtgui_button_create("button 1");
+    rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(button));
 
-	button = rtgui_button_create("button 2");
-	rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(button));
-	rtgui_widget_set_miniheight(RTGUI_WIDGET(button), 25);
-	RTGUI_WIDGET_ALIGN(button) = RTGUI_ALIGN_EXPAND;
+    button = rtgui_button_create("button 2");
+    rtgui_container_add_child(RTGUI_CONTAINER(panel), RTGUI_WIDGET(button));
+    rtgui_widget_set_miniheight(RTGUI_WIDGET(button), 25);
+    RTGUI_WIDGET_ALIGN(button) = RTGUI_ALIGN_EXPAND;
 
-	rtgui_container_layout(RTGUI_CONTAINER(panel));
+    rtgui_container_layout(RTGUI_CONTAINER(panel));
 
     return view;
 }

+ 97 - 91
examples/gui/demo_view_buffer_animation.c

@@ -13,132 +13,138 @@ static rt_int8_t dx = 1, dy = 1;
 static rtgui_rect_t text_rect;
 static rtgui_timer_t *timer;
 static struct rtgui_dc *dc_buffer;
-static void timeout(struct rtgui_timer* timer, void* parameter)
+static void timeout(struct rtgui_timer *timer, void *parameter)
 {
-	struct rtgui_dc* dc;
-	rtgui_rect_t rect;
-	rtgui_widget_t *widget;
+    struct rtgui_dc *dc;
+    rtgui_rect_t rect;
+    rtgui_widget_t *widget;
 
-	/* 控件(view)通过parameter参数传递给定时器 */
-	widget = (rtgui_widget_t*)parameter;
+    /* 控件(view)通过parameter参数传递给定时器 */
+    widget = (rtgui_widget_t *)parameter;
 
-	/* 获得控件所属的DC */
-	dc = rtgui_dc_begin_drawing(widget);
-	if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
-		return ;
+    /* 获得控件所属的DC */
+    dc = rtgui_dc_begin_drawing(widget);
+    if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
+        return ;
 
-	/* 获得demo view允许绘图的区域,主要用于判断边界 */
-	demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
-	rect.y2 -= 5;
+    /* 获得demo view允许绘图的区域,主要用于判断边界 */
+    demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
+    rect.y2 -= 5;
 
-	/* 判断是否是第一次绘图 */
-	if ((text_rect.x1 == 0) && (text_rect.y1 == 0))
-	{
-		rtgui_rect_moveto(&text_rect, rect.x1, rect.y1);
-	}
+    /* 判断是否是第一次绘图 */
+    if ((text_rect.x1 == 0) && (text_rect.y1 == 0))
+    {
+        rtgui_rect_moveto(&text_rect, rect.x1, rect.y1);
+    }
 
     /* 设置dx和dy */
-	if (text_rect.x2 >= rect.x2) dx = -1;
-	if (text_rect.x1 < rect.x1)  dx = 1;
-	if (text_rect.y2 >= rect.y2) dy = -1;
-	if (text_rect.y1 < rect.y1) dy = 1;
+    if (text_rect.x2 >= rect.x2) dx = -1;
+    if (text_rect.x1 < rect.x1)  dx = 1;
+    if (text_rect.y2 >= rect.y2) dy = -1;
+    if (text_rect.y1 < rect.y1) dy = 1;
 
     /* 移动文本框的位置 */
-	text_rect.x1 += dx; text_rect.x2 += dx;
-	text_rect.y1 += dy; text_rect.y2 += dy;
+    text_rect.x1 += dx;
+    text_rect.x2 += dx;
+    text_rect.y1 += dy;
+    text_rect.y2 += dy;
 
     /* 绘图 */
-	rect = text_rect;
-	rect.x2 += 2; rect.y2 += 2;
-	rtgui_dc_blit(dc_buffer, NULL, dc, &rect);
+    rect = text_rect;
+    rect.x2 += 2;
+    rect.y2 += 2;
+    rtgui_dc_blit(dc_buffer, NULL, dc, &rect);
 
-	/* 绘图完成 */
-	rtgui_dc_end_drawing(dc);
+    /* 绘图完成 */
+    rtgui_dc_end_drawing(dc);
 }
 
 static rt_bool_t animation_event_handler(struct rtgui_object *object, rtgui_event_t *event)
 {
-	struct rtgui_widget *widget = RTGUI_WIDGET(object);
+    struct rtgui_widget *widget = RTGUI_WIDGET(object);
 
-	if (event->type == RTGUI_EVENT_PAINT)
-	{
-		struct rtgui_dc* dc;
-		rtgui_rect_t rect;
+    if (event->type == RTGUI_EVENT_PAINT)
+    {
+        struct rtgui_dc *dc;
+        rtgui_rect_t rect;
 
-		/* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view先绘图 */
-		rtgui_container_event_handler(object, event);
+        /* 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view先绘图 */
+        rtgui_container_event_handler(object, event);
 
-		/* 获得控件所属的DC */
-		dc = rtgui_dc_begin_drawing(widget);
-		if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
-			return RT_FALSE;
+        /* 获得控件所属的DC */
+        dc = rtgui_dc_begin_drawing(widget);
+        if (dc == RT_NULL) /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
+            return RT_FALSE;
 
         /* 获得demo view允许绘图的区域 */
         demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
 
-		/* 绘图 */
-		rect = text_rect;
-		rtgui_rect_inflate(&rect, +1);
-		rtgui_dc_blit(dc_buffer, NULL, dc, &rect);
-
-		/* 绘图完成 */
-		rtgui_dc_end_drawing(dc);
-	}
-	else
-	{
-		/* 调用默认的事件处理函数 */
-		return rtgui_container_event_handler(object, event);
-	}
-
-	return RT_FALSE;
+        /* 绘图 */
+        rect = text_rect;
+        rtgui_rect_inflate(&rect, +1);
+        rtgui_dc_blit(dc_buffer, NULL, dc, &rect);
+
+        /* 绘图完成 */
+        rtgui_dc_end_drawing(dc);
+    }
+    else
+    {
+        /* 调用默认的事件处理函数 */
+        return rtgui_container_event_handler(object, event);
+    }
+
+    return RT_FALSE;
 }
 
 static rt_bool_t animation_on_show(struct rtgui_object *object, struct rtgui_event *event)
 {
-	rt_kprintf("buffer animation on show\n");
-	rtgui_timer_start(timer);
+    rt_kprintf("buffer animation on show\n");
+    rtgui_timer_start(timer);
 
-	return RT_TRUE;
+    return RT_TRUE;
 }
 
 static rt_bool_t animation_on_hide(struct rtgui_object *object, struct rtgui_event *event)
 {
-	rt_kprintf("buffer animation on hide\n");
-	rtgui_timer_stop(timer);
+    rt_kprintf("buffer animation on hide\n");
+    rtgui_timer_stop(timer);
 
-	return RT_TRUE;
+    return RT_TRUE;
 }
 
 struct rtgui_container *demo_view_buffer_animation(void)
 {
-	struct rtgui_container *container;
-
-	container= demo_view("DC 缓冲区动画");
-	if (container!= RT_NULL)
-		rtgui_object_set_event_handler(RTGUI_OBJECT(container), animation_event_handler);
-
-	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(container)), "缓冲动画", &text_rect);
-	if (dc_buffer == RT_NULL)
-	{
-		rtgui_rect_t rect;
-
-		rect.x1 = 0; rect.x2 = rtgui_rect_width(text_rect) + 2;
-		rect.y1 = 0; rect.y2 = rtgui_rect_height(text_rect) + 2;
-
-		/* 创建 DC Buffer,长 50,宽 50 */
-		dc_buffer = rtgui_dc_buffer_create(rtgui_rect_width(rect), rtgui_rect_height(rect));
-		RTGUI_DC_FC(dc_buffer) = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(container));
-		rtgui_dc_fill_rect(dc_buffer, &rect);
-		RTGUI_DC_FC(dc_buffer) = black;
-		rect.x1 = 1; rect.y1 = 1;
-		rtgui_dc_draw_text(dc_buffer, "缓冲动画", &rect);
-	}
-
-	/* 启动定时器以触发动画 */
-	timer = rtgui_timer_create(1, RT_TIMER_FLAG_PERIODIC, timeout, (void*)container);
-
-	rtgui_widget_set_onshow(RTGUI_WIDGET(container), animation_on_show);
-	rtgui_widget_set_onhide(RTGUI_WIDGET(container), animation_on_hide);
-
-	return container;
+    struct rtgui_container *container;
+
+    container = demo_view("DC 缓冲区动画");
+    if (container != RT_NULL)
+        rtgui_object_set_event_handler(RTGUI_OBJECT(container), animation_event_handler);
+
+    rtgui_font_get_metrics(RTGUI_WIDGET_FONT(container), "缓冲动画", &text_rect);
+    if (dc_buffer == RT_NULL)
+    {
+        rtgui_rect_t rect;
+
+        rect.x1 = 0;
+        rect.x2 = rtgui_rect_width(text_rect) + 2;
+        rect.y1 = 0;
+        rect.y2 = rtgui_rect_height(text_rect) + 2;
+
+        /* 创建 DC Buffer,长 50,宽 50 */
+        dc_buffer = rtgui_dc_buffer_create(rtgui_rect_width(rect), rtgui_rect_height(rect));
+        RTGUI_DC_FC(dc_buffer) = RTGUI_WIDGET_BACKGROUND(container);
+        rtgui_dc_fill_rect(dc_buffer, &rect);
+        RTGUI_DC_FC(dc_buffer) = black;
+        rect.x1 = 1;
+        rect.y1 = 1;
+        rtgui_dc_draw_text(dc_buffer, "缓冲动画", &rect);
+    }
+
+    /* 启动定时器以触发动画 */
+    timer = rtgui_timer_create(1, RT_TIMER_FLAG_PERIODIC, timeout, (void *)container);
+
+    rtgui_widget_set_onshow(RTGUI_WIDGET(container), animation_on_show);
+    rtgui_widget_set_onhide(RTGUI_WIDGET(container), animation_on_hide);
+
+    return container;
 }

+ 62 - 62
examples/gui/demo_view_button.c

@@ -8,73 +8,73 @@
 #include <rtgui/widgets/button.h>
 
 /* 创建用于演示button控件的视图 */
-rtgui_container_t* demo_view_button(void)
+rtgui_container_t *demo_view_button(void)
 {
-	rtgui_rect_t rect;
-	rtgui_container_t* container;
-	rtgui_button_t* button;
-	rtgui_font_t* font;
+    rtgui_rect_t rect;
+    rtgui_container_t *container;
+    rtgui_button_t *button;
+    rtgui_font_t *font;
 
-	/* 先创建一个演示用的视图 */
-	container = demo_view("Button View");
+    /* 先创建一个演示用的视图 */
+    container = demo_view("Button View");
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个button控件 */
-	button = rtgui_button_create("Red");
-	/* 设置label控件的前景色为红色 */
-	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(button)) = red;
-	/* 设置button的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
-	rtgui_container_add_child(container, RTGUI_WIDGET(button));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个button控件 */
+    button = rtgui_button_create("Red");
+    /* 设置label控件的前景色为红色 */
+    RTGUI_WIDGET_FOREGROUND(button) = red;
+    /* 设置button的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(button));
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 += 5 + 25;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个button控件 */
-	button = rtgui_button_create("Blue");
-	/* 设置label控件的前景色为蓝色 */
-	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(button)) = blue;
-	/* 设置button的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
-	rtgui_container_add_child(container, RTGUI_WIDGET(button));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 5 + 25;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个button控件 */
+    button = rtgui_button_create("Blue");
+    /* 设置label控件的前景色为蓝色 */
+    RTGUI_WIDGET_FOREGROUND(button) = blue;
+    /* 设置button的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(button));
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 += 5 + 25 + 25;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个button控件 */
-	button = rtgui_button_create("12 font");
-	/* 设置字体为12点阵的asc字体 */
-	font = rtgui_font_refer("asc", 12);
-	RTGUI_WIDGET_FONT(RTGUI_WIDGET(button)) = font;
-	/* 设置button的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
-	rtgui_container_add_child(container, RTGUI_WIDGET(button));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 5 + 25 + 25;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个button控件 */
+    button = rtgui_button_create("12 font");
+    /* 设置字体为12点阵的asc字体 */
+    font = rtgui_font_refer("asc", 12);
+    RTGUI_WIDGET_FONT(button) = font;
+    /* 设置button的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(button));
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 += 5 + 25 + 25 + 25;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个button控件 */
-	button = rtgui_button_create("16 font");
-	/* 设置字体为16点阵的asc字体 */
-	font = rtgui_font_refer("asc", 16);
-	RTGUI_WIDGET_FONT(RTGUI_WIDGET(button)) = font;
-	/* 设置button的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
-	rtgui_container_add_child(container, RTGUI_WIDGET(button));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 5 + 25 + 25 + 25;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个button控件 */
+    button = rtgui_button_create("16 font");
+    /* 设置字体为16点阵的asc字体 */
+    font = rtgui_font_refer("asc", 16);
+    RTGUI_WIDGET_FONT(button) = font;
+    /* 设置button的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(button));
 
-	return container;
+    return container;
 }

+ 62 - 62
examples/gui/demo_view_checkbox.c

@@ -8,73 +8,73 @@
 #include <rtgui/widgets/checkbox.h>
 
 /* 创建用于演示checkbox控件的视图 */
-rtgui_container_t* demo_view_checkbox(void)
+rtgui_container_t *demo_view_checkbox(void)
 {
-	rtgui_rect_t rect;
-	rtgui_container_t* container;
-	rtgui_checkbox_t* checkbox;
-	rtgui_font_t* font;
+    rtgui_rect_t rect;
+    rtgui_container_t *container;
+    rtgui_checkbox_t *checkbox;
+    rtgui_font_t *font;
 
-	/* 先创建一个演示用的视图 */
-	container = demo_view("CheckBox View");
+    /* 先创建一个演示用的视图 */
+    container = demo_view("CheckBox View");
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个checkbox控件 */
-	checkbox = rtgui_checkbox_create("Red",RT_TRUE);
-	/* 设置前景色为红色 */
-	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = red;
-	/* 设置checkbox的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
-	rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个checkbox控件 */
+    checkbox = rtgui_checkbox_create("Red", RT_TRUE);
+    /* 设置前景色为红色 */
+    RTGUI_WIDGET_FOREGROUND(checkbox) = red;
+    /* 设置checkbox的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 += 5 + 25;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个checkbox控件 */
-	checkbox = rtgui_checkbox_create("Blue",RT_TRUE);
-	/* 设置前景色为蓝色 */
-	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(checkbox)) = blue;
-	/* 设置checkbox的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
-	rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 5 + 25;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个checkbox控件 */
+    checkbox = rtgui_checkbox_create("Blue", RT_TRUE);
+    /* 设置前景色为蓝色 */
+    RTGUI_WIDGET_FOREGROUND(checkbox) = blue;
+    /* 设置checkbox的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 += 5 + 25 + 25;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个checkbox控件 */
-	checkbox = rtgui_checkbox_create("12 font",RT_TRUE);
-	/* 设置字体为12点阵 */
-	font = rtgui_font_refer("asc", 12);
-	RTGUI_WIDGET_FONT(RTGUI_WIDGET(checkbox)) = font;
-	/* 设置checkbox的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
-	rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 5 + 25 + 25;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个checkbox控件 */
+    checkbox = rtgui_checkbox_create("12 font", RT_TRUE);
+    /* 设置字体为12点阵 */
+    font = rtgui_font_refer("asc", 12);
+    RTGUI_WIDGET_FONT(checkbox) = font;
+    /* 设置checkbox的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 += 5 + 25 + 25 + 25;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个checkbox控件 */
-	checkbox = rtgui_checkbox_create("16 font",RT_TRUE);
-	/* 设置字体为16点阵 */
-	font = rtgui_font_refer("asc", 16);
-	RTGUI_WIDGET_FONT(RTGUI_WIDGET(checkbox)) = font;
-	/* 设置checkbox的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
-	rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 5 + 25 + 25 + 25;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个checkbox控件 */
+    checkbox = rtgui_checkbox_create("16 font", RT_TRUE);
+    /* 设置字体为16点阵 */
+    font = rtgui_font_refer("asc", 16);
+    RTGUI_WIDGET_FONT(checkbox) = font;
+    /* 设置checkbox的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(checkbox), &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(checkbox));
 
-	return container;
+    return container;
 }

+ 22 - 22
examples/gui/demo_view_combobox.c

@@ -8,33 +8,33 @@
 
 struct rtgui_listbox_item items[] =
 {
-	{"item 1", RT_NULL},
-	{"item 2", RT_NULL},
-	{"item 3", RT_NULL},
-	{"item 4", RT_NULL},
-	{"item 5", RT_NULL},
+    {"item 1", RT_NULL},
+    {"item 2", RT_NULL},
+    {"item 3", RT_NULL},
+    {"item 4", RT_NULL},
+    {"item 5", RT_NULL},
 };
 
 /* 创建用于演示combobox控件的视图 */
-rtgui_container_t* demo_view_combobox(void)
+rtgui_container_t *demo_view_combobox(void)
 {
-	rtgui_rect_t rect;
-	rtgui_container_t* container;
-	rtgui_combobox_t* box;
+    rtgui_rect_t rect;
+    rtgui_container_t *container;
+    rtgui_combobox_t *box;
 
-	/* 先创建一个演示用的视图 */
-	container = demo_view("ComboBox View");
+    /* 先创建一个演示用的视图 */
+    container = demo_view("ComboBox View");
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 -= 5;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个label控件 */
-	box = rtgui_combobox_create(items, sizeof(items)/sizeof(items[0]), &rect);
-	/* container是一个container控件,调用add_child方法添加这个box控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(box));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个label控件 */
+    box = rtgui_combobox_create(items, sizeof(items) / sizeof(items[0]), &rect);
+    /* container是一个container控件,调用add_child方法添加这个box控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(box));
 
-	return container;
+    return container;
 }

+ 157 - 155
examples/gui/demo_view_dc.c

@@ -19,174 +19,176 @@ struct rtgui_image_hdcmm stop_image = RTGUI_IMAGE_HDC_DEF(2, 0x1c, 0x16, stop_hd
 /*
  * view的事件处理函数
  */
-rt_bool_t dc_event_handler(struct rtgui_object* object, rtgui_event_t *event)
+rt_bool_t dc_event_handler(struct rtgui_object *object, rtgui_event_t *event)
 {
-	struct rtgui_widget *widget = RTGUI_WIDGET(object);
-
-	/* 仅对PAINT事件进行处理 */
-	if (event->type == RTGUI_EVENT_PAINT)
-	{
-		struct rtgui_dc* dc;
-		rtgui_rect_t rect;
-		const int vx[] = {20, 50, 60, 45, 60, 20};
-		const int vy[] = {150, 50, 90, 60, 45, 50};
-
-		/*
-		 * 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view
-		 * 先绘图
-		 */
-		rtgui_container_event_handler(RTGUI_OBJECT(widget), event);
-
-		/************************************************************************/
-		/* 下面的是DC的操作                                                     */
-		/************************************************************************/
-
-		/* 获得控件所属的DC */
-		dc = rtgui_dc_begin_drawing(widget);
-		/* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
-		if (dc == RT_NULL)
-			return RT_FALSE;
-
-		/* 获得demo view允许绘图的区域 */
-		demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
-
-		RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL;
-		/* 显示GUI的版本信息 */
+    struct rtgui_widget *widget = RTGUI_WIDGET(object);
+
+    /* 仅对PAINT事件进行处理 */
+    if (event->type == RTGUI_EVENT_PAINT)
+    {
+        struct rtgui_dc *dc;
+        rtgui_rect_t rect;
+        const int vx[] = {20, 50, 60, 45, 60, 20};
+        const int vy[] = {150, 50, 90, 60, 45, 50};
+
+        /*
+         * 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view
+         * 先绘图
+         */
+        rtgui_container_event_handler(RTGUI_OBJECT(widget), event);
+
+        /************************************************************************/
+        /* 下面的是DC的操作                                                     */
+        /************************************************************************/
+
+        /* 获得控件所属的DC */
+        dc = rtgui_dc_begin_drawing(widget);
+        /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
+        if (dc == RT_NULL)
+            return RT_FALSE;
+
+        /* 获得demo view允许绘图的区域 */
+        demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
+
+        RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL;
+        /* 显示GUI的版本信息 */
 #ifdef RTGUI_USING_SMALL_SIZE
-		rtgui_dc_draw_text(dc, "RT-Thread/GUI小型版本", &rect);
+        rtgui_dc_draw_text(dc, "RT-Thread/GUI小型版本", &rect);
 #else
-		rtgui_dc_draw_text(dc, "RT-Thread/GUI标准版本", &rect);
+        rtgui_dc_draw_text(dc, "RT-Thread/GUI标准版本", &rect);
 #endif
 
-		{
-			rtgui_rect_t rect = {0, 0, 0x1c, 0x16};
-			rtgui_rect_moveto(&rect, 80, 80);
-			rtgui_image_blit((rtgui_image_t*)&play_image, dc, &rect);
-
-			rect.x1 = 0; rect.y1 = 0;
-			rect.x2 = 0x1c; rect.y2 = 0x16;
-			rtgui_rect_moveto(&rect, 130, 80);
-			rtgui_image_blit((rtgui_image_t*)&stop_image, dc, &rect);
-		}
-		/* 绘制一个圆形 */
-		RTGUI_DC_FC(dc) = red;
-		rtgui_dc_draw_circle(dc, rect.x1 + 10, rect.y1 + 10, 10);
-
-		/* 填充一个圆形 */
-		RTGUI_DC_FC(dc) = green;
-		rtgui_dc_fill_circle(dc, rect.x1 + 30, rect.y1 + 10, 10);
+        {
+            rtgui_rect_t rect = {0, 0, 0x1c, 0x16};
+            rtgui_rect_moveto(&rect, 80, 80);
+            rtgui_image_blit((rtgui_image_t *)&play_image, dc, &rect);
+
+            rect.x1 = 0;
+            rect.y1 = 0;
+            rect.x2 = 0x1c;
+            rect.y2 = 0x16;
+            rtgui_rect_moveto(&rect, 130, 80);
+            rtgui_image_blit((rtgui_image_t *)&stop_image, dc, &rect);
+        }
+        /* 绘制一个圆形 */
+        RTGUI_DC_FC(dc) = red;
+        rtgui_dc_draw_circle(dc, rect.x1 + 10, rect.y1 + 10, 10);
+
+        /* 填充一个圆形 */
+        RTGUI_DC_FC(dc) = green;
+        rtgui_dc_fill_circle(dc, rect.x1 + 30, rect.y1 + 10, 10);
 #if 0
-		/* 画一个圆角矩形 */
-		rect.x1 = 150;
-		rect.y1 = 180;
-		rect.x2 = 210;
-		rect.y2 = 260;
-		RTGUI_DC_FC(dc) = RTGUI_RGB(25, 70, 150);
-		rtgui_dc_draw_round_rect(dc, &rect, 10);
-
-		rect.x1 = 160;
-		rect.y1 = 190;
-		rect.x2 = 200;
-		rect.y2 = 250;
-		RTGUI_DC_FC(dc) = RTGUI_RGB(170, 7, 80);
-		rtgui_dc_fill_round_rect(dc, &rect, 7);
-		
-		/* 画一个圆弧 */
-		RTGUI_DC_FC(dc) = RTGUI_RGB(250, 120, 120);
-		rtgui_dc_draw_arc(dc, rect.x1 + 120, rect.y1 + 60, 30, 0, 120);
-		
-		/* 画一个扇形圆环 */
-		RTGUI_DC_FC(dc) = RTGUI_RGB(150, 23, 100);
-		rtgui_dc_draw_annulus(dc, 180, 170, 30, 50, 210, 330);
-
-		/* 多边形 */
-		RTGUI_DC_FC(dc) = blue;
-		rtgui_dc_draw_polygon(dc, vx, vy, 6);
+        /* 画一个圆角矩形 */
+        rect.x1 = 150;
+        rect.y1 = 180;
+        rect.x2 = 210;
+        rect.y2 = 260;
+        RTGUI_DC_FC(dc) = RTGUI_RGB(25, 70, 150);
+        rtgui_dc_draw_round_rect(dc, &rect, 10);
+
+        rect.x1 = 160;
+        rect.y1 = 190;
+        rect.x2 = 200;
+        rect.y2 = 250;
+        RTGUI_DC_FC(dc) = RTGUI_RGB(170, 7, 80);
+        rtgui_dc_fill_round_rect(dc, &rect, 7);
+
+        /* 画一个圆弧 */
+        RTGUI_DC_FC(dc) = RTGUI_RGB(250, 120, 120);
+        rtgui_dc_draw_arc(dc, rect.x1 + 120, rect.y1 + 60, 30, 0, 120);
+
+        /* 画一个扇形圆环 */
+        RTGUI_DC_FC(dc) = RTGUI_RGB(150, 23, 100);
+        rtgui_dc_draw_annulus(dc, 180, 170, 30, 50, 210, 330);
+
+        /* 多边形 */
+        RTGUI_DC_FC(dc) = blue;
+        rtgui_dc_draw_polygon(dc, vx, vy, 6);
 
 #endif
-		RTGUI_DC_FC(dc) = blue;
-
-		/* 绘制不同的边框 */
-		{
-			rtgui_rect_t rect = {0, 0, 16, 16};
-			rtgui_rect_moveto(&rect, 30, 120);
-
-			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE);
-			rect.x1 += 20;
-			rect.x2 += 20 + 50;
-			rtgui_dc_draw_text(dc, "raise", &rect);
-			rect.x1 -= 20;
-			rect.x2 -= 20 + 50;
-			rect.y1 += 20;
-			rect.y2 += 20;
-
-			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SIMPLE);
-			rect.x1 += 20;
-			rect.x2 += 20 + 50;
-			rtgui_dc_draw_text(dc, "simple", &rect);
-			rect.x1 -= 20;
-			rect.x2 -= 20 + 50;
-			rect.y1 += 20;
-			rect.y2 += 20;
-
-			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
-			rect.x1 += 20;
-			rect.x2 += 20 + 50;
-			rtgui_dc_draw_text(dc, "sunken", &rect);
-			rect.x1 -= 20;
-			rect.x2 -= 20 + 50;
-			rect.y1 += 20;
-			rect.y2 += 20;
-
-			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
-			rect.x1 += 20;
-			rect.x2 += 20 + 50;
-			rtgui_dc_draw_text(dc, "box", &rect);
-			rect.x1 -= 20;
-			rect.x2 -= 20 + 50;
-			rect.y1 += 20;
-			rect.y2 += 20;
-
-			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_STATIC);
-			rect.x1 += 20;
-			rect.x2 += 20 + 50;
-			rtgui_dc_draw_text(dc, "static", &rect);
-			rect.x1 -= 20;
-			rect.x2 -= 20 + 50;
-			rect.y1 += 20;
-			rect.y2 += 20;
-
-			rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_EXTRA);
-			rect.x1 += 20;
-			rect.x2 += 20 + 50;
-			rtgui_dc_draw_text(dc, "extera", &rect);
-			rect.x1 -= 20;
-			rect.x2 -= 20 + 50;
-			rect.y1 += 20;
-			rect.y2 += 20;
-		}
-
-		/* 绘图完成 */
-		rtgui_dc_end_drawing(dc);
-	}
-	else
-	{
-		/* 其他事件,调用默认的事件处理函数 */
-		return rtgui_container_event_handler(object, event);
-	}
-
-	return RT_FALSE;
+        RTGUI_DC_FC(dc) = blue;
+
+        /* 绘制不同的边框 */
+        {
+            rtgui_rect_t rect = {0, 0, 16, 16};
+            rtgui_rect_moveto(&rect, 30, 120);
+
+            rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE);
+            rect.x1 += 20;
+            rect.x2 += 20 + 50;
+            rtgui_dc_draw_text(dc, "raise", &rect);
+            rect.x1 -= 20;
+            rect.x2 -= 20 + 50;
+            rect.y1 += 20;
+            rect.y2 += 20;
+
+            rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SIMPLE);
+            rect.x1 += 20;
+            rect.x2 += 20 + 50;
+            rtgui_dc_draw_text(dc, "simple", &rect);
+            rect.x1 -= 20;
+            rect.x2 -= 20 + 50;
+            rect.y1 += 20;
+            rect.y2 += 20;
+
+            rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
+            rect.x1 += 20;
+            rect.x2 += 20 + 50;
+            rtgui_dc_draw_text(dc, "sunken", &rect);
+            rect.x1 -= 20;
+            rect.x2 -= 20 + 50;
+            rect.y1 += 20;
+            rect.y2 += 20;
+
+            rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
+            rect.x1 += 20;
+            rect.x2 += 20 + 50;
+            rtgui_dc_draw_text(dc, "box", &rect);
+            rect.x1 -= 20;
+            rect.x2 -= 20 + 50;
+            rect.y1 += 20;
+            rect.y2 += 20;
+
+            rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_STATIC);
+            rect.x1 += 20;
+            rect.x2 += 20 + 50;
+            rtgui_dc_draw_text(dc, "static", &rect);
+            rect.x1 -= 20;
+            rect.x2 -= 20 + 50;
+            rect.y1 += 20;
+            rect.y2 += 20;
+
+            rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_EXTRA);
+            rect.x1 += 20;
+            rect.x2 += 20 + 50;
+            rtgui_dc_draw_text(dc, "extera", &rect);
+            rect.x1 -= 20;
+            rect.x2 -= 20 + 50;
+            rect.y1 += 20;
+            rect.y2 += 20;
+        }
+
+        /* 绘图完成 */
+        rtgui_dc_end_drawing(dc);
+    }
+    else
+    {
+        /* 其他事件,调用默认的事件处理函数 */
+        return rtgui_container_event_handler(object, event);
+    }
+
+    return RT_FALSE;
 }
 
 /* 创建用于DC操作演示用的视图 */
 rtgui_container_t *demo_view_dc(void)
 {
-	rtgui_container_t *view;
+    rtgui_container_t *view;
 
-	view = demo_view("DC Demo");
-	if (view != RT_NULL)
-		/* 设置成自己的事件处理函数 */
-		rtgui_object_set_event_handler(RTGUI_OBJECT(view), dc_event_handler);
+    view = demo_view("DC Demo");
+    if (view != RT_NULL)
+        /* 设置成自己的事件处理函数 */
+        rtgui_object_set_event_handler(RTGUI_OBJECT(view), dc_event_handler);
 
-	return view;
+    return view;
 }

+ 54 - 54
examples/gui/demo_view_dc_buffer.c

@@ -16,69 +16,69 @@ static struct rtgui_dc *dc_buffer;
 /*
  * view的事件处理函数
  */
-static rt_bool_t dc_buffer_event_handler(struct rtgui_object* object, rtgui_event_t *event)
+static rt_bool_t dc_buffer_event_handler(struct rtgui_object *object, rtgui_event_t *event)
 {
-	struct rtgui_widget *widget = RTGUI_WIDGET(object);
-
-	/* 仅对PAINT事件进行处理 */
-	if (event->type == RTGUI_EVENT_PAINT)
-	{
-		struct rtgui_dc* dc;
-		rtgui_rect_t rect;
-
-		/*
-		 * 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view
-		 * 先绘图
-		 */
-		rtgui_container_event_handler(object, event);
-
-		/* 获得控件所属的DC */
-		dc = rtgui_dc_begin_drawing(widget);
-		/* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
-		if (dc == RT_NULL)
-			return RT_FALSE;
-
-		/* 获得demo view允许绘图的区域 */
-		demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
-
-		rect.x1 += 10;
-		rect.y1 += 10;
-		rtgui_dc_blit(dc_buffer, NULL, dc, &rect);
-
-		/* 绘图完成 */
-		rtgui_dc_end_drawing(dc);
-	}
-	else
-	{
-		/* 其他事件,调用默认的事件处理函数 */
-		return rtgui_container_event_handler(object, event);
-	}
-
-	return RT_FALSE;
+    struct rtgui_widget *widget = RTGUI_WIDGET(object);
+
+    /* 仅对PAINT事件进行处理 */
+    if (event->type == RTGUI_EVENT_PAINT)
+    {
+        struct rtgui_dc *dc;
+        rtgui_rect_t rect;
+
+        /*
+         * 因为用的是demo view,上面本身有一部分控件,所以在绘图时先要让demo view
+         * 先绘图
+         */
+        rtgui_container_event_handler(object, event);
+
+        /* 获得控件所属的DC */
+        dc = rtgui_dc_begin_drawing(widget);
+        /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
+        if (dc == RT_NULL)
+            return RT_FALSE;
+
+        /* 获得demo view允许绘图的区域 */
+        demo_view_get_logic_rect(RTGUI_CONTAINER(widget), &rect);
+
+        rect.x1 += 10;
+        rect.y1 += 10;
+        rtgui_dc_blit(dc_buffer, NULL, dc, &rect);
+
+        /* 绘图完成 */
+        rtgui_dc_end_drawing(dc);
+    }
+    else
+    {
+        /* 其他事件,调用默认的事件处理函数 */
+        return rtgui_container_event_handler(object, event);
+    }
+
+    return RT_FALSE;
 }
 
 /* 创建用于DC Buffer操作演示用的视图 */
 rtgui_container_t *demo_view_dc_buffer()
 {
-	rtgui_container_t *view;
+    rtgui_container_t *view;
 
-	if (dc_buffer == RT_NULL)
-	{
-		rtgui_rect_t rect = {0, 0, 50, 50};
+    if (dc_buffer == RT_NULL)
+    {
+        rtgui_rect_t rect = {0, 0, 50, 50};
 
-		/* 创建 DC Buffer,长 50,宽 50 */
-		dc_buffer = rtgui_dc_buffer_create(50, 50);
-		RTGUI_DC_FC(dc_buffer) = blue;
-		rtgui_dc_fill_rect(dc_buffer, &rect);
+        /* 创建 DC Buffer,长 50,宽 50 */
+        dc_buffer = rtgui_dc_buffer_create(50, 50);
+        RTGUI_DC_FC(dc_buffer) = blue;
+        rtgui_dc_fill_rect(dc_buffer, &rect);
 
-		RTGUI_DC_FC(dc_buffer) = red;
-		rtgui_dc_draw_circle(dc_buffer, 25, 25, 10);
-	}
+        RTGUI_DC_FC(dc_buffer) = red;
+        rtgui_dc_draw_circle(dc_buffer, 25, 25, 10);
+    }
 
-	view = demo_view("缓冲DC演示");
-	if (view != RT_NULL)
-		/* 设置成自己的事件处理函数 */
-		rtgui_object_set_event_handler(RTGUI_OBJECT(view), dc_buffer_event_handler);
+    view = demo_view("缓冲DC演示");
+    if (view != RT_NULL)
+        /* 设置成自己的事件处理函数 */
+        rtgui_object_set_event_handler(RTGUI_OBJECT(view), dc_buffer_event_handler);
 
-	return view;
+    return view;
 }

+ 120 - 0
examples/gui/demo_view_edit.c

@@ -0,0 +1,120 @@
+/*
+ * 程序清单:edit控件演示
+ *
+ * 这个例子会在conatiner上进行edit控件的演示
+ */
+
+#include "demo_view.h"
+#include <rtgui/dc.h>
+#include <rtgui/rtgui_system.h>
+#include <rtgui/widgets/edit.h>
+#include <rtgui/widgets/button.h>
+
+void demo_edit_readin_file(struct rtgui_object *object, struct rtgui_event *event)
+{
+    rtgui_button_t *button;
+    struct rtgui_edit *edit;
+    const char *filename = "/test_readin.txt";
+    int fd;
+
+    RT_ASSERT(object != RT_NULL);
+    button = RTGUI_BUTTON(object);
+    /* 取得edit指针 */
+    edit = RTGUI_EDIT(RTGUI_WIDGET(button)->user_data);
+
+    /* 判断文件是否存在 */
+    fd = open(filename, O_RDONLY, 0);
+    if (fd < 0)
+    {
+        /* 不存在存在,则创建它 */
+        rt_kprintf("file:\"%s\" does not exist!\n", filename);
+
+        return;
+    }
+    close(fd);
+
+    rt_kprintf("read-in file:\"%s\"\n", filename);
+    rtgui_edit_readin_file(edit, filename);
+}
+
+void demo_edit_saveas_file(struct rtgui_object *object, struct rtgui_event *event)
+{
+    rtgui_button_t *button;
+    struct rtgui_edit *edit;
+    const char* filename = "/test_saveas.txt";
+    int fd;
+
+    RT_ASSERT(object != RT_NULL);
+    button = RTGUI_BUTTON(object);
+    /* 取得edit指针 */
+    edit = RTGUI_EDIT(RTGUI_WIDGET(button)->user_data);
+
+    /* 判断文件是否存在, 如果存在则删除之 */
+    fd = open(filename, O_RDONLY, 0);
+    if (fd > 0)
+    {
+        close(fd);
+        /* 如果是在win32中调试, 请手工删除该文件吧, NT中文件是只读的,unlink删除不掉 */
+        if (unlink(filename) == -1)
+            rt_kprintf("Could not delete %s\n", filename);
+    }
+
+    rt_kprintf("save as file:\"%s\"\n", filename);
+    rtgui_edit_saveas_file(edit, filename);
+}
+
+/* 创建用于演示edit控件的视图 */
+rtgui_container_t *demo_view_edit(void)
+{
+    rtgui_rect_t rect;
+    rtgui_container_t *container;
+    struct rtgui_edit *edit;
+    struct rtgui_button *button;
+
+    /* 先创建一个演示用的视图 */
+    container = demo_view("Edit View");
+
+    edit = rtgui_edit_create(container, 10, 35, 220, 200);
+    rtgui_edit_set_text(edit, 
+                        "Edit beta v0.1\n"
+                        "Hello RT-Thread\n"
+                        "this's edit demo\n"
+                        "rtgui_edit_create\n"
+                        "rtgui_edit_append_line\n"
+                        "rtgui_edit_insert_line\n"
+                        "rtgui_edit_delete_line\n"
+                        "rtgui_edit_connect_line\n"
+                        "a\n"
+                        "b\n"
+                        "c\n"
+                        "d\n"
+                        "1234567890\n");
+
+    /* 创建一个按钮, 读取某个文件 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 10;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 200;
+    rect.y2 = rect.y1 + 22;
+    button = rtgui_button_create("ReadIn File");
+    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(button));
+    rtgui_button_set_onbutton(button, demo_edit_readin_file);
+    /* 使用user_data传递edit指针 */
+    RTGUI_WIDGET(button)->user_data = (rt_uint32_t)edit;
+
+    /* 创建一个按钮, 保存为某个文件 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 130;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 200;
+    rect.y2 = rect.y1 + 22;
+    button = rtgui_button_create("SaveAs File");
+    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(button));
+    rtgui_button_set_onbutton(button, demo_edit_saveas_file);
+    /* 使用user_data传递edit指针 */
+    RTGUI_WIDGET(button)->user_data = (rt_uint32_t)edit;
+
+    return container;
+}

+ 91 - 89
examples/gui/demo_view_image.c

@@ -9,118 +9,120 @@
 #include <rtgui/widgets/filelist_view.h>
 #include <string.h>
 
-static rtgui_image_t* image = RT_NULL;
-static rtgui_container_t* _container = RT_NULL;
+static rtgui_image_t *image = RT_NULL;
+static rtgui_container_t *_container = RT_NULL;
 
 #if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
 /* 打开按钮的回调函数 */
-static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
+static void open_btn_onbutton(rtgui_widget_t *widget, struct rtgui_event *event)
 {
-	rtgui_filelist_view_t *filelist;
-	struct rtgui_rect rect = {0, 100, 240, 280};
+    rtgui_filelist_view_t *filelist;
+    struct rtgui_rect rect = {0, 100, 240, 280};
 
-	/* WIN32平台上和真实设备上的初始路径处理 */
+    /* WIN32平台上和真实设备上的初始路径处理 */
 #ifdef _WIN32
-	filelist = rtgui_filelist_view_create("e:\\", "*.*", &rect);
+    filelist = rtgui_filelist_view_create("e:\\", "*.*", &rect);
 #else
-	filelist = rtgui_filelist_view_create("/", "*.*", &rect);
+    filelist = rtgui_filelist_view_create("/", "*.*", &rect);
 #endif
-	/* 模态显示一个文件列表视图,以提供给用户选择图像文件 */
-	if (rtgui_widget_show(RTGUI_WIDGET(filelist), RT_TRUE) == RTGUI_MODAL_OK)
-	{
-		char path[32], image_type[8];
-
-		/* 设置文件路径的标签 */
-		rtgui_filelist_view_get_fullpath(filelist, path, sizeof(path));
-		if (image != RT_NULL)
-		{
-			rtgui_image_destroy(image);
-			image = RT_NULL;
-		}
-
-		rt_memset(image_type, 0, sizeof(image_type));
-
-		/* 获得图像的类型 */
-		if (rt_strstr(path, ".bmp") != RT_NULL ||
-			rt_strstr(path, ".BMP") != RT_NULL)
-			strcat(image_type, "bmp");
-		if (rt_strstr(path, ".png") != RT_NULL ||
-			rt_strstr(path, ".PNG") != RT_NULL)
-			strcat(image_type, "png");
-		if (rt_strstr(path, ".jpg") != RT_NULL ||
-			rt_strstr(path, ".JPG") != RT_NULL)
-			strcat(image_type, "jpeg");
-		if (rt_strstr(path, ".hdc") != RT_NULL ||
-			rt_strstr(path, ".HDC") != RT_NULL)
-			strcat(image_type, "hdc");
-
-		/* 如果图像文件有效,创建相应的rtgui_image对象 */
-		if (image_type[0] != '\0')
-			image = rtgui_image_create_from_file(image_type, path, RT_TRUE);
-	}
-
-	/* 删除 文件列表 视图 */
-	rtgui_container_destroy(RTGUI_CONTAINER(filelist));
-	rtgui_container_show(_container, RT_FALSE);
+    /* 模态显示一个文件列表视图,以提供给用户选择图像文件 */
+    if (rtgui_widget_show(RTGUI_WIDGET(filelist), RT_TRUE) == RTGUI_MODAL_OK)
+    {
+        char path[32], image_type[8];
+
+        /* 设置文件路径的标签 */
+        rtgui_filelist_view_get_fullpath(filelist, path, sizeof(path));
+        if (image != RT_NULL)
+        {
+            rtgui_image_destroy(image);
+            image = RT_NULL;
+        }
+
+        rt_memset(image_type, 0, sizeof(image_type));
+
+        /* 获得图像的类型 */
+        if (rt_strstr(path, ".bmp") != RT_NULL ||
+                rt_strstr(path, ".BMP") != RT_NULL)
+            strcat(image_type, "bmp");
+        if (rt_strstr(path, ".png") != RT_NULL ||
+                rt_strstr(path, ".PNG") != RT_NULL)
+            strcat(image_type, "png");
+        if (rt_strstr(path, ".jpg") != RT_NULL ||
+                rt_strstr(path, ".JPG") != RT_NULL)
+            strcat(image_type, "jpeg");
+        if (rt_strstr(path, ".hdc") != RT_NULL ||
+                rt_strstr(path, ".HDC") != RT_NULL)
+            strcat(image_type, "hdc");
+
+        /* 如果图像文件有效,创建相应的rtgui_image对象 */
+        if (image_type[0] != '\0')
+            image = rtgui_image_create_from_file(image_type, path, RT_TRUE);
+    }
+
+    /* 删除 文件列表 视图 */
+    rtgui_container_destroy(RTGUI_CONTAINER(filelist));
+    rtgui_container_show(_container, RT_FALSE);
 }
 
 /* 演示视图的事件处理函数 */
-static rt_bool_t demo_view_event_handler(rtgui_widget_t* widget, rtgui_event_t *event)
+static rt_bool_t demo_view_event_handler(rtgui_widget_t *widget, rtgui_event_t *event)
 {
-	rt_bool_t result;
+    rt_bool_t result;
 
-	/* 先调用默认的事件处理函数(这里只关心PAINT事件,但演示视图还有本身的一些控件) */
-	result = rtgui_container_event_handler(widget, event);
+    /* 先调用默认的事件处理函数(这里只关心PAINT事件,但演示视图还有本身的一些控件) */
+    result = rtgui_container_event_handler(widget, event);
 
-	if (event->type == RTGUI_EVENT_PAINT)
-	{
-		struct rtgui_dc* dc;
-		rtgui_rect_t rect;
+    if (event->type == RTGUI_EVENT_PAINT)
+    {
+        struct rtgui_dc *dc;
+        rtgui_rect_t rect;
 
-		/* 获得控件所属的DC */
-		dc = rtgui_dc_begin_drawing(widget);
-		if (dc == RT_NULL)
-			/* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
-			return RT_FALSE;
+        /* 获得控件所属的DC */
+        dc = rtgui_dc_begin_drawing(widget);
+        if (dc == RT_NULL)
+            /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
+            return RT_FALSE;
 
-		/* 获得demo container允许绘图的区域 */
-		demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
+        /* 获得demo container允许绘图的区域 */
+        demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
 
-		/* 获得图像显示区域 */
-		rect.x1 += 5; rect.x2 -= 5;
-		rect.y1 += 30;
+        /* 获得图像显示区域 */
+        rect.x1 += 5;
+        rect.x2 -= 5;
+        rect.y1 += 30;
 
-		if (image != RT_NULL)
-			rtgui_image_blit(image, dc, &rect);
+        if (image != RT_NULL)
+            rtgui_image_blit(image, dc, &rect);
 
-		/* 绘图完成 */
-		rtgui_dc_end_drawing(dc);
-	}
+        /* 绘图完成 */
+        rtgui_dc_end_drawing(dc);
+    }
 
-	return result;
+    return result;
 }
 
 /* 创建用于显示图像的演示视图 */
-rtgui_container_t* demo_view_image(void)
+rtgui_container_t *demo_view_image(void)
 {
-	rtgui_rect_t rect;
-	rtgui_button_t* open_btn;
-
-	/* 先创建一个演示视图 */
-	_container = demo_view("图像演示");
-	if (_container != RT_NULL)
-		/* 设置默认的事件处理函数到demo_view_event_handler函数 */
-		rtgui_object_set_event_handler(RTGUI_WIDGET(_container), demo_view_event_handler);
-
-	/* 添加一个按钮 */
-	demo_view_get_rect(_container, &rect);
-	rect.x1 += 5; rect.x2 = rect.x1 + 120;
-	rect.y2 = rect.y1 + 20;
-	open_btn = rtgui_button_create("打开图像文件");
-	rtgui_container_add_child(RTGUI_CONTAINER(_container), RTGUI_WIDGET(open_btn));
-	rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
-	rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
-
-	return _container;
+    rtgui_rect_t rect;
+    rtgui_button_t *open_btn;
+
+    /* 先创建一个演示视图 */
+    _container = demo_view("图像演示");
+    if (_container != RT_NULL)
+        /* 设置默认的事件处理函数到demo_view_event_handler函数 */
+        rtgui_object_set_event_handler(RTGUI_WIDGET(_container), demo_view_event_handler);
+
+    /* 添加一个按钮 */
+    demo_view_get_rect(_container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 120;
+    rect.y2 = rect.y1 + 20;
+    open_btn = rtgui_button_create("打开图像文件");
+    rtgui_container_add_child(RTGUI_CONTAINER(_container), RTGUI_WIDGET(open_btn));
+    rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
+    rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
+
+    return _container;
 }
 #endif

+ 117 - 117
examples/gui/demo_view_instrument_panel.c

@@ -17,133 +17,133 @@
  */
 rt_bool_t instrument_panel_event_handler(struct rtgui_object *object, rtgui_event_t *event)
 {
-	struct rtgui_widget *widget = RTGUI_WIDGET(object);
-	char ac[4];
-	int i;
-	int x0 = 120;
-	int y0 = 170;
-	int x, y;
-	int default_color;
-	
-	/* 仅对PAINT事件进行处理 */
-	if (event->type == RTGUI_EVENT_PAINT)
-	{
-		struct rtgui_dc* dc;
-		rtgui_rect_t rect;
-		const int arrowx[] = {120+75, 120+75, 120+85};
-		const int arrowy[] = {170-5,  170+5,  170};
-
-		/*
-		 * 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container
-		 * 先绘图
-		 */
-		rtgui_container_event_handler(RTGUI_OBJECT(widget), event);
-
-		/************************************************************************/
-		/* 下面的是DC的操作                                                     */
-		/************************************************************************/
-
-		/* 获得控件所属的DC */
-		dc = rtgui_dc_begin_drawing(widget);
-		/* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
-		if (dc == RT_NULL)
-			return RT_FALSE;
-
-		/* 获得demo container允许绘图的区域 */
-		demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
-
-		RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL;
-		/* 显示GUI的版本信息 */
+    struct rtgui_widget *widget = RTGUI_WIDGET(object);
+    char ac[4];
+    int i;
+    int x0 = 120;
+    int y0 = 170;
+    int x, y;
+    int default_color;
+
+    /* 仅对PAINT事件进行处理 */
+    if (event->type == RTGUI_EVENT_PAINT)
+    {
+        struct rtgui_dc *dc;
+        rtgui_rect_t rect;
+        const int arrowx[] = {120 + 75, 120 + 75, 120 + 85};
+        const int arrowy[] = {170 - 5,  170 + 5,  170};
+
+        /*
+         * 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container
+         * 先绘图
+         */
+        rtgui_container_event_handler(RTGUI_OBJECT(widget), event);
+
+        /************************************************************************/
+        /* 下面的是DC的操作                                                     */
+        /************************************************************************/
+
+        /* 获得控件所属的DC */
+        dc = rtgui_dc_begin_drawing(widget);
+        /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
+        if (dc == RT_NULL)
+            return RT_FALSE;
+
+        /* 获得demo container允许绘图的区域 */
+        demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
+
+        RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_BOTTOM | RTGUI_ALIGN_CENTER_HORIZONTAL;
+        /* 显示GUI的版本信息 */
 #ifdef RTGUI_USING_SMALL_SIZE
-		rtgui_dc_draw_text(dc, "RT-Thread/GUI小型版本", &rect);
+        rtgui_dc_draw_text(dc, "RT-Thread/GUI小型版本", &rect);
 #else
-		rtgui_dc_draw_text(dc, "RT-Thread/GUI标准版本", &rect);
+        rtgui_dc_draw_text(dc, "RT-Thread/GUI标准版本", &rect);
 #endif
 
 
-	RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_CENTER_VERTICAL | RTGUI_ALIGN_CENTER_HORIZONTAL;
-	RTGUI_DC_FC(dc) = blue;
-	rect.y2 = 270;
-	rtgui_dc_draw_text(dc, "rtgui-panel", &rect);
-
-	for(i = 0; i < 6; i++)
-	{
-		rtgui_dc_draw_arc(dc, x0, y0, 117-i, 150, 30);
-	}
-
-	RTGUI_DC_FC(dc) = black;
-
-	RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_LEFT;
-	for(i = 0; i <= 23; i++)
-	{
-		if(i < 12)
-		{
-			x = x0 + 105 * cos((150 + i * 10) * 3.1415926 / 180);
-			y = y0 + 105 * sin((150 + i * 10) * 3.1415926 / 180);
-			rect.x1 = x;
-			rect.y1 = y;
-			rect.x2 = rect.x1 + 12 * 3;
-			rect.y2 = rect.y1 + 12;
-			rt_sprintf(ac, "%d", 10 * i);
-			rtgui_dc_draw_text(dc, ac, &rect);	
-		}
-		else
-		{
-			RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_RIGHT;
-	
-			x = x0 + 105 * cos((160 + i * 10) * 3.1415926 / 180);
-			y = y0 + 105 * sin((160 + i * 10) * 3.1415926 / 180);
-
-			rect.x1 = x  - 12 * 3;
-			rect.y1 = y;
-			rect.x2 = rect.x1 + 12 * 3;
-			rect.y2 = rect.y1 + 12;
-			rt_sprintf(ac, "%d", 10 * i);
-			rtgui_dc_draw_text(dc, ac, &rect);
-		}
-
-		x = x0 + 107 * cos((150 + i * 10) * 3.1415926 / 180);
-		y = y0 + 107 * sin((150 + i * 10) * 3.1415926 / 180);
-		rtgui_dc_fill_circle(dc, x, y, 3);
-	}
-	RTGUI_DC_FC(dc) = RTGUI_RGB(166, 0, 166);
-	rtgui_dc_fill_circle(dc, x0, y0, 3);
-	RTGUI_DC_FC(dc) = RTGUI_RGB(120, 141, 30);
-	rtgui_dc_draw_circle(dc, x0, y0, 5);
-
-	default_color = RTGUI_DC_BC(dc);
-	RTGUI_DC_BC(dc) = red;
-	rect.x1 = x0 + 7;
-	rect.y1 = y0 - 1;
-	rect.x2 = x0 + 75;
-	rect.y2 = y0 + 1;
-	rtgui_dc_fill_rect(dc, &rect);
-
-	RTGUI_DC_BC(dc) = default_color;
-
-	rtgui_dc_fill_polygon(dc, arrowx, arrowy, 3);
-
-		/* 绘图完成 */
-		rtgui_dc_end_drawing(dc);
-	}
-	else
-	{
-		/* 其他事件,调用默认的事件处理函数 */
-		return rtgui_container_event_handler(RTGUI_OBJECT(widget), event);
-	}
-
-	return RT_FALSE;
+        RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_CENTER_VERTICAL | RTGUI_ALIGN_CENTER_HORIZONTAL;
+        RTGUI_DC_FC(dc) = blue;
+        rect.y2 = 270;
+        rtgui_dc_draw_text(dc, "rtgui-panel", &rect);
+
+        for (i = 0; i < 6; i++)
+        {
+            rtgui_dc_draw_arc(dc, x0, y0, 117 - i, 150, 30);
+        }
+
+        RTGUI_DC_FC(dc) = black;
+
+        RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_LEFT;
+        for (i = 0; i <= 23; i++)
+        {
+            if (i < 12)
+            {
+                x = x0 + 105 * cos((150 + i * 10) * 3.1415926 / 180);
+                y = y0 + 105 * sin((150 + i * 10) * 3.1415926 / 180);
+                rect.x1 = x;
+                rect.y1 = y;
+                rect.x2 = rect.x1 + 12 * 3;
+                rect.y2 = rect.y1 + 12;
+                rt_sprintf(ac, "%d", 10 * i);
+                rtgui_dc_draw_text(dc, ac, &rect);
+            }
+            else
+            {
+                RTGUI_DC_TEXTALIGN(dc) = RTGUI_ALIGN_RIGHT;
+
+                x = x0 + 105 * cos((160 + i * 10) * 3.1415926 / 180);
+                y = y0 + 105 * sin((160 + i * 10) * 3.1415926 / 180);
+
+                rect.x1 = x  - 12 * 3;
+                rect.y1 = y;
+                rect.x2 = rect.x1 + 12 * 3;
+                rect.y2 = rect.y1 + 12;
+                rt_sprintf(ac, "%d", 10 * i);
+                rtgui_dc_draw_text(dc, ac, &rect);
+            }
+
+            x = x0 + 107 * cos((150 + i * 10) * 3.1415926 / 180);
+            y = y0 + 107 * sin((150 + i * 10) * 3.1415926 / 180);
+            rtgui_dc_fill_circle(dc, x, y, 3);
+        }
+        RTGUI_DC_FC(dc) = RTGUI_RGB(166, 0, 166);
+        rtgui_dc_fill_circle(dc, x0, y0, 3);
+        RTGUI_DC_FC(dc) = RTGUI_RGB(120, 141, 30);
+        rtgui_dc_draw_circle(dc, x0, y0, 5);
+
+        default_color = RTGUI_DC_BC(dc);
+        RTGUI_DC_BC(dc) = red;
+        rect.x1 = x0 + 7;
+        rect.y1 = y0 - 1;
+        rect.x2 = x0 + 75;
+        rect.y2 = y0 + 1;
+        rtgui_dc_fill_rect(dc, &rect);
+
+        RTGUI_DC_BC(dc) = default_color;
+
+        rtgui_dc_fill_polygon(dc, arrowx, arrowy, 3);
+
+        /* 绘图完成 */
+        rtgui_dc_end_drawing(dc);
+    }
+    else
+    {
+        /* 其他事件,调用默认的事件处理函数 */
+        return rtgui_container_event_handler(RTGUI_OBJECT(widget), event);
+    }
+
+    return RT_FALSE;
 }
 
 /* 创建用于DC操作演示用的视图 */
 rtgui_container_t *demo_view_instrument_panel(void)
 {
-	rtgui_container_t *container;
+    rtgui_container_t *container;
 
-	container = demo_view("instrument panel Demo");
-	if (container != RT_NULL)
-		/* 设置成自己的事件处理函数 */
-		rtgui_object_set_event_handler(RTGUI_OBJECT(container), instrument_panel_event_handler);
+    container = demo_view("instrument panel Demo");
+    if (container != RT_NULL)
+        /* 设置成自己的事件处理函数 */
+        rtgui_object_set_event_handler(RTGUI_OBJECT(container), instrument_panel_event_handler);
 
-	return container;
+    return container;
 }

+ 85 - 85
examples/gui/demo_view_label.c

@@ -7,98 +7,98 @@
 #include <rtgui/widgets/label.h>
 
 /* 创建用于演示label控件的视图 */
-rtgui_container_t* demo_view_label(void)
+rtgui_container_t *demo_view_label(void)
 {
-	rtgui_rect_t rect;
-	rtgui_container_t* container;
-	rtgui_label_t* label;
-	rtgui_font_t* font;
+    rtgui_rect_t rect;
+    rtgui_container_t *container;
+    rtgui_label_t *label;
+    rtgui_font_t *font;
 
-	/* 先创建一个演示用的视图 */
-	container = demo_view("Label View");
+    /* 先创建一个演示用的视图 */
+    container = demo_view("Label View");
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 -= 5;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个label控件 */
-	label = rtgui_label_create("Red Left");
-	/* 设置label控件上的文本对齐方式为:左对齐 */
-	RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_LEFT;
-	/* 设置label控件的前景色为红色 */
-	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = red;
-	/* 设置label的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	/* container是一个container控件,调用add_child方法添加这个label控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个label控件 */
+    label = rtgui_label_create("Red Left");
+    /* 设置label控件上的文本对齐方式为:左对齐 */
+    RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_LEFT;
+    /* 设置label控件的前景色为红色 */
+    RTGUI_WIDGET_FOREGROUND(label) = red;
+    /* 设置label的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    /* container是一个container控件,调用add_child方法添加这个label控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 -= 5;
-	rect.y1 += 5 + 25;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个label控件 */
-	label = rtgui_label_create("Blue Right");
-	/* 设置label控件上的文本对齐方式为:右对齐 */
-	RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_RIGHT;
-	/* 设置label控件的前景色为蓝色 */
-	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = blue;
-	/* 设置label的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	/* container是一个container控件,调用add_child方法添加这个label控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5 + 25;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个label控件 */
+    label = rtgui_label_create("Blue Right");
+    /* 设置label控件上的文本对齐方式为:右对齐 */
+    RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_RIGHT;
+    /* 设置label控件的前景色为蓝色 */
+    RTGUI_WIDGET_FOREGROUND(label) = blue;
+    /* 设置label的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    /* container是一个container控件,调用add_child方法添加这个label控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 -= 5;
-	rect.y1 += 5 + 25 + 25;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个label控件 */
-	label = rtgui_label_create("Green Center");
-	/* 设置label控件的前景色为绿色 */
-	RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(label)) = green;
-	/* 设置label控件上的文本对齐方式为:右对齐 */
-	RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(label)) = RTGUI_ALIGN_CENTER_HORIZONTAL;
-	/* 设置label的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	/* container是一个container控件,调用add_child方法添加这个label控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5 + 25 + 25;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个label控件 */
+    label = rtgui_label_create("Green Center");
+    /* 设置label控件的前景色为绿色 */
+    RTGUI_WIDGET_FOREGROUND(label) = green;
+    /* 设置label控件上的文本对齐方式为:右对齐 */
+    RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_CENTER_HORIZONTAL;
+    /* 设置label的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    /* container是一个container控件,调用add_child方法添加这个label控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 -= 5;
-	rect.y1 += 5 + 25 + 25 + 25;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个label控件 */
-	label = rtgui_label_create("12 font");
-	/* 设置字体为12点阵的asc字体 */
-	font = rtgui_font_refer("asc", 12);
-	RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
-	/* 设置label的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	/* container是一个container控件,调用add_child方法添加这个label控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5 + 25 + 25 + 25;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个label控件 */
+    label = rtgui_label_create("12 font");
+    /* 设置字体为12点阵的asc字体 */
+    font = rtgui_font_refer("asc", 12);
+    RTGUI_WIDGET_FONT(label) = font;
+    /* 设置label的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    /* container是一个container控件,调用add_child方法添加这个label控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.y1 += 5 + 25 + 25 + 25 + 25;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个label控件 */
-	label = rtgui_label_create("16 font");
-	/* 设置字体为16点阵的asc字体 */
-	font = rtgui_font_refer("asc", 16);
-	RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)) = font;
-	/* 设置label的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	/* container是一个container控件,调用add_child方法添加这个label控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.y1 += 5 + 25 + 25 + 25 + 25;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个label控件 */
+    label = rtgui_label_create("16 font");
+    /* 设置字体为16点阵的asc字体 */
+    font = rtgui_font_refer("asc", 16);
+    RTGUI_WIDGET_FONT(label) = font;
+    /* 设置label的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    /* container是一个container控件,调用add_child方法添加这个label控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
 
-	return container;
+    return container;
 }
 

+ 168 - 166
examples/gui/demo_view_listbox.c

@@ -7,187 +7,189 @@
 #include <rtgui/widgets/label.h>
 #include <rtgui/widgets/listbox.h>
 
-static rtgui_image_t* item_icon = RT_NULL;
-static const char * image_xpm[] = {
-	"16 16 106 2",
-	"  	c None",
-	". 	c #D0C83F",
-	"+ 	c #D0C840",
-	"@ 	c #D0C030",
-	"# 	c #D0B820",
-	"$ 	c #D0B020",
-	"% 	c #D0B01F",
-	"& 	c #5F571F",
-	"* 	c #F0F0C0",
-	"= 	c #FFF8D0",
-	"- 	c #FFF8C0",
-	"; 	c #FFF8B0",
-	"> 	c #FFF8A0",
-	", 	c #F0E870",
-	"' 	c #707030",
-	") 	c #4F87EF",
-	"! 	c #4F78C0",
-	"~ 	c #5088E0",
-	"{ 	c #5078C0",
-	"] 	c #C0D0F0",
-	"^ 	c #FFF8E0",
-	"/ 	c #FFF090",
-	"( 	c #F0E070",
-	"_ 	c #6F97D0",
-	": 	c #C0D8FE",
-	"< 	c #80A8F0",
-	"[ 	c #7088D0",
-	"} 	c #B0D0FF",
-	"| 	c #90B0F0",
-	"1 	c #1040A0",
-	"2 	c #F0F080",
-	"3 	c #707040",
-	"4 	c #7098F0",
-	"5 	c #3068E0",
-	"6 	c #A0B8F0",
-	"7 	c #4070C0",
-	"8 	c #002880",
-	"9 	c #404040",
-	"0 	c #505050",
-	"a 	c #F0F090",
-	"b 	c #F0E860",
-	"c 	c #F0D860",
-	"d 	c #807840",
-	"e 	c #2F5FC0",
-	"f 	c #1050D0",
-	"g 	c #1048B0",
-	"h 	c #002870",
-	"i 	c #C0C080",
-	"j 	c #C0C070",
-	"k 	c #F0F070",
-	"l 	c #F0E060",
-	"m 	c #E0D050",
-	"n 	c #00277F",
-	"o 	c #00287F",
-	"p 	c #1F3F6F",
-	"q 	c #1048C0",
-	"r 	c #0040B0",
-	"s 	c #204080",
-	"t 	c #FFF890",
-	"u 	c #F0D850",
-	"v 	c #E0C840",
-	"w 	c #807040",
-	"x 	c #A0B06F",
-	"y 	c #204880",
-	"z 	c #2048A0",
-	"A 	c #90A8C0",
-	"B 	c #FFF080",
-	"C 	c #F0D050",
-	"D 	c #C0A830",
-	"E 	c #6F682F",
-	"F 	c #F0F0A0",
-	"G 	c #E0D060",
-	"H 	c #B0A040",
-	"I 	c #D0B840",
-	"J 	c #E0C040",
-	"K 	c #D0B030",
-	"L 	c #706820",
-	"M 	c #5F581F",
-	"N 	c #CFBF3F",
-	"O 	c #FFF0A0",
-	"P 	c #A09830",
-	"Q 	c #A08820",
-	"R 	c #908030",
-	"S 	c #807830",
-	"T 	c #707020",
-	"U 	c #605820",
-	"V 	c #6F672F",
-	"W 	c #D0C040",
-	"X 	c #F0E880",
-	"Y 	c #907820",
-	"Z 	c #B09820",
-	"` 	c #B09010",
-	" .	c #B08820",
-	"..	c #806820",
-	"+.	c #5F5F1F",
-	"@.	c #F0E080",
-	"#.	c #B09020",
-	"$.	c #C0B040",
-	"%.	c #A09030",
-	"&.	c #908020",
-	"*.	c #606020",
-	"=.	c #6F5F1F",
-	"-.	c #9F982F",
-	";.	c #A0872F",
-	">.	c #6F681F",
-	",.	c #706020",
-	"                                ",
-	"          . + + + @ @ # # $ % & ",
-	"          + * = = = = - ; > , ' ",
-	"  ) !     ~ { ] ^ = - - > / ( ' ",
-	"_ : < { [ } | 1 - ; > > / 2 ( 3 ",
-	"{ 4 5 1 6 7 5 8 9 0 a / , b c d ",
-	"e f g h 8 8 g h i j / k l c m d ",
-	"  n o   p q r s t 2 , l c u v w ",
-	"        x y z A B , l u C v D E ",
-	"        @ F > t k G H I J K L M ",
-	"      N @ O / 2 l P Q R S T U V ",
-	"      W m 2 X l I Y Z `  ...+.  ",
-	"      W @.l u I R #.Z Y U M     ",
-	"    $.G I $.%.R &.Y *.& =.      ",
-	"  -.;.>.,.L L ,.& M             ",
-	"                                "};
+static rtgui_image_t *item_icon = RT_NULL;
+static const char *image_xpm[] =
+{
+    "16 16 106 2",
+    "  	c None",
+    ". 	c #D0C83F",
+    "+ 	c #D0C840",
+    "@ 	c #D0C030",
+    "# 	c #D0B820",
+    "$ 	c #D0B020",
+    "% 	c #D0B01F",
+    "& 	c #5F571F",
+    "* 	c #F0F0C0",
+    "= 	c #FFF8D0",
+    "- 	c #FFF8C0",
+    "; 	c #FFF8B0",
+    "> 	c #FFF8A0",
+    ", 	c #F0E870",
+    "' 	c #707030",
+    ") 	c #4F87EF",
+    "! 	c #4F78C0",
+    "~ 	c #5088E0",
+    "{ 	c #5078C0",
+    "] 	c #C0D0F0",
+    "^ 	c #FFF8E0",
+    "/ 	c #FFF090",
+    "( 	c #F0E070",
+    "_ 	c #6F97D0",
+    ": 	c #C0D8FE",
+    "< 	c #80A8F0",
+    "[ 	c #7088D0",
+    "} 	c #B0D0FF",
+    "| 	c #90B0F0",
+    "1 	c #1040A0",
+    "2 	c #F0F080",
+    "3 	c #707040",
+    "4 	c #7098F0",
+    "5 	c #3068E0",
+    "6 	c #A0B8F0",
+    "7 	c #4070C0",
+    "8 	c #002880",
+    "9 	c #404040",
+    "0 	c #505050",
+    "a 	c #F0F090",
+    "b 	c #F0E860",
+    "c 	c #F0D860",
+    "d 	c #807840",
+    "e 	c #2F5FC0",
+    "f 	c #1050D0",
+    "g 	c #1048B0",
+    "h 	c #002870",
+    "i 	c #C0C080",
+    "j 	c #C0C070",
+    "k 	c #F0F070",
+    "l 	c #F0E060",
+    "m 	c #E0D050",
+    "n 	c #00277F",
+    "o 	c #00287F",
+    "p 	c #1F3F6F",
+    "q 	c #1048C0",
+    "r 	c #0040B0",
+    "s 	c #204080",
+    "t 	c #FFF890",
+    "u 	c #F0D850",
+    "v 	c #E0C840",
+    "w 	c #807040",
+    "x 	c #A0B06F",
+    "y 	c #204880",
+    "z 	c #2048A0",
+    "A 	c #90A8C0",
+    "B 	c #FFF080",
+    "C 	c #F0D050",
+    "D 	c #C0A830",
+    "E 	c #6F682F",
+    "F 	c #F0F0A0",
+    "G 	c #E0D060",
+    "H 	c #B0A040",
+    "I 	c #D0B840",
+    "J 	c #E0C040",
+    "K 	c #D0B030",
+    "L 	c #706820",
+    "M 	c #5F581F",
+    "N 	c #CFBF3F",
+    "O 	c #FFF0A0",
+    "P 	c #A09830",
+    "Q 	c #A08820",
+    "R 	c #908030",
+    "S 	c #807830",
+    "T 	c #707020",
+    "U 	c #605820",
+    "V 	c #6F672F",
+    "W 	c #D0C040",
+    "X 	c #F0E880",
+    "Y 	c #907820",
+    "Z 	c #B09820",
+    "` 	c #B09010",
+    " .	c #B08820",
+    "..	c #806820",
+    "+.	c #5F5F1F",
+    "@.	c #F0E080",
+    "#.	c #B09020",
+    "$.	c #C0B040",
+    "%.	c #A09030",
+    "&.	c #908020",
+    "*.	c #606020",
+    "=.	c #6F5F1F",
+    "-.	c #9F982F",
+    ";.	c #A0872F",
+    ">.	c #6F681F",
+    ",.	c #706020",
+    "                                ",
+    "          . + + + @ @ # # $ % & ",
+    "          + * = = = = - ; > , ' ",
+    "  ) !     ~ { ] ^ = - - > / ( ' ",
+    "_ : < { [ } | 1 - ; > > / 2 ( 3 ",
+    "{ 4 5 1 6 7 5 8 9 0 a / , b c d ",
+    "e f g h 8 8 g h i j / k l c m d ",
+    "  n o   p q r s t 2 , l c u v w ",
+    "        x y z A B , l u C v D E ",
+    "        @ F > t k G H I J K L M ",
+    "      N @ O / 2 l P Q R S T U V ",
+    "      W m 2 X l I Y Z `  ...+.  ",
+    "      W @.l u I R #.Z Y U M     ",
+    "    $.G I $.%.R &.Y *.& =.      ",
+    "  -.;.>.,.L L ,.& M             ",
+    "                                "
+};
 
 static struct rtgui_listbox_item items[] =
 {
-	{"list #0", RT_NULL},
-	{"list #1", RT_NULL},
-	{"list #2", RT_NULL},
-	{"list #3", RT_NULL},
+    {"list #0", RT_NULL},
+    {"list #1", RT_NULL},
+    {"list #2", RT_NULL},
+    {"list #3", RT_NULL},
 };
 
-static rt_bool_t on_items(struct rtgui_object* object, struct rtgui_event* event)
+static rt_bool_t on_items(struct rtgui_object *object, struct rtgui_event *event)
 {
-	rtgui_listbox_t* box;
-	/* get listbox */
-	box = RTGUI_LISTBOX(object);
+    rtgui_listbox_t *box;
+    /* get listbox */
+    box = RTGUI_LISTBOX(object);
 
-	/* 打印当前的项 */
-	rt_kprintf("current item: %d\n", box->current_item);
+    /* 打印当前的项 */
+    rt_kprintf("current item: %d\n", box->current_item);
 
-	return RT_TRUE;
+    return RT_TRUE;
 }
 
 /* 创建用于演示label控件的视图 */
-rtgui_container_t* demo_view_listbox(void)
+rtgui_container_t *demo_view_listbox(void)
 {
-	rtgui_rect_t rect;
-	rtgui_container_t* container;
-	rtgui_label_t* label;
-	rtgui_listbox_t* box;
+    rtgui_rect_t rect;
+    rtgui_container_t *container;
+    rtgui_label_t *label;
+    rtgui_listbox_t *box;
 
-	/* 先创建一个演示用的视图 */
-	container = demo_view("ListBox Demo");
+    /* 先创建一个演示用的视图 */
+    container = demo_view("ListBox Demo");
 
-	if (item_icon == RT_NULL)
-		item_icon = rtgui_image_create_from_mem("xpm",
-			(const rt_uint8_t*)image_xpm, sizeof(image_xpm), RT_TRUE);
-	items[1].image = item_icon;
+    if (item_icon == RT_NULL)
+        item_icon = rtgui_image_create_from_mem("xpm",
+                                                (const rt_uint8_t *)image_xpm, sizeof(image_xpm), RT_TRUE);
+    items[1].image = item_icon;
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 -= 5;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个label控件 */
-	label = rtgui_label_create("listbox: ");
-	/* 设置label的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	/* container是一个container控件,调用add_child方法添加这个label控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个label控件 */
+    label = rtgui_label_create("listbox: ");
+    /* 设置label的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    /* container是一个container控件,调用add_child方法添加这个label控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
 
-	rect.y1 = rect.y2 + 3;
-	rect.y2 = 250;
-	box = rtgui_listbox_create(items, sizeof(items)/sizeof(struct rtgui_listbox_item), &rect);
-	rtgui_listbox_set_onitem(box, on_items);
-	/* container是一个container控件,调用add_child方法添加这个listbox控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(box));
+    rect.y1 = rect.y2 + 3;
+    rect.y2 = 250;
+    box = rtgui_listbox_create(items, sizeof(items) / sizeof(struct rtgui_listbox_item), &rect);
+    rtgui_listbox_set_onitem(box, on_items);
+    /* container是一个container控件,调用add_child方法添加这个listbox控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(box));
 
-	return container;
+    return container;
 }

+ 224 - 217
examples/gui/demo_view_listctrl.c

@@ -7,251 +7,258 @@
 #include <rtgui/widgets/label.h>
 #include <rtgui/widgets/listctrl.h>
 
-static rtgui_image_t* item_icon = RT_NULL;
-static const char * image_xpm[] = {
-	"16 16 106 2",
-	"  	c None",
-	". 	c #D0C83F",
-	"+ 	c #D0C840",
-	"@ 	c #D0C030",
-	"# 	c #D0B820",
-	"$ 	c #D0B020",
-	"% 	c #D0B01F",
-	"& 	c #5F571F",
-	"* 	c #F0F0C0",
-	"= 	c #FFF8D0",
-	"- 	c #FFF8C0",
-	"; 	c #FFF8B0",
-	"> 	c #FFF8A0",
-	", 	c #F0E870",
-	"' 	c #707030",
-	") 	c #4F87EF",
-	"! 	c #4F78C0",
-	"~ 	c #5088E0",
-	"{ 	c #5078C0",
-	"] 	c #C0D0F0",
-	"^ 	c #FFF8E0",
-	"/ 	c #FFF090",
-	"( 	c #F0E070",
-	"_ 	c #6F97D0",
-	": 	c #C0D8FE",
-	"< 	c #80A8F0",
-	"[ 	c #7088D0",
-	"} 	c #B0D0FF",
-	"| 	c #90B0F0",
-	"1 	c #1040A0",
-	"2 	c #F0F080",
-	"3 	c #707040",
-	"4 	c #7098F0",
-	"5 	c #3068E0",
-	"6 	c #A0B8F0",
-	"7 	c #4070C0",
-	"8 	c #002880",
-	"9 	c #404040",
-	"0 	c #505050",
-	"a 	c #F0F090",
-	"b 	c #F0E860",
-	"c 	c #F0D860",
-	"d 	c #807840",
-	"e 	c #2F5FC0",
-	"f 	c #1050D0",
-	"g 	c #1048B0",
-	"h 	c #002870",
-	"i 	c #C0C080",
-	"j 	c #C0C070",
-	"k 	c #F0F070",
-	"l 	c #F0E060",
-	"m 	c #E0D050",
-	"n 	c #00277F",
-	"o 	c #00287F",
-	"p 	c #1F3F6F",
-	"q 	c #1048C0",
-	"r 	c #0040B0",
-	"s 	c #204080",
-	"t 	c #FFF890",
-	"u 	c #F0D850",
-	"v 	c #E0C840",
-	"w 	c #807040",
-	"x 	c #A0B06F",
-	"y 	c #204880",
-	"z 	c #2048A0",
-	"A 	c #90A8C0",
-	"B 	c #FFF080",
-	"C 	c #F0D050",
-	"D 	c #C0A830",
-	"E 	c #6F682F",
-	"F 	c #F0F0A0",
-	"G 	c #E0D060",
-	"H 	c #B0A040",
-	"I 	c #D0B840",
-	"J 	c #E0C040",
-	"K 	c #D0B030",
-	"L 	c #706820",
-	"M 	c #5F581F",
-	"N 	c #CFBF3F",
-	"O 	c #FFF0A0",
-	"P 	c #A09830",
-	"Q 	c #A08820",
-	"R 	c #908030",
-	"S 	c #807830",
-	"T 	c #707020",
-	"U 	c #605820",
-	"V 	c #6F672F",
-	"W 	c #D0C040",
-	"X 	c #F0E880",
-	"Y 	c #907820",
-	"Z 	c #B09820",
-	"` 	c #B09010",
-	" .	c #B08820",
-	"..	c #806820",
-	"+.	c #5F5F1F",
-	"@.	c #F0E080",
-	"#.	c #B09020",
-	"$.	c #C0B040",
-	"%.	c #A09030",
-	"&.	c #908020",
-	"*.	c #606020",
-	"=.	c #6F5F1F",
-	"-.	c #9F982F",
-	";.	c #A0872F",
-	">.	c #6F681F",
-	",.	c #706020",
-	"                                ",
-	"          . + + + @ @ # # $ % & ",
-	"          + * = = = = - ; > , ' ",
-	"  ) !     ~ { ] ^ = - - > / ( ' ",
-	"_ : < { [ } | 1 - ; > > / 2 ( 3 ",
-	"{ 4 5 1 6 7 5 8 9 0 a / , b c d ",
-	"e f g h 8 8 g h i j / k l c m d ",
-	"  n o   p q r s t 2 , l c u v w ",
-	"        x y z A B , l u C v D E ",
-	"        @ F > t k G H I J K L M ",
-	"      N @ O / 2 l P Q R S T U V ",
-	"      W m 2 X l I Y Z `  ...+.  ",
-	"      W @.l u I R #.Z Y U M     ",
-	"    $.G I $.%.R &.Y *.& =.      ",
-	"  -.;.>.,.L L ,.& M             ",
-	"                                "};
+static rtgui_image_t *item_icon = RT_NULL;
+static const char *image_xpm[] =
+{
+    "16 16 106 2",
+    "  	c None",
+    ". 	c #D0C83F",
+    "+ 	c #D0C840",
+    "@ 	c #D0C030",
+    "# 	c #D0B820",
+    "$ 	c #D0B020",
+    "% 	c #D0B01F",
+    "& 	c #5F571F",
+    "* 	c #F0F0C0",
+    "= 	c #FFF8D0",
+    "- 	c #FFF8C0",
+    "; 	c #FFF8B0",
+    "> 	c #FFF8A0",
+    ", 	c #F0E870",
+    "' 	c #707030",
+    ") 	c #4F87EF",
+    "! 	c #4F78C0",
+    "~ 	c #5088E0",
+    "{ 	c #5078C0",
+    "] 	c #C0D0F0",
+    "^ 	c #FFF8E0",
+    "/ 	c #FFF090",
+    "( 	c #F0E070",
+    "_ 	c #6F97D0",
+    ": 	c #C0D8FE",
+    "< 	c #80A8F0",
+    "[ 	c #7088D0",
+    "} 	c #B0D0FF",
+    "| 	c #90B0F0",
+    "1 	c #1040A0",
+    "2 	c #F0F080",
+    "3 	c #707040",
+    "4 	c #7098F0",
+    "5 	c #3068E0",
+    "6 	c #A0B8F0",
+    "7 	c #4070C0",
+    "8 	c #002880",
+    "9 	c #404040",
+    "0 	c #505050",
+    "a 	c #F0F090",
+    "b 	c #F0E860",
+    "c 	c #F0D860",
+    "d 	c #807840",
+    "e 	c #2F5FC0",
+    "f 	c #1050D0",
+    "g 	c #1048B0",
+    "h 	c #002870",
+    "i 	c #C0C080",
+    "j 	c #C0C070",
+    "k 	c #F0F070",
+    "l 	c #F0E060",
+    "m 	c #E0D050",
+    "n 	c #00277F",
+    "o 	c #00287F",
+    "p 	c #1F3F6F",
+    "q 	c #1048C0",
+    "r 	c #0040B0",
+    "s 	c #204080",
+    "t 	c #FFF890",
+    "u 	c #F0D850",
+    "v 	c #E0C840",
+    "w 	c #807040",
+    "x 	c #A0B06F",
+    "y 	c #204880",
+    "z 	c #2048A0",
+    "A 	c #90A8C0",
+    "B 	c #FFF080",
+    "C 	c #F0D050",
+    "D 	c #C0A830",
+    "E 	c #6F682F",
+    "F 	c #F0F0A0",
+    "G 	c #E0D060",
+    "H 	c #B0A040",
+    "I 	c #D0B840",
+    "J 	c #E0C040",
+    "K 	c #D0B030",
+    "L 	c #706820",
+    "M 	c #5F581F",
+    "N 	c #CFBF3F",
+    "O 	c #FFF0A0",
+    "P 	c #A09830",
+    "Q 	c #A08820",
+    "R 	c #908030",
+    "S 	c #807830",
+    "T 	c #707020",
+    "U 	c #605820",
+    "V 	c #6F672F",
+    "W 	c #D0C040",
+    "X 	c #F0E880",
+    "Y 	c #907820",
+    "Z 	c #B09820",
+    "` 	c #B09010",
+    " .	c #B08820",
+    "..	c #806820",
+    "+.	c #5F5F1F",
+    "@.	c #F0E080",
+    "#.	c #B09020",
+    "$.	c #C0B040",
+    "%.	c #A09030",
+    "&.	c #908020",
+    "*.	c #606020",
+    "=.	c #6F5F1F",
+    "-.	c #9F982F",
+    ";.	c #A0872F",
+    ">.	c #6F681F",
+    ",.	c #706020",
+    "                                ",
+    "          . + + + @ @ # # $ % & ",
+    "          + * = = = = - ; > , ' ",
+    "  ) !     ~ { ] ^ = - - > / ( ' ",
+    "_ : < { [ } | 1 - ; > > / 2 ( 3 ",
+    "{ 4 5 1 6 7 5 8 9 0 a / , b c d ",
+    "e f g h 8 8 g h i j / k l c m d ",
+    "  n o   p q r s t 2 , l c u v w ",
+    "        x y z A B , l u C v D E ",
+    "        @ F > t k G H I J K L M ",
+    "      N @ O / 2 l P Q R S T U V ",
+    "      W m 2 X l I Y Z `  ...+.  ",
+    "      W @.l u I R #.Z Y U M     ",
+    "    $.G I $.%.R &.Y *.& =.      ",
+    "  -.;.>.,.L L ,.& M             ",
+    "                                "
+};
 
 static struct list_item
 {
-	const char* name;
-	const char* gender;
-	int age;
-	rtgui_image_t* image;
+    const char *name;
+    const char *gender;
+    int age;
+    rtgui_image_t *image;
 } items[] =
 {
-	{"index0", "00", 30, RT_NULL},
-	{"index1", "m1", 30, RT_NULL},
-	{"index2", "m2", 30, RT_NULL},
-	{"index3", "m3", 30, RT_NULL},
-	{"index4", "m4", 30, RT_NULL},
-	{"index5", "m5", 30, RT_NULL},
-	{"index6", "m6", 30, RT_NULL},
-	{"index7", "m7", 30, RT_NULL},
-	{"index8", "m8", 30, RT_NULL},
-	{"index9", "m9", 30, RT_NULL},
-	{"index10", "m10", 30, RT_NULL},
-	{"index11", "m11", 30, RT_NULL},
-	{"index12", "m12", 30, RT_NULL},
-	{"index13", "m13", 30, RT_NULL},
-	{"index14", "m14", 30, RT_NULL},
-	{"index15", "m15", 30, RT_NULL},
-	{"index16", "m16", 30, RT_NULL},
-	{"index17", "m17", 30, RT_NULL},
-	{"index18", "m18", 30, RT_NULL},
-	{"index19", "m19", 30, RT_NULL},
+    {"index0", "00", 30, RT_NULL},
+    {"index1", "m1", 30, RT_NULL},
+    {"index2", "m2", 30, RT_NULL},
+    {"index3", "m3", 30, RT_NULL},
+    {"index4", "m4", 30, RT_NULL},
+    {"index5", "m5", 30, RT_NULL},
+    {"index6", "m6", 30, RT_NULL},
+    {"index7", "m7", 30, RT_NULL},
+    {"index8", "m8", 30, RT_NULL},
+    {"index9", "m9", 30, RT_NULL},
+    {"index10", "m10", 30, RT_NULL},
+    {"index11", "m11", 30, RT_NULL},
+    {"index12", "m12", 30, RT_NULL},
+    {"index13", "m13", 30, RT_NULL},
+    {"index14", "m14", 30, RT_NULL},
+    {"index15", "m15", 30, RT_NULL},
+    {"index16", "m16", 30, RT_NULL},
+    {"index17", "m17", 30, RT_NULL},
+    {"index18", "m18", 30, RT_NULL},
+    {"index19", "m19", 30, RT_NULL},
 };
 
 void _rtgui_listctrl_item_draw(struct rtgui_listctrl *list,
-							   struct rtgui_dc* dc,
-							   rtgui_rect_t* rect,
-							   rt_uint16_t index)
+                               struct rtgui_dc *dc,
+                               rtgui_rect_t *rect,
+                               rt_uint16_t index)
 {
-	char age_str[8];
-	rtgui_rect_t item_rect;
-	struct list_item *items, *item;
+    char age_str[8];
+    rtgui_rect_t item_rect;
+    struct list_item *items, *item;
 
-	item_rect = *rect;
-	item_rect.x1 += 5;
-	items = (struct list_item*)list->items;
-	item = &items[index];
+    item_rect = *rect;
+    item_rect.x1 += 5;
+    items = (struct list_item *)list->items;
+    item = &items[index];
 
-	/* draw text */
-	rtgui_dc_draw_text(dc, item->name, &item_rect); item_rect.x1 += 60;
-	rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);
+    /* draw text */
+    rtgui_dc_draw_text(dc, item->name, &item_rect);
+    item_rect.x1 += 60;
+    rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);
 
-	item_rect.x1 += 5;
-	rtgui_dc_draw_text(dc, item->gender, &item_rect); item_rect.x1 += 60;
-	rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);
+    item_rect.x1 += 5;
+    rtgui_dc_draw_text(dc, item->gender, &item_rect);
+    item_rect.x1 += 60;
+    rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);
 
-	item_rect.x1 += 5;
-	rt_snprintf(age_str, sizeof(age_str), "%d", item->age);
-	rtgui_dc_draw_text(dc, age_str, &item_rect); item_rect.x1 += 40;
-	rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);
+    item_rect.x1 += 5;
+    rt_snprintf(age_str, sizeof(age_str), "%d", item->age);
+    rtgui_dc_draw_text(dc, age_str, &item_rect);
+    item_rect.x1 += 40;
+    rtgui_dc_draw_vline(dc, item_rect.x1, item_rect.y1, item_rect.y2);
 
-	item_rect.x1 += 5;
+    item_rect.x1 += 5;
 
-	/* draw image */
-	if (item->image != RT_NULL)
-	{
-		rtgui_rect_t image_rect;
+    /* draw image */
+    if (item->image != RT_NULL)
+    {
+        rtgui_rect_t image_rect;
 
-		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);
-	}
+        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);
+    }
 }
 
-static rt_bool_t on_items(struct rtgui_object* object, struct rtgui_event* event)
+static rt_bool_t on_items(struct rtgui_object *object, struct rtgui_event *event)
 {
-	rtgui_listctrl_t* ctrl;
-	/* get listctrl */
-	ctrl = RTGUI_LISTCTRL(object);
+    rtgui_listctrl_t *ctrl;
+    /* get listctrl */
+    ctrl = RTGUI_LISTCTRL(object);
 
-	/* 打印当前的项 */
-	rt_kprintf("current item: %d\n", ctrl->current_item);
+    /* 打印当前的项 */
+    rt_kprintf("current item: %d\n", ctrl->current_item);
 
-	return RT_TRUE;
+    return RT_TRUE;
 }
 
 /* 创建用于演示label控件的视图 */
-rtgui_container_t* demo_view_listctrl(void)
+rtgui_container_t *demo_view_listctrl(void)
 {
-	rtgui_rect_t rect;
-	rtgui_container_t* container;
-	rtgui_label_t* label;
-	rtgui_listctrl_t* box;
+    rtgui_rect_t rect;
+    rtgui_container_t *container;
+    rtgui_label_t *label;
+    rtgui_listctrl_t *box;
 
-	/* 先创建一个演示用的视图 */
-	container = demo_view("List Control Demo");
+    /* 先创建一个演示用的视图 */
+    container = demo_view("List Control Demo");
 
-	if (item_icon == RT_NULL)
-		item_icon = rtgui_image_create_from_mem("xpm",
-			(const rt_uint8_t*)image_xpm, sizeof(image_xpm), RT_TRUE);
-	items[1].image = item_icon;
+    if (item_icon == RT_NULL)
+        item_icon = rtgui_image_create_from_mem("xpm",
+                                                (const rt_uint8_t *)image_xpm, sizeof(image_xpm), RT_TRUE);
+    items[1].image = item_icon;
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 -= 5;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个label控件 */
-	label = rtgui_label_create("List Control: ");
-	/* 设置label的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	/* container是一个container控件,调用add_child方法添加这个label控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个label控件 */
+    label = rtgui_label_create("List Control: ");
+    /* 设置label的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    /* container是一个container控件,调用add_child方法添加这个label控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
 
-	rect.y1 = rect.y2 + 3;
-	rect.y2 = 250;
-	box = rtgui_listctrl_create((rt_uint32_t)items, sizeof(items)/sizeof(items[0]), &rect,
-		_rtgui_listctrl_item_draw);
-	rtgui_listctrl_set_onitem(box, on_items);
-	/* container是一个container控件,调用add_child方法添加这个listctrl控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(box));
+    rect.y1 = rect.y2 + 3;
+    rect.y2 = 250;
+    box = rtgui_listctrl_create((rt_uint32_t)items, sizeof(items) / sizeof(items[0]), &rect,
+                                _rtgui_listctrl_item_draw);
+    rtgui_listctrl_set_onitem(box, on_items);
+    /* container是一个container控件,调用add_child方法添加这个listctrl控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(box));
 
-	return container;
+    return container;
 }

+ 45 - 43
examples/gui/demo_view_menu.c

@@ -7,68 +7,70 @@
 #include <rtgui/widgets/menu.h>
 #include <rtgui/widgets/button.h>
 
-static rt_bool_t _onmenuitem(struct rtgui_object *object, struct rtgui_event* event)
+static rt_bool_t _onmenuitem(struct rtgui_object *object, struct rtgui_event *event)
 {
-	rt_kprintf("menu action!!\n");
-	return RT_TRUE;
+    rt_kprintf("menu action!!\n");
+    return RT_TRUE;
 }
 
-static const rtgui_menu_item_t sub_items[] = 
+static const rtgui_menu_item_t sub_items[] =
 {
-	{RTGUI_ITEM_NORMAL, "item #1", RT_NULL, RT_NULL, 0, _onmenuitem},
-	{RTGUI_ITEM_NORMAL, "item #2", RT_NULL, RT_NULL, 0, RT_NULL},
-	{RTGUI_ITEM_SEPARATOR, RT_NULL, RT_NULL, RT_NULL, 0, RT_NULL},
-	{RTGUI_ITEM_NORMAL, "item #3", RT_NULL, RT_NULL, 0, RT_NULL},
+    {RTGUI_ITEM_NORMAL, "item #1", RT_NULL, RT_NULL, 0, _onmenuitem},
+    {RTGUI_ITEM_NORMAL, "item #2", RT_NULL, RT_NULL, 0, RT_NULL},
+    {RTGUI_ITEM_SEPARATOR, RT_NULL, RT_NULL, RT_NULL, 0, RT_NULL},
+    {RTGUI_ITEM_NORMAL, "item #3", RT_NULL, RT_NULL, 0, RT_NULL},
 };
 static const rtgui_menu_item_t items[] =
 {
-	{RTGUI_ITEM_NORMAL, "item #1", RT_NULL, RT_NULL, 0, RT_NULL},
-	{RTGUI_ITEM_NORMAL, "item #2", RT_NULL, RT_NULL, 0, RT_NULL},
-	{RTGUI_ITEM_SEPARATOR, RT_NULL, RT_NULL, RT_NULL, 0, RT_NULL},
-	{RTGUI_ITEM_SUBMENU, "item #3", RT_NULL,
-		(struct rtgui_menu_item_t *)sub_items,
-		sizeof(sub_items)/sizeof(sub_items[0]), RT_NULL},
+    {RTGUI_ITEM_NORMAL, "item #1", RT_NULL, RT_NULL, 0, RT_NULL},
+    {RTGUI_ITEM_NORMAL, "item #2", RT_NULL, RT_NULL, 0, RT_NULL},
+    {RTGUI_ITEM_SEPARATOR, RT_NULL, RT_NULL, RT_NULL, 0, RT_NULL},
+    {
+        RTGUI_ITEM_SUBMENU, "item #3", RT_NULL,
+        (struct rtgui_menu_item_t *)sub_items,
+        sizeof(sub_items) / sizeof(sub_items[0]), RT_NULL
+    },
 };
-static rtgui_menu_t* menu;
+static rtgui_menu_t *menu;
 
-static rt_bool_t _onmenu(struct rtgui_object* object, struct rtgui_event* event)
+static rt_bool_t _onmenu(struct rtgui_object *object, struct rtgui_event *event)
 {
-	rtgui_rect_t rect;
+    rtgui_rect_t rect;
 
-	rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
-	rtgui_widget_rect_to_device(RTGUI_WIDGET(object), &rect);
+    rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
+    rtgui_widget_rect_to_device(RTGUI_WIDGET(object), &rect);
 
-	if (menu != RT_NULL)
-		rtgui_menu_pop(menu, rect.x1, rect.y2 + 5);
+    if (menu != RT_NULL)
+        rtgui_menu_pop(menu, rect.x1, rect.y2 + 5);
 
-	return RT_TRUE;
+    return RT_TRUE;
 }
 
 /* 创建用于演示menu控件的视图 */
-rtgui_container_t* demo_view_menu(void)
+rtgui_container_t *demo_view_menu(void)
 {
-	rtgui_rect_t rect;
-	rtgui_container_t* container;
-	rtgui_button_t* button;
+    rtgui_rect_t rect;
+    rtgui_container_t *container;
+    rtgui_button_t *button;
 
-	/* 先创建一个演示用的视图 */
-	container = demo_view("MENU View");
+    /* 先创建一个演示用的视图 */
+    container = demo_view("MENU View");
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个button控件 */
-	button = rtgui_button_create("Pop Menu");
-	/* 设置button的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
-	/* container是一个container控件,调用add_child方法添加这个button控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(button));
-	rtgui_button_set_onbutton(button, _onmenu);
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个button控件 */
+    button = rtgui_button_create("Pop Menu");
+    /* 设置button的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
+    /* container是一个container控件,调用add_child方法添加这个button控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(button));
+    rtgui_button_set_onbutton(button, _onmenu);
 
-	menu = rtgui_menu_create("Menu Test", RT_NULL, items, sizeof(items)/sizeof(items[0]));
+    menu = rtgui_menu_create("Menu Test", RT_NULL, items, sizeof(items) / sizeof(items[0]));
 
-	return container;
+    return container;
 }

+ 46 - 45
examples/gui/demo_view_module.c

@@ -1,7 +1,7 @@
 /*
- * 程序清单:DC上显示图像演示
+ * 3ìDò??μ¥£oDCé???ê?í????Yê?
  *
- * 这个例子会在创建出的view上显示图像
+ * ?a??ày×ó?á?ú′′?¨3?μ?viewé???ê?í???
  */
 
 #include "demo_view.h"
@@ -11,66 +11,67 @@
 
 #ifdef RT_USING_MODULE
 #if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
-static rtgui_container_t* _view = RT_NULL;
+static rtgui_container_t *_view = RT_NULL;
 
-/* 打开按钮的回调函数 */
-static void open_btn_onbutton(rtgui_widget_t* widget, struct rtgui_event* event)
+/* ′ò?a°′?¥μ???μ÷oˉêy */
+static void open_btn_onbutton(rtgui_widget_t *widget, struct rtgui_event *event)
 {
-	rtgui_filelist_view_t *view;
-	rtgui_workbench_t *workbench;
-	rtgui_rect_t rect;
+    rtgui_filelist_view_t *view;
+    rtgui_workbench_t *workbench;
+    rtgui_rect_t rect;
 
-	/* 获得顶层的workbench */
-	workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
-	rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
+    /* ??μ??¥2?μ?workbench */
+    workbench = RTGUI_WORKBENCH(rtgui_widget_get_toplevel(widget));
+    rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
 
-	/* WIN32平台上和真实设备上的初始路径处理 */
+    /* WIN32??ì¨é?oí??êμéè±?é?μ?3?ê??·??′|àí */
 #ifdef _WIN32
-	view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect);
+    view = rtgui_filelist_view_create(workbench, "d:\\", "*.*", &rect);
 #else
-	view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
+    view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
 #endif
-	/* 模态显示一个文件列表视图,以提供给用户选择图像文件 */
-	if (rtgui_container_show(RTGUI_CONTAINER(view), RT_TRUE) == RTGUI_MODAL_OK)
-	{
-		char path[32], name[8];
+    /* ?£ì???ê?ò??????táD±íêóí?£?ò?ìá1???ó??§????í??????t */
+    if (rtgui_container_show(RTGUI_CONTAINER(view), RT_TRUE) == RTGUI_MODAL_OK)
+    {
+        char path[32], name[8];
 
-		/* 设置文件路径的标签 */
-		rtgui_filelist_view_get_fullpath(view, path, sizeof(path));
+        /* éè?????t?·??μ?±ê?? */
+        rtgui_filelist_view_get_fullpath(view, path, sizeof(path));
 
-		rt_memset(name, 0, sizeof(name));
+        rt_memset(name, 0, sizeof(name));
 
-		/* 获得应用模块的类型 */
-		if (rt_strstr(path, ".mo") != RT_NULL || rt_strstr(path, ".so") != RT_NULL)
-		{
-			rt_module_open(path);
-		}	
-	}
+        /* ??μ?ó|ó??£?éμ?ààDí */
+        if (rt_strstr(path, ".mo") != RT_NULL || rt_strstr(path, ".so") != RT_NULL)
+        {
+            rt_module_open(path);
+        }
+    }
 
-	/* 删除 文件列表 视图 */
-	rtgui_container_destroy(RTGUI_CONTAINER(view));
-	rtgui_container_show(_view, RT_FALSE);
+    /* é?3y ???táD±í êóí? */
+    rtgui_container_destroy(RTGUI_CONTAINER(view));
+    rtgui_container_show(_view, RT_FALSE);
 }
 
-/* 创建用于显示应用模块的演示视图 */
-rtgui_container_t* demo_view_module(rtgui_workbench_t* workbench)
+/* ′′?¨ó?óú??ê?ó|ó??£?éμ??Yê?êóí? */
+rtgui_container_t *demo_view_module(rtgui_workbench_t *workbench)
 {
-	rtgui_rect_t rect;
-	rtgui_button_t* open_btn;
+    rtgui_rect_t rect;
+    rtgui_button_t *open_btn;
 
-	/* 先创建一个演示视图 */
-	_view = demo_view(workbench, "应用模块演示");
+    /* ?è′′?¨ò????Yê?êóí? */
+    _view = demo_view(workbench, "ó|ó??£?é?Yê?");
 
-	/* 添加一个按钮 */
-	demo_view_get_rect(_view, &rect);
-	rect.x1 += 5; rect.x2 = rect.x1 + 120;
-	rect.y2 = rect.y1 + 20;
-	open_btn = rtgui_button_create("打开应用模块");
-	rtgui_container_add_child(RTGUI_CONTAINER(_view), RTGUI_WIDGET(open_btn));
-	rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
-	rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
+    /* ìí?óò???°′?¥ */
+    demo_view_get_rect(_view, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 120;
+    rect.y2 = rect.y1 + 20;
+    open_btn = rtgui_button_create("′ò?aó|ó??£?é");
+    rtgui_container_add_child(RTGUI_CONTAINER(_view), RTGUI_WIDGET(open_btn));
+    rtgui_widget_set_rect(RTGUI_WIDGET(open_btn), &rect);
+    rtgui_button_set_onbutton(open_btn, open_btn_onbutton);
 
-	return _view;
+    return _view;
 }
 #endif
 #endif

+ 26 - 26
examples/gui/demo_view_mywidget.c

@@ -9,34 +9,34 @@
 /* 创建用于演示自定义控件的视图 */
 rtgui_container_t *demo_view_mywidget(void)
 {
-	rtgui_container_t *container;
-	rtgui_rect_t rect;
-	rtgui_mywidget_t *mywidget;
+    rtgui_container_t *container;
+    rtgui_rect_t rect;
+    rtgui_mywidget_t *mywidget;
 
-	/* 先创建一个演示用的视图 */
-	container = demo_view("MyWidget View");
+    /* 先创建一个演示用的视图 */
+    container = demo_view("MyWidget View");
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.y1 + 80;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 80;
-	/* 创建一个自定义控件 */
-	mywidget = rtgui_mywidget_create(&rect);
-	/* container是一个container控件,调用add_child方法添加这个自控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(mywidget));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.y1 + 80;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 80;
+    /* 创建一个自定义控件 */
+    mywidget = rtgui_mywidget_create(&rect);
+    /* container是一个container控件,调用add_child方法添加这个自控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(mywidget));
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 25;
-	rect.x2 = rect.y1 + 40;
-	rect.y1 += 5 + 100;
-	rect.y2 = rect.y1 + 40;
-	/* 创建一个自定义控件 */
-	mywidget = rtgui_mywidget_create(&rect);
-	/* container是一个container控件,调用add_child方法添加这个自控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(mywidget));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 25;
+    rect.x2 = rect.y1 + 40;
+    rect.y1 += 5 + 100;
+    rect.y2 = rect.y1 + 40;
+    /* 创建一个自定义控件 */
+    mywidget = rtgui_mywidget_create(&rect);
+    /* container是一个container控件,调用add_child方法添加这个自控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(mywidget));
 
-	return container;
+    return container;
 }

+ 26 - 26
examples/gui/demo_view_notebook.c

@@ -10,44 +10,44 @@
 
 const static struct rtgui_listbox_item items[] =
 {
-	{"list #0", RT_NULL},
-	{"list #1", RT_NULL},
-	{"list #2", RT_NULL},
-	{"list #3", RT_NULL},
+    {"list #0", RT_NULL},
+    {"list #1", RT_NULL},
+    {"list #2", RT_NULL},
+    {"list #3", RT_NULL},
 };
 
 const static struct rtgui_listbox_item items2[] =
 {
-	{"list #0", RT_NULL},
-	{"list #1", RT_NULL},
-	{"list #2", RT_NULL},
-	{"new list #1", RT_NULL},
-	{"new list #2", RT_NULL},
+    {"list #0", RT_NULL},
+    {"list #1", RT_NULL},
+    {"list #2", RT_NULL},
+    {"new list #1", RT_NULL},
+    {"new list #2", RT_NULL},
 };
 
 /* 创建用于演示notebook控件的视图 */
-rtgui_container_t* demo_view_notebook(void)
+rtgui_container_t *demo_view_notebook(void)
 {
-	rtgui_rect_t rect;
-	rtgui_container_t* container;
-	struct rtgui_notebook *notebook;
-	rtgui_listbox_t* box;
+    rtgui_rect_t rect;
+    rtgui_container_t *container;
+    struct rtgui_notebook *notebook;
+    rtgui_listbox_t *box;
 
-	/* 先创建一个演示用的视图 */
-	container = demo_view("Notebook View");
+    /* 先创建一个演示用的视图 */
+    container = demo_view("Notebook View");
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
 
-	notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_BOTTOM);
-	/* container是一个container控件,调用add_child方法添加这个notebook控件 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(notebook));
+    notebook = rtgui_notebook_create(&rect, RTGUI_NOTEBOOK_BOTTOM);
+    /* container是一个container控件,调用add_child方法添加这个notebook控件 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(notebook));
 
-	box = rtgui_listbox_create(items, sizeof(items)/sizeof(struct rtgui_listbox_item), &rect);
-	rtgui_notebook_add(notebook, "Tab 1", RTGUI_WIDGET(box));
+    box = rtgui_listbox_create(items, sizeof(items) / sizeof(struct rtgui_listbox_item), &rect);
+    rtgui_notebook_add(notebook, "Tab 1", RTGUI_WIDGET(box));
 
-	box = rtgui_listbox_create(items2, sizeof(items2)/sizeof(struct rtgui_listbox_item), &rect);
-	rtgui_notebook_add(notebook, "Tab 2", RTGUI_WIDGET(box));
+    box = rtgui_listbox_create(items2, sizeof(items2) / sizeof(struct rtgui_listbox_item), &rect);
+    rtgui_notebook_add(notebook, "Tab 2", RTGUI_WIDGET(box));
 
-	return container;
+    return container;
 }

+ 53 - 46
examples/gui/demo_view_progressbar.c

@@ -3,74 +3,81 @@
 #include <rtgui/widgets/label.h>
 #include <rtgui/widgets/progressbar.h>
 
-static rtgui_progressbar_t* hbar;
-static rtgui_progressbar_t* vbar;
+static rtgui_progressbar_t *hbar;
+static rtgui_progressbar_t *vbar;
 static rtgui_timer_t *bar_timer = RT_NULL;
 
-void progressbar_timeout(struct rtgui_timer* timer, void* parameter)
+void progressbar_timeout(struct rtgui_timer *timer, void *parameter)
 {
-	static rt_uint32_t value = 0;
+    static rt_uint32_t value = 0;
 
-	value++;
-	if (value == 100)
-		value = 0;
+    value++;
+    if (value == 100)
+        value = 0;
 
-	rtgui_progressbar_set_value(hbar, value);
-	rtgui_progressbar_set_value(vbar, value);
+    rtgui_progressbar_set_value(hbar, value);
+    rtgui_progressbar_set_value(vbar, value);
 }
 
 static rt_bool_t start_timer(struct rtgui_object *object, struct rtgui_event *event)
 {
-	if (bar_timer != RT_NULL)
-		rtgui_timer_start(bar_timer);
-	return RT_TRUE;
+    if (bar_timer != RT_NULL)
+        rtgui_timer_start(bar_timer);
+    return RT_TRUE;
 }
 
 static rt_bool_t stop_timer(struct rtgui_object *object, struct rtgui_event *event)
 {
-	if (bar_timer != RT_NULL)
-		rtgui_timer_stop(bar_timer);
-	return RT_TRUE;
+    if (bar_timer != RT_NULL)
+        rtgui_timer_stop(bar_timer);
+    return RT_TRUE;
 }
 
 rtgui_container_t *demo_view_progressbar(void)
 {
-	rtgui_container_t *container;
-	rtgui_rect_t rect;
-	rtgui_label_t *label;
+    rtgui_container_t *container;
+    rtgui_rect_t rect;
+    rtgui_label_t *label;
 
-	/* create a demo container */
-	container = demo_view("ProgressBar View");
+    /* create a demo container */
+    container = demo_view("ProgressBar View");
 
-	/* get demo container rect */
-	demo_view_get_rect(container, &rect);
-	label = rtgui_label_create("ˮƽ½ø¶ÈÌõ:");
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
-	rect.x1 += 5; rect.x2 -= 5;
-	rect.y1 += 5; rect.y2 = rect.y1 + 18;
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	rect.y1 += 20; rect.y2 = rect.y1 + 18;
-	hbar = rtgui_progressbar_create(RTGUI_HORIZONTAL, 100, &rect);
-	rtgui_container_add_child(container, RTGUI_WIDGET(hbar));
+    /* get demo container rect */
+    demo_view_get_rect(container, &rect);
+    label = rtgui_label_create("ˮƽ½ø¶ÈÌõ:");
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 18;
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    rect.y1 += 20;
+    rect.y2 = rect.y1 + 18;
+    hbar = rtgui_progressbar_create(RTGUI_HORIZONTAL, 100, &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(hbar));
 
-	/* get demo container rect */
-	demo_view_get_rect(container, &rect);
-	label = rtgui_label_create("´¹Ö±½ø¶ÈÌõ:");
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
-	rect.x1 += 5; rect.x2 -= 5;
-	rect.y1 += 45; rect.y2 = rect.y1 + 18;
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	rect.x1 += 110; rect.x2 = rect.x1 + 20;
-	rect.y1 += 18 + 5; rect.y2 = rect.y1 + 150;
-	vbar = rtgui_progressbar_create(RTGUI_VERTICAL, 100, &rect);
-	rtgui_container_add_child(container, RTGUI_WIDGET(vbar));
+    /* get demo container rect */
+    demo_view_get_rect(container, &rect);
+    label = rtgui_label_create("´¹Ö±½ø¶ÈÌõ:");
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 45;
+    rect.y2 = rect.y1 + 18;
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    rect.x1 += 110;
+    rect.x2 = rect.x1 + 20;
+    rect.y1 += 18 + 5;
+    rect.y2 = rect.y1 + 150;
+    vbar = rtgui_progressbar_create(RTGUI_VERTICAL, 100, &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(vbar));
 
-	bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC,
-										progressbar_timeout, RT_NULL);
+    bar_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC,
+                                   progressbar_timeout, RT_NULL);
 
-	rtgui_widget_set_onshow(RTGUI_WIDGET(container), start_timer);
-	rtgui_widget_set_onhide(RTGUI_WIDGET(container), stop_timer);
+    rtgui_widget_set_onshow(RTGUI_WIDGET(container), start_timer);
+    rtgui_widget_set_onhide(RTGUI_WIDGET(container), stop_timer);
 
-	return container;
+    return container;
 }
 

+ 47 - 47
examples/gui/demo_view_radiobox.c

@@ -8,62 +8,62 @@
 #include <rtgui/widgets/radiobox.h>
 
 /* 用于显示垂直方向的radio文本项数组 */
-static char* radio_item_v[5] =
-	{
-		"one",
-		"two",
-		"three",
-		"item 1",
-		"item 2"
-	};
+static char *radio_item_v[5] =
+{
+    "one",
+    "two",
+    "three",
+    "item 1",
+    "item 2"
+};
 
 /* 用于显示水平方向的radio文本项数组 */
-static char* radio_item_h[3] =
-	{
-		"one", "two", "three"
-	};
+static char *radio_item_h[3] =
+{
+    "one", "two", "three"
+};
 
 /* 创建用于演示radiobox控件的视图 */
-rtgui_container_t* demo_view_radiobox(void)
+rtgui_container_t *demo_view_radiobox(void)
 {
-	rtgui_rect_t rect;
-	rtgui_container_t* container;
-	rtgui_radiobox_t* radiobox;
+    rtgui_rect_t rect;
+    rtgui_container_t *container;
+    rtgui_radiobox_t *radiobox;
 
-	/* 先创建一个演示用的视图 */
-	container = demo_view("RadioBox View");
+    /* 先创建一个演示用的视图 */
+    container = demo_view("RadioBox View");
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 -= 5;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 5 * 25;
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 5 * 25;
 
-	/* 创建一个垂直方向显示的radiobox控件,文本项是radio_item_v数组,共5个项 */
-	radiobox = rtgui_radiobox_create("Radio Box", RTGUI_VERTICAL, radio_item_v, 5);
-	/* 设置当前选择的数组是第0项 */
-	rtgui_radiobox_set_selection(radiobox, 0);
-	/* 添加radiobox控件到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(radiobox));
-	/* 设置radiobox控件的位置信息 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
+    /* 创建一个垂直方向显示的radiobox控件,文本项是radio_item_v数组,共5个项 */
+    radiobox = rtgui_radiobox_create("Radio Box", RTGUI_VERTICAL, radio_item_v, 5);
+    /* 设置当前选择的数组是第0项 */
+    rtgui_radiobox_set_selection(radiobox, 0);
+    /* 添加radiobox控件到视图中 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(radiobox));
+    /* 设置radiobox控件的位置信息 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 -= 5;
-	rect.y1 += 5 + 5 * 25;
-	rect.y2 = rect.y1 + 60;
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5 + 5 * 25;
+    rect.y2 = rect.y1 + 60;
 
-	/* 创建一个水平方向显示的radiobox控件,文本项是radio_item_h数组,共3个项 */
-	radiobox = rtgui_radiobox_create("Radio Box", RTGUI_HORIZONTAL, radio_item_h, 3);
-	/* 设置当前选择的数组是第0项 */
-	rtgui_radiobox_set_selection(radiobox, 0);
-	/* 添加radiobox控件到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(radiobox));
-	/* 设置radiobox控件的位置信息 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
+    /* 创建一个水平方向显示的radiobox控件,文本项是radio_item_h数组,共3个项 */
+    radiobox = rtgui_radiobox_create("Radio Box", RTGUI_HORIZONTAL, radio_item_h, 3);
+    /* 设置当前选择的数组是第0项 */
+    rtgui_radiobox_set_selection(radiobox, 0);
+    /* 添加radiobox控件到视图中 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(radiobox));
+    /* 设置radiobox控件的位置信息 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
 
-	return container;
+    return container;
 }

+ 38 - 31
examples/gui/demo_view_scrollbar.c

@@ -5,39 +5,46 @@
 
 rtgui_container_t *demo_view_scrollbar(void)
 {
-	rtgui_container_t *container;
-	rtgui_rect_t rect;
-	rtgui_label_t *label;
-	rtgui_scrollbar_t* hbar;
-	rtgui_scrollbar_t* vbar;
+    rtgui_container_t *container;
+    rtgui_rect_t rect;
+    rtgui_label_t *label;
+    rtgui_scrollbar_t *hbar;
+    rtgui_scrollbar_t *vbar;
 
-	/* create a demo container */
-	container = demo_view("ScrollBar View");
+    /* create a demo container */
+    container = demo_view("ScrollBar View");
 
-	/* get demo container rect */
-	demo_view_get_rect(container, &rect);
-	label = rtgui_label_create("horizontal bar:");
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
-	rect.x1 += 5; rect.x2 -= 5;
-	rect.y1 += 5; rect.y2 = rect.y1 + 18;
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	rect.y1 += 20; rect.y2 = rect.y1 + 18;
-	hbar = rtgui_scrollbar_create(RTGUI_HORIZONTAL, &rect);
-	rtgui_container_add_child(container, RTGUI_WIDGET(hbar));
+    /* get demo container rect */
+    demo_view_get_rect(container, &rect);
+    label = rtgui_label_create("horizontal bar:");
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 18;
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    rect.y1 += 20;
+    rect.y2 = rect.y1 + 18;
+    hbar = rtgui_scrollbar_create(RTGUI_HORIZONTAL, &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(hbar));
 
-	/* get demo container rect */
-	demo_view_get_rect(container, &rect);
-	label = rtgui_label_create("vertical bar:");
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
-	rect.x1 += 5; rect.x2 -= 5;
-	rect.y1 += 45; rect.y2 = rect.y1 + 18;
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	rect.x1 += 110; rect.x2 = rect.x1 + 20;
-	rect.y1 += 18 + 5; rect.y2 = rect.y1 + 150;
-	vbar = rtgui_scrollbar_create(RTGUI_VERTICAL, &rect);
-	rtgui_container_add_child(container, RTGUI_WIDGET(vbar));
-	rtgui_scrollbar_set_line_step(vbar, 1);
-	// RTGUI_WIDGET_DISABLE(RTGUI_WIDGET(vbar));
+    /* get demo container rect */
+    demo_view_get_rect(container, &rect);
+    label = rtgui_label_create("vertical bar:");
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 45;
+    rect.y2 = rect.y1 + 18;
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    rect.x1 += 110;
+    rect.x2 = rect.x1 + 20;
+    rect.y1 += 18 + 5;
+    rect.y2 = rect.y1 + 150;
+    vbar = rtgui_scrollbar_create(RTGUI_VERTICAL, &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(vbar));
+    rtgui_scrollbar_set_line_step(vbar, 1);
+    // RTGUI_WIDGET_DISABLE(vbar);
 
-	return container;
+    return container;
 }

+ 37 - 30
examples/gui/demo_view_slider.c

@@ -5,38 +5,45 @@
 
 rtgui_container_t *demo_view_slider(void)
 {
-	rtgui_container_t *container;
-	rtgui_rect_t rect;
-	rtgui_label_t *label;
-	rtgui_slider_t *slider;
+    rtgui_container_t *container;
+    rtgui_rect_t rect;
+    rtgui_label_t *label;
+    rtgui_slider_t *slider;
 
-	/* create a demo container */
-	container = demo_view("Slider View");
+    /* create a demo container */
+    container = demo_view("Slider View");
 
-	/* get demo container rect */
-	demo_view_get_rect(container, &rect);
-	label = rtgui_label_create("horizontal slider:");
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
-	rect.x1 += 5; rect.x2 -= 5;
-	rect.y1 += 5; rect.y2 = rect.y1 + 18;
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	rect.y1 += 20; rect.y2 = rect.y1 + 18;
-	slider = rtgui_slider_create(0, 100, RTGUI_HORIZONTAL);
-	rtgui_container_add_child(container, RTGUI_WIDGET(slider));
-	rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect);
+    /* get demo container rect */
+    demo_view_get_rect(container, &rect);
+    label = rtgui_label_create("horizontal slider:");
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 18;
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    rect.y1 += 20;
+    rect.y2 = rect.y1 + 18;
+    slider = rtgui_slider_create(0, 100, RTGUI_HORIZONTAL);
+    rtgui_container_add_child(container, RTGUI_WIDGET(slider));
+    rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect);
 
-	/* get demo container rect */
-	demo_view_get_rect(container, &rect);
-	label = rtgui_label_create("vertical slider:");
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
-	rect.x1 += 5; rect.x2 -= 5;
-	rect.y1 += 50; rect.y2 = rect.y1 + 18;
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	rect.x1 += 110; rect.x2 = rect.x1 + 20;
-	rect.y1 += 18 + 5; rect.y2 = rect.y1 + 150;
-	slider = rtgui_slider_create(0, 100, RTGUI_VERTICAL);
-	rtgui_container_add_child(container, RTGUI_WIDGET(slider));
-	rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect);
+    /* get demo container rect */
+    demo_view_get_rect(container, &rect);
+    label = rtgui_label_create("vertical slider:");
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 50;
+    rect.y2 = rect.y1 + 18;
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    rect.x1 += 110;
+    rect.x2 = rect.x1 + 20;
+    rect.y1 += 18 + 5;
+    rect.y2 = rect.y1 + 150;
+    slider = rtgui_slider_create(0, 100, RTGUI_VERTICAL);
+    rtgui_container_add_child(container, RTGUI_WIDGET(slider));
+    rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect);
 
-	return container;
+    return container;
 }

+ 83 - 83
examples/gui/demo_view_textbox.c

@@ -8,95 +8,95 @@
 #include <rtgui/widgets/textbox.h>
 
 /* 创建用于演示textbox控件的视图 */
-rtgui_container_t* demo_view_textbox(void)
+rtgui_container_t *demo_view_textbox(void)
 {
-	rtgui_rect_t rect, textbox_rect;
-	rtgui_container_t* container;
-	rtgui_label_t* label;
-	rtgui_textbox_t* text;
+    rtgui_rect_t rect, textbox_rect;
+    rtgui_container_t *container;
+    rtgui_label_t *label;
+    rtgui_textbox_t *text;
 
-	/* 先创建一个演示用的视图 */
-	container = demo_view("TextBox View");
+    /* 先创建一个演示用的视图 */
+    container = demo_view("TextBox View");
 
-	/* 获得视图的位置信息 */
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 30;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个label控件 */
-	label = rtgui_label_create("名字: ");
-	/* 设置label的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    /* 获得视图的位置信息 */
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 30;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个label控件 */
+    label = rtgui_label_create("名字: ");
+    /* 设置label的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
 
-	/* 让textbox_rect赋值到rect,以计算textbox控件的位置 */
-	textbox_rect = rect;
-	textbox_rect.x1 = textbox_rect.x2 + 5;
-	textbox_rect.x2 = textbox_rect.x1 + 160;
-	/* 创建一个textbox控件 */
-	text = rtgui_textbox_create("bernard",RTGUI_TEXTBOX_SINGLE);
-	/* 设置textbox控件的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
-	/* 添加textbox控件到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(text));
+    /* 让textbox_rect赋值到rect,以计算textbox控件的位置 */
+    textbox_rect = rect;
+    textbox_rect.x1 = textbox_rect.x2 + 5;
+    textbox_rect.x2 = textbox_rect.x1 + 160;
+    /* 创建一个textbox控件 */
+    text = rtgui_textbox_create("bernard", RTGUI_TEXTBOX_SINGLE);
+    /* 设置textbox控件的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
+    /* 添加textbox控件到视图中 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(text));
 
-	/* 计算下一个label控件的位置 */
-	rect.y1 += 23;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个label控件 */
-	label = rtgui_label_create("邮件: ");
-	/* 设置label的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	/* 添加label控件到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
-	textbox_rect = rect;
-	textbox_rect.x1 = textbox_rect.x2 + 5;
-	textbox_rect.x2 = textbox_rect.x1 + 160;
-	/* 创建一个textbox控件 */
-	text = rtgui_textbox_create("bernard.xiong@gmail.com",RTGUI_TEXTBOX_SINGLE);
-	/* 设置textbox控件的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
-	/* 添加textbox控件到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(text));
+    /* 计算下一个label控件的位置 */
+    rect.y1 += 23;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个label控件 */
+    label = rtgui_label_create("邮件: ");
+    /* 设置label的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    /* 添加label控件到视图中 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    textbox_rect = rect;
+    textbox_rect.x1 = textbox_rect.x2 + 5;
+    textbox_rect.x2 = textbox_rect.x1 + 160;
+    /* 创建一个textbox控件 */
+    text = rtgui_textbox_create("bernard.xiong@gmail.com", RTGUI_TEXTBOX_SINGLE);
+    /* 设置textbox控件的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
+    /* 添加textbox控件到视图中 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(text));
 
-	rect.y1 += 23;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个label控件 */
-	label = rtgui_label_create("密码: ");
-	/* 设置label的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	/* 添加label控件到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
-	textbox_rect = rect;
-	textbox_rect.x1 = textbox_rect.x2 + 5;
-	textbox_rect.x2 = textbox_rect.x1 + 160;
-	/* 创建一个textbox控件 */
-	text = rtgui_textbox_create("rt-thread",RTGUI_TEXTBOX_SINGLE);
-	/* 设置textbox显示文本为掩码形式(即显示为*号,适合于显示密码的情况) */
-	text->flag |= RTGUI_TEXTBOX_MASK;
-	/* 设置textbox控件的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
-	/* 添加textbox控件到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(text));
+    rect.y1 += 23;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个label控件 */
+    label = rtgui_label_create("密码: ");
+    /* 设置label的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    /* 添加label控件到视图中 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    textbox_rect = rect;
+    textbox_rect.x1 = textbox_rect.x2 + 5;
+    textbox_rect.x2 = textbox_rect.x1 + 160;
+    /* 创建一个textbox控件 */
+    text = rtgui_textbox_create("rt-thread", RTGUI_TEXTBOX_SINGLE);
+    /* 设置textbox显示文本为掩码形式(即显示为*号,适合于显示密码的情况) */
+    text->flag |= RTGUI_TEXTBOX_MASK;
+    /* 设置textbox控件的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
+    /* 添加textbox控件到视图中 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(text));
 
-	rect.y1 += 23;
-	rect.y2 = rect.y1 + 20;
-	/* 创建一个label控件 */
-	label = rtgui_label_create("主页: ");
-	/* 设置label的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	/* 添加label控件到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(label));
-	textbox_rect = rect;
-	textbox_rect.x1 = textbox_rect.x2 + 5;
-	textbox_rect.x2 = textbox_rect.x1 + 160;
-	/* 创建一个textbox控件 */
-	text = rtgui_textbox_create("http://www.rt-thread.org",RTGUI_TEXTBOX_SINGLE);
-	/* 设置textbox控件的位置 */
-	rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
-	/* 添加textbox控件到视图中 */
-	rtgui_container_add_child(container, RTGUI_WIDGET(text));
+    rect.y1 += 23;
+    rect.y2 = rect.y1 + 20;
+    /* 创建一个label控件 */
+    label = rtgui_label_create("主页: ");
+    /* 设置label的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    /* 添加label控件到视图中 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(label));
+    textbox_rect = rect;
+    textbox_rect.x1 = textbox_rect.x2 + 5;
+    textbox_rect.x2 = textbox_rect.x1 + 160;
+    /* 创建一个textbox控件 */
+    text = rtgui_textbox_create("http://www.rt-thread.org", RTGUI_TEXTBOX_SINGLE);
+    /* 设置textbox控件的位置 */
+    rtgui_widget_set_rect(RTGUI_WIDGET(text), &textbox_rect);
+    /* 添加textbox控件到视图中 */
+    rtgui_container_add_child(container, RTGUI_WIDGET(text));
 
-	return container;
+    return container;
 }

+ 73 - 73
examples/gui/demo_view_ttf.c

@@ -15,84 +15,84 @@ static rtgui_font_t *font_16, *font_24, *font_36, *font_48;
 /*
  * container的事件处理函数
  */
-rt_bool_t ttf_event_handler(struct rtgui_object* object, rtgui_event_t *event)
+rt_bool_t ttf_event_handler(struct rtgui_object *object, rtgui_event_t *event)
 {
-	struct rtgui_widget *widget = RTGUI_WIDGET(object);
-
-	/* 仅对PAINT事件进行处理 */
-	if (event->type == RTGUI_EVENT_PAINT)
-	{
-		struct rtgui_dc* dc;
-		rtgui_rect_t rect;
-		rtgui_font_t* saved;
-
-		/*
-		 * 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container
-		 * 先绘图
-		 */
-		rtgui_container_event_handler(widget, event);
-
-		/************************************************************************/
-		/* 下面的是DC的操作                                                     */
-		/************************************************************************/
-
-		/* 获得控件所属的DC */
-		dc = rtgui_dc_begin_drawing(widget);
-		/* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
-		if (dc == RT_NULL)
-			return RT_FALSE;
-
-		/* 获得demo container允许绘图的区域 */
-		demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
-
-		saved = RTGUI_WIDGET_FONT(widget);
-
-		RTGUI_WIDGET_FONT(widget) = font_16;
-		rtgui_dc_draw_text(dc, "ABCD中文", &rect);
-		rect.y1 += 18; 
-
-		RTGUI_WIDGET_FONT(widget) = font_24;
-		rtgui_dc_draw_text(dc, "ABCD中文", &rect);
-		rect.y1 += 26; 
-
-		RTGUI_WIDGET_FONT(widget) = font_36;
-		rtgui_dc_draw_text(dc, "ABCD中文", &rect);
-		rect.y1 += 38; 
-
-		RTGUI_WIDGET_FONT(widget) = font_48;
-		rtgui_dc_draw_text(dc, "ABCD中文", &rect);
-
-		RTGUI_WIDGET_FONT(widget) = saved;
-		/* 绘图完成 */
-		rtgui_dc_end_drawing(dc);
-	}
-	else
-	{
-		/* 其他事件,调用默认的事件处理函数 */
-		return rtgui_container_event_handler(widget, event);
-	}
-
-	return RT_FALSE;
+    struct rtgui_widget *widget = RTGUI_WIDGET(object);
+
+    /* 仅对PAINT事件进行处理 */
+    if (event->type == RTGUI_EVENT_PAINT)
+    {
+        struct rtgui_dc *dc;
+        rtgui_rect_t rect;
+        rtgui_font_t *saved;
+
+        /*
+         * 因为用的是demo container,上面本身有一部分控件,所以在绘图时先要让demo container
+         * 先绘图
+         */
+        rtgui_container_event_handler(widget, event);
+
+        /************************************************************************/
+        /* 下面的是DC的操作                                                     */
+        /************************************************************************/
+
+        /* 获得控件所属的DC */
+        dc = rtgui_dc_begin_drawing(widget);
+        /* 如果不能正常获得DC,返回(如果控件或父控件是隐藏状态,DC是获取不成功的) */
+        if (dc == RT_NULL)
+            return RT_FALSE;
+
+        /* 获得demo container允许绘图的区域 */
+        demo_view_get_rect(RTGUI_CONTAINER(widget), &rect);
+
+        saved = RTGUI_WIDGET_FONT(widget);
+
+        RTGUI_WIDGET_FONT(widget) = font_16;
+        rtgui_dc_draw_text(dc, "ABCD中文", &rect);
+        rect.y1 += 18;
+
+        RTGUI_WIDGET_FONT(widget) = font_24;
+        rtgui_dc_draw_text(dc, "ABCD中文", &rect);
+        rect.y1 += 26;
+
+        RTGUI_WIDGET_FONT(widget) = font_36;
+        rtgui_dc_draw_text(dc, "ABCD中文", &rect);
+        rect.y1 += 38;
+
+        RTGUI_WIDGET_FONT(widget) = font_48;
+        rtgui_dc_draw_text(dc, "ABCD中文", &rect);
+
+        RTGUI_WIDGET_FONT(widget) = saved;
+        /* 绘图完成 */
+        rtgui_dc_end_drawing(dc);
+    }
+    else
+    {
+        /* 其他事件,调用默认的事件处理函数 */
+        return rtgui_container_event_handler(widget, event);
+    }
+
+    return RT_FALSE;
 }
 
 /* 创建用于TTF字体显示演示用的视图 */
 rtgui_container_t *demo_view_ttf()
 {
-	rtgui_container_t *container;
-
-	font_16 = rtgui_freetype_font_create("d:/simsun.ttf", 0, 0, 16);
-	font_24 = rtgui_freetype_font_create("d:/simsun.ttf", 0, 0, 24);
-	font_36 = rtgui_freetype_font_create("d:/simsun.ttf", 0, 0, 36);
-	font_48 = rtgui_freetype_font_create("d:/simsun.TTF", 0, 0, 72);
-
-	container = demo_view("TTF 演示");
-	if (container != RT_NULL)
-	{
-		RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(container)) = white;
-		/* 设置成自己的事件处理函数 */
-		rtgui_object_set_event_handler(RTGUI_OBJECT(container), ttf_event_handler);
-	}
-
-	return container;
+    rtgui_container_t *container;
+
+    font_16 = rtgui_freetype_font_create("d:/simsun.ttf", 0, 0, 16);
+    font_24 = rtgui_freetype_font_create("d:/simsun.ttf", 0, 0, 24);
+    font_36 = rtgui_freetype_font_create("d:/simsun.ttf", 0, 0, 36);
+    font_48 = rtgui_freetype_font_create("d:/simsun.TTF", 0, 0, 72);
+
+    container = demo_view("TTF 演示");
+    if (container != RT_NULL)
+    {
+        RTGUI_WIDGET_BACKGROUND(container) = white;
+        /* 设置成自己的事件处理函数 */
+        rtgui_object_set_event_handler(RTGUI_OBJECT(container), ttf_event_handler);
+    }
+
+    return container;
 }
 #endif

+ 198 - 194
examples/gui/demo_view_window.c

@@ -13,8 +13,8 @@
 #include <string.h>
 
 static struct rtgui_timer *timer;
-static struct rtgui_label* label;
-static struct rtgui_win* msgbox = RT_NULL;
+static struct rtgui_label *label;
+static struct rtgui_win *msgbox = RT_NULL;
 static char label_text[80];
 static rt_uint8_t cnt = 5;
 
@@ -25,7 +25,7 @@ static unsigned char normal_window_show_count = 1;
 extern struct rtgui_win *main_win;
 
 static rt_bool_t normal_window_onclose(struct rtgui_object *win,
-                                      struct rtgui_event *event)
+                                       struct rtgui_event *event)
 {
     normal_window_show_count++;
 
@@ -34,261 +34,265 @@ static rt_bool_t normal_window_onclose(struct rtgui_object *win,
 
 static void create_normal_win(void)
 {
-	rtgui_rect_t rect = {30, 40, 150, 80};
+    rtgui_rect_t rect = {30, 40, 150, 80};
 
-	normal_window = rtgui_win_create(RT_NULL, "普通窗口",
-									 &rect, RTGUI_WIN_STYLE_DEFAULT);
+    normal_window = rtgui_win_create(RT_NULL, "普通窗口",
+                                     &rect, RTGUI_WIN_STYLE_DEFAULT);
 
-	rect.x1 += 20;
-	rect.x2 -= 5;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
+    rect.x1 += 20;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
 
-	/* 添加一个文本标签 */
+    /* 添加一个文本标签 */
     rt_sprintf(normal_window_label_text,
-            "第 %d 次显示", normal_window_show_count);
-	normal_window_label = rtgui_label_create(normal_window_label_text);
-	rtgui_widget_set_rect(RTGUI_WIDGET(normal_window_label), &rect);
-	rtgui_container_add_child(RTGUI_CONTAINER(normal_window),
-							  RTGUI_WIDGET(normal_window_label));
+               "第 %d 次显示", normal_window_show_count);
+    normal_window_label = rtgui_label_create(normal_window_label_text);
+    rtgui_widget_set_rect(RTGUI_WIDGET(normal_window_label), &rect);
+    rtgui_container_add_child(RTGUI_CONTAINER(normal_window),
+                              RTGUI_WIDGET(normal_window_label));
 
     rtgui_win_set_onclose(normal_window,
                           normal_window_onclose);
 }
 
 /* 触发正常窗口显示 */
-static void demo_normal_window_onbutton(struct rtgui_object* object, rtgui_event_t* event)
+static void demo_normal_window_onbutton(struct rtgui_object *object, rtgui_event_t *event)
 {
     rt_sprintf(normal_window_label_text,
-            "第 %d 次显示", normal_window_show_count);
+               "第 %d 次显示", normal_window_show_count);
     rtgui_label_set_text(normal_window_label,
                          normal_window_label_text);
-    if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(normal_window)))
+    if (RTGUI_WIDGET_IS_HIDE(normal_window))
         rtgui_win_show(normal_window, RT_FALSE);
     else
         rtgui_win_activate(normal_window);
 }
 
 /* 获取一个递增的窗口标题 */
-static char* get_win_title()
+static char *get_win_title()
 {
-	static rt_uint8_t win_no = 0;
-	static char win_title[16];
+    static rt_uint8_t win_no = 0;
+    static char win_title[16];
 
-	rt_sprintf(win_title, "窗口 %d", ++win_no);
-	return win_title;
+    rt_sprintf(win_title, "窗口 %d", ++win_no);
+    return win_title;
 }
 
 /* 关闭对话框时的回调函数 */
-void diag_close(struct rtgui_timer* timer, void* parameter)
+void diag_close(struct rtgui_timer *timer, void *parameter)
 {
-	cnt --;
-	rt_sprintf(label_text, "closed then %d second!", cnt);
-
-	/* 设置标签文本并更新控件 */
-	rtgui_label_set_text(label, label_text);
-	rtgui_widget_update(RTGUI_WIDGET(label));
-
-	if (cnt == 0)
-	{
-		/* 超时,关闭对话框 */
-		rtgui_win_destroy(msgbox);
-	}
+    cnt --;
+    rt_sprintf(label_text, "closed then %d second!", cnt);
+
+    /* 设置标签文本并更新控件 */
+    rtgui_label_set_text(label, label_text);
+    rtgui_widget_update(RTGUI_WIDGET(label));
+
+    if (cnt == 0)
+    {
+        /* 超时,关闭对话框 */
+        rtgui_win_destroy(msgbox);
+    }
 }
 
 /* AUTO窗口关闭时的事件处理 */
-rt_bool_t auto_window_close(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t auto_window_close(struct rtgui_object *object, struct rtgui_event *event)
 {
-	if (timer != RT_NULL)
-	{
-		/* 停止并删除定时器 */
-		rtgui_timer_stop(timer);
-		rtgui_timer_destory(timer);
+    if (timer != RT_NULL)
+    {
+        /* 停止并删除定时器 */
+        rtgui_timer_stop(timer);
+        rtgui_timer_destory(timer);
 
-		timer = RT_NULL;
-	}
+        timer = RT_NULL;
+    }
 
-	return RT_TRUE;
+    return RT_TRUE;
 }
 
 static rt_uint16_t delta_x = 20;
 static rt_uint16_t delta_y = 40;
 
 /* 触发自动窗口显示 */
-static void demo_autowin_onbutton(struct rtgui_object* object, rtgui_event_t* event)
+static void demo_autowin_onbutton(struct rtgui_object *object, rtgui_event_t *event)
 {
-	struct rtgui_rect rect ={50, 50, 200, 200};
-
-	msgbox = rtgui_win_create(main_win, "Information",
-            &rect, RTGUI_WIN_STYLE_DEFAULT | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
-	if (msgbox == RT_NULL)
-		return;
-
-	cnt = 5;
-	rt_sprintf(label_text, "closed then %d second!", cnt);
-	label = rtgui_label_create(label_text);
-	rect.x1 += 5;
-	rect.x2 -= 5;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	rtgui_container_add_child(RTGUI_CONTAINER(msgbox),
-			RTGUI_WIDGET(label));
-
-	/* 设置关闭窗口时的动作 */
-	rtgui_win_set_onclose(msgbox, auto_window_close);
-
-	rtgui_win_show(msgbox, RT_FALSE);
-	/* 创建一个定时器 */
-	timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL);
-	rtgui_timer_start(timer);
+    struct rtgui_rect rect = {50, 50, 200, 200};
+
+    /* don't create the window twice */
+    if (msgbox)
+        return;
+
+    msgbox = rtgui_win_create(main_win, "Information",
+                              &rect, RTGUI_WIN_STYLE_DEFAULT | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
+    if (msgbox == RT_NULL)
+        return;
+
+    cnt = 5;
+    rt_sprintf(label_text, "closed then %d second!", cnt);
+    label = rtgui_label_create(label_text);
+    rect.x1 += 5;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    rtgui_container_add_child(RTGUI_CONTAINER(msgbox),
+                              RTGUI_WIDGET(label));
+
+    /* 设置关闭窗口时的动作 */
+    rtgui_win_set_onclose(msgbox, auto_window_close);
+
+    rtgui_win_show(msgbox, RT_FALSE);
+    /* 创建一个定时器 */
+    timer = rtgui_timer_create(100, RT_TIMER_FLAG_PERIODIC, diag_close, RT_NULL);
+    rtgui_timer_start(timer);
 }
 
 /* 触发模态窗口显示 */
-static void demo_modalwin_onbutton(struct rtgui_object* object, rtgui_event_t* event)
+static void demo_modalwin_onbutton(struct rtgui_object *object, rtgui_event_t *event)
 {
-	rtgui_win_t *win;
-	rtgui_label_t *label;
-	rtgui_rect_t rect = {0, 0, 150, 80};
+    rtgui_win_t *win;
+    rtgui_label_t *label;
+    rtgui_rect_t rect = {0, 0, 150, 80};
 
-	rtgui_rect_moveto(&rect, delta_x, delta_y);
-	delta_x += 20;
-	delta_y += 20;
+    rtgui_rect_moveto(&rect, delta_x, delta_y);
+    delta_x += 20;
+    delta_y += 20;
 
-	/* 创建一个窗口 */
-	win = rtgui_win_create(main_win,
-		get_win_title(), &rect, RTGUI_WIN_STYLE_DEFAULT);
+    /* 创建一个窗口 */
+    win = rtgui_win_create(main_win,
+                           get_win_title(), &rect, RTGUI_WIN_STYLE_DEFAULT);
 
-	rect.x1 += 20;
-	rect.x2 -= 5;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
+    rect.x1 += 20;
+    rect.x2 -= 5;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
 
-	label = rtgui_label_create("这是一个模式窗口");
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-	rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
+    label = rtgui_label_create("这是一个模式窗口");
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
+    rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
 
-	/* 模态显示窗口 */
-	rtgui_win_show(win, RT_TRUE);
+    /* 模态显示窗口 */
+    rtgui_win_show(win, RT_TRUE);
 
     /* 删除非自动删除窗口 */
-	rtgui_win_destroy(win);
+    rtgui_win_destroy(win);
 }
 
-static void demo_close_ntitle_window(struct rtgui_object* object, rtgui_event_t* event)
+static void demo_close_ntitle_window(struct rtgui_object *object, rtgui_event_t *event)
 {
-	rtgui_win_t* win;
+    rtgui_win_t *win;
 
-	/* 获得最顶层控件 */
-	win = RTGUI_WIN(rtgui_widget_get_toplevel(RTGUI_WIDGET(object)));
+    /* 获得最顶层控件 */
+    win = RTGUI_WIN(rtgui_widget_get_toplevel(RTGUI_WIDGET(object)));
 
-	/* 销毁窗口 */
-	rtgui_win_destroy(win);
+    /* 销毁窗口 */
+    rtgui_win_destroy(win);
 }
 
 /* 触发无标题窗口显示 */
-static void demo_ntitlewin_onbutton(struct rtgui_object* object, rtgui_event_t* event)
+static void demo_ntitlewin_onbutton(struct rtgui_object *object, rtgui_event_t *event)
 {
-	rtgui_win_t *win;
-	rtgui_label_t *label;
-	rtgui_button_t *button;
-	rtgui_rect_t widget_rect, rect = {0, 0, 150, 80};
-
-	rtgui_rect_moveto(&rect, delta_x, delta_y);
-	delta_x += 20;
-	delta_y += 20;
-
-	/* 创建一个窗口,风格为无标题及无边框 */
-	win = rtgui_win_create(main_win,
-		"no title", &rect, RTGUI_WIN_STYLE_NO_TITLE |
-						   RTGUI_WIN_STYLE_NO_BORDER |
-						   RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
-	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(win)) = white;
-
-	/* 创建一个文本标签 */
-	label = rtgui_label_create("无边框窗口");
-	rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(label)), "无边框窗口", &widget_rect);
-	rtgui_rect_moveto_align(&rect, &widget_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
-	widget_rect.y1 += 20;
-	widget_rect.y2 += 20;
-	rtgui_widget_set_rect(RTGUI_WIDGET(label), &widget_rect);
-	rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
-	RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(label)) = white;
-
-	/* 创建一个关闭按钮 */
-	widget_rect.x1 = 0;
-	widget_rect.y1 = 0;
-	widget_rect.x2 = 40;
-	widget_rect.y2 = 20;
-	rtgui_rect_moveto_align(&rect, &widget_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
-	widget_rect.y1 += 40;
-	widget_rect.y2 += 40;
-	button = rtgui_button_create("关闭");
-	rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);
-	rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(button));
-	rtgui_button_set_onbutton(button, demo_close_ntitle_window);
-
-	rtgui_win_show(win, RT_FALSE);
+    rtgui_win_t *win;
+    rtgui_label_t *label;
+    rtgui_button_t *button;
+    rtgui_rect_t widget_rect, rect = {0, 0, 150, 80};
+
+    rtgui_rect_moveto(&rect, delta_x, delta_y);
+    delta_x += 20;
+    delta_y += 20;
+
+    /* 创建一个窗口,风格为无标题及无边框 */
+    win = rtgui_win_create(main_win,
+                           "no title", &rect, RTGUI_WIN_STYLE_NO_TITLE |
+                           RTGUI_WIN_STYLE_NO_BORDER |
+                           RTGUI_WIN_STYLE_DESTROY_ON_CLOSE);
+    RTGUI_WIDGET_BACKGROUND(win) = white;
+
+    /* 创建一个文本标签 */
+    label = rtgui_label_create("无边框窗口");
+    rtgui_font_get_metrics(RTGUI_WIDGET_FONT(label), "无边框窗口", &widget_rect);
+    rtgui_rect_moveto_align(&rect, &widget_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
+    widget_rect.y1 += 20;
+    widget_rect.y2 += 20;
+    rtgui_widget_set_rect(RTGUI_WIDGET(label), &widget_rect);
+    rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label));
+    RTGUI_WIDGET_BACKGROUND(label) = white;
+
+    /* 创建一个关闭按钮 */
+    widget_rect.x1 = 0;
+    widget_rect.y1 = 0;
+    widget_rect.x2 = 40;
+    widget_rect.y2 = 20;
+    rtgui_rect_moveto_align(&rect, &widget_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
+    widget_rect.y1 += 40;
+    widget_rect.y2 += 40;
+    button = rtgui_button_create("关闭");
+    rtgui_widget_set_rect(RTGUI_WIDGET(button), &widget_rect);
+    rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(button));
+    rtgui_button_set_onbutton(button, demo_close_ntitle_window);
+
+    rtgui_win_show(win, RT_FALSE);
 }
 
-rtgui_container_t* demo_view_window(void)
+rtgui_container_t *demo_view_window(void)
 {
-	rtgui_rect_t  rect;
-	rtgui_container_t* container;
-	rtgui_button_t *button;
+    rtgui_rect_t  rect;
+    rtgui_container_t *container;
+    rtgui_button_t *button;
 
-	/* 创建一个演示用的视图 */
-	container = demo_view("Window Demo");
+    /* 创建一个演示用的视图 */
+    container = demo_view("Window Demo");
 
     create_normal_win();
 
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 += 5;
-	rect.y2 = rect.y1 + 20;
-	/* 创建按钮用于显示正常窗口 */
-	button = rtgui_button_create("Normal Win");
-	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
-	rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(button));
-	/* 设置onbutton为demo_win_onbutton函数 */
-	rtgui_button_set_onbutton(button, demo_normal_window_onbutton);
-
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 += 5 + 25;
-	rect.y2 = rect.y1 + 20;
-	/* 创建按钮用于显示一个自动关闭的窗口 */
-	button = rtgui_button_create("Auto Win");
-	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
-	rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(button));
-	/* 设置onbutton为demo_autowin_onbutton函数 */
-	rtgui_button_set_onbutton(button, demo_autowin_onbutton);
-
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 += 5 + 25 + 25;
-	rect.y2 = rect.y1 + 20;
-	/* 创建按钮用于触发一个模式窗口 */
-	button = rtgui_button_create("Modal Win");
-	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
-	rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(button));
-	/* 设置onbutton为demo_modalwin_onbutton函数 */
-	rtgui_button_set_onbutton(button, demo_modalwin_onbutton);
-
-	demo_view_get_rect(container, &rect);
-	rect.x1 += 5;
-	rect.x2 = rect.x1 + 100;
-	rect.y1 += 5 + 25 + 25 + 25;
-	rect.y2 = rect.y1 + 20;
-	/* 创建按钮用于触发一个不包含标题的窗口 */
-	button = rtgui_button_create("NoTitle Win");
-	rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
-	rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(button));
-	/* 设置onbutton为demo_ntitlewin_onbutton函数 */
-	rtgui_button_set_onbutton(button, demo_ntitlewin_onbutton);
-
-	return container;
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 5;
+    rect.y2 = rect.y1 + 20;
+    /* 创建按钮用于显示正常窗口 */
+    button = rtgui_button_create("Normal Win");
+    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
+    rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(button));
+    /* 设置onbutton为demo_win_onbutton函数 */
+    rtgui_button_set_onbutton(button, demo_normal_window_onbutton);
+
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 5 + 25;
+    rect.y2 = rect.y1 + 20;
+    /* 创建按钮用于显示一个自动关闭的窗口 */
+    button = rtgui_button_create("Auto Win");
+    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
+    rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(button));
+    /* 设置onbutton为demo_autowin_onbutton函数 */
+    rtgui_button_set_onbutton(button, demo_autowin_onbutton);
+
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 5 + 25 + 25;
+    rect.y2 = rect.y1 + 20;
+    /* 创建按钮用于触发一个模式窗口 */
+    button = rtgui_button_create("Modal Win");
+    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
+    rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(button));
+    /* 设置onbutton为demo_modalwin_onbutton函数 */
+    rtgui_button_set_onbutton(button, demo_modalwin_onbutton);
+
+    demo_view_get_rect(container, &rect);
+    rect.x1 += 5;
+    rect.x2 = rect.x1 + 100;
+    rect.y1 += 5 + 25 + 25 + 25;
+    rect.y2 = rect.y1 + 20;
+    /* 创建按钮用于触发一个不包含标题的窗口 */
+    button = rtgui_button_create("NoTitle Win");
+    rtgui_widget_set_rect(RTGUI_WIDGET(button), &rect);
+    rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(button));
+    /* 设置onbutton为demo_ntitlewin_onbutton函数 */
+    rtgui_button_set_onbutton(button, demo_ntitlewin_onbutton);
+
+    return container;
 }

+ 10 - 10
examples/gui/demo_xml.c

@@ -2,23 +2,23 @@
 
 #include <rtgui/rtgui_xml.h>
 
-static int xml_event_handler(rt_uint8_t event, const char* text, rt_size_t len, void* user)
+static int xml_event_handler(rt_uint8_t event, const char *text, rt_size_t len, void *user)
 {
-	rt_kprintf("%s: %s\n", rtgui_xml_event_str(event), text);
-	return 1;
+    rt_kprintf("%s: %s\n", rtgui_xml_event_str(event), text);
+    return 1;
 }
 
 const char xml_str[] = "<?xml version=\"1.0\"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>";
 void demo_xml()
 {
-	rtgui_xml_t *xml;
+    rtgui_xml_t *xml;
 
-	xml = rtgui_xml_create(512, xml_event_handler, RT_NULL);
-	if (xml != RT_NULL)
-	{
-		rtgui_xml_parse(xml, xml_str, sizeof(xml_str));
-		rtgui_xml_destroy(xml);
-	}
+    xml = rtgui_xml_create(512, xml_event_handler, RT_NULL);
+    if (xml != RT_NULL)
+    {
+        rtgui_xml_parse(xml, xml_str, sizeof(xml_str));
+        rtgui_xml_destroy(xml);
+    }
 }
 #ifdef RT_USING_FINSH
 #include <finsh.h>

+ 0 - 19
examples/gui/gui_init.c

@@ -1,19 +0,0 @@
-#include <rtgui/rtgui.h>
-#include <rtgui/rtgui_server.h>
-#include <rtgui/rtgui_system.h>
-
-extern void workbench_init(void);
-extern void panel_init(void);
-
-/* GUI相关演示入口,需放在线程中进行初始化 */
-void rtgui_startup()
-{
-	/* GUI系统初始化 */
-    rtgui_system_server_init();
-
-	/* 各个面板初始化 */
-	panel_init();
-
-	/* 启动workbench */
-	workbench_init();
-}

+ 105 - 105
examples/gui/mywidget.c

@@ -2,135 +2,135 @@
 #include "mywidget.h"
 
 /* �找辣蝏睃㦛�賣㺭 */
-static void rtgui_mywidget_ondraw(struct rtgui_mywidget* me)
+static void rtgui_mywidget_ondraw(struct rtgui_mywidget *me)
 {
-	struct rtgui_dc* dc;
-	struct rtgui_rect rect;
-	rt_uint16_t x, y;
-
-	/* �瑕��格�DC嚗��憪讠��?*/
-	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(me));
-	if (dc == RT_NULL) return;
-
-	/* �瑕�蝒堒藁��偕撖?*/
-	rtgui_widget_get_rect(RTGUI_WIDGET(me), &rect);
-	/* 蝏睃��峕艶�?*/
-	RTGUI_DC_BC(dc) = white;
-	rtgui_dc_fill_rect(dc, &rect);
-
-	/* 霈∠�銝剖��毺� */
-	x = (rect.x2 + rect.x1)/2;
-	y = (rect.y2 + rect.y1)/2;
-
-	/* 蝏睃�����?*/
-	RTGUI_DC_FC(dc) = black;
-	rtgui_dc_draw_hline(dc, rect.x1, rect.x2, y);
-	rtgui_dc_draw_vline(dc, x, rect.y1, rect.y2);
-
-	/* �寞旿�嗆����嗅��?*/
-	if (me->status == MYWIDGET_STATUS_ON)
-		RTGUI_DC_FC(dc) = green;
-	else
-		RTGUI_DC_FC(dc) = red;
-	rtgui_dc_fill_circle(dc, x, y, 5);
-
-	/* 蝏𤘪�蝏睃㦛 */
-	rtgui_dc_end_drawing(dc);
-	return;
+    struct rtgui_dc *dc;
+    struct rtgui_rect rect;
+    rt_uint16_t x, y;
+
+    /* �瑕��格�DC嚗��憪讠��?*/
+    dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(me));
+    if (dc == RT_NULL) return;
+
+    /* �瑕�蝒堒藁��偕撖?*/
+    rtgui_widget_get_rect(RTGUI_WIDGET(me), &rect);
+    /* 蝏睃��峕艶�?*/
+    RTGUI_DC_BC(dc) = white;
+    rtgui_dc_fill_rect(dc, &rect);
+
+    /* 霈∠�銝剖��毺� */
+    x = (rect.x2 + rect.x1) / 2;
+    y = (rect.y2 + rect.y1) / 2;
+
+    /* 蝏睃�����?*/
+    RTGUI_DC_FC(dc) = black;
+    rtgui_dc_draw_hline(dc, rect.x1, rect.x2, y);
+    rtgui_dc_draw_vline(dc, x, rect.y1, rect.y2);
+
+    /* �寞旿�嗆����嗅��?*/
+    if (me->status == MYWIDGET_STATUS_ON)
+        RTGUI_DC_FC(dc) = green;
+    else
+        RTGUI_DC_FC(dc) = red;
+    rtgui_dc_fill_circle(dc, x, y, 5);
+
+    /* 蝏𤘪�蝏睃㦛 */
+    rtgui_dc_end_drawing(dc);
+    return;
 }
 
 /* 曌䭾�鈭衤辣憭���賣㺭 */
-static void rtgui_mywidget_onmouse(struct rtgui_mywidget* me, struct rtgui_event_mouse* mouse)
+static void rtgui_mywidget_onmouse(struct rtgui_mywidget *me, struct rtgui_event_mouse *mouse)
 {
-	struct rtgui_rect rect;
-	rt_uint16_t x, y;
-
-	/* 隞�笆曌䭾��祈絲�其�餈𥡝�憭�� */
-	if (!(mouse->button & RTGUI_MOUSE_BUTTON_UP)) return;
-
-	/* �瑕��找辣���蝵?*/
-	rtgui_widget_get_rect(RTGUI_WIDGET(me), &rect);
-	/* get_rect�賣㺭�瑕��舀綉隞嗥��詨笆雿滨蔭嚗諹�屸����隞嗥��箇��鞉��舐�撖孵������閬��銝�銝芾蓮�?*/
-	rtgui_widget_rect_to_device(RTGUI_WIDGET(me), &rect);
-
-	/* 霈∠�銝剖��毺� */
-	x = (rect.x2 + rect.x1)/2;
-	y = (rect.y2 + rect.y1)/2;
-
-	/* 瘥磰�曌䭾��鞉��臬炏�典��?*/
-	if ((mouse->x < x + 5 && mouse->x > x - 5) &&
-			(mouse->y < y + 5 && mouse->y > y - 5))
-	{
-		/* �湔㺿�找辣�嗆�?*/
-		if (me->status & MYWIDGET_STATUS_ON) me->status = MYWIDGET_STATUS_OFF;
-		else me->status = MYWIDGET_STATUS_ON;
-
-		/* �瑟鰵(�齿鰵蝏睃�)�找辣 */
-		rtgui_mywidget_ondraw(me);
-	}
+    struct rtgui_rect rect;
+    rt_uint16_t x, y;
+
+    /* 隞�笆曌䭾��祈絲�其�餈𥡝�憭�� */
+    if (!(mouse->button & RTGUI_MOUSE_BUTTON_UP)) return;
+
+    /* �瑕��找辣���蝵?*/
+    rtgui_widget_get_rect(RTGUI_WIDGET(me), &rect);
+    /* get_rect�賣㺭�瑕��舀綉隞嗥��詨笆雿滨蔭嚗諹�屸����隞嗥��箇��鞉��舐�撖孵������閬��銝�銝芾蓮�?*/
+    rtgui_widget_rect_to_device(RTGUI_WIDGET(me), &rect);
+
+    /* 霈∠�銝剖��毺� */
+    x = (rect.x2 + rect.x1) / 2;
+    y = (rect.y2 + rect.y1) / 2;
+
+    /* 瘥磰�曌䭾��鞉��臬炏�典��?*/
+    if ((mouse->x < x + 5 && mouse->x > x - 5) &&
+            (mouse->y < y + 5 && mouse->y > y - 5))
+    {
+        /* �湔㺿�找辣�嗆�?*/
+        if (me->status & MYWIDGET_STATUS_ON) me->status = MYWIDGET_STATUS_OFF;
+        else me->status = MYWIDGET_STATUS_ON;
+
+        /* �瑟鰵(�齿鰵蝏睃�)�找辣 */
+        rtgui_mywidget_ondraw(me);
+    }
 }
 
 /* mywidget�找辣���隞嗅���遆�?*/
-rt_bool_t rtgui_mywidget_event_handler(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_mywidget_event_handler(struct rtgui_object *object, struct rtgui_event *event)
 {
-	/* 靚�鍂鈭衤辣憭���賣㺭�塚�widget�������找辣�祈澈嚗峕�隞亙��瑕��詨��找辣撖寡情����?*/
-	struct rtgui_mywidget* me = RTGUI_MYWIDGET(object);
-
-	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(object, event);
-	}
-
-	return RT_FALSE;
+    /* 靚�鍂鈭衤辣憭���賣㺭�塚�widget�������找辣�祈澈嚗峕�隞亙��瑕��詨��找辣撖寡情����?*/
+    struct rtgui_mywidget *me = RTGUI_MYWIDGET(object);
+
+    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(object, event);
+    }
+
+    return RT_FALSE;
 }
 
 /* �芸�銋㗇綉隞嗥����惩遆�?*/
 static void _rtgui_mywidget_constructor(rtgui_mywidget_t *mywidget)
 {
-	/* 暺䁅恕餈嗘葵�找辣�交𤣰�𡁶� */
-	RTGUI_WIDGET(mywidget)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
-	/* �嘥��𡝗綉隞嗅僎霈曄蔭鈭衤辣憭���賣㺭 */
-	rtgui_object_set_event_handler(RTGUI_OBJECT(mywidget), rtgui_mywidget_event_handler);
+    /* 暺䁅恕餈嗘葵�找辣�交𤣰�𡁶� */
+    RTGUI_WIDGET(mywidget)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+    /* �嘥��𡝗綉隞嗅僎霈曄蔭鈭衤辣憭���賣㺭 */
+    rtgui_object_set_event_handler(RTGUI_OBJECT(mywidget), rtgui_mywidget_event_handler);
 
-	/* �嘥��嗆��𧒄OFF */
-	mywidget->status = MYWIDGET_STATUS_OFF;
+    /* �嘥��嗆��𧒄OFF */
+    mywidget->status = MYWIDGET_STATUS_OFF;
 }
 
-DEFINE_CLASS_TYPE(mywidget, "mywidget", 
-	RTGUI_WIDGET_TYPE,
-	_rtgui_mywidget_constructor,
-	RT_NULL,
-	sizeof(struct rtgui_mywidget));
+DEFINE_CLASS_TYPE(mywidget, "mywidget",
+                  RTGUI_WIDGET_TYPE,
+                  _rtgui_mywidget_constructor,
+                  RT_NULL,
+                  sizeof(struct rtgui_mywidget));
 
 /* �𥕦遣銝�銝芾䌊摰帋��找辣 */
-struct rtgui_mywidget* rtgui_mywidget_create(rtgui_rect_t* r)
+struct rtgui_mywidget *rtgui_mywidget_create(rtgui_rect_t *r)
 {
-	struct rtgui_mywidget* me;
+    struct rtgui_mywidget *me;
 
-	/* 霈姅tgui_widget�𥕦遣�箔�銝芣�摰𡁶掩�页�RTGUI_MYWIDGET_TYPE蝐餃���綉隞?*/
-	me = (struct rtgui_mywidget*) rtgui_widget_create (RTGUI_MYWIDGET_TYPE);
-	if (me != RT_NULL)
-	{
-		rtgui_widget_set_rect(RTGUI_WIDGET(me), r);
-	}
+    /* 霈姅tgui_widget�𥕦遣�箔�銝芣�摰𡁶掩�页�RTGUI_MYWIDGET_TYPE蝐餃���綉隞?*/
+    me = (struct rtgui_mywidget *) rtgui_widget_create(RTGUI_MYWIDGET_TYPE);
+    if (me != RT_NULL)
+    {
+        rtgui_widget_set_rect(RTGUI_WIDGET(me), r);
+    }
 
-	return me;
+    return me;
 }
 
 /* �𣳇膄銝�銝芾䌊摰帋��找辣 */
-void rtgui_mywidget_destroy(struct rtgui_mywidget* me)
+void rtgui_mywidget_destroy(struct rtgui_mywidget *me)
 {
-	rtgui_widget_destroy(RTGUI_WIDGET(me));
+    rtgui_widget_destroy(RTGUI_WIDGET(me));
 }

+ 9 - 9
examples/gui/mywidget.h

@@ -15,8 +15,8 @@
 #include <rtgui/widgets/widget.h>
 
 /* 鑷�畾涔夋帶浠剁殑鐘舵€佸€煎畾涔?*/
-#define MYWIDGET_STATUS_ON	1
-#define MYWIDGET_STATUS_OFF	0
+#define MYWIDGET_STATUS_ON  1
+#define MYWIDGET_STATUS_OFF 0
 
 DECLARE_CLASS_TYPE(mywidget);
 /** 姣忎釜鎺т欢浼氭湁涓€涓�被鍨嬶紝閫氳繃濡備笅鐨勫畯鑾峰緱鎺т欢鐩稿簲鐨勭被鍨嬩俊鎭?*/
@@ -29,22 +29,22 @@ DECLARE_CLASS_TYPE(mywidget);
 /* 涓�€у寲鎺т欢绫诲畾涔?*/
 struct rtgui_mywidget
 {
-	/* 杩欎釜鎺т欢鏄�户鎵胯嚜rtgui_widget鎺т欢 */
-	struct rtgui_widget parent;
+    /* 杩欎釜鎺т欢鏄�户鎵胯嚜rtgui_widget鎺т欢 */
+    struct rtgui_widget parent;
 
-	/* 鐘舵€侊細ON銆丱FF */
-	rt_uint8_t status;
+    /* 鐘舵€侊細ON銆丱FF */
+    rt_uint8_t status;
 };
 typedef struct rtgui_mywidget rtgui_mywidget_t;
 
 /* 鎺т欢鐨勫垱寤哄拰鍒犻櫎 */
-struct rtgui_mywidget* rtgui_mywidget_create(rtgui_rect_t* r);
-void rtgui_mywidget_destroy(struct rtgui_mywidget* me);
+struct rtgui_mywidget *rtgui_mywidget_create(rtgui_rect_t *r);
+void rtgui_mywidget_destroy(struct rtgui_mywidget *me);
 
 /* 鎺т欢鐨勯粯璁や簨浠跺�鐞嗗嚱鏁般€?
  * 瀵逛竴涓�帶浠惰€岃█锛屽�鏋滄淳鐢熻嚜瀹冪殑瀛愭帶浠跺緢鍙�兘浼氳皟鐢ㄧ埗鎺т欢鐨勪簨浠跺�鐞嗗嚱鏁帮紝
  * 鎵€浠ヨ繖閲岄噰鐢ㄥ叕寮€澹版槑鐨勬柟寮忋€?
  */
-rt_bool_t rtgui_mywidget_event_handler(struct rtgui_object* object, struct rtgui_event* event);
+rt_bool_t rtgui_mywidget_event_handler(struct rtgui_object *object, struct rtgui_event *event);
 
 #endif