summaryrefslogtreecommitdiff
path: root/rtgui/widgets
diff options
context:
space:
mode:
authorbernard.xiong <[email protected]>2010-04-18 15:05:20 +0000
committerbernard.xiong <[email protected]>2010-04-18 15:05:20 +0000
commitf908d62a40b49ee0c03527e63a153acf6822e79b (patch)
tree39d74a8d2b6698171eee392412b69da94f95f05f /rtgui/widgets
parent1df014578a7fab20f6b5ed00b3ea530ba7509d04 (diff)
move to components directory
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@638 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'rtgui/widgets')
-rw-r--r--rtgui/widgets/about_view.c108
-rw-r--r--rtgui/widgets/box.c343
-rw-r--r--rtgui/widgets/button.c246
-rw-r--r--rtgui/widgets/checkbox.c140
-rw-r--r--rtgui/widgets/container.c303
-rw-r--r--rtgui/widgets/filelist_view.c729
-rw-r--r--rtgui/widgets/iconbox.c171
-rw-r--r--rtgui/widgets/label.c116
-rw-r--r--rtgui/widgets/list_view.c290
-rw-r--r--rtgui/widgets/progressbar.c114
-rw-r--r--rtgui/widgets/radiobox.c239
-rw-r--r--rtgui/widgets/slider.c222
-rw-r--r--rtgui/widgets/staticline.c86
-rw-r--r--rtgui/widgets/textbox.c381
-rw-r--r--rtgui/widgets/title.c82
-rw-r--r--rtgui/widgets/toplevel.c194
-rw-r--r--rtgui/widgets/view.c218
-rw-r--r--rtgui/widgets/widget.c555
-rw-r--r--rtgui/widgets/window.c630
-rw-r--r--rtgui/widgets/workbench.c525
20 files changed, 0 insertions, 5692 deletions
diff --git a/rtgui/widgets/about_view.c b/rtgui/widgets/about_view.c
deleted file mode 100644
index 374a6ec43b..0000000000
--- a/rtgui/widgets/about_view.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * File : about_view.c
- * This file is part of RTGUI in RT-Thread RTOS
- * COPYRIGHT (C) 2010, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2010-01-06 Bernard first version
- */
-
-#include <rtgui/rtgui_theme.h>
-#include <rtgui/widgets/about_view.h>
-
-static void _rtgui_about_view_constructor(struct rtgui_about_view *view)
-{
- /* default rect */
- struct rtgui_rect rect = {0, 0, 200, 200};
-
- /* set default widget rect and set event handler */
- rtgui_widget_set_event_handler(RTGUI_WIDGET(view),rtgui_about_view_event_handler);
- rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
-
- RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
-
- view->logo = RT_NULL;
- view->description = RT_NULL;
-
- RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL;
-}
-
-rtgui_type_t *rtgui_about_view_type_get(void)
-{
- static rtgui_type_t *list_view_type = RT_NULL;
-
- if (!list_view_type)
- {
- list_view_type = rtgui_type_create("aboutview", RTGUI_VIEW_TYPE,
- sizeof(rtgui_about_view_t), RTGUI_CONSTRUCTOR(_rtgui_about_view_constructor), RT_NULL);
- }
-
- return list_view_type;
-}
-
-void rtgui_about_view_ondraw(struct rtgui_about_view* view)
-{
- struct rtgui_rect rect;
- struct rtgui_dc* dc;
-
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
- if (dc == RT_NULL) return;
-
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
- rtgui_dc_fill_rect(dc, &rect);
-
- if (view->logo != RT_NULL)
- rtgui_image_blit(view->logo, dc, &rect);
-
- rect.y1 += view->logo->h + 5;
- if (view->description != RT_NULL)
- rtgui_dc_draw_text(dc, view->description, &rect);
-
- rect.y1 += rtgui_dc_get_gc(dc)->font->height;
- rtgui_dc_draw_hline(dc, rect.x1 + 3, rect.x2 - 3, rect.y1);
- RTGUI_DC_FC(dc) = white;
- rtgui_dc_draw_hline(dc, rect.x1 + 4, rect.x2 - 2, rect.y1 + 1);
-
- rtgui_dc_end_drawing(dc);
-}
-
-rt_bool_t rtgui_about_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_about_view* view = RT_NULL;
-
- view = RTGUI_ABOUT_VIEW(widget);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- rtgui_about_view_ondraw(view);
- return RT_FALSE;
- }
-
- /* use view event handler */
- return rtgui_view_event_handler(widget, event);
-}
-
-rtgui_about_view_t* rtgui_about_view_create(rtgui_image_t *logo, const char* description)
-{
- struct rtgui_about_view* view = RT_NULL;
-
- view = (struct rtgui_about_view*) rtgui_widget_create(RTGUI_ABOUT_VIEW_TYPE);
- if (view != RT_NULL)
- {
- view->logo = logo;
- view->description = description;
- }
-
- return view;
-}
-
-void rtgui_about_view_destroy(rtgui_about_view_t* view)
-{
- /* destroy view */
- rtgui_widget_destroy(RTGUI_WIDGET(view));
-}
diff --git a/rtgui/widgets/box.c b/rtgui/widgets/box.c
deleted file mode 100644
index 4f29fbc595..0000000000
--- a/rtgui/widgets/box.c
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * File : box.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2009-10-16 Bernard first version
- */
-#include <rtgui/dc.h>
-#include <rtgui/widgets/box.h>
-
-#ifndef RTGUI_USING_SMALL_SIZE
-static void _rtgui_box_constructor(rtgui_box_t *box)
-{
- /* init widget and set event handler */
- rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_box_event_handler);
-
- RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_TRANSPARENT;
- rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_box_event_handler);
-
- /* set proper of control */
- box->orientation = RTGUI_HORIZONTAL;
- box->border_size = RTGUI_BORDER_DEFAULT_WIDTH;
-}
-
-rtgui_type_t *rtgui_box_type_get(void)
-{
- static rtgui_type_t *box_type = RT_NULL;
-
- if (!box_type)
- {
- box_type = rtgui_type_create("box", RTGUI_CONTAINER_TYPE,
- sizeof(rtgui_box_t), RTGUI_CONSTRUCTOR(_rtgui_box_constructor), RT_NULL);
- }
-
- return box_type;
-}
-
-rt_bool_t rtgui_box_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
-{
- struct rtgui_box* box = (struct rtgui_box*)widget;
-
- RT_ASSERT(box != RT_NULL);
-
- switch (event->type)
- {
- case RTGUI_EVENT_RESIZE:
- /* re-layout */
- rtgui_box_layout(box);
- break;
-
- default:
- return rtgui_container_event_handler(RTGUI_WIDGET(box), event);
- }
-
- return RT_FALSE;
-}
-
-struct rtgui_box* rtgui_box_create(int orientation, rtgui_rect_t* rect)
-{
- struct rtgui_box* box;
-
- box = (struct rtgui_box*) rtgui_widget_create (RTGUI_BOX_TYPE);
- if (box != RT_NULL)
- {
- /* set proper of control */
- rtgui_widget_set_rect(RTGUI_WIDGET(box), rect);
- box->orientation = orientation;
- }
-
- return box;
-}
-
-void rtgui_box_append(struct rtgui_box* box, rtgui_widget_t* widget)
-{
- /* put to box's children list */
- rtgui_container_add_child(RTGUI_CONTAINER(box), widget);
-}
-
-static void rtgui_box_layout_vertical(rtgui_box_t* box)
-{
- rtgui_list_t *node;
- rt_int32_t box_width;
- rt_int32_t space_count;
- rt_int32_t next_x, next_y;
- rt_int32_t total_height, space_height;
- struct rtgui_event_resize size_event;
-
- /* prepare the resize event */
- RTGUI_EVENT_RESIZE_INIT(&size_event);
-
- /* find spaces */
- space_count = 0;
- total_height = 0;
- space_height = 0;
-
- rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children))
- {
- rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
- if (widget->align & RTGUI_ALIGN_STRETCH) space_count ++;
- else total_height += widget->mini_height;
- }
-
- /* calculate the height for each spaces */
- if (space_count != 0)
- {
- space_height = (rtgui_rect_height(RTGUI_WIDGET(box)->extent) - total_height - (box->border_size << 1)) / space_count;
- }
-
- /* init (x, y) and box width */
- next_x = RTGUI_WIDGET(box)->extent.x1 + box->border_size;
- next_y = RTGUI_WIDGET(box)->extent.y1 + box->border_size;
- box_width = rtgui_rect_width(RTGUI_WIDGET(box)->extent) - (box->border_size << 1);
-
- /* layout each widget */
- rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children))
- {
- rtgui_rect_t *rect;
- rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
-
- /* get extent of widget */
- rect = &(widget->extent);
-
- /* reset rect */
- rtgui_rect_moveto(rect, -rect->x1, -rect->y1);
- rect->x2 = widget->mini_width;
- rect->y2 = widget->mini_height;
-
- /* left in default */
- rtgui_rect_moveto(rect, next_x, next_y);
-
- if (widget->align & RTGUI_ALIGN_EXPAND)
- {
- /* expand on horizontal */
- rect->x2 = rect->x1 + (rt_int16_t)box_width;
- }
- if (widget->align & RTGUI_ALIGN_CENTER_VERTICAL)
- {
- /* center */
- rt_uint32_t mid;
-
- mid = box_width - rtgui_rect_width(*rect);
- mid = mid /2;
-
- rect->x1 = next_x + mid;
- rect->x2 = next_x + box_width - mid;
- }
- else if (widget->align & RTGUI_ALIGN_RIGHT)
- {
- /* right */
- rect->x1 = next_x + box_width - rtgui_rect_width(*rect);
- rect->x2 = next_x + box_width;
- }
-
- if (widget->align & RTGUI_ALIGN_STRETCH)
- {
- rect->y2 = rect->y1 + space_height;
- }
-
- /* process resize event */
- size_event.x = rect->x1;
- size_event.y = rect->y1;
- size_event.w = rect->x2 - rect->x1;
- size_event.h = rect->y2 - rect->y1;
- widget->event_handler(widget, &size_event.parent);
-
- /* point to next height */
- next_y = rect->y2;
- }
-}
-
-static void rtgui_box_layout_horizontal(rtgui_box_t* box)
-{
- rtgui_list_t *node;
- rt_int32_t box_height;
- rt_int32_t space_count;
- rt_int32_t next_x, next_y;
- rt_int32_t total_width, space_width;
- struct rtgui_event_resize size_event;
-
- /* prepare the resize event */
- RTGUI_EVENT_RESIZE_INIT(&size_event);
-
- /* find spaces */
- space_count = 0;
- total_width = 0;
- space_width = 0;
-
- rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children))
- {
- rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
- if (widget->align & RTGUI_ALIGN_STRETCH) space_count ++;
- else total_width += widget->mini_width;
- }
-
- if (space_count != 0)
- {
- /* calculate the height for each spaces */
- space_width = (rtgui_rect_width(RTGUI_WIDGET(box)->extent) - total_width) / space_count;
- }
-
- /* init (x, y) and box height */
- next_x = RTGUI_WIDGET(box)->extent.x1 + box->border_size;
- next_y = RTGUI_WIDGET(box)->extent.y1 + box->border_size;
- box_height = rtgui_rect_height(RTGUI_WIDGET(box)->extent) - (box->border_size << 1);
-
- /* layout each widget */
- rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children))
- {
- rtgui_rect_t *rect;
- rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
-
- /* get extent of widget */
- rect = &(widget->extent);
-
- /* reset rect */
- rtgui_rect_moveto(rect, -rect->x1, -rect->y1);
- rect->x2 = widget->mini_width;
- rect->y2 = widget->mini_height;
-
- /* top in default */
- rtgui_rect_moveto(rect, next_x, next_y);
-
- if (widget->align & RTGUI_ALIGN_EXPAND)
- {
- /* expand on vertical */
- rect->y2 = rect->y1 + box_height;
- }
- if (widget->align & RTGUI_ALIGN_CENTER_HORIZONTAL)
- {
- /* center */
- rt_uint32_t mid;
-
- mid = box_height - rtgui_rect_height(*rect);
- mid = mid /2;
-
- rect->y1 = next_y + mid;
- rect->y2 = next_y + box_height - mid;
- }
- else if (widget->align & RTGUI_ALIGN_RIGHT)
- {
- /* right */
- rect->y1 = next_y + box_height - rtgui_rect_height(*rect);
- rect->y2 = next_y + box_height;
- }
-
- if (widget->align & RTGUI_ALIGN_STRETCH)
- {
- rect->x2 = rect->x1 + space_width;
- }
-
- /* process resize event */
- size_event.x = rect->x1;
- size_event.y = rect->y1;
- size_event.w = rect->x2 - rect->x1;
- size_event.h = rect->y2 - rect->y1;
- widget->event_handler(widget, &size_event.parent);
-
- /* point to next width */
- next_x = rect->x2;
- }
-}
-
-void rtgui_box_layout(rtgui_box_t* box)
-{
- RT_ASSERT(box != RT_NULL);
-
- if (box->orientation & RTGUI_VERTICAL)
- {
- rtgui_box_layout_vertical(box);
- }
- else
- {
- rtgui_box_layout_horizontal(box);
- }
-
- /* update box and its children clip */
- if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(box)))
- {
- rtgui_widget_update_clip(RTGUI_WIDGET(box));
- }
-}
-
-rt_uint32_t rtgui_box_get_width(rtgui_box_t* box)
-{
- rtgui_list_t *node;
- rt_uint32_t width;
-
- width = 0;
- rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children))
- {
- rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
- rt_uint32_t widget_width;
-
- widget_width = rtgui_rect_width(widget->extent);
- if (box->orientation & RTGUI_VERTICAL)
- {
- /* get the max width */
- if (width < widget_width) width = widget_width;
- }
- else
- {
- /* get the total width */
- width += widget_width;
- }
- }
-
- return width;
-}
-
-rt_uint32_t rtgui_box_get_height(rtgui_box_t* box)
-{
- rtgui_list_t *node;
- rt_uint32_t height;
-
- height = 0;
- rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children))
- {
- rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
- rt_uint32_t widget_height;
-
- widget_height = rtgui_rect_height(widget->extent);
- if (box->orientation & RTGUI_HORIZONTAL)
- {
- /* get the max height */
- if (height < widget_height) height = widget_height;
- }
- else
- {
- /* get the total height */
- height += widget_height;
- }
- }
-
- return height;
-}
-#endif
-
diff --git a/rtgui/widgets/button.c b/rtgui/widgets/button.c
deleted file mode 100644
index 36e010f28a..0000000000
--- a/rtgui/widgets/button.c
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * File : button.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2009-10-16 Bernard first version
- */
-#include <rtgui/dc.h>
-#include <rtgui/widgets/button.h>
-#include <rtgui/rtgui_theme.h>
-
-static void _rtgui_button_constructor(rtgui_button_t *button)
-{
- /* init widget and set event handler */
- RTGUI_WIDGET(button)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- rtgui_widget_set_event_handler(RTGUI_WIDGET(button), rtgui_button_event_handler);
-
- /* un-press button */
- button->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
-
- /* set flag and on_button event handler */
- button->pressed_image = RT_NULL;
- button->unpressed_image = RT_NULL;
- button->on_button = RT_NULL;
-
- /* set gc */
- RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(button)) = default_foreground;
- RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(button)) = RTGUI_RGB(212, 208, 200);
- RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(button)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
-}
-
-static void _rtgui_button_destructor(rtgui_button_t *button)
-{
- if (button->pressed_image != RT_NULL)
- {
- rtgui_image_destroy(button->pressed_image);
- button->pressed_image = RT_NULL;
- }
-
- if (button->unpressed_image != RT_NULL)
- {
- rtgui_image_destroy(button->unpressed_image);
- button->unpressed_image = RT_NULL;
- }
-}
-
-rtgui_type_t *rtgui_button_type_get(void)
-{
- static rtgui_type_t *button_type = RT_NULL;
-
- if (!button_type)
- {
- button_type = rtgui_type_create("button", RTGUI_LABEL_TYPE,
- sizeof(rtgui_button_t),
- RTGUI_CONSTRUCTOR(_rtgui_button_constructor),
- RTGUI_DESTRUCTOR(_rtgui_button_destructor));
- }
-
- return button_type;
-}
-
-rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_button* btn;
-
- RT_ASSERT(widget != RT_NULL);
-
- btn = (struct rtgui_button*) widget;
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL ) widget->on_draw(widget, event);
- else
-#endif
- rtgui_theme_draw_button(btn);
- break;
-
- case RTGUI_EVENT_KBD:
- {
- struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*) event;
-
- if ((ekbd->key == RTGUIK_RETURN) || (ekbd->key == RTGUIK_SPACE))
- {
- if (RTGUI_KBD_IS_DOWN(ekbd))
- {
- btn->flag |= RTGUI_BUTTON_FLAG_PRESS;
- }
- else
- {
- btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
- }
-
- /* draw button */
- rtgui_theme_draw_button(btn);
-
- if ((btn->flag & RTGUI_BUTTON_FLAG_PRESS) && (btn->on_button != RT_NULL))
- {
- /* call on button handler */
- btn->on_button(widget, event);
- }
- }
- }
- break;
-
- case RTGUI_EVENT_MOUSE_BUTTON:
- {
- struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
-
- if (btn->flag & RTGUI_BUTTON_TYPE_PUSH)
- {
- /* it's a push button */
- if (emouse->button & RTGUI_MOUSE_BUTTON_UP)
- {
- if (btn->flag & RTGUI_BUTTON_FLAG_PRESS)
- btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
- else
- btn->flag |= RTGUI_BUTTON_FLAG_PRESS;
-
- /* draw button */
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL ) widget->on_draw(widget, event);
- else
-#endif
- rtgui_theme_draw_button(btn);
-
- if (btn->on_button != RT_NULL)
- {
- /* call on button handler */
- btn->on_button(widget, event);
- }
-
-#ifndef RTGUI_USING_SMALL_SIZE
- /* invokes call back */
- if (widget->on_mouseclick != RT_NULL &&
- emouse->button & RTGUI_MOUSE_BUTTON_UP)
- return widget->on_mouseclick(widget, event);
-#endif
- }
- }
- else
- {
- if (emouse->button & RTGUI_MOUSE_BUTTON_LEFT)
- {
- /* it's a normal button */
- if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
- {
- btn->flag |= RTGUI_BUTTON_FLAG_PRESS;
- }
- else
- {
- btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
- }
-
- /* draw button */
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL ) widget->on_draw(widget, event);
- else
-#endif
- rtgui_theme_draw_button(btn);
-
-#ifndef RTGUI_USING_SMALL_SIZE
- /* invokes call back */
- if (widget->on_mouseclick != RT_NULL &&
- emouse->button & RTGUI_MOUSE_BUTTON_UP)
- return widget->on_mouseclick(widget, event);
-#endif
-
- if (!(btn->flag & RTGUI_BUTTON_FLAG_PRESS) && (btn->on_button != RT_NULL))
- {
- /* call on button handler */
- btn->on_button(widget, event);
- }
- }
-
- }
-
- return RT_TRUE;
- }
- }
-
- return RT_FALSE;
-}
-
-rtgui_button_t* rtgui_button_create(char* text)
-{
- struct rtgui_button* btn;
-
- btn = (struct rtgui_button*) rtgui_widget_create (RTGUI_BUTTON_TYPE);
- if (btn != RT_NULL)
- {
- rtgui_rect_t rect;
-
- /* set default rect */
- rtgui_font_get_metrics(rtgui_font_default(), text, &rect);
- rect.x2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1);
- rect.y2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1);
- rtgui_widget_set_rect(RTGUI_WIDGET(btn), &rect);
- rtgui_label_set_text(RTGUI_LABEL(btn), text);
- }
-
- return btn;
-}
-
-rtgui_button_t* rtgui_pushbutton_create(char* text)
-{
- rtgui_button_t* btn;
-
- btn = rtgui_button_create(text);
- if (btn != RT_NULL) btn->flag |= RTGUI_BUTTON_TYPE_PUSH;
-
- return btn;
-}
-
-void rtgui_button_destroy(rtgui_button_t* btn)
-{
- rtgui_widget_destroy(RTGUI_WIDGET(btn));
-}
-
-void rtgui_button_set_pressed_image(rtgui_button_t* btn, rtgui_image_t* image)
-{
- RT_ASSERT(btn != RT_NULL);
-
- btn->pressed_image = image;
-}
-
-void rtgui_button_set_unpressed_image(rtgui_button_t* btn, rtgui_image_t* image)
-{
- RT_ASSERT(btn != RT_NULL);
-
- btn->unpressed_image = image;
-}
-
-void rtgui_button_set_onbutton(rtgui_button_t* btn, rtgui_onbutton_func_t func)
-{
- RT_ASSERT(btn != RT_NULL);
-
- btn->on_button = func;
-}
-
diff --git a/rtgui/widgets/checkbox.c b/rtgui/widgets/checkbox.c
deleted file mode 100644
index 46844eec23..0000000000
--- a/rtgui/widgets/checkbox.c
+++ /dev/null
@@ -1,140 +0,0 @@
-#include <rtgui/dc.h>
-#include <rtgui/rtgui_theme.h>
-#include <rtgui/widgets/checkbox.h>
-
-static void _rtgui_checkbox_constructor(rtgui_checkbox_t *box)
-{
- /* init widget and set event handler */
- RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_checkbox_event_handler);
-
- /* set status */
- box->status_down = RTGUI_CHECKBOX_STATUS_UNCHECKED;
-
- /* set default gc */
- RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(box)) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
-}
-
-rtgui_type_t *rtgui_checkbox_type_get(void)
-{
- static rtgui_type_t *checkbox_type = RT_NULL;
-
- if (!checkbox_type)
- {
- checkbox_type = rtgui_type_create("checkbox", RTGUI_LABEL_TYPE,
- sizeof(rtgui_checkbox_t), RTGUI_CONSTRUCTOR(_rtgui_checkbox_constructor), RT_NULL);
- }
-
- return checkbox_type;
-}
-
-rt_bool_t rtgui_checkbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_checkbox* box = (struct rtgui_checkbox*)widget;
-
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL)
- {
- return widget->on_draw(widget, event);
- }
- else
-#endif
- rtgui_theme_draw_checkbox(box);
- break;
-
- case RTGUI_EVENT_MOUSE_BUTTON:
- {
- if (RTGUI_WIDGET_IS_ENABLE(widget) && !RTGUI_WIDGET_IS_HIDE(widget))
- {
- struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
- if (emouse->button & RTGUI_MOUSE_BUTTON_LEFT &&
- emouse->button & RTGUI_MOUSE_BUTTON_UP)
- {
- /* set focus */
- rtgui_widget_focus(widget);
-
- if (box->status_down & RTGUI_CHECKBOX_STATUS_UNCHECKED)
- {
- /* check it */
- box->status_down = RTGUI_CHECKBOX_STATUS_CHECKED;
- }
- else
- {
- /* un-check it */
- box->status_down = RTGUI_CHECKBOX_STATUS_UNCHECKED;
- }
- }
-
- /* draw checkbox */
- rtgui_theme_draw_checkbox(box);
-
-#ifndef RTGUI_USING_SMALL_SIZE
- /* call user callback */
- if (widget->on_mouseclick != RT_NULL)
- {
- return widget->on_mouseclick(widget, event);
- }
-#endif
- }
-
- return RT_TRUE;
- }
- }
-
- return RT_FALSE;
-}
-
-struct rtgui_checkbox* rtgui_checkbox_create(unsigned char* text, rt_bool_t checked)
-{
- struct rtgui_checkbox* box;
-
- box = (struct rtgui_checkbox*) rtgui_widget_create (RTGUI_CHECKBOX_TYPE);
- if (box != RT_NULL)
- {
- rtgui_rect_t rect;
-
- /* set default rect */
- rtgui_font_get_metrics(rtgui_font_default(), text, &rect);
- rect.x2 += RTGUI_BORDER_DEFAULT_WIDTH + 5 + (RTGUI_BORDER_DEFAULT_WIDTH << 1);
- rect.y2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1);
-
- rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect);
- rtgui_label_set_text(RTGUI_LABEL(box), text);
-
- if (checked == RT_TRUE)
- box->status_down = RTGUI_CHECKBOX_STATUS_CHECKED;
- else
- box->status_down = RTGUI_CHECKBOX_STATUS_UNCHECKED;
- }
-
- return box;
-}
-
-void rtgui_checkbox_destroy(rtgui_checkbox_t* box)
-{
- rtgui_widget_destroy(RTGUI_WIDGET(box));
-}
-
-void rtgui_checkbox_set_checked(rtgui_checkbox_t* checkbox, rt_bool_t checked)
-{
- RT_ASSERT(checkbox != RT_NULL);
- if (checked == RT_TRUE)
- checkbox->status_down = RTGUI_CHECKBOX_STATUS_CHECKED;
- else
- checkbox->status_down = RTGUI_CHECKBOX_STATUS_UNCHECKED;
-
-}
-
-rt_bool_t rtgui_checkbox_get_checked(rtgui_checkbox_t* checkbox)
-{
- RT_ASSERT(checkbox != RT_NULL);
-
- if (checkbox->status_down == RTGUI_CHECKBOX_STATUS_CHECKED)
- return RT_TRUE;
-
- return RT_FALSE;
-}
-
diff --git a/rtgui/widgets/container.c b/rtgui/widgets/container.c
deleted file mode 100644
index 35475a904a..0000000000
--- a/rtgui/widgets/container.c
+++ /dev/null
@@ -1,303 +0,0 @@
-/*
- * File : container.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2009-10-16 Bernard first version
- */
-#include <rtgui/widgets/toplevel.h>
-#include <rtgui/widgets/container.h>
-
-static void _rtgui_container_constructor(rtgui_container_t *container)
-{
- /* set event handler and init field */
- rtgui_widget_set_event_handler(RTGUI_WIDGET(container), rtgui_container_event_handler);
- rtgui_list_init(&(container->children));
-
- /* set focused widget to itself */
- container->focused = RTGUI_WIDGET(container);
- /* set container as focusable widget */
- RTGUI_WIDGET(container)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
-}
-
-static void _rtgui_container_destructor(rtgui_container_t *container)
-{
- /* destroy children of container */
- rtgui_container_destroy_children(container);
-}
-
-static void _rtgui_container_update_toplevel(rtgui_container_t* container)
-{
- struct rtgui_list_node* node;
-
- rtgui_list_foreach(node, &(container->children))
- {
- rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling);
- /* set child toplevel */
- child->toplevel = rtgui_widget_get_toplevel(RTGUI_WIDGET(container));
-
- if (RTGUI_IS_CONTAINER(child))
- {
- _rtgui_container_update_toplevel(RTGUI_CONTAINER(child));
- }
- }
-}
-
-rtgui_type_t *rtgui_container_type_get(void)
-{
- static rtgui_type_t *container_type = RT_NULL;
-
- if (!container_type)
- {
- container_type = rtgui_type_create("container", RTGUI_WIDGET_TYPE,
- sizeof(rtgui_container_t),
- RTGUI_CONSTRUCTOR(_rtgui_container_constructor),
- RTGUI_DESTRUCTOR(_rtgui_container_destructor));
- }
-
- return container_type;
-}
-
-rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_event_t* event)
-{
- /* handle in child widget */
- struct rtgui_list_node* node;
-
- rtgui_list_foreach(node, &(container->children))
- {
- struct rtgui_widget* w;
- w = rtgui_list_entry(node, struct rtgui_widget, sibling);
-
- if (w->event_handler(w, event) == RT_TRUE) return RT_TRUE;
- }
-
- return RT_FALSE;
-}
-
-rt_bool_t rtgui_container_dispatch_mouse_event(rtgui_container_t *container, struct rtgui_event_mouse* event)
-{
- /* handle in child widget */
- struct rtgui_list_node* node;
-
- rtgui_list_foreach(node, &(container->children))
- {
- struct rtgui_widget* w;
- w = rtgui_list_entry(node, struct rtgui_widget, sibling);
- if (rtgui_rect_contains_point(&(w->extent), event->x, event->y) == RT_EOK)
- {
- if (w->event_handler(w, (rtgui_event_t*)event) == RT_TRUE) return RT_TRUE;
- }
- }
-
- return RT_FALSE;
-}
-
-rt_bool_t rtgui_container_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
-{
- rtgui_container_t *container = RTGUI_CONTAINER(widget);
-
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL)
- {
- return widget->on_draw(widget, event);
- }
-#endif
-
- rtgui_container_dispatch_event(container, event);
- break;
-
- case RTGUI_EVENT_KBD:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_key != RT_NULL)
- {
- return widget->on_key(widget, event);
- }
- else
-#endif
- {
- /* let parent to handle keyboard event */
- if (widget->parent != RT_NULL && widget->parent != widget->toplevel)
- {
- return widget->parent->event_handler(widget->parent, event);
- }
- }
- break;
-
- case RTGUI_EVENT_MOUSE_BUTTON:
- /* handle in child widget */
- if (rtgui_container_dispatch_mouse_event(container,
- (struct rtgui_event_mouse*)event) == RT_FALSE)
- {
-#ifndef RTGUI_USING_SMALL_SIZE
- /* handle event in current widget */
- if (widget->on_mouseclick != RT_NULL)
- {
- return widget->on_mouseclick(widget, event);
- }
-#endif
- }
- else return RT_TRUE;
- break;
-
- case RTGUI_EVENT_MOUSE_MOTION:
- if (rtgui_container_dispatch_mouse_event(container,
- (struct rtgui_event_mouse*)event) == RT_FALSE)
- {
-#ifndef RTGUI_USING_SMALL_SIZE
-#if 0
- /* handle event in current widget */
- if (widget->on_mousemotion != RT_NULL)
- {
- return widget->on_mousemotion(widget, event);
- }
-#endif
-#endif
- }
- else return RT_TRUE;
- break;
-
- case RTGUI_EVENT_COMMAND:
- if (rtgui_container_dispatch_event(container, event) == RT_FALSE)
- {
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_command != RT_NULL)
- {
- return widget->on_command(widget, event);
- }
-#endif
- }
- else return RT_TRUE;
- break;
-
- case RTGUI_EVENT_RESIZE:
- if (rtgui_container_dispatch_event(container, event) == RT_FALSE)
- {
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_size != RT_NULL)
- return widget->on_size(widget, event);
-#endif
- }
- else return RT_TRUE;
- break;
-
- default:
- /* call parent widget event handler */
- return rtgui_widget_event_handler(widget, event);
- }
-
- return RT_FALSE;
-}
-
-/*
- * This function will add a child to a container widget
- * Note: this function will not change the widget layout
- * the layout is the responsibility of layout widget, such as box.
- */
-void rtgui_container_add_child(rtgui_container_t *container, rtgui_widget_t* child)
-{
- RT_ASSERT(container != RT_NULL);
- RT_ASSERT(child != RT_NULL);
-
- /* set parent and toplevel widget */
- child->parent = RTGUI_WIDGET(container);
- /* put widget to parent's children list */
- rtgui_list_append(&(container->children), &(child->sibling));
-
- /* update children toplevel */
- if (RTGUI_WIDGET(container)->toplevel != RT_NULL &&
- RTGUI_IS_TOPLEVEL(RTGUI_WIDGET(container)->toplevel))
- {
- child->toplevel = rtgui_widget_get_toplevel(RTGUI_WIDGET(container));
-
- /* update all child toplevel */
- if (RTGUI_IS_CONTAINER(child))
- {
- _rtgui_container_update_toplevel(RTGUI_CONTAINER(child));
- }
- }
-}
-
-/* remove a child to widget */
-void rtgui_container_remove_child(rtgui_container_t *container, rtgui_widget_t* child)
-{
- RT_ASSERT(container != RT_NULL);
- RT_ASSERT(child != RT_NULL);
-
- if (child == container->focused)
- {
- /* set focused to itself */
- container->focused = RTGUI_WIDGET(container);
-
- rtgui_widget_focus(RTGUI_WIDGET(container));
- }
-
- /* remove widget from parent's children list */
- rtgui_list_remove(&(container->children), &(child->sibling));
-
- /* set parent and toplevel widget */
- child->parent = RT_NULL;
- child->toplevel = RT_NULL;
-}
-
-/* destroy all children of container */
-void rtgui_container_destroy_children(rtgui_container_t *container)
-{
- struct rtgui_list_node* node;
-
- if (container == RT_NULL) return;
-
- node = container->children.next;
- while (node != RT_NULL)
- {
- rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling);
-
- if (RTGUI_IS_CONTAINER(child))
- {
- /* break parent firstly */
- child->parent = RT_NULL;
-
- /* destroy children of child */
- rtgui_container_destroy_children(RTGUI_CONTAINER(child));
- }
-
- /* remove widget from parent's children list */
- rtgui_list_remove(&(container->children), &(child->sibling));
-
- /* set parent and toplevel widget */
- child->parent = RT_NULL;
-
- /* destroy object and remove from parent */
- rtgui_object_destroy(RTGUI_OBJECT(child));
-
- node = container->children.next;
- }
-
- container->children.next = RT_NULL;
- container->focused = RTGUI_WIDGET(container);
- if (RTGUI_WIDGET(container)->parent != RT_NULL)
- rtgui_widget_focus(RTGUI_WIDGET(container));
-
- /* update widget clip */
- rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(RTGUI_WIDGET(container)->toplevel));
-}
-
-rtgui_widget_t* rtgui_container_get_first_child(rtgui_container_t* container)
-{
- rtgui_widget_t* child = RT_NULL;
-
- if (container->children.next != RT_NULL)
- {
- child = rtgui_list_entry(container->children.next, rtgui_widget_t, sibling);
- }
-
- return child;
-}
diff --git a/rtgui/widgets/filelist_view.c b/rtgui/widgets/filelist_view.c
deleted file mode 100644
index 8d75f9b56d..0000000000
--- a/rtgui/widgets/filelist_view.c
+++ /dev/null
@@ -1,729 +0,0 @@
-/*
- * File : filelist_view.c
- * This file is part of RTGUI in RT-Thread RTOS
- * COPYRIGHT (C) 2010, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2010-01-06 Bernard first version
- */
-
-#include <rtgui/rtgui_object.h>
-#include <rtgui/rtgui_system.h>
-#include <rtgui/rtgui_theme.h>
-
-#include <rtgui/list.h>
-#include <rtgui/image.h>
-#include <rtgui/widgets/view.h>
-#include <rtgui/widgets/workbench.h>
-#include <rtgui/widgets/filelist_view.h>
-
-#ifdef _WIN32
-#include <io.h>
-#include <dirent.h>
-#include <sys/stat.h>
-#define PATH_SEPARATOR '\\'
-#define stat _stat
-#else
-#include <dfs_posix.h>
-#define PATH_SEPARATOR '/'
-#endif
-
-#include <string.h>
-
-#define RTGUI_FILELIST_MARGIN 5
-
-const static char * file_xpm[] = {
-"16 16 21 1",
-" c None",
-". c #999999",
-"+ c #818181",
-"@ c #FFFFFF",
-"# c #ECECEC",
-"$ c #EAEAEA",
-"% c #EBEBEB",
-"& c #EDEDED",
-"* c #F0F0F0",
-"= c #C4C4C4",
-"- c #C5C5C5",
-"; c #C6C6C6",
-"> c #C7C7C7",
-", c #EEEEEE",
-"' c #EDEDE5",
-") c #EDEDE6",
-"! c #EFEFEF",
-"~ c #C8C8C8",
-"{ c #F1F1F1",
-"] c #F2F2F2",
-"^ c #959595",
-".++++++++++++ ",
-"+@@@@@@@@@@@@+ ",
-"+@#$$%%%##&*@+ ",
-"+@$=--;;;;>*@+ ",
-"+@$%%###&&,*@+ ",
-"+@%-;;;;;;>*@+ ",
-"+@%%##&&'#,*@+ ",
-"+@%;;;;,,),*@+ ",
-"+@##&&,,!!!*@+ ",
-"+@#;;;>>~~~*@+ ",
-"+@#&,,!!*{{{@+ ",
-"+@&;>>~~~{{]@+ ",
-"+@&&,!!**{]]@+ ",
-"+@@@@@@@@@@@@+ ",
-"^++++++++++++^ ",
-" "};
-
-const static char * folder_xpm[] = {
-"16 16 121 2",
-" c None",
-". c #D9B434",
-"+ c #E1C25E",
-"@ c #E2C360",
-"# c #E2C35F",
-"$ c #DBB63C",
-"% c #DAB336",
-"& c #FEFEFD",
-"* c #FFFFFE",
-"= c #FFFEFE",
-"- c #FFFEFD",
-"; c #FBF7EA",
-"> c #E4C76B",
-", c #E3C76B",
-"' c #E6CD79",
-") c #E5CA74",
-"! c #DAAF35",
-"~ c #FEFCF7",
-"{ c #F8E48E",
-"] c #F5DE91",
-"^ c #F5E09F",
-"/ c #F6E1AC",
-"( c #FEFBEF",
-"_ c #FEFDF4",
-": c #FEFCF3",
-"< c #FEFCF1",
-"[ c #FEFBEE",
-"} c #FFFDFA",
-"| c #DAAF36",
-"1 c #DAAA36",
-"2 c #FDFAF1",
-"3 c #F5DE94",
-"4 c #F4DC93",
-"5 c #F2D581",
-"6 c #EDCA6A",
-"7 c #EACB6C",
-"8 c #EFD385",
-"9 c #EFD280",
-"0 c #EFD07A",
-"a c #EECF76",
-"b c #EECF72",
-"c c #FBF7E9",
-"d c #DAAE34",
-"e c #DAAB35",
-"f c #FBF6E8",
-"g c #EFD494",
-"h c #EECE88",
-"i c #E9C173",
-"j c #F6E9C9",
-"k c #FEFCF2",
-"l c #FEFCF0",
-"m c #DAAB36",
-"n c #DAA637",
-"o c #FFFDF8",
-"p c #FFFDF6",
-"q c #FFFCF5",
-"r c #FCF6D8",
-"s c #F8E694",
-"t c #F7E385",
-"u c #F6DF76",
-"v c #F5DB68",
-"w c #F4D85C",
-"x c #FCF4D7",
-"y c #DAA435",
-"z c #DAA136",
-"A c #FEFCF6",
-"B c #FCF2C8",
-"C c #FBEFB9",
-"D c #FAECAC",
-"E c #F9E89C",
-"F c #F7E38B",
-"G c #F6E07C",
-"H c #F6DC6C",
-"I c #F5D95D",
-"J c #F4D64F",
-"K c #F3D344",
-"L c #FCF3D0",
-"M c #DA9F35",
-"N c #DA9A36",
-"O c #FDFAF2",
-"P c #FAEDB3",
-"Q c #F9E9A4",
-"R c #F8E695",
-"S c #F7E285",
-"T c #F6DE76",
-"U c #F5DB65",
-"V c #F4D757",
-"W c #F3D449",
-"X c #F2D13B",
-"Y c #F1CE30",
-"Z c #FBF2CC",
-"` c #DA9835",
-" . c #DA9435",
-".. c #FEFAEF",
-"+. c #F9E9A1",
-"@. c #F8E591",
-"#. c #F7E181",
-"$. c #F6DE72",
-"%. c #F5DA63",
-"&. c #F4D754",
-"*. c #F3D347",
-"=. c #F2D039",
-"-. c #F1CD2E",
-";. c #F0CB26",
-">. c #FBF2CA",
-",. c #D98E33",
-"'. c #FAF0DC",
-"). c #F4DDA7",
-"!. c #F4DB9E",
-"~. c #F3DA96",
-"{. c #F3D88E",
-"]. c #F3D786",
-"^. c #F2D47F",
-"/. c #F2D379",
-"(. c #F1D272",
-"_. c #F1D06C",
-":. c #F1CF69",
-"<. c #F8EAC2",
-"[. c #D8882D",
-"}. c #D8872D",
-"|. c #D8862C",
-" ",
-" ",
-" ",
-" . + @ @ @ # $ ",
-" % & * = - * ; > , , , ' ) ",
-" ! ~ { ] ^ / ( _ : < ( [ } | ",
-" 1 2 3 4 5 6 7 8 9 0 a b c d ",
-" e f g h i j k : k l ( [ * m ",
-" n * o p q : r s t u v w x y ",
-" z A B C D E F G H I J K L M ",
-" N O P Q R S T U V W X Y Z ` ",
-" ...+.@.#.$.%.&.*.=.-.;.>. . ",
-" ,.'.).!.~.{.].^./.(._.:.<.,. ",
-" [.}.[.[.[.[.[.[.[.[.}.[.|. ",
-" ",
-" "};
-
-/* image for file and folder */
-static rtgui_image_t *file_image, *folder_image;
-static void rtgui_filelist_view_clear(rtgui_filelist_view_t* view);
-
-static void _rtgui_filelist_view_constructor(struct rtgui_filelist_view *view)
-{
- /* default rect */
- struct rtgui_rect rect = {0, 0, 200, 200};
-
- /* set default widget rect and set event handler */
- rtgui_widget_set_event_handler(RTGUI_WIDGET(view), rtgui_filelist_view_event_handler);
- rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
-
- RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
-
- view->current_item = 0;
- view->items_count = 0;
- view->page_items = 0;
-
- view->current_directory = RT_NULL;
- view->pattern = RT_NULL;
- RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
- RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL;
-
- file_image = rtgui_image_create_from_mem("xpm",
- (rt_uint8_t*)file_xpm, sizeof(file_xpm), RT_TRUE);
- folder_image = rtgui_image_create_from_mem("xpm",
- (rt_uint8_t*)folder_xpm, sizeof(folder_xpm), RT_TRUE);
-}
-
-rtgui_type_t *rtgui_filelist_view_type_get(void)
-{
- static rtgui_type_t *filelist_view_type = RT_NULL;
-
- if (!filelist_view_type)
- {
- filelist_view_type = rtgui_type_create("flview", RTGUI_VIEW_TYPE,
- sizeof(rtgui_filelist_view_t), RTGUI_CONSTRUCTOR(_rtgui_filelist_view_constructor), RT_NULL);
- }
-
- return filelist_view_type;
-}
-
-void rtgui_filelist_view_ondraw(struct rtgui_filelist_view* view)
-{
- struct rtgui_dc* dc;
- rt_uint16_t page_index, index;
- struct rtgui_file_item* item;
- struct rtgui_rect rect, item_rect, image_rect;
-
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
- if (dc == RT_NULL) return;
-
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
- rtgui_dc_fill_rect(dc, &rect);
-
- /* get item base rect */
- item_rect = rect;
- item_rect.y1 += 1;
- item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());
-
- /* get image base rect */
- image_rect.x1 = RTGUI_FILELIST_MARGIN; image_rect.y1 = 0;
- image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h;
- rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
-
- /* get current page */
- page_index = (view->current_item / view->page_items) * view->page_items;
- for (index = 0; index < view->page_items; index ++)
- {
- if (page_index + index >= view->items_count) break;
-
- item = &(view->items[page_index + index]);
-
- if (page_index + index == view->current_item)
- {
- rtgui_theme_draw_selected(dc, &item_rect);
- }
- else
- {
- /* draw background */
- rtgui_dc_fill_rect(dc, &item_rect);
- }
-
- /* draw item */
-
- if (item->type == RTGUI_FITEM_FILE)
- rtgui_image_blit(file_image, dc, &image_rect);
- else
- rtgui_image_blit(folder_image, dc, &image_rect);
-
- /* draw text */
- item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2;
- rtgui_dc_draw_text(dc, item->name, &item_rect);
- item_rect.x1 -= RTGUI_FILELIST_MARGIN + file_image->w + 2;
-
- /* move to next item position */
- item_rect.y1 += (rtgui_theme_get_selected_height() + 1);
- item_rect.y2 += (rtgui_theme_get_selected_height() + 1);
-
- image_rect.y1 += (rtgui_theme_get_selected_height() + 1);
- image_rect.y2 += (rtgui_theme_get_selected_height() + 1);
- }
-
- rtgui_dc_end_drawing(dc);
-}
-
-void rtgui_filelist_view_update_current(struct rtgui_filelist_view* view, rt_uint16_t old_item)
-{
- struct rtgui_dc* dc;
- struct rtgui_file_item* item;
- rtgui_rect_t rect, item_rect, image_rect;
-
- if (old_item/view->page_items != view->current_item/view->page_items)
- {
- /* it's not a same page, update all */
- rtgui_widget_update(RTGUI_WIDGET(view));
- return;
- }
-
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
- if (dc == RT_NULL) return;
-
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
-
- /* get old item rect */
- item_rect = rect;
- item_rect.y1 += 1;
- item_rect.y1 += (old_item % view->page_items) * (1 + rtgui_theme_get_selected_height());
- item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());
-
- /* get image rect */
- image_rect.x1 = RTGUI_FILELIST_MARGIN; image_rect.y1 = 0;
- image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h;
- rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
-
- /* draw old item */
- rtgui_dc_fill_rect(dc, &item_rect);
-
- item = &(view->items[old_item]);
- if (item->type == RTGUI_FITEM_FILE) /* draw item image */
- rtgui_image_blit(file_image, dc, &image_rect);
- else
- rtgui_image_blit(folder_image, dc, &image_rect);
-
- item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2;
- rtgui_dc_draw_text(dc, item->name, &item_rect);
-
- /* draw current item */
- item_rect = rect;
- item_rect.y1 += 1;
- item_rect.y1 += (view->current_item % view->page_items) * (1 + rtgui_theme_get_selected_height());
- item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());
-
- rtgui_theme_draw_selected(dc, &item_rect);
-
- /* get image base rect */
- image_rect.x1 = RTGUI_FILELIST_MARGIN; image_rect.y1 = 0;
- image_rect.x2 = RTGUI_FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h;
- rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
-
- item = &(view->items[view->current_item]);
- if (item->type == RTGUI_FITEM_FILE) /* draw item image */
- rtgui_image_blit(file_image, dc, &image_rect);
- else
- rtgui_image_blit(folder_image, dc, &image_rect);
-
- item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2;
- rtgui_dc_draw_text(dc, item->name, &item_rect);
-
- rtgui_dc_end_drawing(dc);
-}
-
-rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_filelist_view* view = RT_NULL;
-
- view = RTGUI_FILELIST_VIEW(widget);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- rtgui_filelist_view_ondraw(view);
- return RT_FALSE;
-
- case RTGUI_EVENT_RESIZE:
- {
- struct rtgui_event_resize* resize;
-
- resize = (struct rtgui_event_resize*)event;
-
- /* recalculate page items */
- if (file_image != RT_NULL)
- view->page_items = resize->h / (1 + rtgui_theme_get_selected_height());
- else
- view->page_items = resize->h / (2 + 14);
- }
- break;
-
- case RTGUI_EVENT_MOUSE_BUTTON:
- {
- rtgui_rect_t rect;
- struct rtgui_event_mouse* emouse;
-
- emouse = (struct rtgui_event_mouse*)event;
-
- /* calculate selected item */
-
- /* get physical extent information */
- rtgui_widget_get_rect(widget, &rect);
- rtgui_widget_rect_to_device(widget, &rect);
-
- if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
- {
- rt_uint16_t index;
- index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());
-
- if ((index < view->items_count) && (index < view->page_items))
- {
- rt_uint16_t old_item;
-
- old_item = view->current_item;
-
- /* set selected item */
- view->current_item = (old_item/view->page_items) * view->page_items + index;
- rtgui_filelist_view_update_current(view, old_item);
- }
- }
- }
- break;
-
- case RTGUI_EVENT_KBD:
- {
- struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
- if (ekbd->type == RTGUI_KEYDOWN)
- {
- rt_uint16_t old_item;
-
- old_item = view->current_item;
- switch (ekbd->key)
- {
- case RTGUIK_UP:
- if (view->current_item > 0)
- view->current_item --;
- rtgui_filelist_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_DOWN:
- if (view->current_item < view->items_count - 1)
- view->current_item ++;
- rtgui_filelist_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_LEFT:
- if (view->current_item - view->page_items >= 0)
- view->current_item -= view->page_items;
- rtgui_filelist_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_RIGHT:
- if (view->current_item + view->page_items < view->items_count - 1)
- view->current_item += view->page_items;
- rtgui_filelist_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_RETURN:
- if (view->items[view->current_item].type == RTGUI_FITEM_DIR)
- {
- char new_path[64];
-
- if (strcmp(view->items[view->current_item].name, ".") == 0) return RT_FALSE;
- if (strcmp(view->items[view->current_item].name, "..") == 0)
- {
- char *ptr;
- ptr = strrchr(view->current_directory, PATH_SEPARATOR);
-
- if (ptr == RT_NULL) return RT_FALSE;
- if (ptr == &(view->current_directory[0]))
- {
- /* it's root directory */
- new_path[0] = PATH_SEPARATOR;
- new_path[1] = '\0';
- }
- else
- {
- strncpy(new_path, view->current_directory, ptr - view->current_directory + 1);
- new_path[ptr - view->current_directory] = '\0';
- }
- }
- else if (view->current_item == 0 &&
-#ifdef _WIN32
- (view->current_directory[1] == ':') && (view->current_directory[2] == '\\'))
-#else
- (view->current_directory[0] == '/') && (view->current_directory[1] == '\0'))
-#endif
- {
- if (RTGUI_VIEW(view)->modal_show == RT_TRUE)
- {
- rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_CANCEL);
- }
- else
- {
- rtgui_filelist_view_destroy(view);
- }
-
- return RT_FALSE;
- }
- else
- {
- if (view->current_directory[strlen(view->current_directory) - 1] != PATH_SEPARATOR)
- rt_snprintf(new_path, sizeof(new_path), "%s%c%s",view->current_directory, PATH_SEPARATOR,
- view->items[view->current_item].name);
- else
- rt_snprintf(new_path, sizeof(new_path), "%s%s",view->current_directory,
- view->items[view->current_item].name);
- }
- rtgui_filelist_view_set_directory(view, new_path);
- }
- else
- {
- if (RTGUI_VIEW(view)->modal_show == RT_TRUE)
- {
- rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_OK);
- }
- }
- return RT_FALSE;
-
- default:
- break;
- }
- }
- }
- return RT_FALSE;
- }
-
- /* use view event handler */
- return rtgui_view_event_handler(widget, event);
-}
-
-rtgui_filelist_view_t* rtgui_filelist_view_create(rtgui_workbench_t* workbench,
- const char* directory, const char* pattern, const rtgui_rect_t* rect)
-{
- struct rtgui_filelist_view* view = RT_NULL;
-
- /* create a new view */
- view = (struct rtgui_filelist_view*) rtgui_widget_create(RTGUI_FILELIST_VIEW_TYPE);
- if (view != RT_NULL)
- {
- view->items = RT_NULL;
- view->pattern = rt_strdup(pattern);
- view->page_items = rtgui_rect_height(*rect) / (1 + rtgui_theme_get_selected_height());
- rtgui_filelist_view_set_directory(view, directory);
-
- rtgui_workbench_add_view(workbench, RTGUI_VIEW(view));
- }
-
- return view;
-}
-
-void rtgui_filelist_view_destroy(rtgui_filelist_view_t* view)
-{
- /* delete all file items */
- rtgui_filelist_view_clear(view);
- /* delete current directory and pattern */
- rtgui_free(view->current_directory); view->current_directory = RT_NULL;
- rtgui_free(view->pattern); view->pattern = RT_NULL;
-
- /* delete image */
- rtgui_image_destroy(file_image);
- rtgui_image_destroy(folder_image);
-
- /* destroy view */
- rtgui_widget_destroy(RTGUI_WIDGET(view));
-}
-
-/* clear all file items */
-static void rtgui_filelist_view_clear(rtgui_filelist_view_t* view)
-{
- rt_uint32_t index;
- struct rtgui_file_item* item;
-
- for (index = 0; index < view->items_count; index ++)
- {
- item = &(view->items[index]);
-
- /* release item name */
- rt_free(item->name);
- item->name = RT_NULL;
- }
-
- /* release items */
- rtgui_free(view->items);
- view->items = RT_NULL;
-
- view->items_count = 0;
- view->current_item = 0;
-}
-
-void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char* directory)
-{
- char fullpath[256];
- struct rtgui_file_item *item;
-
- RT_ASSERT(view != RT_NULL);
-
- /* clear file items firstly */
- rtgui_filelist_view_clear(view);
- if (directory != RT_NULL)
- {
- DIR* dir;
- struct stat s;
- rt_uint32_t index;
- struct dirent* dirent;
-
- view->items_count = 0;
- dir = opendir(directory);
- if (dir == RT_NULL) goto __return;
-
- /* current directory exists, set it */
- if (view->current_directory != RT_NULL) rt_free(view->current_directory);
- view->current_directory = rt_strdup(directory);
-
- do
- {
- dirent = readdir(dir);
- if (dirent == RT_NULL) break;
-
- if (strcmp(dirent->d_name, ".") == 0) continue;
- if (strcmp(dirent->d_name, "..") == 0) continue;
-
- view->items_count ++;
- } while (dirent != RT_NULL);
- closedir(dir);
-
- view->items_count ++; /* root directory for [x] exit, others for .. */
-
- view->items = (struct rtgui_file_item*) rtgui_malloc(sizeof(struct rtgui_file_item) * view->items_count);
- if (view->items == RT_NULL) return; /* no memory */
-
- index = 0;
- if (directory[0] == '/' && directory[1] != '\0')
- {
- item = &(view->items[0]);
-
- /* add .. directory */
- item->name = rt_strdup("..");
- item->type = RTGUI_FITEM_DIR;
- item->size = 0;
-
- index ++;
- }
- else
- {
- item = &(view->items[0]);
-
- /* add .. directory */
- item->name = rt_strdup("�˳��ļ����");
- item->type = RTGUI_FITEM_DIR;
- item->size = 0;
-
- index ++;
- }
-
- /* reopen directory */
- dir = opendir(directory);
- for (; index < view->items_count; index ++)
- {
- dirent = readdir(dir);
- if (dirent == RT_NULL) break;
-
- item = &(view->items[index]);
- item->name = rt_strdup(dirent->d_name);
-
- rt_memset(&s, 0, sizeof(struct stat));
-
- /* build full path for the file */
- if (directory[strlen(directory) - 1] != PATH_SEPARATOR)
- rt_sprintf(fullpath, "%s%c%s", directory, PATH_SEPARATOR, dirent->d_name);
- else
- rt_sprintf(fullpath, "%s%s", directory, dirent->d_name);
-
- stat(fullpath, &s);
- if ( s.st_mode & S_IFDIR )
- {
- item->type = RTGUI_FITEM_DIR;
- item->size = 0;
- }
- else
- {
- item->type = RTGUI_FITEM_FILE;
- item->size = s.st_size;
- }
- }
-
- closedir(dir);
- }
-
- view->current_item = 0;
-
-__return:
- /* update view */
- rtgui_widget_update(RTGUI_WIDGET(view));
-}
-
-void rtgui_filelist_get_fullpath(rtgui_filelist_view_t* view, char* path, rt_size_t len)
-{
- RT_ASSERT(view != RT_NULL);
-
- rt_sprintf(path, "%s%c%s", view->current_directory, PATH_SEPARATOR,
- view->items[view->current_item].name);
-}
diff --git a/rtgui/widgets/iconbox.c b/rtgui/widgets/iconbox.c
deleted file mode 100644
index 7a25f3df26..0000000000
--- a/rtgui/widgets/iconbox.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * File : iconbox.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2009-10-16 Bernard first version
- */
-#include <rtgui/dc.h>
-#include <rtgui/widgets/iconbox.h>
-#include <rtgui/rtgui_theme.h>
-
-static void _rtgui_iconbox_constructor(rtgui_iconbox_t *iconbox)
-{
- /* init widget and set event handler */
- RTGUI_WIDGET(iconbox)->flag |= RTGUI_WIDGET_FLAG_TRANSPARENT;
- rtgui_widget_set_event_handler(RTGUI_WIDGET(iconbox), rtgui_iconbox_event_handler);
-
- /* set proper of control */
- iconbox->image = RT_NULL;
- iconbox->selected = RT_FALSE;
- iconbox->text = RT_NULL;
- iconbox->text_position = RTGUI_ICONBOX_TEXT_BELOW;
-}
-
-static void _rtgui_iconbox_destructor(rtgui_iconbox_t *iconbox)
-{
- if (iconbox->image != RT_NULL)
- {
- rtgui_image_destroy(iconbox->image);
- iconbox->image = RT_NULL;
- }
-
- rt_free(iconbox->text);
- iconbox->text = RT_NULL;
-}
-
-rtgui_type_t *rtgui_iconbox_type_get(void)
-{
- static rtgui_type_t *iconbox_type = RT_NULL;
-
- if (!iconbox_type)
- {
- iconbox_type = rtgui_type_create("iconbox", RTGUI_WIDGET_TYPE,
- sizeof(rtgui_iconbox_t), RTGUI_CONSTRUCTOR(_rtgui_iconbox_constructor),
- RTGUI_DESTRUCTOR(_rtgui_iconbox_destructor));
- }
-
- return iconbox_type;
-}
-
-rt_bool_t rtgui_iconbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_iconbox* iconbox = (struct rtgui_iconbox*)widget;
-
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else
-#endif
- {
- rtgui_theme_draw_iconbox(iconbox);
- }
-
- break;
- }
-
- return RT_FALSE;
-}
-
-struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image,
- const char* text,
- int position)
-{
- struct rtgui_iconbox* iconbox;
-
- iconbox = (struct rtgui_iconbox*)rtgui_widget_create(RTGUI_ICONBOX_TYPE);
- if (iconbox != RT_NULL)
- {
- rtgui_rect_t rect = {0, 0, 0, 0}, text_rect;
-
- rect.x2 = image->w;
- rect.y2 = image->h;
-
- /* get text rect */
- rtgui_font_get_metrics(rtgui_font_default(), text, &text_rect);
- if (position == RTGUI_ICONBOX_TEXT_BELOW)
- {
- rect.y2 += RTGUI_WIDGET_DEFAULT_MARGIN;
- if (text_rect.x2 > rect.x2)
- {
- rect.x2 = text_rect.x2;
- }
- rect.y2 += text_rect.y2;
- }
- else if (position == RTGUI_ICONBOX_TEXT_RIGHT)
- {
- rect.x2 += RTGUI_WIDGET_DEFAULT_MARGIN;
- if (text_rect.y2 > rect.y2)
- {
- rect.y2 = text_rect.y2;
- }
- rect.x2 += text_rect.x2;
- }
-
- /* set widget rect */
- rtgui_widget_set_rect(RTGUI_WIDGET(iconbox), &rect);
-
- /* set image and text position */
- iconbox->image = image;
- iconbox->text = (char*)rt_strdup((const char*)text);
- iconbox->text_position = position;
- }
-
- return iconbox;
-}
-
-void rtgui_iconbox_destroy(struct rtgui_iconbox* iconbox)
-{
- rtgui_widget_destroy(RTGUI_WIDGET(iconbox));
-}
-
-void rtgui_iconbox_set_text_position(struct rtgui_iconbox* iconbox, int position)
-{
- rtgui_rect_t rect = {0, 0, 0, 0}, text_rect;
-
- RT_ASSERT(iconbox != RT_NULL);
-
- iconbox->text_position = position;
-
- /* set mini width and height */
- rect.x2 = iconbox->image->w;
- rect.y2 = iconbox->image->h;
-
- /* get text rect */
- if (iconbox->text != RT_NULL)
- {
- rtgui_font_get_metrics(rtgui_font_default(),
- iconbox->text, &text_rect);
- if (position == RTGUI_ICONBOX_TEXT_BELOW)
- {
- rect.y2 += RTGUI_WIDGET_DEFAULT_MARGIN;
- if (text_rect.x2 > rect.x2)
- {
- rect.x2 = text_rect.x2;
- }
- rect.y2 += text_rect.y2;
- }
- else if (position == RTGUI_ICONBOX_TEXT_RIGHT)
- {
- rect.x2 += RTGUI_WIDGET_DEFAULT_MARGIN;
- if (text_rect.y2 > rect.y2)
- {
- rect.y2 = text_rect.y2;
- }
- rect.x2 += text_rect.x2;
- }
- }
-
-#ifndef RTGUI_USING_SMALL_SIZE
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(iconbox), rect.x2);
- rtgui_widget_set_miniheight(RTGUI_WIDGET(iconbox), rect.y2);
-#endif
-}
diff --git a/rtgui/widgets/label.c b/rtgui/widgets/label.c
deleted file mode 100644
index ae5448080c..0000000000
--- a/rtgui/widgets/label.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * File : label.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2009-10-16 Bernard first version
- */
-#include <rtgui/dc.h>
-#include <rtgui/widgets/label.h>
-#include <rtgui/rtgui_system.h>
-#include <rtgui/rtgui_theme.h>
-
-static void _rtgui_label_constructor(rtgui_label_t *label)
-{
- /* init widget and set event handler */
- rtgui_widget_set_event_handler(RTGUI_WIDGET(label), rtgui_label_event_handler);
-
- /* set field */
- label->text = RT_NULL;
-}
-
-static void _rtgui_label_destructor(rtgui_label_t *label)
-{
- /* release text memory */
- rt_free(label->text);
- label->text = RT_NULL;
-}
-
-rtgui_type_t *rtgui_label_type_get(void)
-{
- static rtgui_type_t *label_type = RT_NULL;
-
- if (!label_type)
- {
- label_type = rtgui_type_create("label", RTGUI_WIDGET_TYPE,
- sizeof(rtgui_label_t),
- RTGUI_CONSTRUCTOR(_rtgui_label_constructor),
- RTGUI_DESTRUCTOR(_rtgui_label_destructor));
- }
-
- return label_type;
-}
-
-rt_bool_t rtgui_label_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_label* label;
-
- RT_ASSERT(widget != RT_NULL);
-
- label = (struct rtgui_label*) widget;
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- rtgui_theme_draw_label(label);
- break;
- }
-
- return RT_FALSE;
-}
-
-rtgui_label_t* rtgui_label_create(const char* text)
-{
- struct rtgui_label* label;
-
- label = (struct rtgui_label*) rtgui_widget_create(RTGUI_LABEL_TYPE);
- if (label != RT_NULL)
- {
- rtgui_rect_t rect;
-
- /* set default rect */
- rtgui_font_get_metrics(rtgui_font_default(), text, &rect);
- rect.x2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1);
- rect.y2 += (RTGUI_BORDER_DEFAULT_WIDTH << 1);
- rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
-
- /* set text */
- label->text = (char*)rt_strdup((const char*)text);
- }
-
- return label;
-}
-
-void rtgui_label_destroy(rtgui_label_t* label)
-{
- rtgui_widget_destroy(RTGUI_WIDGET(label));
-}
-
-char* rtgui_label_get_text(rtgui_label_t* label)
-{
- RT_ASSERT(label != RT_NULL);
-
- return label->text;
-}
-
-void rtgui_label_set_text(rtgui_label_t* label, const char* text)
-{
- RT_ASSERT(label != RT_NULL);
-
- if (label->text != RT_NULL)
- {
- /* release old text memory */
- rt_free(label->text);
- }
-
- if (text != RT_NULL) label->text = (char*)rt_strdup((const char*)text);
- else label->text = RT_NULL;
-
- /* update widget */
- rtgui_theme_draw_label(label);
-}
diff --git a/rtgui/widgets/list_view.c b/rtgui/widgets/list_view.c
deleted file mode 100644
index 857a9454a1..0000000000
--- a/rtgui/widgets/list_view.c
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * File : list_view.c
- * This file is part of RTGUI in RT-Thread RTOS
- * COPYRIGHT (C) 2010, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2010-01-06 Bernard first version
- */
-
-#include <rtgui/rtgui_theme.h>
-#include <rtgui/widgets/list_view.h>
-
-#define LIST_MARGIN 5
-
-static void _rtgui_list_view_constructor(struct rtgui_list_view *view)
-{
- /* default rect */
- struct rtgui_rect rect = {0, 0, 200, 200};
-
- /* set default widget rect and set event handler */
- rtgui_widget_set_event_handler(RTGUI_WIDGET(view),rtgui_list_view_event_handler);
- rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
-
- RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
-
- view->current_item = 0;
- view->items_count = 0;
- view->page_items = 0;
-
- RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
- RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL;
-}
-
-rtgui_type_t *rtgui_list_view_type_get(void)
-{
- static rtgui_type_t *list_view_type = RT_NULL;
-
- if (!list_view_type)
- {
- list_view_type = rtgui_type_create("listview", RTGUI_VIEW_TYPE,
- sizeof(rtgui_list_view_t), RTGUI_CONSTRUCTOR(_rtgui_list_view_constructor), RT_NULL);
- }
-
- return list_view_type;
-}
-
-void rtgui_list_view_ondraw(struct rtgui_list_view* view)
-{
- struct rtgui_rect rect, item_rect;
- struct rtgui_dc* dc;
- rt_uint16_t page_index, index;
- const struct rtgui_list_item* item;
-
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
- if (dc == RT_NULL) return;
-
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
- rtgui_dc_fill_rect(dc, &rect);
-
- /* get item base rect */
- item_rect = rect;
- item_rect.y1 += 2;
- item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
-
- /* get current page */
- page_index = (view->current_item / view->page_items) * view->page_items;
- for (index = 0; index < view->page_items; index ++)
- {
- if (page_index + index >= view->items_count) break;
-
- item = &(view->items[page_index + index]);
-
- if (page_index + index == view->current_item)
- {
- rtgui_theme_draw_selected(dc, &item_rect);
- }
- item_rect.x1 += LIST_MARGIN;
-
- if (item->image != RT_NULL)
- {
- rtgui_image_blit(item->image, dc, &item_rect);
- item_rect.x1 += item->image->w + 2;
- }
- /* draw text */
- rtgui_dc_draw_text(dc, item->name, &item_rect);
-
- if (item->image != RT_NULL)
- item_rect.x1 -= (item->image->w + 2);
- item_rect.x1 -= LIST_MARGIN;
-
- /* move to next item position */
- item_rect.y1 += (rtgui_theme_get_selected_height() + 2);
- item_rect.y2 += (rtgui_theme_get_selected_height() + 2);
- }
- rtgui_dc_end_drawing(dc);
-}
-
-void rtgui_list_view_update_current(struct rtgui_list_view* view, rt_uint16_t old_item)
-{
- struct rtgui_dc* dc;
- const struct rtgui_list_item* item;
- rtgui_rect_t rect, item_rect;
-
- if (old_item/view->page_items != view->current_item/view->page_items)
- {
- /* it's not a same page, update all */
- rtgui_widget_update(RTGUI_WIDGET(view));
- return;
- }
-
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
- if (dc == RT_NULL) return;
-
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
-
- item_rect = rect;
- /* get old item's rect */
- item_rect.y1 += 2;
- item_rect.y1 += (old_item % view->page_items) * (2 + rtgui_theme_get_selected_height());
- item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
-
- /* draw old item */
- rtgui_dc_fill_rect(dc, &item_rect);
-
- item_rect.x1 += LIST_MARGIN;
-
- item = &(view->items[old_item]);
- if (item->image != RT_NULL)
- {
- rtgui_image_blit(item->image, dc, &item_rect);
- item_rect.x1 += item->image->w + 2;
- }
- rtgui_dc_draw_text(dc, item->name, &item_rect);
-
- /* draw current item */
- item_rect = rect;
- /* get current item's rect */
- item_rect.y1 += 2;
- item_rect.y1 += (view->current_item % view->page_items) * (2 + rtgui_theme_get_selected_height());
- item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
-
- /* draw current item */
- rtgui_theme_draw_selected(dc, &item_rect);
-
- item_rect.x1 += LIST_MARGIN;
-
- item = &(view->items[view->current_item]);
- if (item->image != RT_NULL)
- {
- rtgui_image_blit(item->image, dc, &item_rect);
- item_rect.x1 += (item->image->w + 2);
- }
- rtgui_dc_draw_text(dc, item->name, &item_rect);
-
- rtgui_dc_end_drawing(dc);
-}
-
-rt_bool_t rtgui_list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_list_view* view = RT_NULL;
-
- view = RTGUI_LIST_VIEW(widget);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- rtgui_list_view_ondraw(view);
- return RT_FALSE;
-
- case RTGUI_EVENT_RESIZE:
- {
- struct rtgui_event_resize* resize;
-
- resize = (struct rtgui_event_resize*)event;
-
- /* recalculate page items */
- view->page_items = resize->h / (2 + rtgui_theme_get_selected_height());
- }
- break;
-
- case RTGUI_EVENT_MOUSE_BUTTON:
- {
- rtgui_rect_t rect;
- struct rtgui_event_mouse* emouse;
-
- emouse = (struct rtgui_event_mouse*)event;
-
- /* calculate selected item */
-
- /* get physical extent information */
- rtgui_widget_get_rect(widget, &rect);
- rtgui_widget_rect_to_device(widget, &rect);
-
- if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
- {
- rt_uint16_t index;
- index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());
-
- if ((index < view->items_count) && (index < view->page_items))
- {
- rt_uint16_t old_item;
-
- old_item = view->current_item;
-
- /* set selected item */
- view->current_item = view->current_item/view->page_items + index;
- rtgui_list_view_update_current(view, old_item);
- }
- }
- }
- break;
-
- case RTGUI_EVENT_KBD:
- {
- struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
- if (ekbd->type == RTGUI_KEYDOWN)
- {
- rt_uint16_t old_item;
-
- old_item = view->current_item;
- switch (ekbd->key)
- {
- case RTGUIK_LEFT:
- if (view->current_item - view->page_items >= 0)
- view->current_item -= view->page_items;
- rtgui_list_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_UP:
- if (view->current_item > 0)
- view->current_item --;
- rtgui_list_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_RIGHT:
- if (view->current_item + view->page_items < view->items_count - 1)
- view->current_item += view->page_items;
- rtgui_list_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_DOWN:
- if (view->current_item < view->items_count - 1)
- view->current_item ++;
- rtgui_list_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_RETURN:
- if (view->items[view->current_item].action != RT_NULL)
- {
- view->items[view->current_item].action(view->items[view->current_item].parameter);
- }
- return RT_FALSE;
-
- default:
- break;
- }
- }
- }
- return RT_FALSE;
- }
-
- /* use view event handler */
- return rtgui_view_event_handler(widget, event);
-}
-
-rtgui_list_view_t* rtgui_list_view_create(const struct rtgui_list_item* items, rt_uint16_t count, rtgui_rect_t *rect)
-{
- struct rtgui_list_view* view = RT_NULL;
-
- view = (struct rtgui_list_view*) rtgui_widget_create(RTGUI_LIST_VIEW_TYPE);
- if (view != RT_NULL)
- {
- view->items = items;
- view->items_count = count;
-
- view->page_items = rtgui_rect_height(*rect) / (2 + rtgui_theme_get_selected_height());
- }
-
- return view;
-}
-
-void rtgui_list_view_destroy(rtgui_list_view_t* view)
-{
- /* destroy view */
- rtgui_widget_destroy(RTGUI_WIDGET(view));
-}
diff --git a/rtgui/widgets/progressbar.c b/rtgui/widgets/progressbar.c
deleted file mode 100644
index 23e8445338..0000000000
--- a/rtgui/widgets/progressbar.c
+++ /dev/null
@@ -1,114 +0,0 @@
-#include <rtgui/dc.h>
-#include <rtgui/rtgui_theme.h>
-#include <rtgui/widgets/progressbar.h>
-
-#define RTGUI_PROGRESSBAR_DEFAULT_RANGE 100
-
-static void _rtgui_progressbar_constructor(rtgui_progressbar_t *bar)
-{
- rtgui_rect_t rect = {0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT};
-
- rtgui_widget_set_event_handler(RTGUI_WIDGET(bar), rtgui_progressbar_event_handler);
- rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);
-
- bar->orientation = RTGUI_HORIZONTAL;
- bar->range = RTGUI_PROGRESSBAR_DEFAULT_RANGE;
- bar->position = 0;
-
- /* set gc */
- RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(bar)) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
-}
-
-rtgui_type_t *rtgui_progressbar_type_get(void)
-{
- static rtgui_type_t *progressbar_type = RT_NULL;
-
- if (!progressbar_type)
- {
- progressbar_type = rtgui_type_create("progressbar", RTGUI_WIDGET_TYPE,
- sizeof(rtgui_progressbar_t), RTGUI_CONSTRUCTOR(_rtgui_progressbar_constructor), RT_NULL);
- }
-
- return progressbar_type;
-}
-
-rt_bool_t rtgui_progressbar_event_handler(struct rtgui_widget* widget,
- struct rtgui_event* event)
-{
- struct rtgui_progressbar* bar = (struct rtgui_progressbar*)widget;
-
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else
-#endif
- {
- rtgui_theme_draw_progressbar(bar);
- }
-
- break;
- }
-
- return RT_FALSE;
-}
-
-struct rtgui_progressbar* rtgui_progressbar_create(int orientation, int range,
- rtgui_rect_t* r)
-{
- struct rtgui_progressbar* bar;
-
- bar = (struct rtgui_progressbar*) rtgui_widget_create (RTGUI_PROGRESSBAR_TYPE);
- if (bar != RT_NULL)
- {
- if (r != RT_NULL)
- rtgui_widget_set_rect(RTGUI_WIDGET(bar), r);
-
- bar->orientation = orientation;
- bar->range = range;
- }
-
- return bar;
-}
-
-void rtgui_progressbar_destroy(struct rtgui_progressbar* bar)
-{
- rtgui_widget_destroy(RTGUI_WIDGET(bar));
-}
-
-
-void rtgui_progressbar_set_value(struct rtgui_progressbar *bar, int value)
-{
- RT_ASSERT(bar != RT_NULL);
-
- bar->position = value;
-
- rtgui_theme_draw_progressbar(bar);
- return;
-}
-
-int rtgui_progressbar_get_value(struct rtgui_progressbar *bar)
-{
- RT_ASSERT(bar != RT_NULL);
-
- return bar->position;
-}
-
-void rtgui_progressbar_set_range(struct rtgui_progressbar *bar, int range)
-{
- RT_ASSERT(bar != RT_NULL);
-
- bar->range = range;
-
- rtgui_theme_draw_progressbar(bar);
- return;
-}
-
-int rtgui_progressbar_get_range(struct rtgui_progressbar *bar)
-{
- RT_ASSERT(bar != RT_NULL);
-
- return bar->range;
-}
-
diff --git a/rtgui/widgets/radiobox.c b/rtgui/widgets/radiobox.c
deleted file mode 100644
index babf9f9ce1..0000000000
--- a/rtgui/widgets/radiobox.c
+++ /dev/null
@@ -1,239 +0,0 @@
-#include <rtgui/dc.h>
-#include <rtgui/rtgui_theme.h>
-#include <rtgui/widgets/radiobox.h>
-
-#define RTGUI_RADIOBOX_DEFAULT_WIDTH 100
-#define RTGUI_RADIOBOX_DEFAULT_HEIGHT 20
-
-static void _rtgui_radiobox_constructor(rtgui_radiobox_t *radiobox)
-{
- rtgui_rect_t rect = {0, 0, RTGUI_RADIOBOX_DEFAULT_WIDTH, RTGUI_RADIOBOX_DEFAULT_HEIGHT};
-
- /* init widget and set event handler */
- RTGUI_WIDGET(radiobox)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(radiobox)) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
- rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
- rtgui_widget_set_event_handler(RTGUI_WIDGET(radiobox), rtgui_radiobox_event_handler);
-
- /* set proper of control */
- radiobox->items = RT_NULL;
- radiobox->item_count = 0;
- radiobox->item_selection = -1;
- radiobox->orient = RTGUI_HORIZONTAL;
-}
-
-rtgui_type_t *rtgui_radiobox_type_get(void)
-{
- static rtgui_type_t *radiobox_type = RT_NULL;
-
- if (!radiobox_type)
- {
- radiobox_type = rtgui_type_create("radiobox", RTGUI_WIDGET_TYPE,
- sizeof(rtgui_radiobox_t), RTGUI_CONSTRUCTOR(_rtgui_radiobox_constructor), RT_NULL);
- }
-
- return radiobox_type;
-}
-
-static void rtgui_radiobox_onmouse(struct rtgui_radiobox* radiobox, struct rtgui_event_mouse* event)
-{
- RT_ASSERT(radiobox != RT_NULL);
- RT_ASSERT(event != RT_NULL);
-
- if (event->button & RTGUI_MOUSE_BUTTON_DOWN &&
- event->button & RTGUI_MOUSE_BUTTON_LEFT)
- {
- int bord_size;
- struct rtgui_rect rect;
-
- /* focus widgets */
- rtgui_widget_focus(RTGUI_WIDGET(radiobox));
-
- /* get widget physical rect */
- rtgui_widget_get_rect(RTGUI_WIDGET(radiobox), &rect);
- rtgui_widget_rect_to_device(RTGUI_WIDGET(radiobox), &rect);
-
- /* get board size */
- if (radiobox->orient == RTGUI_VERTICAL)
- bord_size = radiobox->item_size;
- else
- {
- struct rtgui_rect bord_rect;
-
- rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(radiobox)), "H", &bord_rect);
- bord_size = rtgui_rect_height(bord_rect);
- }
- rtgui_rect_inflate(&rect, - bord_size);
- if (rtgui_rect_contains_point(&rect, event->x, event->y) != RT_EOK) return;
-
- if (radiobox->orient == RTGUI_VERTICAL)
- {
- int delta_y = event->y - rect.y1;
- rtgui_radiobox_set_selection(radiobox, delta_y / radiobox->item_size);
- }
- else
- {
- int delta_x = event->x - rect.x1;
- rtgui_radiobox_set_selection(radiobox, delta_x / radiobox->item_size);
- }
- }
-}
-
-rt_bool_t rtgui_radiobox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_radiobox* radiobox = (struct rtgui_radiobox*)widget;
-
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else
-#endif
- {
- rtgui_theme_draw_radiobox(radiobox);
- }
-
- break;
-
- case RTGUI_EVENT_KBD:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_key != RT_NULL) widget->on_key(widget, event);
- else
-#endif
- {
- struct rtgui_event_kbd *e = (struct rtgui_event_kbd*)event;
-
- /* set focused */
- rtgui_widget_focus(RTGUI_WIDGET(radiobox));
- if (!(RTGUI_KBD_IS_UP(e))) return RT_FALSE;
-
- if (radiobox->orient == RTGUI_VERTICAL)
- {
- if (e->key == RTGUIK_UP)
- {
- if (radiobox->item_selection > 0)
- rtgui_radiobox_set_selection(radiobox, radiobox->item_selection - 1);
- }
- else if (e->key == RTGUIK_DOWN)
- {
- if (radiobox->item_selection < radiobox->item_count - 1)
- rtgui_radiobox_set_selection(radiobox, radiobox->item_selection + 1);
- }
- }
- else
- {
- if (e->key == RTGUIK_LEFT)
- {
- if (radiobox->item_selection > 0)
- rtgui_radiobox_set_selection(radiobox, radiobox->item_selection - 1);
- }
- else if (e->key == RTGUIK_RIGHT)
- {
- if (radiobox->item_selection < radiobox->item_count - 1)
- rtgui_radiobox_set_selection(radiobox, radiobox->item_selection + 1);
- }
- }
- }
- break;
-
- case RTGUI_EVENT_MOUSE_BUTTON:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_mouseclick != RT_NULL) widget->on_mouseclick(widget, event);
- else
-#endif
- {
- rtgui_radiobox_onmouse(radiobox, (struct rtgui_event_mouse*)event);
- }
- break;
- }
-
- return RT_FALSE;
-}
-
-struct rtgui_radiobox* rtgui_radiobox_create(const char* label, int orient, char** radio_items, int number)
-{
- struct rtgui_radiobox* radiobox;
-
- radiobox = (struct rtgui_radiobox*) rtgui_widget_create (RTGUI_RADIOBOX_TYPE);
- if (radiobox != RT_NULL)
- {
- rt_uint8_t board_size;
- struct rtgui_rect rect;
-
- radiobox->items = radio_items;
- radiobox->item_count = number;
- radiobox->item_selection = -1;
- radiobox->text = rt_strdup(label);
-
- /* set proper of control */
- rtgui_radiobox_set_orientation(radiobox, orient);
- rtgui_font_get_metrics(RTGUI_WIDGET_FONT(RTGUI_WIDGET(radiobox)), "H", &rect);
- board_size = rtgui_rect_height(rect);
-
- if (orient == RTGUI_VERTICAL)
- {
- radiobox->item_size = board_size;
- }
- else
- {
- int index;
- struct rtgui_font* font;
- struct rtgui_rect rect;
-
- /* set init item size */
- radiobox->item_size = 0;
-
- font = RTGUI_WIDGET_FONT(RTGUI_WIDGET(radiobox));
- for (index = 0; index < number; index ++)
- {
- rtgui_font_get_metrics(font, radio_items[index], &rect);
- if ( (board_size + 3 + rtgui_rect_width(rect)) > radiobox->item_size)
- radiobox->item_size = board_size + 3 + rtgui_rect_width(rect);
- }
- }
-
- if (radiobox->item_size < RADIO_BOX_H + 2)
- radiobox->item_size = RADIO_BOX_H + 2;
- }
-
- return radiobox;
-}
-
-void rtgui_radiobox_set_orientation(struct rtgui_radiobox* radiobox, int orientation)
-{
- RT_ASSERT(radiobox != RT_NULL);
-
- /* set orientation */
- radiobox->orient = orientation;
-#ifndef RTGUI_USING_SMALL_SIZE
- if (radiobox->orient == RTGUI_HORIZONTAL)
- {
- /* HORIZONTAL */
- rtgui_widget_set_miniheight(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_HEIGHT);
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_WIDTH);
- }
- else
- {
- /* VERTICAL */
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_HEIGHT);
- rtgui_widget_set_miniheight(RTGUI_WIDGET(radiobox), RTGUI_RADIOBOX_DEFAULT_WIDTH);
- }
-#endif
-}
-
-void rtgui_radiobox_set_selection(struct rtgui_radiobox* radiobox, int selection)
-{
- if (selection >= 0 && selection < radiobox->item_count)
- {
- radiobox->item_selection = selection;
- }
-
- /* update radiobox widget */
- rtgui_theme_draw_radiobox(radiobox);
-}
-
-int rtgui_radiobox_get_selection(struct rtgui_radiobox* radiobox)
-{
- return radiobox->item_selection;
-}
diff --git a/rtgui/widgets/slider.c b/rtgui/widgets/slider.c
deleted file mode 100644
index f9be26b72a..0000000000
--- a/rtgui/widgets/slider.c
+++ /dev/null
@@ -1,222 +0,0 @@
-#include <rtgui/dc.h>
-#include <rtgui/rtgui_theme.h>
-#include <rtgui/widgets/slider.h>
-
-#define RTGUI_SLIDER_DEFAULT_WIDTH 100
-#define RTGUI_SLIDER_DEFAULT_HEIGHT 20
-#define RTGUI_SLIDER_DEFAULT_MIN 0
-#define RTGUI_SLIDER_DEFAULT_MAX 100
-
-static void _rtgui_slider_constructor(rtgui_slider_t *slider)
-{
- rtgui_rect_t rect = {0, 0, RTGUI_SLIDER_DEFAULT_WIDTH, RTGUI_SLIDER_DEFAULT_HEIGHT};
-
- /* init widget and set event handler */
- RTGUI_WIDGET(slider)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect);
- rtgui_widget_set_event_handler(RTGUI_WIDGET(slider), rtgui_slider_event_handler);
-
- /* set proper of control */
- slider->min = RTGUI_SLIDER_DEFAULT_MIN;
- slider->max = RTGUI_SLIDER_DEFAULT_MAX;
- slider->value = RTGUI_SLIDER_DEFAULT_MIN;
- slider->orient = RTGUI_HORIZONTAL;
-
- slider->ticks = 10;
- slider->thumb_width = 8;
-}
-
-rtgui_type_t *rtgui_slider_type_get(void)
-{
- static rtgui_type_t *slider_type = RT_NULL;
-
- if (!slider_type)
- {
- slider_type = rtgui_type_create("slider", RTGUI_WIDGET_TYPE,
- sizeof(rtgui_slider_t), RTGUI_CONSTRUCTOR(_rtgui_slider_constructor), RT_NULL);
- }
-
- return slider_type;
-}
-
-static void rtgui_slider_onmouse(struct rtgui_slider* slider, struct rtgui_event_mouse* event)
-{
- RT_ASSERT(slider != RT_NULL);
- RT_ASSERT(event != RT_NULL);
-
- if (event->button & RTGUI_MOUSE_BUTTON_DOWN &&
- event->button & RTGUI_MOUSE_BUTTON_LEFT)
- {
- int sel;
- int range = slider->max - slider->min;
- int x0, xsize;
- int x;
- x0 = 1 + slider->thumb_width/2;
-
- if (slider->orient == RTGUI_VERTICAL)
- {
- x = event->y - RTGUI_WIDGET(slider)->extent.y1;
- x -= x0;
- xsize = rtgui_rect_height(RTGUI_WIDGET(slider)->extent) - 2 * x0;
- }
- else
- {
- x = event->x - RTGUI_WIDGET(slider)->extent.x1;
- x -= x0;
- xsize = rtgui_rect_width(RTGUI_WIDGET(slider)->extent) - 2 * x0;
- }
-
- if (x <= 0)
- {
- sel = slider->min;
- }
- else if (x >= xsize)
- {
- sel = slider->max;
- }
- else
- {
- sel = ((range * x) + xsize/2) / xsize;
- sel += slider->min;
- }
-
- rtgui_widget_focus(RTGUI_WIDGET(slider));
- rtgui_slider_set_value(slider, sel);
- }
-}
-
-static void rtgui_slider_onkey(struct rtgui_slider* slider, struct rtgui_event_kbd *event)
-{
- RT_ASSERT(slider != RT_NULL);
- RT_ASSERT(event != RT_NULL);
-
- if (!(RTGUI_KBD_IS_UP(event))) return;
-
- if (event->key == RTGUIK_LEFT)
- {
- if (slider->value > slider->min)
- slider->value ++;
- }
-
- if (event->key == RTGUIK_RIGHT)
- {
- if (slider->value < slider->max)
- slider->value --;
- }
-
- /* update widget */
- rtgui_widget_update(RTGUI_WIDGET(slider));
-}
-
-rt_bool_t rtgui_slider_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_slider* slider = (struct rtgui_slider*)widget;
-
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else
-#endif
- {
- rtgui_theme_draw_slider(slider);
- }
-
- break;
-
- case RTGUI_EVENT_KBD:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_key != RT_NULL) widget->on_key(widget, event);
- else
-#endif
- {
- rtgui_slider_onkey(slider, (struct rtgui_event_kbd *)event);
- }
- break;
-
- case RTGUI_EVENT_MOUSE_BUTTON:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_mouseclick != RT_NULL) widget->on_mouseclick(widget, event);
- else
-#endif
- {
- rtgui_slider_onmouse(slider, (struct rtgui_event_mouse*)event);
- }
- break;
- }
-
- return RT_FALSE;
-}
-
-struct rtgui_slider* rtgui_slider_create(rt_size_t min, rt_size_t max, int orient)
-{
- struct rtgui_slider* slider;
-
- slider = (struct rtgui_slider*) rtgui_widget_create (RTGUI_SLIDER_TYPE);
- if (slider != RT_NULL)
- {
- /* set proper of control */
- slider->min = min;
- slider->max = max;
- slider->value = min;
-
- slider->ticks = 10;
- slider->thumb_width = 8;
-
- rtgui_slider_set_orientation(slider, orient);
- }
-
- return slider;
-}
-
-void rtgui_slider_set_range(struct rtgui_slider* slider, rt_size_t min, rt_size_t max)
-{
- RT_ASSERT(slider != RT_NULL);
-
- slider->max = max;
- slider->min = min;
-}
-
-void rtgui_slider_set_value(struct rtgui_slider* slider, rt_size_t value)
-{
- RT_ASSERT(slider != RT_NULL);
-
- if (value < slider->min) value = slider->min;
- if (value > slider->max) value = slider->max;
-
- if (slider->value != value)
- {
- slider->value = value;
- rtgui_theme_draw_slider(slider);
- }
-}
-
-void rtgui_slider_set_orientation(struct rtgui_slider* slider, int orientation)
-{
- RT_ASSERT(slider != RT_NULL);
-
- /* set orientation */
- slider->orient = orientation;
-#ifndef RTGUI_USING_SMALL_SIZE
- if (slider->orient == RTGUI_HORIZONTAL)
- {
- /* HORIZONTAL */
- rtgui_widget_set_miniheight(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_HEIGHT);
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_WIDTH);
- }
- else
- {
- /* VERTICAL */
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_HEIGHT);
- rtgui_widget_set_miniheight(RTGUI_WIDGET(slider), RTGUI_SLIDER_DEFAULT_WIDTH);
- }
-#endif
-}
-
-rt_size_t rtgui_slider_get_value(struct rtgui_slider* slider)
-{
- RT_ASSERT(slider != RT_NULL);
-
- return slider->value;
-}
diff --git a/rtgui/widgets/staticline.c b/rtgui/widgets/staticline.c
deleted file mode 100644
index 055bb353d8..0000000000
--- a/rtgui/widgets/staticline.c
+++ /dev/null
@@ -1,86 +0,0 @@
-#include <rtgui/dc.h>
-#include <rtgui/rtgui_theme.h>
-#include <rtgui/widgets/staticline.h>
-
-static void _rtgui_staticline_constructor(rtgui_staticline_t *staticline)
-{
- /* init widget and set event handler */
- rtgui_rect_t rect = {0, 0, 100, 2};
-
- rtgui_widget_set_rect(RTGUI_WIDGET(staticline), &rect);
- staticline->orientation= RTGUI_HORIZONTAL;
-
- rtgui_widget_set_event_handler(RTGUI_WIDGET(staticline), rtgui_staticline_event_handler);
-}
-
-rtgui_type_t *rtgui_staticline_type_get(void)
-{
- static rtgui_type_t *staticline_type = RT_NULL;
-
- if (!staticline_type)
- {
- staticline_type = rtgui_type_create("staticline", RTGUI_WIDGET_TYPE,
- sizeof(rtgui_staticline_t), RTGUI_CONSTRUCTOR(_rtgui_staticline_constructor), RT_NULL);
- }
-
- return staticline_type;
-}
-
-rt_bool_t rtgui_staticline_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_staticline* staticline;
- RT_ASSERT(widget != RT_NULL);
-
- staticline = (struct rtgui_staticline*) widget;
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else
-#endif
- rtgui_theme_draw_staticline(staticline);
- break;
- }
-
- return RT_FALSE;
-}
-
-rtgui_staticline_t * rtgui_staticline_create(int orientation)
-{
- rtgui_staticline_t* staticline;
-
- staticline = (struct rtgui_staticline*) rtgui_widget_create(RTGUI_STATICLINE_TYPE);
- if (staticline!= RT_NULL)
- {
- rtgui_staticline_set_orientation(staticline, orientation);
- }
-
- return staticline;
-}
-
-void rtgui_staticline_destroy(rtgui_staticline_t* staticline)
-{
- rtgui_widget_destroy(RTGUI_WIDGET(staticline));
-}
-
-void rtgui_staticline_set_orientation(rtgui_staticline_t* staticline, int orientation)
-{
- RT_ASSERT(staticline != RT_NULL);
-
- staticline->orientation = orientation;
-#ifndef RTGUI_USING_SMALL_SIZE
- if (orientation == RTGUI_HORIZONTAL)
- {
- /* HORIZONTAL */
- rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 2);
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 100);
- }
- else
- {
- /* VERTICAL */
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(staticline), 2);
- rtgui_widget_set_miniheight(RTGUI_WIDGET(staticline), 100);
- }
-#endif
-}
diff --git a/rtgui/widgets/textbox.c b/rtgui/widgets/textbox.c
deleted file mode 100644
index 9fd86b7efd..0000000000
--- a/rtgui/widgets/textbox.c
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * File : textbox.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2009-10-16 Bernard first version
- */
-#include <rtgui/dc.h>
-#include <rtgui/rtgui_theme.h>
-#include <rtgui/rtgui_system.h>
-#include <rtgui/widgets/textbox.h>
-
-#ifndef _WIN32
-#include <ctype.h>
-#endif
-
-#define RTGUI_TEXTBOX_LINE_MAX 64
-#define RTGUI_TEXTBOX_MARGIN 3
-
-static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kbd* event);
-static rt_bool_t rtgui_textbox_onfocus(struct rtgui_widget* widget, struct rtgui_event* event);
-static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_widget* widget, struct rtgui_event* event);
-
-static void _rtgui_textbox_caret_timeout(struct rtgui_timer* timer, void* parameter)
-{
- rtgui_textbox_t* box;
-
- box = (rtgui_textbox_t*)parameter;
- /* set caret flag */
- if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
- box->flag &= ~RTGUI_TEXTBOX_CARET_SHOW;
- else
- box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
-
- /* re-darw textbox */
- rtgui_theme_draw_textbox(box);
-
- return ;
-}
-
-static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
-{
- rtgui_rect_t rect = {0, 0, RTGUI_TEXTBOX_DEFAULT_WIDTH, RTGUI_TEXTBOX_DEFAULT_HEIGHT};
- rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect);
-
- RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- rtgui_widget_set_event_handler(RTGUI_WIDGET(box), rtgui_textbox_event_handler);
- rtgui_widget_set_onfocus(RTGUI_WIDGET(box), rtgui_textbox_onfocus);
- rtgui_widget_set_onunfocus(RTGUI_WIDGET(box), rtgui_textbox_onunfocus);
-
- /* set default text align */
- RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(box)) = RTGUI_ALIGN_CENTER_VERTICAL;
-
- /* set proper of control */
- box->caret_timer = rtgui_timer_create(RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC,
- _rtgui_textbox_caret_timeout, box);
-
- box->line = box->line_begin = box->position = 0;
- box->flag = RTGUI_TEXTBOX_SINGLE;
-
- /* allocate default line buffer */
- box->text = RT_NULL;
-
- rtgui_font_get_metrics(RTGUI_WIDGET(box)->gc.font, "h", &rect);
- box->font_width = rtgui_rect_width(rect);
-}
-
-static void _rtgui_textbox_deconstructor(rtgui_textbox_t *box)
-{
- if (box->text != RT_NULL)
- {
- rt_free(box->text);
- box->text = RT_NULL;
- }
-
- rtgui_timer_destory(box->caret_timer);
- box->caret_timer = RT_NULL;
-}
-
-rtgui_type_t *rtgui_textbox_type_get(void)
-{
- static rtgui_type_t *textbox_type = RT_NULL;
-
- if (!textbox_type)
- {
- textbox_type = rtgui_type_create("textbox", RTGUI_WIDGET_TYPE,
- sizeof(rtgui_textbox_t),
- RTGUI_CONSTRUCTOR(_rtgui_textbox_constructor),
- RTGUI_DESTRUCTOR(_rtgui_textbox_deconstructor));
- }
-
- return textbox_type;
-}
-
-static void rtgui_textbox_onmouse(struct rtgui_textbox* box, struct rtgui_event_mouse* event)
-{
- rt_size_t length;
-
- RT_ASSERT(box != RT_NULL);
- RT_ASSERT(event != RT_NULL);
-
- length = rt_strlen((const char*)box->text);
-
- if (event->button & RTGUI_MOUSE_BUTTON_LEFT &&
- event->button & RTGUI_MOUSE_BUTTON_DOWN)
- {
- rt_int32_t x;
-
- /* set caret position */
- x = event->x - RTGUI_WIDGET(box)->extent.x1;
- if (x < 0)
- {
- box->position = 0;
- }
- else if (x > length * box->font_width)
- {
- box->position = length;
- }
- else
- {
- box->position = x / box->font_width;
- }
-
- /* set caret to show */
- box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
-
- /* set widget focus */
- rtgui_widget_focus(RTGUI_WIDGET(box));
- /* re-draw text box */
- rtgui_theme_draw_textbox(box);
- }
-}
-
-static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kbd* event)
-{
- rt_size_t length;
-
- RT_ASSERT(box != RT_NULL);
- RT_ASSERT(event != RT_NULL);
-
- if (event->type != RTGUI_KEYUP)
- return ;
-
- length = rt_strlen((const char*)box->text);
- if (event->key == RTGUIK_DELETE)
- {
- if (box->position == length - 1)
- {
- box->text[box->position] = '\0';
- }
- else
- {
- char *c;
-
- /* remove character */
- for (c = &box->text[box->position]; c[1] != '\0'; c++)
- *c = c[1];
- *c = '\0';
- }
- }
- else if (event->key == RTGUIK_BACKSPACE)
- {
- if (box->position == length - 1)
- {
- box->text[box->position] = '\0';
- box->position --;
- }
- else if (box->position != 0)
- {
- /* remove current character */
- if (box->position != 0)
- {
- char *c;
-
- /* remove character */
- for (c = &box->text[box->position - 1]; c[1] != '\0'; c++)
- *c = c[1];
- *c = '\0';
- }
- box->position --;
- }
- }
- else if (event->key == RTGUIK_LEFT)
- {
- if (box->position > 0) box->position --;
- }
- else if (event->key == RTGUIK_RIGHT)
- {
- if (box->position < length) box->position ++;
- }
- else if (event->key == RTGUIK_HOME)
- {
- box->position = 0;
- }
- else if (event->key == RTGUIK_END)
- {
- box->position = length;
- }
- else if (event->key == RTGUIK_RETURN)
- {
- if (box->on_enter != RT_NULL)
- {
- box->on_enter(RTGUI_WIDGET(box), RT_NULL);
- }
- }
- else
- {
- if (isprint(event->key) || isdigit(event->key))
- {
- /* no buffer on this line */
- if (length + 1 > box->line_length) return;
-
- if (box->position < length - 1)
- {
- char* c;
-
- for (c = &box->text[length]; c != &box->text[box->position]; c--)
- *c = *(c-1);
- box->text[length + 1] = '\0';
- }
-
- box->text[box->position] = event->key;
- box->position ++;
- }
- }
-
- /* set caret to show */
- box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
-
- /* re-draw text box */
- rtgui_theme_draw_textbox(box);
-}
-
-static rt_bool_t rtgui_textbox_onfocus(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_textbox* box = (struct rtgui_textbox*)widget;
-
- /* set caret to show */
- box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
- /* start caret timer */
- rtgui_timer_start(box->caret_timer);
-
- return RT_TRUE;
-}
-
-static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_textbox* box = (struct rtgui_textbox*)widget;
-
- /* stop caret timer */
- rtgui_timer_stop(box->caret_timer);
- /* set caret to hide */
- box->flag &= ~RTGUI_TEXTBOX_CARET_SHOW;
-
- return RT_TRUE;
-}
-
-rt_bool_t rtgui_textbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_textbox* box = (struct rtgui_textbox*)widget;
-
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else
-#endif
- rtgui_theme_draw_textbox(box);
- break;
-
- case RTGUI_EVENT_MOUSE_BUTTON:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_mouseclick != RT_NULL) widget->on_mouseclick(widget, event);
- else
-#endif
- rtgui_textbox_onmouse(box, (struct rtgui_event_mouse*)event);
- return RT_TRUE;
-
- case RTGUI_EVENT_KBD:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_key != RT_NULL) widget->on_key(widget, event);
- else
-#endif
- rtgui_textbox_onkey(box, (struct rtgui_event_kbd*)event);
- return RT_TRUE;
- }
-
- return RT_FALSE;
-}
-
-struct rtgui_textbox* rtgui_textbox_create(const char* text, rt_uint8_t flag)
-{
- struct rtgui_textbox* box;
-
- box = (struct rtgui_textbox*) rtgui_widget_create (RTGUI_TEXTBOX_TYPE);
- if (box != RT_NULL)
- {
- rtgui_rect_t rect = {0, 0, RTGUI_TEXTBOX_DEFAULT_WIDTH, RTGUI_TEXTBOX_DEFAULT_HEIGHT};
-
- /* allocate default line buffer */
- rtgui_textbox_set_value(box, text);
- box->flag = flag;
-
- rtgui_font_get_metrics(RTGUI_WIDGET(box)->gc.font, "h", &rect);
- }
-
- return box;
-}
-
-void rtgui_textbox_destroy(struct rtgui_textbox* box)
-{
- rtgui_widget_destroy(RTGUI_WIDGET(box));
-}
-
-void rtgui_textbox_set_value(struct rtgui_textbox* box, const char* text)
-{
- if (box->text != RT_NULL)
- {
- if (box->line_length > rt_strlen(text) + 1)
- {
- rt_memcpy(box->text, text, rt_strlen(text) + 1);
- return;
- }
- else
- {
- /* free the old text */
- rtgui_free(box->text);
- box->text = RT_NULL;
- }
- }
-
- box->line_length = RTGUI_TEXTBOX_LINE_MAX > rt_strlen(text) + 1 ?
- RTGUI_TEXTBOX_LINE_MAX : rt_strlen(text) + 1;
-
- /* allocate line buffer */
- box->text = rtgui_malloc(box->line_length);
- rt_memset(box->text, 0, box->line_length);
-
- /* copy text */
- rt_memcpy(box->text, text, rt_strlen(text) + 1);
-
- /* set current position */
- box->position = 0;
-}
-
-const char* rtgui_textbox_get_value(struct rtgui_textbox* box)
-{
- return (const char*)box->text;
-}
-
-void rtgui_textbox_set_line_length(struct rtgui_textbox* box, rt_size_t length)
-{
- rt_uint8_t* new_line;
-
- RT_ASSERT(box != RT_NULL);
-
- /* invalid length */
- if (length <= 0) return;
-
- new_line = rtgui_malloc(length);
- if (length < box->line_length)
- {
- rt_memcpy(new_line, box->text, length - 1);
- new_line[length] = '\0';
- }
- else
- {
- rt_memcpy(new_line, (const char*)box->text, rt_strlen((const char*)box->text));
- }
-
- /* set line length */
- box->line_length = length;
-}
-
diff --git a/rtgui/widgets/title.c b/rtgui/widgets/title.c
deleted file mode 100644
index c1b2419f37..0000000000
--- a/rtgui/widgets/title.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * File : title.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2009-10-16 Bernard first version
- */
-#include <rtgui/widgets/title.h>
-#include <rtgui/rtgui_system.h>
-
-/* there is no event handler in wintitle but handle the event on topwin of server */
-static void _rtgui_wintitle_constructor(rtgui_wintitle_t* wintitle)
-{
- wintitle->title = RT_NULL;
- RTGUI_WIDGET(wintitle)->flag = RTGUI_WIDGET_FLAG_DEFAULT;
- RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(wintitle)) = RTGUI_ALIGN_CENTER_VERTICAL;
-}
-
-static void _rtgui_wintitle_deconstructor(rtgui_wintitle_t* wintitle)
-{
- rt_free(wintitle->title);
- wintitle->title = RT_NULL;
-}
-
-rtgui_type_t* rtgui_wintitle_type_get()
-{
- static rtgui_type_t *wintitle_type = RT_NULL;
-
- if (!wintitle_type)
- {
- wintitle_type = rtgui_type_create("wintitle", RTGUI_TOPLEVEL_TYPE,
- sizeof(rtgui_wintitle_t),
- RTGUI_CONSTRUCTOR(_rtgui_wintitle_constructor),
- RTGUI_DESTRUCTOR(_rtgui_wintitle_deconstructor));
- }
-
- return wintitle_type;
-}
-
-rtgui_wintitle_t* rtgui_wintitle_create(const char* title)
-{
- rtgui_wintitle_t* wintitle;
-
- wintitle = (rtgui_wintitle_t*)rtgui_widget_create(RTGUI_WINTITLE_TYPE);
- if (wintitle != RT_NULL)
- {
- rtgui_wintitle_set_title(wintitle, title);
- }
-
- return wintitle;
-}
-
-void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle)
-{
- rtgui_widget_destroy(RTGUI_WIDGET(wintitle));
-}
-
-void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const char* title)
-{
- RT_ASSERT(wintitle != RT_NULL);
-
- if (wintitle->title != RT_NULL)
- {
- rtgui_free(wintitle->title);
- }
-
- if (title != RT_NULL) wintitle->title = (char*)rt_strdup((const char*)title);
- else wintitle->title = RT_NULL;
-}
-
-char *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle)
-{
- RT_ASSERT(wintitle != RT_NULL);
-
- return wintitle->title;
-}
diff --git a/rtgui/widgets/toplevel.c b/rtgui/widgets/toplevel.c
deleted file mode 100644
index d700038082..0000000000
--- a/rtgui/widgets/toplevel.c
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * File : toplevel.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2009-10-16 Bernard first version
- */
-#include <rtgui/rtgui_system.h>
-#include <rtgui/widgets/toplevel.h>
-
-static void _rtgui_toplevel_constructor(rtgui_toplevel_t *toplevel)
-{
- /* set event handler */
- rtgui_widget_set_event_handler(RTGUI_WIDGET(toplevel), rtgui_toplevel_event_handler);
-
- /* set toplevel to self */
- RTGUI_WIDGET(toplevel)->toplevel = RTGUI_WIDGET(toplevel);
-
- /* init toplevel property */
- toplevel->drawing = 0;
- toplevel->external_clip_rect = RT_NULL;
- toplevel->external_clip_size = 0;
-
- /* hide toplevel default */
- RTGUI_WIDGET_HIDE(RTGUI_WIDGET(toplevel));
-
- /* set server as RT_NULL (no connected) */
- toplevel->server = RT_NULL;
-}
-
-static void _rtgui_toplevel_destructor(rtgui_toplevel_t* toplevel)
-{
- /* release external clip info */
- toplevel->drawing = 0;
- if (toplevel->external_clip_size > 0)
- {
- rtgui_free(toplevel->external_clip_rect);
- toplevel->external_clip_rect = RT_NULL;
- toplevel->external_clip_size = 0;
- }
-}
-
-rtgui_type_t *rtgui_toplevel_type_get(void)
-{
- static rtgui_type_t *toplevel_type = RT_NULL;
-
- if (!toplevel_type)
- {
- toplevel_type = rtgui_type_create("toplevel", RTGUI_CONTAINER_TYPE,
- sizeof(rtgui_toplevel_t),
- RTGUI_CONSTRUCTOR(_rtgui_toplevel_constructor),
- RTGUI_DESTRUCTOR(_rtgui_toplevel_destructor));
- }
-
- return toplevel_type;
-}
-
-rt_bool_t rtgui_toplevel_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
-{
- rtgui_toplevel_t* toplevel = (rtgui_toplevel_t*)widget;
-
- switch (event->type)
- {
- case RTGUI_EVENT_KBD:
- if (RTGUI_CONTAINER(toplevel)->focused != RT_NULL)
- {
- RTGUI_CONTAINER(toplevel)->focused->event_handler(RTGUI_CONTAINER(toplevel)->focused, event);
- }
- break;
-
- case RTGUI_EVENT_CLIP_INFO:
- /* set toplevel external clip info */
- rtgui_toplevel_handle_clip(toplevel, (struct rtgui_event_clip_info*)event);
-
- /* update toplevel clip */
- rtgui_toplevel_update_clip(toplevel);
- break;
-
- case RTGUI_EVENT_TIMER:
- {
- struct rtgui_timer* timer;
- struct rtgui_event_timer* etimer = (struct rtgui_event_timer*) event;
-
- timer = etimer->timer;
- if (timer->timeout != RT_NULL)
- {
- /* call timeout function */
- timer->timeout(timer, timer->user_data);
- }
- }
- break;
-
- case RTGUI_EVENT_COMMAND:
- if (rtgui_container_dispatch_event(RTGUI_CONTAINER(widget), event) != RT_TRUE)
- {
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_command != RT_NULL)
- {
- widget->on_command(widget, event);
- }
-#endif
- }
- else return RT_TRUE;
- break;
-
- default :
- return rtgui_container_event_handler(widget, event);
- }
-
- return RT_FALSE;
-}
-
-#include <rtgui/widgets/window.h>
-#include <rtgui/widgets/workbench.h>
-#include <rtgui/widgets/title.h>
-
-void rtgui_toplevel_handle_clip(struct rtgui_toplevel* top,
- struct rtgui_event_clip_info* info)
-{
- RT_ASSERT(top != RT_NULL);
- RT_ASSERT(info != RT_NULL);
-
- /* release old rect array */
- if (top->external_clip_size != 0)
- {
- rtgui_free(top->external_clip_rect);
- top->external_clip_rect = RT_NULL;
- top->external_clip_size = 0;
- }
-
- /* no rect info */
- if (info->num_rect == 0) return;
-
- top->external_clip_rect = (rtgui_rect_t*) rtgui_malloc(sizeof(rtgui_rect_t) *
- info->num_rect);
- top->external_clip_size = info->num_rect;
-
-#ifdef RTGUI_USING_SMALL_SIZE
- {
- extern void rtgui_topwin_get_clipinfo(struct rtgui_rect* list, rt_int32_t count);
-
- /* get rect list from topwin list */
- rtgui_topwin_get_clipinfo(top->external_clip_rect, top->external_clip_size);
- }
-#else
- /* copy rect array */
- rt_memcpy(top->external_clip_rect, (void*)(info + 1), sizeof(rtgui_rect_t) * info->num_rect);
-#endif
-}
-
-#include <rtgui/driver.h> /* to get screen rect */
-
-void rtgui_toplevel_update_clip(rtgui_toplevel_t* top)
-{
- rt_uint32_t idx;
- rtgui_container_t* container;
- struct rtgui_list_node* node;
- rtgui_rect_t screen_rect;
-
- if (top == RT_NULL) return;
-
- /* reset toplevel widget clip to extent */
- rtgui_region_reset(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->extent));
- RTGUI_WIDGET(top)->clip_sync ++;
-
- /* subtract the screen rect */
- screen_rect.x1 = screen_rect.y1 = 0;
- screen_rect.x2 = rtgui_graphic_driver_get_default()->width;
- screen_rect.y2 = rtgui_graphic_driver_get_default()->height;
- rtgui_region_intersect_rect(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->clip),
- &screen_rect);
-
- /* subtract the external rect */
- for (idx = 0; idx < top->external_clip_size; idx ++)
- {
- rtgui_region_subtract_rect(&(RTGUI_WIDGET(top)->clip), &(RTGUI_WIDGET(top)->clip),
- &(top->external_clip_rect[idx]));
- }
-
- /* update the clip info of each child */
- container = RTGUI_CONTAINER(top);
- rtgui_list_foreach(node, &(container->children))
- {
- rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling);
-
- rtgui_widget_update_clip(child);
- }
-}
diff --git a/rtgui/widgets/view.c b/rtgui/widgets/view.c
deleted file mode 100644
index 04cbc79a34..0000000000
--- a/rtgui/widgets/view.c
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * File : view.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2009-10-16 Bernard first version
- */
-#include <rtgui/dc.h>
-#include <rtgui/rtgui_system.h>
-#include <rtgui/widgets/view.h>
-#include <rtgui/widgets/workbench.h>
-
-static void _rtgui_view_constructor(rtgui_view_t *view)
-{
- /* init view */
- rtgui_widget_set_event_handler(RTGUI_WIDGET(view),
- rtgui_view_event_handler);
-
- view->modal_show = RT_FALSE;
- view->title = RT_NULL;
-}
-
-static void _rtgui_view_destructor(rtgui_view_t *view)
-{
- /* remove view from workbench */
- if (RTGUI_WIDGET(view)->parent != RT_NULL)
- {
- rtgui_workbench_t *workbench;
-
- if (view->modal_show == RT_TRUE)
- rtgui_view_end_modal(view, RTGUI_MODAL_CANCEL);
-
- workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent);
- rtgui_workbench_remove_view(workbench, view);
- }
-
- if (view->title != RT_NULL)
- {
- rt_free(view->title);
- view->title = RT_NULL;
- }
-}
-
-rtgui_type_t *rtgui_view_type_get(void)
-{
- static rtgui_type_t *view_type = RT_NULL;
-
- if (!view_type)
- {
- view_type = rtgui_type_create("view", RTGUI_CONTAINER_TYPE,
- sizeof(rtgui_view_t),
- RTGUI_CONSTRUCTOR(_rtgui_view_constructor),
- RTGUI_DESTRUCTOR(_rtgui_view_destructor));
- }
-
- return view_type;
-}
-
-rt_bool_t rtgui_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_view* view = (struct rtgui_view*) widget;
- RT_ASSERT(widget != RT_NULL);
-
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else
-#endif
- {
- struct rtgui_dc* dc;
- struct rtgui_rect rect;
-
- dc = rtgui_dc_begin_drawing(widget);
- if (dc == RT_NULL) return RT_FALSE;
- rtgui_widget_get_rect(widget, &rect);
-
- /* fill view with background */
- rtgui_dc_fill_rect(dc, &rect);
-
- /* paint on each child */
- rtgui_container_dispatch_event(RTGUI_CONTAINER(view), event);
-
- rtgui_dc_end_drawing(dc);
- }
- break;
-
- default:
- return rtgui_container_event_handler(widget, event);
- }
-
- return RT_FALSE;
-}
-
-rtgui_view_t* rtgui_view_create(const char* title)
-{
- struct rtgui_view* view;
-
- /* allocate view */
- view = (struct rtgui_view*) rtgui_widget_create (RTGUI_VIEW_TYPE);
- if (view != RT_NULL)
- {
- if (title != RT_NULL)
- view->title = rt_strdup(title);
- }
-
- return view;
-}
-
-void rtgui_view_destroy(rtgui_view_t* view)
-{
- if (view->modal_show == RT_TRUE)
- rtgui_view_end_modal(view, RTGUI_MODAL_CANCEL);
- else
- rtgui_widget_destroy(RTGUI_WIDGET(view));
-}
-
-#ifndef RTGUI_USING_SMALL_SIZE
-void rtgui_view_set_box(rtgui_view_t* view, rtgui_box_t* box)
-{
- if (view == RT_NULL ||
- box == RT_NULL) return;
-
- rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(box));
- rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(view)->extent));
-}
-#endif
-
-rtgui_modal_code_t rtgui_view_show(rtgui_view_t* view, rt_bool_t is_modal)
-{
- rtgui_workbench_t* workbench;
-
- /* parameter check */
- if (view == RT_NULL) return RTGUI_MODAL_CANCEL;
-
- if (RTGUI_WIDGET(view)->parent == RT_NULL)
- {
- RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(view));
- return RTGUI_MODAL_CANCEL;
- }
-
- workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent);
- rtgui_workbench_show_view(workbench, view);
- if (RTGUI_WIDGET_IS_FOCUSABLE(RTGUI_WIDGET(view)))
- rtgui_widget_focus(RTGUI_WIDGET(view));
-
- view->modal_show = is_modal;
- if (is_modal == RT_TRUE)
- {
- /* set modal mode */
- workbench->flag |= RTGUI_WORKBENCH_FLAG_MODAL_MODE;
- workbench->modal_widget = RTGUI_WIDGET(view);
-
- /* perform workbench event loop */
- rtgui_workbench_event_loop(workbench);
-
- workbench->modal_widget = RT_NULL;
- return workbench->modal_code;
- }
-
- /* no modal mode, always return modal_ok */
- return RTGUI_MODAL_OK;
-}
-
-void rtgui_view_end_modal(rtgui_view_t* view, rtgui_modal_code_t modal_code)
-{
- rtgui_workbench_t* workbench;
-
- /* parameter check */
- if ((view == RT_NULL) || (RTGUI_WIDGET(view)->parent == RT_NULL))return ;
-
- workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent);
- workbench->modal_code = modal_code;
- workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE;
-
- /* remove modal mode */
- view->modal_show = RT_FALSE;
-}
-
-void rtgui_view_hide(rtgui_view_t* view)
-{
- if (view == RT_NULL) return;
-
- if (RTGUI_WIDGET(view)->parent == RT_NULL)
- {
- RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view));
- return;
- }
-
- rtgui_workbench_hide_view((rtgui_workbench_t*)(RTGUI_WIDGET(view)->parent), view);
-}
-
-char* rtgui_view_get_title(rtgui_view_t* view)
-{
- RT_ASSERT(view != RT_NULL);
-
- return view->title;
-}
-
-void rtgui_view_set_title(rtgui_view_t* view, const char *title)
-{
- RT_ASSERT(view != RT_NULL);
-
- if (view->title != RT_NULL)
- {
- rtgui_free(view->title);
-
- if (title != RT_NULL) view->title = rt_strdup(title);
- else view->title = RT_NULL;
- }
-}
diff --git a/rtgui/widgets/widget.c b/rtgui/widgets/widget.c
deleted file mode 100644
index e1826c1489..0000000000
--- a/rtgui/widgets/widget.c
+++ /dev/null
@@ -1,555 +0,0 @@
-/*
- * File : widget.c
- * This file is part of RTGUI in RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2009-10-04 Bernard first version
- */
-#include <rtgui/widgets/widget.h>
-#include <rtgui/widgets/window.h>
-#include <rtgui/widgets/view.h>
-
-static void _rtgui_widget_constructor(rtgui_widget_t *widget)
-{
- if (!widget) return;
-
- /* set default flag */
- widget->flag = RTGUI_WIDGET_FLAG_DEFAULT;
-
- /* init list */
- rtgui_list_init(&(widget->sibling));
-
- /* init gc */
- widget->gc.foreground = default_foreground;
- widget->gc.background = default_background;
- widget->gc.font = rtgui_font_default();
- widget->gc.textalign = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
- widget->align = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
-
- /* set parent and toplevel root */
- widget->parent = RT_NULL;
- widget->toplevel = RT_NULL;
-
- /* some common event handler */
- widget->on_focus_in = RT_NULL;
- widget->on_focus_out = RT_NULL;
-
-#ifndef RTGUI_USING_SMALL_SIZE
- widget->on_draw = RT_NULL;
- widget->on_mouseclick = RT_NULL;
- widget->on_key = RT_NULL;
- widget->on_size = RT_NULL;
- widget->on_command = RT_NULL;
-#endif
-
- /* set default event handler */
- widget->event_handler = rtgui_widget_event_handler;
-
- /* does not set widget extent and only set clip_sync to zero */
- rtgui_region_init(&(widget->clip));
- widget->clip_sync = 0;
-}
-
-/* Destroys the widget */
-static void _rtgui_widget_destructor(rtgui_widget_t *widget)
-{
- if (widget == RT_NULL) return;
-
- if (widget->parent != RT_NULL)
- {
- /* remove widget from parent's children list */
- rtgui_list_remove(&(RTGUI_CONTAINER(widget->parent)->children), &(widget->sibling));
-
- widget->parent = RT_NULL;
- }
-
- /* fini clip region */
- rtgui_region_fini(&(widget->clip));
- widget->clip_sync = 0;
-}
-
-rtgui_type_t *rtgui_widget_type_get(void)
-{
- static rtgui_type_t *widget_type = RT_NULL;
-
- if (!widget_type)
- {
- widget_type = rtgui_type_create("rtgui_widget", RTGUI_OBJECT_TYPE,
- sizeof(rtgui_widget_t), RTGUI_CONSTRUCTOR(_rtgui_widget_constructor),
- RTGUI_DESTRUCTOR(_rtgui_widget_destructor));
- }
-
- return widget_type;
-}
-
-rtgui_widget_t *rtgui_widget_create(rtgui_type_t *widget_type)
-{
- struct rtgui_widget* widget;
-
- widget = RTGUI_WIDGET(rtgui_object_create(widget_type));
-
- return widget;
-}
-
-void rtgui_widget_destroy(rtgui_widget_t* widget)
-{
- rtgui_object_destroy(RTGUI_OBJECT(widget));
-}
-
-void rtgui_widget_set_rect(rtgui_widget_t* widget, rtgui_rect_t* rect)
-{
- if (widget == RT_NULL || rect == RT_NULL) return;
-
- widget->extent = *rect;
-
-#ifndef RTGUI_USING_SMALL_SIZE
- /* reset mini width and height */
- widget->mini_width = rtgui_rect_width(widget->extent);
- widget->mini_height = rtgui_rect_height(widget->extent);
-#endif
-
- /* it's not empty, fini it */
- if (rtgui_region_not_empty(&(widget->clip)))
- {
- rtgui_region_fini(&(widget->clip));
- }
-
- /* reset clip info */
- rtgui_region_init_with_extents(&(widget->clip), rect);
-}
-
-#ifndef RTGUI_USING_SMALL_SIZE
-void rtgui_widget_set_miniwidth(rtgui_widget_t* widget, int width)
-{
- RT_ASSERT(widget != RT_NULL);
-
- widget->mini_width = width;
-}
-
-void rtgui_widget_set_miniheight(rtgui_widget_t* widget, int height)
-{
- RT_ASSERT(widget != RT_NULL);
-
- widget->mini_height = height;
-}
-#endif
-
-/*
- * This function moves widget and its children to a logic point
- */
-void rtgui_widget_move_to_logic(rtgui_widget_t* widget, int dx, int dy)
-{
- struct rtgui_list_node* node;
- rtgui_widget_t* child;
-
- if (widget == RT_NULL) return;
-
- rtgui_rect_moveto(&(widget->extent), dx, dy);
-
- /* move each child */
- if (RTGUI_IS_CONTAINER(widget))
- {
- rtgui_list_foreach(node, &(RTGUI_CONTAINER(widget)->children))
- {
- child = rtgui_list_entry(node, rtgui_widget_t, sibling);
-
- rtgui_widget_move_to_logic(child, dx, dy);
- }
- }
-}
-
-void rtgui_widget_set_event_handler(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
-{
- RT_ASSERT(widget != RT_NULL);
-
- widget->event_handler = handler;
-}
-
-void rtgui_widget_get_rect(rtgui_widget_t* widget, rtgui_rect_t *rect)
-{
- RT_ASSERT(widget != RT_NULL);
-
- if (rect != RT_NULL)
- {
- rect->x1 = rect->y1 = 0;
- rect->x2 = widget->extent.x2 - widget->extent.x1;
- rect->y2 = widget->extent.y2 - widget->extent.y1;
- }
-}
-
-void rtgui_widget_set_onfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
-{
- RT_ASSERT(widget != RT_NULL);
-
- widget->on_focus_in = handler;
-}
-
-void rtgui_widget_set_onunfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
-{
- RT_ASSERT(widget != RT_NULL);
-
- widget->on_focus_out = handler;
-}
-
-#ifndef RTGUI_USING_SMALL_SIZE
-void rtgui_widget_set_ondraw(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
-{
- RT_ASSERT(widget != RT_NULL);
-
- widget->on_draw = handler;
-}
-
-void rtgui_widget_set_onmouseclick(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
-{
- RT_ASSERT(widget != RT_NULL);
-
- widget->on_mouseclick = handler;
-}
-
-void rtgui_widget_set_onkey(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
-{
- RT_ASSERT(widget != RT_NULL);
-
- widget->on_key = handler;
-}
-
-void rtgui_widget_set_onsize(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
-{
- RT_ASSERT(widget != RT_NULL);
-
- widget->on_size = handler;
-}
-
-void rtgui_widget_set_oncommand(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
-{
- RT_ASSERT(widget != RT_NULL);
-
- widget->on_command = handler;
-}
-#endif
-
-/**
- * @brief Focuses the widget. The focused widget is the widget which can receive the keyboard events
- * @param widget a widget
- * @note The widget has to be attached to a toplevel widget, otherwise it will have no effect
- */
-void rtgui_widget_focus(rtgui_widget_t *widget)
-{
- rtgui_widget_t *focused;
- rtgui_container_t *parent;
-
- RT_ASSERT(widget != RT_NULL);
-
- if (!widget->parent || !RTGUI_WIDGET_IS_FOCUSABLE(widget) || !RTGUI_WIDGET_IS_ENABLE(widget))
- return;
-
- /* set widget as focused */
- widget->flag |= RTGUI_WIDGET_FLAG_FOCUS;
-
- /* get parent container */
- parent = RTGUI_CONTAINER(widget->parent);
-
- /* get old focused widget */
- focused = parent->focused;
- if (focused == widget) return ; /* it's the same focused widget */
-
- if (focused != RT_NULL)
- rtgui_widget_unfocus(focused);
-
- /* set widget as focused widget in parent link */
- parent->focused = widget;
- while (RTGUI_WIDGET(parent)->parent != RT_NULL)
- {
- parent = RTGUI_CONTAINER(RTGUI_WIDGET(parent)->parent);
- parent->focused = widget;
-
- /* if the parent is hide, break it */
- if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(parent))) break;
- }
-
- /* invoke on focus in call back */
- if (widget->on_focus_in != RT_NULL)
- widget->on_focus_in(widget, RT_NULL);
-}
-
-/**
- * @brief Unfocused the widget
- * @param widget a widget
- */
-void rtgui_widget_unfocus(rtgui_widget_t *widget)
-{
- RT_ASSERT(widget != RT_NULL);
-
- if (!widget->toplevel || !RTGUI_WIDGET_IS_FOCUSED(widget))
- return;
-
- widget->flag &= ~RTGUI_WIDGET_FLAG_FOCUS;
-
- if (widget->on_focus_out != RT_NULL)
- widget->on_focus_out(widget, RT_NULL);
-
- /* refresh widget */
- rtgui_widget_update(widget);
-}
-
-void rtgui_widget_point_to_device(rtgui_widget_t* widget, rtgui_point_t* point)
-{
- RT_ASSERT(widget != RT_NULL);
-
- if (point != RT_NULL)
- {
- point->x += widget->extent.x1;
- point->y += widget->extent.y1;
- }
-}
-
-void rtgui_widget_rect_to_device(rtgui_widget_t* widget, rtgui_rect_t* rect)
-{
- RT_ASSERT(widget != RT_NULL);
-
- if (rect != RT_NULL)
- {
- rect->x1 += widget->extent.x1;
- rect->x2 += widget->extent.x1;
-
- rect->y1 += widget->extent.y1;
- rect->y2 += widget->extent.y1;
- }
-}
-
-void rtgui_widget_point_to_logic(rtgui_widget_t* widget, rtgui_point_t* point)
-{
- RT_ASSERT(widget != RT_NULL);
-
- if (point != RT_NULL)
- {
- point->x -= widget->extent.x1;
- point->y -= widget->extent.y1;
- }
-}
-
-void rtgui_widget_rect_to_logic(rtgui_widget_t* widget, rtgui_rect_t* rect)
-{
- RT_ASSERT(widget != RT_NULL);
-
- if (rect != RT_NULL)
- {
- rect->x1 -= widget->extent.x1;
- rect->x2 -= widget->extent.x1;
-
- rect->y1 -= widget->extent.y1;
- rect->y2 -= widget->extent.y1;
- }
-}
-
-rtgui_widget_t* rtgui_widget_get_toplevel(rtgui_widget_t* widget)
-{
- rtgui_widget_t* r;
-
- RT_ASSERT(widget != RT_NULL);
-
- if (widget->toplevel) return widget->toplevel;
-
- r = widget;
- /* get the toplevel widget */
- while (r->parent != RT_NULL) r = r->parent;
-
- /* set toplevel */
- widget->toplevel = r;
-
- return r;
-}
-
-rt_bool_t rtgui_widget_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
-{
-#ifndef RTGUI_USING_SMALL_SIZE
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- if (widget->on_draw != RT_NULL) return widget->on_draw(widget, event);
- break;
-
- case RTGUI_EVENT_KBD:
- if (widget->on_key != RT_NULL) return widget->on_key(widget, event);
- break;
-
- case RTGUI_EVENT_MOUSE_BUTTON:
- if (widget->on_mouseclick != RT_NULL) return widget->on_mouseclick(widget, event);
- break;
-
- case RTGUI_EVENT_COMMAND:
- if (widget->on_command != RT_NULL) return widget->on_command(widget, event);
- break;
-
- case RTGUI_EVENT_RESIZE:
- if (widget->on_size != RT_NULL) return widget->on_size(widget, event);
- break;
- }
-#endif
-
- return RT_FALSE;
-}
-
-/*
- * This function updates the clip info of widget
- */
-void rtgui_widget_update_clip(rtgui_widget_t* widget)
-{
- struct rtgui_list_node* node;
- rtgui_widget_t *parent;
-
- /* no widget or widget is hide, no update clip */
- if (widget == RT_NULL || RTGUI_WIDGET_IS_HIDE(widget)) return;
-
- parent = widget->parent;
- /* if there is no parent, do not update clip (please use toplevel widget API) */
- if (parent == RT_NULL) return;
-
- /* increase clip sync */
- widget->clip_sync ++;
-
- /* reset clip to extent */
- rtgui_region_reset(&(widget->clip), &(widget->extent));
-
- /* limit widget extent in parent extent */
- rtgui_region_intersect(&(widget->clip), &(widget->clip), &(parent->clip));
-
- /* get the no transparent parent */
- while (parent != RT_NULL && parent->flag & RTGUI_WIDGET_FLAG_TRANSPARENT)
- {
- parent = parent->parent;
- }
-
- if (parent != RT_NULL)
- {
- /* subtract widget clip in parent clip */
- if (!(widget->flag & RTGUI_WIDGET_FLAG_TRANSPARENT))
- {
- rtgui_region_subtract_rect(&(parent->clip), &(parent->clip),
- &(widget->extent));
- }
- }
-
- /*
- * note: since the layout widget introduction, the sibling widget will not
- * intersect.
- */
-
- /* if it's a container object, update the clip info of children */
- if (RTGUI_IS_CONTAINER(widget))
- {
- rtgui_widget_t* child;
- rtgui_list_foreach(node, &(RTGUI_CONTAINER(widget)->children))
- {
- child = rtgui_list_entry(node, rtgui_widget_t, sibling);
-
- rtgui_widget_update_clip(child);
- }
- }
-}
-
-void rtgui_widget_show(rtgui_widget_t* widget)
-{
- /* there is no parent or the parent is hide, no show at all */
- if (widget->parent == RT_NULL ||
- RTGUI_WIDGET_IS_HIDE(widget->parent)) return;
-
- /* update the clip info of widget */
- RTGUI_WIDGET_UNHIDE(widget);
- rtgui_widget_update_clip(widget);
-}
-
-void rtgui_widget_hide(rtgui_widget_t* widget)
-{
- /* hide this widget */
- RTGUI_WIDGET_HIDE(widget);
-
- /* update the clip info of widget parent */
- rtgui_widget_update_clip(widget->parent);
-}
-
-rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t* widget)
-{
- rtgui_widget_t* parent;
-
- /* get parent widget */
- parent = widget->parent;
- while (parent->parent != RT_NULL && (RTGUI_WIDGET_FLAG(parent) & RTGUI_WIDGET_FLAG_TRANSPARENT))
- parent = parent->parent;
-
- /* get parent's color */
- if (parent != RT_NULL)
- return RTGUI_WIDGET_FOREGROUND(parent);
-
- return RTGUI_WIDGET_FOREGROUND(widget);
-}
-
-rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t* widget)
-{
- rtgui_widget_t* parent;
-
- /* get parent widget */
- parent = widget->parent;
- while (parent->parent != RT_NULL && (RTGUI_WIDGET_FLAG(parent) & RTGUI_WIDGET_FLAG_TRANSPARENT))
- parent = parent->parent;
-
- /* get parent's color */
- if (parent != RT_NULL)
- return RTGUI_WIDGET_BACKGROUND(parent);
-
- return RTGUI_WIDGET_BACKGROUND(widget);
-}
-
-void rtgui_widget_update(rtgui_widget_t* widget)
-{
- struct rtgui_event_paint paint;
- RTGUI_EVENT_PAINT_INIT(&paint);
- paint.wid = RT_NULL;
-
- RT_ASSERT(widget != RT_NULL);
-
- if (widget->event_handler != RT_NULL)
- {
- widget->event_handler(widget, &paint.parent);
- }
-}
-
-rtgui_widget_t* rtgui_widget_get_next_sibling(rtgui_widget_t* widget)
-{
- rtgui_widget_t* sibling = RT_NULL;
-
- if (widget->sibling.next != RT_NULL)
- {
- sibling = rtgui_list_entry(widget->sibling.next, rtgui_widget_t, sibling);
- }
-
- return sibling;
-}
-
-rtgui_widget_t* rtgui_widget_get_prev_sibling(rtgui_widget_t* widget)
-{
- struct rtgui_list_node* node;
- rtgui_widget_t *sibling, *parent;
-
- node = RT_NULL; sibling = RT_NULL;
- parent = widget->parent;
- if (parent != RT_NULL)
- {
- rtgui_list_foreach(node, &(RTGUI_CONTAINER(parent)->children))
- {
- if (node->next == &(widget->sibling))
- break;
- }
- }
-
- if (node != RT_NULL)
- sibling = rtgui_list_entry(node, rtgui_widget_t, sibling);
-
- return sibling;
-}
diff --git a/rtgui/widgets/window.c b/rtgui/widgets/window.c
deleted file mode 100644
index 268c9c50c4..0000000000
--- a/rtgui/widgets/window.c
+++ /dev/null
@@ -1,630 +0,0 @@
-/*
- * File : window.c
- * This file is part of RTGUI in RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2009-10-04 Bernard first version
- */
-#include <rtgui/dc.h>
-#include <rtgui/color.h>
-#include <rtgui/image.h>
-#include <rtgui/rtgui_system.h>
-
-#include <rtgui/widgets/window.h>
-#include <rtgui/widgets/button.h>
-#include <rtgui/widgets/workbench.h>
-
-static void _rtgui_win_constructor(rtgui_win_t *win)
-{
- /* init window attribute */
- win->on_activate = RT_NULL;
- win->on_deactivate = RT_NULL;
- win->on_close = RT_NULL;
- win->title = RT_NULL;
- win->modal_code = RTGUI_MODAL_OK;
- win->modal_widget = RT_NULL;
-
- /* set window hide */
- RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
-
- /* set window style */
- win->style = RTGUI_WIN_STYLE_DEFAULT;
- rtgui_widget_set_event_handler(RTGUI_WIDGET(win), rtgui_win_event_handler);
-
- /* init user data */
- win->user_data = 0;
-}
-
-static void _rtgui_win_destructor(rtgui_win_t* win)
-{
- struct rtgui_event_win_destroy edestroy;
-
- if (RTGUI_TOPLEVEL(win)->server != RT_NULL)
- {
- /* destroy in server */
- RTGUI_EVENT_WIN_DESTROY_INIT(&edestroy);
- edestroy.wid = win;
- if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&edestroy),
- sizeof(struct rtgui_event_win_destroy)) != RT_EOK)
- {
- /* destroy in server failed */
- return;
- }
- }
-
- /* release field */
- rt_free(win->title);
-}
-
-static rt_bool_t _rtgui_win_create_in_server(rtgui_win_t* win)
-{
- if (RTGUI_TOPLEVEL(win)->server == RT_NULL)
- {
- rt_thread_t server;
- struct rtgui_event_win_create ecreate;
- RTGUI_EVENT_WIN_CREATE_INIT(&ecreate);
-
- /* get server thread id */
- server = rtgui_thread_get_server();
- if (server == RT_NULL)
- {
- rt_kprintf("RTGUI server is not running...\n");
- return RT_FALSE;
- }
-
- /* send win create event to server */
- ecreate.wid = win;
- ecreate.parent.user = win->style;
-#ifndef RTGUI_USING_SMALL_SIZE
- ecreate.extent = RTGUI_WIDGET(win)->extent;
- rt_strncpy((char*)ecreate.title, (char*)win->title, RTGUI_NAME_MAX);
-#endif
-
- if (rtgui_thread_send_sync(server, RTGUI_EVENT(&ecreate),
- sizeof(struct rtgui_event_win_create)) != RT_EOK)
- {
- rt_kprintf("create win: %s failed\n", win->title);
- return RT_FALSE;
- }
-
- /* set server */
- RTGUI_TOPLEVEL(win)->server = server;
- }
-
- return RT_TRUE;
-}
-
-rtgui_type_t *rtgui_win_type_get(void)
-{
- static rtgui_type_t *win_type = RT_NULL;
-
- if (!win_type)
- {
- win_type = rtgui_type_create("win", RTGUI_TOPLEVEL_TYPE,
- sizeof(rtgui_win_t),
- RTGUI_CONSTRUCTOR(_rtgui_win_constructor),
- RTGUI_DESTRUCTOR(_rtgui_win_destructor));
- }
-
- return win_type;
-}
-
-rtgui_win_t* rtgui_win_create(rtgui_toplevel_t* parent_toplevel, const char* title, rtgui_rect_t *rect, rt_uint8_t style)
-{
- struct rtgui_win* win;
-
- /* allocate win memory */
- win = (struct rtgui_win*) rtgui_widget_create (RTGUI_WIN_TYPE);
- if (win != RT_NULL)
- {
- /* set parent toplevel */
- win->parent_toplevel = parent_toplevel;
-
- /* set title, rect and style */
- if (title != RT_NULL) win->title = rt_strdup(title);
- else win->title = RT_NULL;
-
- rtgui_widget_set_rect(RTGUI_WIDGET(win), rect);
- win->style = style;
-
- if (_rtgui_win_create_in_server(win) == RT_FALSE)
- {
- rtgui_widget_destroy(RTGUI_WIDGET(win));
- return RT_NULL;
- }
- }
-
- return win;
-}
-
-void rtgui_win_destroy(struct rtgui_win* win)
-{
- if (win->style & RTGUI_WIN_STYLE_MODAL)
- {
- /* end modal */
- rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
- }
- else
- {
- rtgui_widget_destroy(RTGUI_WIDGET(win));
- }
-}
-
-rtgui_modal_code_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
-{
- rtgui_modal_code_t result;
-
- RT_ASSERT(win != RT_NULL);
- result = RTGUI_MODAL_CANCEL;
-
- /* if it does not register into server, create it in server */
- if (RTGUI_TOPLEVEL(win)->server == RT_NULL)
- {
- if (_rtgui_win_create_in_server(win) == RT_FALSE)
- return result;
- }
-
- if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)))
- {
- /* send show message to server */
- struct rtgui_event_win_show eshow;
- RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
- eshow.wid = win;
-
- if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow),
- sizeof(struct rtgui_event_win_show)) != RT_EOK)
- {
- /* hide window failed */
- return result;
- }
-
- /* set window unhidden */
- RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win));
- }
- else rtgui_widget_update(RTGUI_WIDGET(win));
-
- if (is_modal == RT_TRUE)
- {
- if (win->parent_toplevel != RT_NULL)
- {
- rtgui_widget_t *parent_widget;
-
- /* set style */
- win->style |= RTGUI_WIN_STYLE_MODAL;
-
- /* get root toplevel */
- parent_widget = RTGUI_WIDGET(win->parent_toplevel);
- if (RTGUI_IS_WORKBENCH(parent_widget))
- {
- rtgui_workbench_t* workbench;
- workbench = RTGUI_WORKBENCH(win->parent_toplevel);
- workbench->flag |= RTGUI_WORKBENCH_FLAG_MODAL_MODE;
- workbench->modal_widget = RTGUI_WIDGET(win);
-
- rtgui_workbench_event_loop(workbench);
- result = workbench->modal_code;
- workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE;
- workbench->modal_widget = RT_NULL;
- }
- else if (RTGUI_IS_WIN(parent_widget))
- {
- rtgui_win_t* parent_win;
- parent_win = RTGUI_WIN(win->parent_toplevel);
- parent_win->flag |= RTGUI_WORKBENCH_FLAG_MODAL_MODE;
- parent_win->modal_widget = RTGUI_WIDGET(win);
-
- rtgui_win_event_loop(parent_win);
- result = parent_win->modal_code;
- parent_win->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE;
- parent_win->modal_widget = RT_NULL;
- }
- }
- else
- {
- /* which is a root window */
- win->style |= RTGUI_WIN_STYLE_MODAL;
- rtgui_win_event_loop(win);
-
- result = win->modal_code;
- win->style &= ~RTGUI_WIN_STYLE_MODAL;
- }
- }
-
- return result;
-}
-
-void rtgui_win_end_modal(struct rtgui_win* win, rtgui_modal_code_t modal_code)
-{
- if (win->parent_toplevel != RT_NULL)
- {
- if (RTGUI_IS_WORKBENCH(win->parent_toplevel))
- {
- rtgui_workbench_t* workbench;
-
- /* which is shown under workbench */
- workbench = RTGUI_WORKBENCH(win->parent_toplevel);
- workbench->modal_code = modal_code;
- workbench->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE;
- }
- else if (RTGUI_IS_WIN(win->parent_toplevel))
- {
- rtgui_win_t* parent_win;
-
- /* which is shown under win */
- parent_win = RTGUI_WIN(win->parent_toplevel);
- parent_win->modal_code = modal_code;
- parent_win->flag &= ~RTGUI_WORKBENCH_FLAG_MODAL_MODE;
- }
- }
- else
- {
- /* which is a stand alone window */
- win->modal_code = modal_code;
- }
-
- /* remove modal mode */
- win->style &= ~RTGUI_WIN_STYLE_MODAL;
-}
-
-void rtgui_win_hiden(struct rtgui_win* win)
-{
- RT_ASSERT(win != RT_NULL);
-
- if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)) &&
- RTGUI_TOPLEVEL(win)->server != RT_NULL)
- {
- /* send hidden message to server */
- struct rtgui_event_win_hide ehide;
- RTGUI_EVENT_WIN_HIDE_INIT(&ehide);
- ehide.wid = win;
-
- if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&ehide),
- sizeof(struct rtgui_event_win_hide)) != RT_EOK)
- {
- rt_kprintf("hide win: %s failed\n", win->title);
- return;
- }
-
- /* set window hide and deactivated */
- RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
- win->style &= ~RTGUI_WIN_STYLE_ACTIVATE;
- }
-}
-
-rt_bool_t rtgui_win_is_activated(struct rtgui_win* win)
-{
- RT_ASSERT(win != RT_NULL);
-
- return win->style & RTGUI_WIN_STYLE_ACTIVATE;
-}
-
-void rtgui_win_move(struct rtgui_win* win, int x, int y)
-{
- struct rtgui_event_win_move emove;
- RTGUI_EVENT_WIN_MOVE_INIT(&emove);
-
- if (win == RT_NULL) return;
-
- if (RTGUI_TOPLEVEL(win)->server != RT_NULL)
- {
- /* set win hide firstly */
- RTGUI_WIDGET_HIDE(RTGUI_WIDGET(win));
-
- emove.wid = win;
- emove.x = x;
- emove.y = y;
- if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&emove),
- sizeof(struct rtgui_event_win_move)) != RT_EOK)
- {
- return;
- }
- }
-
- /* move window to logic position */
- rtgui_widget_move_to_logic(RTGUI_WIDGET(win),
- x - RTGUI_WIDGET(win)->extent.x1,
- y - RTGUI_WIDGET(win)->extent.y1);
-
- /* set window visible */
- RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(win));
- return;
-}
-
-static rt_bool_t rtgui_win_ondraw(struct rtgui_win* win)
-{
- struct rtgui_dc* dc;
- struct rtgui_rect rect;
- struct rtgui_event_paint event;
-
- /* begin drawing */
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(win));
- if (dc == RT_NULL) return RT_FALSE;
-
- /* get window rect */
- rtgui_widget_get_rect(RTGUI_WIDGET(win), &rect);
- /* fill area */
- rtgui_dc_fill_rect(dc, &rect);
-
- /* paint each widget */
- RTGUI_EVENT_PAINT_INIT(&event);
- event.wid = RT_NULL;
- rtgui_container_dispatch_event(RTGUI_CONTAINER(win), (rtgui_event_t*)&event);
-
- rtgui_dc_end_drawing(dc);
-
- return RT_FALSE;
-}
-
-rt_bool_t rtgui_win_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct rtgui_win* win = (struct rtgui_win*)widget;
-
- RT_ASSERT((win != RT_NULL) && (event != RT_NULL));
-
- switch (event->type)
- {
- case RTGUI_EVENT_WIN_SHOW:
- rtgui_win_show(win, RT_FALSE);
- break;
-
- case RTGUI_EVENT_WIN_HIDE:
- rtgui_win_hiden(win);
- break;
-
- case RTGUI_EVENT_WIN_CLOSE:
- if (win->on_close != RT_NULL)
- {
- if (win->on_close(widget, event) == RT_FALSE) return RT_TRUE;
- }
-
- if (win->style & RTGUI_WIN_STYLE_MODAL)
- {
- rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
- }
- else
- {
- /* destroy window */
- rtgui_win_destroy(win);
- }
-
- /* exit event loop */
- return RT_TRUE;
-
- case RTGUI_EVENT_WIN_MOVE:
- {
- struct rtgui_event_win_move* emove = (struct rtgui_event_win_move*)event;
-
- /* move window */
- rtgui_win_move(win, emove->x, emove->y);
- }
- break;
-
- case RTGUI_EVENT_WIN_ACTIVATE:
- if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(win)))
- {
- rt_kprintf("activate window, but window is hide!\n");
- }
-
- win->style |= RTGUI_WIN_STYLE_ACTIVATE;
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else
-#endif
- rtgui_win_ondraw(win);
-
- if (win->on_activate != RT_NULL)
- {
- win->on_activate(widget, event);
- }
- break;
-
- case RTGUI_EVENT_WIN_DEACTIVATE:
- if (win->style & RTGUI_WIN_STYLE_MODAL)
- {
- /* do not deactivate a modal win */
- struct rtgui_event_win_show eshow;
- RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
- eshow.wid = win;
-
- rtgui_thread_send(RTGUI_TOPLEVEL(win)->server, RTGUI_EVENT(&eshow),
- sizeof(struct rtgui_event_win_show));
- }
- else
- {
- win->style &= ~RTGUI_WIN_STYLE_ACTIVATE;
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else
-#endif
- rtgui_win_ondraw(win);
-
- if (win->on_deactivate != RT_NULL)
- {
- win->on_deactivate(widget, event);
- }
- }
- break;
-
- case RTGUI_EVENT_PAINT:
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL) widget->on_draw(widget, event);
- else
-#endif
- rtgui_win_ondraw(win);
- break;
-
- case RTGUI_EVENT_MOUSE_BUTTON:
- if (win->flag & RTGUI_WORKBENCH_FLAG_MODAL_MODE)
- {
- if (win->modal_widget != RT_NULL)
- return win->modal_widget->event_handler(win->modal_widget, event);
- }
- else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win),
- (struct rtgui_event_mouse*)event) == RT_FALSE)
- {
-#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_mouseclick != RT_NULL)
- {
- return widget->on_mouseclick(widget, event);
- }
-#endif
- }
- break;
-
- case RTGUI_EVENT_MOUSE_MOTION:
-#if 0
- if (rtgui_widget_dispatch_mouse_event(widget,
- (struct rtgui_event_mouse*)event) == RT_FALSE)
- {
-#ifndef RTGUI_USING_SMALL_SIZE
- /* handle event in current widget */
- if (widget->on_mousemotion != RT_NULL)
- {
- return widget->on_mousemotion(widget, event);
- }
-#endif
- }
- else return RT_TRUE;
-#endif
- break;
-
- case RTGUI_EVENT_KBD:
- if (win->flag & RTGUI_WORKBENCH_FLAG_MODAL_MODE)
- {
- if (win->modal_widget != RT_NULL)
- return win->modal_widget->event_handler(win->modal_widget, event);
- }
- else if (RTGUI_CONTAINER(win)->focused != widget)
- {
- RTGUI_CONTAINER(win)->focused->event_handler(RTGUI_CONTAINER(win)->focused, event);
- }
- break;
-
- default:
- /* call parent event handler */
- return rtgui_toplevel_event_handler(widget, event);
- }
-
- return RT_FALSE;
-}
-
-/* windows event loop */
-void rtgui_win_event_loop(rtgui_win_t* wnd)
-{
- /* the buffer uses to receive event */
- char event_buf[256];
-
- struct rtgui_event* event = (struct rtgui_event*)&event_buf[0];
-
- if (wnd->style & RTGUI_WIN_STYLE_MODAL)
- {
- while (wnd->style & RTGUI_WIN_STYLE_MODAL)
- {
- if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK)
- {
- /* perform event handler */
- RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event);
- }
- }
- }
- else
- {
- while (!(wnd->style & RTGUI_WIN_STYLE_CLOSED))
- {
- if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK)
- {
- /* perform event handler */
- RTGUI_WIDGET(wnd)->event_handler(RTGUI_WIDGET(wnd), event);
- }
- }
- }
-
- /* destroy window */
- rtgui_widget_destroy(RTGUI_WIDGET(wnd));
-}
-
-void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect)
-{
- struct rtgui_event_win_resize event;
-
- if (win == RT_NULL || rect == RT_NULL) return;
-
- RTGUI_WIDGET(win)->extent = *rect;
-
- if (RTGUI_TOPLEVEL(win)->server != RT_NULL)
- {
- /* set window resize event to server */
- RTGUI_EVENT_WIN_RESIZE_INIT(&event);
- event.wid = win;
- event.rect = *rect;
-
- rtgui_thread_send(RTGUI_TOPLEVEL(win)->server, &(event.parent), sizeof(struct rtgui_event_win_resize));
- }
-}
-
-#ifndef RTGUI_USING_SMALL_SIZE
-void rtgui_win_set_box(rtgui_win_t* win, rtgui_box_t* box)
-{
- if (win == RT_NULL || box == RT_NULL) return;
-
- rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(box));
- rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(win)->extent));
-}
-#endif
-
-void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler)
-{
- if (win != RT_NULL)
- {
- win->on_activate = handler;
- }
-}
-
-void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler)
-{
- if (win != RT_NULL)
- {
- win->on_deactivate = handler;
- }
-}
-
-void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler)
-{
- if (win != RT_NULL)
- {
- win->on_close = handler;
- }
-}
-
-void rtgui_win_set_title(rtgui_win_t* win, const char *title)
-{
- /* send title to server */
- if (RTGUI_TOPLEVEL(win)->server != RT_NULL)
- {
- }
-
- /* modify in local side */
- if (win->title != RT_NULL)
- {
- rtgui_free(win->title);
- win->title = RT_NULL;
- }
-
- if (title != RT_NULL)
- {
- win->title = rt_strdup(title);
- }
-}
-
-char* rtgui_win_get_title(rtgui_win_t* win)
-{
- RT_ASSERT(win != RT_NULL);
-
- return win->title;
-}
diff --git a/rtgui/widgets/workbench.c b/rtgui/widgets/workbench.c
deleted file mode 100644
index 2408f1254e..0000000000
--- a/rtgui/widgets/workbench.c
+++ /dev/null
@@ -1,525 +0,0 @@
-/*
- * File : workbench.c
- * This file is part of RTGUI in RT-Thread RTOS
- * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
- *
- * The license and distribution terms for this file may be
- * found in the file LICENSE in this distribution or at
- * http://www.rt-thread.org/license/LICENSE
- *
- * Change Logs:
- * Date Author Notes
- * 2009-10-04 Bernard first version
- */
-#include <rtgui/rtgui_system.h>
-#include <rtgui/widgets/window.h>
-#include <rtgui/widgets/workbench.h>
-
-static void _rtgui_workbench_constructor(rtgui_workbench_t *workbench)
-{
- /* set event handler */
- rtgui_widget_set_event_handler(RTGUI_WIDGET(workbench), rtgui_workbench_event_handler);
-
- /* set attributes */
- workbench->flag = RTGUI_WORKBENCH_FLAG_DEFAULT;
- workbench->panel = RT_NULL;
- workbench->title = RT_NULL;
- workbench->current_view = RT_NULL;
- workbench->modal_code = RTGUI_MODAL_OK;
- workbench->modal_widget = RT_NULL;
-}
-
-static void _rtgui_workbench_destructor(rtgui_workbench_t *workbench)
-{
- RT_ASSERT(workbench != RT_NULL);
-
- if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL)
- {
- struct rtgui_event_panel_detach edetach;
- RTGUI_EVENT_PANEL_DETACH_INIT(&edetach);
-
- /* detach from panel */
- edetach.panel = workbench->panel;
-
- /* send PANEL DETACH to server */
- if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(workbench)->server,
- RTGUI_EVENT(&edetach), sizeof(struct rtgui_event_panel_detach)) != RT_EOK)
- return;
-
- RTGUI_TOPLEVEL(workbench)->server = RT_NULL;
- }
-
- /* release title */
- rt_free(workbench->title);
- workbench->title = RT_NULL;
-}
-
-rtgui_type_t *rtgui_workbench_type_get(void)
-{
- static rtgui_type_t *workbench_type = RT_NULL;
-
- if (!workbench_type)
- {
- workbench_type = rtgui_type_create("workbench", RTGUI_TOPLEVEL_TYPE,
- sizeof(rtgui_workbench_t),
- RTGUI_CONSTRUCTOR(_rtgui_workbench_constructor),
- RTGUI_DESTRUCTOR(_rtgui_workbench_destructor));
- }
-
- return workbench_type;
-}
-
-rtgui_workbench_t *rtgui_workbench_create(const char* panel_name, const unsigned char* title)
-{
- struct rtgui_workbench* workbench;
-
- /* the server thread id */
- rt_thread_t server = rtgui_thread_get_server();
- if (server == RT_NULL)
- {
- rt_kprintf("can't find rtgui server\n");
- return RT_NULL;
- }
-
- /* create workbench */
- workbench = (rtgui_workbench_t*) rtgui_widget_create (RTGUI_WORKBENCH_TYPE);
- if (workbench != RT_NULL)
- {
- /* the buffer uses to receive event */
- union
- {
- struct rtgui_event_panel_attach ecreate;
- struct rtgui_event_panel_info epanel;
-
- char buffer[256]; /* use to recv other information */
- } event;
-
- /* set workbench title */
- workbench->title = (unsigned char*)rt_strdup((char*)title);
-
- /* create application in server */
- RTGUI_EVENT_PANEL_ATTACH_INIT(&(event.ecreate));
-
- /* set the panel name and workbench */
- rt_strncpy(event.ecreate.panel_name, panel_name, RTGUI_NAME_MAX);
- event.ecreate.workbench = workbench;
-
- /* send PANEL ATTACH to server */
- if (rtgui_thread_send_sync(server,
- &(event.ecreate.parent), sizeof(struct rtgui_event_panel_attach)) != RTGUI_STATUS_OK)
- {
- return RT_NULL;
- }
-
- /* get PANEL INFO */
- rtgui_thread_recv_filter(RTGUI_EVENT_PANEL_INFO, &(event.epanel.parent), sizeof(event));
-
- /* set panel */
- workbench->panel = (struct rtgui_panel*)event.epanel.panel;
-
- /* connected */
- RTGUI_TOPLEVEL(workbench)->server = server;
-
- /* set extent of workbench */
- rtgui_widget_set_rect(RTGUI_WIDGET(workbench), &(event.epanel.extent));
-
- /* set workbench in thread */
- rtgui_thread_set_widget(RTGUI_WIDGET(workbench));
- }
-
- return workbench;
-}
-
-void rtgui_workbench_destroy(rtgui_workbench_t* workbench)
-{
- RT_ASSERT(workbench != RT_NULL);
-
- if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL)
- {
- struct rtgui_event_panel_detach edetach;
- RTGUI_EVENT_PANEL_DETACH_INIT(&edetach);
-
- /* detach from panel */
- edetach.panel = workbench->panel;
-
- /* send PANEL DETACH to server */
- if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(workbench)->server,
- RTGUI_EVENT(&edetach), sizeof(struct rtgui_event_panel_detach)) != RT_EOK)
- return;
-
- RTGUI_TOPLEVEL(workbench)->server = RT_NULL;
- }
-
- rtgui_widget_destroy(RTGUI_WIDGET(workbench));
-}
-
-void rtgui_workbench_set_flag(rtgui_workbench_t* workbench, rt_uint8_t flag)
-{
- RT_ASSERT(workbench != RT_NULL);
-
- workbench->flag = flag;
-}
-
-rt_bool_t rtgui_workbench_event_loop(rtgui_workbench_t* workbench)
-{
- /* the buffer uses to receive event */
- char event_buf[256];
- struct rtgui_event* event = (struct rtgui_event*)&event_buf[0];
-
- if (workbench->flag & RTGUI_WORKBENCH_FLAG_MODAL_MODE)
- {
- /* event loop for modal mode shown view */
- while (workbench->flag & RTGUI_WORKBENCH_FLAG_MODAL_MODE)
- {
- if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK)
- {
- RTGUI_WIDGET(workbench)->event_handler(RTGUI_WIDGET(workbench), event);
- }
- }
- }
- else
- {
- /* show workbench firstly */
- rtgui_workbench_show(workbench);
-
- while (!(workbench->flag & RTGUI_WORKBENCH_FLAG_CLOSED))
- {
- if (rtgui_thread_recv(event, sizeof(event_buf)) == RT_EOK)
- {
- RTGUI_WIDGET(workbench)->event_handler(RTGUI_WIDGET(workbench), event);
- }
- }
- }
-
- return RT_TRUE;
-}
-
-rt_err_t rtgui_workbench_show(rtgui_workbench_t* workbench)
-{
- RT_ASSERT(workbench != RT_NULL);
-
- if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL)
- {
- struct rtgui_event_panel_show eraise;
- RTGUI_EVENT_PANEL_SHOW_INIT(&eraise);
- eraise.workbench = workbench;
-
- eraise.panel = workbench->panel;
- if (rtgui_thread_send_sync(workbench->parent.server, RTGUI_EVENT(&eraise),
- sizeof(struct rtgui_event_panel_show)) != RT_EOK)
- return -RT_ERROR;
-
- RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(workbench));
- rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
- }
- else return -RT_ERROR;
-
- return RT_EOK;
-}
-
-rt_err_t rtgui_workbench_hide(rtgui_workbench_t* workbench)
-{
- if (RTGUI_TOPLEVEL(workbench)->server != RT_NULL)
- {
- struct rtgui_event_panel_hide ehide;
- RTGUI_EVENT_PANEL_HIDE_INIT(&ehide);
-
- RT_ASSERT(workbench != RT_NULL);
- if (workbench->parent.server == RT_NULL) return -RT_ERROR;
-
- ehide.panel = workbench->panel;
- if (rtgui_thread_send_sync(RTGUI_TOPLEVEL(workbench)->server, RTGUI_EVENT(&ehide),
- sizeof(struct rtgui_event_panel_hide)) != RT_EOK)
- return -RT_ERROR;
-
- RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench));
- rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
- }
-
- return RT_EOK;
-}
-
-rt_bool_t rtgui_workbench_event_handler(rtgui_widget_t* widget, rtgui_event_t* event)
-{
- struct rtgui_workbench* workbench = (struct rtgui_workbench*)widget;
-
- switch (event->type)
- {
- case RTGUI_EVENT_PANEL_DETACH:
- RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench));
- RTGUI_TOPLEVEL(workbench)->server = RT_NULL;
- return RT_TRUE;
-
- case RTGUI_EVENT_PANEL_SHOW:
- /* show workbench in server */
- rtgui_workbench_show(workbench);
- break;
-
- case RTGUI_EVENT_PANEL_HIDE:
- /* hide widget */
- RTGUI_WIDGET_HIDE(widget);
- break;
-
- case RTGUI_EVENT_MOUSE_MOTION:
- {
- struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
- struct rtgui_toplevel* top = RTGUI_TOPLEVEL(emouse->wid);
-
- /* check the destination window */
- if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
- {
- RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
- }
- else
- {
- /* let viewer to handle it */
- rtgui_view_t* view = workbench->current_view;
- if (view != RT_NULL &&
- RTGUI_WIDGET(view)->event_handler != RT_NULL)
- {
- RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
- }
- }
- }
- break;
-
- case RTGUI_EVENT_MOUSE_BUTTON:
- {
- struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
- struct rtgui_toplevel* top = RTGUI_TOPLEVEL(emouse->wid);
-
- /* check the destination window */
- if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
- {
- RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
- }
- else
- {
- if (RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
- {
- /* let modal widget to handle it */
- if (workbench->modal_widget != RT_NULL &&
- workbench->modal_widget->event_handler != RT_NULL)
- {
- workbench->modal_widget->event_handler(workbench->modal_widget, event);
- }
- }
- else
- {
- /* let viewer to handle it */
- rtgui_view_t* view = workbench->current_view;
- if (view != RT_NULL &&
- RTGUI_WIDGET(view)->event_handler != RT_NULL)
- {
- RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
- }
- }
- }
- }
- break;
-
- case RTGUI_EVENT_KBD:
- {
- struct rtgui_event_kbd* kbd = (struct rtgui_event_kbd*)event;
- struct rtgui_toplevel* top = RTGUI_TOPLEVEL(kbd->wid);
-
- /* check the destination window */
- if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
- {
- RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
- }
- else
- {
- if (RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
- {
- /* let modal widget to handle it */
- if (workbench->modal_widget != RT_NULL &&
- workbench->modal_widget->event_handler != RT_NULL)
- {
- workbench->modal_widget->event_handler(workbench->modal_widget, event);
- }
- }
- else
- {
- if (RTGUI_CONTAINER(widget)->focused == widget)
- {
- /* set focused widget to the current view */
- if (workbench->current_view != RT_NULL)
- rtgui_widget_focus(RTGUI_WIDGET(RTGUI_CONTAINER(workbench->current_view)->focused));
- }
-
- return rtgui_toplevel_event_handler(widget, event);
- }
- }
- }
- break;
-
- case RTGUI_EVENT_PAINT:
- {
- struct rtgui_event_paint* epaint = (struct rtgui_event_paint*)event;
- struct rtgui_toplevel* top = RTGUI_TOPLEVEL(epaint->wid);
-
- /* check the destination window */
- if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
- {
- RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
- }
- else
- {
- rtgui_view_t* view;
-
- /* paint a view */
- view = workbench->current_view;
- if (view != RT_NULL)
- {
- /* remake a paint event */
- RTGUI_EVENT_PAINT_INIT(epaint);
- epaint->wid = RT_NULL;
-
- /* send this event to the view */
- if (RTGUI_WIDGET(view)->event_handler != RT_NULL)
- {
- RTGUI_WIDGET(view)->event_handler(RTGUI_WIDGET(view), event);
- }
- }
- else
- {
- struct rtgui_dc* dc;
- struct rtgui_rect rect;
-
- dc = rtgui_dc_begin_drawing(widget);
- rtgui_widget_get_rect(widget, &rect);
- rtgui_dc_fill_rect(dc, &rect);
- rtgui_dc_end_drawing(dc);
- }
- }
- }
- break;
-
- case RTGUI_EVENT_CLIP_INFO:
- {
- struct rtgui_event_clip_info* eclip = (struct rtgui_event_clip_info*)event;
- struct rtgui_widget* dest_widget = RTGUI_WIDGET(eclip->wid);
-
- if (dest_widget != RT_NULL && dest_widget->event_handler != RT_NULL)
- {
- dest_widget->event_handler(dest_widget, event);
- }
- else
- {
- return rtgui_toplevel_event_handler(widget, event);
- }
- }
- break;
-
- case RTGUI_EVENT_WIN_CLOSE:
- case RTGUI_EVENT_WIN_ACTIVATE:
- case RTGUI_EVENT_WIN_DEACTIVATE:
- {
- struct rtgui_event_win* wevent = (struct rtgui_event_win*)event;
- struct rtgui_widget* dest_widget = RTGUI_WIDGET(wevent->wid);
- if (dest_widget != RT_NULL && dest_widget->event_handler != RT_NULL)
- {
- dest_widget->event_handler(dest_widget, event);
- }
- }
- break;
-
- case RTGUI_EVENT_WIN_MOVE:
- {
- struct rtgui_event_win_move* wevent = (struct rtgui_event_win_move*)event;
- struct rtgui_toplevel* top = RTGUI_TOPLEVEL(wevent->wid);
- if (top != RT_NULL && RTGUI_WIDGET(top)->event_handler != RT_NULL)
- {
- RTGUI_WIDGET(top)->event_handler(RTGUI_WIDGET(top), event);
- }
- }
- break;
-
- default:
- return rtgui_toplevel_event_handler(widget, event);
- }
-
- return RT_TRUE;
-}
-
-/*
- *
- * view on workbench
- *
- */
-
-void rtgui_workbench_add_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
-{
- rtgui_container_add_child(RTGUI_CONTAINER(workbench), RTGUI_WIDGET(view));
- /* hide view in default */
- RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view));
-
- /* reset view extent */
- rtgui_widget_set_rect(RTGUI_WIDGET(view), &(RTGUI_WIDGET(workbench)->extent));
-}
-
-void rtgui_workbench_remove_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
-{
- if (view == workbench->current_view)
- rtgui_workbench_hide_view(workbench, view);
-
- rtgui_container_remove_child(RTGUI_CONTAINER(workbench), RTGUI_WIDGET(view));
-}
-
-void rtgui_workbench_show_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
-{
- RT_ASSERT(workbench != RT_NULL);
- RT_ASSERT(view != RT_NULL);
-
- /* already shown */
- if (workbench->current_view == view) return;
-
- if (workbench->current_view != RT_NULL)
- {
- /* hide old view */
- RTGUI_WIDGET_HIDE(RTGUI_WIDGET(workbench->current_view));
- }
-
- /* show view */
- RTGUI_WIDGET_UNHIDE(RTGUI_WIDGET(view));
- workbench->current_view = view;
-
- /* update workbench clip */
- rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
-
- if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(workbench)))
- {
- rtgui_widget_update(RTGUI_WIDGET(view));
- }
-}
-
-void rtgui_workbench_hide_view(rtgui_workbench_t* workbench, rtgui_view_t* view)
-{
- RT_ASSERT(workbench != RT_NULL);
- RT_ASSERT(view != RT_NULL);
-
- /* hide view */
- RTGUI_WIDGET_HIDE(RTGUI_WIDGET(view));
-
- if (view == workbench->current_view)
- {
- rtgui_view_t *next_view;
-
- workbench->current_view = RT_NULL;
-
- next_view = RTGUI_VIEW(rtgui_widget_get_next_sibling(RTGUI_WIDGET(view)));
- if (next_view == RT_NULL)
- next_view = RTGUI_VIEW(rtgui_widget_get_prev_sibling(RTGUI_WIDGET(view)));
-
- if (next_view != RT_NULL)
- {
- rtgui_view_show(next_view, RT_FALSE);
- }
- else
- {
- /* update workbench clip */
- rtgui_toplevel_update_clip(RTGUI_TOPLEVEL(workbench));
- }
- }
-}