summaryrefslogtreecommitdiff
path: root/components/rtgui/widgets
diff options
context:
space:
mode:
author[email protected] <[email protected]>2012-11-26 02:42:52 +0000
committer[email protected] <[email protected]>2012-11-26 02:42:52 +0000
commit62447b2cd84b529f7dbf6712c29d7ac4ff0c1e12 (patch)
tree399aa1bbc0d4c632d7dc2804ed76e5c62b5cec27 /components/rtgui/widgets
parent9789907ca1b4c43ee34fac6e94e5a48f76aaca3c (diff)
sync RTGUI with github(https://github.com/RT-Thread/RTGUI) 9ae08379da5b698d6facc40bd0415de2e254ae9c
As always, full log is in GitHub. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2449 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/rtgui/widgets')
-rw-r--r--components/rtgui/widgets/box.c406
-rw-r--r--components/rtgui/widgets/button.c378
-rw-r--r--components/rtgui/widgets/checkbox.c200
-rw-r--r--components/rtgui/widgets/combobox.c374
-rw-r--r--components/rtgui/widgets/container.c368
-rw-r--r--components/rtgui/widgets/edit.c3191
-rw-r--r--components/rtgui/widgets/filelist_view.c1251
-rw-r--r--components/rtgui/widgets/groupbox.c170
-rw-r--r--components/rtgui/widgets/iconbox.c248
-rw-r--r--components/rtgui/widgets/label.c114
-rw-r--r--components/rtgui/widgets/list_view.c971
-rw-r--r--components/rtgui/widgets/listbox.c591
-rw-r--r--components/rtgui/widgets/listctrl.c652
-rw-r--r--components/rtgui/widgets/menu.c427
-rw-r--r--components/rtgui/widgets/mv_view.c81
-rw-r--r--components/rtgui/widgets/notebook.c877
-rw-r--r--components/rtgui/widgets/panel.c84
-rw-r--r--components/rtgui/widgets/plot.c231
-rw-r--r--components/rtgui/widgets/plot_curve.c46
-rw-r--r--components/rtgui/widgets/progressbar.c76
-rw-r--r--components/rtgui/widgets/radiobox.c376
-rw-r--r--components/rtgui/widgets/scrollbar.c906
-rw-r--r--components/rtgui/widgets/slider.c404
-rw-r--r--components/rtgui/widgets/staticline.c102
-rw-r--r--components/rtgui/widgets/textbox.c401
-rw-r--r--components/rtgui/widgets/textview.c522
-rw-r--r--components/rtgui/widgets/title.c66
-rw-r--r--components/rtgui/widgets/widget.c870
-rw-r--r--components/rtgui/widgets/window.c965
29 files changed, 8078 insertions, 7270 deletions
diff --git a/components/rtgui/widgets/box.c b/components/rtgui/widgets/box.c
index 2c6452fc35..47c704b7c9 100644
--- a/components/rtgui/widgets/box.c
+++ b/components/rtgui/widgets/box.c
@@ -16,273 +16,273 @@
static void _rtgui_box_constructor(rtgui_box_t *box)
{
- /* init widget and set event handler */
- rtgui_object_set_event_handler(RTGUI_OBJECT(box), RT_NULL);
+ /* init widget and set event handler */
+ rtgui_object_set_event_handler(RTGUI_OBJECT(box), RT_NULL);
- /* set proper of control */
- box->orient = RTGUI_HORIZONTAL;
- box->border_size = RTGUI_BORDER_DEFAULT_WIDTH;
- box->container = RT_NULL;
+ /* set proper of control */
+ box->orient = RTGUI_HORIZONTAL;
+ box->border_size = RTGUI_BORDER_DEFAULT_WIDTH;
+ box->container = RT_NULL;
}
DEFINE_CLASS_TYPE(box, "box",
- RTGUI_OBJECT_TYPE,
- _rtgui_box_constructor,
- RT_NULL,
- sizeof(struct rtgui_box));
+ RTGUI_OBJECT_TYPE,
+ _rtgui_box_constructor,
+ RT_NULL,
+ sizeof(struct rtgui_box));
-struct rtgui_box* rtgui_box_create(int orientation, int border_size)
+struct rtgui_box *rtgui_box_create(int orientation, int border_size)
{
- struct rtgui_box* box;
+ struct rtgui_box *box;
- box = (struct rtgui_box*) rtgui_object_create (RTGUI_BOX_TYPE);
+ box = (struct rtgui_box *) rtgui_object_create(RTGUI_BOX_TYPE);
if (box != RT_NULL)
{
- box->orient = orientation;
- box->border_size = border_size;
- }
+ box->orient = orientation;
+ box->border_size = border_size;
+ }
- return box;
+ return box;
}
RTM_EXPORT(rtgui_box_create);
-void rtgui_box_destroy(struct rtgui_box* box)
+void rtgui_box_destroy(struct rtgui_box *box)
{
- rtgui_object_destroy(RTGUI_OBJECT(box));
+ rtgui_object_destroy(RTGUI_OBJECT(box));
}
RTM_EXPORT(rtgui_box_destroy);
-static void rtgui_box_layout_vertical(struct rtgui_box* box, struct rtgui_rect* extent)
+static void rtgui_box_layout_vertical(struct rtgui_box *box, struct rtgui_rect *extent)
{
- 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);
+ 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;
- /* find spaces */
- space_count = 0;
- total_height = 0;
- space_height = 0;
+ /* prepare the resize event */
+ RTGUI_EVENT_RESIZE_INIT(&size_event);
- rtgui_list_foreach(node, &(box->container->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;
- }
+ /* find spaces */
+ space_count = 0;
+ total_height = 0;
+ space_height = 0;
- /* calculate the height for each spaces */
- if (space_count != 0)
- {
- space_height = (rtgui_rect_height(*extent) - total_height - (box->border_size << 1)) / space_count;
- }
+ rtgui_list_foreach(node, &(box->container->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(*extent) - total_height - (box->border_size << 1)) / space_count;
+ }
- /* init (x, y) and box width */
- next_x = extent->x1 + box->border_size;
- next_y = extent->y1 + box->border_size;
- box_width = rtgui_rect_width(*extent) - (box->border_size << 1);
+ /* init (x, y) and box width */
+ next_x = extent->x1 + box->border_size;
+ next_y = extent->y1 + box->border_size;
+ box_width = rtgui_rect_width(*extent) - (box->border_size << 1);
- /* layout each widget */
- rtgui_list_foreach(node, &(box->container->children))
- {
- struct rtgui_rect *rect;
- rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
+ /* layout each widget */
+ rtgui_list_foreach(node, &(box->container->children))
+ {
+ struct rtgui_rect *rect;
+ rtgui_widget_t *widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
- /* get extent of widget */
- rect = &(widget->extent);
+ /* 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;
+ /* 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);
+ /* 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;
+ 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;
+ 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;
- }
+ 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;
- }
+ 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;
- RTGUI_OBJECT(widget)->event_handler(RTGUI_OBJECT(widget),
- &size_event.parent);
+ /* 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;
+ RTGUI_OBJECT(widget)->event_handler(RTGUI_OBJECT(widget),
+ &size_event.parent);
- /* point to next height */
- next_y = rect->y2 + box->border_size;
- }
+ /* point to next height */
+ next_y = rect->y2 + box->border_size;
+ }
}
-static void rtgui_box_layout_horizontal(struct rtgui_box* box, struct rtgui_rect* extent)
+static void rtgui_box_layout_horizontal(struct rtgui_box *box, struct rtgui_rect *extent)
{
- 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;
+ 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);
+ /* prepare the resize event */
+ RTGUI_EVENT_RESIZE_INIT(&size_event);
- /* find spaces */
- space_count = 0;
- total_width = 0;
- space_width = 0;
+ /* find spaces */
+ space_count = 0;
+ total_width = 0;
+ space_width = 0;
- rtgui_list_foreach(node, &(box->container->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;
- }
+ rtgui_list_foreach(node, &(box->container->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(*extent) - total_width) / space_count;
- }
+ if (space_count != 0)
+ {
+ /* calculate the height for each spaces */
+ space_width = (rtgui_rect_width(*extent) - total_width) / space_count;
+ }
- /* init (x, y) and box height */
- next_x = extent->x1 + box->border_size;
- next_y = extent->y1 + box->border_size;
- box_height = rtgui_rect_height(*extent) - (box->border_size << 1);
+ /* init (x, y) and box height */
+ next_x = extent->x1 + box->border_size;
+ next_y = extent->y1 + box->border_size;
+ box_height = rtgui_rect_height(*extent) - (box->border_size << 1);
- /* layout each widget */
- rtgui_list_foreach(node, &(box->container->children))
- {
- rtgui_rect_t *rect;
- rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
+ /* layout each widget */
+ rtgui_list_foreach(node, &(box->container->children))
+ {
+ rtgui_rect_t *rect;
+ rtgui_widget_t *widget = rtgui_list_entry(node, struct rtgui_widget, sibling);
- /* get extent of widget */
- rect = &(widget->extent);
+ /* 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;
+ /* 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);
+ /* 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;
+ 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;
+ 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;
- }
+ 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;
- }
+ 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;
- RTGUI_OBJECT(widget)->event_handler(RTGUI_OBJECT(widget),
- &size_event.parent);
+ /* 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;
+ RTGUI_OBJECT(widget)->event_handler(RTGUI_OBJECT(widget),
+ &size_event.parent);
- /* point to next width */
- next_x = rect->x2 + box->border_size;
- }
+ /* point to next width */
+ next_x = rect->x2 + box->border_size;
+ }
}
-void rtgui_box_layout(rtgui_box_t* box)
+void rtgui_box_layout(rtgui_box_t *box)
{
- struct rtgui_rect extent;
+ struct rtgui_rect extent;
RT_ASSERT(box != RT_NULL);
- if (box->container == RT_NULL) return;
+ if (box->container == RT_NULL) return;
- rtgui_widget_get_extent(RTGUI_WIDGET(box->container), &extent);
- if (box->orient & RTGUI_VERTICAL)
- {
- rtgui_box_layout_vertical(box, &extent);
- }
- else
- {
- rtgui_box_layout_horizontal(box, &extent);
- }
+ rtgui_widget_get_extent(RTGUI_WIDGET(box->container), &extent);
+ if (box->orient & RTGUI_VERTICAL)
+ {
+ rtgui_box_layout_vertical(box, &extent);
+ }
+ else
+ {
+ rtgui_box_layout_horizontal(box, &extent);
+ }
- /* update box and its children clip */
- if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(box->container)))
- {
- rtgui_widget_update_clip(RTGUI_WIDGET(box->container));
- }
+ /* update box and its children clip */
+ if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(box->container)))
+ {
+ rtgui_widget_update_clip(RTGUI_WIDGET(box->container));
+ }
}
RTM_EXPORT(rtgui_box_layout);
-void rtgui_box_layout_rect(rtgui_box_t* box, struct rtgui_rect* rect)
+void rtgui_box_layout_rect(rtgui_box_t *box, struct rtgui_rect *rect)
{
- RT_ASSERT(box != RT_NULL);
+ RT_ASSERT(box != RT_NULL);
- if (box->container == RT_NULL) return;
+ if (box->container == RT_NULL) return;
- if (box->orient & RTGUI_VERTICAL)
- {
- rtgui_box_layout_vertical(box, rect);
- }
- else
- {
- rtgui_box_layout_horizontal(box, rect);
- }
+ if (box->orient & RTGUI_VERTICAL)
+ {
+ rtgui_box_layout_vertical(box, rect);
+ }
+ else
+ {
+ rtgui_box_layout_horizontal(box, rect);
+ }
- /* update box and its children clip */
- if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(box->container)))
- {
- rtgui_widget_update_clip(RTGUI_WIDGET(box->container));
- }
+ /* update box and its children clip */
+ if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(box->container)))
+ {
+ rtgui_widget_update_clip(RTGUI_WIDGET(box->container));
+ }
}
RTM_EXPORT(rtgui_box_layout_rect);
diff --git a/components/rtgui/widgets/button.c b/components/rtgui/widgets/button.c
index 26add4e33e..6f1f7984f3 100644
--- a/components/rtgui/widgets/button.c
+++ b/components/rtgui/widgets/button.c
@@ -16,276 +16,276 @@
#include <rtgui/widgets/button.h>
#include <rtgui/widgets/window.h>
-static rt_bool_t rtgui_button_onunfocus(struct rtgui_object* object, rtgui_event_t* event);
+static rt_bool_t rtgui_button_onunfocus(struct rtgui_object *object, rtgui_event_t *event);
static void _rtgui_button_constructor(rtgui_button_t *button)
{
- /* init widget and set event handler */
- RTGUI_WIDGET(button)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- rtgui_object_set_event_handler(RTGUI_OBJECT(button), rtgui_button_event_handler);
- rtgui_widget_set_onunfocus(RTGUI_WIDGET(button), rtgui_button_onunfocus);
- /* un-press button */
- button->flag = 0;
+ /* init widget and set event handler */
+ RTGUI_WIDGET(button)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+ rtgui_object_set_event_handler(RTGUI_OBJECT(button), rtgui_button_event_handler);
+ rtgui_widget_set_onunfocus(RTGUI_WIDGET(button), rtgui_button_onunfocus);
+ /* un-press button */
+ button->flag = 0;
- /* set flag and on_button event handler */
- button->pressed_image = RT_NULL;
- button->unpressed_image = RT_NULL;
- button->on_button = RT_NULL;
+ /* 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(button) = default_foreground;
- RTGUI_WIDGET_BACKGROUND(button) = RTGUI_RGB(212, 208, 200);
- RTGUI_WIDGET_TEXTALIGN(button) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
+ /* set gc */
+ RTGUI_WIDGET_FOREGROUND(button) = default_foreground;
+ RTGUI_WIDGET_BACKGROUND(button) = RTGUI_RGB(212, 208, 200);
+ RTGUI_WIDGET_TEXTALIGN(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->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;
- }
+ if (button->unpressed_image != RT_NULL)
+ {
+ rtgui_image_destroy(button->unpressed_image);
+ button->unpressed_image = RT_NULL;
+ }
}
-DEFINE_CLASS_TYPE(button, "button",
- RTGUI_LABEL_TYPE,
- _rtgui_button_constructor,
- _rtgui_button_destructor,
- sizeof(struct rtgui_button));
+DEFINE_CLASS_TYPE(button, "button",
+ RTGUI_LABEL_TYPE,
+ _rtgui_button_constructor,
+ _rtgui_button_destructor,
+ sizeof(struct rtgui_button));
-rt_bool_t rtgui_button_event_handler(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_button_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_widget *widget;
- struct rtgui_button *btn;
+ struct rtgui_widget *widget;
+ struct rtgui_button *btn;
- RT_ASSERT(object != RT_NULL);
- RT_ASSERT(event != RT_NULL);
+ RT_ASSERT(object != RT_NULL);
+ RT_ASSERT(event != RT_NULL);
- widget = RTGUI_WIDGET(object);
- btn = RTGUI_BUTTON(widget);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- rtgui_theme_draw_button(btn);
- break;
+ widget = RTGUI_WIDGET(object);
+ btn = RTGUI_BUTTON(widget);
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
+ rtgui_theme_draw_button(btn);
+ break;
- case RTGUI_EVENT_KBD:
- {
- struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*) event;
+ case RTGUI_EVENT_KBD:
+ {
+ struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *) event;
- if (RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
- 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;
- }
+ if (RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
+ 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);
+ /* 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(RTGUI_OBJECT(widget), event);
- }
- }
- }
- break;
+ if ((btn->flag & RTGUI_BUTTON_FLAG_PRESS) && (btn->on_button != RT_NULL))
+ {
+ /* call on button handler */
+ btn->on_button(RTGUI_OBJECT(widget), event);
+ }
+ }
+ }
+ break;
- case RTGUI_EVENT_MOUSE_BUTTON:
- if (RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
- {
- struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
+ case RTGUI_EVENT_MOUSE_BUTTON:
+ if (RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
+ {
+ struct rtgui_event_mouse *emouse = (struct rtgui_event_mouse *)event;
- /* it's not this widget event, clean status */
- if (rtgui_rect_contains_point(&(RTGUI_WIDGET(btn)->extent),
- emouse->x, emouse->y) != RT_EOK)
- {
- btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
- /* draw button */
- rtgui_theme_draw_button(btn);
+ /* it's not this widget event, clean status */
+ if (rtgui_rect_contains_point(&(RTGUI_WIDGET(btn)->extent),
+ emouse->x, emouse->y) != RT_EOK)
+ {
+ btn->flag &= ~RTGUI_BUTTON_FLAG_PRESS;
+ /* draw button */
+ rtgui_theme_draw_button(btn);
- break;
- }
+ break;
+ }
- 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;
- }
+ 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 */
- rtgui_theme_draw_button(btn);
+ /* draw button */
+ rtgui_theme_draw_button(btn);
- if (btn->on_button != RT_NULL)
- {
- /* call on button handler */
- btn->on_button(RTGUI_OBJECT(widget), event);
- }
+ if (btn->on_button != RT_NULL)
+ {
+ /* call on button handler */
+ btn->on_button(RTGUI_OBJECT(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(RTGUI_OBJECT(widget), event);
+ /* invokes call back */
+ if (widget->on_mouseclick != RT_NULL &&
+ emouse->button & RTGUI_MOUSE_BUTTON_UP)
+ return widget->on_mouseclick(RTGUI_OBJECT(widget), event);
#endif
- }
- }
- else
- {
- if (emouse->button & RTGUI_MOUSE_BUTTON_LEFT)
- {
- /* set the last mouse event handled widget */
- struct rtgui_win* win;
+ }
+ }
+ else
+ {
+ if (emouse->button & RTGUI_MOUSE_BUTTON_LEFT)
+ {
+ /* set the last mouse event handled widget */
+ struct rtgui_win *win;
- win = RTGUI_WIN(RTGUI_WIDGET(btn)->toplevel);
- win->last_mevent_widget = RTGUI_WIDGET(btn);
+ win = RTGUI_WIN(RTGUI_WIDGET(btn)->toplevel);
+ win->last_mevent_widget = RTGUI_WIDGET(btn);
- /* 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;
- }
+ /* 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 */
- rtgui_theme_draw_button(btn);
+ /* draw button */
+ 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(RTGUI_OBJECT(widget), event);
+ /* invokes call back */
+ if (widget->on_mouseclick != RT_NULL &&
+ emouse->button & RTGUI_MOUSE_BUTTON_UP)
+ return widget->on_mouseclick(RTGUI_OBJECT(widget), event);
#endif
- if (!(btn->flag & RTGUI_BUTTON_FLAG_PRESS) && (btn->on_button != RT_NULL))
- {
- /* call on button handler */
- btn->on_button(RTGUI_OBJECT(widget), event);
- }
- }
+ if (!(btn->flag & RTGUI_BUTTON_FLAG_PRESS) && (btn->on_button != RT_NULL))
+ {
+ /* call on button handler */
+ btn->on_button(RTGUI_OBJECT(widget), event);
+ }
+ }
- }
+ }
- return RT_TRUE;
- }
- default:
- return rtgui_widget_event_handler(object, event);
- }
+ return RT_TRUE;
+ }
+ default:
+ return rtgui_widget_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_button_event_handler);
-rtgui_button_t* rtgui_button_create(const char* text)
+rtgui_button_t *rtgui_button_create(const char *text)
{
- struct rtgui_button* btn;
+ struct rtgui_button *btn;
- btn = (struct rtgui_button*) rtgui_widget_create (RTGUI_BUTTON_TYPE);
+ btn = (struct rtgui_button *) rtgui_widget_create(RTGUI_BUTTON_TYPE);
if (btn != RT_NULL)
{
- rtgui_rect_t rect;
+ 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);
+ /* 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;
}
RTM_EXPORT(rtgui_button_create);
-rtgui_button_t* rtgui_pushbutton_create(const char* text)
+rtgui_button_t *rtgui_pushbutton_create(const char *text)
{
- rtgui_button_t* btn;
+ rtgui_button_t *btn;
- btn = rtgui_button_create(text);
- if (btn != RT_NULL) btn->flag |= RTGUI_BUTTON_TYPE_PUSH;
+ btn = rtgui_button_create(text);
+ if (btn != RT_NULL) btn->flag |= RTGUI_BUTTON_TYPE_PUSH;
- return btn;
+ return btn;
}
RTM_EXPORT(rtgui_pushbutton_create);
-void rtgui_button_destroy(rtgui_button_t* btn)
+void rtgui_button_destroy(rtgui_button_t *btn)
{
- rtgui_widget_destroy(RTGUI_WIDGET(btn));
+ rtgui_widget_destroy(RTGUI_WIDGET(btn));
}
RTM_EXPORT(rtgui_button_destroy);
-void rtgui_button_set_pressed_image(rtgui_button_t* btn, rtgui_image_t* image)
+void rtgui_button_set_pressed_image(rtgui_button_t *btn, rtgui_image_t *image)
{
- RT_ASSERT(btn != RT_NULL);
+ RT_ASSERT(btn != RT_NULL);
- btn->pressed_image = image;
+ btn->pressed_image = image;
}
RTM_EXPORT(rtgui_button_set_pressed_image);
-void rtgui_button_set_unpressed_image(rtgui_button_t* btn, rtgui_image_t* image)
+void rtgui_button_set_unpressed_image(rtgui_button_t *btn, rtgui_image_t *image)
{
- RT_ASSERT(btn != RT_NULL);
+ RT_ASSERT(btn != RT_NULL);
- btn->unpressed_image = image;
+ btn->unpressed_image = image;
}
RTM_EXPORT(rtgui_button_set_unpressed_image);
-void rtgui_button_set_onbutton(rtgui_button_t* btn, rtgui_onbutton_func_t func)
+void rtgui_button_set_onbutton(rtgui_button_t *btn, rtgui_onbutton_func_t func)
{
- RT_ASSERT(btn != RT_NULL);
+ RT_ASSERT(btn != RT_NULL);
- btn->on_button = func;
+ btn->on_button = func;
}
RTM_EXPORT(rtgui_button_set_onbutton);
-static rt_bool_t rtgui_button_onunfocus(struct rtgui_object* object, rtgui_event_t* event)
+static rt_bool_t rtgui_button_onunfocus(struct rtgui_object *object, rtgui_event_t *event)
{
- rtgui_rect_t rect;
- rtgui_widget_t *widget;
- struct rtgui_dc *dc;
+ rtgui_rect_t rect;
+ rtgui_widget_t *widget;
+ struct rtgui_dc *dc;
- RT_ASSERT(object);
- widget = RTGUI_WIDGET(object);
+ RT_ASSERT(object);
+ widget = RTGUI_WIDGET(object);
- dc = rtgui_dc_begin_drawing(widget);
- if(dc == RT_NULL) return RT_FALSE;
-
- rtgui_widget_get_rect(widget, &rect);
+ dc = rtgui_dc_begin_drawing(widget);
+ if (dc == RT_NULL) return RT_FALSE;
- if(!RTGUI_WIDGET_IS_FOCUSED(widget))
- {
- /* only clear focus rect */
- rtgui_color_t color;
- rtgui_rect_inflate(&rect, -2);
- color = RTGUI_DC_FC(dc);
- RTGUI_DC_FC(dc) = RTGUI_DC_BC(dc);
- rtgui_dc_draw_focus_rect(dc, &rect);
- RTGUI_DC_FC(dc) = color;
- }
+ rtgui_widget_get_rect(widget, &rect);
+
+ if (!RTGUI_WIDGET_IS_FOCUSED(widget))
+ {
+ /* only clear focus rect */
+ rtgui_color_t color;
+ rtgui_rect_inflate(&rect, -2);
+ color = RTGUI_DC_FC(dc);
+ RTGUI_DC_FC(dc) = RTGUI_DC_BC(dc);
+ rtgui_dc_draw_focus_rect(dc, &rect);
+ RTGUI_DC_FC(dc) = color;
+ }
- rtgui_dc_end_drawing(dc);
- return RT_TRUE;
+ rtgui_dc_end_drawing(dc);
+ return RT_TRUE;
}
diff --git a/components/rtgui/widgets/checkbox.c b/components/rtgui/widgets/checkbox.c
index ee3b2a32f6..4f0c6a49bc 100644
--- a/components/rtgui/widgets/checkbox.c
+++ b/components/rtgui/widgets/checkbox.c
@@ -4,149 +4,149 @@
static void _rtgui_checkbox_constructor(rtgui_checkbox_t *box)
{
- /* init widget and set event handler */
- RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_checkbox_event_handler);
+ /* init widget and set event handler */
+ RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+ rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_checkbox_event_handler);
- /* set status */
- box->status_down = RTGUI_CHECKBOX_STATUS_UNCHECKED;
- box->on_button = RT_NULL;
+ /* set status */
+ box->status_down = RTGUI_CHECKBOX_STATUS_UNCHECKED;
+ box->on_button = RT_NULL;
- /* set default gc */
- RTGUI_WIDGET_TEXTALIGN(box) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
+ /* set default gc */
+ RTGUI_WIDGET_TEXTALIGN(box) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
}
DEFINE_CLASS_TYPE(checkbox, "checkbox",
- RTGUI_LABEL_TYPE,
- _rtgui_checkbox_constructor,
- RT_NULL,
- sizeof(struct rtgui_checkbox));
+ RTGUI_LABEL_TYPE,
+ _rtgui_checkbox_constructor,
+ RT_NULL,
+ sizeof(struct rtgui_checkbox));
-void rtgui_checkbox_set_onbutton(rtgui_checkbox_t* checkbox, rtgui_onbutton_func_t func)
+void rtgui_checkbox_set_onbutton(rtgui_checkbox_t *checkbox, rtgui_onbutton_func_t func)
{
- RT_ASSERT(checkbox != RT_NULL);
+ RT_ASSERT(checkbox != RT_NULL);
- checkbox->on_button = func;
+ checkbox->on_button = func;
}
-rt_bool_t rtgui_checkbox_event_handler(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_checkbox_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_checkbox *box;
+ struct rtgui_checkbox *box;
- RTGUI_WIDGET_EVENT_HANDLER_PREPARE
+ RTGUI_WIDGET_EVENT_HANDLER_PREPARE
- box = RTGUI_CHECKBOX(object);
+ box = RTGUI_CHECKBOX(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL)
- {
- return widget->on_draw(RTGUI_OBJECT(widget), event);
- }
- else
+ if (widget->on_draw != RT_NULL)
+ {
+ return widget->on_draw(RTGUI_OBJECT(widget), event);
+ }
+ else
#endif
- rtgui_theme_draw_checkbox(box);
- break;
+ 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);
+ 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;
- }
- }
+ 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);
+ /* 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(RTGUI_OBJECT(widget), event);
- }
+ /* call user callback */
+ if (widget->on_mouseclick != RT_NULL)
+ {
+ return widget->on_mouseclick(RTGUI_OBJECT(widget), event);
+ }
#endif
- if (box->on_button != RT_NULL)
- {
- box->on_button(RTGUI_OBJECT(widget), event);
- return RT_TRUE;
- }
- }
+ if (box->on_button != RT_NULL)
+ {
+ box->on_button(RTGUI_OBJECT(widget), event);
+ return RT_TRUE;
+ }
+ }
- return RT_TRUE;
- }
- default:
- return rtgui_widget_event_handler(object, event);
- }
+ return RT_TRUE;
+ }
+ default:
+ return rtgui_widget_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
-struct rtgui_checkbox* rtgui_checkbox_create(const char* text, rt_bool_t checked)
+struct rtgui_checkbox *rtgui_checkbox_create(const char *text, rt_bool_t checked)
{
- struct rtgui_checkbox* box;
+ struct rtgui_checkbox *box;
- box = (struct rtgui_checkbox*) rtgui_widget_create (RTGUI_CHECKBOX_TYPE);
+ box = (struct rtgui_checkbox *) rtgui_widget_create(RTGUI_CHECKBOX_TYPE);
if (box != RT_NULL)
{
- rtgui_rect_t rect;
+ 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);
+ /* 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;
- }
+ rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect);
+ rtgui_label_set_text(RTGUI_LABEL(box), text);
- return box;
+ 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)
+void rtgui_checkbox_destroy(rtgui_checkbox_t *box)
{
- rtgui_widget_destroy(RTGUI_WIDGET(box));
+ rtgui_widget_destroy(RTGUI_WIDGET(box));
}
-void rtgui_checkbox_set_checked(rtgui_checkbox_t* checkbox, rt_bool_t checked)
+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_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_bool_t rtgui_checkbox_get_checked(rtgui_checkbox_t *checkbox)
{
- RT_ASSERT(checkbox != RT_NULL);
+ RT_ASSERT(checkbox != RT_NULL);
- if (checkbox->status_down == RTGUI_CHECKBOX_STATUS_CHECKED)
- return RT_TRUE;
+ if (checkbox->status_down == RTGUI_CHECKBOX_STATUS_CHECKED)
+ return RT_TRUE;
- return RT_FALSE;
+ return RT_FALSE;
}
diff --git a/components/rtgui/widgets/combobox.c b/components/rtgui/widgets/combobox.c
index a1d4c8634b..50cac173b1 100644
--- a/components/rtgui/widgets/combobox.c
+++ b/components/rtgui/widgets/combobox.c
@@ -2,275 +2,279 @@
#include <rtgui/rtgui_theme.h>
#include <rtgui/widgets/combobox.h>
-static rt_bool_t rtgui_combobox_pulldown_hide(struct rtgui_object* object, struct rtgui_event* event);
+static rt_bool_t rtgui_combobox_pulldown_hide(struct rtgui_object *object, struct rtgui_event *event);
const static rt_uint8_t down_arrow[] = {0xff, 0x7e, 0x3c, 0x18};
static void _rtgui_combobox_constructor(rtgui_combobox_t *box)
{
- rtgui_rect_t rect = {0, 0, RTGUI_COMBOBOX_WIDTH, RTGUI_COMBOBOX_HEIGHT};
+ rtgui_rect_t rect = {0, 0, RTGUI_COMBOBOX_WIDTH, RTGUI_COMBOBOX_HEIGHT};
- /* init widget and set event handler */
- rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_combobox_event_handler);
- rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect);
+ /* init widget and set event handler */
+ rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_combobox_event_handler);
+ rtgui_widget_set_rect(RTGUI_WIDGET(box), &rect);
- RTGUI_WIDGET_TEXTALIGN(box) = RTGUI_ALIGN_CENTER_VERTICAL;
+ RTGUI_WIDGET_TEXTALIGN(box) = RTGUI_ALIGN_CENTER_VERTICAL;
- box->pd_pressed = RT_FALSE;
- box->current_item = 0;
- box->on_selected = RT_NULL;
- box->pd_win = RT_NULL;
+ box->pd_pressed = RT_FALSE;
+ box->current_item = 0;
+ box->on_selected = RT_NULL;
+ box->pd_win = RT_NULL;
}
static void _rtgui_combobox_destructor(rtgui_combobox_t *box)
{
- /* destroy pull down window */
- rtgui_win_destroy(box->pd_win);
+ /* destroy pull down window */
+ rtgui_win_destroy(box->pd_win);
- /* reset box field */
- box->pd_win = RT_NULL;
+ /* reset box field */
+ box->pd_win = RT_NULL;
}
-rt_bool_t rtgui_combobox_pdwin_onitem(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_combobox_pdwin_onitem(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_widget *widget;
- rtgui_win_t* pd_win;
- rtgui_combobox_t* combo;
- rtgui_listbox_t* list;
+ struct rtgui_widget *widget;
+ rtgui_win_t *pd_win;
+ rtgui_combobox_t *combo;
+ rtgui_listbox_t *list;
- RT_ASSERT(object != RT_NULL);
+ RT_ASSERT(object != RT_NULL);
- widget = RTGUI_WIDGET(object);
- list = RTGUI_LISTBOX(widget);
- pd_win = RTGUI_WIN(rtgui_widget_get_toplevel(widget));
- combo = RTGUI_COMBOBOX(pd_win->user_data);
- combo->current_item = list->current_item;
+ widget = RTGUI_WIDGET(object);
+ list = RTGUI_LISTBOX(widget);
+ pd_win = RTGUI_WIN(rtgui_widget_get_toplevel(widget));
+ combo = RTGUI_COMBOBOX(pd_win->user_data);
+ combo->current_item = list->current_item;
- if (combo->on_selected != RT_NULL)
- combo->on_selected(RTGUI_OBJECT(combo), RT_NULL);
+ if (combo->on_selected != RT_NULL)
+ combo->on_selected(RTGUI_OBJECT(combo), RT_NULL);
- rtgui_win_hiden(pd_win);
- rtgui_widget_update(RTGUI_WIDGET(combo));
+ rtgui_win_hiden(pd_win);
+ rtgui_widget_update(RTGUI_WIDGET(combo));
- return RT_FALSE;
+ return RT_FALSE;
}
-rt_bool_t rtgui_combobox_pdwin_ondeactive(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_combobox_pdwin_ondeactive(struct rtgui_object *object, struct rtgui_event *event)
{
- rtgui_win_hiden(RTGUI_WIN(object));
- return RT_TRUE;
+ rtgui_win_hiden(RTGUI_WIN(object));
+ return RT_TRUE;
}
-DEFINE_CLASS_TYPE(combobox, "combobox",
- RTGUI_WIDGET_TYPE,
- _rtgui_combobox_constructor,
- _rtgui_combobox_destructor,
- sizeof(struct rtgui_combobox));
+DEFINE_CLASS_TYPE(combobox, "combobox",
+ RTGUI_WIDGET_TYPE,
+ _rtgui_combobox_constructor,
+ _rtgui_combobox_destructor,
+ sizeof(struct rtgui_combobox));
-rtgui_combobox_t *rtgui_combobox_create(struct rtgui_listbox_item* items, rt_uint16_t count, struct rtgui_rect* rect)
+rtgui_combobox_t *rtgui_combobox_create(struct rtgui_listbox_item *items, rt_uint16_t count, struct rtgui_rect *rect)
{
- rtgui_combobox_t *box;
+ rtgui_combobox_t *box;
- box = (rtgui_combobox_t*)rtgui_widget_create(RTGUI_COMBOBOX_TYPE);
- box->items_count = count;
- box->items = items;
- rtgui_widget_set_rect(RTGUI_WIDGET(box), rect);
-
- box->pd_win = RT_NULL;
+ box = (rtgui_combobox_t *)rtgui_widget_create(RTGUI_COMBOBOX_TYPE);
+ box->items_count = count;
+ box->items = items;
+ rtgui_widget_set_rect(RTGUI_WIDGET(box), rect);
- return box;
+ box->pd_win = RT_NULL;
+
+ return box;
}
-void rtgui_combobox_destroy(rtgui_combobox_t* box)
+void rtgui_combobox_destroy(rtgui_combobox_t *box)
{
- rtgui_widget_destroy(RTGUI_WIDGET(box));
+ rtgui_widget_destroy(RTGUI_WIDGET(box));
}
-static void rtgui_combobox_ondraw(struct rtgui_combobox* box)
+static void rtgui_combobox_ondraw(struct rtgui_combobox *box)
{
- /* draw button */
- rtgui_color_t bc;
- struct rtgui_dc* dc;
- struct rtgui_rect rect, r;
+ /* draw button */
+ rtgui_color_t bc;
+ struct rtgui_dc *dc;
+ struct rtgui_rect rect, r;
- /* begin drawing */
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
- if (dc == RT_NULL) return;
+ /* begin drawing */
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
+ if (dc == RT_NULL) return;
- bc = RTGUI_WIDGET_BACKGROUND(box);
+ bc = RTGUI_WIDGET_BACKGROUND(box);
- /* get widget rect */
- rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
- RTGUI_WIDGET_BACKGROUND(box) = white;
+ /* get widget rect */
+ rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
+ RTGUI_WIDGET_BACKGROUND(box) = white;
- /* fill widget rect with background color */
- rtgui_dc_fill_rect(dc, &rect);
- rtgui_dc_draw_rect(dc, &rect);
+ /* fill widget rect with background color */
+ rtgui_dc_fill_rect(dc, &rect);
+ rtgui_dc_draw_rect(dc, &rect);
- /* draw current item */
- if (box->current_item < box->items_count)
- {
- rect.x1 += 5;
- rtgui_dc_draw_text(dc, box->items[box->current_item].name, &rect);
- }
+ /* draw current item */
+ if (box->current_item < box->items_count)
+ {
+ rect.x1 += 5;
+ rtgui_dc_draw_text(dc, box->items[box->current_item].name, &rect);
+ }
- /* restore background color */
- RTGUI_WIDGET_BACKGROUND(box) = bc;
+ /* restore background color */
+ RTGUI_WIDGET_BACKGROUND(box) = bc;
- /* draw pull down button */
- rect.x1 = rect.x2 - RTGUI_COMBOBOX_BUTTON_WIDTH;
- rtgui_rect_inflate(&rect, -1);
- rtgui_dc_fill_rect(dc, &rect);
- if (box->pd_pressed == RT_TRUE) rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
- else rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE);
+ /* draw pull down button */
+ rect.x1 = rect.x2 - RTGUI_COMBOBOX_BUTTON_WIDTH;
+ rtgui_rect_inflate(&rect, -1);
+ rtgui_dc_fill_rect(dc, &rect);
+ if (box->pd_pressed == RT_TRUE) rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
+ else rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_RAISE);
- r.x1 = 0; r.y1 = 0; r.x2 = 8; r.y2 = 4;
- rtgui_rect_moveto_align(&rect, &r, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
- rtgui_dc_draw_byte(dc, r.x1, r.y1, 4, down_arrow);
+ r.x1 = 0;
+ r.y1 = 0;
+ r.x2 = 8;
+ r.y2 = 4;
+ rtgui_rect_moveto_align(&rect, &r, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
+ rtgui_dc_draw_byte(dc, r.x1, r.y1, 4, down_arrow);
- /* end drawing */
- rtgui_dc_end_drawing(dc);
- return;
+ /* end drawing */
+ rtgui_dc_end_drawing(dc);
+ return;
}
-static rt_bool_t rtgui_combobox_onmouse_button(struct rtgui_combobox* box, struct rtgui_event_mouse* event)
+static rt_bool_t rtgui_combobox_onmouse_button(struct rtgui_combobox *box, struct rtgui_event_mouse *event)
{
- struct rtgui_rect rect;
+ struct rtgui_rect rect;
- /* get widget rect */
- rect = RTGUI_WIDGET(box)->extent;
+ /* get widget rect */
+ rect = RTGUI_WIDGET(box)->extent;
- /* move to the pull down button */
- rect.x1 = rect.x2 - RTGUI_COMBOBOX_BUTTON_WIDTH;
- if (rtgui_rect_contains_point(&rect, event->x, event->y) == RT_EOK)
- {
- /* handle mouse button on pull down button */
- if (event->button & RTGUI_MOUSE_BUTTON_LEFT &&
- event->button & RTGUI_MOUSE_BUTTON_DOWN)
- {
- box->pd_pressed = RT_TRUE;
- rtgui_widget_update(RTGUI_WIDGET(box));
- }
- else if (event->button & RTGUI_MOUSE_BUTTON_LEFT &&
- event->button & RTGUI_MOUSE_BUTTON_UP)
- {
- box->pd_pressed = RT_FALSE;
- rtgui_widget_update(RTGUI_WIDGET(box));
+ /* move to the pull down button */
+ rect.x1 = rect.x2 - RTGUI_COMBOBOX_BUTTON_WIDTH;
+ if (rtgui_rect_contains_point(&rect, event->x, event->y) == RT_EOK)
+ {
+ /* handle mouse button on pull down button */
+ if (event->button & RTGUI_MOUSE_BUTTON_LEFT &&
+ event->button & RTGUI_MOUSE_BUTTON_DOWN)
+ {
+ box->pd_pressed = RT_TRUE;
+ rtgui_widget_update(RTGUI_WIDGET(box));
+ }
+ else if (event->button & RTGUI_MOUSE_BUTTON_LEFT &&
+ event->button & RTGUI_MOUSE_BUTTON_UP)
+ {
+ box->pd_pressed = RT_FALSE;
+ rtgui_widget_update(RTGUI_WIDGET(box));
- /* pop pull down window */
- if (box->pd_win == RT_NULL)
- {
- rtgui_listbox_t *list;
+ /* pop pull down window */
+ if (box->pd_win == RT_NULL)
+ {
+ rtgui_listbox_t *list;
- /* create pull down window */
- rect = RTGUI_WIDGET(box)->extent;
- rect.y1 = rect.y2;
- rect.y2 = rect.y1 + 5 * (2 + rtgui_theme_get_selected_height());
- box->pd_win = rtgui_win_create(RT_NULL, "combo", &rect, RTGUI_WIN_STYLE_NO_TITLE);
- rtgui_win_set_ondeactivate(RTGUI_WIN(box->pd_win), rtgui_combobox_pulldown_hide);
- /* set user data to parent combobox */
- box->pd_win->user_data = (rt_uint32_t)box;
+ /* create pull down window */
+ rect = RTGUI_WIDGET(box)->extent;
+ rect.y1 = rect.y2;
+ /* give it 5 pixels margin, or the last item won't get shown */
+ rect.y2 = rect.y1 + box->items_count * (2 + rtgui_theme_get_selected_height()) + 5;
+ box->pd_win = rtgui_win_create(RT_NULL, "combo", &rect, RTGUI_WIN_STYLE_NO_TITLE);
+ rtgui_win_set_ondeactivate(RTGUI_WIN(box->pd_win), rtgui_combobox_pulldown_hide);
+ /* set user data to parent combobox */
+ box->pd_win->user_data = (rt_uint32_t)box;
- /* create list box */
- rtgui_rect_inflate(&rect, -1);
- list = rtgui_listbox_create(box->items, box->items_count, &rect);
- rtgui_container_add_child(RTGUI_CONTAINER(box->pd_win), RTGUI_WIDGET(list));
- rtgui_widget_focus(RTGUI_WIDGET(list));
+ /* create list box */
+ rtgui_rect_inflate(&rect, -1);
+ list = rtgui_listbox_create(box->items, box->items_count, &rect);
+ rtgui_container_add_child(RTGUI_CONTAINER(box->pd_win), RTGUI_WIDGET(list));
+ rtgui_widget_focus(RTGUI_WIDGET(list));
- rtgui_listbox_set_onitem(list, rtgui_combobox_pdwin_onitem);
- rtgui_win_set_ondeactivate(box->pd_win, rtgui_combobox_pdwin_ondeactive);
- }
+ rtgui_listbox_set_onitem(list, rtgui_combobox_pdwin_onitem);
+ rtgui_win_set_ondeactivate(box->pd_win, rtgui_combobox_pdwin_ondeactive);
+ }
- /* show combo box pull down window */
- rtgui_win_show(RTGUI_WIN(box->pd_win), RT_FALSE);
- }
+ /* show combo box pull down window */
+ rtgui_win_show(RTGUI_WIN(box->pd_win), RT_FALSE);
+ }
- return RT_TRUE;
- }
+ return RT_TRUE;
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
-rt_bool_t rtgui_combobox_event_handler(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_combobox_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_combobox *box;
- RTGUI_WIDGET_EVENT_HANDLER_PREPARE
+ struct rtgui_combobox *box;
+ RTGUI_WIDGET_EVENT_HANDLER_PREPARE
- box = RTGUI_COMBOBOX(object);
+ box = RTGUI_COMBOBOX(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL)
- widget->on_draw(RTGUI_OBJECT(widget), event);
- else
+ if (widget->on_draw != RT_NULL)
+ widget->on_draw(RTGUI_OBJECT(widget), event);
+ else
#endif
- rtgui_combobox_ondraw(box);
+ rtgui_combobox_ondraw(box);
- break;
+ break;
- case RTGUI_EVENT_MOUSE_BUTTON:
- return rtgui_combobox_onmouse_button(box, (struct rtgui_event_mouse*)event);
+ case RTGUI_EVENT_MOUSE_BUTTON:
+ return rtgui_combobox_onmouse_button(box, (struct rtgui_event_mouse *)event);
- case RTGUI_EVENT_FOCUSED:
- {
- /* item focused */
- struct rtgui_event_focused* focused;
+ case RTGUI_EVENT_FOCUSED:
+ {
+ /* item focused */
+ struct rtgui_event_focused *focused;
- focused = (struct rtgui_event_focused*) event;
+ focused = (struct rtgui_event_focused *) event;
- if (focused->widget != RT_NULL)
- {
- /* hide pull down window */
- rtgui_win_hiden(RTGUI_WIN(box->pd_win));
- rtgui_combobox_ondraw(box);
- }
- }
- break;
- default:
- return rtgui_widget_event_handler(object, event);
- }
+ if (focused->widget != RT_NULL)
+ {
+ /* hide pull down window */
+ rtgui_win_hiden(RTGUI_WIN(box->pd_win));
+ rtgui_combobox_ondraw(box);
+ }
+ }
+ break;
+ default:
+ return rtgui_widget_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
-static rt_bool_t rtgui_combobox_pulldown_hide(struct rtgui_object* object, struct rtgui_event* event)
+static rt_bool_t rtgui_combobox_pulldown_hide(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_widget *widget;
- struct rtgui_combobox *box;
+ struct rtgui_widget *widget;
+ struct rtgui_combobox *box;
- RT_ASSERT(object != RT_NULL);
- RT_ASSERT(event != RT_NULL);
+ RT_ASSERT(object != RT_NULL);
+ RT_ASSERT(event != RT_NULL);
- widget = RTGUI_WIDGET(object);
- box = RTGUI_COMBOBOX(object);
+ widget = RTGUI_WIDGET(object);
+ box = RTGUI_COMBOBOX(object);
- if (widget == RT_NULL) return RT_TRUE;
+ if (widget == RT_NULL) return RT_TRUE;
- box = (struct rtgui_combobox*) (((struct rtgui_win*)widget)->user_data);
- if (box == RT_NULL) return RT_TRUE;
+ box = (struct rtgui_combobox *)(((struct rtgui_win *)widget)->user_data);
+ if (box == RT_NULL) return RT_TRUE;
- /* hide pull down window */
- rtgui_win_hiden(RTGUI_WIN(box->pd_win));
+ /* hide pull down window */
+ rtgui_win_hiden(RTGUI_WIN(box->pd_win));
- /* clear pull down button state */
- box->pd_pressed = RT_FALSE;
- rtgui_widget_update(RTGUI_WIDGET(box));
+ /* clear pull down button state */
+ box->pd_pressed = RT_FALSE;
+ rtgui_widget_update(RTGUI_WIDGET(box));
- return RT_TRUE;
+ return RT_TRUE;
}
-struct rtgui_listbox_item* rtgui_combox_get_select(struct rtgui_combobox* box)
+struct rtgui_listbox_item *rtgui_combox_get_select(struct rtgui_combobox *box)
{
- if ((box != RT_NULL) && (box->current_item < box->items_count))
- {
- return &(box->items[box->current_item]);
- }
+ if ((box != RT_NULL) && (box->current_item < box->items_count))
+ {
+ return &(box->items[box->current_item]);
+ }
- return RT_NULL;
+ return RT_NULL;
}
-void rtgui_combobox_set_onselected(struct rtgui_combobox* box, rtgui_event_handler_ptr func)
+void rtgui_combobox_set_onselected(struct rtgui_combobox *box, rtgui_event_handler_ptr func)
{
- box->on_selected = func;
+ box->on_selected = func;
}
diff --git a/components/rtgui/widgets/container.c b/components/rtgui/widgets/container.c
index e483897aa1..7014102cd2 100644
--- a/components/rtgui/widgets/container.c
+++ b/components/rtgui/widgets/container.c
@@ -20,47 +20,47 @@
static void _rtgui_container_constructor(rtgui_container_t *container)
{
- /* init container */
- rtgui_object_set_event_handler(RTGUI_OBJECT(container),
- rtgui_container_event_handler);
+ /* init container */
+ rtgui_object_set_event_handler(RTGUI_OBJECT(container),
+ rtgui_container_event_handler);
- rtgui_list_init(&(container->children));
- container->layout_box = RT_NULL;
+ rtgui_list_init(&(container->children));
+ container->layout_box = RT_NULL;
- RTGUI_WIDGET(container)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+ RTGUI_WIDGET(container)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
}
static void _rtgui_container_destructor(rtgui_container_t *container)
{
- rtgui_container_destroy_children(container);
+ rtgui_container_destroy_children(container);
- if (container->layout_box != RT_NULL)
- rtgui_object_destroy(RTGUI_OBJECT(container->layout_box));
+ if (container->layout_box != RT_NULL)
+ rtgui_object_destroy(RTGUI_OBJECT(container->layout_box));
}
DEFINE_CLASS_TYPE(container, "container",
- RTGUI_WIDGET_TYPE,
- _rtgui_container_constructor,
- _rtgui_container_destructor,
- sizeof(struct rtgui_container));
+ RTGUI_WIDGET_TYPE,
+ _rtgui_container_constructor,
+ _rtgui_container_destructor,
+ sizeof(struct rtgui_container));
RTM_EXPORT(_rtgui_container);
-rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_event_t* event)
+rt_bool_t rtgui_container_dispatch_event(rtgui_container_t *container, rtgui_event_t *event)
{
- /* handle in child widget */
- struct rtgui_list_node* node;
+ /* 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);
+ rtgui_list_foreach(node, &(container->children))
+ {
+ struct rtgui_widget *w;
+ w = rtgui_list_entry(node, struct rtgui_widget, sibling);
- if (RTGUI_OBJECT(w)->event_handler &&
- RTGUI_OBJECT(w)->event_handler(RTGUI_OBJECT(w), event) == RT_TRUE)
- return RT_TRUE;
- }
+ if (RTGUI_OBJECT(w)->event_handler &&
+ RTGUI_OBJECT(w)->event_handler(RTGUI_OBJECT(w), event) == RT_TRUE)
+ return RT_TRUE;
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_container_dispatch_event);
@@ -68,133 +68,137 @@ RTM_EXPORT(rtgui_container_dispatch_event);
* events will always reach every child.*/
rt_bool_t rtgui_container_broadcast_event(struct rtgui_container *container, struct rtgui_event *event)
{
- struct rtgui_list_node* node;
+ struct rtgui_list_node *node;
- rtgui_list_foreach(node, &(container->children))
- {
- struct rtgui_widget* w;
- w = rtgui_list_entry(node, struct rtgui_widget, sibling);
+ rtgui_list_foreach(node, &(container->children))
+ {
+ struct rtgui_widget *w;
+ w = rtgui_list_entry(node, struct rtgui_widget, sibling);
- if (RTGUI_OBJECT(w)->event_handler)
- RTGUI_OBJECT(w)->event_handler(RTGUI_OBJECT(w), event);
- }
+ if (RTGUI_OBJECT(w)->event_handler)
+ RTGUI_OBJECT(w)->event_handler(RTGUI_OBJECT(w), event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_container_broadcast_event);
-rt_bool_t rtgui_container_dispatch_mouse_event(rtgui_container_t *container, struct rtgui_event_mouse* event)
+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;
- struct rtgui_widget *old_focus;
+ /* handle in child widget */
+ struct rtgui_list_node *node;
+ struct rtgui_widget *old_focus;
- old_focus = RTGUI_WIDGET(container)->toplevel->focused_widget;
+ old_focus = RTGUI_WIDGET(container)->toplevel->focused_widget;
- 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 ((old_focus != w) && RTGUI_WIDGET_IS_FOCUSABLE(w))
- rtgui_widget_focus(w);
- if (RTGUI_OBJECT(w)->event_handler &&
- RTGUI_OBJECT(w)->event_handler(RTGUI_OBJECT(w),
- (rtgui_event_t*)event) == RT_TRUE)
- return RT_TRUE;
- }
- }
+ 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 ((old_focus != w) && RTGUI_WIDGET_IS_FOCUSABLE(w))
+ rtgui_widget_focus(w);
+ if (RTGUI_OBJECT(w)->event_handler &&
+ RTGUI_OBJECT(w)->event_handler(RTGUI_OBJECT(w),
+ (rtgui_event_t *)event) == RT_TRUE)
+ return RT_TRUE;
+ }
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_container_dispatch_mouse_event);
-rt_bool_t rtgui_container_event_handler(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_container_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_container *container;
- struct rtgui_widget *widget;
+ struct rtgui_container *container;
+ struct rtgui_widget *widget;
- RT_ASSERT(object != RT_NULL);
- RT_ASSERT(event != RT_NULL);
+ RT_ASSERT(object != RT_NULL);
+ RT_ASSERT(event != RT_NULL);
- container = RTGUI_CONTAINER(object);
- widget = RTGUI_WIDGET(object);
+ container = RTGUI_CONTAINER(object);
+ widget = RTGUI_WIDGET(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- {
- struct rtgui_dc* dc;
- struct rtgui_rect rect;
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
+ {
+ 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);
+ dc = rtgui_dc_begin_drawing(widget);
+ if (dc == RT_NULL)
+ return RT_FALSE;
+ rtgui_widget_get_rect(widget, &rect);
- /* fill container with background */
- rtgui_dc_fill_rect(dc, &rect);
+ /* fill container with background */
+ rtgui_dc_fill_rect(dc, &rect);
- /* paint on each child */
- rtgui_container_dispatch_event(container, event);
+ /* paint on each child */
+ rtgui_container_dispatch_event(container, event);
- rtgui_dc_end_drawing(dc);
- }
- break;
+ rtgui_dc_end_drawing(dc);
+ }
+ break;
- case RTGUI_EVENT_KBD:
- break;
+ case RTGUI_EVENT_KBD:
+ break;
- case RTGUI_EVENT_MOUSE_BUTTON:
- case RTGUI_EVENT_MOUSE_MOTION:
- /* handle in child widget */
- return rtgui_container_dispatch_mouse_event(container,
- (struct rtgui_event_mouse*)event);
+ case RTGUI_EVENT_MOUSE_BUTTON:
+ case RTGUI_EVENT_MOUSE_MOTION:
+ /* handle in child widget */
+ return rtgui_container_dispatch_mouse_event(container,
+ (struct rtgui_event_mouse *)event);
- case RTGUI_EVENT_SHOW:
- rtgui_widget_onshow(RTGUI_OBJECT(container), event);
- rtgui_container_dispatch_event(container, event);
- break;
- case RTGUI_EVENT_HIDE:
- rtgui_widget_onhide(RTGUI_OBJECT(container), event);
- rtgui_container_dispatch_event(container, event);
- break;
- case RTGUI_EVENT_COMMAND:
- case RTGUI_EVENT_RESIZE:
- rtgui_container_dispatch_event(container, event);
- break;
+ case RTGUI_EVENT_SHOW:
+ rtgui_widget_onshow(RTGUI_OBJECT(container), event);
+ rtgui_container_dispatch_event(container, event);
+ break;
+ case RTGUI_EVENT_HIDE:
+ rtgui_widget_onhide(RTGUI_OBJECT(container), event);
+ rtgui_container_dispatch_event(container, event);
+ break;
+ case RTGUI_EVENT_COMMAND:
+ rtgui_container_dispatch_event(container, event);
+ break;
- case RTGUI_EVENT_UPDATE_TOPLVL:
- /* call parent handler */
- rtgui_widget_onupdate_toplvl(object, event);
- /* update the children */
- rtgui_container_broadcast_event(container, event);
- break;
+ case RTGUI_EVENT_UPDATE_TOPLVL:
+ /* call parent handler */
+ rtgui_widget_onupdate_toplvl(object, event);
+ /* update the children */
+ rtgui_container_broadcast_event(container, event);
+ break;
- default:
- /* call parent widget event handler */
- return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
- }
+ case RTGUI_EVENT_RESIZE:
+ /* re-layout container */
+ rtgui_container_layout(container);
+ break;
- return RT_FALSE;
+ default:
+ /* call parent widget event handler */
+ return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
+ }
+
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_container_event_handler);
-rtgui_container_t* rtgui_container_create(void)
+rtgui_container_t *rtgui_container_create(void)
{
- struct rtgui_container* container;
+ struct rtgui_container *container;
- /* allocate container */
- container = (struct rtgui_container*) rtgui_widget_create (RTGUI_CONTAINER_TYPE);
- return container;
+ /* allocate container */
+ container = (struct rtgui_container *) rtgui_widget_create(RTGUI_CONTAINER_TYPE);
+ return container;
}
RTM_EXPORT(rtgui_container_create);
-void rtgui_container_destroy(rtgui_container_t* container)
+void rtgui_container_destroy(rtgui_container_t *container)
{
- rtgui_widget_destroy(RTGUI_WIDGET(container));
+ rtgui_widget_destroy(RTGUI_WIDGET(container));
}
RTM_EXPORT(rtgui_container_destroy);
@@ -203,117 +207,117 @@ RTM_EXPORT(rtgui_container_destroy);
* 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)
+void rtgui_container_add_child(rtgui_container_t *container, rtgui_widget_t *child)
{
- RT_ASSERT(container != RT_NULL);
- RT_ASSERT(child != RT_NULL);
+ 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));
+ /* 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_WIN(RTGUI_WIDGET(container)->toplevel))
- {
- struct rtgui_event_update_toplvl eup;
- RTGUI_EVENT_UPDATE_TOPLVL_INIT(&eup);
- eup.toplvl = RTGUI_WIDGET(container)->toplevel;
- rtgui_container_broadcast_event(container, (struct rtgui_event*)&eup);
- }
+ /* update children toplevel */
+ if (RTGUI_WIDGET(container)->toplevel != RT_NULL &&
+ RTGUI_IS_WIN(RTGUI_WIDGET(container)->toplevel))
+ {
+ struct rtgui_event_update_toplvl eup;
+ RTGUI_EVENT_UPDATE_TOPLVL_INIT(&eup);
+ eup.toplvl = RTGUI_WIDGET(container)->toplevel;
+ rtgui_container_broadcast_event(container, (struct rtgui_event *)&eup);
+ }
}
RTM_EXPORT(rtgui_container_add_child);
/* remove a child to widget */
-void rtgui_container_remove_child(rtgui_container_t *container, rtgui_widget_t* child)
+void rtgui_container_remove_child(rtgui_container_t *container, rtgui_widget_t *child)
{
- RT_ASSERT(container != RT_NULL);
- RT_ASSERT(child != RT_NULL);
+ RT_ASSERT(container != RT_NULL);
+ RT_ASSERT(child != RT_NULL);
- rtgui_widget_unfocus(child);
+ rtgui_widget_unfocus(child);
- /* remove widget from parent's children list */
- rtgui_list_remove(&(container->children), &(child->sibling));
+ /* 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;
+ /* set parent and toplevel widget */
+ child->parent = RT_NULL;
+ child->toplevel = RT_NULL;
}
RTM_EXPORT(rtgui_container_remove_child);
/* destroy all children of container */
void rtgui_container_destroy_children(rtgui_container_t *container)
{
- struct rtgui_list_node* node;
+ struct rtgui_list_node *node;
- if (container == RT_NULL)
- return;
+ 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);
+ 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;
+ if (RTGUI_IS_CONTAINER(child))
+ {
+ /* break parent firstly */
+ child->parent = RT_NULL;
- /* destroy children of child */
- rtgui_container_destroy_children(RTGUI_CONTAINER(child));
- }
+ /* 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));
+ /* remove widget from parent's children list */
+ rtgui_list_remove(&(container->children), &(child->sibling));
- /* set parent and toplevel widget */
- child->parent = RT_NULL;
+ /* set parent and toplevel widget */
+ child->parent = RT_NULL;
- /* destroy object and remove from parent */
- rtgui_object_destroy(RTGUI_OBJECT(child));
+ /* destroy object and remove from parent */
+ rtgui_object_destroy(RTGUI_OBJECT(child));
- node = container->children.next;
- }
+ node = container->children.next;
+ }
- container->children.next = RT_NULL;
+ container->children.next = RT_NULL;
- /* update widget clip */
- rtgui_win_update_clip(RTGUI_WIN(RTGUI_WIDGET(container)->toplevel));
+ /* update widget clip */
+ rtgui_win_update_clip(RTGUI_WIN(RTGUI_WIDGET(container)->toplevel));
}
RTM_EXPORT(rtgui_container_destroy_children);
-rtgui_widget_t* rtgui_container_get_first_child(rtgui_container_t* container)
+rtgui_widget_t *rtgui_container_get_first_child(rtgui_container_t *container)
{
- rtgui_widget_t* child = RT_NULL;
+ rtgui_widget_t *child = RT_NULL;
- RT_ASSERT(container != RT_NULL);
+ RT_ASSERT(container != RT_NULL);
- if (container->children.next != RT_NULL)
- {
- child = rtgui_list_entry(container->children.next, rtgui_widget_t, sibling);
- }
+ if (container->children.next != RT_NULL)
+ {
+ child = rtgui_list_entry(container->children.next, rtgui_widget_t, sibling);
+ }
- return child;
+ return child;
}
RTM_EXPORT(rtgui_container_get_first_child);
-void rtgui_container_set_box(rtgui_container_t* container, struct rtgui_box* box)
+void rtgui_container_set_box(rtgui_container_t *container, struct rtgui_box *box)
{
- if (container == RT_NULL || box == RT_NULL)
+ if (container == RT_NULL || box == RT_NULL)
return;
- container->layout_box = box;
- box->container = container;
+ container->layout_box = box;
+ box->container = container;
}
RTM_EXPORT(rtgui_container_set_box);
-void rtgui_container_layout(struct rtgui_container* container)
+void rtgui_container_layout(struct rtgui_container *container)
{
- if (container == RT_NULL || container->layout_box == RT_NULL)
- return;
+ if (container == RT_NULL || container->layout_box == RT_NULL)
+ return;
- rtgui_box_layout(container->layout_box);
+ rtgui_box_layout(container->layout_box);
}
RTM_EXPORT(rtgui_container_layout);
diff --git a/components/rtgui/widgets/edit.c b/components/rtgui/widgets/edit.c
index 388037da6b..d8e1effe3d 100644
--- a/components/rtgui/widgets/edit.c
+++ b/components/rtgui/widgets/edit.c
@@ -20,82 +20,82 @@
extern int isprint(unsigned char ch); /* Quote from shell.c */
static void rtgui_edit_draw_caret(struct rtgui_edit *edit);
-static void rtgui_edit_timeout(struct rtgui_timer* timer, void* parameter);
-static rt_bool_t rtgui_edit_onfocus(struct rtgui_object* object, rtgui_event_t* event);
-static rt_bool_t rtgui_edit_onunfocus(struct rtgui_object* object, rtgui_event_t* event);
+static void rtgui_edit_timeout(struct rtgui_timer *timer, void *parameter);
+static rt_bool_t rtgui_edit_onfocus(struct rtgui_object *object, rtgui_event_t *event);
+static rt_bool_t rtgui_edit_onunfocus(struct rtgui_object *object, rtgui_event_t *event);
#ifdef RTGUI_EDIT_USING_SCROLL
-static rt_bool_t rtgui_edit_hscroll_handle(struct rtgui_widget* widget, rtgui_event_t* event);
-static rt_bool_t rtgui_edit_vscroll_handle(struct rtgui_widget* widget, rtgui_event_t* event);
+static rt_bool_t rtgui_edit_hscroll_handle(struct rtgui_widget *widget, rtgui_event_t *event);
+static rt_bool_t rtgui_edit_vscroll_handle(struct rtgui_widget *widget, rtgui_event_t *event);
#endif
void _rtgui_edit_constructor(struct rtgui_edit *edit)
{
- rtgui_rect_t font_rect;
- RTGUI_WIDGET_FLAG(edit) |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+ rtgui_rect_t font_rect;
+ RTGUI_WIDGET_FLAG(edit) |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- rtgui_object_set_event_handler(RTGUI_OBJECT(edit), rtgui_edit_event_handler);
- rtgui_widget_set_onfocus(RTGUI_WIDGET(edit), rtgui_edit_onfocus);
- rtgui_widget_set_onunfocus(RTGUI_WIDGET(edit), rtgui_edit_onunfocus);
-
- RTGUI_WIDGET_FOREGROUND(edit) = black;
- RTGUI_WIDGET_BACKGROUND(edit) = white;
- /* set default text align */
- RTGUI_WIDGET_TEXTALIGN(edit) = RTGUI_ALIGN_CENTER_VERTICAL;
- rtgui_widget_set_border(RTGUI_WIDGET(edit), RTGUI_BORDER_SUNKEN);
- /* set proper of control */
- edit->caret_timer = RT_NULL;
- edit->caret = RT_NULL;
+ rtgui_object_set_event_handler(RTGUI_OBJECT(edit), rtgui_edit_event_handler);
+ rtgui_widget_set_onfocus(RTGUI_WIDGET(edit), rtgui_edit_onfocus);
+ rtgui_widget_set_onunfocus(RTGUI_WIDGET(edit), rtgui_edit_onunfocus);
- edit->tabsize = 4;
- edit->margin = 1;
- edit->max_rows = edit->max_cols = 0;
- edit->visual.x = edit->visual.y = 0;
- edit->upleft.x = edit->upleft.y = 0;
- edit->row_per_page = edit->col_per_page = 0;
+ RTGUI_WIDGET_FOREGROUND(edit) = black;
+ RTGUI_WIDGET_BACKGROUND(edit) = white;
+ /* set default text align */
+ RTGUI_WIDGET_TEXTALIGN(edit) = RTGUI_ALIGN_CENTER_VERTICAL;
+ rtgui_widget_set_border(RTGUI_WIDGET(edit), RTGUI_BORDER_SUNKEN);
+ /* set proper of control */
+ edit->caret_timer = RT_NULL;
+ edit->caret = RT_NULL;
- edit->update_buf = RT_NULL;
- edit->flag = RTGUI_EDIT_NONE;
+ edit->tabsize = 4;
+ edit->margin = 1;
+ edit->max_rows = edit->max_cols = 0;
+ edit->visual.x = edit->visual.y = 0;
+ edit->upleft.x = edit->upleft.y = 0;
+ edit->row_per_page = edit->col_per_page = 0;
+
+ edit->update_buf = RT_NULL;
+ edit->flag = RTGUI_EDIT_NONE;
#ifdef RTGUI_EDIT_USING_SCROLL
- edit->flag |= RTGUI_EDIT_VSCROLL;
- edit->flag |= RTGUI_EDIT_HSCROLL;
+ edit->flag |= RTGUI_EDIT_VSCROLL;
+ edit->flag |= RTGUI_EDIT_HSCROLL;
#endif
- /* allocate default line buffer */
- edit->bzsize = 16;
-
- rtgui_font_get_metrics(RTGUI_WIDGET_FONT(edit), "H", &font_rect);
- edit->font_width = rtgui_rect_width(font_rect);
- edit->font_height = rtgui_rect_height(font_rect);
+ /* allocate default line buffer */
+ edit->bzsize = 16;
+
+ rtgui_font_get_metrics(RTGUI_WIDGET_FONT(edit), "H", &font_rect);
+ edit->font_width = rtgui_rect_width(font_rect);
+ edit->font_height = rtgui_rect_height(font_rect);
- edit->dbl_buf = rtgui_dc_buffer_create(edit->font_width*2+1, edit->font_height+1);
-
- edit->head = RT_NULL;
- edit->tail = RT_NULL;
- edit->first_line = RT_NULL;
-#ifdef RTGUI_EDIT_USING_SCROLL
- edit->hscroll = RT_NULL;
- edit->vscroll = RT_NULL;
+ edit->dbl_buf = rtgui_dc_buffer_create(edit->font_width * 2 + 1, edit->font_height + 1);
+
+ edit->head = RT_NULL;
+ edit->tail = RT_NULL;
+ edit->first_line = RT_NULL;
+#ifdef RTGUI_EDIT_USING_SCROLL
+ edit->hscroll = RT_NULL;
+ edit->vscroll = RT_NULL;
#endif
}
void _rtgui_edit_deconstructor(struct rtgui_edit *edit)
{
- if(edit->max_rows > 0)
- {
- while(edit->max_rows > 0)
- rtgui_edit_delete_line(edit, edit->head);
- edit->max_rows = 0;
- }
- if(edit->caret_timer != RT_NULL)
- rtgui_timer_destory(edit->caret_timer);
- edit->caret_timer = RT_NULL;
+ if (edit->max_rows > 0)
+ {
+ while (edit->max_rows > 0)
+ rtgui_edit_delete_line(edit, edit->head);
+ edit->max_rows = 0;
+ }
+ if (edit->caret_timer != RT_NULL)
+ rtgui_timer_destory(edit->caret_timer);
+ edit->caret_timer = RT_NULL;
- if(edit->caret != RT_NULL)
- rtgui_free(edit->caret);
- edit->caret = RT_NULL;
- if(edit->update_buf != RT_NULL)
- rtgui_free(edit->update_buf);
+ if (edit->caret != RT_NULL)
+ rtgui_free(edit->caret);
+ edit->caret = RT_NULL;
+ if (edit->update_buf != RT_NULL)
+ rtgui_free(edit->update_buf);
- rtgui_dc_destory(edit->dbl_buf);
+ rtgui_dc_destory(edit->dbl_buf);
}
DEFINE_CLASS_TYPE(edit, "edit",
@@ -107,146 +107,146 @@ DEFINE_CLASS_TYPE(edit, "edit",
#ifdef RTGUI_EDIT_USING_SCROLL
void rtgui_edit_adjust_scroll(rtgui_scrollbar_t *bar)
{
- struct rtgui_edit *edit;
-
- RT_ASSERT(bar != RT_NULL);
-
- if(bar->widget_link != RT_NULL)
- {
- rtgui_rect_t rect;
- rt_uint32_t _left=0,_top=0,_width=RTGUI_DEFAULT_SB_WIDTH,_len=0;
+ struct rtgui_edit *edit;
+
+ RT_ASSERT(bar != RT_NULL);
+
+ if (bar->widget_link != RT_NULL)
+ {
+ rtgui_rect_t rect;
+ rt_uint32_t _left = 0, _top = 0, _width = RTGUI_DEFAULT_SB_WIDTH, _len = 0;
+
+ edit = bar->widget_link;
+ rtgui_widget_get_rect(edit, &rect);
+ rtgui_widget_rect_to_device(edit, &rect);
+ if (bar->orient == RTGUI_HORIZONTAL)
+ {
+ if (RTGUI_WIDGET_IS_HIDE(edit->hscroll))
+ {
+ if (edit->max_rows > edit->row_per_page)
+ {
+ RTGUI_WIDGET_SHOW(edit->hscroll);
+ rtgui_scrollbar_set_line_step(edit->hscroll, 1);
+ rtgui_scrollbar_set_page_step(edit->hscroll, edit->row_per_page);
+ rtgui_scrollbar_set_range(edit->hscroll, edit->max_rows);
+ }
+ else
+ RTGUI_WIDGET_HIDE(edit->vscroll);
+ rtgui_widget_update_clip(RTGUI_WIDGET(edit));
+ }
+ else
+ {
+ _left = RTGUI_WIDGET_BORDER(edit);
+ _top = rtgui_rect_height(rect) - RTGUI_WIDGET_BORDER(edit) - _width;
+ _len = rtgui_rect_width(rect) - RTGUI_WIDGET_BORDER(edit) * 2;
+
+ if (!RTGUI_WIDGET_IS_HIDE(edit->vscroll))
+ _len -= _width;
+ rect.x1 += _left;
+ rect.y1 += _top;
+ rect.x2 = rect.x1 + _len;
+ rect.y2 = rect.y1 + _width;
+ }
+ }
+ else if (bar->orient == RTGUI_VERTICAL)
+ {
+ _left = rtgui_rect_width(rect) - RTGUI_WIDGET_BORDER(edit) - _width;
+ _top = RTGUI_WIDGET_BORDER(edit);
+ _len = rtgui_rect_height(rect) - RTGUI_WIDGET_BORDER(edit) * 2;
- edit = bar->widget_link;
- rtgui_widget_get_rect(edit, &rect);
- rtgui_widget_rect_to_device(edit,&rect);
- if(bar->orient==RTGUI_HORIZONTAL)
- {
- if(RTGUI_WIDGET_IS_HIDE(edit->hscroll))
- {
- if(edit->max_rows > edit->row_per_page)
- {
- RTGUI_WIDGET_SHOW(edit->hscroll);
- rtgui_scrollbar_set_line_step(edit->hscroll, 1);
- rtgui_scrollbar_set_page_step(edit->hscroll, edit->row_per_page);
- rtgui_scrollbar_set_range(edit->hscroll, edit->max_rows);
- }
- else
- RTGUI_WIDGET_HIDE(edit->vscroll);
- rtgui_widget_update_clip(RTGUI_WIDGET(edit));
- }
- else
- {
- _left = RTGUI_WIDGET_BORDER(edit);
- _top = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER(edit)-_width;
- _len = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER(edit)*2;
-
- if(!RTGUI_WIDGET_IS_HIDE(edit->vscroll))
- _len -= _width;
- rect.x1 += _left;
- rect.y1 += _top;
- rect.x2 = rect.x1+_len;
- rect.y2 = rect.y1+_width;
- }
- }
- else if(bar->orient==RTGUI_VERTICAL)
- {
- _left = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER(edit)-_width;
- _top = RTGUI_WIDGET_BORDER(edit);
- _len = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER(edit)*2;
-
- if(!RTGUI_WIDGET_IS_HIDE(edit->hscroll))
- _len -= _width;
- rect.x1 += _left;
- rect.y1 += _top;
- rect.x2 = rect.x1+_width;
- rect.y2 = rect.y1+_len;
- }
- rtgui_widget_set_rect(bar,&rect);
- }
+ if (!RTGUI_WIDGET_IS_HIDE(edit->hscroll))
+ _len -= _width;
+ rect.x1 += _left;
+ rect.y1 += _top;
+ rect.x2 = rect.x1 + _width;
+ rect.y2 = rect.y1 + _len;
+ }
+ rtgui_widget_set_rect(bar, &rect);
+ }
}
RTM_EXPORT(rtgui_edit_adjust_scroll);
#endif
-struct rtgui_edit* rtgui_edit_create(struct rtgui_container* container, int left, int top, int w, int h)
+struct rtgui_edit *rtgui_edit_create(struct rtgui_container *container, int left, int top, int w, int h)
{
- struct rtgui_edit* edit;
+ struct rtgui_edit *edit;
- RT_ASSERT(container != RT_NULL);
+ RT_ASSERT(container != RT_NULL);
- edit = (struct rtgui_edit*)rtgui_widget_create(RTGUI_EDIT_TYPE);
- if(edit != RT_NULL)
- {
- rtgui_rect_t rect;
- int effe;
- rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
- rtgui_widget_rect_to_device(RTGUI_WIDGET(container),&rect);
- rect.x1 += left;
- rect.y1 += top;
- rect.x2 = rect.x1+w;
- rect.y2 = rect.y1+h;
- rtgui_widget_set_rect(RTGUI_WIDGET(edit),&rect);
- rtgui_container_add_child(container, RTGUI_WIDGET(edit));
+ edit = (struct rtgui_edit *)rtgui_widget_create(RTGUI_EDIT_TYPE);
+ if (edit != RT_NULL)
+ {
+ rtgui_rect_t rect;
+ int effe;
+ rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
+ rtgui_widget_rect_to_device(RTGUI_WIDGET(container), &rect);
+ rect.x1 += left;
+ rect.y1 += top;
+ rect.x2 = rect.x1 + w;
+ rect.y2 = rect.y1 + h;
+ rtgui_widget_set_rect(RTGUI_WIDGET(edit), &rect);
+ rtgui_container_add_child(container, RTGUI_WIDGET(edit));
- /* set character number */
- edit->item_height = edit->font_height; /* the same height */
- effe = h-(edit->margin + RTGUI_WIDGET_BORDER(edit))*2;
- edit->row_per_page = effe / edit->item_height;
- if(effe % edit->item_height)
- edit->row_per_page += 1;
-
- effe = w-(edit->margin + RTGUI_WIDGET_BORDER(edit))*2;
- edit->col_per_page = effe / edit->font_width;
- if(effe % edit->font_width)
- edit->col_per_page += 1;
- edit->update_buf = rtgui_malloc(edit->col_per_page + 1);
+ /* set character number */
+ edit->item_height = edit->font_height; /* the same height */
+ effe = h - (edit->margin + RTGUI_WIDGET_BORDER(edit)) * 2;
+ edit->row_per_page = effe / edit->item_height;
+ if (effe % edit->item_height)
+ edit->row_per_page += 1;
+
+ effe = w - (edit->margin + RTGUI_WIDGET_BORDER(edit)) * 2;
+ edit->col_per_page = effe / edit->font_width;
+ if (effe % edit->font_width)
+ edit->col_per_page += 1;
+ edit->update_buf = rtgui_malloc(edit->col_per_page + 1);
#ifdef RTGUI_EDIT_USING_SCROLL
- if(edit->hscroll == RT_NULL && edit->flag & RTGUI_EDIT_HSCROLL)
- {
- /* create horizontal scrollbar */
- rt_uint32_t _left,_top,_width=RTGUI_DEFAULT_SB_WIDTH,_len;
- _left = RTGUI_WIDGET_BORDER(edit);
- _top = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER(edit)-_width;
- _len = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER(edit)*2;
- if(edit->max_rows > edit->row_per_page) _len -= _width;
+ if (edit->hscroll == RT_NULL && edit->flag & RTGUI_EDIT_HSCROLL)
+ {
+ /* create horizontal scrollbar */
+ rt_uint32_t _left, _top, _width = RTGUI_DEFAULT_SB_WIDTH, _len;
+ _left = RTGUI_WIDGET_BORDER(edit);
+ _top = rtgui_rect_height(rect) - RTGUI_WIDGET_BORDER(edit) - _width;
+ _len = rtgui_rect_width(rect) - RTGUI_WIDGET_BORDER(edit) * 2;
+ if (edit->max_rows > edit->row_per_page) _len -= _width;
- edit->hscroll = rtgui_scrollbar_create(edit,_left,_top,_width,_len,RTGUI_HORIZONTAL);
+ edit->hscroll = rtgui_scrollbar_create(edit, _left, _top, _width, _len, RTGUI_HORIZONTAL);
- if(edit->hscroll != RT_NULL)
- {
- edit->hscroll->widget_link = (pvoid)edit;
- edit->hscroll->on_scroll = rtgui_edit_hscroll_handle;
- RTGUI_WIDGET_HIDE(edit->hscroll);
- }
- }
- if(edit->vscroll == RT_NULL && edit->flag & RTGUI_EDIT_VSCROLL)
- {
- /* create vertical scrollbar */
- rt_uint32_t _left,_top,_width=RTGUI_DEFAULT_SB_WIDTH,_len;
- _left = rtgui_rect_width(rect)-RTGUI_WIDGET_BORDER(edit)-_width;
- _top = RTGUI_WIDGET_BORDER(edit);
- _len = rtgui_rect_height(rect)-RTGUI_WIDGET_BORDER(edit)*2;
- if(edit->max_cols > edit->col_per_page) _len -= _width;
+ if (edit->hscroll != RT_NULL)
+ {
+ edit->hscroll->widget_link = (pvoid)edit;
+ edit->hscroll->on_scroll = rtgui_edit_hscroll_handle;
+ RTGUI_WIDGET_HIDE(edit->hscroll);
+ }
+ }
+ if (edit->vscroll == RT_NULL && edit->flag & RTGUI_EDIT_VSCROLL)
+ {
+ /* create vertical scrollbar */
+ rt_uint32_t _left, _top, _width = RTGUI_DEFAULT_SB_WIDTH, _len;
+ _left = rtgui_rect_width(rect) - RTGUI_WIDGET_BORDER(edit) - _width;
+ _top = RTGUI_WIDGET_BORDER(edit);
+ _len = rtgui_rect_height(rect) - RTGUI_WIDGET_BORDER(edit) * 2;
+ if (edit->max_cols > edit->col_per_page) _len -= _width;
- edit->vscroll = rtgui_scrollbar_create(edit,_left,_top,_width,_len,RTGUI_VERTICAL);
+ edit->vscroll = rtgui_scrollbar_create(edit, _left, _top, _width, _len, RTGUI_VERTICAL);
- if(edit->vscroll != RT_NULL)
- {
- edit->vscroll->widget_link = (pvoid)edit;
- edit->vscroll->on_scroll = rtgui_edit_vscroll_handle;
- RTGUI_WIDGET_HIDE(edit->vscroll);
- }
- }
+ if (edit->vscroll != RT_NULL)
+ {
+ edit->vscroll->widget_link = (pvoid)edit;
+ edit->vscroll->on_scroll = rtgui_edit_vscroll_handle;
+ RTGUI_WIDGET_HIDE(edit->vscroll);
+ }
+ }
#endif
- }
+ }
- return edit;
+ return edit;
}
RTM_EXPORT(rtgui_edit_create);
-void rtgui_edit_destroy(struct rtgui_edit* edit)
+void rtgui_edit_destroy(struct rtgui_edit *edit)
{
- rtgui_widget_destroy(RTGUI_WIDGET(edit));
+ rtgui_widget_destroy(RTGUI_WIDGET(edit));
}
RTM_EXPORT(rtgui_edit_destroy);
@@ -256,15 +256,15 @@ RTM_EXPORT(rtgui_edit_destroy);
* @param n a standard buffer value, please use edit->bzsize
* @param m given a reference value
*
- * @return get a proper standard values
+ * @return get a proper standard values
*/
rt_inline rt_int16_t rtgui_edit_alloc_len(rt_int16_t n, rt_int16_t m)
{
- if(n > m) return n;
+ if (n > m) return n;
#ifndef RTGUI_USING_SMALL_SIZE
- return rtgui_edit_alloc_len(n*2, m);
+ return rtgui_edit_alloc_len(n * 2, m);
#else
- return rtgui_edit_alloc_len(n+16, m);
+ return rtgui_edit_alloc_len(n + 16, m);
#endif
}
@@ -274,314 +274,315 @@ rt_inline rt_int16_t rtgui_edit_alloc_len(rt_int16_t n, rt_int16_t m)
*/
rt_inline rt_int16_t rtgui_edit_line_strlen(const char *s)
{
- const char *sc;
- /* ascii text end of 0x0A or 0x0D-0x0A*/
- for(sc = s; *sc != 0x0D && *sc != 0x0A && *sc != 0x00; ++sc);
- return sc - s;
+ const char *sc;
+ /* ascii text end of 0x0A or 0x0D-0x0A*/
+ for (sc = s; *sc != 0x0D && *sc != 0x0A && *sc != 0x00; ++sc);
+ return sc - s;
}
-rt_bool_t rtgui_edit_append_line(struct rtgui_edit* edit, const char *text)
+rt_bool_t rtgui_edit_append_line(struct rtgui_edit *edit, const char *text)
{
- rt_int16_t len;
- struct edit_line *line, *node;
+ rt_int16_t len;
+ struct edit_line *line, *node;
+
+ RT_ASSERT(edit != RT_NULL);
- RT_ASSERT(edit != RT_NULL);
+ line = rtgui_malloc(sizeof(struct edit_line));
+ if (line == RT_NULL) return RT_FALSE;
- line = rtgui_malloc(sizeof(struct edit_line));
- if(line == RT_NULL) return RT_FALSE;
+ len = rtgui_edit_line_strlen(text);
+ line->zsize = rtgui_edit_alloc_len(edit->bzsize, len + 1);
+ line->text = rtgui_malloc(line->zsize);
+ rt_memcpy(line->text, text, len);
+ *(line->text + len) = '\0';
+ line->len = rtgui_edit_line_strlen(line->text);
- len = rtgui_edit_line_strlen(text);
- line->zsize = rtgui_edit_alloc_len(edit->bzsize, len+1);
- line->text = rtgui_malloc(line->zsize);
- rt_memcpy(line->text, text, len);
- *(line->text+len) = '\0';
- line->len = rtgui_edit_line_strlen(line->text);
-
- line->next = RT_NULL;
- edit->max_rows++;
- if(edit->max_cols < len) edit->max_cols = len;
+ line->next = RT_NULL;
+ edit->max_rows++;
+ if (edit->max_cols < len) edit->max_cols = len;
- node = edit->head;
- if(node == RT_NULL)
- {
- edit->head = line;
- edit->tail = line;
- line->prev = RT_NULL;
- edit->first_line = line;
- return RT_TRUE;
- }
- while(node->next != RT_NULL) node = node->next;
- /* to tail item on to queue */
- node->next = line;
- line->prev = node;
- /* re-fixed position tail */
- edit->tail = line;
-
- return RT_TRUE;
+ node = edit->head;
+ if (node == RT_NULL)
+ {
+ edit->head = line;
+ edit->tail = line;
+ line->prev = RT_NULL;
+ edit->first_line = line;
+ return RT_TRUE;
+ }
+ while (node->next != RT_NULL) node = node->next;
+ /* to tail item on to queue */
+ node->next = line;
+ line->prev = node;
+ /* re-fixed position tail */
+ edit->tail = line;
+
+ return RT_TRUE;
}
RTM_EXPORT(rtgui_edit_append_line);
rt_bool_t rtgui_edit_insert_line(struct rtgui_edit *edit, struct edit_line *p, char *text)
{
- rt_int16_t len;
- struct edit_line *line;
+ rt_int16_t len;
+ struct edit_line *line;
+
+ RT_ASSERT(edit != RT_NULL);
+ RT_ASSERT(p != RT_NULL);
- RT_ASSERT(edit != RT_NULL);
- RT_ASSERT(p != RT_NULL);
+ if (p->next == RT_NULL)
+ {
+ rtgui_edit_append_line(edit, text);
+ return RT_TRUE;
+ }
- if(p->next == RT_NULL)
- {
- rtgui_edit_append_line(edit, text);
- return RT_TRUE;
- }
+ line = rtgui_malloc(sizeof(struct edit_line));
+ if (line == RT_NULL) return RT_FALSE;
- line = rtgui_malloc(sizeof(struct edit_line));
- if(line == RT_NULL) return RT_FALSE;
+ line->prev = p;
+ line->next = p->next;
+ p->next = line;
+ if (line->next != RT_NULL)
+ {
+ line->next->prev = line;
+ }
- line->prev = p;
- line->next = p->next;
- p->next = line;
- if(line->next != RT_NULL)
- {
- line->next->prev = line;
- }
+ len = rtgui_edit_line_strlen(text);
+ line->zsize = rtgui_edit_alloc_len(edit->bzsize, len + 1);
- len = rtgui_edit_line_strlen(text);
- line->zsize = rtgui_edit_alloc_len(edit->bzsize, len+1);
-
- line->text = rtgui_malloc(line->zsize);
- rt_memset(line->text, 0, line->zsize);
- rt_memcpy(line->text, text, len);
- *(line->text+len) = '\0';
-
- edit->max_rows ++;
- line->len = rtgui_edit_line_strlen(line->text);
-
- return RT_TRUE;
+ line->text = rtgui_malloc(line->zsize);
+ rt_memset(line->text, 0, line->zsize);
+ rt_memcpy(line->text, text, len);
+ *(line->text + len) = '\0';
+
+ edit->max_rows ++;
+ line->len = rtgui_edit_line_strlen(line->text);
+
+ return RT_TRUE;
}
RTM_EXPORT(rtgui_edit_insert_line);
-rt_bool_t rtgui_edit_delete_line(struct rtgui_edit* edit, struct edit_line *line)
+rt_bool_t rtgui_edit_delete_line(struct rtgui_edit *edit, struct edit_line *line)
{
- RT_ASSERT(edit != RT_NULL);
- RT_ASSERT(line != RT_NULL);
+ RT_ASSERT(edit != RT_NULL);
+ RT_ASSERT(line != RT_NULL);
- if(edit->max_rows == 0) return RT_FALSE;
+ if (edit->max_rows == 0) return RT_FALSE;
- if(line->prev == RT_NULL)
- {
- if(line->next == RT_NULL)
- {
- /* only one item */
- edit->head = RT_NULL;
- edit->tail = RT_NULL;
- }
- else
- {
- /* first item */
- line->next->prev = RT_NULL;
- edit->head = line->next;
- }
- }
- else
- {
- if(line->next == RT_NULL)
- {
- /* last item */
- line->prev->next = RT_NULL;
- edit->tail = line->prev;
- }
- else
- {
- /* middle item */
- line->prev->next = line->next;
- line->next->prev = line->prev;
- }
- }
+ if (line->prev == RT_NULL)
+ {
+ if (line->next == RT_NULL)
+ {
+ /* only one item */
+ edit->head = RT_NULL;
+ edit->tail = RT_NULL;
+ }
+ else
+ {
+ /* first item */
+ line->next->prev = RT_NULL;
+ edit->head = line->next;
+ }
+ }
+ else
+ {
+ if (line->next == RT_NULL)
+ {
+ /* last item */
+ line->prev->next = RT_NULL;
+ edit->tail = line->prev;
+ }
+ else
+ {
+ /* middle item */
+ line->prev->next = line->next;
+ line->next->prev = line->prev;
+ }
+ }
- if(edit->max_rows > 0)edit->max_rows--;
- if(line->text)
- {
- rtgui_free(line->text);
- line->text = RT_NULL;
- }
- rtgui_free(line);
- line = RT_NULL;
+ if (edit->max_rows > 0)edit->max_rows--;
+ if (line->text)
+ {
+ rtgui_free(line->text);
+ line->text = RT_NULL;
+ }
+ rtgui_free(line);
+ line = RT_NULL;
- return RT_TRUE;
+ return RT_TRUE;
}
RTM_EXPORT(rtgui_edit_delete_line);
-rt_bool_t rtgui_edit_connect_line(struct rtgui_edit* edit, struct edit_line *line, struct edit_line *connect)
+rt_bool_t rtgui_edit_connect_line(struct rtgui_edit *edit, struct edit_line *line, struct edit_line *connect)
{
- rt_int16_t len1,len2;
-
- RT_ASSERT(edit != RT_NULL);
- RT_ASSERT(line != RT_NULL);
- RT_ASSERT(connect != RT_NULL);
+ rt_int16_t len1, len2;
+
+ RT_ASSERT(edit != RT_NULL);
+ RT_ASSERT(line != RT_NULL);
+ RT_ASSERT(connect != RT_NULL);
- len1 = rtgui_edit_line_strlen(line->text);
- len2 = rtgui_edit_line_strlen(connect->text);
+ len1 = rtgui_edit_line_strlen(line->text);
+ len2 = rtgui_edit_line_strlen(connect->text);
- line->zsize = rtgui_edit_alloc_len(edit->bzsize, len1+len2+1);
- line->text = rt_realloc(line->text, line->zsize);
- rt_memcpy(line->text+len1, connect->text, len2);
- *(line->text+len1+len2) = '\0';
+ line->zsize = rtgui_edit_alloc_len(edit->bzsize, len1 + len2 + 1);
+ line->text = rt_realloc(line->text, line->zsize);
+ rt_memcpy(line->text + len1, connect->text, len2);
+ *(line->text + len1 + len2) = '\0';
- line->len = rtgui_edit_line_strlen(line->text);
- return RT_TRUE;
+ line->len = rtgui_edit_line_strlen(line->text);
+ return RT_TRUE;
}
RTM_EXPORT(rtgui_edit_connect_line);
static void rtgui_edit_get_caret_rect(struct rtgui_edit *edit, rtgui_rect_t *rect, rtgui_point_t visual)
{
- RT_ASSERT(edit != RT_NULL);
+ RT_ASSERT(edit != RT_NULL);
- rtgui_widget_get_rect(RTGUI_WIDGET(edit), rect);
+ rtgui_widget_get_rect(RTGUI_WIDGET(edit), rect);
- rect->x1 += visual.x * edit->font_width + RTGUI_WIDGET_BORDER(edit) + edit->margin;
- rect->x2 = rect->x1+1; /* caret width: 1 */
- rect->y1 += visual.y * edit->item_height + RTGUI_WIDGET_BORDER(edit) + edit->margin;
- if((rect->y1 + edit->font_height) < (rect->y2 - RTGUI_WIDGET_BORDER(edit) - edit->margin))
- rect->y2 = rect->y1 + edit->font_height;
- else
- rect->y2 = rect->y2 - RTGUI_WIDGET_BORDER(edit) - edit->margin;
+ rect->x1 += visual.x * edit->font_width + RTGUI_WIDGET_BORDER(edit) + edit->margin;
+ rect->x2 = rect->x1 + 1; /* caret width: 1 */
+ rect->y1 += visual.y * edit->item_height + RTGUI_WIDGET_BORDER(edit) + edit->margin;
+ if ((rect->y1 + edit->font_height) < (rect->y2 - RTGUI_WIDGET_BORDER(edit) - edit->margin))
+ rect->y2 = rect->y1 + edit->font_height;
+ else
+ rect->y2 = rect->y2 - RTGUI_WIDGET_BORDER(edit) - edit->margin;
}
static void rtgui_edit_init_caret(struct rtgui_edit *edit, rtgui_point_t visual)
{
- struct rtgui_graphic_driver *hw_driver = rtgui_graphic_driver_get_default();
- int x, y;
- rtgui_color_t color;
- rtgui_rect_t rect;
- int ofs=0;
+ struct rtgui_graphic_driver *hw_driver = rtgui_graphic_driver_get_default();
+ int x, y;
+ rtgui_color_t color;
+ rtgui_rect_t rect;
+ int ofs = 0;
- RT_ASSERT(edit != RT_NULL);
- if(!RTGUI_WIDGET_IS_FOCUSED(edit)) return;
+ RT_ASSERT(edit != RT_NULL);
+ if (!RTGUI_WIDGET_IS_FOCUSED(edit)) return;
- rtgui_edit_get_caret_rect(edit, &edit->caret_rect, visual);
- rect = edit->caret_rect;
- rtgui_widget_rect_to_device(RTGUI_WIDGET(edit), &rect);
+ rtgui_edit_get_caret_rect(edit, &edit->caret_rect, visual);
+ rect = edit->caret_rect;
+ rtgui_widget_rect_to_device(RTGUI_WIDGET(edit), &rect);
- if(edit->caret == RT_NULL)
- edit->caret = (rtgui_color_t*)rtgui_malloc(rtgui_rect_width(rect) * rtgui_rect_height(rect)*sizeof(rtgui_color_t));
- rtgui_timer_stop(edit->caret_timer);
+ if (edit->caret == RT_NULL)
+ edit->caret = (rtgui_color_t *)rtgui_malloc(rtgui_rect_width(rect) * rtgui_rect_height(rect) * sizeof(rtgui_color_t));
+ rtgui_timer_stop(edit->caret_timer);
- for(x=rect.x1; x<rect.x2; x++)
- {
- for(y=rect.y1; y<rect.y2; y++)
- {
- hw_driver->ops->get_pixel(&color,x,y);
- *(edit->caret + ofs++) = color;
- }
- }
+ for (x = rect.x1; x < rect.x2; x++)
+ {
+ for (y = rect.y1; y < rect.y2; y++)
+ {
+ hw_driver->ops->get_pixel(&color, x, y);
+ *(edit->caret + ofs++) = color;
+ }
+ }
- rtgui_timer_start(edit->caret_timer);
+ rtgui_timer_start(edit->caret_timer);
}
/* draw caret */
static void rtgui_edit_draw_caret(struct rtgui_edit *edit)
{
- int x,y;
- rtgui_color_t color;
- rtgui_rect_t rect;
- int ofs=0;
- struct rtgui_dc *dc;
+ int x, y;
+ rtgui_color_t color;
+ rtgui_rect_t rect;
+ int ofs = 0;
+ struct rtgui_dc *dc;
- RT_ASSERT(edit != RT_NULL);
- if(edit->caret == RT_NULL) return;
+ RT_ASSERT(edit != RT_NULL);
+ if (edit->caret == RT_NULL) return;
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(edit));
- if(dc == RT_NULL)return;
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(edit));
+ if (dc == RT_NULL)return;
- rect = edit->caret_rect;
+ rect = edit->caret_rect;
- for(x=rect.x1; x<rect.x2; x++)
- {
- for(y=rect.y1; y<rect.y2; y++)
- {
- color = *(edit->caret + ofs);
- ofs++;
- if(edit->flag & RTGUI_EDIT_CARET)
- {
- color = ~color;
- rtgui_dc_draw_color_point(dc, x,y, color);
- }
- else
- {
- rtgui_dc_draw_color_point(dc, x,y, color);
- }
- }
- }
+ for (x = rect.x1; x < rect.x2; x++)
+ {
+ for (y = rect.y1; y < rect.y2; y++)
+ {
+ color = *(edit->caret + ofs);
+ ofs++;
+ if (edit->flag & RTGUI_EDIT_CARET)
+ {
+ color = ~color;
+ rtgui_dc_draw_color_point(dc, x, y, color);
+ }
+ else
+ {
+ rtgui_dc_draw_color_point(dc, x, y, color);
+ }
+ }
+ }
- rtgui_dc_end_drawing(dc);
+ rtgui_dc_end_drawing(dc);
}
-static void rtgui_edit_timeout(struct rtgui_timer* timer, void* parameter)
+static void rtgui_edit_timeout(struct rtgui_timer *timer, void *parameter)
{
- struct rtgui_edit* edit;
+ struct rtgui_edit *edit;
- edit = RTGUI_EDIT(parameter);
- /* set caret flag */
- if(edit->flag & RTGUI_EDIT_CARET)
- edit->flag &= ~RTGUI_EDIT_CARET;
- else
- edit->flag |= RTGUI_EDIT_CARET;
+ edit = RTGUI_EDIT(parameter);
+ /* set caret flag */
+ if (edit->flag & RTGUI_EDIT_CARET)
+ edit->flag &= ~RTGUI_EDIT_CARET;
+ else
+ edit->flag |= RTGUI_EDIT_CARET;
- rtgui_edit_draw_caret(edit);
+ rtgui_edit_draw_caret(edit);
- return;
+ return;
}
-struct edit_line* rtgui_edit_get_line_by_index(struct rtgui_edit *edit, rt_uint32_t index)
+struct edit_line *rtgui_edit_get_line_by_index(struct rtgui_edit *edit, rt_uint32_t index)
{
- struct edit_line *line = RT_NULL;
-
- RT_ASSERT(edit != RT_NULL);
-
- if(edit->head != RT_NULL)
- {
- int i=0;
- line = edit->first_line;
- while(line)
- {
- if((edit->upleft.y + i++) == index)
- break;
- line = line->next;
- }
- }
- return line;
+ struct edit_line *line = RT_NULL;
+
+ RT_ASSERT(edit != RT_NULL);
+
+ if (edit->head != RT_NULL)
+ {
+ int i = 0;
+ line = edit->first_line;
+ while (line)
+ {
+ if ((edit->upleft.y + i++) == index)
+ break;
+ line = line->next;
+ }
+ }
+ return line;
}
RTM_EXPORT(rtgui_edit_get_line_by_index);
rt_uint32_t rtgui_edit_get_index_by_line(struct rtgui_edit *edit, struct edit_line *line)
{
- rt_uint32_t index=0;
- struct edit_line *tmp;
-
- RT_ASSERT(edit != RT_NULL);
- RT_ASSERT(line != RT_NULL);
-
- if(edit->head != RT_NULL)
- {
- tmp = edit->first_line;
- index = edit->upleft.y;
- while(tmp)
- {
- if(tmp == line)
- break;
- index ++;
- tmp = tmp->next;
- }
- }
- return index;
+ rt_uint32_t index = 0;
+ struct edit_line *tmp;
+
+ RT_ASSERT(edit != RT_NULL);
+ RT_ASSERT(line != RT_NULL);
+
+ if (edit->head != RT_NULL)
+ {
+ tmp = edit->first_line;
+ index = edit->upleft.y;
+ while (tmp)
+ {
+ if (tmp == line)
+ break;
+ index ++;
+ tmp = tmp->next;
+ }
+ }
+ return index;
}
RTM_EXPORT(rtgui_edit_get_index_by_line);
-enum {
- EDIT_IDENT_DIR_BOTH,
- EDIT_IDENT_DIR_LEFT,
- EDIT_IDENT_DIR_RIGHT
+enum
+{
+ EDIT_IDENT_DIR_BOTH,
+ EDIT_IDENT_DIR_LEFT,
+ EDIT_IDENT_DIR_RIGHT
};
/*
* identify a byte is double byte
@@ -589,1324 +590,1370 @@ enum {
* @param *p record the position of the effective.
* @return RT_TRUE is Got it, else not found.
*/
-static rt_bool_t identify_double_byte(struct rtgui_edit *edit, struct edit_line *line,
- rt_uint32_t dir, rt_int16_t *p)
+static rt_bool_t identify_double_byte(struct rtgui_edit *edit, struct edit_line *line,
+ rt_uint32_t dir, rt_int16_t *p)
{
- int index, effe_nums;
+ int index, effe_nums;
- RT_ASSERT(edit != RT_NULL);
- RT_ASSERT(line != RT_NULL);
+ RT_ASSERT(edit != RT_NULL);
+ RT_ASSERT(line != RT_NULL);
- if(dir == EDIT_IDENT_DIR_BOTH)
- {
- }
- else if(dir == EDIT_IDENT_DIR_LEFT)
- {
- if(edit->upleft.x == 0 && edit->visual.x == 0)
- return RT_FALSE;
- index = edit->upleft.x + edit->visual.x;
- effe_nums = 0;
- while(index--)
- {
- if((rt_uint8_t)(*(line->text + index)) >= 0x80)
- effe_nums ++;
- else
- break;
- }
- if(effe_nums > 0)
- {
- *p = 2-effe_nums%2;
- return RT_TRUE;
- }
- }
- else if(dir == EDIT_IDENT_DIR_RIGHT)
- {
- if(edit->upleft.x + edit->visual.x == line->len)
- return RT_FALSE;
- index = edit->upleft.x + edit->visual.x;
- effe_nums = 0;
- while(index < line->len)
- {
- if((rt_uint8_t)(*(line->text + index)) >= 0x80)
- effe_nums ++;
- else
- break;
- index ++;
- }
- if(effe_nums > 0)
- {
- *p = 2-effe_nums%2;
- return RT_TRUE;
- }
- }
- return RT_FALSE;
+ if (dir == EDIT_IDENT_DIR_BOTH)
+ {
+ }
+ else if (dir == EDIT_IDENT_DIR_LEFT)
+ {
+ if (edit->upleft.x == 0 && edit->visual.x == 0)
+ return RT_FALSE;
+ index = edit->upleft.x + edit->visual.x;
+ effe_nums = 0;
+ while (index--)
+ {
+ if ((rt_uint8_t)(*(line->text + index)) >= 0x80)
+ effe_nums ++;
+ else
+ break;
+ }
+ if (effe_nums > 0)
+ {
+ *p = 2 - effe_nums % 2;
+ return RT_TRUE;
+ }
+ }
+ else if (dir == EDIT_IDENT_DIR_RIGHT)
+ {
+ if (edit->upleft.x + edit->visual.x == line->len)
+ return RT_FALSE;
+ index = edit->upleft.x + edit->visual.x;
+ effe_nums = 0;
+ while (index < line->len)
+ {
+ if ((rt_uint8_t)(*(line->text + index)) >= 0x80)
+ effe_nums ++;
+ else
+ break;
+ index ++;
+ }
+ if (effe_nums > 0)
+ {
+ *p = 2 - effe_nums % 2;
+ return RT_TRUE;
+ }
+ }
+ return RT_FALSE;
}
-static void rtgui_edit_onmouse(struct rtgui_edit* edit, struct rtgui_event_mouse* emouse)
+static void rtgui_edit_onmouse(struct rtgui_edit *edit, struct rtgui_event_mouse *emouse)
{
- rtgui_rect_t rect;
+ rtgui_rect_t rect;
+
+ RT_ASSERT(edit != RT_NULL);
+ RT_ASSERT(emouse != RT_NULL);
+
+ rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
+ if ((rtgui_region_contains_point(&(RTGUI_WIDGET(edit)->clip), emouse->x, emouse->y, &rect) == RT_EOK))
+ {
+ rt_uint16_t x, y;
- RT_ASSERT(edit != RT_NULL);
- RT_ASSERT(emouse != RT_NULL);
+ /* multiline text */
+ x = (emouse->x - rect.x1) / (edit->font_width);
+ y = (emouse->y - rect.y1) / (edit->item_height);
+ if ((x < edit->col_per_page) && (y < edit->row_per_page))
+ {
+ if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
+ {
+ struct edit_line *line;
+ rt_int16_t tmp_pos = 0;
- rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
- if((rtgui_region_contains_point(&(RTGUI_WIDGET(edit)->clip), emouse->x, emouse->y, &rect) == RT_EOK))
- {
- rt_uint16_t x, y;
+ edit->visual.x = x;
+ edit->visual.y = y;
- /* multiline text */
- x = (emouse->x - rect.x1) / (edit->font_width);
- y = (emouse->y - rect.y1) / (edit->item_height);
- if((x < edit->col_per_page) && (y < edit->row_per_page))
- {
- if(emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
- {
- struct edit_line *line;
- rt_int16_t tmp_pos=0;
-
- edit->visual.x = x;
- edit->visual.y = y;
-
- line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->visual.y);
- if(line == RT_NULL)
- return;
-
- if(edit->visual.x > line->len)
- edit->visual.x = line->len;
- if(edit->upleft.x > 0)
- {
- if(edit->upleft.x >= line->len)
- edit->upleft.x = 0;
- else
- edit->visual.x -= edit->upleft.x;
- rtgui_edit_ondraw(edit);
- }
- if(identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
- edit->visual.x -= (2-tmp_pos);
- if(edit->flag & RTGUI_EDIT_CARET)
- {
- if(edit->caret_timer != RT_NULL)
- rtgui_timer_stop(edit->caret_timer);
+ line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
+ if (line == RT_NULL)
+ return;
- edit->flag &= ~RTGUI_EDIT_CARET;
- rtgui_edit_draw_caret(edit);
+ if (edit->visual.x > line->len)
+ edit->visual.x = line->len;
+ if (edit->upleft.x > 0)
+ {
+ if (edit->upleft.x >= line->len)
+ edit->upleft.x = 0;
+ else
+ edit->visual.x -= edit->upleft.x;
+ rtgui_edit_ondraw(edit);
+ }
+ if (identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
+ edit->visual.x -= (2 - tmp_pos);
+ if (edit->flag & RTGUI_EDIT_CARET)
+ {
+ if (edit->caret_timer != RT_NULL)
+ rtgui_timer_stop(edit->caret_timer);
- if(edit->caret_timer != RT_NULL)
- rtgui_timer_start(edit->caret_timer);
- }
+ edit->flag &= ~RTGUI_EDIT_CARET;
+ rtgui_edit_draw_caret(edit);
- /* set widget focus */
- rtgui_widget_focus(RTGUI_WIDGET(edit));
+ if (edit->caret_timer != RT_NULL)
+ rtgui_timer_start(edit->caret_timer);
+ }
- if(RTGUI_WIDGET_IS_FOCUSED(edit))
- {
- rtgui_edit_init_caret(edit, edit->visual);
- edit->flag |= RTGUI_EDIT_CARET;
- rtgui_edit_draw_caret(edit);
- }
- }
- else if(emouse->button & RTGUI_MOUSE_BUTTON_UP)
- {
- /* please add codes at here. */
- }
-#ifdef RTGUI_EDIT_USING_SCROLL
- if(edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit))
- {
- if(!RTGUI_WIDGET_IS_HIDE(edit->vscroll))
- rtgui_scrollbar_set_value(edit->vscroll,edit->upleft.y);
- }
- if(edit->hscroll && !RTGUI_WIDGET_IS_HIDE(edit))
- {
- if(!RTGUI_WIDGET_IS_HIDE(edit->hscroll))
- rtgui_scrollbar_set_value(edit->hscroll,edit->upleft.x);
- }
+ /* set widget focus */
+ rtgui_widget_focus(RTGUI_WIDGET(edit));
+
+ if (RTGUI_WIDGET_IS_FOCUSED(edit))
+ {
+ rtgui_edit_init_caret(edit, edit->visual);
+ edit->flag |= RTGUI_EDIT_CARET;
+ rtgui_edit_draw_caret(edit);
+ }
+ }
+ else if (emouse->button & RTGUI_MOUSE_BUTTON_UP)
+ {
+ /* please add codes at here. */
+ }
+#ifdef RTGUI_EDIT_USING_SCROLL
+ if (edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit))
+ {
+ if (!RTGUI_WIDGET_IS_HIDE(edit->vscroll))
+ rtgui_scrollbar_set_value(edit->vscroll, edit->upleft.y);
+ }
+ if (edit->hscroll && !RTGUI_WIDGET_IS_HIDE(edit))
+ {
+ if (!RTGUI_WIDGET_IS_HIDE(edit->hscroll))
+ rtgui_scrollbar_set_value(edit->hscroll, edit->upleft.x);
+ }
#endif
- }
- }
+ }
+ }
}
rt_inline rt_uint16_t query_shift_code(rt_uint16_t key)
{
- if(key >= RTGUIK_a && key <= RTGUIK_z)
- return (key - ('a'-'A'));
- else
- {
- switch (key)
- {
- case '1': return '!';
- case '2': return '@';
- case '3': return '#';
- case '4': return '$';
- case '5': return '%';
- case '6': return '^';
- case '7': return '&';
- case '8': return '*';
- case '9': return '(';
- case '0': return ')';
- case '-': return '_';
- case '=': return '+';
- case '\\':return '|';
- case ';': return ':';
- case '\'':return '"';
- case ',': return '<';
- case '.': return '>';
- case '/': return '?';
- case '`': return '~';
- }
- }
- return key;
+ if (key >= RTGUIK_a && key <= RTGUIK_z)
+ return (key - ('a' - 'A'));
+ else
+ {
+ switch (key)
+ {
+ case '1':
+ return '!';
+ case '2':
+ return '@';
+ case '3':
+ return '#';
+ case '4':
+ return '$';
+ case '5':
+ return '%';
+ case '6':
+ return '^';
+ case '7':
+ return '&';
+ case '8':
+ return '*';
+ case '9':
+ return '(';
+ case '0':
+ return ')';
+ case '-':
+ return '_';
+ case '=':
+ return '+';
+ case '\\':
+ return '|';
+ case ';':
+ return ':';
+ case '\'':
+ return '"';
+ case ',':
+ return '<';
+ case '.':
+ return '>';
+ case '/':
+ return '?';
+ case '`':
+ return '~';
+ }
+ }
+ return key;
}
rt_inline rt_uint16_t query_caps_code(rt_uint16_t key)
{
- if(key >= RTGUIK_a && key <= RTGUIK_z)
- return (key - ('a'-'A'));
- return key;
+ if (key >= RTGUIK_a && key <= RTGUIK_z)
+ return (key - ('a' - 'A'));
+ return key;
}
rt_inline rt_bool_t is_small_keyboard(rt_uint16_t *key)
{
- if(*key >= RTGUIK_KP0 && *key <= RTGUIK_KP9)
- {
- *key = *key - (RTGUIK_KP0 - RTGUIK_0);
- return RT_TRUE;
- }
- else if(*key == RTGUIK_KP_PERIOD)
- {
- *key = '.';
- return RT_TRUE;
- }
- else if(*key == RTGUIK_KP_DIVIDE)
- {
- *key = '/';
- return RT_TRUE;
- }
- else if(*key == RTGUIK_KP_MULTIPLY)
- {
- *key = '*';
- return RT_TRUE;
- }
- else if(*key == RTGUIK_KP_MINUS)
- {
- *key = '-';
- return RT_TRUE;
- }
- else if(*key == RTGUIK_KP_PLUS)
- {
- *key = '+';
- return RT_TRUE;
- }
- else if(*key == RTGUIK_KP_ENTER)
- {
- *key = RTGUIK_RETURN;
- return RT_TRUE;
- }
- return RT_FALSE;
+ if (*key >= RTGUIK_KP0 && *key <= RTGUIK_KP9)
+ {
+ *key = *key - (RTGUIK_KP0 - RTGUIK_0);
+ return RT_TRUE;
+ }
+ else if (*key == RTGUIK_KP_PERIOD)
+ {
+ *key = '.';
+ return RT_TRUE;
+ }
+ else if (*key == RTGUIK_KP_DIVIDE)
+ {
+ *key = '/';
+ return RT_TRUE;
+ }
+ else if (*key == RTGUIK_KP_MULTIPLY)
+ {
+ *key = '*';
+ return RT_TRUE;
+ }
+ else if (*key == RTGUIK_KP_MINUS)
+ {
+ *key = '-';
+ return RT_TRUE;
+ }
+ else if (*key == RTGUIK_KP_PLUS)
+ {
+ *key = '+';
+ return RT_TRUE;
+ }
+ else if (*key == RTGUIK_KP_ENTER)
+ {
+ *key = RTGUIK_RETURN;
+ return RT_TRUE;
+ }
+ return RT_FALSE;
}
void kbd_event_set_key(struct rtgui_event_kbd *ekbd, rt_uint16_t key)
{
- RTGUI_EVENT_KBD_INIT(ekbd);
- ekbd->mod = RTGUI_KMOD_NONE;
- ekbd->unicode = 0;
+ RTGUI_EVENT_KBD_INIT(ekbd);
+ ekbd->mod = RTGUI_KMOD_NONE;
+ ekbd->unicode = 0;
- ekbd->key = key;
- ekbd->type = RTGUI_KEYDOWN;
+ ekbd->key = key;
+ ekbd->type = RTGUI_KEYDOWN;
}
-static rt_bool_t rtgui_edit_onkey(struct rtgui_object* object, rtgui_event_t* event)
+static rt_bool_t rtgui_edit_onkey(struct rtgui_object *object, rtgui_event_t *event)
{
- enum { EDIT_NONE, EDIT_ONDRAW, EDIT_UPDATE };
- struct rtgui_edit *edit = RTGUI_EDIT(object);
- struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd*)event;
- struct edit_line *line=RT_NULL;
- rt_bool_t update_type = EDIT_NONE;
-
- RT_ASSERT(edit != RT_NULL);
- RT_ASSERT(ekbd != RT_NULL);
+ enum { EDIT_NONE, EDIT_ONDRAW, EDIT_UPDATE };
+ struct rtgui_edit *edit = RTGUI_EDIT(object);
+ struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
+ struct edit_line *line = RT_NULL;
+ rt_bool_t update_type = EDIT_NONE;
+
+ RT_ASSERT(edit != RT_NULL);
+ RT_ASSERT(ekbd != RT_NULL);
+
+ if (RTGUI_KBD_IS_UP(ekbd))
+ {
+ /* reset function key */
+ if (ekbd->key == RTGUIK_RCTRL || ekbd->key == RTGUIK_LCTRL)
+ edit->flag &= ~RTGUI_EDIT_CTRL;
+ else if (ekbd->key == RTGUIK_RALT || ekbd->key == RTGUIK_LALT)
+ edit->flag &= ~RTGUI_EDIT_ALT;
+ else if (ekbd->key == RTGUIK_RSHIFT || ekbd->key == RTGUIK_LSHIFT)
+ edit->flag &= ~RTGUI_EDIT_SHIFT;
+ else if (ekbd->key == RTGUIK_CAPSLOCK)
+ edit->flag &= ~RTGUI_EDIT_CAPSLOCK;
+ else if (ekbd->key == RTGUIK_NUMLOCK)
+ edit->flag &= ~RTGUI_EDIT_NUMLOCK;
+ return RT_TRUE;
+ }
+
+ line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
+ if (line == RT_NULL)
+ return RT_FALSE;
+
+ /* rt_kprintf("key=%04X ",ekbd->key); */
+ if (ekbd->key == RTGUIK_RCTRL || ekbd->key == RTGUIK_LCTRL)
+ {
+ /* use CTRL key */
+ edit->flag |= RTGUI_EDIT_CTRL;
+ return RT_FALSE;
+ }
+ else if (ekbd->key == RTGUIK_RALT || ekbd->key == RTGUIK_LALT)
+ {
+ /* use ALT key */
+ edit->flag |= RTGUI_EDIT_ALT;
+ return RT_FALSE;
+ }
+ else if (ekbd->key == RTGUIK_RSHIFT || ekbd->key == RTGUIK_LSHIFT)
+ {
+ /* use SHIFT key */
+ edit->flag |= RTGUI_EDIT_SHIFT;
+ return RT_FALSE;
+ }
+ else if (ekbd->key == RTGUIK_CAPSLOCK)
+ {
+ edit->flag |= RTGUI_EDIT_CAPSLOCK;
+ return RT_FALSE;
+ }
+ else if (ekbd->key == RTGUIK_NUMLOCK)
+ {
+ edit->flag |= RTGUI_EDIT_NUMLOCK;
+ return RT_FALSE;
+ }
+ else if (ekbd->key == RTGUIK_DELETE)
+ {
+ /* delete latter character */
+ int ofs = edit->upleft.x + edit->visual.x;
+ if (ofs > line->len - 1 || (ofs == 0 && line->len == 0))
+ {
+ /* will the next line marges into the current line */
+ struct edit_line *next_line = line->next;
+ if (next_line != RT_NULL)
+ {
+ struct edit_line *update_end_line;
+
+ update_type = EDIT_UPDATE;
+ edit->update.start = edit->visual;
- if (RTGUI_KBD_IS_UP(ekbd))
- { /* reset function key */
- if(ekbd->key == RTGUIK_RCTRL || ekbd->key == RTGUIK_LCTRL)
- edit->flag &= ~RTGUI_EDIT_CTRL;
- else if(ekbd->key == RTGUIK_RALT || ekbd->key == RTGUIK_LALT)
- edit->flag &= ~RTGUI_EDIT_ALT;
- else if(ekbd->key == RTGUIK_RSHIFT || ekbd->key == RTGUIK_LSHIFT)
- edit->flag &= ~RTGUI_EDIT_SHIFT;
- else if(ekbd->key == RTGUIK_CAPSLOCK)
- edit->flag &= ~RTGUI_EDIT_CAPSLOCK;
- else if(ekbd->key == RTGUIK_NUMLOCK)
- edit->flag &= ~RTGUI_EDIT_NUMLOCK;
- return RT_TRUE;
- }
-
- line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
- if(line == RT_NULL)
- return RT_FALSE;
+ rtgui_edit_connect_line(edit, line, next_line);
+ rtgui_edit_delete_line(edit, next_line);
- /* rt_kprintf("key=%04X ",ekbd->key); */
- if(ekbd->key == RTGUIK_RCTRL || ekbd->key == RTGUIK_LCTRL)
- { /* use CTRL key */
- edit->flag |= RTGUI_EDIT_CTRL;
- return RT_FALSE;
- }
- else if(ekbd->key == RTGUIK_RALT || ekbd->key == RTGUIK_LALT)
- { /* use ALT key */
- edit->flag |= RTGUI_EDIT_ALT;
- return RT_FALSE;
- }
- else if(ekbd->key == RTGUIK_RSHIFT || ekbd->key == RTGUIK_LSHIFT)
- { /* use SHIFT key */
- edit->flag |= RTGUI_EDIT_SHIFT;
- return RT_FALSE;
- }
- else if(ekbd->key == RTGUIK_CAPSLOCK)
- {
- edit->flag |= RTGUI_EDIT_CAPSLOCK;
- return RT_FALSE;
- }
- else if(ekbd->key == RTGUIK_NUMLOCK)
- {
- edit->flag |= RTGUI_EDIT_NUMLOCK;
- return RT_FALSE;
- }
- else if(ekbd->key == RTGUIK_DELETE)
- { /* delete latter character */
- int ofs = edit->upleft.x + edit->visual.x;
- if(ofs > line->len - 1 || (ofs==0 && line->len==0))
- { /* will the next line marges into the current line */
- struct edit_line* next_line = line->next;
- if(next_line != RT_NULL)
- {
- struct edit_line *update_end_line;
-
- update_type = EDIT_UPDATE;
- edit->update.start = edit->visual;
+ if (edit->max_rows - edit->upleft.y > edit->row_per_page)
+ {
+ update_end_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->row_per_page);
+ if (update_end_line != RT_NULL)
+ {
+ edit->update.end.x = edit->col_per_page;
+ edit->update.end.y = edit->upleft.y + edit->row_per_page;
+ }
+ }
+ else
+ {
+ int update_end_index = rtgui_edit_get_index_by_line(edit, edit->tail);
+ edit->update.end.x = edit->col_per_page;
+ edit->update.end.y = update_end_index + 1;
+ }
+ }
+ line->len = rtgui_edit_line_strlen(line->text);
+ goto _edit_exit;
+ }
+ else if (ofs == line->len - 1)
+ {
+ line->text[ofs] = '\0';
+ }
+ else
+ {
+ char *c;
+ rt_int16_t tmp_pos = 1;
+ identify_double_byte(edit, line, EDIT_IDENT_DIR_RIGHT, &tmp_pos);
+ /* remove character */
+ for (c = &line->text[ofs]; c[tmp_pos] != '\0'; c++)
+ *c = c[tmp_pos];
+ *c = '\0';
+ }
+ update_type = EDIT_UPDATE;
+ edit->update.start = edit->visual;
+ edit->update.end.x = line->len - edit->upleft.x;
+ if (edit->update.end.x > edit->col_per_page)
+ edit->update.end.x = edit->col_per_page;
+ edit->update.end.y = edit->visual.y;
+ }
+ else if (ekbd->key == RTGUIK_BACKSPACE)
+ {
+ if (edit->visual.x == 0)
+ {
+ /* incorporated into prev line */
+ struct rtgui_event_kbd event_kbd;
+ struct edit_line *prev_line = line->prev;
+ if (prev_line != RT_NULL)
+ {
+ struct edit_line *update_end_line;
- rtgui_edit_connect_line(edit, line, next_line);
- rtgui_edit_delete_line(edit, next_line);
+ update_type = EDIT_UPDATE;
+ edit->visual.x = prev_line->len;
- if(edit->max_rows-edit->upleft.y > edit->row_per_page)
- {
- update_end_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->row_per_page);
- if(update_end_line != RT_NULL)
- {
- edit->update.end.x = edit->col_per_page;
- edit->update.end.y = edit->upleft.y + edit->row_per_page;
- }
- }
- else
- {
- int update_end_index = rtgui_edit_get_index_by_line(edit, edit->tail);
- edit->update.end.x = edit->col_per_page;
- edit->update.end.y = update_end_index+1;
- }
- }
- line->len = rtgui_edit_line_strlen(line->text);
- goto _edit_exit;
- }
- else if(ofs == line->len - 1)
- {
- line->text[ofs] = '\0';
- }
- else
- {
- char *c;
- rt_int16_t tmp_pos=1;
- identify_double_byte(edit, line, EDIT_IDENT_DIR_RIGHT, &tmp_pos);
- /* remove character */
- for(c = &line->text[ofs]; c[tmp_pos] != '\0'; c++)
- *c = c[tmp_pos];
- *c = '\0';
- }
- update_type = EDIT_UPDATE;
- edit->update.start = edit->visual;
- edit->update.end.x = line->len-edit->upleft.x;
- if (edit->update.end.x > edit->col_per_page)
- edit->update.end.x = edit->col_per_page;
- edit->update.end.y = edit->visual.y;
- }
- else if(ekbd->key == RTGUIK_BACKSPACE)
- {
- if(edit->visual.x == 0)
- { /* incorporated into prev line */
- struct rtgui_event_kbd event_kbd;
- struct edit_line* prev_line = line->prev;
- if(prev_line != RT_NULL)
- {
- struct edit_line *update_end_line;
-
- update_type = EDIT_UPDATE;
- edit->visual.x = prev_line->len;
+ rtgui_edit_connect_line(edit, prev_line, line);
+ kbd_event_set_key(&event_kbd, RTGUIK_UP);
+ rtgui_edit_onkey(object, (rtgui_event_t *)&event_kbd);
+ rtgui_edit_delete_line(edit, line);
- rtgui_edit_connect_line(edit, prev_line, line);
- kbd_event_set_key(&event_kbd, RTGUIK_UP);
- rtgui_edit_onkey(object, (rtgui_event_t*)&event_kbd);
- rtgui_edit_delete_line(edit, line);
+ edit->update.start = edit->visual; /* update.start.y is changed */
+ if (edit->max_rows - edit->upleft.y > edit->row_per_page)
+ {
+ update_end_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->row_per_page);
+ if (update_end_line != RT_NULL)
+ {
+ edit->update.end.x = edit->col_per_page;
+ edit->update.end.y = edit->upleft.y + edit->row_per_page;
+ }
+ }
+ else
+ {
+ int update_end_index = rtgui_edit_get_index_by_line(edit, edit->tail);
+ edit->update.end.x = edit->col_per_page;
+ edit->update.end.y = update_end_index + 1;
+ }
+ }
+ goto _edit_exit;
+ }
- edit->update.start = edit->visual; /* update.start.y is changed */
- if(edit->max_rows-edit->upleft.y > edit->row_per_page)
- {
- update_end_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->row_per_page);
- if(update_end_line != RT_NULL)
- {
- edit->update.end.x = edit->col_per_page;
- edit->update.end.y = edit->upleft.y + edit->row_per_page;
- }
- }
- else
- {
- int update_end_index = rtgui_edit_get_index_by_line(edit, edit->tail);
- edit->update.end.x = edit->col_per_page;
- edit->update.end.y = update_end_index+1;
- }
- }
- goto _edit_exit;
- }
-
- /* delete front character */
- if(edit->visual.x == line->len)
- {
- rt_int16_t tmp_pos=1;
- identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
- line->text[edit->visual.x-tmp_pos] = '\0';
- edit->visual.x -= tmp_pos;
- }
- else if(edit->visual.x != 0)
- { /* remove current character */
- char *c;
- rt_int16_t tmp_pos=1;
- identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
- /* remove character */
- for(c = &line->text[edit->visual.x - tmp_pos]; c[tmp_pos] != '\0'; c++)
- {
- *c = c[tmp_pos];
- }
- *c = '\0';
- edit->visual.x -= tmp_pos;
- }
- /* adjusted line buffer length */
- if(rtgui_edit_alloc_len(edit->bzsize, line->len+2) < line->zsize)
- {
- line->zsize = rtgui_edit_alloc_len(edit->bzsize, line->len+1);
- line->text = rt_realloc(line->text, line->zsize);
- }
- update_type = EDIT_UPDATE;
- edit->update.start = edit->visual;
- edit->update.end.x = line->len;
- edit->update.end.y = edit->visual.y;
- }
- else if(ekbd->key == RTGUIK_UP)
- { /* move to prev line */
- struct edit_line* prev_line;
- if(edit->visual.y > 0)
- edit->visual.y --;
- else
- {
- /* change first row */
- if(edit->upleft.y > 0)
- {
- edit->upleft.y --;
- if(edit->first_line->prev != RT_NULL)
- edit->first_line = edit->first_line->prev;
- update_type = EDIT_ONDRAW;
- }
- }
-
- /* The position of the recount X */
- prev_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->visual.y);
- if(prev_line == RT_NULL)
- return RT_FALSE;
+ /* delete front character */
+ if (edit->visual.x == line->len)
+ {
+ rt_int16_t tmp_pos = 1;
+ identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
+ line->text[edit->visual.x - tmp_pos] = '\0';
+ edit->visual.x -= tmp_pos;
+ }
+ else if (edit->visual.x != 0)
+ {
+ /* remove current character */
+ char *c;
+ rt_int16_t tmp_pos = 1;
+ identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
+ /* remove character */
+ for (c = &line->text[edit->visual.x - tmp_pos]; c[tmp_pos] != '\0'; c++)
+ {
+ *c = c[tmp_pos];
+ }
+ *c = '\0';
+ edit->visual.x -= tmp_pos;
+ }
+ /* adjusted line buffer length */
+ if (rtgui_edit_alloc_len(edit->bzsize, line->len + 2) < line->zsize)
+ {
+ line->zsize = rtgui_edit_alloc_len(edit->bzsize, line->len + 1);
+ line->text = rt_realloc(line->text, line->zsize);
+ }
+ update_type = EDIT_UPDATE;
+ edit->update.start = edit->visual;
+ edit->update.end.x = line->len;
+ edit->update.end.y = edit->visual.y;
+ }
+ else if (ekbd->key == RTGUIK_UP)
+ {
+ /* move to prev line */
+ struct edit_line *prev_line;
+ if (edit->visual.y > 0)
+ edit->visual.y --;
+ else
+ {
+ /* change first row */
+ if (edit->upleft.y > 0)
+ {
+ edit->upleft.y --;
+ if (edit->first_line->prev != RT_NULL)
+ edit->first_line = edit->first_line->prev;
+ update_type = EDIT_ONDRAW;
+ }
+ }
- if(edit->upleft.x > 0)
- {
- if(prev_line->len <= edit->upleft.x)
- {
- if(prev_line->len <= edit->col_per_page)
- {
- edit->upleft.x = 0;
- edit->visual.x = prev_line->len;
- }
- else
- {
- edit->upleft.x = prev_line->len - (edit->col_per_page-1);
- edit->visual.x = edit->col_per_page-1;
- }
- update_type = EDIT_ONDRAW;
- }
- else if(prev_line->len - edit->upleft.x < edit->col_per_page)
- {
- if(edit->visual.x > prev_line->len - edit->upleft.x)
- edit->visual.x = prev_line->len - edit->upleft.x;
- else
- {
- rt_int16_t tmp_pos=0;
- if(identify_double_byte(edit, prev_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
- edit->visual.x -= (2-tmp_pos);
- }
- }
- }
- else if(edit->visual.x > prev_line->len)
- edit->visual.x = prev_line->len;
- else if(prev_line->len >= 2)
- {
- rt_int16_t tmp_pos=0;
- if(identify_double_byte(edit, prev_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
- edit->visual.x -= (2-tmp_pos);
- }
+ /* The position of the recount X */
+ prev_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
+ if (prev_line == RT_NULL)
+ return RT_FALSE;
-#ifdef RTGUI_EDIT_USING_SCROLL
- /* update vscroll */
- if(edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit))
- {
- if(!RTGUI_WIDGET_IS_HIDE(edit->vscroll))
- rtgui_scrollbar_set_value(edit->vscroll,edit->upleft.y);
- }
+ if (edit->upleft.x > 0)
+ {
+ if (prev_line->len <= edit->upleft.x)
+ {
+ if (prev_line->len <= edit->col_per_page)
+ {
+ edit->upleft.x = 0;
+ edit->visual.x = prev_line->len;
+ }
+ else
+ {
+ edit->upleft.x = prev_line->len - (edit->col_per_page - 1);
+ edit->visual.x = edit->col_per_page - 1;
+ }
+ update_type = EDIT_ONDRAW;
+ }
+ else if (prev_line->len - edit->upleft.x < edit->col_per_page)
+ {
+ if (edit->visual.x > prev_line->len - edit->upleft.x)
+ edit->visual.x = prev_line->len - edit->upleft.x;
+ else
+ {
+ rt_int16_t tmp_pos = 0;
+ if (identify_double_byte(edit, prev_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
+ edit->visual.x -= (2 - tmp_pos);
+ }
+ }
+ }
+ else if (edit->visual.x > prev_line->len)
+ edit->visual.x = prev_line->len;
+ else if (prev_line->len >= 2)
+ {
+ rt_int16_t tmp_pos = 0;
+ if (identify_double_byte(edit, prev_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
+ edit->visual.x -= (2 - tmp_pos);
+ }
+
+#ifdef RTGUI_EDIT_USING_SCROLL
+ /* update vscroll */
+ if (edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit))
+ {
+ if (!RTGUI_WIDGET_IS_HIDE(edit->vscroll))
+ rtgui_scrollbar_set_value(edit->vscroll, edit->upleft.y);
+ }
#endif
- }
- else if(ekbd->key == RTGUIK_DOWN)
- {
- struct edit_line *tail_line, *next_line;
- tail_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
- if(tail_line != RT_NULL)
- { /* it is tail line */
- if(tail_line == edit->tail) return RT_FALSE;
- }
- /* move to next line */
- if(edit->visual.y < edit->row_per_page - 2)
- {
- edit->visual.y ++;
- }
- else if(edit->visual.y+edit->upleft.y < edit->max_rows-1)
- {
- /* change first row */
- edit->upleft.y++;
- if(edit->first_line->next != RT_NULL)
- edit->first_line = edit->first_line->next;
- update_type = EDIT_ONDRAW;
- }
-
- /* adjust next line end position */
- next_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->visual.y);
- if(next_line == RT_NULL)
- return RT_FALSE;
-
- if(edit->upleft.x > 0)
- {
- if(next_line->len <= edit->upleft.x)
- {
- if(next_line->len <= edit->col_per_page)
- {
- edit->upleft.x = 0;
- edit->visual.x = next_line->len;
- }
- else
- {
- edit->upleft.x = next_line->len - (edit->col_per_page-1);
- edit->visual.x = edit->col_per_page-1;
- }
- update_type = EDIT_ONDRAW;
- }
- else if(next_line->len - edit->upleft.x < edit->col_per_page)
- {
- if(edit->visual.x > next_line->len - edit->upleft.x)
- edit->visual.x = next_line->len - edit->upleft.x;
- else
- {
- rt_int16_t tmp_pos=0;
- if(identify_double_byte(edit, next_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
- edit->visual.x -= (2-tmp_pos);
- }
- }
- }
- else if(edit->visual.x > next_line->len)
- edit->visual.x = next_line->len;
- else if(next_line->len >= 2)
- {
- rt_int16_t tmp_pos=0;
- if(identify_double_byte(edit, next_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
- edit->visual.x -= (2-tmp_pos);
- }
+ }
+ else if (ekbd->key == RTGUIK_DOWN)
+ {
+ struct edit_line *tail_line, *next_line;
+ tail_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
+ if (tail_line != RT_NULL)
+ {
+ /* it is tail line */
+ if (tail_line == edit->tail) return RT_FALSE;
+ }
+ /* move to next line */
+ if (edit->visual.y < edit->row_per_page - 2)
+ {
+ edit->visual.y ++;
+ }
+ else if (edit->visual.y + edit->upleft.y < edit->max_rows - 1)
+ {
+ /* change first row */
+ edit->upleft.y++;
+ if (edit->first_line->next != RT_NULL)
+ edit->first_line = edit->first_line->next;
+ update_type = EDIT_ONDRAW;
+ }
+
+ /* adjust next line end position */
+ next_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
+ if (next_line == RT_NULL)
+ return RT_FALSE;
+
+ if (edit->upleft.x > 0)
+ {
+ if (next_line->len <= edit->upleft.x)
+ {
+ if (next_line->len <= edit->col_per_page)
+ {
+ edit->upleft.x = 0;
+ edit->visual.x = next_line->len;
+ }
+ else
+ {
+ edit->upleft.x = next_line->len - (edit->col_per_page - 1);
+ edit->visual.x = edit->col_per_page - 1;
+ }
+ update_type = EDIT_ONDRAW;
+ }
+ else if (next_line->len - edit->upleft.x < edit->col_per_page)
+ {
+ if (edit->visual.x > next_line->len - edit->upleft.x)
+ edit->visual.x = next_line->len - edit->upleft.x;
+ else
+ {
+ rt_int16_t tmp_pos = 0;
+ if (identify_double_byte(edit, next_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
+ edit->visual.x -= (2 - tmp_pos);
+ }
+ }
+ }
+ else if (edit->visual.x > next_line->len)
+ edit->visual.x = next_line->len;
+ else if (next_line->len >= 2)
+ {
+ rt_int16_t tmp_pos = 0;
+ if (identify_double_byte(edit, next_line, EDIT_IDENT_DIR_LEFT, &tmp_pos))
+ edit->visual.x -= (2 - tmp_pos);
+ }
-#ifdef RTGUI_EDIT_USING_SCROLL
- /* update vscroll */
- if(edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit))
- {
- if(!RTGUI_WIDGET_IS_HIDE(edit->vscroll))
- rtgui_scrollbar_set_value(edit->vscroll,edit->upleft.y);
- }
+#ifdef RTGUI_EDIT_USING_SCROLL
+ /* update vscroll */
+ if (edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit))
+ {
+ if (!RTGUI_WIDGET_IS_HIDE(edit->vscroll))
+ rtgui_scrollbar_set_value(edit->vscroll, edit->upleft.y);
+ }
#endif
- }
- else if(ekbd->key == RTGUIK_LEFT)
- { /* move to prev char */
- if(edit->visual.x > 0)
- {
- rt_int16_t tmp_pos=1;
- identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
- edit->visual.x -= tmp_pos;
- if(edit->visual.x == -1)
- {
- edit->visual.x = 0;
- edit->upleft.x --;
- update_type = EDIT_ONDRAW;
- }
- }
- else
- {
- if(edit->upleft.x > 0)
- {
- rt_int16_t tmp_pos=1;
- identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
- edit->upleft.x -= tmp_pos;
- update_type = EDIT_ONDRAW;
- }
- else
- {
- struct rtgui_event_kbd event_kbd;
- struct edit_line* first_line;
- first_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
- if(first_line != RT_NULL)
- { /* it is head line */
- if(first_line == edit->head) return RT_FALSE;
- }
- /* move the caret to the prev line end */
- kbd_event_set_key(&event_kbd, RTGUIK_UP);
- rtgui_edit_onkey(object, (rtgui_event_t*)&event_kbd);
- kbd_event_set_key(&event_kbd, RTGUIK_END);
- rtgui_edit_onkey(object, (rtgui_event_t*)&event_kbd);
- }
- }
- }
- else if(ekbd->key == RTGUIK_RIGHT)
- { /* move to next char */
- if(line->len >= edit->col_per_page)
- {
- if(edit->upleft.x+edit->col_per_page <= line->len)
- {
- if(edit->visual.x < edit->col_per_page-1)
- {
- rt_int16_t tmp_pos=1;
- identify_double_byte(edit, line, EDIT_IDENT_DIR_RIGHT, &tmp_pos);
- edit->visual.x += tmp_pos;
- }
- else if(edit->visual.x == edit->col_per_page-1)
- {
- if(edit->upleft.x+edit->col_per_page < line->len)
- edit->upleft.x ++;
- else
- edit->upleft.x = line->len - edit->col_per_page + 1;
- update_type = EDIT_ONDRAW;
- }
- }
- else
- {
- struct rtgui_event_kbd event_kbd;
- /* move to next head */
- kbd_event_set_key(&event_kbd, RTGUIK_DOWN);
- rtgui_edit_onkey(object, (rtgui_event_t*)&event_kbd);
- kbd_event_set_key(&event_kbd, RTGUIK_HOME);
- rtgui_edit_onkey(object, (rtgui_event_t*)&event_kbd);
- }
- }
- else
- {
- if(edit->visual.x < line->len)
- {
- rt_int16_t tmp_pos=1;
- identify_double_byte(edit, line, EDIT_IDENT_DIR_RIGHT, &tmp_pos);
- edit->visual.x += tmp_pos;
- }
- else
- {
- struct rtgui_event_kbd event_kbd;
- struct edit_line* tail_line;
- tail_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
- if(tail_line != RT_NULL)
- { /* it is tail line */
- if(tail_line == edit->tail) return RT_FALSE;
- }
- /* move the caret to the next line head */
- kbd_event_set_key(&event_kbd, RTGUIK_DOWN);
- rtgui_edit_onkey(object, (rtgui_event_t*)&event_kbd);
- kbd_event_set_key(&event_kbd, RTGUIK_HOME);
- rtgui_edit_onkey(object, (rtgui_event_t*)&event_kbd);
- }
- }
- }
- else if(ekbd->key == RTGUIK_HOME)
- { /* move cursor to line head */
- edit->visual.x = 0;
- if(edit->upleft.x > 0)
- {
- edit->upleft.x = 0;
- update_type = EDIT_ONDRAW;
- }
- }
- else if(ekbd->key == RTGUIK_END)
- { /* move cursor to line tail */
- if(line->len >= edit->col_per_page)
- {
- edit->visual.x = edit->col_per_page - 1;
- edit->upleft.x = line->len - (edit->col_per_page-1);
- update_type = EDIT_ONDRAW;
- }
- else
- edit->visual.x = line->len;
- }
- else if(ekbd->key == RTGUIK_TAB)
- {
- int space_nums;
- struct rtgui_event_kbd event_kbd;
- /* using spaces to replace TAB */
- space_nums = edit->tabsize - (edit->upleft.x+edit->visual.x) % edit->tabsize;
- while(space_nums--)
- {
- kbd_event_set_key(&event_kbd, RTGUIK_SPACE);
- rtgui_edit_onkey(object, (rtgui_event_t*)&event_kbd);
- }
- }
- else if(ekbd->key == RTGUIK_RETURN)
- {
- struct edit_line *update_end_line;
- struct rtgui_event_kbd event_kbd;
-
- /* insert a new line buffer */
- rtgui_edit_insert_line(edit, line, line->text + edit->upleft.x + edit->visual.x);
- line->text[edit->upleft.x + edit->visual.x] = '\0';
- line->len = rtgui_edit_line_strlen(line->text);
+ }
+ else if (ekbd->key == RTGUIK_LEFT)
+ {
+ /* move to prev char */
+ if (edit->visual.x > 0)
+ {
+ rt_int16_t tmp_pos = 1;
+ identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
+ edit->visual.x -= tmp_pos;
+ if (edit->visual.x == -1)
+ {
+ edit->visual.x = 0;
+ edit->upleft.x --;
+ update_type = EDIT_ONDRAW;
+ }
+ }
+ else
+ {
+ if (edit->upleft.x > 0)
+ {
+ rt_int16_t tmp_pos = 1;
+ identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
+ edit->upleft.x -= tmp_pos;
+ update_type = EDIT_ONDRAW;
+ }
+ else
+ {
+ struct rtgui_event_kbd event_kbd;
+ struct edit_line *first_line;
+ first_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
+ if (first_line != RT_NULL)
+ {
+ /* it is head line */
+ if (first_line == edit->head) return RT_FALSE;
+ }
+ /* move the caret to the prev line end */
+ kbd_event_set_key(&event_kbd, RTGUIK_UP);
+ rtgui_edit_onkey(object, (rtgui_event_t *)&event_kbd);
+ kbd_event_set_key(&event_kbd, RTGUIK_END);
+ rtgui_edit_onkey(object, (rtgui_event_t *)&event_kbd);
+ }
+ }
+ }
+ else if (ekbd->key == RTGUIK_RIGHT)
+ {
+ /* move to next char */
+ if (line->len >= edit->col_per_page)
+ {
+ if (edit->upleft.x + edit->col_per_page <= line->len)
+ {
+ if (edit->visual.x < edit->col_per_page - 1)
+ {
+ rt_int16_t tmp_pos = 1;
+ identify_double_byte(edit, line, EDIT_IDENT_DIR_RIGHT, &tmp_pos);
+ edit->visual.x += tmp_pos;
+ }
+ else if (edit->visual.x == edit->col_per_page - 1)
+ {
+ if (edit->upleft.x + edit->col_per_page < line->len)
+ edit->upleft.x ++;
+ else
+ edit->upleft.x = line->len - edit->col_per_page + 1;
+ update_type = EDIT_ONDRAW;
+ }
+ }
+ else
+ {
+ struct rtgui_event_kbd event_kbd;
+ /* move to next head */
+ kbd_event_set_key(&event_kbd, RTGUIK_DOWN);
+ rtgui_edit_onkey(object, (rtgui_event_t *)&event_kbd);
+ kbd_event_set_key(&event_kbd, RTGUIK_HOME);
+ rtgui_edit_onkey(object, (rtgui_event_t *)&event_kbd);
+ }
+ }
+ else
+ {
+ if (edit->visual.x < line->len)
+ {
+ rt_int16_t tmp_pos = 1;
+ identify_double_byte(edit, line, EDIT_IDENT_DIR_RIGHT, &tmp_pos);
+ edit->visual.x += tmp_pos;
+ }
+ else
+ {
+ struct rtgui_event_kbd event_kbd;
+ struct edit_line *tail_line;
+ tail_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->visual.y);
+ if (tail_line != RT_NULL)
+ {
+ /* it is tail line */
+ if (tail_line == edit->tail) return RT_FALSE;
+ }
+ /* move the caret to the next line head */
+ kbd_event_set_key(&event_kbd, RTGUIK_DOWN);
+ rtgui_edit_onkey(object, (rtgui_event_t *)&event_kbd);
+ kbd_event_set_key(&event_kbd, RTGUIK_HOME);
+ rtgui_edit_onkey(object, (rtgui_event_t *)&event_kbd);
+ }
+ }
+ }
+ else if (ekbd->key == RTGUIK_HOME)
+ {
+ /* move cursor to line head */
+ edit->visual.x = 0;
+ if (edit->upleft.x > 0)
+ {
+ edit->upleft.x = 0;
+ update_type = EDIT_ONDRAW;
+ }
+ }
+ else if (ekbd->key == RTGUIK_END)
+ {
+ /* move cursor to line tail */
+ if (line->len >= edit->col_per_page)
+ {
+ edit->visual.x = edit->col_per_page - 1;
+ edit->upleft.x = line->len - (edit->col_per_page - 1);
+ update_type = EDIT_ONDRAW;
+ }
+ else
+ edit->visual.x = line->len;
+ }
+ else if (ekbd->key == RTGUIK_TAB)
+ {
+ int space_nums;
+ struct rtgui_event_kbd event_kbd;
+ /* using spaces to replace TAB */
+ space_nums = edit->tabsize - (edit->upleft.x + edit->visual.x) % edit->tabsize;
+ while (space_nums--)
+ {
+ kbd_event_set_key(&event_kbd, RTGUIK_SPACE);
+ rtgui_edit_onkey(object, (rtgui_event_t *)&event_kbd);
+ }
+ }
+ else if (ekbd->key == RTGUIK_RETURN)
+ {
+ struct edit_line *update_end_line;
+ struct rtgui_event_kbd event_kbd;
+
+ /* insert a new line buffer */
+ rtgui_edit_insert_line(edit, line, line->text + edit->upleft.x + edit->visual.x);
+ line->text[edit->upleft.x + edit->visual.x] = '\0';
+ line->len = rtgui_edit_line_strlen(line->text);
+
+ if ((edit->max_rows - edit->upleft.y) < edit->row_per_page)
+ {
+ int update_end_index = rtgui_edit_get_index_by_line(edit, edit->tail);
+ update_type = EDIT_UPDATE;
+ edit->update.start = edit->visual;
+ edit->update.end.x = edit->tail->len;
+ edit->update.end.y = update_end_index;
+ }
+ else
+ {
+ /* nothing */
+ /* it will be adjusted upleft.y when entering DOWN case */
+ }
+
+ /* move the caret to the next line head */
+ kbd_event_set_key(&event_kbd, RTGUIK_DOWN);
+ rtgui_edit_onkey(object, (rtgui_event_t *)&event_kbd);
+ kbd_event_set_key(&event_kbd, RTGUIK_HOME);
+ rtgui_edit_onkey(object, (rtgui_event_t *)&event_kbd);
+ /* adjust update line end position */
+ if ((edit->max_rows - edit->upleft.y) >= edit->row_per_page)
+ {
+ update_type = EDIT_UPDATE;
+ edit->update.start = edit->visual;
+ edit->update.start.y -= 1;
+ update_end_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + edit->row_per_page - 1);
- if((edit->max_rows-edit->upleft.y) < edit->row_per_page)
- {
- int update_end_index = rtgui_edit_get_index_by_line(edit, edit->tail);
- update_type = EDIT_UPDATE;
- edit->update.start = edit->visual;
- edit->update.end.x = edit->tail->len;
- edit->update.end.y = update_end_index;
- }
- else
- {
- /* nothing */
- /* it will be adjusted upleft.y when entering DOWN case */
- }
-
- /* move the caret to the next line head */
- kbd_event_set_key(&event_kbd, RTGUIK_DOWN);
- rtgui_edit_onkey(object, (rtgui_event_t*)&event_kbd);
- kbd_event_set_key(&event_kbd, RTGUIK_HOME);
- rtgui_edit_onkey(object, (rtgui_event_t*)&event_kbd);
- /* adjust update line end position */
- if((edit->max_rows-edit->upleft.y) >= edit->row_per_page)
- {
- update_type = EDIT_UPDATE;
- edit->update.start = edit->visual;
- edit->update.start.y -= 1;
- update_end_line = rtgui_edit_get_line_by_index(edit, edit->upleft.y+edit->row_per_page-1);
-
- if(update_end_line != RT_NULL)
- {
- edit->update.end.x = update_end_line->len;
- edit->update.end.y = edit->upleft.y + edit->row_per_page;
- }
- }
- }
- else
- {
- if(isprint((unsigned char)ekbd->key))
- { /* it's may print character */
- update_type = EDIT_UPDATE;
- edit->update.start = edit->visual;
-
- if(edit->flag & RTGUI_EDIT_SHIFT)
- ekbd->key = query_shift_code(ekbd->key);
- if(edit->flag & RTGUI_EDIT_CAPSLOCK)
- ekbd->key = query_caps_code(ekbd->key);
+ if (update_end_line != RT_NULL)
+ {
+ edit->update.end.x = update_end_line->len;
+ edit->update.end.y = edit->upleft.y + edit->row_per_page;
+ }
+ }
+ }
+ else
+ {
+ if (isprint((unsigned char)ekbd->key))
+ {
+ /* it's may print character */
+ update_type = EDIT_UPDATE;
+ edit->update.start = edit->visual;
- if(line->len < line->zsize-1)
- {
- int ofs = edit->upleft.x + edit->visual.x;
- if(edit->visual.x >= edit->col_per_page-1)
- {
- edit->upleft.x ++;
- update_type = EDIT_ONDRAW;
- }
+ if (edit->flag & RTGUI_EDIT_SHIFT)
+ ekbd->key = query_shift_code(ekbd->key);
+ if (edit->flag & RTGUI_EDIT_CAPSLOCK)
+ ekbd->key = query_caps_code(ekbd->key);
- if(ofs < line->len)
- {
- char* c;
- for(c = &line->text[line->len]; c != &line->text[ofs]; c--)
- *c = *(c-1);
- }
- line->text[ofs] = (char)ekbd->key;
- if(edit->visual.x < edit->col_per_page-1)
- edit->visual.x ++;
- line->text[line->len+1] = '\0';
- line->len = rtgui_edit_line_strlen(line->text);
- edit->update.end.x = line->len;
- if(edit->update.end.x > edit->col_per_page)
- edit->update.end.x = edit->col_per_page;
- edit->update.end.y = edit->visual.y;
- }
- else
- { /* adjust line buffer's zone size */
- line->zsize = rtgui_edit_alloc_len(edit->bzsize, line->len+1);
- line->text = rt_realloc(line->text, line->zsize);
- rtgui_edit_onkey(object, event); /* reentry */
- }
- }
- else
- {
- /* Is small keyboard ? */
- if(edit->flag & RTGUI_EDIT_NUMLOCK)
- {
- if(is_small_keyboard(&ekbd->key))
- rtgui_edit_onkey(object, event);
- /* small keyboard another value reserved */
- }
- }
- }
- line->len = rtgui_edit_line_strlen(line->text);
+ if (line->len < line->zsize - 1)
+ {
+ int ofs = edit->upleft.x + edit->visual.x;
+ if (edit->visual.x >= edit->col_per_page - 1)
+ {
+ edit->upleft.x ++;
+ update_type = EDIT_ONDRAW;
+ }
+
+ if (ofs < line->len)
+ {
+ char *c;
+ for (c = &line->text[line->len]; c != &line->text[ofs]; c--)
+ *c = *(c - 1);
+ }
+ line->text[ofs] = (char)ekbd->key;
+ if (edit->visual.x < edit->col_per_page - 1)
+ edit->visual.x ++;
+ line->text[line->len + 1] = '\0';
+ line->len = rtgui_edit_line_strlen(line->text);
+ edit->update.end.x = line->len;
+ if (edit->update.end.x > edit->col_per_page)
+ edit->update.end.x = edit->col_per_page;
+ edit->update.end.y = edit->visual.y;
+ }
+ else
+ {
+ /* adjust line buffer's zone size */
+ line->zsize = rtgui_edit_alloc_len(edit->bzsize, line->len + 1);
+ line->text = rt_realloc(line->text, line->zsize);
+ rtgui_edit_onkey(object, event); /* reentry */
+ }
+ }
+ else
+ {
+ /* Is small keyboard ? */
+ if (edit->flag & RTGUI_EDIT_NUMLOCK)
+ {
+ if (is_small_keyboard(&ekbd->key))
+ rtgui_edit_onkey(object, event);
+ /* small keyboard another value reserved */
+ }
+ }
+ }
+ line->len = rtgui_edit_line_strlen(line->text);
_edit_exit:
- if(edit->flag & RTGUI_EDIT_CARET)
- {
- if(edit->caret_timer != RT_NULL)
- rtgui_timer_stop(edit->caret_timer);
+ if (edit->flag & RTGUI_EDIT_CARET)
+ {
+ if (edit->caret_timer != RT_NULL)
+ rtgui_timer_stop(edit->caret_timer);
- edit->flag &= ~RTGUI_EDIT_CARET;
- rtgui_edit_draw_caret(edit);/* refresh it */
- if(edit->caret_timer != RT_NULL)
- rtgui_timer_start(edit->caret_timer);
- }
+ edit->flag &= ~RTGUI_EDIT_CARET;
+ rtgui_edit_draw_caret(edit);/* refresh it */
+ if (edit->caret_timer != RT_NULL)
+ rtgui_timer_start(edit->caret_timer);
+ }
- /* re-draw edit widget */
- if(update_type == EDIT_ONDRAW)
- rtgui_edit_ondraw(edit);
- else if(update_type == EDIT_UPDATE)
- rtgui_edit_update(edit);
+ /* re-draw edit widget */
+ if (update_type == EDIT_ONDRAW)
+ rtgui_edit_ondraw(edit);
+ else if (update_type == EDIT_UPDATE)
+ rtgui_edit_update(edit);
- if(RTGUI_WIDGET_IS_FOCUSED(edit))
- {
- rtgui_edit_init_caret(edit, edit->visual);
- edit->flag |= RTGUI_EDIT_CARET;
- rtgui_edit_draw_caret(edit);
- }
- return RT_TRUE;
+ if (RTGUI_WIDGET_IS_FOCUSED(edit))
+ {
+ rtgui_edit_init_caret(edit, edit->visual);
+ edit->flag |= RTGUI_EDIT_CARET;
+ rtgui_edit_draw_caret(edit);
+ }
+ return RT_TRUE;
}
-static rt_bool_t rtgui_edit_onfocus(struct rtgui_object* object, rtgui_event_t* event)
+static rt_bool_t rtgui_edit_onfocus(struct rtgui_object *object, rtgui_event_t *event)
{
- struct rtgui_edit* edit = RTGUI_EDIT(object);
+ struct rtgui_edit *edit = RTGUI_EDIT(object);
- edit->caret_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC,
- rtgui_edit_timeout, (void*)edit);
- /* set caret to show */
- edit->flag |= RTGUI_EDIT_CARET;
- /* start caret timer */
- if(edit->caret_timer != RT_NULL)
- rtgui_timer_start(edit->caret_timer);
+ edit->caret_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC,
+ rtgui_edit_timeout, (void *)edit);
+ /* set caret to show */
+ edit->flag |= RTGUI_EDIT_CARET;
+ /* start caret timer */
+ if (edit->caret_timer != RT_NULL)
+ rtgui_timer_start(edit->caret_timer);
- return RT_TRUE;
+ return RT_TRUE;
}
-static rt_bool_t rtgui_edit_onunfocus(struct rtgui_object* object, rtgui_event_t* event)
+static rt_bool_t rtgui_edit_onunfocus(struct rtgui_object *object, rtgui_event_t *event)
{
- struct rtgui_edit* edit = RTGUI_EDIT(object);
+ struct rtgui_edit *edit = RTGUI_EDIT(object);
+
+ /* stop caret timer */
+ if (edit->caret_timer != RT_NULL)
+ {
+ rtgui_timer_stop(edit->caret_timer);
+ rtgui_timer_destory(edit->caret_timer);
+ }
+ /* set caret to hide */
+ edit->flag &= ~RTGUI_EDIT_CARET;
+ rtgui_edit_draw_caret(edit);
- /* stop caret timer */
- if(edit->caret_timer != RT_NULL)
- {
- rtgui_timer_stop(edit->caret_timer);
- rtgui_timer_destory(edit->caret_timer);
- }
- /* set caret to hide */
- edit->flag &= ~RTGUI_EDIT_CARET;
- rtgui_edit_draw_caret(edit);
-
- return RT_TRUE;
+ return RT_TRUE;
}
#ifdef RTGUI_EDIT_USING_SCROLL
-static rt_bool_t rtgui_edit_hscroll_handle(struct rtgui_widget* widget, rtgui_event_t* event)
+static rt_bool_t rtgui_edit_hscroll_handle(struct rtgui_widget *widget, rtgui_event_t *event)
{
- struct rtgui_edit *edit = RTGUI_EDIT(widget);
+ struct rtgui_edit *edit = RTGUI_EDIT(widget);
- /* adjust first display row when dragging */
- edit->upleft.y = edit->hscroll->value;
+ /* adjust first display row when dragging */
+ edit->upleft.y = edit->hscroll->value;
- rtgui_edit_ondraw(edit);
+ rtgui_edit_ondraw(edit);
- return RT_TRUE;
+ return RT_TRUE;
}
-static rt_bool_t rtgui_edit_vscroll_handle(struct rtgui_widget* widget, rtgui_event_t* event)
+static rt_bool_t rtgui_edit_vscroll_handle(struct rtgui_widget *widget, rtgui_event_t *event)
{
- struct rtgui_edit *edit = RTGUI_EDIT(widget);
+ struct rtgui_edit *edit = RTGUI_EDIT(widget);
- /* adjust first display row when dragging */
- edit->upleft.x = edit->vscroll->value;
+ /* adjust first display row when dragging */
+ edit->upleft.x = edit->vscroll->value;
- rtgui_edit_ondraw(edit);
+ rtgui_edit_ondraw(edit);
- return RT_TRUE;
+ return RT_TRUE;
}
#endif
/* local area update */
void rtgui_edit_update(struct rtgui_edit *edit)
{
- rt_int16_t i,cpy_len=0,prev_len;
- rtgui_rect_t rect, r;
- struct rtgui_dc *dc;
- char *src;
-
- RT_ASSERT(edit != RT_NULL);
-
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(edit));
- if(dc == RT_NULL) return;
-
- rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
- rtgui_rect_inflate(&rect, -(edit->margin + RTGUI_WIDGET_BORDER(edit)));
+ rt_int16_t i, cpy_len = 0, prev_len;
+ rtgui_rect_t rect, r;
+ struct rtgui_dc *dc;
+ char *src;
+
+ RT_ASSERT(edit != RT_NULL);
+
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(edit));
+ if (dc == RT_NULL) return;
+
+ rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
+ rtgui_rect_inflate(&rect, -(edit->margin + RTGUI_WIDGET_BORDER(edit)));
+
+ if (edit->update_buf == RT_NULL)
+ {
+ /* try again allocate */
+ edit->update_buf = rtgui_malloc(edit->col_per_page + 1);
+ }
+
+ prev_len = edit->col_per_page;
+ for (i = edit->update.start.y; i <= edit->update.end.y; i++)
+ {
+ struct edit_line *line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + i);
- if(edit->update_buf == RT_NULL)
- { /* try again allocate */
- edit->update_buf = rtgui_malloc(edit->col_per_page+1);
- }
-
- prev_len = edit->col_per_page;
- for(i=edit->update.start.y; i<=edit->update.end.y; i++)
- {
- struct edit_line *line = rtgui_edit_get_line_by_index(edit, edit->upleft.y + i);
+ if (i > edit->upleft.y + edit->row_per_page) break;
+ if (line == RT_NULL)
+ {
+ /* when use "RTGUIK_BACKSPACE" backspace forward,
+ * the last line is blank, that only fill background. */
+ r.x1 = rect.x1;
+ r.x2 = rect.x1 + prev_len * edit->font_width;
+ r.y1 = rect.y1 + i * edit->font_height;
+ r.y2 = r.y1 + edit->font_height;
+ if (r.x2 > rect.x2) r.x2 = rect.x2;
+ if (r.y2 > rect.y2) r.y2 = rect.y2;
+ rtgui_dc_fill_rect(dc, &r);
+ break;
+ }
- if(i > edit->upleft.y+edit->row_per_page) break;
- if(line == RT_NULL)
- { /* when use "RTGUIK_BACKSPACE" backspace forward,
- * the last line is blank, that only fill background. */
- r.x1 = rect.x1;
- r.x2 = rect.x1 + prev_len * edit->font_width;
- r.y1 = rect.y1 + i * edit->font_height;
- r.y2 = r.y1 + edit->font_height;
- if(r.x2 > rect.x2) r.x2 = rect.x2;
- if(r.y2 > rect.y2) r.y2 = rect.y2;
- rtgui_dc_fill_rect(dc, &r);
- break;
- }
-
- if(edit->update.start.y == edit->update.end.y)
- {
- r.x1 = rect.x1 + edit->update.start.x * edit->font_width;
- r.x2 = rect.x1 + edit->update.end.x * edit->font_width;
- r.y1 = rect.y1 + i * edit->font_height;
- r.y2 = r.y1 + edit->font_height;
- cpy_len = edit->update.end.x - edit->update.start.x;
- src = line->text + edit->update.start.x + edit->upleft.x;
- }
- else
- {
- if(i == edit->update.start.y)
- {
- r.x1 = rect.x1 + edit->update.start.x * edit->font_width;
- r.x2 = rect.x2;
- r.y1 = rect.y1 + i * edit->font_height;
- r.y2 = r.y1 + edit->font_height;
- cpy_len = line->len - edit->update.start.x - edit->upleft.x;
- if(cpy_len > (edit->col_per_page-edit->update.start.x))
- cpy_len = edit->col_per_page-edit->update.start.x;
- src = line->text + edit->update.start.x + edit->upleft.x;
- }
- else if(i == edit->update.end.y)
- {
- r.x1 = rect.x1;
- r.x2 = rect.x1 + edit->update.end.x * edit->font_width;
- cpy_len = edit->update.end.x;
- r.y1 = rect.y1 + i * edit->font_height;
- r.y2 = r.y1 + edit->font_height;
- src = line->text + edit->upleft.x;
- }
- else
- {
- r.x1 = rect.x1;
- r.x2 = rect.x2;
- r.y1 = rect.y1 + i * edit->font_height;
- r.y2 = r.y1 + edit->font_height;
- cpy_len = line->len - edit->upleft.x;
- if(cpy_len > edit->col_per_page)
- cpy_len = edit->col_per_page;
- src = line->text + edit->upleft.x;
- }
- }
- if(r.y1 > rect.y2) break;
- if(r.x2 > rect.x2) r.x2 = rect.x2;
- if(r.y2 > rect.y2) r.y2 = rect.y2;
-
- rt_memcpy(edit->update_buf, src, cpy_len);
- *(edit->update_buf + cpy_len) = '\0';
-
- rtgui_dc_fill_rect(dc, &r);
- rtgui_dc_draw_text(dc, edit->update_buf, &r);
- prev_len = line->len;
- }
-
- rtgui_dc_end_drawing(dc);
+ if (edit->update.start.y == edit->update.end.y)
+ {
+ r.x1 = rect.x1 + edit->update.start.x * edit->font_width;
+ r.x2 = rect.x1 + edit->update.end.x * edit->font_width;
+ r.y1 = rect.y1 + i * edit->font_height;
+ r.y2 = r.y1 + edit->font_height;
+ cpy_len = edit->update.end.x - edit->update.start.x;
+ src = line->text + edit->update.start.x + edit->upleft.x;
+ }
+ else
+ {
+ if (i == edit->update.start.y)
+ {
+ r.x1 = rect.x1 + edit->update.start.x * edit->font_width;
+ r.x2 = rect.x2;
+ r.y1 = rect.y1 + i * edit->font_height;
+ r.y2 = r.y1 + edit->font_height;
+ cpy_len = line->len - edit->update.start.x - edit->upleft.x;
+ if (cpy_len > (edit->col_per_page - edit->update.start.x))
+ cpy_len = edit->col_per_page - edit->update.start.x;
+ src = line->text + edit->update.start.x + edit->upleft.x;
+ }
+ else if (i == edit->update.end.y)
+ {
+ r.x1 = rect.x1;
+ r.x2 = rect.x1 + edit->update.end.x * edit->font_width;
+ cpy_len = edit->update.end.x;
+ r.y1 = rect.y1 + i * edit->font_height;
+ r.y2 = r.y1 + edit->font_height;
+ src = line->text + edit->upleft.x;
+ }
+ else
+ {
+ r.x1 = rect.x1;
+ r.x2 = rect.x2;
+ r.y1 = rect.y1 + i * edit->font_height;
+ r.y2 = r.y1 + edit->font_height;
+ cpy_len = line->len - edit->upleft.x;
+ if (cpy_len > edit->col_per_page)
+ cpy_len = edit->col_per_page;
+ src = line->text + edit->upleft.x;
+ }
+ }
+ if (r.y1 > rect.y2) break;
+ if (r.x2 > rect.x2) r.x2 = rect.x2;
+ if (r.y2 > rect.y2) r.y2 = rect.y2;
+
+ rt_memcpy(edit->update_buf, src, cpy_len);
+ *(edit->update_buf + cpy_len) = '\0';
+
+ rtgui_dc_fill_rect(dc, &r);
+ rtgui_dc_draw_text(dc, edit->update_buf, &r);
+ prev_len = line->len;
+ }
+
+ rtgui_dc_end_drawing(dc);
}
void rtgui_edit_ondraw(struct rtgui_edit *edit)
{
- rtgui_rect_t rect, r;
- struct rtgui_dc *dc;
+ rtgui_rect_t rect, r;
+ struct rtgui_dc *dc;
#ifdef RTGUI_EDIT_USING_SCROLL
- int hscroll_flag=0;
- int vscroll_flag=0;
+ int hscroll_flag = 0;
+ int vscroll_flag = 0;
#endif
- RT_ASSERT(edit != RT_NULL);
+ RT_ASSERT(edit != RT_NULL);
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(edit));
- if(dc == RT_NULL) return;
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(edit));
+ if (dc == RT_NULL) return;
- /* get widget rect */
- rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
- rtgui_rect_inflate(&rect, -RTGUI_WIDGET_BORDER(edit));
+ /* get widget rect */
+ rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
+ rtgui_rect_inflate(&rect, -RTGUI_WIDGET_BORDER(edit));
- /* fill widget rect with edit background color */
- RTGUI_DC_BC(dc) = RTGUI_WIDGET_BACKGROUND(edit);
- rtgui_dc_fill_rect(dc, &rect);
+ /* fill widget rect with edit background color */
+ RTGUI_DC_BC(dc) = RTGUI_WIDGET_BACKGROUND(edit);
+ rtgui_dc_fill_rect(dc, &rect);
- rtgui_rect_inflate(&rect, RTGUI_WIDGET_BORDER(edit));
- /* draw border */
- rtgui_dc_draw_border(dc, &rect, RTGUI_WIDGET_BORDER_STYLE(edit));
+ rtgui_rect_inflate(&rect, RTGUI_WIDGET_BORDER(edit));
+ /* draw border */
+ rtgui_dc_draw_border(dc, &rect, RTGUI_WIDGET_BORDER_STYLE(edit));
- rtgui_rect_inflate(&rect, -(edit->margin + RTGUI_WIDGET_BORDER(edit)));
+ rtgui_rect_inflate(&rect, -(edit->margin + RTGUI_WIDGET_BORDER(edit)));
#ifdef RTGUI_EDIT_USING_SCROLL
- if(edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit->vscroll))
- {
- rect.x2 = rect.x2 - rtgui_rect_width(edit->vscroll->parent.extent);
- }
- if(edit->hscroll && !RTGUI_WIDGET_IS_HIDE(edit->hscroll))
- {
- rect.y2 = rect.y2 - rtgui_rect_height(edit->hscroll->parent.extent);
- }
+ if (edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit->vscroll))
+ {
+ rect.x2 = rect.x2 - rtgui_rect_width(edit->vscroll->parent.extent);
+ }
+ if (edit->hscroll && !RTGUI_WIDGET_IS_HIDE(edit->hscroll))
+ {
+ rect.y2 = rect.y2 - rtgui_rect_height(edit->hscroll->parent.extent);
+ }
#endif
- r = rect;
-
- /* draw text */
- if(edit->head != RT_NULL)
- {
- struct edit_line *line = edit->first_line;
- int num=0;
-
- rect.y2 = rect.y1 + edit->item_height;
- while(line)
- {
- rt_int16_t tmp_pos=0, ofs;
- char *str = line->text+edit->upleft.x;
+ r = rect;
+
+ /* draw text */
+ if (edit->head != RT_NULL)
+ {
+ struct edit_line *line = edit->first_line;
+ int num = 0;
+
+ rect.y2 = rect.y1 + edit->item_height;
+ while (line)
+ {
+ rt_int16_t tmp_pos = 0, ofs;
+ char *str = line->text + edit->upleft.x;
+
+ if (edit->upleft.x < line->len)
+ {
+ rtgui_point_t p = edit->visual; /* backup */
+ edit->visual.x = 0;
+ identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
+ ofs = tmp_pos % 2;
+ if (ofs == 1)
+ {
+ /* use dc_buffer draw the left half of double byte */
+ char dbl_bmp[3];
+ rtgui_point_t pot = {0};
+ rtgui_rect_t r = {0};
+
+ pot.x = edit->font_width;
+ r.x2 = edit->font_width * 2;
+ r.y2 = edit->font_height;
+ dbl_bmp[0] = *(str - 1);
+ dbl_bmp[1] = *str;
+ dbl_bmp[2] = '\0';
+ RTGUI_DC_BC(edit->dbl_buf) = RTGUI_WIDGET_BACKGROUND(edit);
+ rtgui_dc_fill_rect(edit->dbl_buf, &r);
+ RTGUI_DC_FC(edit->dbl_buf) = RTGUI_WIDGET_FOREGROUND(edit);
+ rtgui_dc_draw_text(edit->dbl_buf, dbl_bmp, &r);
+ rtgui_dc_blit(edit->dbl_buf, &pot, dc, &rect);
+ }
+ rect.x1 += ofs * edit->font_width;
+ rtgui_dc_draw_text(dc, line->text + edit->upleft.x + ofs, &rect);
+ rect.x1 -= ofs * edit->font_width;
+ edit->visual = p; /* restore */
+ }
- if(edit->upleft.x < line->len)
- {
- rtgui_point_t p = edit->visual; /* backup */
- edit->visual.x = 0;
- identify_double_byte(edit, line, EDIT_IDENT_DIR_LEFT, &tmp_pos);
- ofs = tmp_pos % 2;
- if(ofs == 1)
- { /* use dc_buffer draw the left half of double byte */
- char dbl_bmp[3];
- rtgui_point_t pot = {0};
- rtgui_rect_t r = {0};
+ line = line->next;
- pot.x = edit->font_width;
- r.x2 = edit->font_width*2;
- r.y2 = edit->font_height;
- dbl_bmp[0] = *(str-1);
- dbl_bmp[1] = *str;
- dbl_bmp[2] = '\0';
- RTGUI_DC_BC(edit->dbl_buf) = RTGUI_WIDGET_BACKGROUND(edit);
- rtgui_dc_fill_rect(edit->dbl_buf, &r);
- RTGUI_DC_FC(edit->dbl_buf) = RTGUI_WIDGET_FOREGROUND(edit);
- rtgui_dc_draw_text(edit->dbl_buf, dbl_bmp, &r);
- rtgui_dc_blit(edit->dbl_buf, &pot, dc, &rect);
- }
- rect.x1 += ofs * edit->font_width;
- rtgui_dc_draw_text(dc, line->text+edit->upleft.x+ofs, &rect);
- rect.x1 -= ofs * edit->font_width;
- edit->visual = p; /* restore */
- }
+ rect.y1 += edit->item_height;
+ if ((rect.y1 + edit->item_height) < r.y2)
+ rect.y2 = rect.y1 + edit->item_height;
+ else
+ rect.y2 = r.y2;
- line = line->next;
-
- rect.y1 += edit->item_height;
- if((rect.y1 + edit->item_height) < r.y2)
- rect.y2 = rect.y1 + edit->item_height;
- else
- rect.y2 = r.y2;
-
- if(num++ >= edit->row_per_page)
- break;
- }
- }
+ if (num++ >= edit->row_per_page)
+ break;
+ }
+ }
#ifdef RTGUI_EDIT_USING_SCROLL
- if(edit->hscroll && !RTGUI_WIDGET_IS_HIDE(edit->hscroll))
- {
- hscroll_flag = 1;
- rtgui_scrollbar_ondraw(edit->hscroll);
- }
- if(edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit->vscroll))
- {
- vscroll_flag = 1;
- rtgui_scrollbar_ondraw(edit->vscroll);
- }
+ if (edit->hscroll && !RTGUI_WIDGET_IS_HIDE(edit->hscroll))
+ {
+ hscroll_flag = 1;
+ rtgui_scrollbar_ondraw(edit->hscroll);
+ }
+ if (edit->vscroll && !RTGUI_WIDGET_IS_HIDE(edit->vscroll))
+ {
+ vscroll_flag = 1;
+ rtgui_scrollbar_ondraw(edit->vscroll);
+ }
- if(hscroll_flag && vscroll_flag)
- {
- rtgui_color_t _bc;
- rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
- rect.x1 = rect.x2-RTGUI_WIDGET_BORDER(edit);
- rect.y1 = rect.y2-RTGUI_WIDGET_BORDER(edit);
- _bc = RTGUI_DC_BC(dc);
- RTGUI_DC_BC(dc) = default_background;
- rtgui_dc_fill_rect(dc,&rect);
- RTGUI_DC_BC(dc) = _bc;
- }
+ if (hscroll_flag && vscroll_flag)
+ {
+ rtgui_color_t _bc;
+ rtgui_widget_get_rect(RTGUI_WIDGET(edit), &rect);
+ rect.x1 = rect.x2 - RTGUI_WIDGET_BORDER(edit);
+ rect.y1 = rect.y2 - RTGUI_WIDGET_BORDER(edit);
+ _bc = RTGUI_DC_BC(dc);
+ RTGUI_DC_BC(dc) = default_background;
+ rtgui_dc_fill_rect(dc, &rect);
+ RTGUI_DC_BC(dc) = _bc;
+ }
#endif
- rtgui_dc_end_drawing(dc);
+ rtgui_dc_end_drawing(dc);
}
/* set edit text */
-void rtgui_edit_set_text(struct rtgui_edit* edit, const char* text)
+void rtgui_edit_set_text(struct rtgui_edit *edit, const char *text)
{
- const char *begin, *ptr;
+ const char *begin, *ptr;
#ifdef RTGUI_EDIT_USING_SCROLL
- int hscroll_flag=0;
- int vscroll_flag=0;
+ int hscroll_flag = 0;
+ int vscroll_flag = 0;
#endif
- RT_ASSERT(edit != RT_NULL);
+ RT_ASSERT(edit != RT_NULL);
- while(edit->max_rows > 0)
- rtgui_edit_delete_line(edit, edit->head);
- edit->max_rows = 0;
+ while (edit->max_rows > 0)
+ rtgui_edit_delete_line(edit, edit->head);
+ edit->max_rows = 0;
+
+ begin = text;
+ for (ptr = begin; *ptr != '\0'; ptr++)
+ {
+ if (*ptr == 0x0A)
+ {
+ /* unix style */
+ rtgui_edit_append_line(edit, begin);
+ begin = ptr + 1;
+ }
+ else if (*ptr == 0x0D && *(ptr + 1) == 0x0A)
+ {
+ /* windows style */
+ rtgui_edit_append_line(edit, begin);
+ begin = ptr + 2;
+ }
+ }
+ if (*ptr == '\0')
+ {
+ if (begin < ptr)
+ rtgui_edit_append_line(edit, begin);
+ }
- begin = text;
- for(ptr=begin; *ptr != '\0'; ptr++)
- {
- if(*ptr == 0x0A)
- { /* unix style */
- rtgui_edit_append_line(edit, begin);
- begin = ptr+1;
- }
- else if(*ptr == 0x0D && *(ptr+1) == 0x0A)
- { /* windows style */
- rtgui_edit_append_line(edit, begin);
- begin = ptr+2;
- }
- }
- if(*ptr == '\0')
- {
- if(begin < ptr)
- rtgui_edit_append_line(edit, begin);
- }
-
#ifdef RTGUI_EDIT_USING_SCROLL
- if(edit->hscroll != RT_NULL)
- {
- if(edit->max_cols > edit->col_per_page)
- {
- RTGUI_WIDGET_SHOW(edit->hscroll);
- rtgui_scrollbar_set_line_step(edit->hscroll, 1);
- rtgui_scrollbar_set_page_step(edit->hscroll, edit->col_per_page);
- rtgui_scrollbar_set_range(edit->hscroll, edit->max_cols);
- hscroll_flag = 1;
- }
- else
- {
- RTGUI_WIDGET_HIDE(edit->hscroll);
- }
- }
- if(edit->vscroll != RT_NULL)
- {
- if(edit->max_rows > edit->row_per_page)
- {
- RTGUI_WIDGET_SHOW(edit->vscroll);
- rtgui_scrollbar_set_line_step(edit->vscroll, 1);
- rtgui_scrollbar_set_page_step(edit->vscroll, edit->row_per_page);
- rtgui_scrollbar_set_range(edit->vscroll, edit->max_rows);
- vscroll_flag = 1;
- }
- else
- {
- RTGUI_WIDGET_HIDE(edit->vscroll);
- }
- }
+ if (edit->hscroll != RT_NULL)
+ {
+ if (edit->max_cols > edit->col_per_page)
+ {
+ RTGUI_WIDGET_SHOW(edit->hscroll);
+ rtgui_scrollbar_set_line_step(edit->hscroll, 1);
+ rtgui_scrollbar_set_page_step(edit->hscroll, edit->col_per_page);
+ rtgui_scrollbar_set_range(edit->hscroll, edit->max_cols);
+ hscroll_flag = 1;
+ }
+ else
+ {
+ RTGUI_WIDGET_HIDE(edit->hscroll);
+ }
+ }
+ if (edit->vscroll != RT_NULL)
+ {
+ if (edit->max_rows > edit->row_per_page)
+ {
+ RTGUI_WIDGET_SHOW(edit->vscroll);
+ rtgui_scrollbar_set_line_step(edit->vscroll, 1);
+ rtgui_scrollbar_set_page_step(edit->vscroll, edit->row_per_page);
+ rtgui_scrollbar_set_range(edit->vscroll, edit->max_rows);
+ vscroll_flag = 1;
+ }
+ else
+ {
+ RTGUI_WIDGET_HIDE(edit->vscroll);
+ }
+ }
- if(edit->hscroll != RT_NULL && !RTGUI_WIDGET_IS_HIDE(edit->hscroll))
- {
- rtgui_edit_adjust_scroll(edit->hscroll);
- }
- if(edit->vscroll != RT_NULL && !RTGUI_WIDGET_IS_HIDE(edit->vscroll))
- {
- rtgui_edit_adjust_scroll(edit->vscroll);
- }
+ if (edit->hscroll != RT_NULL && !RTGUI_WIDGET_IS_HIDE(edit->hscroll))
+ {
+ rtgui_edit_adjust_scroll(edit->hscroll);
+ }
+ if (edit->vscroll != RT_NULL && !RTGUI_WIDGET_IS_HIDE(edit->vscroll))
+ {
+ rtgui_edit_adjust_scroll(edit->vscroll);
+ }
- if(hscroll_flag || vscroll_flag)
- {
- rtgui_widget_update_clip(RTGUI_WIDGET(edit));
- }
+ if (hscroll_flag || vscroll_flag)
+ {
+ rtgui_widget_update_clip(RTGUI_WIDGET(edit));
+ }
#endif
}
-rt_bool_t rtgui_edit_event_handler(struct rtgui_object* object, rtgui_event_t* event)
+rt_bool_t rtgui_edit_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
- rtgui_widget_t *widget = RTGUI_WIDGET(object);
- struct rtgui_edit* edit = RTGUI_EDIT(object);
+ rtgui_widget_t *widget = RTGUI_WIDGET(object);
+ struct rtgui_edit *edit = RTGUI_EDIT(object);
- switch(event->type)
- {
- case RTGUI_EVENT_PAINT:
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
- if(widget->on_draw != RT_NULL)
- widget->on_draw(object, event);
- else
+ if (widget->on_draw != RT_NULL)
+ widget->on_draw(object, event);
+ else
#endif
- rtgui_edit_ondraw(edit);
- break;
+ rtgui_edit_ondraw(edit);
+ break;
- case RTGUI_EVENT_MOUSE_BUTTON:
+ case RTGUI_EVENT_MOUSE_BUTTON:
#ifndef RTGUI_USING_SMALL_SIZE
- if(widget->on_mouseclick != RT_NULL)
- widget->on_mouseclick(object, event);
- else
+ if (widget->on_mouseclick != RT_NULL)
+ widget->on_mouseclick(object, event);
+ else
#endif
- rtgui_edit_onmouse(edit, (struct rtgui_event_mouse*)event);
- return RT_TRUE;
+ rtgui_edit_onmouse(edit, (struct rtgui_event_mouse *)event);
+ return RT_TRUE;
- case RTGUI_EVENT_KBD:
+ case RTGUI_EVENT_KBD:
#ifndef RTGUI_USING_SMALL_SIZE
- if(widget->on_key != RT_NULL)
- widget->on_key(object, event);
- else
+ if (widget->on_key != RT_NULL)
+ widget->on_key(object, event);
+ else
#endif
- rtgui_edit_onkey(object, event);
- return RT_TRUE;
+ rtgui_edit_onkey(object, event);
+ return RT_TRUE;
- default:
- return rtgui_widget_event_handler(object, event);
- }
+ default:
+ return rtgui_widget_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
rtgui_point_t rtgui_edit_get_current_point(struct rtgui_edit *edit)
{
- rtgui_point_t p;
+ rtgui_point_t p;
- RT_ASSERT(edit != RT_NULL);
+ RT_ASSERT(edit != RT_NULL);
- p.x = edit->upleft.x + edit->visual.x;
- p.y = edit->upleft.y + edit->visual.y;
+ p.x = edit->upleft.x + edit->visual.x;
+ p.y = edit->upleft.y + edit->visual.y;
- return p;
+ return p;
}
rt_uint32_t rtgui_edit_get_mem_consume(struct rtgui_edit *edit)
{
- rt_uint32_t mem_size;
- struct edit_line *line;
+ rt_uint32_t mem_size;
+ struct edit_line *line;
- mem_size = sizeof(struct rtgui_edit);
- mem_size += edit->col_per_page + 1; /* update_buf */
- if(edit->head != RT_NULL)
- {
- line = edit->head;
- while(line)
- {
- mem_size += line->zsize;
- mem_size += sizeof(struct edit_line);
- line = line->next;
- }
- }
+ mem_size = sizeof(struct rtgui_edit);
+ mem_size += edit->col_per_page + 1; /* update_buf */
+ if (edit->head != RT_NULL)
+ {
+ line = edit->head;
+ while (line)
+ {
+ mem_size += line->zsize;
+ mem_size += sizeof(struct edit_line);
+ line = line->next;
+ }
+ }
- return mem_size;
+ return mem_size;
}
#ifdef RTGUI_USING_DFS_FILERW
-/**
+/**
* File access component, General File Access Interface
*/
rt_bool_t rtgui_edit_readin_file(struct rtgui_edit *edit, const char *filename)
{
- struct rtgui_filerw *filerw;
- int num=0, read_bytes, size ,len=0;
- char *text ,ch;
+ struct rtgui_filerw *filerw;
+ int num = 0, read_bytes, size , len = 0;
+ char *text , ch;
+
+ filerw = rtgui_filerw_create_file(filename, "rb");
+ if (filerw == RT_NULL) return RT_FALSE;
+ /**
+ * If it was in the debug of the win32, If document encode is UTF-8 or Unicode,
+ * Will read to garbled code when using the function read documents.
+ * You can Change of the document contains the source code for ANSI.
+ */
+ while (edit->max_rows > 0)
+ rtgui_edit_delete_line(edit, edit->head);
+ edit->max_rows = 0;
+
+ size = edit->bzsize;
+ text = rtgui_malloc(size);
+ if (text == RT_NULL) return RT_FALSE;
- filerw = rtgui_filerw_create_file(filename, "rb");
- if (filerw == RT_NULL) return RT_FALSE;
- /**
- * If it was in the debug of the win32, If document encode is UTF-8 or Unicode,
- * Will read to garbled code when using the function read documents.
- * You can Change of the document contains the source code for ANSI.
- */
- while(edit->max_rows > 0)
- rtgui_edit_delete_line(edit, edit->head);
- edit->max_rows = 0;
+ do
+ {
+ if ((read_bytes = rtgui_filerw_read(filerw, &ch, 1, 1)) > 0)
+ {
+ /* rt_kprintf("ch=%02X ",ch); DEBUG */
+ if (num >= size - 1)
+ text = rt_realloc(text, rtgui_edit_alloc_len(size, num));
+ if (ch == 0x09) //Tab
+ {
+ len = edit->tabsize - num % edit->tabsize;
+ while (len--)
+ *(text + num++) = ' ';
+ }
+ else
+ *(text + num++) = ch;
+ if (ch == 0x0A)
+ {
+ rtgui_edit_append_line(edit, text);
+ num = 0;
+ }
- size = edit->bzsize;
- text = rtgui_malloc(size);
- if(text == RT_NULL) return RT_FALSE;
-
- do {
- if ( (read_bytes = rtgui_filerw_read(filerw, &ch, 1, 1)) > 0 )
- { /* rt_kprintf("ch=%02X ",ch); DEBUG */
- if(num >= size - 1)
- text = rt_realloc(text, rtgui_edit_alloc_len(size, num));
- if(ch == 0x09) //Tab
- {
- len = edit->tabsize - num%edit->tabsize;
- while(len--)
- *(text + num++) = ' ';
- }
- else
- *(text + num++) = ch;
- if(ch == 0x0A)
- {
- rtgui_edit_append_line(edit, text);
- num = 0;
- }
-
- }
- else if(num > 0)
- { /* last line does not exist the end operator */
- *(text + num) = '\0';
- rtgui_edit_append_line(edit, text);
- }
- } while(read_bytes);
-
- rtgui_filerw_close(filerw);
- rtgui_free(text);
- rtgui_edit_ondraw(edit);
+ }
+ else if (num > 0)
+ {
+ /* last line does not exist the end operator */
+ *(text + num) = '\0';
+ rtgui_edit_append_line(edit, text);
+ }
+ }
+ while (read_bytes);
- return RT_TRUE;
+ rtgui_filerw_close(filerw);
+ rtgui_free(text);
+ rtgui_edit_ondraw(edit);
+
+ return RT_TRUE;
}
rt_bool_t rtgui_edit_saveas_file(struct rtgui_edit *edit, const char *filename)
{
- struct rtgui_filerw *filerw;
- char ch_tailed = 0x0A;
- struct edit_line *line;
+ struct rtgui_filerw *filerw;
+ char ch_tailed = 0x0A;
+ struct edit_line *line;
+
+ filerw = rtgui_filerw_create_file(filename, "wb");
+ if (filerw == RT_NULL) return RT_FALSE;
+
+ line = edit->head;
+ while (line)
+ {
+ rtgui_filerw_write(filerw, line->text, line->len, 1);
+ if (line != edit->tail)
+ rtgui_filerw_write(filerw, &ch_tailed, 1, 1);
+ line = line->next;
+ }
- filerw = rtgui_filerw_create_file(filename, "wb");
- if (filerw == RT_NULL) return RT_FALSE;
-
- line = edit->head;
- while(line)
- {
- rtgui_filerw_write(filerw, line->text, line->len, 1);
- if(line != edit->tail)
- rtgui_filerw_write(filerw, &ch_tailed, 1, 1);
- line = line->next;
- }
-
- rtgui_filerw_close(filerw);
+ rtgui_filerw_close(filerw);
- return RT_TRUE;
+ return RT_TRUE;
}
#endif
diff --git a/components/rtgui/widgets/filelist_view.c b/components/rtgui/widgets/filelist_view.c
index 612abe5ae4..effb42c251 100644
--- a/components/rtgui/widgets/filelist_view.c
+++ b/components/rtgui/widgets/filelist_view.c
@@ -25,699 +25,709 @@
#include <rtgui/widgets/window.h>
#if defined(RTGUI_USING_DFS_FILERW)
-#ifdef _WIN32
+#ifdef _WIN32_NATIVE
#include <io.h>
#include <dirent.h>
#include <sys/stat.h>
-#define PATH_SEPARATOR '\\'
+#define PATH_SEPARATOR '\\'
#else
#include <dfs_posix.h>
-#define PATH_SEPARATOR '/'
+#define PATH_SEPARATOR '/'
#endif
#include <string.h>
-#define RTGUI_FILELIST_MARGIN 5
+#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 *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 ` ",
-" ...+.@.#.$.%.&.*.=.-.;.>. . ",
-" ,.'.).!.~.{.].^./.(._.:.<.,. ",
-" [.}.[.[.[.[.[.[.[.[.}.[.|. ",
-" ",
-" "};
+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 struct rtgui_listbox_item items[] =
{
#ifdef RTGUI_USING_FONTHZ
- {"���ː`����", RT_NULL},
- {"���v�`����", RT_NULL},
- {"�X��", RT_NULL}
+ {"���ː`����", RT_NULL},
+ {"���v�`����", RT_NULL},
+ {"�X��", RT_NULL}
#else
- {"Open folder", RT_NULL},
- {"Select folder", RT_NULL},
- {"Cancel", RT_NULL}
+ {"Open folder", RT_NULL},
+ {"Select folder", RT_NULL},
+ {"Cancel", RT_NULL}
#endif
};
-static void rtgui_filelist_view_clear(rtgui_filelist_view_t* view);
+static void rtgui_filelist_view_clear(rtgui_filelist_view_t *view);
-static rt_bool_t rtgui_filelist_view_on_folder_item(rtgui_object_t* object, struct rtgui_event* event)
+static rt_bool_t rtgui_filelist_view_on_folder_item(rtgui_object_t *object, struct rtgui_event *event)
{
- rtgui_win_t *menu;
- rtgui_listbox_t *listbox;
- rtgui_filelist_view_t *view;
+ rtgui_win_t *menu;
+ rtgui_listbox_t *listbox;
+ rtgui_filelist_view_t *view;
- listbox = RTGUI_LISTBOX(object);
- menu = RTGUI_WIN(rtgui_widget_get_toplevel(RTGUI_WIDGET(object)));
- view = RTGUI_FILELIST_VIEW(menu->user_data);
+ listbox = RTGUI_LISTBOX(object);
+ menu = RTGUI_WIN(rtgui_widget_get_toplevel(RTGUI_WIDGET(object)));
+ view = RTGUI_FILELIST_VIEW(menu->user_data);
- /* hide window */
- rtgui_win_hiden(menu);
+ /* hide window */
+ rtgui_win_hiden(menu);
- switch (listbox->current_item)
- {
- case 0:
- {
- char* dir_ptr;
+ switch (listbox->current_item)
+ {
+ case 0:
+ {
+ char *dir_ptr;
- /* destroy menu window */
- rtgui_win_destroy(menu);
+ /* destroy menu window */
+ rtgui_win_destroy(menu);
- dir_ptr = (char*) rtgui_malloc (256);
- rtgui_filelist_view_get_fullpath(view, dir_ptr, 256);
- rtgui_filelist_view_set_directory(view, dir_ptr);
- rtgui_free(dir_ptr);
- }
- break;
- case 1:
- /* destroy menu window */
- rtgui_win_destroy(menu);
- break;
+ dir_ptr = (char *) rtgui_malloc(256);
+ rtgui_filelist_view_get_fullpath(view, dir_ptr, 256);
+ rtgui_filelist_view_set_directory(view, dir_ptr);
+ rtgui_free(dir_ptr);
+ }
+ break;
+ case 1:
+ /* destroy menu window */
+ rtgui_win_destroy(menu);
+ break;
- default:
- /* destroy menu window */
- rtgui_win_destroy(menu);
- break;
- }
+ default:
+ /* destroy menu window */
+ rtgui_win_destroy(menu);
+ break;
+ }
- return RT_TRUE;
+ return RT_TRUE;
}
-static rt_bool_t rtgui_filelist_view_on_menu_deactivate(rtgui_object_t* object, struct rtgui_event* event)
+static rt_bool_t rtgui_filelist_view_on_menu_deactivate(rtgui_object_t *object, struct rtgui_event *event)
{
- rtgui_win_t *menu;
- menu = RTGUI_WIN(rtgui_widget_get_toplevel(RTGUI_WIDGET(object)));
+ rtgui_win_t *menu;
+ menu = RTGUI_WIN(rtgui_widget_get_toplevel(RTGUI_WIDGET(object)));
- /* destroy menu window */
- rtgui_win_destroy(menu);
+ /* destroy menu window */
+ rtgui_win_destroy(menu);
- return RT_TRUE;
+ return RT_TRUE;
}
static void rtgui_filelist_view_menu_pop(rtgui_widget_t *parent)
{
- rtgui_win_t *menu;
- rtgui_listbox_t *listbox;
- rtgui_rect_t screen, rect = {0, 0, 140, 85};
+ rtgui_win_t *menu;
+ rtgui_listbox_t *listbox;
+ rtgui_rect_t screen, rect = {0, 0, 140, 85};
- rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &screen);
- rtgui_rect_moveto_align(&screen, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
+ rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &screen);
+ rtgui_rect_moveto_align(&screen, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
- menu = rtgui_win_create(RTGUI_WIN(rtgui_widget_get_toplevel(parent)),
- "Folder Menu", &rect, RTGUI_WIN_STYLE_DEFAULT);
- if (menu != RT_NULL)
- {
- /* set user data on menu window */
- menu->user_data = (rt_uint32_t)parent;
+ menu = rtgui_win_create(RTGUI_WIN(rtgui_widget_get_toplevel(parent)),
+ "Folder Menu", &rect, RTGUI_WIN_STYLE_DEFAULT);
+ if (menu != RT_NULL)
+ {
+ /* set user data on menu window */
+ menu->user_data = (rt_uint32_t)parent;
- rtgui_win_set_ondeactivate(menu, rtgui_filelist_view_on_menu_deactivate);
+ rtgui_win_set_ondeactivate(menu, rtgui_filelist_view_on_menu_deactivate);
- listbox = rtgui_listbox_create(items, sizeof(items)/sizeof(items[0]), &rect);
- rtgui_listbox_set_onitem(listbox, rtgui_filelist_view_on_folder_item);
- rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(listbox));
- rtgui_listbox_set_current_item(listbox, 0);
- rtgui_win_show(menu, RT_TRUE);
- }
+ listbox = rtgui_listbox_create(items, sizeof(items) / sizeof(items[0]), &rect);
+ rtgui_listbox_set_onitem(listbox, rtgui_filelist_view_on_folder_item);
+ rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(listbox));
+ rtgui_listbox_set_current_item(listbox, 0);
+ rtgui_win_show(menu, RT_TRUE);
+ }
}
static void _rtgui_filelist_view_constructor(struct rtgui_filelist_view *view)
{
- /* default rect */
- struct rtgui_rect rect = {0, 0, 200, 200};
+ /* default rect */
+ struct rtgui_rect rect = {0, 0, 200, 200};
- /* set default widget rect and set event handler */
- rtgui_object_set_event_handler(RTGUI_OBJECT(view), rtgui_filelist_view_event_handler);
- rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
+ /* set default widget rect and set event handler */
+ rtgui_object_set_event_handler(RTGUI_OBJECT(view), rtgui_filelist_view_event_handler);
+ rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
- RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+ RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- view->current_item = 0;
- view->items_count = 0;
- view->page_items = 0;
+ view->current_item = 0;
+ view->items_count = 0;
+ view->page_items = 0;
- view->current_directory = RT_NULL;
- view->pattern = RT_NULL;
- RTGUI_WIDGET_BACKGROUND(view) = white;
- RTGUI_WIDGET_TEXTALIGN(view) = RTGUI_ALIGN_CENTER_VERTICAL;
+ view->current_directory = RT_NULL;
+ view->pattern = RT_NULL;
+ RTGUI_WIDGET_BACKGROUND(view) = white;
+ RTGUI_WIDGET_TEXTALIGN(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);
+ 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);
}
static void _rtgui_filelist_view_destructor(struct rtgui_filelist_view *view)
{
/* delete all file items */
rtgui_filelist_view_clear(view);
- /* delete current directory and pattern */
- if (view->current_directory != RT_NULL)
- {
- rt_free(view->current_directory);
- view->current_directory = RT_NULL;
- }
- if (view->pattern != RT_NULL)
- {
- rt_free(view->pattern);
- view->pattern = RT_NULL;
- }
+ /* delete current directory and pattern */
+ if (view->current_directory != RT_NULL)
+ {
+ rt_free(view->current_directory);
+ view->current_directory = RT_NULL;
+ }
+ if (view->pattern != RT_NULL)
+ {
+ rt_free(view->pattern);
+ view->pattern = RT_NULL;
+ }
- /* delete image */
- rtgui_image_destroy(file_image);
- rtgui_image_destroy(folder_image);
+ /* delete image */
+ rtgui_image_destroy(file_image);
+ rtgui_image_destroy(folder_image);
}
DEFINE_CLASS_TYPE(filelist, "filelist",
- RTGUI_CONTAINER_TYPE,
- _rtgui_filelist_view_constructor,
- _rtgui_filelist_view_destructor,
- sizeof(struct rtgui_filelist_view));
+ RTGUI_CONTAINER_TYPE,
+ _rtgui_filelist_view_constructor,
+ _rtgui_filelist_view_destructor,
+ sizeof(struct rtgui_filelist_view));
-void rtgui_filelist_view_ondraw(struct rtgui_filelist_view* view)
+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;
+ 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;
+ 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);
+ 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 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 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;
+ /* 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]);
+ 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);
- }
+ 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 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;
+ 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);
+ 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);
- }
+ image_rect.y1 += (rtgui_theme_get_selected_height() + 1);
+ image_rect.y2 += (rtgui_theme_get_selected_height() + 1);
+ }
- rtgui_dc_end_drawing(dc);
+ rtgui_dc_end_drawing(dc);
}
-void rtgui_filelist_view_update_current(struct rtgui_filelist_view* view, rt_uint16_t old_item)
+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;
+ 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;
- }
+ 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;
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
+ if (dc == RT_NULL) return;
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
+ 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 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);
+ /* 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);
+ /* 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 = &(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);
+ 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());
+ /* 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);
+ 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);
+ /* 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 = &(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);
+ item_rect.x1 += RTGUI_FILELIST_MARGIN + file_image->w + 2;
+ rtgui_dc_draw_text(dc, item->name, &item_rect);
- rtgui_dc_end_drawing(dc);
+ rtgui_dc_end_drawing(dc);
}
-static void rtgui_filelist_view_onenturn(struct rtgui_filelist_view* view)
+static void rtgui_filelist_view_onenturn(struct rtgui_filelist_view *view)
{
- if (view->items[view->current_item].type == RTGUI_FITEM_DIR)
- {
- char new_path[64];
+ if (view->items[view->current_item].type == RTGUI_FITEM_DIR)
+ {
+ char new_path[64];
- if (strcmp(view->items[view->current_item].name, ".") == 0) return ;
- if (strcmp(view->items[view->current_item].name, "..") == 0)
- {
- char *ptr;
- ptr = strrchr(view->current_directory, PATH_SEPARATOR);
+ if (strcmp(view->items[view->current_item].name, ".") == 0) return ;
+ if (strcmp(view->items[view->current_item].name, "..") == 0)
+ {
+ char *ptr;
+ ptr = strrchr(view->current_directory, PATH_SEPARATOR);
- if (ptr == RT_NULL) return ;
- 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] == '\\')
+ if (ptr == RT_NULL) return ;
+ 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_NATIVE
+ (view->current_directory[1] == ':') && (view->current_directory[2] == '\\')
#else
- (view->current_directory[0] == '/') && (view->current_directory[1] == '\0')
+ (view->current_directory[0] == '/') && (view->current_directory[1] == '\0')
#endif
- )
- {
- rtgui_filelist_view_destroy(view);
+ )
+ {
+ rtgui_filelist_view_destroy(view);
- return ;
- }
- else
- {
- rtgui_filelist_view_menu_pop(RTGUI_WIDGET(view));
- return ;
- }
- rtgui_filelist_view_set_directory(view, new_path);
- }
+ return ;
+ }
+ else
+ {
+ rtgui_filelist_view_menu_pop(RTGUI_WIDGET(view));
+ return ;
+ }
+ rtgui_filelist_view_set_directory(view, new_path);
+ }
}
-rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_widget *widget;
- struct rtgui_filelist_view* view = RT_NULL;
+ struct rtgui_widget *widget;
+ struct rtgui_filelist_view *view = RT_NULL;
- widget = RTGUI_WIDGET(object);
- view = RTGUI_FILELIST_VIEW(widget);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- rtgui_filelist_view_ondraw(view);
- return RT_FALSE;
+ widget = RTGUI_WIDGET(object);
+ 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;
+ {
+ struct rtgui_event_resize *resize;
- resize = (struct rtgui_event_resize*)event;
+ 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;
+ /* 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;
+ case RTGUI_EVENT_MOUSE_BUTTON:
+ {
+ rtgui_rect_t rect;
+ struct rtgui_event_mouse *emouse;
- emouse = (struct rtgui_event_mouse*)event;
+ emouse = (struct rtgui_event_mouse *)event;
- /* calculate selected item */
+ /* calculate selected item */
- /* get physical extent information */
- rtgui_widget_get_rect(widget, &rect);
- rtgui_widget_rect_to_device(widget, &rect);
+ /* 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;
- rt_uint16_t current_page;
- rt_uint16_t old_item;
+ if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
+ {
+ rt_uint16_t index;
+ rt_uint16_t current_page;
+ rt_uint16_t old_item;
- index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());
+ index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());
- /* get current page */
- current_page = view->current_item/view->page_items;
- old_item = view->current_item;
+ /* get current page */
+ current_page = view->current_item / view->page_items;
+ old_item = view->current_item;
- if (index + current_page * view->page_items < view->items_count)
- {
- /* set selected item */
- view->current_item = index + current_page * view->page_items;
- if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
- {
- rtgui_filelist_view_update_current(view, old_item);
- }
- else
- {
- /* up event */
- rtgui_filelist_view_onenturn(view);
- }
- }
+ if (index + current_page * view->page_items < view->items_count)
+ {
+ /* set selected item */
+ view->current_item = index + current_page * view->page_items;
+ if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
+ {
+ rtgui_filelist_view_update_current(view, old_item);
+ }
+ else
+ {
+ /* up event */
+ rtgui_filelist_view_onenturn(view);
+ }
+ }
- return RT_TRUE;
- }
- }
- break;
+ return RT_TRUE;
+ }
+ }
+ break;
case RTGUI_EVENT_KBD:
+ {
+ struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
+ if (ekbd->type == RTGUI_KEYDOWN)
{
- struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
- if (ekbd->type == RTGUI_KEYDOWN)
- {
- rt_uint16_t old_item;
+ 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_TRUE;
+ 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_TRUE;
- case RTGUIK_DOWN:
- if (view->current_item < view->items_count - 1)
- view->current_item ++;
- rtgui_filelist_view_update_current(view, old_item);
- return RT_TRUE;
+ case RTGUIK_DOWN:
+ if (view->current_item < view->items_count - 1)
+ view->current_item ++;
+ rtgui_filelist_view_update_current(view, old_item);
+ return RT_TRUE;
- 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_TRUE;
+ 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_TRUE;
- 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_TRUE;
+ 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_TRUE;
- case RTGUIK_RETURN:
- rtgui_filelist_view_onenturn(view);
- return RT_TRUE;
+ case RTGUIK_RETURN:
+ rtgui_filelist_view_onenturn(view);
+ return RT_TRUE;
- default:
- break;
- }
+ default:
+ break;
}
}
- return RT_FALSE;
- }
+ }
+ return RT_FALSE;
+ }
/* use view event handler */
return rtgui_container_event_handler(object, event);
}
-rtgui_filelist_view_t* rtgui_filelist_view_create(const char* directory,
- const char* pattern,
- const rtgui_rect_t* rect)
+rtgui_filelist_view_t *rtgui_filelist_view_create(const char *directory,
+ const char *pattern,
+ const rtgui_rect_t *rect)
{
- struct rtgui_filelist_view* view = RT_NULL;
+ 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)
- {
- rtgui_widget_set_rect(RTGUI_WIDGET(view), rect);
- 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);
- }
+ /* create a new view */
+ view = (struct rtgui_filelist_view *) rtgui_widget_create(RTGUI_FILELIST_VIEW_TYPE);
+ if (view != RT_NULL)
+ {
+ rtgui_widget_set_rect(RTGUI_WIDGET(view), rect);
+ 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);
+ }
- return view;
+ return view;
}
RTM_EXPORT(rtgui_filelist_view_create);
-void rtgui_filelist_view_destroy(rtgui_filelist_view_t* view)
+void rtgui_filelist_view_destroy(rtgui_filelist_view_t *view)
{
/* destroy view */
- rtgui_widget_destroy(RTGUI_WIDGET(view));
+ rtgui_widget_destroy(RTGUI_WIDGET(view));
}
RTM_EXPORT(rtgui_filelist_view_destroy);
/* clear all file items */
-static void rtgui_filelist_view_clear(rtgui_filelist_view_t* view)
+static void rtgui_filelist_view_clear(rtgui_filelist_view_t *view)
{
- rt_uint32_t index;
- struct rtgui_file_item* item;
+ rt_uint32_t index;
+ struct rtgui_file_item *item;
- for (index = 0; index < view->items_count; index ++)
- {
- item = &(view->items[index]);
+ for (index = 0; index < view->items_count; index ++)
+ {
+ item = &(view->items[index]);
- /* release item name */
- rt_free(item->name);
- item->name = RT_NULL;
- }
+ /* release item name */
+ rt_free(item->name);
+ item->name = RT_NULL;
+ }
- /* release items */
- rtgui_free(view->items);
- view->items = RT_NULL;
+ /* release items */
+ rtgui_free(view->items);
+ view->items = RT_NULL;
- view->items_count = 0;
- view->current_item = 0;
+ view->items_count = 0;
+ view->current_item = 0;
}
RTM_EXPORT(rtgui_filelist_view_clear);
-void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char* directory)
+void rtgui_filelist_view_set_directory(rtgui_filelist_view_t *view, const char *directory)
{
struct rtgui_file_item *item;
@@ -727,106 +737,107 @@ void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char*
rtgui_filelist_view_clear(view);
if (directory != RT_NULL)
{
- DIR* dir;
- struct stat s;
- char* fullpath;
- rt_uint32_t index;
- struct dirent* dirent;
+ DIR *dir;
+ struct stat s;
+ char *fullpath;
+ rt_uint32_t index;
+ struct dirent *dirent;
- view->items_count = 0;
+ view->items_count = 0;
dir = opendir(directory);
- if (dir == RT_NULL) goto __return;
+ 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);
+ /* 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;
+ do
+ {
+ dirent = readdir(dir);
+ if (dirent == RT_NULL) break;
- if (strcmp(dirent->d_name, ".") == 0) continue;
- if (strcmp(dirent->d_name, "..") == 0) continue;
+ 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 ++;
+ }
+ while (dirent != RT_NULL);
+ closedir(dir);
- view->items_count ++; /* root directory for [x] exit, others for .. */
+ 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 */
+ 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]);
+ 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;
+ /* add .. directory */
+ item->name = rt_strdup("..");
+ item->type = RTGUI_FITEM_DIR;
+ item->size = 0;
- index ++;
- }
- else
- {
- item = &(view->items[0]);
+ index ++;
+ }
+ else
+ {
+ item = &(view->items[0]);
- /* add .. directory */
+ /* add .. directory */
#ifdef RTGUI_USING_FONTHZ
- item->name = rt_strdup("�˳��ļ����");
+ item->name = rt_strdup("�˳��ļ����");
#else
- item->name = rt_strdup("..");
+ item->name = rt_strdup("..");
#endif
- item->type = RTGUI_FITEM_DIR;
- item->size = 0;
+ item->type = RTGUI_FITEM_DIR;
+ item->size = 0;
- index ++;
- }
+ index ++;
+ }
- /* reopen directory */
- dir = opendir(directory);
- fullpath = rtgui_malloc(256);
- while (index < view->items_count)
- {
- dirent = readdir(dir);
- if (dirent == RT_NULL) break;
+ /* reopen directory */
+ dir = opendir(directory);
+ fullpath = rtgui_malloc(256);
+ while (index < view->items_count)
+ {
+ dirent = readdir(dir);
+ if (dirent == RT_NULL) break;
- if (strcmp(dirent->d_name, ".") == 0) continue;
- if (strcmp(dirent->d_name, "..") == 0) continue;
+ if (strcmp(dirent->d_name, ".") == 0) continue;
+ if (strcmp(dirent->d_name, "..") == 0) continue;
- item = &(view->items[index]);
- item->name = rt_strdup(dirent->d_name);
+ item = &(view->items[index]);
+ item->name = rt_strdup(dirent->d_name);
- rt_memset(&s, 0, sizeof(struct stat));
+ rt_memset(&s, 0, sizeof(struct stat));
- /* build full path for the file */
- if (directory[strlen(directory) - 1] != PATH_SEPARATOR)
- rt_snprintf(fullpath, 256, "%s%c%s", directory, PATH_SEPARATOR, dirent->d_name);
- else
- rt_snprintf(fullpath, 256, "%s%s", directory, dirent->d_name);
+ /* build full path for the file */
+ if (directory[strlen(directory) - 1] != PATH_SEPARATOR)
+ rt_snprintf(fullpath, 256, "%s%c%s", directory, PATH_SEPARATOR, dirent->d_name);
+ else
+ rt_snprintf(fullpath, 256, "%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;
- }
+ 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;
+ }
- index ++;
- }
- rtgui_free(fullpath);
- closedir(dir);
+ index ++;
+ }
+ rtgui_free(fullpath);
+ closedir(dir);
}
- view->current_item = 0;
+ view->current_item = 0;
__return:
/* update view */
@@ -834,16 +845,16 @@ __return:
}
RTM_EXPORT(rtgui_filelist_view_set_directory);
-void rtgui_filelist_view_get_fullpath(rtgui_filelist_view_t* view, char* path, rt_size_t len)
+void rtgui_filelist_view_get_fullpath(rtgui_filelist_view_t *view, char *path, rt_size_t len)
{
- RT_ASSERT(view != RT_NULL);
+ RT_ASSERT(view != RT_NULL);
- if (view->current_directory[strlen(view->current_directory) - 1] != PATH_SEPARATOR)
- rt_snprintf(path, len, "%s%c%s",view->current_directory, PATH_SEPARATOR,
- view->items[view->current_item].name);
- else
- rt_snprintf(path, len, "%s%s",view->current_directory,
- view->items[view->current_item].name);
+ if (view->current_directory[strlen(view->current_directory) - 1] != PATH_SEPARATOR)
+ rt_snprintf(path, len, "%s%c%s", view->current_directory, PATH_SEPARATOR,
+ view->items[view->current_item].name);
+ else
+ rt_snprintf(path, len, "%s%s", view->current_directory,
+ view->items[view->current_item].name);
}
RTM_EXPORT(rtgui_filelist_view_get_fullpath);
diff --git a/components/rtgui/widgets/groupbox.c b/components/rtgui/widgets/groupbox.c
index 709759ea57..2e648c2997 100644
--- a/components/rtgui/widgets/groupbox.c
+++ b/components/rtgui/widgets/groupbox.c
@@ -18,138 +18,138 @@
static void _rtgui_groupbox_constructor(rtgui_groupbox_t *box)
{
- /* init widget and set event handler */
- rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_groupbox_event_handler);
+ /* init widget and set event handler */
+ rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_groupbox_event_handler);
- /* set field */
- box->box = RT_NULL;
- box->label = RT_NULL;
- box->selected = RT_NULL;
+ /* set field */
+ box->box = RT_NULL;
+ box->label = RT_NULL;
+ box->selected = RT_NULL;
- box->on_selected = RT_NULL;
+ box->on_selected = RT_NULL;
}
-DEFINE_CLASS_TYPE(groupbox, "groupbox",
- RTGUI_PANEL_TYPE,
- _rtgui_groupbox_constructor,
- RT_NULL,
- sizeof(struct rtgui_groupbox));
+DEFINE_CLASS_TYPE(groupbox, "groupbox",
+ RTGUI_PANEL_TYPE,
+ _rtgui_groupbox_constructor,
+ RT_NULL,
+ sizeof(struct rtgui_groupbox));
-rt_bool_t rtgui_groupbox_event_handler(struct rtgui_object *object, struct rtgui_event* event)
+rt_bool_t rtgui_groupbox_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_groupbox* box;
+ struct rtgui_groupbox *box;
- box = RTGUI_GROUPBOX(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- {
- rtgui_panel_event_handler(RTGUI_OBJECT(box), event);
+ box = RTGUI_GROUPBOX(object);
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
+ {
+ rtgui_panel_event_handler(RTGUI_OBJECT(box), event);
- /* dispatch paint event to child */
- rtgui_container_dispatch_event(RTGUI_CONTAINER(box), event);
- }
- break;
- default:
- return rtgui_container_event_handler(object, event);
- }
+ /* dispatch paint event to child */
+ rtgui_container_dispatch_event(RTGUI_CONTAINER(box), event);
+ }
+ break;
+ default:
+ return rtgui_container_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
-rtgui_groupbox_t* rtgui_groupbox_create(const char* label, struct rtgui_rect *rect,
- int style, widget_select_t select_func)
+rtgui_groupbox_t *rtgui_groupbox_create(const char *label, struct rtgui_rect *rect,
+ int style, widget_select_t select_func)
{
struct rtgui_groupbox *box;
- RT_ASSERT(select_func != RT_NULL);
+ RT_ASSERT(select_func != RT_NULL);
- box = (struct rtgui_groupbox*) rtgui_widget_create(RTGUI_GROUPBOX_TYPE);
+ box = (struct rtgui_groupbox *) rtgui_widget_create(RTGUI_GROUPBOX_TYPE);
if (box != RT_NULL)
{
- rtgui_widget_set_rect(RTGUI_WIDGET(box), rect);
+ rtgui_widget_set_rect(RTGUI_WIDGET(box), rect);
- if (label != RT_NULL)
- {
- box->label = rt_strdup(label);
- }
+ if (label != RT_NULL)
+ {
+ box->label = rt_strdup(label);
+ }
- /* create layout box */
- box->box = rtgui_box_create(style, RTGUI_WIDGET_DEFAULT_MARGIN + 1);
- rtgui_container_set_box(RTGUI_CONTAINER(box), box->box);
+ /* create layout box */
+ box->box = rtgui_box_create(style, RTGUI_WIDGET_DEFAULT_MARGIN + 1);
+ rtgui_container_set_box(RTGUI_CONTAINER(box), box->box);
- rtgui_panel_set_border(RTGUI_PANEL(box), RTGUI_BORDER_NONE);
+ rtgui_panel_set_border(RTGUI_PANEL(box), RTGUI_BORDER_NONE);
- box->select_func = select_func;
+ box->select_func = select_func;
}
return box;
}
-void rtgui_groupbox_destroy(rtgui_groupbox_t* groupbox)
+void rtgui_groupbox_destroy(rtgui_groupbox_t *groupbox)
{
- rtgui_object_destroy(RTGUI_OBJECT(groupbox));
+ rtgui_object_destroy(RTGUI_OBJECT(groupbox));
}
void rtgui_groupbox_select_widget(struct rtgui_groupbox *box, struct rtgui_widget *widget)
{
- struct rtgui_event event;
+ struct rtgui_event event;
- RT_ASSERT(box != RT_NULL);
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(box != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- if (box->selected != widget)
- {
- if (box->selected != RT_NULL)
- {
- box->select_func(box->selected, RT_FALSE);
- if (box->on_selected != RT_NULL)
- {
- RTGUI_EVENT_INIT(&event, RTGUI_EVENT_UNSELECTED);
- box->on_selected(RTGUI_OBJECT(widget), &event);
- }
- rtgui_widget_update(widget);
- }
- box->selected = widget;
- }
+ if (box->selected != widget)
+ {
+ if (box->selected != RT_NULL)
+ {
+ box->select_func(box->selected, RT_FALSE);
+ if (box->on_selected != RT_NULL)
+ {
+ RTGUI_EVENT_INIT(&event, RTGUI_EVENT_UNSELECTED);
+ box->on_selected(RTGUI_OBJECT(widget), &event);
+ }
+ rtgui_widget_update(widget);
+ }
+ box->selected = widget;
+ }
- box->select_func(box->selected, RT_TRUE);
+ box->select_func(box->selected, RT_TRUE);
- if (box->on_selected != RT_NULL)
- {
- RTGUI_EVENT_INIT(&event, RTGUI_EVENT_SELECTED);
- box->on_selected(RTGUI_OBJECT(widget), &event);
- }
+ if (box->on_selected != RT_NULL)
+ {
+ RTGUI_EVENT_INIT(&event, RTGUI_EVENT_SELECTED);
+ box->on_selected(RTGUI_OBJECT(widget), &event);
+ }
}
struct rtgui_widget *rtgui_groupbox_get_selected(struct rtgui_groupbox *box)
{
- RT_ASSERT(box != RT_NULL);
+ RT_ASSERT(box != RT_NULL);
- return box->selected;
+ return box->selected;
}
void rtgui_groupbox_add_widget(struct rtgui_groupbox *box, struct rtgui_widget *widget)
{
- widget->user_data = (rt_uint32_t)box;
- rtgui_container_add_child(RTGUI_CONTAINER(box), widget);
- RTGUI_WIDGET_ALIGN(widget) = RTGUI_ALIGN_CENTER;
- RTGUI_WIDGET_BACKGROUND(widget) = RTGUI_WIDGET_BACKGROUND(box);
+ widget->user_data = (rt_uint32_t)box;
+ rtgui_container_add_child(RTGUI_CONTAINER(box), widget);
+ RTGUI_WIDGET_ALIGN(widget) = RTGUI_ALIGN_CENTER;
+ RTGUI_WIDGET_BACKGROUND(widget) = RTGUI_WIDGET_BACKGROUND(box);
}
void rtgui_groupbox_layout(struct rtgui_groupbox *box)
{
- if (RTGUI_PANEL(box)->border_style != RTGUI_BORDER_NONE)
- {
- rtgui_box_layout(box->box);
- }
- else
- {
- struct rtgui_rect extent;
+ if (RTGUI_PANEL(box)->border_style != RTGUI_BORDER_NONE)
+ {
+ rtgui_box_layout(box->box);
+ }
+ else
+ {
+ struct rtgui_rect extent;
- RT_ASSERT(box != RT_NULL);
- rtgui_widget_get_extent(RTGUI_WIDGET(box), &extent);
- rtgui_rect_inflate(&extent, -RTGUI_WIDGET_DEFAULT_MARGIN);
- rtgui_box_layout_rect(box->box, &extent);
- }
+ RT_ASSERT(box != RT_NULL);
+ rtgui_widget_get_extent(RTGUI_WIDGET(box), &extent);
+ rtgui_rect_inflate(&extent, -RTGUI_WIDGET_DEFAULT_MARGIN);
+ rtgui_box_layout_rect(box->box, &extent);
+ }
}
diff --git a/components/rtgui/widgets/iconbox.c b/components/rtgui/widgets/iconbox.c
index 9514038ab6..a5807347fd 100644
--- a/components/rtgui/widgets/iconbox.c
+++ b/components/rtgui/widgets/iconbox.c
@@ -17,170 +17,170 @@
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_FLAG_FOCUSABLE);
- rtgui_object_set_event_handler(RTGUI_OBJECT(iconbox), rtgui_iconbox_event_handler);
+ /* init widget and set event handler */
+ RTGUI_WIDGET(iconbox)->flag |= (RTGUI_WIDGET_FLAG_TRANSPARENT | RTGUI_WIDGET_FLAG_FOCUSABLE);
+ rtgui_object_set_event_handler(RTGUI_OBJECT(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;
+ /* 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;
- }
+ if (iconbox->image != RT_NULL)
+ {
+ rtgui_image_destroy(iconbox->image);
+ iconbox->image = RT_NULL;
+ }
- if (iconbox->text != RT_NULL)
- {
- rt_free(iconbox->text);
- iconbox->text = RT_NULL;
- }
+ if (iconbox->text != RT_NULL)
+ {
+ rt_free(iconbox->text);
+ iconbox->text = RT_NULL;
+ }
}
-DEFINE_CLASS_TYPE(iconbox, "iconbox",
- RTGUI_WIDGET_TYPE,
- _rtgui_iconbox_constructor,
- _rtgui_iconbox_destructor,
- sizeof(struct rtgui_iconbox));
+DEFINE_CLASS_TYPE(iconbox, "iconbox",
+ RTGUI_WIDGET_TYPE,
+ _rtgui_iconbox_constructor,
+ _rtgui_iconbox_destructor,
+ sizeof(struct rtgui_iconbox));
-rt_bool_t rtgui_iconbox_event_handler(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_iconbox_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_iconbox* iconbox;
+ struct rtgui_iconbox *iconbox;
- iconbox = RTGUI_ICONBOX(object);
+ iconbox = RTGUI_ICONBOX(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- rtgui_theme_draw_iconbox(iconbox);
- break;
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
+ rtgui_theme_draw_iconbox(iconbox);
+ break;
- case RTGUI_EVENT_MOUSE_BUTTON:
- if (RTGUI_WIDGET_IS_HIDE(object)) return RT_FALSE;
+ case RTGUI_EVENT_MOUSE_BUTTON:
+ if (RTGUI_WIDGET_IS_HIDE(object)) return RT_FALSE;
- {
- struct rtgui_event_mouse* emouse = (struct rtgui_event_mouse*)event;
+ {
+ struct rtgui_event_mouse *emouse = (struct rtgui_event_mouse *)event;
- /* it's not this widget event, clean status */
- if (rtgui_rect_contains_point(&(RTGUI_WIDGET(iconbox)->extent),
- emouse->x, emouse->y) != RT_EOK)
- {
- if (iconbox->selected != RT_TRUE)
- {
- rtgui_iconbox_set_selected(iconbox, RT_TRUE);
- rtgui_widget_focus(RTGUI_WIDGET(iconbox));
- }
- break;
- }
- }
- return RT_TRUE;
+ /* it's not this widget event, clean status */
+ if (rtgui_rect_contains_point(&(RTGUI_WIDGET(iconbox)->extent),
+ emouse->x, emouse->y) != RT_EOK)
+ {
+ if (iconbox->selected != RT_TRUE)
+ {
+ rtgui_iconbox_set_selected(iconbox, RT_TRUE);
+ rtgui_widget_focus(RTGUI_WIDGET(iconbox));
+ }
+ break;
+ }
+ }
+ return RT_TRUE;
- default:
- return rtgui_widget_event_handler(object, event);
- }
+ default:
+ return rtgui_widget_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
-struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image,
- const char* text,
- int position)
+struct rtgui_iconbox *rtgui_iconbox_create(struct rtgui_image *image,
+ const char *text,
+ int position)
{
- struct rtgui_iconbox* iconbox;
+ struct rtgui_iconbox *iconbox;
- iconbox = (struct rtgui_iconbox*)rtgui_widget_create(RTGUI_ICONBOX_TYPE);
+ iconbox = (struct rtgui_iconbox *)rtgui_widget_create(RTGUI_ICONBOX_TYPE);
if (iconbox != RT_NULL)
{
- rtgui_rect_t rect = {0, 0, 0, 0}, text_rect;
+ rtgui_rect_t rect = {0, 0, 0, 0}, text_rect;
- rect.x2 = image->w;
- rect.y2 = image->h;
+ 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;
- }
+ /* 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 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;
- }
+ /* set image and text position */
+ iconbox->image = image;
+ iconbox->text = (char *)rt_strdup((const char *)text);
+ iconbox->text_position = position;
+ }
- return iconbox;
+ return iconbox;
}
-void rtgui_iconbox_destroy(struct rtgui_iconbox* iconbox)
+void rtgui_iconbox_destroy(struct rtgui_iconbox *iconbox)
{
- rtgui_widget_destroy(RTGUI_WIDGET(iconbox));
+ rtgui_widget_destroy(RTGUI_WIDGET(iconbox));
}
-void rtgui_iconbox_set_text_position(struct rtgui_iconbox* iconbox, int position)
+void rtgui_iconbox_set_text_position(struct rtgui_iconbox *iconbox, int position)
{
- struct rtgui_rect rect = {0, 0, 0, 0}, text_rect;
+ struct rtgui_rect rect = {0, 0, 0, 0}, text_rect;
- RT_ASSERT(iconbox != RT_NULL);
+ RT_ASSERT(iconbox != RT_NULL);
- iconbox->text_position = position;
+ iconbox->text_position = position;
- /* set mini width and height */
- rect.x2 = iconbox->image->w;
- rect.y2 = iconbox->image->h;
+ /* 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;
- }
- }
+ /* 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;
+ }
+ }
}
-void rtgui_iconbox_set_selected(struct rtgui_iconbox* iconbox, rt_bool_t selected)
+void rtgui_iconbox_set_selected(struct rtgui_iconbox *iconbox, rt_bool_t selected)
{
- RT_ASSERT(iconbox != RT_NULL);
+ RT_ASSERT(iconbox != RT_NULL);
- iconbox->selected = selected;
+ iconbox->selected = selected;
}
diff --git a/components/rtgui/widgets/label.c b/components/rtgui/widgets/label.c
index cc2c2aeecb..2465879e45 100644
--- a/components/rtgui/widgets/label.c
+++ b/components/rtgui/widgets/label.c
@@ -18,105 +18,105 @@
static void _rtgui_label_constructor(rtgui_label_t *label)
{
- RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
- /* init widget and set event handler */
- rtgui_object_set_event_handler(RTGUI_OBJECT(label), rtgui_label_event_handler);
+ RTGUI_WIDGET_TEXTALIGN(label) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
+ /* init widget and set event handler */
+ rtgui_object_set_event_handler(RTGUI_OBJECT(label), rtgui_label_event_handler);
- /* set field */
- label->text = RT_NULL;
+ /* set field */
+ label->text = RT_NULL;
}
static void _rtgui_label_destructor(rtgui_label_t *label)
{
- /* release text memory */
- if (label->text)
- rt_free(label->text);
- label->text = RT_NULL;
+ /* release text memory */
+ if (label->text)
+ rt_free(label->text);
+ label->text = RT_NULL;
}
-DEFINE_CLASS_TYPE(label, "label",
- RTGUI_WIDGET_TYPE,
- _rtgui_label_constructor,
- _rtgui_label_destructor,
- sizeof(struct rtgui_label));
+DEFINE_CLASS_TYPE(label, "label",
+ RTGUI_WIDGET_TYPE,
+ _rtgui_label_constructor,
+ _rtgui_label_destructor,
+ sizeof(struct rtgui_label));
-rt_bool_t rtgui_label_event_handler(struct rtgui_object *object, struct rtgui_event* event)
+rt_bool_t rtgui_label_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_label *label;
- RTGUI_WIDGET_EVENT_HANDLER_PREPARE
+ struct rtgui_label *label;
+ RTGUI_WIDGET_EVENT_HANDLER_PREPARE
- label = RTGUI_LABEL(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- rtgui_theme_draw_label(label);
- break;
- default:
- return rtgui_widget_event_handler(object, event);
- }
+ label = RTGUI_LABEL(object);
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
+ rtgui_theme_draw_label(label);
+ break;
+ default:
+ return rtgui_widget_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_label_event_handler);
-rtgui_label_t* rtgui_label_create(const char* text)
+rtgui_label_t *rtgui_label_create(const char *text)
{
- struct rtgui_label* label;
+ struct rtgui_label *label;
- label = (struct rtgui_label*) rtgui_widget_create(RTGUI_LABEL_TYPE);
+ label = (struct rtgui_label *) rtgui_widget_create(RTGUI_LABEL_TYPE);
if (label != RT_NULL)
{
- rtgui_rect_t rect;
+ 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 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);
+ /* set text */
+ label->text = (char *)rt_strdup((const char *)text);
}
return label;
}
RTM_EXPORT(rtgui_label_create);
-void rtgui_label_destroy(rtgui_label_t* label)
+void rtgui_label_destroy(rtgui_label_t *label)
{
- rtgui_widget_destroy(RTGUI_WIDGET(label));
+ rtgui_widget_destroy(RTGUI_WIDGET(label));
}
RTM_EXPORT(rtgui_label_destroy);
-char* rtgui_label_get_text(rtgui_label_t* label)
+char *rtgui_label_get_text(rtgui_label_t *label)
{
- RT_ASSERT(label != RT_NULL);
+ RT_ASSERT(label != RT_NULL);
- return label->text;
+ return label->text;
}
RTM_EXPORT(rtgui_label_get_text);
-void rtgui_label_set_text(rtgui_label_t* label, const char* text)
+void rtgui_label_set_text(rtgui_label_t *label, const char *text)
{
- RT_ASSERT(label != RT_NULL);
+ RT_ASSERT(label != RT_NULL);
- if (label->text != RT_NULL)
- {
- /* it's a same text string */
- if (rt_strcmp(text, label->text) == 0)
+ if (label->text != RT_NULL)
+ {
+ /* it's a same text string */
+ if (rt_strcmp(text, label->text) == 0)
return;
- /* release old text memory */
- rt_free(label->text);
- }
+ /* release old text memory */
+ rt_free(label->text);
+ }
- if (text != RT_NULL)
- label->text = (char*)rt_strdup((const char*)text);
- else
+ if (text != RT_NULL)
+ label->text = (char *)rt_strdup((const char *)text);
+ else
label->text = RT_NULL;
- /* update widget */
- rtgui_theme_draw_label(label);
+ /* update widget */
+ rtgui_theme_draw_label(label);
}
RTM_EXPORT(rtgui_label_set_text);
diff --git a/components/rtgui/widgets/list_view.c b/components/rtgui/widgets/list_view.c
index d4aa7a4bce..d45be89e5d 100644
--- a/components/rtgui/widgets/list_view.c
+++ b/components/rtgui/widgets/list_view.c
@@ -15,628 +15,641 @@
#include <rtgui/rtgui_theme.h>
#include <rtgui/widgets/list_view.h>
-#define LIST_MARGIN 5
+#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};
+ /* default rect */
+ struct rtgui_rect rect = {0, 0, 200, 200};
- /* set default widget rect and set event handler */
- rtgui_object_set_event_handler(RTGUI_OBJECT(view),rtgui_list_view_event_handler);
- rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
+ /* set default widget rect and set event handler */
+ rtgui_object_set_event_handler(RTGUI_OBJECT(view), rtgui_list_view_event_handler);
+ rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
- RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+ RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- view->flag = RTGUI_LIST_VIEW_LIST;
- view->current_item = 0;
- view->items_count = 0;
- view->page_items = 0;
+ view->flag = RTGUI_LIST_VIEW_LIST;
+ view->current_item = 0;
+ view->items_count = 0;
+ view->page_items = 0;
- RTGUI_WIDGET_BACKGROUND(view) = white;
- RTGUI_WIDGET_TEXTALIGN(view) = RTGUI_ALIGN_CENTER_VERTICAL;
+ RTGUI_WIDGET_BACKGROUND(view) = white;
+ RTGUI_WIDGET_TEXTALIGN(view) = RTGUI_ALIGN_CENTER_VERTICAL;
}
-DEFINE_CLASS_TYPE(listview, "listview",
- RTGUI_CONTAINER_TYPE,
- _rtgui_list_view_constructor,
- RT_NULL,
- sizeof(struct rtgui_list_view));
+DEFINE_CLASS_TYPE(listview, "listview",
+ RTGUI_CONTAINER_TYPE,
+ _rtgui_list_view_constructor,
+ RT_NULL,
+ sizeof(struct rtgui_list_view));
-static void rtgui_list_view_onicondraw(struct rtgui_list_view* view, struct rtgui_dc *dc)
+static void rtgui_list_view_onicondraw(struct rtgui_list_view *view, struct rtgui_dc *dc)
{
- struct rtgui_rect rect, item_rect, drawing_rect;
- rt_ubase_t c, r, item_index; /* col and row index */
- rt_ubase_t item_width, item_height;
- rtgui_image_t* image;
+ struct rtgui_rect rect, item_rect, drawing_rect;
+ rt_ubase_t c, r, item_index; /* col and row index */
+ rt_ubase_t item_width, item_height;
+ rtgui_image_t *image;
- if (view->items_count == 0) return;
+ if (view->items_count == 0) return;
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
- item_index = (view->current_item / view->page_items) * view->page_items;
+ rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
+ item_index = (view->current_item / view->page_items) * view->page_items;
- item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN)/view->col_items;
- item_height = (rtgui_rect_height(rect) - 4)/view->row_items;
- image = view->items[0].image;
+ item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN) / view->col_items;
+ item_height = (rtgui_rect_height(rect) - 4) / view->row_items;
+ image = view->items[0].image;
- for (r = 0; r < view->row_items; r ++)
- {
- for (c = 0; c < view->col_items; c ++)
- {
- if (item_index < view->items_count)
- {
- item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height;
- item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width;
- item_rect.x2 = item_rect.x1 + item_width;
- item_rect.y2 = item_rect.y1 + item_height;
+ for (r = 0; r < view->row_items; r ++)
+ {
+ for (c = 0; c < view->col_items; c ++)
+ {
+ if (item_index < view->items_count)
+ {
+ item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height;
+ item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width;
+ item_rect.x2 = item_rect.x1 + item_width;
+ item_rect.y2 = item_rect.y1 + item_height;
- if (item_index == view->current_item)
- {
- rtgui_theme_draw_selected(dc, &item_rect);
- }
+ if (item_index == view->current_item)
+ {
+ rtgui_theme_draw_selected(dc, &item_rect);
+ }
- drawing_rect.x1 = drawing_rect.y1 = 0;
- drawing_rect.x2 = image->w;
- drawing_rect.y2 = image->h;
- rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
- drawing_rect.y1 += 5; drawing_rect.y2 += 5;
- rtgui_image_blit(view->items[item_index].image, dc, &drawing_rect);
+ drawing_rect.x1 = drawing_rect.y1 = 0;
+ drawing_rect.x2 = image->w;
+ drawing_rect.y2 = image->h;
+ rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
+ drawing_rect.y1 += 5;
+ drawing_rect.y2 += 5;
+ rtgui_image_blit(view->items[item_index].image, dc, &drawing_rect);
- item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
- item_rect.x1 += 3; item_rect.x2 -=3;
- rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view), view->items[item_index].name,
- &drawing_rect);
- rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
- rtgui_dc_draw_text(dc, view->items[item_index].name, &drawing_rect);
+ item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
+ item_rect.x1 += 3;
+ item_rect.x2 -= 3;
+ rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view), view->items[item_index].name,
+ &drawing_rect);
+ rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
+ rtgui_dc_draw_text(dc, view->items[item_index].name, &drawing_rect);
- item_index ++;
- }
- else break;
- }
- }
+ item_index ++;
+ }
+ else break;
+ }
+ }
}
-static void rtgui_list_view_update_icon(struct rtgui_list_view* view, rt_int16_t old_item)
+static void rtgui_list_view_update_icon(struct rtgui_list_view *view, rt_int16_t old_item)
{
- struct rtgui_rect rect, item_rect, drawing_rect;
- rt_ubase_t c, r; /* col and row index */
- rt_ubase_t item_width, item_height;
- rtgui_image_t* image;
- struct rtgui_dc* dc;
+ struct rtgui_rect rect, item_rect, drawing_rect;
+ rt_ubase_t c, r; /* col and row index */
+ rt_ubase_t item_width, item_height;
+ rtgui_image_t *image;
+ struct rtgui_dc *dc;
- if ((view->items_count == 0) ||
- (old_item == view->current_item))
- return;
+ if ((view->items_count == 0) ||
+ (old_item == view->current_item))
+ return;
- 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;
- }
+ 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;
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
+ if (dc == RT_NULL) return;
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
+ rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
- item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN)/view->col_items;
- item_height = (rtgui_rect_height(rect) - 4)/view->row_items;
- image = view->items[0].image;
+ item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN) / view->col_items;
+ item_height = (rtgui_rect_height(rect) - 4) / view->row_items;
+ image = view->items[0].image;
- /* update old item */
- r = (old_item % view->page_items)/ view->col_items;
- c = (old_item % view->page_items)% view->col_items;
- item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height;
- item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width;
- item_rect.x2 = item_rect.x1 + item_width;
- item_rect.y2 = item_rect.y1 + item_height;
- rtgui_dc_fill_rect(dc, &item_rect);
+ /* update old item */
+ r = (old_item % view->page_items) / view->col_items;
+ c = (old_item % view->page_items) % view->col_items;
+ item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height;
+ item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width;
+ item_rect.x2 = item_rect.x1 + item_width;
+ item_rect.y2 = item_rect.y1 + item_height;
+ rtgui_dc_fill_rect(dc, &item_rect);
- /* draw image */
- drawing_rect.x1 = drawing_rect.y1 = 0;
- drawing_rect.x2 = image->w;
- drawing_rect.y2 = image->h;
- rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
- drawing_rect.y1 += 5; drawing_rect.y2 += 5;
- rtgui_image_blit(view->items[old_item].image, dc, &drawing_rect);
+ /* draw image */
+ drawing_rect.x1 = drawing_rect.y1 = 0;
+ drawing_rect.x2 = image->w;
+ drawing_rect.y2 = image->h;
+ rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
+ drawing_rect.y1 += 5;
+ drawing_rect.y2 += 5;
+ rtgui_image_blit(view->items[old_item].image, dc, &drawing_rect);
- /* draw text */
- item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
- item_rect.x1 += 3; item_rect.x2 -=3;
- rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view), view->items[old_item].name,
- &drawing_rect);
- rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
- rtgui_dc_draw_text(dc, view->items[old_item].name, &drawing_rect);
+ /* draw text */
+ item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
+ item_rect.x1 += 3;
+ item_rect.x2 -= 3;
+ rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view), view->items[old_item].name,
+ &drawing_rect);
+ rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
+ rtgui_dc_draw_text(dc, view->items[old_item].name, &drawing_rect);
- /* update new item as selected */
- r = (view->current_item % view->page_items) / view->col_items;
- c = (view->current_item % view->page_items) % view->col_items;
- item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height;
- item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width;
- item_rect.x2 = item_rect.x1 + item_width;
- item_rect.y2 = item_rect.y1 + item_height;
- rtgui_theme_draw_selected(dc, &item_rect);
+ /* update new item as selected */
+ r = (view->current_item % view->page_items) / view->col_items;
+ c = (view->current_item % view->page_items) % view->col_items;
+ item_rect.y1 = rect.y1 + LIST_MARGIN + r * item_height;
+ item_rect.x1 = rect.x1 + LIST_MARGIN + c * item_width;
+ item_rect.x2 = item_rect.x1 + item_width;
+ item_rect.y2 = item_rect.y1 + item_height;
+ rtgui_theme_draw_selected(dc, &item_rect);
- /* draw image */
- drawing_rect.x1 = 0;
- drawing_rect.y1 = 3;
- drawing_rect.x2 = image->w;
- drawing_rect.y2 = 3 + image->h;
+ /* draw image */
+ drawing_rect.x1 = 0;
+ drawing_rect.y1 = 3;
+ drawing_rect.x2 = image->w;
+ drawing_rect.y2 = 3 + image->h;
- rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
- rtgui_image_blit(view->items[view->current_item].image, dc, &drawing_rect);
+ rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
+ rtgui_image_blit(view->items[view->current_item].image, dc, &drawing_rect);
- /* draw text */
- item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
- item_rect.x1 += 3; item_rect.x2 -=3;
- rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view),
- view->items[view->current_item].name,
- &drawing_rect);
- rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
- rtgui_dc_draw_text(dc, view->items[view->current_item].name, &drawing_rect);
+ /* draw text */
+ item_rect.y1 = drawing_rect.y2 + LIST_MARGIN;
+ item_rect.x1 += 3;
+ item_rect.x2 -= 3;
+ rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view),
+ view->items[view->current_item].name,
+ &drawing_rect);
+ rtgui_rect_moveto_align(&item_rect, &drawing_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
+ rtgui_dc_draw_text(dc, view->items[view->current_item].name, &drawing_rect);
- rtgui_dc_end_drawing(dc);
+ rtgui_dc_end_drawing(dc);
}
-static void rtgui_list_view_onlistdraw(struct rtgui_list_view* view, struct rtgui_dc *dc)
+static void rtgui_list_view_onlistdraw(struct rtgui_list_view *view, struct rtgui_dc *dc)
{
- rt_ubase_t index, page_index;
- rtgui_rect_t rect, item_rect, image_rect;
- const struct rtgui_list_item* item;
+ rt_ubase_t index, page_index;
+ rtgui_rect_t rect, item_rect, image_rect;
+ const struct rtgui_list_item *item;
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
+ rtgui_widget_get_rect(RTGUI_WIDGET(view), &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 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;
+ /* 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]);
+ 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 (page_index + index == view->current_item)
+ {
+ rtgui_theme_draw_selected(dc, &item_rect);
+ }
+ item_rect.x1 += LIST_MARGIN;
- if (item->image != RT_NULL)
- {
- /* blit on center */
- image_rect.x1 = 0; image_rect.y1 = 0;
- image_rect.x2 = item->image->w;
- image_rect.y2 = item->image->h;
+ if (item->image != RT_NULL)
+ {
+ /* blit on center */
+ image_rect.x1 = 0;
+ image_rect.y1 = 0;
+ image_rect.x2 = item->image->w;
+ image_rect.y2 = item->image->h;
- rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
- rtgui_image_blit(item->image, dc, &image_rect);
- item_rect.x1 += item->image->w + 2;
- }
- /* draw text */
- rtgui_dc_draw_text(dc, item->name, &item_rect);
+ rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
+ rtgui_image_blit(item->image, dc, &image_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;
+ 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);
- }
+ /* move to next item position */
+ item_rect.y1 += (rtgui_theme_get_selected_height() + 2);
+ item_rect.y2 += (rtgui_theme_get_selected_height() + 2);
+ }
}
-void rtgui_list_view_update_list(struct rtgui_list_view* view, rt_int16_t old_item)
+void rtgui_list_view_update_list(struct rtgui_list_view *view, rt_int16_t old_item)
{
- struct rtgui_dc* dc;
- const struct rtgui_list_item* item;
- rtgui_rect_t rect, item_rect;
+ 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;
- }
+ 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;
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
+ if (dc == RT_NULL) return;
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
+ rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
- /* get old item's rect and draw old item */
- item_rect.x1 = rect.x1; item_rect.x2 = rect.x2;
- item_rect.y1 = 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());
- rtgui_dc_fill_rect(dc, &item_rect);
+ /* get old item's rect and draw old item */
+ item_rect.x1 = rect.x1;
+ item_rect.x2 = rect.x2;
+ item_rect.y1 = 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());
+ rtgui_dc_fill_rect(dc, &item_rect);
- item_rect.x1 += LIST_MARGIN;
+ item_rect.x1 += LIST_MARGIN;
- item = &(view->items[old_item]);
- if (item->image != RT_NULL)
- {
- struct rtgui_rect image_rect;
+ item = &(view->items[old_item]);
+ if (item->image != RT_NULL)
+ {
+ struct rtgui_rect image_rect;
- /* blit on center */
- image_rect.x1 = 0; image_rect.y1 = 0;
- image_rect.x2 = item->image->w;
- image_rect.y2 = item->image->h;
+ /* blit on center */
+ image_rect.x1 = 0;
+ image_rect.y1 = 0;
+ image_rect.x2 = item->image->w;
+ image_rect.y2 = item->image->h;
- rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
- rtgui_image_blit(item->image, dc, &image_rect);
- item_rect.x1 += item->image->w + 2;
- }
- rtgui_dc_draw_text(dc, item->name, &item_rect);
+ rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
+ rtgui_image_blit(item->image, dc, &image_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 */
+ 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);
+ /* draw current item */
+ rtgui_theme_draw_selected(dc, &item_rect);
- item_rect.x1 += LIST_MARGIN;
+ item_rect.x1 += LIST_MARGIN;
- item = &(view->items[view->current_item]);
- if (item->image != RT_NULL)
- {
- struct rtgui_rect image_rect;
+ item = &(view->items[view->current_item]);
+ if (item->image != RT_NULL)
+ {
+ struct rtgui_rect image_rect;
- /* blit on center */
- image_rect.x1 = 0; image_rect.y1 = 0;
- image_rect.x2 = item->image->w;
- image_rect.y2 = item->image->h;
+ /* blit on center */
+ image_rect.x1 = 0;
+ image_rect.y1 = 0;
+ image_rect.x2 = item->image->w;
+ image_rect.y2 = item->image->h;
- rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
- rtgui_image_blit(item->image, dc, &image_rect);
- item_rect.x1 += (item->image->w + 2);
- }
- rtgui_dc_draw_text(dc, item->name, &item_rect);
+ rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
+ rtgui_image_blit(item->image, dc, &image_rect);
+ item_rect.x1 += (item->image->w + 2);
+ }
+ rtgui_dc_draw_text(dc, item->name, &item_rect);
- rtgui_dc_end_drawing(dc);
+ rtgui_dc_end_drawing(dc);
}
RTM_EXPORT(rtgui_list_view_update_list);
-void rtgui_list_view_ondraw(struct rtgui_list_view* view)
+void rtgui_list_view_ondraw(struct rtgui_list_view *view)
{
- struct rtgui_rect rect;
- struct rtgui_dc* dc;
+ struct rtgui_rect rect;
+ struct rtgui_dc *dc;
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
- if (dc == RT_NULL) return;
+ 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);
+ rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
+ rtgui_dc_fill_rect(dc, &rect);
- switch (view->flag)
- {
- case RTGUI_LIST_VIEW_LIST:
- rtgui_list_view_onlistdraw(view, dc);
- break;
+ switch (view->flag)
+ {
+ case RTGUI_LIST_VIEW_LIST:
+ rtgui_list_view_onlistdraw(view, dc);
+ break;
- case RTGUI_LIST_VIEW_ICON:
- rtgui_list_view_onicondraw(view, dc);
- break;
- }
+ case RTGUI_LIST_VIEW_ICON:
+ rtgui_list_view_onicondraw(view, dc);
+ break;
+ }
- rtgui_dc_end_drawing(dc);
+ rtgui_dc_end_drawing(dc);
}
RTM_EXPORT(rtgui_list_view_ondraw);
-static rt_bool_t rtgui_list_view_onmouse(struct rtgui_list_view* view, struct rtgui_event_mouse* emouse)
+static rt_bool_t rtgui_list_view_onmouse(struct rtgui_list_view *view, struct rtgui_event_mouse *emouse)
{
- rtgui_rect_t rect;
+ rtgui_rect_t rect;
- /* calculate selected item */
+ /* calculate selected item */
- /* get physical extent information */
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
- rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
+ /* get physical extent information */
+ rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
+ rtgui_widget_rect_to_device(RTGUI_WIDGET(view), &rect);
- if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
- {
- rt_uint16_t index;
- rt_uint16_t old_item;
+ if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
+ {
+ rt_uint16_t index;
+ rt_uint16_t old_item;
- /* get old item */
- old_item = view->current_item;
+ /* get old item */
+ old_item = view->current_item;
- switch (view->flag)
- {
- case RTGUI_LIST_VIEW_LIST:
- index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());
+ switch (view->flag)
+ {
+ case RTGUI_LIST_VIEW_LIST:
+ index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());
- if ((index < view->items_count) && (index < view->page_items))
- {
- /* set selected item */
- view->current_item = (view->current_item/view->page_items) * view->page_items + index;
- if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
- {
- /* down event */
- rtgui_list_view_update_list(view, old_item);
- }
- else
- {
- /* up event */
- if (view->items[view->current_item].action != RT_NULL)
- {
- view->items[view->current_item].action(RTGUI_WIDGET(view),
- view->items[view->current_item].parameter);
- }
- }
- }
- break;
+ if ((index < view->items_count) && (index < view->page_items))
+ {
+ /* set selected item */
+ view->current_item = (view->current_item / view->page_items) * view->page_items + index;
+ if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
+ {
+ /* down event */
+ rtgui_list_view_update_list(view, old_item);
+ }
+ else
+ {
+ /* up event */
+ if (view->items[view->current_item].action != RT_NULL)
+ {
+ view->items[view->current_item].action(RTGUI_WIDGET(view),
+ view->items[view->current_item].parameter);
+ }
+ }
+ }
+ break;
- case RTGUI_LIST_VIEW_ICON:
- {
- rt_uint16_t x, y;
- rt_uint16_t item_height, item_width;
- rt_ubase_t current_page;
+ case RTGUI_LIST_VIEW_ICON:
+ {
+ rt_uint16_t x, y;
+ rt_uint16_t item_height, item_width;
+ rt_ubase_t current_page;
- item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN)/view->col_items;
- item_height = (rtgui_rect_height(rect) - 4)/view->row_items;
- x = emouse->x - rect.x1;
- y = emouse->y - rect.y1;
+ item_width = (rtgui_rect_width(rect) - 2 * LIST_MARGIN) / view->col_items;
+ item_height = (rtgui_rect_height(rect) - 4) / view->row_items;
+ x = emouse->x - rect.x1;
+ y = emouse->y - rect.y1;
- index = (y / item_height * view->col_items) + x / item_width;
- current_page = view->current_item / view->page_items;
+ index = (y / item_height * view->col_items) + x / item_width;
+ current_page = view->current_item / view->page_items;
- if ((index + (current_page * view->page_items) < view->items_count))
- {
- if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
- {
- view->current_item = index + (current_page * view->page_items);
+ if ((index + (current_page * view->page_items) < view->items_count))
+ {
+ if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
+ {
+ view->current_item = index + (current_page * view->page_items);
- /* down event */
- rtgui_list_view_update_icon(view, old_item);
- }
- else
- {
- /* up event */
- if (view->items[view->current_item].action != RT_NULL)
- {
- view->items[view->current_item].action(RTGUI_WIDGET(view),
- view->items[view->current_item].parameter);
- }
- }
- }
- }
- break;
+ /* down event */
+ rtgui_list_view_update_icon(view, old_item);
+ }
+ else
+ {
+ /* up event */
+ if (view->items[view->current_item].action != RT_NULL)
+ {
+ view->items[view->current_item].action(RTGUI_WIDGET(view),
+ view->items[view->current_item].parameter);
+ }
+ }
+ }
+ }
+ break;
- case RTGUI_LIST_VIEW_REPORT:
- break;
- }
+ case RTGUI_LIST_VIEW_REPORT:
+ break;
+ }
- return RT_TRUE;
- }
+ return RT_TRUE;
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
-rt_bool_t rtgui_list_view_event_handler(struct rtgui_object* widget, struct rtgui_event* event)
+rt_bool_t rtgui_list_view_event_handler(struct rtgui_object *widget, struct rtgui_event *event)
{
- struct rtgui_list_view* view = RT_NULL;
+ 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;
+ 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;
+ {
+ struct rtgui_event_resize *resize;
- resize = (struct rtgui_event_resize*)event;
+ resize = (struct rtgui_event_resize *)event;
- /* recalculate page items */
- view->page_items = resize->h / (2 + rtgui_theme_get_selected_height());
- }
- break;
+ /* recalculate page items */
+ view->page_items = resize->h / (2 + rtgui_theme_get_selected_height());
+ }
+ break;
- case RTGUI_EVENT_MOUSE_BUTTON:
- {
- struct rtgui_event_mouse* emouse;
+ case RTGUI_EVENT_MOUSE_BUTTON:
+ {
+ struct rtgui_event_mouse *emouse;
- emouse = (struct rtgui_event_mouse*)event;
- return rtgui_list_view_onmouse(view, emouse);
- }
+ emouse = (struct rtgui_event_mouse *)event;
+ return rtgui_list_view_onmouse(view, emouse);
+ }
case RTGUI_EVENT_KBD:
+ {
+ struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
+ if (ekbd->type == RTGUI_KEYDOWN)
{
- struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
- if (ekbd->type == RTGUI_KEYDOWN)
+ rt_uint16_t old_item;
+
+ if (view->current_item == -1)
{
- rt_uint16_t old_item;
+ /* set a initial item */
+ if ((view->items_count > 0) &&
+ (ekbd->key == RTGUIK_UP || ekbd->key == RTGUIK_DOWN))
+ {
+ view->current_item = 0;
+ if (view->flag == RTGUI_LIST_VIEW_LIST)
+ rtgui_list_view_update_list(view, -1);
+ else
+ rtgui_list_view_update_icon(view, -1);
+ break;
+ }
+ else return RT_FALSE;
+ }
- if (view->current_item == -1)
- {
- /* set a initial item */
- if ((view->items_count > 0) &&
- (ekbd->key == RTGUIK_UP || ekbd->key == RTGUIK_DOWN))
- {
- view->current_item = 0;
- if (view->flag == RTGUI_LIST_VIEW_LIST)
- rtgui_list_view_update_list(view, -1);
- else
- rtgui_list_view_update_icon(view, -1);
- break;
- }
- else return RT_FALSE;
- }
+ old_item = view->current_item;
+ switch (ekbd->key)
+ {
+ case RTGUIK_LEFT:
+ if (view->flag == RTGUI_LIST_VIEW_LIST)
+ {
+ if (view->current_item - view->page_items >= 0)
+ view->current_item -= view->page_items;
- old_item = view->current_item;
- switch (ekbd->key)
+ rtgui_list_view_update_list(view, old_item);
+ }
+ else if (view->flag == RTGUI_LIST_VIEW_ICON)
{
- case RTGUIK_LEFT:
- if (view->flag == RTGUI_LIST_VIEW_LIST)
- {
- if (view->current_item - view->page_items >= 0)
- view->current_item -= view->page_items;
-
- rtgui_list_view_update_list(view, old_item);
- }
- else if (view->flag == RTGUI_LIST_VIEW_ICON)
- {
- if (view->current_item > 0)
- view->current_item --;
- rtgui_list_view_update_icon(view, old_item);
- }
- return RT_FALSE;
+ if (view->current_item > 0)
+ view->current_item --;
+ rtgui_list_view_update_icon(view, old_item);
+ }
+ return RT_FALSE;
- case RTGUIK_UP:
- if (view->flag == RTGUI_LIST_VIEW_LIST)
- {
- if (view->current_item > 0)
- view->current_item --;
- rtgui_list_view_update_list(view, old_item);
- }
- else if (view->flag == RTGUI_LIST_VIEW_ICON)
- {
- if (view->current_item >= view->col_items)
- view->current_item -= view->col_items;
- else
- view->current_item = 0;
-
- rtgui_list_view_update_icon(view, old_item);
- }
- return RT_FALSE;
+ case RTGUIK_UP:
+ if (view->flag == RTGUI_LIST_VIEW_LIST)
+ {
+ if (view->current_item > 0)
+ view->current_item --;
+ rtgui_list_view_update_list(view, old_item);
+ }
+ else if (view->flag == RTGUI_LIST_VIEW_ICON)
+ {
+ if (view->current_item >= view->col_items)
+ view->current_item -= view->col_items;
+ else
+ view->current_item = 0;
- case RTGUIK_RIGHT:
- if (view->flag == RTGUI_LIST_VIEW_LIST)
- {
- if (view->current_item + view->page_items < view->items_count - 1)
- view->current_item += view->page_items;
-
- rtgui_list_view_update_list(view, old_item);
- }
- else if (view->flag == RTGUI_LIST_VIEW_ICON)
- {
- if (view->current_item < view->items_count - 1)
- view->current_item ++;
-
- rtgui_list_view_update_icon(view, old_item);
- }
- return RT_FALSE;
+ rtgui_list_view_update_icon(view, old_item);
+ }
+ return RT_FALSE;
- case RTGUIK_DOWN:
- if (view->flag == RTGUI_LIST_VIEW_LIST)
- {
- if (view->current_item < view->items_count - 1)
- view->current_item ++;
-
- rtgui_list_view_update_list(view, old_item);
- }
- else if (view->flag == RTGUI_LIST_VIEW_ICON)
- {
- if (view->current_item + view->col_items <= (view->items_count - 1))
- view->current_item += view->col_items;
- else
- view->current_item = view->items_count - 1;
+ case RTGUIK_RIGHT:
+ if (view->flag == RTGUI_LIST_VIEW_LIST)
+ {
+ if (view->current_item + view->page_items < view->items_count - 1)
+ view->current_item += view->page_items;
- rtgui_list_view_update_icon(view, old_item);
- }
- return RT_FALSE;
+ rtgui_list_view_update_list(view, old_item);
+ }
+ else if (view->flag == RTGUI_LIST_VIEW_ICON)
+ {
+ if (view->current_item < view->items_count - 1)
+ view->current_item ++;
- case RTGUIK_RETURN:
- if (view->items[view->current_item].action != RT_NULL)
- {
- view->items[view->current_item].action(RTGUI_WIDGET(view),
- view->items[view->current_item].parameter);
- }
- return RT_FALSE;
+ rtgui_list_view_update_icon(view, old_item);
+ }
+ return RT_FALSE;
- default:
- break;
+ case RTGUIK_DOWN:
+ if (view->flag == RTGUI_LIST_VIEW_LIST)
+ {
+ if (view->current_item < view->items_count - 1)
+ view->current_item ++;
+
+ rtgui_list_view_update_list(view, old_item);
+ }
+ else if (view->flag == RTGUI_LIST_VIEW_ICON)
+ {
+ if (view->current_item + view->col_items <= (view->items_count - 1))
+ view->current_item += view->col_items;
+ else
+ view->current_item = view->items_count - 1;
+
+ rtgui_list_view_update_icon(view, old_item);
+ }
+ return RT_FALSE;
+
+ case RTGUIK_RETURN:
+ if (view->items[view->current_item].action != RT_NULL)
+ {
+ view->items[view->current_item].action(RTGUI_WIDGET(view),
+ view->items[view->current_item].parameter);
}
+ return RT_FALSE;
+
+ default:
+ break;
}
}
- return RT_FALSE;
- }
+ }
+ return RT_FALSE;
+
+ default:
/* use view event handler */
return rtgui_container_event_handler(widget, event);
+ }
+
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_list_view_event_handler);
-static void rtgui_list_view_calc(struct rtgui_list_view* view)
+static void rtgui_list_view_calc(struct rtgui_list_view *view)
{
- rtgui_rect_t rect;
- rt_uint32_t image_width, image_height;
- rt_ubase_t text_width, text_height;
- rt_ubase_t item_width, item_height;
+ rtgui_rect_t rect;
+ rt_uint32_t image_width, image_height;
+ rt_ubase_t text_width, text_height;
+ rt_ubase_t item_width, item_height;
+
+ if (view->items_count == 0) return;
- if (view->items_count == 0) return;
+ /* get image width and height */
+ if (view->items[0].image != RT_NULL)
+ {
+ image_width = view->items[0].image->w;
+ image_height = view->items[0].image->h;
+ }
+ else
+ {
+ image_width = 0;
+ image_height = 0;
+ }
- /* get image width and height */
- if (view->items[0].image != RT_NULL)
- {
- image_width = view->items[0].image->w;
- image_height = view->items[0].image->h;
- }
- else
- {
- image_width = 0;
- image_height = 0;
- }
+ rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view), "HHHHHH", &rect);
- rtgui_font_get_metrics(RTGUI_WIDGET_FONT(view), "HHHHHH", &rect);
+ text_height = rtgui_rect_height(rect);
+ text_width = rtgui_rect_width(rect);
- text_height = rtgui_rect_height(rect);
- text_width = rtgui_rect_width(rect);
+ rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
+ item_width = (image_width + LIST_MARGIN);
+ if (item_width < (text_width + LIST_MARGIN)) item_width = text_width + LIST_MARGIN;
+ item_height = image_height + 8 + text_height + LIST_MARGIN;
+ if (item_width > item_height) item_height = item_width;
+ else item_width = item_height;
- item_width = (image_width + LIST_MARGIN);
- if (item_width < (text_width + LIST_MARGIN)) item_width = text_width + LIST_MARGIN;
- item_height = image_height + 8 + text_height + LIST_MARGIN;
- if (item_width > item_height) item_height = item_width;
- else item_width = item_height;
-
- view->row_items = (rtgui_rect_height(rect) - 2 * LIST_MARGIN) / item_height;
- view->col_items = (rtgui_rect_width(rect) - 2 * LIST_MARGIN) / item_width;
- view->page_items = view->row_items * view->col_items;
+ view->row_items = (rtgui_rect_height(rect) - 2 * LIST_MARGIN) / item_height;
+ view->col_items = (rtgui_rect_width(rect) - 2 * LIST_MARGIN) / item_width;
+ view->page_items = view->row_items * view->col_items;
}
-rtgui_list_view_t* rtgui_list_view_create(const struct rtgui_list_item* items, rt_uint16_t count,
- rtgui_rect_t *rect, rt_uint16_t flag)
+rtgui_list_view_t *rtgui_list_view_create(const struct rtgui_list_item *items, rt_uint16_t count,
+ rtgui_rect_t *rect, rt_uint16_t flag)
{
- struct rtgui_list_view* view = RT_NULL;
+ 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 = (struct rtgui_list_view *) rtgui_widget_create(RTGUI_LIST_VIEW_TYPE);
+ if (view != RT_NULL)
+ {
+ view->items = items;
+ view->items_count = count;
- view->flag = flag;
- rtgui_widget_set_rect(RTGUI_WIDGET(view), rect);
+ view->flag = flag;
+ rtgui_widget_set_rect(RTGUI_WIDGET(view), rect);
- if (flag == RTGUI_LIST_VIEW_LIST)
- view->page_items = rtgui_rect_height(*rect) / (2 + rtgui_theme_get_selected_height());
- else if ((flag == RTGUI_LIST_VIEW_ICON) && (count > 0))
- {
- rtgui_list_view_calc(view);
- }
- }
+ if (flag == RTGUI_LIST_VIEW_LIST)
+ view->page_items = rtgui_rect_height(*rect) / (2 + rtgui_theme_get_selected_height());
+ else if ((flag == RTGUI_LIST_VIEW_ICON) && (count > 0))
+ {
+ rtgui_list_view_calc(view);
+ }
+ }
- return view;
+ return view;
}
RTM_EXPORT(rtgui_list_view_create);
-void rtgui_list_view_destroy(rtgui_list_view_t* view)
+void rtgui_list_view_destroy(rtgui_list_view_t *view)
{
/* destroy view */
- rtgui_widget_destroy(RTGUI_WIDGET(view));
+ rtgui_widget_destroy(RTGUI_WIDGET(view));
}
RTM_EXPORT(rtgui_list_view_destroy);
diff --git a/components/rtgui/widgets/listbox.c b/components/rtgui/widgets/listbox.c
index 904def734e..901624e021 100644
--- a/components/rtgui/widgets/listbox.c
+++ b/components/rtgui/widgets/listbox.c
@@ -15,409 +15,422 @@
#include <rtgui/rtgui_theme.h>
#include <rtgui/widgets/listbox.h>
-#define LIST_MARGIN 5
-static rt_bool_t rtgui_listbox_onunfocus(struct rtgui_object* object, rtgui_event_t* event);
+#define LIST_MARGIN 5
+static rt_bool_t rtgui_listbox_onunfocus(struct rtgui_object *object, rtgui_event_t *event);
static void _rtgui_listbox_constructor(struct rtgui_listbox *box)
{
- /* set default widget rect and set event handler */
- rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_listbox_event_handler);
- rtgui_widget_set_onunfocus(RTGUI_WIDGET(box), rtgui_listbox_onunfocus);
- RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+ /* set default widget rect and set event handler */
+ rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_listbox_event_handler);
+ rtgui_widget_set_onunfocus(RTGUI_WIDGET(box), rtgui_listbox_onunfocus);
+ RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- box->current_item = -1;
- box->items_count = 0;
- box->page_items = 1;
- box->on_item = 0;
+ box->current_item = -1;
+ box->items_count = 0;
+ box->page_items = 1;
+ box->on_item = 0;
- RTGUI_WIDGET_BACKGROUND(box) = white;
- RTGUI_WIDGET_TEXTALIGN(box) = RTGUI_ALIGN_CENTER_VERTICAL;
+ RTGUI_WIDGET_BACKGROUND(box) = white;
+ RTGUI_WIDGET_TEXTALIGN(box) = RTGUI_ALIGN_CENTER_VERTICAL;
}
-DEFINE_CLASS_TYPE(listbox, "listbox",
- RTGUI_WIDGET_TYPE,
- _rtgui_listbox_constructor,
- RT_NULL,
- sizeof(struct rtgui_listbox));
+DEFINE_CLASS_TYPE(listbox, "listbox",
+ RTGUI_WIDGET_TYPE,
+ _rtgui_listbox_constructor,
+ RT_NULL,
+ sizeof(struct rtgui_listbox));
-void rtgui_listbox_ondraw(struct rtgui_listbox* box)
+void rtgui_listbox_ondraw(struct rtgui_listbox *box)
{
- struct rtgui_dc* dc;
- rt_uint16_t page_index, index;
- const struct rtgui_listbox_item* item;
- struct rtgui_rect rect, item_rect, image_rect;
+ struct rtgui_dc *dc;
+ rt_uint16_t page_index, index;
+ const struct rtgui_listbox_item *item;
+ struct rtgui_rect rect, item_rect, image_rect;
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
- if (dc == RT_NULL) return;
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
+ if (dc == RT_NULL) return;
- rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
- rtgui_dc_fill_rect(dc, &rect);
+ rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
+ rtgui_dc_fill_rect(dc, &rect);
- rect.x2 -= 1; rect.y2 -= 1;
- /* draw focused border */
- if (RTGUI_WIDGET_IS_FOCUSED(box))
- rtgui_dc_draw_focus_rect(dc, &rect);
+ rect.x2 -= 1;
+ rect.y2 -= 1;
+ /* draw focused border */
+ if (RTGUI_WIDGET_IS_FOCUSED(box))
+ rtgui_dc_draw_focus_rect(dc, &rect);
- /* get item base rect */
- item_rect = rect;
- item_rect.x1 += 1; item_rect.x2 -= 1;
- item_rect.y1 += 2;
- item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
+ /* get item base rect */
+ item_rect = rect;
+ item_rect.x1 += 1;
+ item_rect.x2 -= 1;
+ item_rect.y1 += 2;
+ item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
- /* get current page */
- if (box->current_item == -1)
- page_index = 0;
- else
- page_index = (box->current_item / box->page_items) * box->page_items;
+ /* get current page */
+ if (box->current_item == -1)
+ page_index = 0;
+ else
+ page_index = (box->current_item / box->page_items) * box->page_items;
- for (index = 0; index < box->page_items; index ++)
- {
- if (page_index + index >= box->items_count) break;
+ for (index = 0; index < box->page_items; index ++)
+ {
+ if (page_index + index >= box->items_count) break;
- item = &(box->items[page_index + index]);
+ item = &(box->items[page_index + index]);
- if (page_index + index == box->current_item)
- {
- rtgui_theme_draw_selected(dc, &item_rect);
- }
- item_rect.x1 += LIST_MARGIN;
+ if (page_index + index == box->current_item)
+ {
+ rtgui_theme_draw_selected(dc, &item_rect);
+ }
+ item_rect.x1 += LIST_MARGIN;
- if (item->image != RT_NULL)
- {
- rtgui_image_get_rect(item->image, &image_rect);
- rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
+ if (item->image != RT_NULL)
+ {
+ rtgui_image_get_rect(item->image, &image_rect);
+ rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
- rtgui_image_blit(item->image, dc, &image_rect);
- item_rect.x1 += item->image->w + 2;
- }
+ rtgui_image_blit(item->image, dc, &image_rect);
+ item_rect.x1 += item->image->w + 2;
+ }
/* draw text */
- rtgui_dc_draw_text(dc, item->name, &item_rect);
+ 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;
+ 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);
+ item_rect.y1 += (rtgui_theme_get_selected_height() + 2);
+ item_rect.y2 += (rtgui_theme_get_selected_height() + 2);
+ }
+ rtgui_dc_end_drawing(dc);
}
RTM_EXPORT(rtgui_listbox_ondraw);
-static void rtgui_listbox_update_current(struct rtgui_listbox* box, rt_int16_t old_item)
+static void rtgui_listbox_update_current(struct rtgui_listbox *box, rt_int16_t old_item)
{
- struct rtgui_dc* dc;
- const struct rtgui_listbox_item* item;
- rtgui_rect_t rect, item_rect, image_rect;
+ struct rtgui_dc *dc;
+ const struct rtgui_listbox_item *item;
+ rtgui_rect_t rect, item_rect, image_rect;
+
+ if ((old_item == -1) || (old_item / box->page_items != box->current_item / box->page_items))
+ {
+ /* it's not a same page, update all */
+ rtgui_widget_update(RTGUI_WIDGET(box));
+ return;
+ }
- if ((old_item == -1) || (old_item/box->page_items != box->current_item/box->page_items))
- {
- /* it's not a same page, update all */
- rtgui_widget_update(RTGUI_WIDGET(box));
- return;
- }
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
+ if (dc == RT_NULL) return;
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
- if (dc == RT_NULL) return;
+ rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
+ rect.x2 -= 1;
+ rect.y2 -= 1;
- rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
- rect.x2 -= 1; rect.y2 -= 1;
+ item_rect = rect;
+ /* get old item's rect */
+ item_rect.x1 += 1;
+ item_rect.x2 -= 1;
+ item_rect.y1 += 2;
+ item_rect.y1 += (old_item % box->page_items) * (2 + rtgui_theme_get_selected_height());
+ item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
- item_rect = rect;
- /* get old item's rect */
- item_rect.x1 += 1; item_rect.x2 -= 1;
- item_rect.y1 += 2;
- item_rect.y1 += (old_item % box->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);
- /* draw old item */
- rtgui_dc_fill_rect(dc, &item_rect);
+ item_rect.x1 += LIST_MARGIN;
- item_rect.x1 += LIST_MARGIN;
+ item = &(box->items[old_item]);
+ if (item->image != RT_NULL)
+ {
+ rtgui_image_get_rect(item->image, &image_rect);
+ rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
- item = &(box->items[old_item]);
- if (item->image != RT_NULL)
- {
- rtgui_image_get_rect(item->image, &image_rect);
- rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
-
- rtgui_image_blit(item->image, dc, &image_rect);
- item_rect.x1 += item->image->w + 2;
- }
- rtgui_dc_draw_text(dc, item->name, &item_rect);
+ rtgui_image_blit(item->image, dc, &image_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.x1 += 1; item_rect.x2 -= 1;
- item_rect.y1 += 2;
- item_rect.y1 += (box->current_item % box->page_items) * (2 + rtgui_theme_get_selected_height());
- item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
+ /* draw current item */
+ item_rect = rect;
+ /* get current item's rect */
+ item_rect.x1 += 1;
+ item_rect.x2 -= 1;
+ item_rect.y1 += 2;
+ item_rect.y1 += (box->current_item % box->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);
+ /* draw current item */
+ rtgui_theme_draw_selected(dc, &item_rect);
- item_rect.x1 += LIST_MARGIN;
+ item_rect.x1 += LIST_MARGIN;
- item = &(box->items[box->current_item]);
- if (item->image != RT_NULL)
- {
- rtgui_image_get_rect(item->image, &image_rect);
- rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
+ item = &(box->items[box->current_item]);
+ if (item->image != RT_NULL)
+ {
+ rtgui_image_get_rect(item->image, &image_rect);
+ rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
- rtgui_image_blit(item->image, dc, &image_rect);
+ rtgui_image_blit(item->image, dc, &image_rect);
item_rect.x1 += (item->image->w + 2);
- }
- rtgui_dc_draw_text(dc, item->name, &item_rect);
+ }
+ rtgui_dc_draw_text(dc, item->name, &item_rect);
- rtgui_dc_end_drawing(dc);
+ rtgui_dc_end_drawing(dc);
}
-rt_bool_t rtgui_listbox_event_handler(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_listbox_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_listbox* box;
- RTGUI_WIDGET_EVENT_HANDLER_PREPARE
+ struct rtgui_listbox *box;
+ RTGUI_WIDGET_EVENT_HANDLER_PREPARE
- box = RTGUI_LISTBOX(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- rtgui_listbox_ondraw(box);
- return RT_FALSE;
+ box = RTGUI_LISTBOX(object);
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
+ rtgui_listbox_ondraw(box);
+ return RT_FALSE;
case RTGUI_EVENT_RESIZE:
- {
- struct rtgui_event_resize* resize;
+ {
+ struct rtgui_event_resize *resize;
- resize = (struct rtgui_event_resize*)event;
+ resize = (struct rtgui_event_resize *)event;
- /* recalculate page items */
- box->page_items = resize->h / (2 + rtgui_theme_get_selected_height());
- }
- break;
+ /* recalculate page items */
+ box->page_items = resize->h / (2 + rtgui_theme_get_selected_height());
+ }
+ break;
- case RTGUI_EVENT_MOUSE_BUTTON:
- {
- rtgui_rect_t rect;
- struct rtgui_event_mouse* emouse;
+ case RTGUI_EVENT_MOUSE_BUTTON:
+ {
+ rtgui_rect_t rect;
+ struct rtgui_event_mouse *emouse;
- emouse = (struct rtgui_event_mouse*)event;
+ emouse = (struct rtgui_event_mouse *)event;
- /* calculate selected item */
+ /* calculate selected item */
- /* get physical extent information */
- rtgui_widget_get_rect(widget, &rect);
- rtgui_widget_rect_to_device(widget, &rect);
+ /* get physical extent information */
+ rtgui_widget_get_rect(widget, &rect);
+ rtgui_widget_rect_to_device(widget, &rect);
- if ((rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK) && (box->items_count > 0))
- {
- rt_uint16_t index;
- index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());
+ if ((rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK) && (box->items_count > 0))
+ {
+ rt_uint16_t index;
+ index = (emouse->y - rect.y1) / (2 + rtgui_theme_get_selected_height());
- /* set focus */
- rtgui_widget_focus(widget);
- {
- struct rtgui_rect rect;
- struct rtgui_dc* dc;
+ /* set focus */
+ rtgui_widget_focus(widget);
+ {
+ struct rtgui_rect rect;
+ struct rtgui_dc *dc;
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
- if (dc != RT_NULL)
- {
- /* get widget rect */
- rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
- /* update focus border */
- rect.x2 -= 1; rect.y2 -= 1;
- /* draw focused border */
- if (RTGUI_WIDGET_IS_FOCUSED(box))
- rtgui_dc_draw_focus_rect(dc, &rect);
- rtgui_dc_end_drawing(dc);
- }
- }
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
+ if (dc != RT_NULL)
+ {
+ /* get widget rect */
+ rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
+ /* update focus border */
+ rect.x2 -= 1;
+ rect.y2 -= 1;
+ /* draw focused border */
+ if (RTGUI_WIDGET_IS_FOCUSED(box))
+ rtgui_dc_draw_focus_rect(dc, &rect);
+ rtgui_dc_end_drawing(dc);
+ }
+ }
- if ((index < box->items_count) && (index < box->page_items))
- {
- rt_uint16_t old_item;
+ if ((index < box->items_count) && (index < box->page_items))
+ {
+ rt_uint16_t old_item;
- old_item = box->current_item;
+ old_item = box->current_item;
- /* set selected item */
- box->current_item = (box->current_item/box->page_items) * box->page_items + index;
- if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
- {
- /* down event */
- rtgui_listbox_update_current(box, old_item);
- }
- else
- {
- /* up event */
- if (box->on_item != RT_NULL)
- {
- box->on_item(RTGUI_OBJECT(box), RT_NULL);
- }
- }
- }
- }
+ /* set selected item */
+ box->current_item = (box->current_item / box->page_items) * box->page_items + index;
+ if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
+ {
+ /* down event */
+ rtgui_listbox_update_current(box, old_item);
+ }
+ else
+ {
+ /* up event */
+ if (box->on_item != RT_NULL)
+ {
+ box->on_item(RTGUI_OBJECT(box), RT_NULL);
+ }
+ }
+ }
+ }
- return RT_TRUE;
- }
+ return RT_TRUE;
+ }
case RTGUI_EVENT_KBD:
+ {
+ struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
+ if ((ekbd->type == RTGUI_KEYDOWN) && (box->items_count > 0))
{
- struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
- if ((ekbd->type == RTGUI_KEYDOWN) && (box->items_count > 0))
- {
- rt_int16_t old_item;
+ rt_int16_t old_item;
- if (box->current_item == -1)
- {
- /* set a initial item */
- if ((box->items_count > 0) &&
- (ekbd->key == RTGUIK_UP || ekbd->key == RTGUIK_DOWN))
- {
- box->current_item = 0;
- rtgui_listbox_update_current(box, -1);
- return RT_TRUE;
- }
- else
- return RT_FALSE;
- }
- old_item = box->current_item;
-
- switch (ekbd->key)
+ if (box->current_item == -1)
+ {
+ /* set a initial item */
+ if ((box->items_count > 0) &&
+ (ekbd->key == RTGUIK_UP || ekbd->key == RTGUIK_DOWN))
{
- case RTGUIK_LEFT:
- if (box->current_item - box->page_items >= 0)
- box->current_item -= box->page_items;
- rtgui_listbox_update_current(box, old_item);
- return RT_TRUE;
+ box->current_item = 0;
+ rtgui_listbox_update_current(box, -1);
+ return RT_TRUE;
+ }
+ else
+ return RT_FALSE;
+ }
+ old_item = box->current_item;
- case RTGUIK_UP:
- if (box->current_item > 0)
- box->current_item --;
- rtgui_listbox_update_current(box, old_item);
- return RT_TRUE;
+ switch (ekbd->key)
+ {
+ case RTGUIK_LEFT:
+ if (box->current_item - box->page_items >= 0)
+ box->current_item -= box->page_items;
+ rtgui_listbox_update_current(box, old_item);
+ return RT_TRUE;
- case RTGUIK_RIGHT:
- if (box->current_item + box->page_items < box->items_count - 1)
- box->current_item += box->page_items;
- rtgui_listbox_update_current(box, old_item);
- return RT_TRUE;
+ case RTGUIK_UP:
+ if (box->current_item > 0)
+ box->current_item --;
+ rtgui_listbox_update_current(box, old_item);
+ return RT_TRUE;
- case RTGUIK_DOWN:
- if (box->current_item < box->items_count - 1)
- box->current_item ++;
- rtgui_listbox_update_current(box, old_item);
- return RT_TRUE;
+ case RTGUIK_RIGHT:
+ if (box->current_item + box->page_items < box->items_count - 1)
+ box->current_item += box->page_items;
+ rtgui_listbox_update_current(box, old_item);
+ return RT_TRUE;
- case RTGUIK_RETURN:
- if (box->on_item != RT_NULL)
- box->on_item(RTGUI_OBJECT(box), RT_NULL);
- return RT_TRUE;
+ case RTGUIK_DOWN:
+ if (box->current_item < box->items_count - 1)
+ box->current_item ++;
+ rtgui_listbox_update_current(box, old_item);
+ return RT_TRUE;
- default:
- break;
- }
+ case RTGUIK_RETURN:
+ if (box->on_item != RT_NULL)
+ box->on_item(RTGUI_OBJECT(box), RT_NULL);
+ return RT_TRUE;
+
+ default:
+ break;
}
}
- return RT_FALSE;
- }
-
+ }
+ return RT_FALSE;
+ default:
/* use box event handler */
return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
+ }
+
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_listbox_event_handler);
-rtgui_listbox_t* rtgui_listbox_create(const struct rtgui_listbox_item* items, rt_uint16_t count, rtgui_rect_t *rect)
+rtgui_listbox_t *rtgui_listbox_create(const struct rtgui_listbox_item *items, rt_uint16_t count, rtgui_rect_t *rect)
{
- struct rtgui_listbox* box = RT_NULL;
+ struct rtgui_listbox *box = RT_NULL;
- box = (struct rtgui_listbox*) rtgui_widget_create(RTGUI_LISTBOX_TYPE);
- if (box != RT_NULL)
- {
- box->items = items;
- box->items_count = count;
+ box = (struct rtgui_listbox *) rtgui_widget_create(RTGUI_LISTBOX_TYPE);
+ if (box != RT_NULL)
+ {
+ box->items = items;
+ box->items_count = count;
- box->page_items = rtgui_rect_height(*rect) / (2 + rtgui_theme_get_selected_height());
- if (box->page_items == 0) box->page_items = 1;
- rtgui_widget_set_rect(RTGUI_WIDGET(box), rect);
- }
+ box->page_items = rtgui_rect_height(*rect) / (2 + rtgui_theme_get_selected_height());
+ if (box->page_items == 0) box->page_items = 1;
+ rtgui_widget_set_rect(RTGUI_WIDGET(box), rect);
+ }
- return box;
+ return box;
}
RTM_EXPORT(rtgui_listbox_create);
-void rtgui_listbox_destroy(rtgui_listbox_t* box)
+void rtgui_listbox_destroy(rtgui_listbox_t *box)
{
/* destroy box */
- rtgui_widget_destroy(RTGUI_WIDGET(box));
+ rtgui_widget_destroy(RTGUI_WIDGET(box));
}
RTM_EXPORT(rtgui_listbox_destroy);
-void rtgui_listbox_set_onitem(rtgui_listbox_t* box, rtgui_event_handler_ptr func)
+void rtgui_listbox_set_onitem(rtgui_listbox_t *box, rtgui_event_handler_ptr func)
{
- RT_ASSERT(box != RT_NULL);
+ RT_ASSERT(box != RT_NULL);
- box->on_item = func;
+ box->on_item = func;
}
RTM_EXPORT(rtgui_listbox_set_onitem);
-void rtgui_listbox_set_items(rtgui_listbox_t* box, struct rtgui_listbox_item* items, rt_uint16_t count)
+void rtgui_listbox_set_items(rtgui_listbox_t *box, struct rtgui_listbox_item *items, rt_uint16_t count)
{
- rtgui_rect_t rect;
+ rtgui_rect_t rect;
- box->items = items;
- box->items_count = count;
- box->current_item = -1;
+ box->items = items;
+ box->items_count = count;
+ box->current_item = -1;
- rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
- box->page_items = rtgui_rect_height(rect) / (2 + rtgui_theme_get_selected_height());
+ rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
+ box->page_items = rtgui_rect_height(rect) / (2 + rtgui_theme_get_selected_height());
- rtgui_widget_update(RTGUI_WIDGET(box));
+ rtgui_widget_update(RTGUI_WIDGET(box));
}
RTM_EXPORT(rtgui_listbox_set_items);
-void rtgui_listbox_set_current_item(rtgui_listbox_t* box, int index)
+void rtgui_listbox_set_current_item(rtgui_listbox_t *box, int index)
{
- RT_ASSERT(box != RT_NULL);
+ RT_ASSERT(box != RT_NULL);
- if (index != box->current_item)
- {
- int old_item;
+ if (index >= box->items_count)
+ return;
- old_item = box->current_item;
- box->current_item = index;
+ if (index != box->current_item)
+ {
+ int old_item;
- rtgui_listbox_update_current(box, old_item);
- }
+ old_item = box->current_item;
+ box->current_item = index;
+ rtgui_listbox_update_current(box, old_item);
+ }
+ if (box->on_item)
+ box->on_item(RTGUI_OBJECT(box), RT_NULL);
}
RTM_EXPORT(rtgui_listbox_set_current_item);
-static rt_bool_t rtgui_listbox_onunfocus(struct rtgui_object* object, rtgui_event_t* event)
+static rt_bool_t rtgui_listbox_onunfocus(struct rtgui_object *object, rtgui_event_t *event)
{
- rtgui_rect_t rect;
- rtgui_widget_t *widget;
- struct rtgui_dc *dc;
+ rtgui_rect_t rect;
+ rtgui_widget_t *widget;
+ struct rtgui_dc *dc;
- RT_ASSERT(object);
- widget = RTGUI_WIDGET(object);
+ RT_ASSERT(object);
+ widget = RTGUI_WIDGET(object);
- dc = rtgui_dc_begin_drawing(widget);
- if(dc == RT_NULL) return RT_FALSE;
+ dc = rtgui_dc_begin_drawing(widget);
+ if (dc == RT_NULL) return RT_FALSE;
- rtgui_widget_get_rect(widget, &rect);
+ rtgui_widget_get_rect(widget, &rect);
- if(!RTGUI_WIDGET_IS_FOCUSED(widget))
- {
- /* only clear focus rect */
- rtgui_color_t color;
- rect.x2 -= 1; rect.y2 -= 1;
- color = RTGUI_DC_FC(dc);
- RTGUI_DC_FC(dc) = RTGUI_DC_BC(dc);
- rtgui_dc_draw_focus_rect(dc, &rect);
- RTGUI_DC_FC(dc) = color;
- }
+ if (!RTGUI_WIDGET_IS_FOCUSED(widget))
+ {
+ /* only clear focus rect */
+ rtgui_color_t color;
+ rect.x2 -= 1;
+ rect.y2 -= 1;
+ color = RTGUI_DC_FC(dc);
+ RTGUI_DC_FC(dc) = RTGUI_DC_BC(dc);
+ rtgui_dc_draw_focus_rect(dc, &rect);
+ RTGUI_DC_FC(dc) = color;
+ }
- rtgui_dc_end_drawing(dc);
- return RT_TRUE;
+ rtgui_dc_end_drawing(dc);
+ return RT_TRUE;
}
diff --git a/components/rtgui/widgets/listctrl.c b/components/rtgui/widgets/listctrl.c
index 892a08633a..8c6409c084 100644
--- a/components/rtgui/widgets/listctrl.c
+++ b/components/rtgui/widgets/listctrl.c
@@ -15,433 +15,473 @@
#include <rtgui/rtgui_theme.h>
#include <rtgui/widgets/listctrl.h>
-static void rtgui_listctrl_update_current(struct rtgui_listctrl* ctrl, rt_uint16_t old_item);
+static void rtgui_listctrl_update_current(struct rtgui_listctrl *ctrl, rt_uint16_t old_item);
static void _rtgui_listctrl_constructor(struct rtgui_listctrl *ctrl)
{
- /* set default widget rect and set event handler */
- rtgui_object_set_event_handler(RTGUI_OBJECT(ctrl), rtgui_listctrl_event_handler);
+ /* set default widget rect and set event handler */
+ rtgui_object_set_event_handler(RTGUI_OBJECT(ctrl), rtgui_listctrl_event_handler);
- RTGUI_WIDGET(ctrl)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+ RTGUI_WIDGET(ctrl)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- ctrl->current_item = -1;
- ctrl->item_height = rtgui_theme_get_selected_height();
- ctrl->items_count = 0;
- ctrl->page_items = 0;
- ctrl->on_item = 0;
- ctrl->on_item_draw = RT_NULL;
+ ctrl->current_item = -1;
+ ctrl->item_height = rtgui_theme_get_selected_height();
+ ctrl->items_count = 0;
+ ctrl->page_items = 0;
+ ctrl->on_item = 0;
+ ctrl->on_item_draw = RT_NULL;
- RTGUI_WIDGET_BACKGROUND(ctrl) = white;
- RTGUI_WIDGET_TEXTALIGN(ctrl) = RTGUI_ALIGN_CENTER_VERTICAL;
+ RTGUI_WIDGET_BACKGROUND(ctrl) = white;
+ RTGUI_WIDGET_TEXTALIGN(ctrl) = RTGUI_ALIGN_CENTER_VERTICAL;
}
DEFINE_CLASS_TYPE(listctrl, "listctrl",
- RTGUI_WIDGET_TYPE,
- _rtgui_listctrl_constructor,
- RT_NULL,
- sizeof(struct rtgui_listctrl));
+ RTGUI_WIDGET_TYPE,
+ _rtgui_listctrl_constructor,
+ RT_NULL,
+ sizeof(struct rtgui_listctrl));
-static void _rtgui_listctrl_get_rect(struct rtgui_listctrl* ctrl, rtgui_rect_t* rect)
+static void _rtgui_listctrl_get_rect(struct rtgui_listctrl *ctrl, rtgui_rect_t *rect)
{
- rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), rect);
- if (ctrl->items_count > rtgui_rect_height(*rect)/ctrl->item_height)
- {
- rect->x2 = rect->x2 - 8;
- }
+ rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), rect);
+ if (ctrl->items_count > rtgui_rect_height(*rect) / ctrl->item_height)
+ {
+ rect->x2 = rect->x2 - 8;
+ }
}
-static void _rtgui_listctrl_get_scrollbar_rect(struct rtgui_listctrl* ctrl, rtgui_rect_t* rect)
+static void _rtgui_listctrl_get_scrollbar_rect(struct rtgui_listctrl *ctrl, rtgui_rect_t *rect)
{
- rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), rect);
- if (ctrl->items_count > rtgui_rect_height(*rect)/ctrl->item_height)
- {
- rect->x1 = rect->x2 - 8;
- }
- else
- {
- /* no scrollbar */
- rt_memset(rect, 0, sizeof(rtgui_rect_t));
- }
+ rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), rect);
+ if (ctrl->items_count > rtgui_rect_height(*rect) / ctrl->item_height)
+ {
+ rect->x1 = rect->x2 - 8;
+ }
+ else
+ {
+ /* no scrollbar */
+ rt_memset(rect, 0, sizeof(rtgui_rect_t));
+ }
}
-static void _rtgui_listctrl_scrollbar_ondraw(struct rtgui_listctrl* ctrl, struct rtgui_dc* dc)
+static void _rtgui_listctrl_scrollbar_ondraw(struct rtgui_listctrl *ctrl, struct rtgui_dc *dc)
{
- rtgui_rect_t rect;
- rt_uint32_t height, y1;
+ rtgui_rect_t rect;
+ rt_uint32_t height, y1;
- /* get scrollbar rect */
- _rtgui_listctrl_get_scrollbar_rect(ctrl, &rect);
- if (rtgui_rect_is_empty(&rect) == RT_TRUE) return;
+ /* get scrollbar rect */
+ _rtgui_listctrl_get_scrollbar_rect(ctrl, &rect);
+ if (rtgui_rect_is_empty(&rect) == RT_TRUE) return;
- rtgui_dc_fill_rect(dc, &rect);
+ rtgui_dc_fill_rect(dc, &rect);
- height = rtgui_rect_height(rect);
- height = height / ((ctrl->items_count + (ctrl->page_items - 1))/ctrl->page_items);
- y1 = (ctrl->current_item / ctrl->page_items) * height;
+ height = rtgui_rect_height(rect);
+ height = height / ((ctrl->items_count + (ctrl->page_items - 1)) / ctrl->page_items);
+ y1 = (ctrl->current_item / ctrl->page_items) * height;
- rect.y1 = rect.y1 + y1; rect.y2 = rect.y1 + height;
- rect.x1 -= 3;
- rtgui_theme_draw_selected(dc, &rect);
+ rect.y1 = rect.y1 + y1;
+ rect.y2 = rect.y1 + height;
+ rect.x1 -= 3;
+ rtgui_theme_draw_selected(dc, &rect);
}
-static void _rtgui_listctrl_scrollbar_onmouse(struct rtgui_listctrl* ctrl, struct rtgui_event_mouse* mouse)
+static void _rtgui_listctrl_scrollbar_onmouse(struct rtgui_listctrl *ctrl, struct rtgui_event_mouse *mouse)
{
- rtgui_rect_t rect;
- rt_uint32_t height, y1;
- rt_uint16_t old_item;
+ rtgui_rect_t rect;
+ rt_uint32_t height, y1;
+ rt_uint16_t old_item;
- /* get scrollbar rect */
- _rtgui_listctrl_get_scrollbar_rect(ctrl, &rect);
- height = rtgui_rect_height(rect);
- height = height / ((ctrl->items_count + (ctrl->page_items - 1))/ctrl->page_items);
- y1 = (ctrl->current_item / ctrl->page_items) * height;
+ /* get scrollbar rect */
+ _rtgui_listctrl_get_scrollbar_rect(ctrl, &rect);
+ height = rtgui_rect_height(rect);
+ height = height / ((ctrl->items_count + (ctrl->page_items - 1)) / ctrl->page_items);
+ y1 = (ctrl->current_item / ctrl->page_items) * height;
- rect.y1 = rect.y1 + y1; rect.y2 = rect.y1 + height;
- rtgui_widget_rect_to_device(RTGUI_WIDGET(ctrl), &rect);
+ rect.y1 = rect.y1 + y1;
+ rect.y2 = rect.y1 + height;
+ rtgui_widget_rect_to_device(RTGUI_WIDGET(ctrl), &rect);
- old_item = ctrl->current_item;
- if (mouse->y < rect.y1)
- {
- if (ctrl->current_item - ctrl->page_items >= 0)
- ctrl->current_item -= ctrl->page_items;
- rtgui_listctrl_update_current(ctrl, old_item);
- }
- else if (mouse->y > rect.y2)
- {
- if (ctrl->current_item + ctrl->page_items < ctrl->items_count - 1)
- ctrl->current_item += ctrl->page_items;
- else
- ctrl->current_item = ((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items;
- rtgui_listctrl_update_current(ctrl, old_item);
- }
+ old_item = ctrl->current_item;
+ if (mouse->y < rect.y1)
+ {
+ if (ctrl->current_item - ctrl->page_items >= 0)
+ ctrl->current_item -= ctrl->page_items;
+ rtgui_listctrl_update_current(ctrl, old_item);
+ }
+ else if (mouse->y > rect.y2)
+ {
+ if (ctrl->current_item + ctrl->page_items < ctrl->items_count - 1)
+ ctrl->current_item += ctrl->page_items;
+ else
+ ctrl->current_item = ((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items;
+ rtgui_listctrl_update_current(ctrl, old_item);
+ }
}
-static void _rtgui_listctrl_ondraw(struct rtgui_listctrl* ctrl)
+static void _rtgui_listctrl_ondraw(struct rtgui_listctrl *ctrl)
{
- struct rtgui_rect rect, item_rect;
- struct rtgui_dc* dc;
- rt_uint16_t page_index, index;
+ struct rtgui_rect rect, item_rect;
+ struct rtgui_dc *dc;
+ rt_uint16_t page_index, index;
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(ctrl));
- if (dc == RT_NULL) return;
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(ctrl));
+ if (dc == RT_NULL) return;
- _rtgui_listctrl_get_rect(ctrl, &rect);
- rtgui_dc_fill_rect(dc, &rect);
+ _rtgui_listctrl_get_rect(ctrl, &rect);
+ rtgui_dc_fill_rect(dc, &rect);
- rect.x2 -= 1; rect.y2 -= 1;
+ rect.x2 -= 1;
+ rect.y2 -= 1;
- /* get item base rect */
- item_rect = rect;
- item_rect.x1 += 1; item_rect.x2 -= 1;
- item_rect.y1 += 2;
- item_rect.y2 = item_rect.y1 + (2 + ctrl->item_height);
+ /* get item base rect */
+ item_rect = rect;
+ item_rect.x1 += 1;
+ item_rect.x2 -= 1;
+ item_rect.y1 += 2;
+ item_rect.y2 = item_rect.y1 + (2 + ctrl->item_height);
- /* get current page */
- page_index = (ctrl->current_item / ctrl->page_items) * ctrl->page_items;
- for (index = 0; index < ctrl->page_items; index ++)
- {
- if (page_index + index >= ctrl->items_count) break;
+ /* get current page */
+ page_index = (ctrl->current_item / ctrl->page_items) * ctrl->page_items;
+ for (index = 0; index < ctrl->page_items; index ++)
+ {
+ if (page_index + index >= ctrl->items_count) break;
- if (page_index + index == ctrl->current_item)
- {
- rtgui_theme_draw_selected(dc, &item_rect);
- }
+ if (page_index + index == ctrl->current_item)
+ {
+ rtgui_theme_draw_selected(dc, &item_rect);
+ }
- if (ctrl->on_item_draw != RT_NULL)
- {
- ctrl->on_item_draw(ctrl, dc, &item_rect, page_index + index);
- }
+ if (ctrl->on_item_draw != RT_NULL)
+ {
+ ctrl->on_item_draw(ctrl, dc, &item_rect, page_index + index);
+ }
/* move to next item position */
- item_rect.y1 += (ctrl->item_height + 2);
- item_rect.y2 += (ctrl->item_height + 2);
- }
+ item_rect.y1 += (ctrl->item_height + 2);
+ item_rect.y2 += (ctrl->item_height + 2);
+ }
- /* draw scrollbar */
- _rtgui_listctrl_scrollbar_ondraw(ctrl, dc);
- rtgui_dc_end_drawing(dc);
+ /* draw scrollbar */
+ _rtgui_listctrl_scrollbar_ondraw(ctrl, dc);
+ rtgui_dc_end_drawing(dc);
}
-void rtgui_listctrl_update_current(struct rtgui_listctrl* ctrl, rt_uint16_t old_item)
+void rtgui_listctrl_update_current(struct rtgui_listctrl *ctrl, rt_uint16_t old_item)
{
- struct rtgui_dc* dc;
- rtgui_rect_t rect, item_rect;
+ struct rtgui_dc *dc;
+ rtgui_rect_t rect, item_rect;
- if (old_item/ctrl->page_items != ctrl->current_item/ctrl->page_items)
- {
- /* it's not a same page, update all */
- rtgui_widget_update(RTGUI_WIDGET(ctrl));
- return;
- }
+ if (old_item / ctrl->page_items != ctrl->current_item / ctrl->page_items)
+ {
+ /* it's not a same page, update all */
+ rtgui_widget_update(RTGUI_WIDGET(ctrl));
+ return;
+ }
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(ctrl));
- if (dc == RT_NULL) return;
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(ctrl));
+ if (dc == RT_NULL) return;
- _rtgui_listctrl_get_rect(ctrl, &rect);
- rect.x2 -= 1; rect.y2 -= 1;
+ _rtgui_listctrl_get_rect(ctrl, &rect);
+ rect.x2 -= 1;
+ rect.y2 -= 1;
- item_rect = rect;
- /* get old item's rect */
- item_rect.x1 += 1; item_rect.x2 -= 1;
- item_rect.y1 += 2;
- item_rect.y1 += (old_item % ctrl->page_items) * (2 + ctrl->item_height);
- item_rect.y2 = item_rect.y1 + (2 + ctrl->item_height);
+ item_rect = rect;
+ /* get old item's rect */
+ item_rect.x1 += 1;
+ item_rect.x2 -= 1;
+ item_rect.y1 += 2;
+ item_rect.y1 += (old_item % ctrl->page_items) * (2 + ctrl->item_height);
+ item_rect.y2 = item_rect.y1 + (2 + ctrl->item_height);
- /* draw old item */
- rtgui_dc_fill_rect(dc, &item_rect);
- if (ctrl->on_item_draw != RT_NULL)
- ctrl->on_item_draw(ctrl, dc, &item_rect, old_item);
+ /* draw old item */
+ rtgui_dc_fill_rect(dc, &item_rect);
+ if (ctrl->on_item_draw != RT_NULL)
+ ctrl->on_item_draw(ctrl, dc, &item_rect, old_item);
- /* draw current item */
- item_rect = rect;
- /* get current item's rect */
- item_rect.x1 += 1; item_rect.x2 -= 1;
- item_rect.y1 += 2;
- item_rect.y1 += (ctrl->current_item % ctrl->page_items) * (2 + ctrl->item_height);
- item_rect.y2 = item_rect.y1 + (2 + ctrl->item_height);
+ /* draw current item */
+ item_rect = rect;
+ /* get current item's rect */
+ item_rect.x1 += 1;
+ item_rect.x2 -= 1;
+ item_rect.y1 += 2;
+ item_rect.y1 += (ctrl->current_item % ctrl->page_items) * (2 + ctrl->item_height);
+ item_rect.y2 = item_rect.y1 + (2 + ctrl->item_height);
- /* draw current item */
- rtgui_theme_draw_selected(dc, &item_rect);
- if (ctrl->on_item_draw != RT_NULL)
- ctrl->on_item_draw(ctrl, dc, &item_rect, ctrl->current_item);
+ /* draw current item */
+ rtgui_theme_draw_selected(dc, &item_rect);
+ if (ctrl->on_item_draw != RT_NULL)
+ ctrl->on_item_draw(ctrl, dc, &item_rect, ctrl->current_item);
- rtgui_dc_end_drawing(dc);
+ rtgui_dc_end_drawing(dc);
}
RTM_EXPORT(rtgui_listctrl_update_current);
-rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_listctrl_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_listctrl* ctrl;
- RTGUI_WIDGET_EVENT_HANDLER_PREPARE
+ struct rtgui_listctrl *ctrl;
+ RTGUI_WIDGET_EVENT_HANDLER_PREPARE
- ctrl = RTGUI_LISTCTRL(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- _rtgui_listctrl_ondraw(ctrl);
- return RT_FALSE;
+ ctrl = RTGUI_LISTCTRL(object);
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
+ _rtgui_listctrl_ondraw(ctrl);
+ return RT_FALSE;
case RTGUI_EVENT_RESIZE:
- {
- struct rtgui_event_resize* resize;
+ {
+ struct rtgui_event_resize *resize;
- resize = (struct rtgui_event_resize*)event;
+ resize = (struct rtgui_event_resize *)event;
- /* recalculate page items */
- ctrl->page_items = resize->h / (2 + ctrl->item_height);
- }
- break;
+ /* recalculate page items */
+ ctrl->page_items = resize->h / (2 + ctrl->item_height);
+ }
+ break;
- case RTGUI_EVENT_MOUSE_BUTTON:
- {
- rtgui_rect_t rect;
- struct rtgui_event_mouse* emouse;
+ case RTGUI_EVENT_MOUSE_BUTTON:
+ {
+ rtgui_rect_t rect;
+ struct rtgui_event_mouse *emouse;
- emouse = (struct rtgui_event_mouse*)event;
+ emouse = (struct rtgui_event_mouse *)event;
- /* get scrollbar rect */
- _rtgui_listctrl_get_scrollbar_rect(ctrl, &rect);
- rtgui_widget_rect_to_device(RTGUI_WIDGET(ctrl), &rect);
- if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
- {
- _rtgui_listctrl_scrollbar_onmouse(ctrl, emouse);
- return RT_TRUE;
- }
+ /* get scrollbar rect */
+ _rtgui_listctrl_get_scrollbar_rect(ctrl, &rect);
+ rtgui_widget_rect_to_device(RTGUI_WIDGET(ctrl), &rect);
+ if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
+ {
+ _rtgui_listctrl_scrollbar_onmouse(ctrl, emouse);
+ return RT_TRUE;
+ }
- /* calculate selected item */
+ /* calculate selected item */
- /* get physical extent information */
- _rtgui_listctrl_get_rect(ctrl, &rect);
- rtgui_widget_rect_to_device(widget, &rect);
+ /* get physical extent information */
+ _rtgui_listctrl_get_rect(ctrl, &rect);
+ rtgui_widget_rect_to_device(widget, &rect);
- if ((rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK) &&
- (ctrl->items_count > 0))
- {
- rt_uint16_t index;
- index = (emouse->y - rect.y1) / (2 + ctrl->item_height);
+ if ((rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK) &&
+ (ctrl->items_count > 0))
+ {
+ rt_uint16_t index;
+ index = (emouse->y - rect.y1) / (2 + ctrl->item_height);
- /* set focus */
- rtgui_widget_focus(widget);
- {
- struct rtgui_rect rect;
- struct rtgui_dc* dc;
+ /* set focus */
+ rtgui_widget_focus(widget);
+ {
+ struct rtgui_rect rect;
+ struct rtgui_dc *dc;
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(ctrl));
- if (dc != RT_NULL)
- {
- /* get widget rect */
- rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), &rect);
- /* update focus border */
- rect.x2 -= 1; rect.y2 -= 1;
- rtgui_dc_end_drawing(dc);
- }
- }
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(ctrl));
+ if (dc != RT_NULL)
+ {
+ /* get widget rect */
+ rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), &rect);
+ /* update focus border */
+ rect.x2 -= 1;
+ rect.y2 -= 1;
+ rtgui_dc_end_drawing(dc);
+ }
+ }
- if ((index < ctrl->page_items) &&
- (ctrl->current_item/ctrl->page_items)* ctrl->page_items + index < ctrl->items_count)
- {
- rt_uint16_t old_item;
+ if ((index < ctrl->page_items) &&
+ (ctrl->current_item / ctrl->page_items)* ctrl->page_items + index < ctrl->items_count)
+ {
+ rt_uint16_t old_item;
- old_item = ctrl->current_item;
+ old_item = ctrl->current_item;
- /* set selected item */
- ctrl->current_item = (ctrl->current_item/ctrl->page_items) * ctrl->page_items + index;
- if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
- {
- /* down event */
- rtgui_listctrl_update_current(ctrl, old_item);
- }
- else
- {
- /* up event */
- if (ctrl->on_item != RT_NULL)
- {
- ctrl->on_item(RTGUI_OBJECT(ctrl), RT_NULL);
- }
- }
- }
- }
+ /* set selected item */
+ ctrl->current_item = (ctrl->current_item / ctrl->page_items) * ctrl->page_items + index;
+ if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN)
+ {
+ /* down event */
+ rtgui_listctrl_update_current(ctrl, old_item);
+ }
+ else
+ {
+ /* up event */
+ if (ctrl->on_item != RT_NULL)
+ {
+ ctrl->on_item(RTGUI_OBJECT(ctrl), RT_NULL);
+ }
+ }
+ }
+ }
- return RT_TRUE;
- }
+ return RT_TRUE;
+ }
case RTGUI_EVENT_KBD:
+ {
+ struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
+ if ((ekbd->type == RTGUI_KEYDOWN) && (ctrl->items_count > 0))
{
- struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
- if ((ekbd->type == RTGUI_KEYDOWN) && (ctrl->items_count > 0))
- {
- rt_uint16_t old_item;
+ rt_uint16_t old_item;
- old_item = ctrl->current_item;
- switch (ekbd->key)
- {
- case RTGUIK_LEFT:
- if (ctrl->current_item - ctrl->page_items >= 0)
- ctrl->current_item -= ctrl->page_items;
- rtgui_listctrl_update_current(ctrl, old_item);
- return RT_TRUE;
-
- case RTGUIK_UP:
- if (ctrl->current_item > 0)
- ctrl->current_item --;
- rtgui_listctrl_update_current(ctrl, old_item);
- return RT_TRUE;
+ old_item = ctrl->current_item;
+ switch (ekbd->key)
+ {
+ case RTGUIK_LEFT:
+ if (ctrl->current_item - ctrl->page_items >= 0)
+ ctrl->current_item -= ctrl->page_items;
+ rtgui_listctrl_update_current(ctrl, old_item);
+ return RT_TRUE;
- case RTGUIK_RIGHT:
- if (ctrl->current_item + ctrl->page_items < ctrl->items_count - 1)
- ctrl->current_item += ctrl->page_items;
- else
- {
- if ((((ctrl->current_item/ctrl->page_items) + 1) * ctrl->page_items) < ctrl->items_count - 1)
- ctrl->current_item = ((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items;
- }
- rtgui_listctrl_update_current(ctrl, old_item);
- return RT_TRUE;
+ case RTGUIK_UP:
+ if (ctrl->current_item > 0)
+ ctrl->current_item --;
+ rtgui_listctrl_update_current(ctrl, old_item);
+ return RT_TRUE;
- case RTGUIK_DOWN:
- if (ctrl->current_item < ctrl->items_count - 1)
- ctrl->current_item ++;
- rtgui_listctrl_update_current(ctrl, old_item);
- return RT_TRUE;
+ case RTGUIK_RIGHT:
+ if (ctrl->current_item + ctrl->page_items < ctrl->items_count - 1)
+ ctrl->current_item += ctrl->page_items;
+ else
+ {
+ if ((((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items) < ctrl->items_count - 1)
+ ctrl->current_item = ((ctrl->current_item / ctrl->page_items) + 1) * ctrl->page_items;
+ }
+ rtgui_listctrl_update_current(ctrl, old_item);
+ return RT_TRUE;
- case RTGUIK_RETURN:
- if (ctrl->on_item != RT_NULL)
- {
- return ctrl->on_item(RTGUI_OBJECT(ctrl), RT_NULL);
- }
- return RT_FALSE;
+ case RTGUIK_DOWN:
+ if (ctrl->current_item < ctrl->items_count - 1)
+ ctrl->current_item ++;
+ rtgui_listctrl_update_current(ctrl, old_item);
+ return RT_TRUE;
- default:
- break;
+ case RTGUIK_RETURN:
+ if (ctrl->on_item != RT_NULL)
+ {
+ return ctrl->on_item(RTGUI_OBJECT(ctrl), RT_NULL);
}
+ return RT_FALSE;
+
+ default:
+ break;
}
}
- return RT_FALSE;
- }
-
+ }
+ return RT_FALSE;
+ default:
/* use ctrl event handler */
return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
+ }
+
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_listctrl_event_handler);
-rtgui_listctrl_t* rtgui_listctrl_create(rt_uint32_t items, rt_uint16_t count, rtgui_rect_t *rect,
- rtgui_onitem_draw_t ondraw)
+rtgui_listctrl_t *rtgui_listctrl_create(void *items, rt_uint16_t count, rtgui_rect_t *rect,
+ rtgui_onitem_draw_t ondraw)
{
- struct rtgui_listctrl* ctrl = RT_NULL;
+ struct rtgui_listctrl *ctrl = RT_NULL;
- ctrl = (struct rtgui_listctrl*) rtgui_widget_create(RTGUI_LISTCTRL_TYPE);
- if (ctrl != RT_NULL)
- {
- ctrl->items = items;
- ctrl->items_count = count;
- ctrl->on_item_draw = ondraw;
+ ctrl = (struct rtgui_listctrl *) rtgui_widget_create(RTGUI_LISTCTRL_TYPE);
+ if (ctrl != RT_NULL)
+ {
+ ctrl->items = items;
+ ctrl->items_count = count;
+ ctrl->on_item_draw = ondraw;
- ctrl->page_items = rtgui_rect_height(*rect) / (2 + ctrl->item_height);
- rtgui_widget_set_rect(RTGUI_WIDGET(ctrl), rect);
- }
+ ctrl->page_items = rtgui_rect_height(*rect) / (2 + ctrl->item_height);
+ rtgui_widget_set_rect(RTGUI_WIDGET(ctrl), rect);
+ }
- return ctrl;
+ return ctrl;
}
RTM_EXPORT(rtgui_listctrl_create);
-void rtgui_listctrl_destroy(rtgui_listctrl_t* ctrl)
+void rtgui_listctrl_destroy(rtgui_listctrl_t *ctrl)
{
/* destroy ctrl */
- rtgui_widget_destroy(RTGUI_WIDGET(ctrl));
+ rtgui_widget_destroy(RTGUI_WIDGET(ctrl));
}
RTM_EXPORT(rtgui_listctrl_destroy);
-void rtgui_listctrl_set_onitem(rtgui_listctrl_t* ctrl, rtgui_event_handler_ptr func)
+void rtgui_listctrl_set_onitem(rtgui_listctrl_t *ctrl, rtgui_event_handler_ptr func)
{
- RT_ASSERT(ctrl != RT_NULL);
+ RT_ASSERT(ctrl != RT_NULL);
- ctrl->on_item = func;
+ ctrl->on_item = func;
}
RTM_EXPORT(rtgui_listctrl_set_onitem);
-void rtgui_listctrl_set_items(rtgui_listctrl_t* ctrl, rt_uint32_t items, rt_uint16_t count)
+void rtgui_listctrl_set_items(rtgui_listctrl_t *ctrl, void *items, rt_uint16_t count)
{
- rtgui_rect_t rect;
+ rtgui_rect_t rect;
- ctrl->items = items;
- ctrl->items_count = count;
- ctrl->current_item = 0;
+ ctrl->items = items;
+ ctrl->items_count = count;
+ ctrl->current_item = 0;
- rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), &rect);
- ctrl->page_items = rtgui_rect_height(rect) / (2 + ctrl->item_height);
+ rtgui_widget_get_rect(RTGUI_WIDGET(ctrl), &rect);
+ ctrl->page_items = rtgui_rect_height(rect) / (2 + ctrl->item_height);
- rtgui_widget_update(RTGUI_WIDGET(ctrl));
+ rtgui_widget_update(RTGUI_WIDGET(ctrl));
}
RTM_EXPORT(rtgui_listctrl_set_items);
-rt_bool_t rtgui_listctrl_get_item_rect(rtgui_listctrl_t* ctrl, rt_uint16_t item, rtgui_rect_t* item_rect)
+/**
+ * @brief set the selected(current) item of listctrl widget.
+ *
+ * If the index is greater than items_count, it will have no effect. Otherwise,
+ * the item on @param index will be selected and the on_item will be invoked if
+ * it has one.
+ *
+ * @fixme set current to the items which is not in current page won't update
+ * the scrollbar.
+ */
+void rtgui_listctrl_set_current_item(struct rtgui_listctrl *ctrl, rt_uint16_t index)
+{
+ RT_ASSERT(ctrl);
+
+ if (index >= ctrl->items_count)
+ return;
+
+ if (index != ctrl->current_item)
+ {
+ rt_uint16_t old_item = ctrl->current_item;
+ ctrl->current_item = index;
+ rtgui_listctrl_update_current(ctrl, old_item);
+ }
+ if (ctrl->on_item != RT_NULL)
+ {
+ ctrl->on_item(RTGUI_OBJECT(ctrl), RT_NULL);
+ }
+}
+RTM_EXPORT(rtgui_listctrl_set_current_item);
+
+rt_bool_t rtgui_listctrl_get_item_rect(rtgui_listctrl_t *ctrl, rt_uint16_t item, rtgui_rect_t *item_rect)
{
- if (item < ctrl->items_count)
- {
- rt_uint16_t index;
+ if (item < ctrl->items_count)
+ {
+ rt_uint16_t index;
- /* check whether this item in current page */
- index = (ctrl->current_item / ctrl->page_items) * ctrl->page_items;
- if (index > item || index + ctrl->page_items <= item) return RT_FALSE;
+ /* check whether this item in current page */
+ index = (ctrl->current_item / ctrl->page_items) * ctrl->page_items;
+ if (index > item || index + ctrl->page_items <= item) return RT_FALSE;
- rtgui_widget_get_extent(RTGUI_WIDGET(ctrl), item_rect);
- item_rect->y1 -= 2;
- item_rect->y1 += (item % ctrl->page_items) * (2 + ctrl->item_height);
- item_rect->y2 = item_rect->y1 + (2 + ctrl->item_height);
- return RT_TRUE;
- }
+ rtgui_widget_get_extent(RTGUI_WIDGET(ctrl), item_rect);
+ item_rect->y1 -= 2;
+ item_rect->y1 += (item % ctrl->page_items) * (2 + ctrl->item_height);
+ item_rect->y2 = item_rect->y1 + (2 + ctrl->item_height);
+ return RT_TRUE;
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_listctrl_get_item_rect);
-void rtgui_listctrl_set_itemheight(struct rtgui_listctrl* ctrl, int height)
+void rtgui_listctrl_set_itemheight(struct rtgui_listctrl *ctrl, int height)
{
- RT_ASSERT(ctrl != RT_NULL);
- if (height <= 0) return;
+ RT_ASSERT(ctrl != RT_NULL);
+ if (height <= 0) return;
- ctrl->item_height = height;
- ctrl->page_items = rtgui_rect_height(RTGUI_WIDGET(ctrl)->extent) / (2 + ctrl->item_height);
+ ctrl->item_height = height;
+ ctrl->page_items = rtgui_rect_height(RTGUI_WIDGET(ctrl)->extent) / (2 + ctrl->item_height);
}
RTM_EXPORT(rtgui_listctrl_set_itemheight);
diff --git a/components/rtgui/widgets/menu.c b/components/rtgui/widgets/menu.c
index b4856ee8fa..07a3a4dd15 100644
--- a/components/rtgui/widgets/menu.c
+++ b/components/rtgui/widgets/menu.c
@@ -2,288 +2,293 @@
#include <rtgui/widgets/menu.h>
#include <rtgui/rtgui_theme.h>
-static rt_bool_t rtgui_menu_on_deactivate(struct rtgui_object* object, rtgui_event_t* event);
+static rt_bool_t rtgui_menu_on_deactivate(struct rtgui_object *object, rtgui_event_t *event);
const static rt_uint8_t right_arrow[] = {0x80, 0xc0, 0xe0, 0xf0, 0xe0, 0xc0, 0x80};
static void _rtgui_menu_constructor(rtgui_menu_t *menu)
{
- /* set window style */
- RTGUI_WIN(menu)->style = RTGUI_WIN_STYLE_NO_TITLE;
+ /* set window style */
+ RTGUI_WIN(menu)->style = RTGUI_WIN_STYLE_NO_TITLE;
- /* set deactivate handler */
- rtgui_win_set_ondeactivate(RTGUI_WIN(menu), rtgui_menu_on_deactivate);
+ /* set deactivate handler */
+ rtgui_win_set_ondeactivate(RTGUI_WIN(menu), rtgui_menu_on_deactivate);
- /* set proper of control */
- menu->parent_menu = RT_NULL;
- menu->sub_menu = RT_NULL;
+ /* set proper of control */
+ menu->parent_menu = RT_NULL;
+ menu->sub_menu = RT_NULL;
- menu->items = RT_NULL;
- menu->items_count = 0;
- menu->items_list = RT_NULL;
+ menu->items = RT_NULL;
+ menu->items_count = 0;
+ menu->items_list = RT_NULL;
- menu->on_menupop = RT_NULL;
- menu->on_menuhide = RT_NULL;
+ menu->on_menupop = RT_NULL;
+ menu->on_menuhide = RT_NULL;
}
-static void _rtgui_menu_destructor(rtgui_menu_t* menu)
+static void _rtgui_menu_destructor(rtgui_menu_t *menu)
{
- if (menu->sub_menu != RT_NULL)
- {
- rtgui_menu_destroy(menu->sub_menu);
- menu->sub_menu = RT_NULL;
- }
+ if (menu->sub_menu != RT_NULL)
+ {
+ rtgui_menu_destroy(menu->sub_menu);
+ menu->sub_menu = RT_NULL;
+ }
- rtgui_listctrl_destroy(menu->items_list);
- menu->items_list = RT_NULL;
+ rtgui_listctrl_destroy(menu->items_list);
+ menu->items_list = RT_NULL;
}
-static rt_bool_t _rtgui_menu_onitem(struct rtgui_object* object, struct rtgui_event* event)
+static rt_bool_t _rtgui_menu_onitem(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_menu* menu;
+ struct rtgui_menu *menu;
- /* event will be NULL, don't check it. */
- RT_ASSERT(object);
+ /* event will be NULL, don't check it. */
+ RT_ASSERT(object);
- /* get menu */
- menu = RTGUI_MENU(rtgui_widget_get_toplevel(RTGUI_WIDGET(object)));
- if (menu->items[menu->items_list->current_item].type == RTGUI_ITEM_SUBMENU)
- {
- const rtgui_menu_item_t* items;
- rt_uint16_t count;
- rtgui_rect_t item_rect;
+ /* get menu */
+ menu = RTGUI_MENU(rtgui_widget_get_toplevel(RTGUI_WIDGET(object)));
+ if (menu->items[menu->items_list->current_item].type == RTGUI_ITEM_SUBMENU)
+ {
+ const rtgui_menu_item_t *items;
+ rt_uint16_t count;
+ rtgui_rect_t item_rect;
- items = (rtgui_menu_item_t*)menu->items[menu->items_list->current_item].submenu;
- count = menu->items[menu->items_list->current_item].submenu_count;
- if (menu->sub_menu != RT_NULL)
- {
- if (menu->sub_menu->items == items)
- {
- if (!RTGUI_WIDGET_IS_HIDE(menu->sub_menu))
- {
- /* hide this sub menu */
- rtgui_win_hiden(RTGUI_WIN(menu->sub_menu));
- return RT_FALSE;
- }
+ items = (rtgui_menu_item_t *)menu->items[menu->items_list->current_item].submenu;
+ count = menu->items[menu->items_list->current_item].submenu_count;
+ if (menu->sub_menu != RT_NULL)
+ {
+ if (menu->sub_menu->items == items)
+ {
+ if (!RTGUI_WIDGET_IS_HIDE(menu->sub_menu))
+ {
+ /* hide this sub menu */
+ rtgui_win_hiden(RTGUI_WIN(menu->sub_menu));
+ return RT_FALSE;
+ }
- /* show this sub menu */
- rtgui_listctrl_get_item_rect(menu->items_list, menu->items_list->current_item, &item_rect);
- rtgui_menu_pop(menu->sub_menu, item_rect.x2, item_rect.y1);
- return RT_FALSE;
- }
+ /* show this sub menu */
+ rtgui_listctrl_get_item_rect(menu->items_list, menu->items_list->current_item, &item_rect);
+ rtgui_menu_pop(menu->sub_menu, item_rect.x2, item_rect.y1);
+ return RT_FALSE;
+ }
- /* delete sub menu */
- rtgui_menu_destroy(menu->sub_menu);
- menu->sub_menu = RT_NULL;
- }
+ /* delete sub menu */
+ rtgui_menu_destroy(menu->sub_menu);
+ menu->sub_menu = RT_NULL;
+ }
- /* create sub menu */
- menu->sub_menu = rtgui_menu_create("submenu", menu, items, count);
+ /* create sub menu */
+ menu->sub_menu = rtgui_menu_create("submenu", menu, items, count);
- rtgui_listctrl_get_item_rect(menu->items_list, menu->items_list->current_item, &item_rect);
- rtgui_menu_pop(menu->sub_menu, item_rect.x2 + 5, item_rect.y1);
- }
- else /* other menu item */
- {
- /* invoke action */
- if (menu->items[menu->items_list->current_item].on_menuaction != RT_NULL)
- menu->items[menu->items_list->current_item].on_menuaction(RTGUI_OBJECT(menu), RT_NULL);
+ rtgui_listctrl_get_item_rect(menu->items_list, menu->items_list->current_item, &item_rect);
+ rtgui_menu_pop(menu->sub_menu, item_rect.x2 + 5, item_rect.y1);
+ }
+ else /* other menu item */
+ {
+ /* invoke action */
+ if (menu->items[menu->items_list->current_item].on_menuaction != RT_NULL)
+ menu->items[menu->items_list->current_item].on_menuaction(RTGUI_OBJECT(menu), RT_NULL);
- /* hide sub-menu */
- if (menu->sub_menu != RT_NULL)
- {
- rtgui_menu_hiden(menu->sub_menu);
- }
- rtgui_menu_hiden(menu);
- }
- return RT_FALSE;
+ /* hide sub-menu */
+ if (menu->sub_menu != RT_NULL)
+ {
+ rtgui_menu_hiden(menu->sub_menu);
+ }
+ rtgui_menu_hiden(menu);
+ }
+ return RT_FALSE;
}
static void _rtgui_menu_item_ondraw(struct rtgui_listctrl *list,
- struct rtgui_dc* dc,
- rtgui_rect_t* rect,
- rt_uint16_t index)
+ struct rtgui_dc *dc,
+ rtgui_rect_t *rect,
+ rt_uint16_t index)
{
- rtgui_rect_t item_rect;
- struct rtgui_menu_item* item;
+ rtgui_rect_t item_rect;
+ struct rtgui_menu_item *item;
- item_rect = *rect;
- item_rect.x1 += 5;
+ item_rect = *rect;
+ item_rect.x1 += 5;
- /* re-fill item */
- if (list->current_item == index)
- {
- rtgui_color_t bc;
+ /* re-fill item */
+ if (list->current_item == index)
+ {
+ rtgui_color_t bc;
- bc = RTGUI_WIDGET_BACKGROUND(list);
- RTGUI_WIDGET_BACKGROUND(list) = blue;
- rtgui_dc_fill_rect(dc, rect);
- RTGUI_WIDGET_BACKGROUND(list) = bc;
- }
+ bc = RTGUI_WIDGET_BACKGROUND(list);
+ RTGUI_WIDGET_BACKGROUND(list) = blue;
+ rtgui_dc_fill_rect(dc, rect);
+ RTGUI_WIDGET_BACKGROUND(list) = bc;
+ }
- /* get menu item */
- item = (rtgui_menu_item_t*)list->items;
- item = &item[index];
+ /* get menu item */
+ item = (rtgui_menu_item_t *)list->items;
+ item = &item[index];
- if (item->type == RTGUI_ITEM_SUBMENU)
- {
- rtgui_rect_t r = {0, 0, 8, 8};
- rtgui_dc_draw_text(dc, item->label, &item_rect);
- item_rect.x1 = item_rect.x2 - 16; item_rect.x2 -= 8;
- rtgui_rect_moveto_align(&item_rect, &r, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
- rtgui_dc_draw_byte(dc, r.x1, r.y1, 8, right_arrow);
- }
- else if (item->type == RTGUI_ITEM_SEPARATOR)
- {
- rtgui_dc_draw_horizontal_line(dc, item_rect.x1, item_rect.x2, (item_rect.y2 + item_rect.y1)/2);
- }
- else if (item->type == RTGUI_ITEM_CHECK)
- {
- /* not support right now */
- }
- else
- {
- /* normal menu item */
- rtgui_dc_draw_text(dc, item->label, &item_rect);
- if (item->image != RT_NULL)
- rtgui_image_blit(item->image, dc, &item_rect);
- }
+ if (item->type == RTGUI_ITEM_SUBMENU)
+ {
+ rtgui_rect_t r = {0, 0, 8, 8};
+ rtgui_dc_draw_text(dc, item->label, &item_rect);
+ item_rect.x1 = item_rect.x2 - 16;
+ item_rect.x2 -= 8;
+ rtgui_rect_moveto_align(&item_rect, &r, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
+ rtgui_dc_draw_byte(dc, r.x1, r.y1, 8, right_arrow);
+ }
+ else if (item->type == RTGUI_ITEM_SEPARATOR)
+ {
+ rtgui_dc_draw_horizontal_line(dc, item_rect.x1, item_rect.x2, (item_rect.y2 + item_rect.y1) / 2);
+ }
+ else if (item->type == RTGUI_ITEM_CHECK)
+ {
+ /* not support right now */
+ }
+ else
+ {
+ /* normal menu item */
+ rtgui_dc_draw_text(dc, item->label, &item_rect);
+ if (item->image != RT_NULL)
+ rtgui_image_blit(item->image, dc, &item_rect);
+ }
}
DEFINE_CLASS_TYPE(menu, "menu",
- RTGUI_WIN_TYPE,
- _rtgui_menu_constructor,
- _rtgui_menu_destructor,
- sizeof(struct rtgui_menu));
+ RTGUI_WIN_TYPE,
+ _rtgui_menu_constructor,
+ _rtgui_menu_destructor,
+ sizeof(struct rtgui_menu));
-static rt_bool_t rtgui_menu_on_deactivate(struct rtgui_object *object, rtgui_event_t* event)
+static rt_bool_t rtgui_menu_on_deactivate(struct rtgui_object *object, rtgui_event_t *event)
{
- rtgui_menu_t* menu;
- RTGUI_WIDGET_EVENT_HANDLER_PREPARE
+ rtgui_menu_t *menu;
+ RTGUI_WIDGET_EVENT_HANDLER_PREPARE
- menu = RTGUI_MENU(object);
- if (menu->parent_menu != RT_NULL)
- {
- /* whether click on parent menu */
- if (rtgui_win_is_activated(RTGUI_WIN(menu->parent_menu)) == RT_TRUE &&
- menu->parent_menu->items[menu->parent_menu->items_list->current_item].submenu
- == (struct rtgui_menu_item_t *)menu->items)
- return RT_TRUE;
- }
+ menu = RTGUI_MENU(object);
+ if (menu->parent_menu != RT_NULL)
+ {
+ /* whether click on parent menu */
+ if (rtgui_win_is_activated(RTGUI_WIN(menu->parent_menu)) == RT_TRUE &&
+ menu->parent_menu->items[menu->parent_menu->items_list->current_item].submenu
+ == (struct rtgui_menu_item_t *)menu->items)
+ return RT_TRUE;
+ }
- /* submenu is activate */
- if (menu->items[menu->items_list->current_item].type == RTGUI_ITEM_SUBMENU)
- {
- /* if sub menu activated, not hide menu. But we cannot use the
- * activated flag as criteria since the old window is deactivated
- * before the new window got activated. But the window will be shown in
- * this context, so use 'is not hide'. */
- if (menu->sub_menu != RT_NULL &&
- !RTGUI_WIDGET_IS_HIDE(menu->sub_menu))
- return RT_TRUE;
- }
+ /* submenu is activate */
+ if (menu->items[menu->items_list->current_item].type == RTGUI_ITEM_SUBMENU)
+ {
+ /* if sub menu activated, not hide menu. But we cannot use the
+ * activated flag as criteria since the old window is deactivated
+ * before the new window got activated. But the window will be shown in
+ * this context, so use 'is not hide'. */
+ if (menu->sub_menu != RT_NULL &&
+ !RTGUI_WIDGET_IS_HIDE(menu->sub_menu))
+ return RT_TRUE;
+ }
- rtgui_win_hiden(RTGUI_WIN(menu));
- if (menu->on_menuhide != RT_NULL)
- {
- menu->on_menuhide(RTGUI_OBJECT(menu), RT_NULL);
- }
+ rtgui_win_hiden(RTGUI_WIN(menu));
+ if (menu->on_menuhide != RT_NULL)
+ {
+ menu->on_menuhide(RTGUI_OBJECT(menu), RT_NULL);
+ }
- /* un-select item */
- menu->items_list->current_item = -1;
+ /* un-select item */
+ menu->items_list->current_item = -1;
- /* if it's a submenu, try to hide parent menu */
- if (menu->parent_menu != RT_NULL &&
- rtgui_win_is_activated(RTGUI_WIN(menu->parent_menu)) == RT_FALSE)
- {
- rtgui_menu_on_deactivate(RTGUI_OBJECT(menu->parent_menu), event);
- }
+ /* if it's a submenu, try to hide parent menu */
+ if (menu->parent_menu != RT_NULL &&
+ rtgui_win_is_activated(RTGUI_WIN(menu->parent_menu)) == RT_FALSE)
+ {
+ rtgui_menu_on_deactivate(RTGUI_OBJECT(menu->parent_menu), event);
+ }
- return RT_TRUE;
+ return RT_TRUE;
}
-struct rtgui_menu* rtgui_menu_create(const char* title, struct rtgui_menu* parent_menu,
- const struct rtgui_menu_item* items, rt_uint16_t count)
+struct rtgui_menu *rtgui_menu_create(const char *title, struct rtgui_menu *parent_menu,
+ const struct rtgui_menu_item *items, rt_uint16_t count)
{
- rtgui_rect_t rect = {0, 0, 100, 100};
- struct rtgui_menu* menu;
+ rtgui_rect_t rect = {0, 0, 100, 100};
+ struct rtgui_menu *menu;
- menu = (struct rtgui_menu*) rtgui_widget_create ( RTGUI_MENU_TYPE );
- if (menu != RT_NULL)
- {
- rtgui_win_set_title(RTGUI_WIN(menu), title);
- menu->parent_menu = parent_menu;
- menu->items = items;
- menu->items_count = count;
+ menu = (struct rtgui_menu *) rtgui_widget_create(RTGUI_MENU_TYPE);
+ if (menu != RT_NULL)
+ {
+ rtgui_win_set_title(RTGUI_WIN(menu), title);
+ menu->parent_menu = parent_menu;
+ menu->items = items;
+ menu->items_count = count;
- rtgui_widget_set_rect(RTGUI_WIDGET(menu), &rect);
- rtgui_rect_inflate(&rect, -1);
- /* create menu item list */
- menu->items_list = rtgui_listctrl_create((rt_uint32_t)items, count, &rect, _rtgui_menu_item_ondraw);
- RTGUI_WIDGET_BACKGROUND(menu->items_list) = rtgui_theme_default_bc();
- rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(menu->items_list));
- rtgui_listctrl_set_onitem(menu->items_list, _rtgui_menu_onitem);
- }
+ rtgui_widget_set_rect(RTGUI_WIDGET(menu), &rect);
+ rtgui_rect_inflate(&rect, -1);
+ /* create menu item list */
+ menu->items_list = rtgui_listctrl_create((void*)items, count, &rect, _rtgui_menu_item_ondraw);
+ RTGUI_WIDGET_BACKGROUND(menu->items_list) = rtgui_theme_default_bc();
+ rtgui_container_add_child(RTGUI_CONTAINER(menu), RTGUI_WIDGET(menu->items_list));
+ rtgui_listctrl_set_onitem(menu->items_list, _rtgui_menu_onitem);
+ }
- return menu;
+ return menu;
}
-void rtgui_menu_destroy(struct rtgui_menu* menu)
+void rtgui_menu_destroy(struct rtgui_menu *menu)
{
- rtgui_widget_destroy (RTGUI_WIDGET(menu));
+ rtgui_widget_destroy(RTGUI_WIDGET(menu));
}
-void rtgui_menu_set_onmenupop(struct rtgui_menu* menu, rtgui_event_handler_ptr handler)
+void rtgui_menu_set_onmenupop(struct rtgui_menu *menu, rtgui_event_handler_ptr handler)
{
- if (menu == RT_NULL) return;
+ if (menu == RT_NULL) return;
- menu->on_menupop = handler;
+ menu->on_menupop = handler;
}
-void rtgui_menu_set_onmenuhide(struct rtgui_menu* menu, rtgui_event_handler_ptr handler)
+void rtgui_menu_set_onmenuhide(struct rtgui_menu *menu, rtgui_event_handler_ptr handler)
{
- if (menu == RT_NULL) return;
+ if (menu == RT_NULL) return;
- menu->on_menuhide = handler;
+ menu->on_menuhide = handler;
}
-void rtgui_menu_pop(struct rtgui_menu* menu, int x, int y)
+void rtgui_menu_pop(struct rtgui_menu *menu, int x, int y)
{
- rtgui_rect_t rect;
- struct rtgui_event_resize eresize;
+ rtgui_rect_t rect;
+ struct rtgui_event_resize eresize;
- if (menu == RT_NULL)
- return;
+ if (menu == RT_NULL)
+ return;
- /* set window extent */
- rect.x1 = 0; rect.y1 = 0;
- rect.x2 = 100; rect.y2 = menu->items_count * (rtgui_theme_get_selected_height() + 2) + 5;
- rtgui_rect_moveto(&rect, x, y);
- rtgui_win_set_rect(RTGUI_WIN(menu), &rect);
- rtgui_rect_inflate(&rect, -1);
- rtgui_widget_set_rect(RTGUI_WIDGET(menu->items_list), &rect);
+ /* set window extent */
+ rect.x1 = 0;
+ rect.y1 = 0;
+ rect.x2 = 100;
+ rect.y2 = menu->items_count * (rtgui_theme_get_selected_height() + 2) + 5;
+ rtgui_rect_moveto(&rect, x, y);
+ rtgui_win_set_rect(RTGUI_WIN(menu), &rect);
+ rtgui_rect_inflate(&rect, -1);
+ rtgui_widget_set_rect(RTGUI_WIDGET(menu->items_list), &rect);
- eresize.parent.type = RTGUI_EVENT_RESIZE;
- eresize.x = rect.x1; eresize.y = rect.y1;
- eresize.h = rect.y2 - rect.y1; eresize.w = rect.x2 - rect.x1;
- rtgui_listctrl_event_handler(RTGUI_OBJECT(menu->items_list), &(eresize.parent));
+ eresize.parent.type = RTGUI_EVENT_RESIZE;
+ eresize.x = rect.x1;
+ eresize.y = rect.y1;
+ eresize.h = rect.y2 - rect.y1;
+ eresize.w = rect.x2 - rect.x1;
+ rtgui_listctrl_event_handler(RTGUI_OBJECT(menu->items_list), &(eresize.parent));
- /* on menu pop handler */
- if (menu->on_menupop != RT_NULL)
- {
- menu->on_menupop(RTGUI_OBJECT(menu), RT_NULL);
- }
+ /* on menu pop handler */
+ if (menu->on_menupop != RT_NULL)
+ {
+ menu->on_menupop(RTGUI_OBJECT(menu), RT_NULL);
+ }
- /* show menu window */
- rtgui_win_show(RTGUI_WIN(menu), RT_FALSE);
+ /* show menu window */
+ rtgui_win_show(RTGUI_WIN(menu), RT_FALSE);
}
-void rtgui_menu_hiden(struct rtgui_menu* menu)
+void rtgui_menu_hiden(struct rtgui_menu *menu)
{
- rtgui_win_hiden(RTGUI_WIN(menu));
- /* un-select item */
- menu->items_list->current_item = -1;
+ rtgui_win_hiden(RTGUI_WIN(menu));
+ /* un-select item */
+ menu->items_list->current_item = -1;
- if (menu->parent_menu != RT_NULL)
- rtgui_menu_hiden(menu->parent_menu);
+ if (menu->parent_menu != RT_NULL)
+ rtgui_menu_hiden(menu->parent_menu);
}
diff --git a/components/rtgui/widgets/mv_view.c b/components/rtgui/widgets/mv_view.c
new file mode 100644
index 0000000000..dbc5f91f6d
--- /dev/null
+++ b/components/rtgui/widgets/mv_view.c
@@ -0,0 +1,81 @@
+/*
+ * File : mv_view.c
+ * This file is part of RT-Thread RTOS
+ * COPYRIGHT (C) 2012, 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
+ * 2012-09-17 Grissiom first version
+ */
+
+#include <rtgui/rtgui.h>
+#include <rtgui/rtgui_mv_model.h>
+#include <rtgui/widgets/mv_view.h>
+
+static void _rtgui_mv_view_constructor(struct rtgui_mv_view *view)
+{
+ view->model_number = 0;
+ view->model = RT_NULL;
+}
+
+static void _rtgui_mv_view_destructor(struct rtgui_mv_view *view)
+{
+ if (view->model_number == 1)
+ {
+ rtgui_mv_model_remove_view(view->model, view);
+ }
+ else if (view->model_number > 1)
+ {
+ void **model_arr = *(void ** *)view->model;
+ int i;
+
+ for (i = 0; i < view->model_number; i++)
+ {
+ rtgui_mv_model_remove_view(model_arr[i], view);
+ }
+ }
+}
+
+DEFINE_CLASS_TYPE(mv_view, "mv_view",
+ RTGUI_WIDGET_TYPE,
+ _rtgui_mv_view_constructor,
+ _rtgui_mv_view_destructor,
+ sizeof(struct rtgui_mv_view));
+
+struct rtgui_mv_view *rtgui_mv_view_create(void)
+{
+ return RTGUI_MV_VIEW(rtgui_widget_create(RTGUI_MV_VIEW_TYPE));
+}
+
+void rtgui_mv_view_destroy(struct rtgui_mv_view *view)
+{
+ rtgui_widget_destroy(RTGUI_WIDGET(view));
+}
+
+struct rtgui_mv_model *rtgui_mv_view_foreach_in_model(struct rtgui_mv_view *view, rt_uint32_t *iter)
+{
+ struct rtgui_mv_model *model;
+
+ RT_ASSERT(view);
+
+ if (*iter >= view->model_number)
+ return RT_NULL;
+
+ if (view->model_number == 1)
+ {
+ model = view->model;
+ }
+ else
+ {
+ struct rtgui_mv_model **model_array = view->model;
+ model = model_array[*iter];
+ }
+
+ (*iter)++;
+ return model;
+}
+
diff --git a/components/rtgui/widgets/notebook.c b/components/rtgui/widgets/notebook.c
index 3f0fa97820..b0d1846e65 100644
--- a/components/rtgui/widgets/notebook.c
+++ b/components/rtgui/widgets/notebook.c
@@ -11,610 +11,623 @@
struct rtgui_notebook_tab
{
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
- struct rtgui_image *pressed_image;
- struct rtgui_image *unpressed_image;
+ struct rtgui_image *pressed_image;
+ struct rtgui_image *unpressed_image;
#endif
- struct rtgui_widget *widget;
- char *title;
+ struct rtgui_widget *widget;
+ char *title;
};
-static void _rtgui_notebook_get_bar_rect(struct rtgui_notebook *notebook, struct rtgui_rect* rect);
-static void _rtgui_notebook_get_page_rect(struct rtgui_notebook *notebook, struct rtgui_rect* rect);
+static void _rtgui_notebook_get_bar_rect(struct rtgui_notebook *notebook, struct rtgui_rect *rect);
+static void _rtgui_notebook_get_page_rect(struct rtgui_notebook *notebook, struct rtgui_rect *rect);
static void _rtgui_notebook_constructor(struct rtgui_notebook *notebook)
{
- notebook->flag = 0;
- notebook->childs = RT_NULL;
- notebook->count = 0;
- notebook->current = 0;
+ notebook->flag = 0;
+ notebook->childs = RT_NULL;
+ notebook->count = 0;
+ notebook->current = 0;
- notebook->tab_h = RTGUI_NOTEBOOK_TAB_DEFAULT_HEIGHT;
- notebook->tab_w = RTGUI_NOTEBOOK_TAB_DEFAULT_WIDTH;
+ notebook->tab_h = RTGUI_NOTEBOOK_TAB_DEFAULT_HEIGHT;
+ notebook->tab_w = RTGUI_NOTEBOOK_TAB_DEFAULT_WIDTH;
- RTGUI_WIDGET(notebook)->gc.textalign = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
- rtgui_object_set_event_handler(RTGUI_OBJECT(notebook), rtgui_notebook_event_handler);
+ RTGUI_WIDGET(notebook)->gc.textalign = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
+ rtgui_object_set_event_handler(RTGUI_OBJECT(notebook), rtgui_notebook_event_handler);
}
static void _rtgui_notebook_destructor(struct rtgui_notebook *notebook)
{
- int index;
+ int index;
- if (notebook->childs != RT_NULL)
- {
- for (index = 0; index < notebook->count; index ++)
- {
- rtgui_widget_destroy(notebook->childs[index].widget);
- rt_free(notebook->childs[index].title);
- }
+ if (notebook->childs != RT_NULL)
+ {
+ for (index = 0; index < notebook->count; index ++)
+ {
+ rtgui_widget_destroy(notebook->childs[index].widget);
+ rt_free(notebook->childs[index].title);
+ }
- rtgui_free(notebook->childs);
- }
+ rtgui_free(notebook->childs);
+ }
}
DEFINE_CLASS_TYPE(notebook, "notebook",
- RTGUI_WIDGET_TYPE,
- _rtgui_notebook_constructor,
- _rtgui_notebook_destructor,
- sizeof(struct rtgui_notebook));
+ RTGUI_WIDGET_TYPE,
+ _rtgui_notebook_constructor,
+ _rtgui_notebook_destructor,
+ sizeof(struct rtgui_notebook));
/* Draw tab bars of @param notebook. @param dc should be initialized and
* finished outside this function. Don't pass @param notebook or @param dc as
* RT_NULL, it should be checked outside.
*/
static void _rtgui_notebook_draw_bar(struct rtgui_notebook *notebook,
- struct rtgui_dc *dc)
+ struct rtgui_dc *dc)
{
- int index;
- struct rtgui_rect rect;
- struct rtgui_rect text_rect;
+ int index;
+ struct rtgui_rect rect;
+ struct rtgui_rect text_rect;
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
- struct rtgui_image* image = RT_NULL;
- struct rtgui_rect image_rect;
+ struct rtgui_image *image = RT_NULL;
+ struct rtgui_rect image_rect;
#endif
- RT_ASSERT((notebook != RT_NULL) && (dc != RT_NULL));
+ RT_ASSERT((notebook != RT_NULL) && (dc != RT_NULL));
- if (notebook->flag == RTGUI_NOTEBOOK_NOTAB)
- return;
+ if (notebook->flag == RTGUI_NOTEBOOK_NOTAB)
+ return;
- _rtgui_notebook_get_bar_rect(notebook, &rect);
- rtgui_dc_fill_rect(dc, &rect);
+ _rtgui_notebook_get_bar_rect(notebook, &rect);
+ rtgui_dc_fill_rect(dc, &rect);
- if (notebook->flag == RTGUI_NOTEBOOK_TOP ||
- notebook->flag == RTGUI_NOTEBOOK_BOTTOM)
- {
- rect.x2 = rect.x1 + notebook->tab_w;
- /* draw tab bar */
- for (index = 0; index < notebook->count; index++)
- {
- if (notebook->current == index)
- {
+ if (notebook->flag == RTGUI_NOTEBOOK_TOP ||
+ notebook->flag == RTGUI_NOTEBOOK_BOTTOM)
+ {
+ rect.x2 = rect.x1 + notebook->tab_w;
+ /* draw tab bar */
+ for (index = 0; index < notebook->count; index++)
+ {
+ if (notebook->current == index)
+ {
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
- if (notebook->childs[index].pressed_image != RT_NULL)
- image = notebook->childs[index].pressed_image;
- else
+ if (notebook->childs[index].pressed_image != RT_NULL)
+ image = notebook->childs[index].pressed_image;
+ else
#endif
- rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
- }
- else
- {
+ rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
+ }
+ else
+ {
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
- if (notebook->childs[index].unpressed_image != RT_NULL)
- image = notebook->childs[index].unpressed_image;
- else
+ if (notebook->childs[index].unpressed_image != RT_NULL)
+ image = notebook->childs[index].unpressed_image;
+ else
#endif
- rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
- }
+ rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
+ }
- rtgui_font_get_metrics(RTGUI_WIDGET_FONT(notebook),
- notebook->childs[index].title, &text_rect);
- rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_ALIGN_CENTER);
+ rtgui_font_get_metrics(RTGUI_WIDGET_FONT(notebook),
+ notebook->childs[index].title, &text_rect);
+ rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_ALIGN_CENTER);
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
- if (image != RT_NULL)
- {
- image_rect.x1 = 0;
- image_rect.y1 = RTGUI_WIDGET_DEFAULT_MARGIN;
- image_rect.x2 = image_rect.x1 + image->w;
- image_rect.y2 = image_rect.y1 + image->h;
- rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
-
- rtgui_image_blit(image, dc, &image_rect);
- }
- if (image != RT_NULL)
- {
- int text_height = text_rect.y2 - text_rect.y1;
-
- text_rect.y1 = image_rect.y2 + RTGUI_WIDGET_DEFAULT_MARGIN;
- text_rect.y2 = text_rect.y1 + text_height;
- }
- image = RT_NULL;
+ if (image != RT_NULL)
+ {
+ image_rect.x1 = 0;
+ image_rect.y1 = RTGUI_WIDGET_DEFAULT_MARGIN;
+ image_rect.x2 = image_rect.x1 + image->w;
+ image_rect.y2 = image_rect.y1 + image->h;
+ rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
+
+ rtgui_image_blit(image, dc, &image_rect);
+ }
+ if (image != RT_NULL)
+ {
+ int text_height = text_rect.y2 - text_rect.y1;
+
+ text_rect.y1 = image_rect.y2 + RTGUI_WIDGET_DEFAULT_MARGIN;
+ text_rect.y2 = text_rect.y1 + text_height;
+ }
+ image = RT_NULL;
#endif
- rtgui_dc_draw_text(dc, notebook->childs[index].title, &text_rect);
+ rtgui_dc_draw_text(dc, notebook->childs[index].title, &text_rect);
- /* move to next tab */
- rect.x1 = rect.x2;
- rect.x2 = rect.x1 + notebook->tab_w;
- }
- }
- else
- {
- rect.y2 = rect.y1 + notebook->tab_h;
- /* draw tab bar */
- for (index = 0; index < notebook->count; index++)
- {
- if (notebook->current == index)
- {
+ /* move to next tab */
+ rect.x1 = rect.x2;
+ rect.x2 = rect.x1 + notebook->tab_w;
+ }
+ }
+ else
+ {
+ rect.y2 = rect.y1 + notebook->tab_h;
+ /* draw tab bar */
+ for (index = 0; index < notebook->count; index++)
+ {
+ if (notebook->current == index)
+ {
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
- if (notebook->childs[index].pressed_image != RT_NULL)
- image = notebook->childs[index].pressed_image;
- else
+ if (notebook->childs[index].pressed_image != RT_NULL)
+ image = notebook->childs[index].pressed_image;
+ else
#endif
- rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
- }
- else
- {
+ rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_SUNKEN);
+ }
+ else
+ {
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
- if (notebook->childs[index].unpressed_image != RT_NULL)
- image = notebook->childs[index].unpressed_image;
- else
+ if (notebook->childs[index].unpressed_image != RT_NULL)
+ image = notebook->childs[index].unpressed_image;
+ else
#endif
- rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
- }
+ rtgui_dc_draw_border(dc, &rect, RTGUI_BORDER_BOX);
+ }
- rtgui_font_get_metrics(RTGUI_WIDGET_FONT(notebook),
- notebook->childs[index].title, &text_rect);
- rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_ALIGN_CENTER);
+ rtgui_font_get_metrics(RTGUI_WIDGET_FONT(notebook),
+ notebook->childs[index].title, &text_rect);
+ rtgui_rect_moveto_align(&rect, &text_rect, RTGUI_ALIGN_CENTER);
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
- if (image != RT_NULL)
- {
- image_rect.x1 = 0;
- image_rect.y1 = RTGUI_WIDGET_DEFAULT_MARGIN;
- image_rect.x2 = image->w;
- image_rect.y2 = image_rect.y1 + image->h;
- rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
-
- rtgui_image_blit(image, dc, &image_rect);
- }
+ if (image != RT_NULL)
+ {
+ image_rect.x1 = 0;
+ image_rect.y1 = RTGUI_WIDGET_DEFAULT_MARGIN;
+ image_rect.x2 = image->w;
+ image_rect.y2 = image_rect.y1 + image->h;
+ rtgui_rect_moveto_align(&rect, &image_rect, RTGUI_ALIGN_CENTER_HORIZONTAL);
+
+ rtgui_image_blit(image, dc, &image_rect);
+ }
- if (image != RT_NULL)
- {
- int text_height = text_rect.y2 - text_rect.y1;
-
- text_rect.y1 = image_rect.y2 + RTGUI_WIDGET_DEFAULT_MARGIN;
- text_rect.y2 = text_rect.y1 + text_height;
- }
- image = RT_NULL;
+ if (image != RT_NULL)
+ {
+ int text_height = text_rect.y2 - text_rect.y1;
+
+ text_rect.y1 = image_rect.y2 + RTGUI_WIDGET_DEFAULT_MARGIN;
+ text_rect.y2 = text_rect.y1 + text_height;
+ }
+ image = RT_NULL;
#endif
- rtgui_dc_draw_text(dc, notebook->childs[index].title, &text_rect);
+ rtgui_dc_draw_text(dc, notebook->childs[index].title, &text_rect);
- /* move to next tab */
- rect.y1 = rect.y2;
- rect.y2 = rect.y1 + notebook->tab_h;
- }
+ /* move to next tab */
+ rect.y1 = rect.y2;
+ rect.y2 = rect.y1 + notebook->tab_h;
+ }
- }
+ }
}
static void _rtgui_notebook_ondraw(struct rtgui_notebook *notebook)
{
- struct rtgui_dc* dc;
+ struct rtgui_dc *dc;
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
- if (dc == RT_NULL) return;
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
+ if (dc == RT_NULL) return;
- if (notebook->count == 0)
- {
- rtgui_rect_t rect;
- rtgui_widget_get_rect(RTGUI_WIDGET(notebook), &rect);
- rtgui_dc_fill_rect(dc, &rect);
- }
- else
- {
- if (notebook->current == RTGUI_NOT_FOUND)
- notebook->current = 0;
+ if (notebook->count == 0)
+ {
+ rtgui_rect_t rect;
+ rtgui_widget_get_rect(RTGUI_WIDGET(notebook), &rect);
+ rtgui_dc_fill_rect(dc, &rect);
+ }
+ else
+ {
+ if (notebook->current == RTGUI_NOT_FOUND)
+ notebook->current = 0;
- _rtgui_notebook_draw_bar(notebook, dc);
+ _rtgui_notebook_draw_bar(notebook, dc);
- /* draw current tab */
- rtgui_widget_update(notebook->childs[notebook->current].widget);
- }
- rtgui_dc_end_drawing(dc);
+ /* draw current tab */
+ rtgui_widget_update(notebook->childs[notebook->current].widget);
+ }
+ rtgui_dc_end_drawing(dc);
}
-static void _rtgui_notebook_onmouse(struct rtgui_notebook *notebook, struct rtgui_event_mouse* emouse)
+static void _rtgui_notebook_onmouse(struct rtgui_notebook *notebook, struct rtgui_event_mouse *emouse)
{
- rtgui_rect_t rect;
+ rtgui_rect_t rect;
+
+ /* handle notebook bar */
+ _rtgui_notebook_get_bar_rect(notebook, &rect);
+ rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
+ if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
+ {
+ int index;
+ struct rtgui_dc *dc;
- /* handle notebook bar */
- _rtgui_notebook_get_bar_rect(notebook, &rect);
- rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
- if (rtgui_rect_contains_point(&rect, emouse->x, emouse->y) == RT_EOK)
- {
- int index;
- struct rtgui_dc* dc;
+ if (notebook->flag == RTGUI_NOTEBOOK_BOTTOM || notebook->flag == RTGUI_NOTEBOOK_TOP)
+ {
+ index = (emouse->x - rect.x1) / notebook->tab_w;
+ if (index < notebook->count && index != notebook->current)
+ {
+ /* update tab bar */
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
+ if (dc == RT_NULL) return;
- if (notebook->flag == RTGUI_NOTEBOOK_BOTTOM || notebook->flag == RTGUI_NOTEBOOK_TOP)
- {
- index = (emouse->x - rect.x1) / notebook->tab_w;
- if (index < notebook->count && index != notebook->current)
- {
- /* update tab bar */
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
- if (dc == RT_NULL) return;
+ rtgui_notebook_set_current_by_index(notebook, index);
- rtgui_notebook_set_current_by_index(notebook, index);
+ _rtgui_notebook_draw_bar(notebook, dc);
- _rtgui_notebook_draw_bar(notebook, dc);
+ rtgui_dc_end_drawing(dc);
+ }
+ }
+ else
+ {
+ index = (emouse->y - rect.y1) / notebook->tab_h;
+ if (index < notebook->count && index != notebook->current)
+ {
+ /* update tab bar */
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
+ if (dc == RT_NULL) return;
- rtgui_dc_end_drawing(dc);
- }
- }
- else
- {
- index = (emouse->y - rect.y1) / notebook->tab_h;
- if (index < notebook->count && index != notebook->current)
- {
- /* update tab bar */
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(notebook));
- if (dc == RT_NULL) return;
+ rtgui_notebook_set_current_by_index(notebook, index);
+ _rtgui_notebook_draw_bar(notebook, dc);
- rtgui_notebook_set_current_by_index(notebook, index);
- _rtgui_notebook_draw_bar(notebook, dc);
-
- rtgui_dc_end_drawing(dc);
- }
- }
- }
- else
- {
- /* handle on page */
- if (RTGUI_OBJECT(notebook->childs[notebook->current].widget)->event_handler != RT_NULL)
- RTGUI_OBJECT(notebook->childs[notebook->current].widget)->event_handler(
- RTGUI_OBJECT(notebook->childs[notebook->current].widget),
- &(emouse->parent));
- }
+ rtgui_dc_end_drawing(dc);
+ }
+ }
+ }
+ else
+ {
+ /* handle on page */
+ if (RTGUI_OBJECT(notebook->childs[notebook->current].widget)->event_handler != RT_NULL)
+ RTGUI_OBJECT(notebook->childs[notebook->current].widget)->event_handler(
+ RTGUI_OBJECT(notebook->childs[notebook->current].widget),
+ &(emouse->parent));
+ }
}
-static void _rtgui_notebook_get_page_rect(struct rtgui_notebook *notebook, struct rtgui_rect* rect)
+static void _rtgui_notebook_get_page_rect(struct rtgui_notebook *notebook, struct rtgui_rect *rect)
{
- struct rtgui_rect tab_rect;
+ struct rtgui_rect tab_rect;
- RT_ASSERT(notebook != RT_NULL);
- RT_ASSERT(rect != RT_NULL);
+ RT_ASSERT(notebook != RT_NULL);
+ RT_ASSERT(rect != RT_NULL);
- _rtgui_notebook_get_bar_rect(notebook, &tab_rect);
- rtgui_widget_get_rect(RTGUI_WIDGET(notebook), rect);
+ _rtgui_notebook_get_bar_rect(notebook, &tab_rect);
+ rtgui_widget_get_rect(RTGUI_WIDGET(notebook), rect);
- if (notebook->flag == RTGUI_NOTEBOOK_NOTAB)
- return;
- else if (notebook->flag == RTGUI_NOTEBOOK_TOP)
- {
- rect->y1 = tab_rect.y2;
- }
- else if (notebook->flag == RTGUI_NOTEBOOK_BOTTOM)
- {
- rect->y2 = tab_rect.y1;
- }
- else if (notebook->flag == RTGUI_NOTEBOOK_LEFT)
- {
- rect->x1 = tab_rect.x2;
- }
- else if (notebook->flag == RTGUI_NOTEBOOK_RIGHT)
- {
- rect->x2 = tab_rect.x1;
- }
+ if (notebook->flag == RTGUI_NOTEBOOK_NOTAB)
+ return;
+ else if (notebook->flag == RTGUI_NOTEBOOK_TOP)
+ {
+ rect->y1 = tab_rect.y2;
+ }
+ else if (notebook->flag == RTGUI_NOTEBOOK_BOTTOM)
+ {
+ rect->y2 = tab_rect.y1;
+ }
+ else if (notebook->flag == RTGUI_NOTEBOOK_LEFT)
+ {
+ rect->x1 = tab_rect.x2;
+ }
+ else if (notebook->flag == RTGUI_NOTEBOOK_RIGHT)
+ {
+ rect->x2 = tab_rect.x1;
+ }
}
-static void _rtgui_notebook_get_bar_rect(struct rtgui_notebook *notebook, struct rtgui_rect* rect)
+static void _rtgui_notebook_get_bar_rect(struct rtgui_notebook *notebook, struct rtgui_rect *rect)
{
- RT_ASSERT(notebook != RT_NULL);
- RT_ASSERT(rect != RT_NULL);
+ RT_ASSERT(notebook != RT_NULL);
+ RT_ASSERT(rect != RT_NULL);
- rtgui_widget_get_rect(RTGUI_WIDGET(notebook), rect);
- if (notebook->flag == RTGUI_NOTEBOOK_NOTAB)
- {
- rect->x1 = rect->y1 = rect->x2 = rect->y2 = 0;
- }
- else if (notebook->flag == RTGUI_NOTEBOOK_TOP)
- {
- rect->y2 = rect->y1 + notebook->tab_h;
- }
- else if (notebook->flag == RTGUI_NOTEBOOK_BOTTOM)
- {
- rect->y1 = rect->y2 - notebook->tab_h;
- }
- else if (notebook->flag == RTGUI_NOTEBOOK_LEFT)
- {
- rect->x2 = rect->x1 + notebook->tab_w;
- }
- else if (notebook->flag == RTGUI_NOTEBOOK_RIGHT)
- {
- rect->x1 = rect->x2 - notebook->tab_w;
- }
+ rtgui_widget_get_rect(RTGUI_WIDGET(notebook), rect);
+ if (notebook->flag == RTGUI_NOTEBOOK_NOTAB)
+ {
+ rect->x1 = rect->y1 = rect->x2 = rect->y2 = 0;
+ }
+ else if (notebook->flag == RTGUI_NOTEBOOK_TOP)
+ {
+ rect->y2 = rect->y1 + notebook->tab_h;
+ }
+ else if (notebook->flag == RTGUI_NOTEBOOK_BOTTOM)
+ {
+ rect->y1 = rect->y2 - notebook->tab_h;
+ }
+ else if (notebook->flag == RTGUI_NOTEBOOK_LEFT)
+ {
+ rect->x2 = rect->x1 + notebook->tab_w;
+ }
+ else if (notebook->flag == RTGUI_NOTEBOOK_RIGHT)
+ {
+ rect->x1 = rect->x2 - notebook->tab_w;
+ }
}
-struct rtgui_notebook* rtgui_notebook_create(const rtgui_rect_t* rect, rt_uint8_t style)
+struct rtgui_notebook *rtgui_notebook_create(const rtgui_rect_t *rect, rt_uint8_t style)
{
- struct rtgui_notebook* notebook;
+ struct rtgui_notebook *notebook;
- notebook = (struct rtgui_notebook*) rtgui_widget_create(RTGUI_NOTEBOOK_TYPE);
+ notebook = (struct rtgui_notebook *) rtgui_widget_create(RTGUI_NOTEBOOK_TYPE);
if (notebook != RT_NULL)
{
- notebook->flag = style;
- rtgui_widget_set_rect(RTGUI_WIDGET(notebook), rect);
+ notebook->flag = style;
+ rtgui_widget_set_rect(RTGUI_WIDGET(notebook), rect);
}
return notebook;
}
-void rtgui_notebook_destroy(struct rtgui_notebook* notebook)
+void rtgui_notebook_destroy(struct rtgui_notebook *notebook)
{
- rtgui_widget_destroy(RTGUI_WIDGET(notebook));
+ rtgui_widget_destroy(RTGUI_WIDGET(notebook));
}
-void rtgui_notebook_add(struct rtgui_notebook* notebook, const char* label, struct rtgui_widget* child)
+void rtgui_notebook_add(struct rtgui_notebook *notebook, const char *label, struct rtgui_widget *child)
{
- rtgui_rect_t rect;
- RT_ASSERT(notebook != RT_NULL);
+ rtgui_rect_t rect;
+ RT_ASSERT(notebook != RT_NULL);
- notebook->count += 1;
- notebook->childs = (struct rtgui_notebook_tab*)
- rtgui_realloc(notebook->childs,
- sizeof(struct rtgui_notebook_tab) * notebook->count);
+ notebook->count += 1;
+ notebook->childs = (struct rtgui_notebook_tab *)
+ rtgui_realloc(notebook->childs,
+ sizeof(struct rtgui_notebook_tab) * notebook->count);
- notebook->childs[notebook->count - 1].title = rt_strdup(label);
- notebook->childs[notebook->count - 1].widget = child;
+ notebook->childs[notebook->count - 1].title = rt_strdup(label);
+ notebook->childs[notebook->count - 1].widget = child;
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
- notebook->childs[notebook->count - 1].pressed_image = RT_NULL;
- notebook->childs[notebook->count - 1].unpressed_image = RT_NULL;
+ notebook->childs[notebook->count - 1].pressed_image = RT_NULL;
+ notebook->childs[notebook->count - 1].unpressed_image = RT_NULL;
#endif
- /* set parent */
- rtgui_widget_set_parent(child, RTGUI_WIDGET(notebook));
-
- _rtgui_notebook_get_page_rect(notebook, &rect);
- rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
- rtgui_widget_set_rect(child, &rect);
+ /* set parent */
+ rtgui_widget_set_parent(child, RTGUI_WIDGET(notebook));
if (notebook->count - 1 != notebook->current)
rtgui_widget_hide(child);
- if (RTGUI_WIDGET(notebook)->toplevel != RT_NULL &&
- RTGUI_IS_WIN(RTGUI_WIDGET(notebook)->toplevel))
- {
- struct rtgui_event_update_toplvl eup;
- RTGUI_EVENT_UPDATE_TOPLVL_INIT(&eup);
- eup.toplvl = RTGUI_WIDGET(notebook)->toplevel;
- if (RTGUI_OBJECT(child)->event_handler)
- RTGUI_OBJECT(child)->event_handler(RTGUI_OBJECT(child), (struct rtgui_event*)&eup);
- }
+ _rtgui_notebook_get_page_rect(notebook, &rect);
+ rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
+ rtgui_widget_set_rect(child, &rect);
+
+ if (RTGUI_WIDGET(notebook)->toplevel != RT_NULL &&
+ RTGUI_IS_WIN(RTGUI_WIDGET(notebook)->toplevel))
+ {
+ struct rtgui_event_update_toplvl eup;
+ RTGUI_EVENT_UPDATE_TOPLVL_INIT(&eup);
+ eup.toplvl = RTGUI_WIDGET(notebook)->toplevel;
+ if (RTGUI_OBJECT(child)->event_handler)
+ RTGUI_OBJECT(child)->event_handler(RTGUI_OBJECT(child), (struct rtgui_event *)&eup);
+ }
}
#ifdef RTGUI_USING_NOTEBOOK_IMAGE
-void rtgui_notebook_add_image(struct rtgui_notebook* notebook, const char* label, struct rtgui_widget* child,
- struct rtgui_image *pressed_image, struct rtgui_image *unpressed_image)
+void rtgui_notebook_add_image(struct rtgui_notebook *notebook, const char *label, struct rtgui_widget *child,
+ struct rtgui_image *pressed_image, struct rtgui_image *unpressed_image)
{
- rtgui_rect_t rect;
- RT_ASSERT(notebook != RT_NULL);
+ rtgui_rect_t rect;
+ RT_ASSERT(notebook != RT_NULL);
- notebook->count += 1;
- notebook->childs = (struct rtgui_notebook_tab*)
- rtgui_realloc(notebook->childs,
- sizeof(struct rtgui_notebook_tab) * notebook->count);
+ notebook->count += 1;
+ notebook->childs = (struct rtgui_notebook_tab *)
+ rtgui_realloc(notebook->childs,
+ sizeof(struct rtgui_notebook_tab) * notebook->count);
- notebook->childs[notebook->count - 1].title = rt_strdup(label);
- notebook->childs[notebook->count - 1].widget = child;
- notebook->childs[notebook->count - 1].pressed_image = pressed_image;
- notebook->childs[notebook->count - 1].unpressed_image = unpressed_image;
+ notebook->childs[notebook->count - 1].title = rt_strdup(label);
+ notebook->childs[notebook->count - 1].widget = child;
+ notebook->childs[notebook->count - 1].pressed_image = pressed_image;
+ notebook->childs[notebook->count - 1].unpressed_image = unpressed_image;
- /* set parent */
- rtgui_widget_set_parent(child, RTGUI_WIDGET(notebook));
+ /* set parent */
+ rtgui_widget_set_parent(child, RTGUI_WIDGET(notebook));
- _rtgui_notebook_get_page_rect(notebook, &rect);
- rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
- rtgui_widget_set_rect(child, &rect);
+ _rtgui_notebook_get_page_rect(notebook, &rect);
+ rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
+ rtgui_widget_set_rect(child, &rect);
- if (notebook->count - 1 != notebook->current)
- rtgui_widget_hide(child);
+ if (notebook->count - 1 != notebook->current)
+ rtgui_widget_hide(child);
- if (RTGUI_WIDGET(notebook)->toplevel != RT_NULL &&
- RTGUI_IS_WIN(RTGUI_WIDGET(notebook)->toplevel))
- {
- struct rtgui_event_update_toplvl eup;
- RTGUI_EVENT_UPDATE_TOPLVL_INIT(&eup);
- eup.toplvl = RTGUI_WIDGET(notebook)->toplevel;
- if (RTGUI_OBJECT(child)->event_handler)
- RTGUI_OBJECT(child)->event_handler(RTGUI_OBJECT(child), (struct rtgui_event*)&eup);
- }
+ if (RTGUI_WIDGET(notebook)->toplevel != RT_NULL &&
+ RTGUI_IS_WIN(RTGUI_WIDGET(notebook)->toplevel))
+ {
+ struct rtgui_event_update_toplvl eup;
+ RTGUI_EVENT_UPDATE_TOPLVL_INIT(&eup);
+ eup.toplvl = RTGUI_WIDGET(notebook)->toplevel;
+ if (RTGUI_OBJECT(child)->event_handler)
+ RTGUI_OBJECT(child)->event_handler(RTGUI_OBJECT(child), (struct rtgui_event *)&eup);
+ }
- return;
+ return;
}
#endif
-void rtgui_notebook_remove(struct rtgui_notebook* notebook, rt_uint16_t index)
+void rtgui_notebook_remove(struct rtgui_notebook *notebook, rt_uint16_t index)
{
- struct rtgui_notebook_tab tab;
+ struct rtgui_notebook_tab tab;
rt_bool_t need_update = RT_FALSE;
- RT_ASSERT(notebook != RT_NULL);
+ RT_ASSERT(notebook != RT_NULL);
- if (index < notebook->count)
- {
- if (notebook->count == 1)
- {
- tab = notebook->childs[0];
- rtgui_free(notebook->childs);
- notebook->childs = RT_NULL;
- notebook->count = 0;
- }
- else
- {
+ if (index < notebook->count)
+ {
+ if (notebook->count == 1)
+ {
+ tab = notebook->childs[0];
+ rtgui_free(notebook->childs);
+ notebook->childs = RT_NULL;
+ notebook->count = 0;
+ }
+ else
+ {
if (notebook->current == index)
need_update = RT_TRUE;
- tab = notebook->childs[index];
- for (;index < notebook->count - 1; index++)
- {
- notebook->childs[index] = notebook->childs[index + 1];
- }
+ tab = notebook->childs[index];
+ for (; index < notebook->count - 1; index++)
+ {
+ notebook->childs[index] = notebook->childs[index + 1];
+ }
- notebook->count -= 1;
- notebook->childs = (struct rtgui_notebook_tab*) rtgui_realloc(notebook->childs,
- sizeof(struct rtgui_notebook_tab) * notebook->count);
- }
+ notebook->count -= 1;
+ notebook->childs = (struct rtgui_notebook_tab *) rtgui_realloc(notebook->childs,
+ sizeof(struct rtgui_notebook_tab) * notebook->count);
+ }
- rt_free(tab.title);
+ rt_free(tab.title);
- if (need_update)
- {
- if (notebook->current > notebook->count - 1)
- notebook->current = notebook->count - 1;
+ if (need_update)
+ {
+ if (notebook->current > notebook->count - 1)
+ notebook->current = notebook->count - 1;
rtgui_widget_hide(tab.widget);
rtgui_widget_show(notebook->childs[notebook->current].widget);
- rtgui_widget_update(RTGUI_WIDGET(notebook));
+ rtgui_widget_update(RTGUI_WIDGET(notebook));
rtgui_widget_set_parent(tab.widget, RT_NULL);
- }
- }
+ }
+ }
}
-int rtgui_notebook_get_count(struct rtgui_notebook* notebook)
+int rtgui_notebook_get_count(struct rtgui_notebook *notebook)
{
- RT_ASSERT(notebook != RT_NULL);
- return notebook->count;
+ RT_ASSERT(notebook != RT_NULL);
+ return notebook->count;
}
-void rtgui_notebook_get_client_rect(struct rtgui_notebook* notebook, struct rtgui_rect *rect)
+void rtgui_notebook_get_client_rect(struct rtgui_notebook *notebook, struct rtgui_rect *rect)
{
- _rtgui_notebook_get_page_rect(notebook, rect);
- rtgui_rect_moveto(rect, 0, 0);
+ _rtgui_notebook_get_page_rect(notebook, rect);
+ rtgui_rect_moveto(rect, 0, 0);
}
-struct rtgui_widget* rtgui_notebook_get_current(struct rtgui_notebook* notebook)
+struct rtgui_widget *rtgui_notebook_get_current(struct rtgui_notebook *notebook)
{
- RT_ASSERT(notebook != RT_NULL);
- if (notebook->current != RTGUI_NOT_FOUND)
- return notebook->childs[notebook->current].widget;
+ RT_ASSERT(notebook != RT_NULL);
+ if (notebook->current != RTGUI_NOT_FOUND)
+ return notebook->childs[notebook->current].widget;
- return RT_NULL;
+ return RT_NULL;
}
-rt_int16_t rtgui_notebook_get_current_index(struct rtgui_notebook* notebook)
+rt_int16_t rtgui_notebook_get_current_index(struct rtgui_notebook *notebook)
{
- RT_ASSERT(notebook != RT_NULL);
- return notebook->current;
+ RT_ASSERT(notebook != RT_NULL);
+ return notebook->current;
}
-void rtgui_notebook_set_current(struct rtgui_notebook* notebook, struct rtgui_widget* widget)
+void rtgui_notebook_set_current(struct rtgui_notebook *notebook, struct rtgui_widget *widget)
{
- rt_int16_t index;
+ rt_int16_t index;
- RT_ASSERT(notebook != RT_NULL);
+ RT_ASSERT(notebook != RT_NULL);
- for (index = 0; index < notebook->count; index ++)
- {
- if (widget == notebook->childs[index].widget)
- {
- rtgui_notebook_set_current_by_index(notebook, index);
- return;
- }
- }
+ for (index = 0; index < notebook->count; index ++)
+ {
+ if (widget == notebook->childs[index].widget)
+ {
+ rtgui_notebook_set_current_by_index(notebook, index);
+ return;
+ }
+ }
}
-void rtgui_notebook_set_current_by_index(struct rtgui_notebook* notebook, rt_uint16_t index)
+void rtgui_notebook_set_current_by_index(struct rtgui_notebook *notebook, rt_uint16_t index)
{
- RT_ASSERT(notebook != RT_NULL);
+ RT_ASSERT(notebook != RT_NULL);
- if ((index < notebook->count) && (notebook->current != index))
- {
- struct rtgui_widget *widget;
+ if ((index < notebook->count) && (notebook->current != index))
+ {
+ struct rtgui_widget *widget;
- if (notebook->current != RTGUI_NOT_FOUND)
- rtgui_widget_hide(notebook->childs[notebook->current].widget);
+ if (notebook->current != RTGUI_NOT_FOUND)
+ rtgui_widget_hide(notebook->childs[notebook->current].widget);
- notebook->current = index;
- widget = notebook->childs[notebook->current].widget;
- rtgui_widget_show(widget);
+ notebook->current = index;
+ widget = notebook->childs[notebook->current].widget;
+ rtgui_widget_show(widget);
rtgui_widget_update_clip(widget);
- rtgui_widget_update(widget);
- rtgui_widget_focus(widget);
- }
+ rtgui_widget_update(widget);
+ rtgui_widget_focus(widget);
+ }
}
-struct rtgui_widget* rtgui_notebook_get_widget_at(struct rtgui_notebook* notebook, rt_uint16_t index)
+struct rtgui_widget *rtgui_notebook_get_widget_at(struct rtgui_notebook *notebook, rt_uint16_t index)
{
- RT_ASSERT(notebook != RT_NULL);
- if (index < notebook->count)
- return notebook->childs[index].widget;
+ RT_ASSERT(notebook != RT_NULL);
+ if (index < notebook->count)
+ return notebook->childs[index].widget;
- return RT_NULL;
+ return RT_NULL;
}
static rt_bool_t _rtgui_notebook_current_widget_handle(struct rtgui_notebook *notebook,
- struct rtgui_event *event)
+ struct rtgui_event *event)
{
- struct rtgui_widget *widget = rtgui_notebook_get_current(notebook);
- if (widget && widget != RTGUI_WIDGET(notebook))
- return RTGUI_OBJECT(widget)->event_handler(RTGUI_OBJECT(widget), event);
- else
- return RT_FALSE;
+ struct rtgui_widget *widget = rtgui_notebook_get_current(notebook);
+ if (widget && widget != RTGUI_WIDGET(notebook))
+ return RTGUI_OBJECT(widget)->event_handler(RTGUI_OBJECT(widget), event);
+ else
+ return RT_FALSE;
}
static void _rtgui_notebook_all_widget_handle(struct rtgui_notebook *notebook,
- struct rtgui_event *event)
+ struct rtgui_event *event)
{
- struct rtgui_object *object;
- int i;
- for (i = 0; i < notebook->count; i++)
- {
- object = RTGUI_OBJECT(notebook->childs[i].widget);
- if (object->event_handler)
- object->event_handler(object, event);
- }
+ struct rtgui_object *object;
+ int i;
+ for (i = 0; i < notebook->count; i++)
+ {
+ object = RTGUI_OBJECT(notebook->childs[i].widget);
+ if (object->event_handler)
+ object->event_handler(object, event);
+ }
}
-rt_bool_t rtgui_notebook_event_handler(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_notebook_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_notebook* notebook;
+ int page_index;
+ rtgui_rect_t rect;
+ struct rtgui_notebook *notebook;
- RT_ASSERT(object != RT_NULL);
- RT_ASSERT(event != RT_NULL);
+ RT_ASSERT(object != RT_NULL);
+ RT_ASSERT(event != RT_NULL);
- notebook = RTGUI_NOTEBOOK(object);
+ notebook = RTGUI_NOTEBOOK(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- _rtgui_notebook_ondraw(notebook);
- break;
- case RTGUI_EVENT_MOUSE_BUTTON:
- _rtgui_notebook_onmouse(notebook, (struct rtgui_event_mouse*)event);
- break;
- case RTGUI_EVENT_SHOW:
- /* show myself */
- rtgui_widget_onshow(object, event);
- /* show the tab widget */
- return _rtgui_notebook_current_widget_handle(notebook, event);
- case RTGUI_EVENT_HIDE:
- /* hide myself */
- rtgui_widget_onhide(object, event);
- /* hide the tab widget */
- return _rtgui_notebook_current_widget_handle(notebook, event);
- case RTGUI_EVENT_KBD:
- return _rtgui_notebook_current_widget_handle(notebook, event);
- case RTGUI_EVENT_UPDATE_TOPLVL:
- /* update myself */
- rtgui_widget_onupdate_toplvl(object, event);
- /* update all the widgets in myself */
- _rtgui_notebook_all_widget_handle(notebook, event);
- return RT_FALSE;
- default:
- /* use parent event handler */
- return rtgui_widget_event_handler(object, event);
- }
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
+ _rtgui_notebook_ondraw(notebook);
+ break;
+ case RTGUI_EVENT_MOUSE_BUTTON:
+ _rtgui_notebook_onmouse(notebook, (struct rtgui_event_mouse *)event);
+ break;
+ case RTGUI_EVENT_SHOW:
+ /* show myself */
+ rtgui_widget_onshow(object, event);
+ /* show the tab widget */
+ return _rtgui_notebook_current_widget_handle(notebook, event);
+ case RTGUI_EVENT_HIDE:
+ /* hide myself */
+ rtgui_widget_onhide(object, event);
+ /* hide the tab widget */
+ return _rtgui_notebook_current_widget_handle(notebook, event);
+ case RTGUI_EVENT_KBD:
+ return _rtgui_notebook_current_widget_handle(notebook, event);
+ case RTGUI_EVENT_UPDATE_TOPLVL:
+ /* update myself */
+ rtgui_widget_onupdate_toplvl(object, event);
+ /* update all the widgets in myself */
+ _rtgui_notebook_all_widget_handle(notebook, event);
+ return RT_FALSE;
+
+ case RTGUI_EVENT_RESIZE:
+ /* re-size page widget */
+ _rtgui_notebook_get_page_rect(notebook, &rect);
+ rtgui_widget_rect_to_device(RTGUI_WIDGET(notebook), &rect);
+ for (page_index = 0; page_index < notebook->count; page_index ++)
+ {
+ rtgui_widget_set_rect(notebook->childs[page_index].widget, &rect);
+ }
+ break;
+
+ default:
+ /* use parent event handler */
+ return rtgui_widget_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
diff --git a/components/rtgui/widgets/panel.c b/components/rtgui/widgets/panel.c
index a2aa912cc5..466835f745 100644
--- a/components/rtgui/widgets/panel.c
+++ b/components/rtgui/widgets/panel.c
@@ -18,72 +18,72 @@
static void _rtgui_panel_constructor(rtgui_panel_t *panel)
{
- /* init widget and set event handler */
- rtgui_object_set_event_handler(RTGUI_OBJECT(panel), rtgui_panel_event_handler);
+ /* init widget and set event handler */
+ rtgui_object_set_event_handler(RTGUI_OBJECT(panel), rtgui_panel_event_handler);
- /* set field */
- panel->border_style = RTGUI_BORDER_NONE;
+ /* set field */
+ panel->border_style = RTGUI_BORDER_NONE;
}
-DEFINE_CLASS_TYPE(panel, "panel",
- RTGUI_CONTAINER_TYPE,
- _rtgui_panel_constructor,
- RT_NULL,
- sizeof(struct rtgui_panel));
+DEFINE_CLASS_TYPE(panel, "panel",
+ RTGUI_CONTAINER_TYPE,
+ _rtgui_panel_constructor,
+ RT_NULL,
+ sizeof(struct rtgui_panel));
-rt_bool_t rtgui_panel_event_handler(struct rtgui_object *object, struct rtgui_event* event)
+rt_bool_t rtgui_panel_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_panel* panel;
+ struct rtgui_panel *panel;
- panel = RTGUI_PANEL(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- {
- struct rtgui_dc* dc;
- struct rtgui_rect rect;
+ panel = RTGUI_PANEL(object);
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
+ {
+ struct rtgui_dc *dc;
+ struct rtgui_rect rect;
- rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
-
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(object));
- if (dc == RT_NULL) return RT_FALSE;
+ rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
- rtgui_dc_fill_rect(dc, &rect);
- // rtgui_rect_inflate(&rect, RTGUI_WIDGET(panel)->);
- rtgui_dc_draw_border(dc, &rect, panel->border_style);
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(object));
+ if (dc == RT_NULL) return RT_FALSE;
- /* paint on each child */
- rtgui_container_dispatch_event(RTGUI_CONTAINER(panel), event);
+ rtgui_dc_fill_rect(dc, &rect);
+ // rtgui_rect_inflate(&rect, RTGUI_WIDGET(panel)->);
+ rtgui_dc_draw_border(dc, &rect, panel->border_style);
- rtgui_dc_end_drawing(dc);
- }
- break;
+ /* paint on each child */
+ rtgui_container_dispatch_event(RTGUI_CONTAINER(panel), event);
- default:
- return rtgui_container_event_handler(object, event);
- }
+ rtgui_dc_end_drawing(dc);
+ }
+ break;
+
+ default:
+ return rtgui_container_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
-rtgui_panel_t* rtgui_panel_create(int border_style)
+rtgui_panel_t *rtgui_panel_create(int border_style)
{
- struct rtgui_panel* panel;
+ struct rtgui_panel *panel;
- panel = (struct rtgui_panel*) rtgui_widget_create(RTGUI_PANEL_TYPE);
+ panel = (struct rtgui_panel *) rtgui_widget_create(RTGUI_PANEL_TYPE);
if (panel != RT_NULL)
{
- rtgui_rect_t rect = {0, 0, 100, 100};
- rtgui_widget_set_rect(RTGUI_WIDGET(panel), &rect);
+ rtgui_rect_t rect = {0, 0, 100, 100};
+ rtgui_widget_set_rect(RTGUI_WIDGET(panel), &rect);
- panel->border_style = border_style;
+ panel->border_style = border_style;
}
return panel;
}
-void rtgui_panel_destroy(rtgui_panel_t* panel)
+void rtgui_panel_destroy(rtgui_panel_t *panel)
{
- rtgui_object_destroy(RTGUI_OBJECT(panel));
+ rtgui_object_destroy(RTGUI_OBJECT(panel));
}
diff --git a/components/rtgui/widgets/plot.c b/components/rtgui/widgets/plot.c
index 6881295d87..9c3018a5c3 100644
--- a/components/rtgui/widgets/plot.c
+++ b/components/rtgui/widgets/plot.c
@@ -1,5 +1,5 @@
/*
- * File : plot.h
+ * File : plot.c
* This file is part of RT-Thread RTOS
* COPYRIGHT (C) 2012, RT-Thread Development Team
*
@@ -15,42 +15,32 @@
#include <rtgui/rtgui_system.h>
#include <rtgui/dc.h>
#include <rtgui/widgets/plot.h>
+#include <rtgui/widgets/plot_curve.h>
static void _rtgui_plot_constructor(struct rtgui_plot *plot)
{
- plot->base_point.x = plot->base_point.y = 0;
- plot->curve_container.curve = RT_NULL;
- plot->curve_container.next = RT_NULL;
+ plot->base_x = plot->base_y = 0;
+ plot->ptype = RTGUI_PLOT_TYPE_SCAN;
+ plot->scale_x = plot->scale_y = 1;
- /* init widget and set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(plot), rtgui_plot_event_handler);
}
-static void _free_curve_container_recursive(struct rtgui_plot_curve_container *cnt)
-{
- if (!cnt)
- return;
- _free_curve_container_recursive(cnt->next);
- rtgui_free(cnt);
-}
-
static void _rtgui_plot_destructor(struct rtgui_plot *plot)
{
- _free_curve_container_recursive(plot->curve_container.next);
}
DEFINE_CLASS_TYPE(plot, "plot",
- RTGUI_WIDGET_TYPE,
+ RTGUI_MV_VIEW_TYPE,
_rtgui_plot_constructor,
_rtgui_plot_destructor,
sizeof(struct rtgui_plot));
-struct rtgui_plot *rtgui_plot_create(struct rtgui_plot_curve *curve)
+struct rtgui_plot *rtgui_plot_create(void)
{
struct rtgui_plot *plot;
- plot = (struct rtgui_plot *)rtgui_widget_create(RTGUI_PLOT_TYPE);
- plot->curve_container.curve = curve;
+ plot = RTGUI_PLOT(rtgui_widget_create(RTGUI_PLOT_TYPE));
return plot;
}
@@ -58,45 +48,40 @@ RTM_EXPORT(rtgui_plot_create);
void rtgui_plot_destroy(struct rtgui_plot *plot)
{
- rtgui_widget_destroy(RTGUI_WIDGET(plot));
+ rtgui_mv_view_destroy(RTGUI_MV_VIEW(plot));
}
RTM_EXPORT(rtgui_plot_destroy);
-void rtgui_plot_set_base_point(struct rtgui_plot *plot, rt_uint16_t x, rt_uint16_t y)
+void rtgui_plot_set_base(struct rtgui_plot *plot,
+ rtgui_plot_curve_dtype x, rtgui_plot_curve_dtype y)
{
- plot->base_point.x = x;
- plot->base_point.y = y;
+ plot->base_x = x;
+ plot->base_y = y;
}
-RTM_EXPORT(rtgui_plot_set_base_point);
+RTM_EXPORT(rtgui_plot_set_base);
-void rtgui_plot_append_curve(struct rtgui_plot *plot, struct rtgui_plot_curve *curve)
+rt_inline int _rtgui_plot_curve_calc_x(struct rtgui_plot *plot, rtgui_plot_curve_dtype x)
{
- struct rtgui_plot_curve_container *cur_cnt, *next_cnt;
-
- RT_ASSERT(plot);
-
- next_cnt = rtgui_malloc(sizeof(*next_cnt));
- next_cnt->curve = curve;
- next_cnt->next = RT_NULL;
+ return (x - plot->base_x) / plot->scale_x;
+}
- cur_cnt = &plot->curve_container;
- while (cur_cnt->next)
- {
- cur_cnt = cur_cnt->next;
- }
- cur_cnt->next = next_cnt;
+rt_inline int _rtgui_plot_curve_calc_y(struct rtgui_plot *plot, rtgui_plot_curve_dtype y, rt_uint16_t height)
+{
+ return height - (y - plot->base_y) / plot->scale_y;
}
-RTM_EXPORT(rtgui_plot_append_curve);
static void _rtgui_plot_curve_onpaint(
- struct rtgui_dc *dc,
- struct rtgui_plot_curve *curve,
- struct rtgui_point base)
+ struct rtgui_dc *dc,
+ struct rtgui_plot *plot,
+ struct rtgui_plot_curve *curve,
+ rt_uint16_t start_idx,
+ rt_uint16_t stop_idx)
{
struct rtgui_rect rect;
rt_uint16_t height;
int last_x, last_y;
rtgui_color_t old_color;
+ rtgui_plot_curve_dtype *x_data, *y_data;
rtgui_dc_get_rect(dc, &rect);
height = rtgui_rect_height(rect);
@@ -104,16 +89,18 @@ static void _rtgui_plot_curve_onpaint(
old_color = RTGUI_DC_FC(dc);
RTGUI_DC_FC(dc) = curve->color;
- if (curve->x_data)
+ x_data = rtgui_plot_curve_get_x(curve);
+ y_data = rtgui_plot_curve_get_y(curve);
+ if (x_data)
{
rt_size_t i;
- last_x = curve->x_data[0] + base.x;
- last_y = height - curve->y_data[0] - base.y;
- for (i = 1; i < curve->length; i++)
+ last_x = _rtgui_plot_curve_calc_x(plot, x_data[start_idx]);
+ last_y = _rtgui_plot_curve_calc_y(plot, y_data[start_idx], height);
+ for (i = start_idx + 1; i < stop_idx; i++)
{
- int cur_x = curve->x_data[i] + base.x;
- int cur_y = height - curve->y_data[i] - base.y;
+ int cur_x = _rtgui_plot_curve_calc_x(plot, x_data[i]);
+ int cur_y = _rtgui_plot_curve_calc_y(plot, y_data[i], height);
rtgui_dc_draw_line(dc,
last_x, last_y,
cur_x, cur_y);
@@ -125,12 +112,12 @@ static void _rtgui_plot_curve_onpaint(
{
rt_size_t i;
- last_x = 0 + base.x;
- last_y = height - curve->y_data[0] - base.y;
- for (i = 1; i < curve->length; i++)
+ last_x = _rtgui_plot_curve_calc_x(plot, start_idx);
+ last_y = _rtgui_plot_curve_calc_y(plot, y_data[start_idx], height);
+ for (i = start_idx + 1; i < stop_idx; i++)
{
- int cur_x = i + base.x;
- int cur_y = height - curve->y_data[i] - base.y;
+ int cur_x = _rtgui_plot_curve_calc_x(plot, i);
+ int cur_y = _rtgui_plot_curve_calc_y(plot, y_data[i], height);
rtgui_dc_draw_line(dc,
last_x, last_y,
cur_x, cur_y);
@@ -141,44 +128,160 @@ static void _rtgui_plot_curve_onpaint(
RTGUI_DC_FC(dc) = old_color;
}
-static void _rtgui_plot_onpaint(struct rtgui_object *object, struct rtgui_event *event)
+static void _rtgui_plot_draw_curve(struct rtgui_plot *plot, struct rtgui_event *event)
{
+ int i;
struct rtgui_dc *dc;
- struct rtgui_rect rect;
- struct rtgui_plot *plot = RTGUI_PLOT(object);
- struct rtgui_plot_curve_container *cnt;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(plot));
if (dc == RT_NULL)
return;
- rtgui_widget_get_rect(RTGUI_WIDGET(object), &rect);
- rtgui_dc_fill_rect(dc, &rect);
+ if (RTGUI_MV_VIEW(plot)->model_number == 1)
+ {
+ _rtgui_plot_curve_onpaint(dc, plot,
+ RTGUI_PLOT_CURVE(RTGUI_MV_VIEW(plot)->model),
+ 0, RTGUI_MV_MODEL(RTGUI_MV_VIEW(plot)->model)->length);
+ }
+ else
+ {
+ void **curve_array = (void **)RTGUI_MV_VIEW(plot)->model;
+ for (i = 0; i < RTGUI_MV_VIEW(plot)->model_number; i++)
+ {
+ _rtgui_plot_curve_onpaint(dc, plot,
+ RTGUI_PLOT_CURVE(curve_array[i]),
+ 0, RTGUI_MV_MODEL(curve_array[i])->length);
+ }
+ }
+
+ rtgui_dc_end_drawing(dc);
+}
+
+static void _rtgui_plot_update_scale(struct rtgui_plot *plot)
+{
+ struct rtgui_plot_curve *curve;
+ struct rtgui_rect rect;
+ rtgui_plot_curve_dtype max_x = 0;
+ rtgui_plot_curve_dtype min_x = 0;
+ rtgui_plot_curve_dtype max_y = 0;
+ rtgui_plot_curve_dtype min_y = 0;
+ rt_uint32_t iter = 0;
- for (cnt = &plot->curve_container; cnt; cnt = cnt->next)
+ rtgui_widget_get_rect(RTGUI_WIDGET(plot), &rect);
+
+ curve = RTGUI_PLOT_CURVE(
+ rtgui_mv_view_foreach_in_model(RTGUI_MV_VIEW(plot), &iter));
+ max_x = curve->max_x;
+ min_x = curve->min_x;
+ max_y = curve->max_y;
+ min_y = curve->min_y;
+
+ while (curve)
{
- _rtgui_plot_curve_onpaint(dc, cnt->curve, plot->base_point);
+ if (curve->max_x > max_x)
+ max_x = curve->max_x;
+ if (curve->min_x < min_x)
+ min_x = curve->min_x;
+ if (curve->max_y > max_y)
+ max_y = curve->max_y;
+ if (curve->min_y < min_y)
+ min_y = curve->min_y;
+
+ curve = RTGUI_PLOT_CURVE(
+ rtgui_mv_view_foreach_in_model(RTGUI_MV_VIEW(plot), &iter));
}
+ plot->scale_x = (max_x - min_x + rtgui_rect_width(rect)) / rtgui_rect_width(rect);
+ plot->scale_y = (max_y - min_y + rtgui_rect_height(rect)) / rtgui_rect_height(rect);
+}
+
+rt_bool_t rtgui_plot_ondraw(struct rtgui_plot *plot, struct rtgui_event *event)
+{
+ struct rtgui_dc *dc;
+ struct rtgui_rect rect;
+
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(plot));
+ if (dc == RT_NULL)
+ return RT_FALSE;
+
+ rtgui_widget_get_rect(RTGUI_WIDGET(plot), &rect);
+
+ rtgui_dc_fill_rect(dc, &rect);
+
+ _rtgui_plot_draw_curve(plot, event);
+
rtgui_dc_end_drawing(dc);
+
+ return RT_FALSE;
+}
+
+rt_bool_t rtgui_plot_onmvmodel(struct rtgui_plot *plot, struct rtgui_event *event)
+{
+ struct rtgui_event_mv_model *emodel = (struct rtgui_event_mv_model *)event;
+
+ RT_ASSERT(plot);
+ RT_ASSERT(event);
+
+ switch (plot->ptype)
+ {
+ case RTGUI_PLOT_TYPE_SCAN:
+ _rtgui_plot_update_scale(plot);
+ rtgui_plot_ondraw(plot, event);
+ case RTGUI_PLOT_TYPE_INCREMENTAL:
+ {
+ rt_uint16_t old_sc_x = plot->scale_x;
+ rt_uint16_t old_sc_y = plot->scale_y;
+
+ _rtgui_plot_update_scale(plot);
+
+ if (old_sc_x != plot->scale_x || old_sc_y != plot->scale_y)
+ {
+ /* we need to repaint the whole widget as the scale changed. */
+ rtgui_plot_ondraw(plot, event);
+ }
+ else
+ {
+ /* get dc for _rtgui_plot_curve_onpaint */
+ struct rtgui_dc *dc;
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(plot));
+ if (dc == RT_NULL)
+ return RT_FALSE;
+
+ /* only draw the newly recieved data */
+ _rtgui_plot_curve_onpaint(dc, plot,
+ RTGUI_PLOT_CURVE(emodel->model),
+ emodel->first_data_changed_idx,
+ emodel->last_data_changed_idx + 1);
+
+ rtgui_dc_end_drawing(dc);
+ }
+ }
+ return RT_TRUE;
+ default:
+ RT_ASSERT(0);
+ }
+
+ return RT_TRUE;
}
rt_bool_t rtgui_plot_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
struct rtgui_plot *plot;
+
RTGUI_WIDGET_EVENT_HANDLER_PREPARE;
plot = RTGUI_PLOT(object);
+
switch (event->type)
{
case RTGUI_EVENT_PAINT:
- _rtgui_plot_onpaint(object, event);
- break;
+ _rtgui_plot_update_scale(RTGUI_PLOT(object));
+ return rtgui_plot_ondraw(plot, event);
+ case RTGUI_EVENT_MV_MODEL:
+ return rtgui_plot_onmvmodel(plot, event);
default:
return rtgui_widget_event_handler(object, event);
}
-
- return RT_FALSE;
}
RTM_EXPORT(rtgui_plot_event_handler);
diff --git a/components/rtgui/widgets/plot_curve.c b/components/rtgui/widgets/plot_curve.c
index 4eccbd5209..11b620da65 100644
--- a/components/rtgui/widgets/plot_curve.c
+++ b/components/rtgui/widgets/plot_curve.c
@@ -13,14 +13,14 @@
*/
#include <rtgui/color.h>
+#include <rtgui/rtgui_mv_model.h>
#include <rtgui/widgets/widget.h>
#include <rtgui/widgets/plot_curve.h>
static void _rtgui_plot_curve_constructor(struct rtgui_plot_curve *curve)
{
- curve->length = 0;
- curve->x_data = curve->y_data = RT_NULL;
curve->color = red;
+ curve->max_x = curve->min_x = curve->max_y = curve->min_y = 0;
/* init widget and set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(curve), RT_NULL);
@@ -32,20 +32,56 @@ static void _rtgui_plot_curve_destructor(struct rtgui_plot_curve *curve)
}
DEFINE_CLASS_TYPE(plot_curve, "plot_curve",
- RTGUI_OBJECT_TYPE,
+ RTGUI_MV_MODEL_TYPE,
_rtgui_plot_curve_constructor,
_rtgui_plot_curve_destructor,
sizeof(struct rtgui_plot_curve));
struct rtgui_plot_curve *rtgui_plot_curve_create(void)
{
- return (struct rtgui_plot_curve*)rtgui_object_create(RTGUI_PLOT_CURVE_TYPE);
+ struct rtgui_plot_curve *curve;
+
+ curve = RTGUI_PLOT_CURVE(rtgui_object_create(RTGUI_PLOT_CURVE_TYPE));
+ if (curve == RT_NULL)
+ return RT_NULL;
+
+ if (rtgui_mv_model_set_dimension(RTGUI_MV_MODEL(curve), 2) != RT_EOK)
+ {
+ rtgui_object_destroy(RTGUI_OBJECT(curve));
+ return RT_NULL;
+ }
+
+ return curve;
}
RTM_EXPORT(rtgui_plot_curve_create);
void rtgui_plot_curve_destroy(struct rtgui_plot_curve *curve)
{
- rtgui_object_destroy(RTGUI_OBJECT(curve));
+ rtgui_mv_model_destroy(RTGUI_MV_MODEL(curve));
}
RTM_EXPORT(rtgui_plot_curve_destroy);
+void rtgui_plot_curve_set_x(struct rtgui_plot_curve *curve, void *p)
+{
+ rtgui_mv_model_set_data(RTGUI_MV_MODEL(curve), 0, p);
+}
+RTM_EXPORT(rtgui_plot_curve_set_x);
+
+void *rtgui_plot_curve_get_x(struct rtgui_plot_curve *curve)
+{
+ return rtgui_mv_model_get_data(RTGUI_MV_MODEL(curve), 0);
+}
+RTM_EXPORT(rtgui_plot_curve_get_x);
+
+void rtgui_plot_curve_set_y(struct rtgui_plot_curve *curve, void *p)
+{
+ rtgui_mv_model_set_data(RTGUI_MV_MODEL(curve), 1, p);
+}
+RTM_EXPORT(rtgui_plot_curve_set_y);
+
+void *rtgui_plot_curve_get_y(struct rtgui_plot_curve *curve)
+{
+ return rtgui_mv_model_get_data(RTGUI_MV_MODEL(curve), 1);
+}
+RTM_EXPORT(rtgui_plot_curve_get_y);
+
diff --git a/components/rtgui/widgets/progressbar.c b/components/rtgui/widgets/progressbar.c
index bafd82995c..c140342c72 100644
--- a/components/rtgui/widgets/progressbar.c
+++ b/components/rtgui/widgets/progressbar.c
@@ -2,77 +2,77 @@
#include <rtgui/rtgui_theme.h>
#include <rtgui/widgets/progressbar.h>
-#define RTGUI_PROGRESSBAR_DEFAULT_RANGE 100
+#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_rect_t rect = {0, 0, DEFAULT_WIDTH, DEFAULT_HEIGHT};
- rtgui_object_set_event_handler(RTGUI_OBJECT(bar), rtgui_progressbar_event_handler);
- rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);
+ rtgui_object_set_event_handler(RTGUI_OBJECT(bar), rtgui_progressbar_event_handler);
+ rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);
- bar->orient = RTGUI_HORIZONTAL;
- bar->range = RTGUI_PROGRESSBAR_DEFAULT_RANGE;
- bar->position = 0;
+ bar->orient = RTGUI_HORIZONTAL;
+ bar->range = RTGUI_PROGRESSBAR_DEFAULT_RANGE;
+ bar->position = 0;
- /* set gc */
- RTGUI_WIDGET_TEXTALIGN(bar) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
+ /* set gc */
+ RTGUI_WIDGET_TEXTALIGN(bar) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
}
-DEFINE_CLASS_TYPE(progressbar, "progressbar",
- RTGUI_WIDGET_TYPE,
- _rtgui_progressbar_constructor,
- RT_NULL,
- sizeof(struct rtgui_progressbar));
+DEFINE_CLASS_TYPE(progressbar, "progressbar",
+ RTGUI_WIDGET_TYPE,
+ _rtgui_progressbar_constructor,
+ RT_NULL,
+ sizeof(struct rtgui_progressbar));
-rt_bool_t rtgui_progressbar_event_handler(struct rtgui_object* object,
- struct rtgui_event* event)
+rt_bool_t rtgui_progressbar_event_handler(struct rtgui_object *object,
+ struct rtgui_event *event)
{
- struct rtgui_progressbar* bar;
- RTGUI_WIDGET_EVENT_HANDLER_PREPARE
+ struct rtgui_progressbar *bar;
+ RTGUI_WIDGET_EVENT_HANDLER_PREPARE
- bar = RTGUI_PROGRESSBAR(object);
+ bar = RTGUI_PROGRESSBAR(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- rtgui_theme_draw_progressbar(bar);
- break;
- default:
- return rtgui_widget_event_handler(object, event);
- }
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
+ rtgui_theme_draw_progressbar(bar);
+ break;
+ default:
+ return rtgui_widget_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
-struct rtgui_progressbar* rtgui_progressbar_create(int orientation, int range,
- rtgui_rect_t* r)
+struct rtgui_progressbar *rtgui_progressbar_create(int orientation, int range,
+ rtgui_rect_t *r)
{
- struct rtgui_progressbar* bar;
+ struct rtgui_progressbar *bar;
- bar = (struct rtgui_progressbar*) rtgui_widget_create (RTGUI_PROGRESSBAR_TYPE);
+ 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);
+ if (r != RT_NULL)
+ rtgui_widget_set_rect(RTGUI_WIDGET(bar), r);
- bar->orient = orientation;
+ bar->orient = orientation;
bar->range = range;
}
return bar;
}
-void rtgui_progressbar_destroy(struct rtgui_progressbar* bar)
+void rtgui_progressbar_destroy(struct rtgui_progressbar *bar)
{
- rtgui_widget_destroy(RTGUI_WIDGET(bar));
+ rtgui_widget_destroy(RTGUI_WIDGET(bar));
}
void rtgui_progressbar_set_value(struct rtgui_progressbar *bar, int value)
{
RT_ASSERT(bar != RT_NULL);
- if (!RTGUI_WIDGET_IS_ENABLE(bar)) return;
+ if (!RTGUI_WIDGET_IS_ENABLE(bar)) return;
bar->position = value;
diff --git a/components/rtgui/widgets/radiobox.c b/components/rtgui/widgets/radiobox.c
index cab215b161..47dc92e9db 100644
--- a/components/rtgui/widgets/radiobox.c
+++ b/components/rtgui/widgets/radiobox.c
@@ -2,262 +2,262 @@
#include <rtgui/rtgui_theme.h>
#include <rtgui/widgets/radiobox.h>
-#define RTGUI_RADIOBOX_DEFAULT_WIDTH 100
-#define RTGUI_RADIOBOX_DEFAULT_HEIGHT 20
+#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};
+ 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(radiobox) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
- rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
- rtgui_object_set_event_handler(RTGUI_OBJECT(radiobox), rtgui_radiobox_event_handler);
+ /* init widget and set event handler */
+ RTGUI_WIDGET(radiobox)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+ RTGUI_WIDGET_TEXTALIGN(radiobox) = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_CENTER_VERTICAL;
+ rtgui_widget_set_rect(RTGUI_WIDGET(radiobox), &rect);
+ rtgui_object_set_event_handler(RTGUI_OBJECT(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;
+ /* set proper of control */
+ radiobox->items = RT_NULL;
+ radiobox->item_count = 0;
+ radiobox->item_selection = -1;
+ radiobox->orient = RTGUI_HORIZONTAL;
}
-DEFINE_CLASS_TYPE(radiobox, "radiobox",
- RTGUI_WIDGET_TYPE,
- _rtgui_radiobox_constructor,
- RT_NULL,
- sizeof(struct rtgui_radiobox));
+DEFINE_CLASS_TYPE(radiobox, "radiobox",
+ RTGUI_WIDGET_TYPE,
+ _rtgui_radiobox_constructor,
+ RT_NULL,
+ sizeof(struct rtgui_radiobox));
-static void rtgui_radiobox_onmouse(struct rtgui_radiobox* radiobox, struct rtgui_event_mouse* event)
+static void rtgui_radiobox_onmouse(struct rtgui_radiobox *radiobox, struct rtgui_event_mouse *event)
{
- RT_ASSERT(radiobox != RT_NULL);
- RT_ASSERT(event != RT_NULL);
+ RT_ASSERT(radiobox != RT_NULL);
+ RT_ASSERT(event != RT_NULL);
- /* widget is hide, return */
- if (RTGUI_WIDGET_IS_HIDE(radiobox) ||
- !RTGUI_WIDGET_IS_ENABLE(radiobox)) return;
+ /* widget is hide, return */
+ if (RTGUI_WIDGET_IS_HIDE(radiobox) ||
+ !RTGUI_WIDGET_IS_ENABLE(radiobox)) return;
- if (event->button & RTGUI_MOUSE_BUTTON_DOWN &&
- event->button & RTGUI_MOUSE_BUTTON_LEFT)
- {
- int bord_size;
- struct rtgui_rect rect;
+ 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));
- /* 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 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;
- /* 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(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;
+ rtgui_font_get_metrics(RTGUI_WIDGET_FONT(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);
- }
- }
+ 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_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_radiobox_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_radiobox* radiobox;
- RTGUI_WIDGET_EVENT_HANDLER_PREPARE
+ struct rtgui_radiobox *radiobox;
+ RTGUI_WIDGET_EVENT_HANDLER_PREPARE
- radiobox = RTGUI_RADIOBOX(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
+ radiobox = RTGUI_RADIOBOX(object);
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL)
- widget->on_draw(RTGUI_OBJECT(widget), event);
- else
+ if (widget->on_draw != RT_NULL)
+ widget->on_draw(RTGUI_OBJECT(widget), event);
+ else
#endif
- {
- rtgui_theme_draw_radiobox(radiobox);
- }
+ {
+ rtgui_theme_draw_radiobox(radiobox);
+ }
- break;
+ break;
- case RTGUI_EVENT_KBD:
- if (RTGUI_WIDGET_IS_HIDE(radiobox)) return RT_FALSE;
+ case RTGUI_EVENT_KBD:
+ if (RTGUI_WIDGET_IS_HIDE(radiobox)) return RT_FALSE;
#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_key != RT_NULL)
- return widget->on_key(RTGUI_OBJECT(widget), event);
- else
+ if (widget->on_key != RT_NULL)
+ return widget->on_key(RTGUI_OBJECT(widget), event);
+ else
#endif
- {
- struct rtgui_event_kbd *e = (struct rtgui_event_kbd*)event;
+ {
+ struct rtgui_event_kbd *e = (struct rtgui_event_kbd *)event;
/* set focused */
rtgui_widget_focus(RTGUI_WIDGET(radiobox));
if (!(RTGUI_KBD_IS_UP(e))) return RT_FALSE;
- if (radiobox->orient == RTGUI_VERTICAL)
- {
- if (e->key == RTGUIK_UP)
- {
- if (radiobox->item_selection > 0)
- {
- rtgui_radiobox_set_selection(radiobox, radiobox->item_selection - 1);
- return RT_TRUE;
- }
- }
- else if (e->key == RTGUIK_DOWN)
- {
- if (radiobox->item_selection < radiobox->item_count - 1)
- {
- rtgui_radiobox_set_selection(radiobox, radiobox->item_selection + 1);
- return RT_TRUE;
- }
- }
- }
- else
- {
- if (e->key == RTGUIK_LEFT)
- {
- if (radiobox->item_selection > 0)
- {
- rtgui_radiobox_set_selection(radiobox, radiobox->item_selection - 1);
- return RT_TRUE;
- }
- }
- else if (e->key == RTGUIK_RIGHT)
- {
- if (radiobox->item_selection < radiobox->item_count - 1)
- {
- rtgui_radiobox_set_selection(radiobox, radiobox->item_selection + 1);
- return RT_TRUE;
- }
- }
- }
+ if (radiobox->orient == RTGUI_VERTICAL)
+ {
+ if (e->key == RTGUIK_UP)
+ {
+ if (radiobox->item_selection > 0)
+ {
+ rtgui_radiobox_set_selection(radiobox, radiobox->item_selection - 1);
+ return RT_TRUE;
+ }
+ }
+ else if (e->key == RTGUIK_DOWN)
+ {
+ if (radiobox->item_selection < radiobox->item_count - 1)
+ {
+ rtgui_radiobox_set_selection(radiobox, radiobox->item_selection + 1);
+ return RT_TRUE;
+ }
+ }
+ }
+ else
+ {
+ if (e->key == RTGUIK_LEFT)
+ {
+ if (radiobox->item_selection > 0)
+ {
+ rtgui_radiobox_set_selection(radiobox, radiobox->item_selection - 1);
+ return RT_TRUE;
+ }
+ }
+ else if (e->key == RTGUIK_RIGHT)
+ {
+ if (radiobox->item_selection < radiobox->item_count - 1)
+ {
+ rtgui_radiobox_set_selection(radiobox, radiobox->item_selection + 1);
+ return RT_TRUE;
+ }
+ }
+ }
}
- break;
+ break;
- case RTGUI_EVENT_MOUSE_BUTTON:
+ case RTGUI_EVENT_MOUSE_BUTTON:
#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_mouseclick != RT_NULL)
- widget->on_mouseclick(RTGUI_OBJECT(widget), event);
- else
+ if (widget->on_mouseclick != RT_NULL)
+ widget->on_mouseclick(RTGUI_OBJECT(widget), event);
+ else
#endif
- {
- rtgui_radiobox_onmouse(radiobox, (struct rtgui_event_mouse*)event);
- }
- break;
- default:
- return rtgui_widget_event_handler(object, event);
- }
+ {
+ rtgui_radiobox_onmouse(radiobox, (struct rtgui_event_mouse *)event);
+ }
+ break;
+ default:
+ return rtgui_widget_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
-struct rtgui_radiobox* rtgui_radiobox_create(const char* label, int orient, char** radio_items, int number)
+struct rtgui_radiobox *rtgui_radiobox_create(const char *label, int orient, char **radio_items, int number)
{
- struct rtgui_radiobox* radiobox;
+ struct rtgui_radiobox *radiobox;
- radiobox = (struct rtgui_radiobox*) rtgui_widget_create (RTGUI_RADIOBOX_TYPE);
+ radiobox = (struct rtgui_radiobox *) rtgui_widget_create(RTGUI_RADIOBOX_TYPE);
if (radiobox != RT_NULL)
{
- rt_uint8_t board_size;
- struct rtgui_rect rect;
-
+ 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);
+ radiobox->text = rt_strdup(label);
- /* set proper of control */
- rtgui_radiobox_set_orientation(radiobox, orient);
- rtgui_font_get_metrics(RTGUI_WIDGET_FONT(radiobox), "H", &rect);
- board_size = rtgui_rect_height(rect);
+ /* set proper of control */
+ rtgui_radiobox_set_orientation(radiobox, orient);
+ rtgui_font_get_metrics(RTGUI_WIDGET_FONT(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;
+ 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(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);
- }
- }
+ /* set init item size */
+ radiobox->item_size = 0;
- if (radiobox->item_size < RADIO_BOX_H + 2)
- radiobox->item_size = RADIO_BOX_H + 2;
- }
+ font = RTGUI_WIDGET_FONT(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;
+ return radiobox;
}
-void rtgui_radiobox_set_orientation(struct rtgui_radiobox* radiobox, int orientation)
+void rtgui_radiobox_set_orientation(struct rtgui_radiobox *radiobox, int orientation)
{
- RT_ASSERT(radiobox != RT_NULL);
+ RT_ASSERT(radiobox != RT_NULL);
- /* set orientation */
- radiobox->orient = orientation;
+ /* 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);
- }
+ 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)
+void rtgui_radiobox_set_selection(struct rtgui_radiobox *radiobox, int selection)
{
- rt_uint16_t old_item;
+ rt_uint16_t old_item;
- if (selection == radiobox->item_selection) return;
+ if (selection == radiobox->item_selection) return;
- old_item = radiobox->item_selection;
+ old_item = radiobox->item_selection;
if (selection >= 0 && selection < radiobox->item_count)
{
- radiobox->item_selection = selection;
+ radiobox->item_selection = selection;
}
/* update radiobox widget */
- rtgui_theme_draw_radiobutton(radiobox, old_item);
- rtgui_theme_draw_radiobutton(radiobox, radiobox->item_selection);
+ rtgui_theme_draw_radiobutton(radiobox, old_item);
+ rtgui_theme_draw_radiobutton(radiobox, radiobox->item_selection);
}
-int rtgui_radiobox_get_selection(struct rtgui_radiobox* radiobox)
+int rtgui_radiobox_get_selection(struct rtgui_radiobox *radiobox)
{
return radiobox->item_selection;
}
diff --git a/components/rtgui/widgets/scrollbar.c b/components/rtgui/widgets/scrollbar.c
index 89e76dc24b..9b67c7210c 100644
--- a/components/rtgui/widgets/scrollbar.c
+++ b/components/rtgui/widgets/scrollbar.c
@@ -1,305 +1,663 @@
/*
- * File : scrollbar.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
- * 2010-08-09 Bernard first version
- */
+* File : scrollbar.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
+*
+*/
+#include <stdlib.h>
#include <rtgui/dc.h>
-#include <rtgui/rtgui_theme.h>
#include <rtgui/widgets/scrollbar.h>
static void _rtgui_scrollbar_constructor(rtgui_scrollbar_t *bar)
{
- struct rtgui_rect rect = {0, 0, RTGUI_DEFAULT_SB_WIDTH, RTGUI_DEFAULT_SB_HEIGHT};
-
/* set event handler */
rtgui_object_set_event_handler(RTGUI_OBJECT(bar), rtgui_scrollbar_event_handler);
- rtgui_scrollbar_set_range(bar, 0, 100);
- rtgui_scrollbar_set_page_step(bar, 20);
- rtgui_scrollbar_set_line_step(bar, 10);
-
bar->status = 0;
- bar->thumb_position = 0;
- bar->thumb_size = 16;
+ bar->value = 0;
+
+ bar->thumb_w = 16;
+ bar->thumb_len = 16;
+
+ bar->widget_link = RT_NULL;
bar->on_scroll = RT_NULL;
bar->orient = RTGUI_HORIZONTAL;
- rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);
-
/* set gc */
- RTGUI_WIDGET_TEXTALIGN(bar) = RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL;
+ RTGUI_WIDGET_TEXTALIGN(bar) = RTGUI_ALIGN_CENTER;
+}
+
+static void _rtgui_scrollbar_destructor(rtgui_scrollbar_t *bar)
+{
+
}
-rt_inline rt_uint32_t _rtgui_scrollbar_get_length(rtgui_scrollbar_t *bar)
+rt_uint32_t _rtgui_scrollbar_get_length(rtgui_scrollbar_t *bar)
{
- struct rtgui_rect rect;
+ rtgui_rect_t rect;
+ rt_uint32_t result;
rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
- if (bar->orient & RTGUI_VERTICAL)
- return rect.y2 - 2 * (rect.x2 - rect.x1);
+ if(bar->orient & RTGUI_VERTICAL)
+ result = rtgui_rect_height(rect) - 2*rtgui_rect_width(rect) - bar->thumb_len;
+ else
+ result = rtgui_rect_width(rect) - 2*rtgui_rect_height(rect) - bar->thumb_len;
- return rect.x2 - 2 * (rect.y2 - rect.y1);
+ return result;
}
-rt_inline rt_uint32_t _rtgui_scrollbar_get_thumb_position(rtgui_scrollbar_t* bar)
+rt_uint32_t get_scrollbar_pos(rtgui_scrollbar_t* bar)
{
- rt_uint32_t thumb_position;
+ double pos,ftmp;
+ rt_uint32_t result;
/* calculate thumb position */
- thumb_position = (rtgui_scrollbar_get_value(bar) - bar->min_position) * _rtgui_scrollbar_get_length(bar) /
- (bar->max_position - bar->min_position);
+ pos = bar->value;
+ ftmp = _rtgui_scrollbar_get_length(bar);
+ pos *= ftmp;
+ ftmp = bar->count;
+ pos /= ftmp;
- return thumb_position;
+ result = pos;
+ return result;
}
-void rtgui_scrollbar_get_thumb_rect(rtgui_scrollbar_t *bar, rtgui_rect_t *rect)
+DEFINE_CLASS_TYPE(scrollbar, "scrollbar",
+ RTGUI_WIDGET_TYPE,
+ _rtgui_scrollbar_constructor,
+ _rtgui_scrollbar_destructor,
+ sizeof(struct rtgui_scrollbar));
+
+rtgui_scrollbar_t* rtgui_scrollbar_create(rtgui_container_t *container,int left,int top,int w,int len,int orient)
{
- struct rtgui_rect scrollbar_rect;
+ rtgui_scrollbar_t* bar;
+
+ RT_ASSERT(container != RT_NULL);
- rtgui_widget_get_rect(RTGUI_WIDGET(bar), &scrollbar_rect);
- if (bar->orient & RTGUI_VERTICAL)
+ bar = (rtgui_scrollbar_t *)rtgui_widget_create(RTGUI_SCROLLBAR_TYPE);
+ if(bar != RT_NULL)
{
- rt_uint32_t btn_width = scrollbar_rect.x2 - scrollbar_rect.x1;
+ rtgui_rect_t rect;
- /* vertical scroll bar */
- rect->x1 = scrollbar_rect.x1;
- rect->x2 = scrollbar_rect.x2;
- rect->y1 = scrollbar_rect.y1 + btn_width + _rtgui_scrollbar_get_thumb_position(bar);
- rect->y2 = rect->y1 + btn_width;
+ rtgui_widget_get_rect(RTGUI_WIDGET(container), &rect);
+ rtgui_widget_rect_to_device(RTGUI_WIDGET(container),&rect);
+ rect.x1 += left;
+ rect.y1 += top;
+
+ bar->thumb_w = w;
+ if(orient == RTGUI_VERTICAL)
+ {
+ rect.x2 = rect.x1+w;
+ rect.y2 = rect.y1+len;
+ }
+ else
+ {
+ rect.x2 = rect.x1+len;
+ rect.y2 = rect.y1+w;
+ }
+
+ rtgui_widget_set_rect(RTGUI_WIDGET(bar), &rect);
+
+ bar->orient = orient;
+
+ rtgui_container_add_child(container, RTGUI_WIDGET(bar));
+ }
+
+ return bar;
+}
+
+void rtgui_scrollbar_destroy(rtgui_scrollbar_t* bar)
+{
+ rtgui_widget_destroy(RTGUI_WIDGET(bar));
+}
+
+const static rt_uint8_t _up_arrow[] = {0x10, 0x38, 0x7C, 0xFE};
+const static rt_uint8_t _down_arrow[] = {0xFE,0x7C, 0x38, 0x10};
+const static rt_uint8_t _left_arrow[] = {0x10, 0x30, 0x70, 0xF0, 0x70, 0x30, 0x10};
+const static rt_uint8_t _right_arrow[] = {0x80, 0xC0, 0xE0, 0xF0, 0xE0, 0xC0, 0x80};
+
+void rtgui_scrollbar_ondraw(rtgui_scrollbar_t* bar)
+{
+ /* draw scroll bar */
+ rtgui_rect_t rect, btn_rect, thum_rect, arrow_rect;
+ struct rtgui_dc* dc;
+ rtgui_color_t bc;
+
+ RT_ASSERT(bar != RT_NULL);
+
+ /* begin drawing */
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(bar));
+ if(dc == RT_NULL)return;
+
+ bc = RTGUI_DC_BC(dc);
+ /* begin drawing */
+ rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
+ RTGUI_DC_BC(dc) = white;
+ rtgui_dc_fill_rect(dc,&rect);
+ RTGUI_DC_BC(dc) = bc;
+
+ if(bar->orient == RTGUI_VERTICAL)
+ {
+ btn_rect = rect;
+ btn_rect.y2 = btn_rect.y1 + (rect.x2 - rect.x1);
+ rtgui_dc_fill_rect(dc,&btn_rect);
+ /* draw up button */
+ if(bar->status & SBS_UPARROW)
+ rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
+ else
+ rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
+ /* draw up arrow */
+ arrow_rect.x1 = 0; arrow_rect.y1 = 0;
+ arrow_rect.x2 = 7; arrow_rect.y2 = 4;
+ rtgui_rect_moveto_align(&btn_rect, &arrow_rect, RTGUI_ALIGN_CENTER);
+ rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _up_arrow);
+
+ /* draw thumb */
+ rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
+ rtgui_dc_fill_rect(dc,&thum_rect);
+ rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
+
+ /* draw down button */
+ btn_rect.y1 = rect.y2 - (rect.x2 - rect.x1);
+ btn_rect.y2 = rect.y2;
+ rtgui_dc_fill_rect(dc,&btn_rect);
+ if(bar->status & SBS_DOWNARROW)
+ rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
+ else
+ rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
+ /* draw down arrow */
+ arrow_rect.x1 = 0;
+ arrow_rect.y1 = 0;
+ arrow_rect.x2 = 7;
+ arrow_rect.y2 = 4;
+ rtgui_rect_moveto_align(&btn_rect, &arrow_rect, RTGUI_ALIGN_CENTER);
+ rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _down_arrow);
}
else
{
- rt_uint32_t btn_height = scrollbar_rect.y2 - scrollbar_rect.y1;
+ btn_rect = rect;
+ btn_rect.x2 = btn_rect.x1 + (rect.y2 - rect.y1);
+ rtgui_dc_fill_rect(dc,&btn_rect);
+ /* draw left button */
+ if(bar->status & SBS_LEFTARROW)
+ rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
+ else
+ rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
+ arrow_rect.x1 = 0;
+ arrow_rect.y1 = 0;
+ arrow_rect.x2 = 4;
+ arrow_rect.y2 = 7;
+ rtgui_rect_moveto_align(&btn_rect, &arrow_rect, RTGUI_ALIGN_CENTER);
+ rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _left_arrow);
- /* horizontal scroll bar */
- rect->x1 = scrollbar_rect.x1 + btn_height + _rtgui_scrollbar_get_thumb_position(bar);
- rect->x2 = rect->x1 + btn_height;
+ /* draw thumb */
+ if(RTGUI_WIDGET_IS_ENABLE(bar))
+ {
+ rtgui_scrollbar_get_thumb_rect(bar, &thum_rect);
+ rtgui_dc_fill_rect(dc,&thum_rect);
+ rtgui_dc_draw_border(dc, &thum_rect, RTGUI_BORDER_RAISE);
+ }
+
+ btn_rect.x1 = rect.x2 - (rect.y2-rect.y1);
+ btn_rect.x2 = rect.x2;
+ rtgui_dc_fill_rect(dc,&btn_rect);
+ /* draw right button */
+ if(bar->status & SBS_RIGHTARROW)
+ rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_SUNKEN);
+ else
+ rtgui_dc_draw_border(dc, &btn_rect, RTGUI_BORDER_RAISE);
+ arrow_rect.x1 = 0;
+ arrow_rect.y1 = 0;
+ arrow_rect.x2 = 4;
+ arrow_rect.y2 = 7;
+ rtgui_rect_moveto_align(&btn_rect, &arrow_rect, RTGUI_ALIGN_CENTER);
+ rtgui_dc_draw_byte(dc, arrow_rect.x1, arrow_rect.y1, rtgui_rect_height(arrow_rect), _right_arrow);
+
+ }
+
+ rtgui_dc_end_drawing(dc);
+}
- rect->y1 = scrollbar_rect.y1;
- rect->y2 = scrollbar_rect.y2;
+void rtgui_scrollbar_get_thumb_rect(rtgui_scrollbar_t *bar, rtgui_rect_t *erect)
+{
+ rtgui_rect_t rect;
+
+ rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
+ if(bar->orient & RTGUI_VERTICAL)
+ {
+ /* vertical scroll bar */
+ erect->x1 = rect.x1;
+ erect->x2 = rect.x2;
+ erect->y1 = rect.y1 + rtgui_rect_width(rect) + get_scrollbar_pos(bar);
+ erect->y2 = erect->y1 + bar->thumb_len;
+ }
+ else
+ {
+ /* horizontal scroll bar */
+ erect->x1 = rect.x1 + rtgui_rect_height(rect) + get_scrollbar_pos(bar);
+ erect->x2 = erect->x1 + bar->thumb_len;
+ erect->y1 = rect.y1;
+ erect->y2 = rect.y2;
}
}
-DEFINE_CLASS_TYPE(scrollbar, "scrollbar",
- RTGUI_WIDGET_TYPE,
- _rtgui_scrollbar_constructor,
- RT_NULL,
- sizeof(struct rtgui_scrollbar));
+static rtgui_point_t sbar_mouse_move_size;
-static void _rtgui_scrollbar_on_mouseclick(struct rtgui_widget * widget, struct rtgui_event * event)
+static void _rtgui_scrollbar_on_mouseclick(rtgui_scrollbar_t *bar, rtgui_event_t * event)
{
- rtgui_rect_t btn_rect, bar_rect;
- rt_uint32_t thumb_size, thumb_position;
- struct rtgui_scrollbar* bar = (struct rtgui_scrollbar*)widget;
- struct rtgui_event_mouse* mouse = (struct rtgui_event_mouse*)event;
+ rtgui_rect_t btn_rect, bar_rect,rect;
+ rt_uint32_t pos;
+ struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event;
+
+ RT_ASSERT(bar != RT_NULL);
- /* get the thumb size and position */
- thumb_size = bar->thumb_size * (bar->max_position - bar->min_position) / _rtgui_scrollbar_get_length(bar);
- thumb_position = _rtgui_scrollbar_get_thumb_position(bar);
+ /* get value */
+ pos = get_scrollbar_pos(bar);
- if (bar->orient == RTGUI_VERTICAL)
- {
+ rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
+ rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&rect);
+
+ if(bar->orient == RTGUI_VERTICAL)
+ {
+ /* arrange vertical */
/* get up arrow button rect */
- btn_rect.x1 = widget->extent.x1;
- btn_rect.x2 = widget->extent.x2;
- btn_rect.y1 = widget->extent.y1;
- btn_rect.y2 = widget->extent.y1 + (widget->extent.x2 - widget->extent.x1);
- if (rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
- {
- if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
- (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
- {
- bar->status |= SBS_UPARROW;
+ btn_rect.x1 = rect.x1;
+ btn_rect.x2 = rect.x2;
+ btn_rect.y1 = rect.y1;
+ btn_rect.y2 = rect.y1 + rtgui_rect_width(rect);
+ if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
+ {
+ if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
+ {
+ bar->status |= SBS_UPARROW;
+ if(bar->value==0)
+ {
+ rtgui_scrollbar_ondraw(bar);
+ return;
+ }
/* line step */
- bar->thumb_position -= bar->line_step;
- if (bar->thumb_position < bar->min_position) bar->thumb_position = bar->min_position;
- }
- else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
+ bar->value -= bar->line_step;
+ if(bar->value < 0) bar->value = 0;
+ }
+ else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
{
- bar->status = 0;
+ bar->status = 0;
}
goto __exit;
- }
-
- /* get bar rect */
- bar_rect.x1 = widget->extent.x1;
- bar_rect.x2 = widget->extent.x2;
- bar_rect.y1 = widget->extent.y1 + (widget->extent.x2 - widget->extent.x1);
- bar_rect.y2 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
- if (rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
- {
- if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
- (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
- {
- /* page step */
- if (mouse->y < bar_rect.y1 + thumb_position)
+ }
+ /* click on the thumb chunk, be going to dragging */
+ rtgui_scrollbar_get_thumb_rect(bar, &bar_rect);
+ rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&bar_rect);
+ if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
+ {
+ /* on thumb */
+ if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
+ {
+ /* changed status into drag */
+ bar->status |= SBS_VERTTHUMB;
+ sbar_mouse_move_size.x = mouse->x;
+ sbar_mouse_move_size.y = mouse->y;
+ }
+ else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
+ {
+ bar->status = 0;
+ }
+ goto __exit;
+ }
+ else
+ {
+ /* click on space without thumb */
+ /* get bar rect */
+ bar_rect.y1 = rect.y1 + rtgui_rect_width(rect);
+ bar_rect.y2 = rect.y2 - rtgui_rect_width(rect);
+ if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
+ {
+ if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
{
- bar->thumb_position -= bar->page_step;
- if (bar->thumb_position < bar->min_position)
- bar->thumb_position = bar->min_position;
+ /* page step */
+ if(mouse->y < bar_rect.y1 + pos)
+ {
+ bar->status |= SBS_UPSPACE;
+ bar->value -= bar->page_step;
+ if(bar->value < 0) bar->value = 0;
+ }
+ else if(mouse->y > pos + bar->thumb_len)
+ {
+ bar->status |= SBS_DOWNSPACE;
+ bar->value += bar->page_step;
+ if(bar->value > bar->count) bar->value = bar->count;
+ }
}
- else if (mouse->y > thumb_position + bar->thumb_size)
+ goto __exit;
+ }
+ }
+ /* likewise foregoing */
+ /* get down arrow button rect */
+ bar_rect.x1 = rect.x1;
+ bar_rect.x2 = rect.x2;
+ btn_rect.y1 = rect.y2 - rtgui_rect_width(rect);
+ btn_rect.y2 = rect.y2;
+ if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
+ {
+ if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
+ {
+ bar->status |= SBS_DOWNARROW;
+ if(bar->value==bar->count)
{
- bar->thumb_position += bar->page_step;
- if (bar->thumb_position > bar->max_position - thumb_size)
- bar->thumb_position = bar->max_position - thumb_size;
+ rtgui_scrollbar_ondraw(bar);
+ return;
}
- }
- goto __exit;
- }
-
- /* get down arrow button rect */
- btn_rect.y1 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
- btn_rect.y2 = widget->extent.y2;
- bar_rect.y1 = widget->extent.y1 + ((widget->extent.y2 - widget->extent.y1)/2);
- bar_rect.y2 = widget->extent.y2 - (widget->extent.x2 - widget->extent.x1);
- if (rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
- {
- if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
- (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
- {
- bar->status |= SBS_DOWNARROW;
-
/* line step */
- bar->thumb_position += bar->line_step;
- if (bar->thumb_position > bar->max_position - thumb_size)
- bar->thumb_position = bar->max_position - thumb_size;
- }
- else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
- bar->status = 0;
- }
- }
- else
- {
+ bar->value += bar->line_step;
+ if(bar->value > bar->count) bar->value = bar->count;
+ }
+ else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
+ bar->status = 0;
+ goto __exit;
+ }
+ }
+ else
+ {
/* get left arrow button rect */
- btn_rect.x1 = widget->extent.x1;
- btn_rect.x2 = widget->extent.x1 + (widget->extent.y2 - widget->extent.y1);
- btn_rect.y1 = widget->extent.y1;
- btn_rect.y2 = widget->extent.y2;
- if (rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
- {
- if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
- (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
- {
- bar->status |= SBS_LEFTARROW;
-
+ btn_rect.x1 = rect.x1;
+ btn_rect.x2 = rect.x1 + rtgui_rect_height(rect);
+ btn_rect.y1 = rect.y1;
+ btn_rect.y2 = rect.y2;
+ if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
+ {
+ if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
+ {
+ bar->status |= SBS_LEFTARROW;
+ if(bar->value==0)
+ {
+ rtgui_scrollbar_ondraw(bar);
+ return;
+ }
/* line step */
- bar->thumb_position -= bar->line_step;
- if (bar->thumb_position < bar->min_position) bar->thumb_position = bar->min_position;
- }
- else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
- bar->status = 0;
+ bar->value -= bar->line_step;
+ if(bar->value < 0) bar->value = 0;
+ }
+ else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
+ bar->status = 0;
goto __exit;
- }
+ }
- /* get bar rect */
- bar_rect.x1 = widget->extent.x1 + (widget->extent.y2 - widget->extent.y1);
- bar_rect.x2 = widget->extent.x2 - (widget->extent.y2 - widget->extent.y1);
- bar_rect.y1 = widget->extent.y1;
- bar_rect.y2 = widget->extent.y2;
- if (rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
- {
- if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
- (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
- {
- /* page step */
- if (mouse->x < bar_rect.x1 + thumb_position)
+ rtgui_scrollbar_get_thumb_rect(bar, &bar_rect);
+ rtgui_widget_rect_to_device(RTGUI_WIDGET(bar),&bar_rect);
+ if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
+ {
+ /* on the thumb */
+ if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
+ {
+ bar->status |= SBS_HORZTHUMB;
+ sbar_mouse_move_size.x = mouse->x;
+ sbar_mouse_move_size.y = mouse->y;
+ }
+ else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
+ {
+ bar->status = 0;
+ }
+ goto __exit;
+ }
+ else
+ {
+ /* get bar rect */
+ bar_rect.x1 = rect.x1 + rtgui_rect_height(rect);
+ bar_rect.x2 = rect.x2 - rtgui_rect_height(rect);
+ bar_rect.y1 = rect.y1;
+ bar_rect.y2 = rect.y2;
+ if(rtgui_rect_contains_point(&bar_rect, mouse->x, mouse->y) == RT_EOK)
+ {
+ if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
{
- bar->thumb_position -= bar->page_step;
- if (bar->thumb_position < bar->min_position)
- bar->thumb_position = bar->min_position;
+ /* page step */
+ if(mouse->x < bar_rect.x1 + pos)
+ {
+ bar->status |= SBS_LEFTSPACE;
+ bar->value -= bar->page_step;
+ if(bar->value < 0) bar->value = 0;
+ }
+ else if(mouse->x > pos + bar->thumb_len)
+ {
+ bar->status |= SBS_RIGHTSPACE;
+ bar->value += bar->page_step;
+ if(bar->value > bar->count) bar->value = bar->count;
+ }
}
- else if (mouse->x > thumb_position + bar->thumb_size)
+ else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
{
- bar->thumb_position += bar->page_step;
- if (bar->thumb_position > bar->max_position - thumb_size)
- bar->thumb_position = bar->max_position - thumb_size;
+ bar->status = 0;
}
- }
- goto __exit;
- }
-
+ goto __exit;
+ }
+ }
/* get right arrow button rect */
- btn_rect.x1 = widget->extent.x2 - (widget->extent.y2 - widget->extent.y1);
- btn_rect.x2 = widget->extent.x2;
- bar_rect.x1 = widget->extent.x1 + ((widget->extent.x2 - widget->extent.x1)/2);
- bar_rect.x2 = widget->extent.x2 - (widget->extent.y2 - widget->extent.y1);
- if (rtgui_rect_contains_point(&btn_rect,
- mouse->x, mouse->y) == RT_EOK)
- {
- if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
- (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
- {
- bar->status |= SBS_RIGHTARROW;
-
+ btn_rect.x1 = rect.x2 - rtgui_rect_height(rect);
+ btn_rect.x2 = rect.x2;
+ bar_rect.y1 = rect.y1;
+ bar_rect.y2 = rect.y2;
+ if(rtgui_rect_contains_point(&btn_rect, mouse->x, mouse->y) == RT_EOK)
+ {
+ if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
+ {
+ bar->status |= SBS_RIGHTARROW;
+ if(bar->value==bar->count)
+ {
+ rtgui_scrollbar_ondraw(bar);
+ return;
+ }
/* line step */
- bar->thumb_position += bar->line_step;
- if (bar->thumb_position > bar->max_position - bar->line_step)
- bar->thumb_position = bar->max_position - bar->line_step;
- }
- else if (mouse->button & RTGUI_MOUSE_BUTTON_UP)
- bar->status = 0;
- }
- }
+ bar->value += bar->line_step;
+ if(bar->value > bar->count) bar->value = bar->count;
+ }
+ else if(mouse->button & RTGUI_MOUSE_BUTTON_UP)
+ bar->status = 0;
+ goto __exit;
+ }
+ }
__exit:
- rtgui_theme_draw_scrollbar(bar);
- if ((mouse->button & (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN)) ==
- (RTGUI_MOUSE_BUTTON_LEFT | RTGUI_MOUSE_BUTTON_DOWN))
+ rtgui_scrollbar_ondraw(bar);
+ if((mouse->button & RTGUI_MOUSE_BUTTON_LEFT) && (mouse->button & RTGUI_MOUSE_BUTTON_DOWN))
{
- if (bar->on_scroll != RT_NULL)
- bar->on_scroll(RTGUI_OBJECT(widget), RT_NULL);
+ if(bar->widget_link != RT_NULL && bar->on_scroll != RT_NULL)
+ {
+ rtgui_widget_focus(bar->widget_link);
+ bar->on_scroll(RTGUI_OBJECT(bar->widget_link), event);
+ }
}
}
-rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_object *object,
- struct rtgui_event *event)
+/* thumb chunk activity */
+static void _rtgui_scrollbar_on_mousemotion(rtgui_scrollbar_t *bar, rtgui_event_t * event)
{
- struct rtgui_scrollbar* bar;
- RTGUI_WIDGET_EVENT_HANDLER_PREPARE
+ float tmppos;
+ rt_uint32_t pos;
+ struct rtgui_event_mouse *mouse = (struct rtgui_event_mouse*)event;
+rt_kprintf("sbar mouse motion.\n");
+ tmppos = _rtgui_scrollbar_get_length(bar);
+ tmppos /= bar->count;
+ pos = (rt_uint32_t)tmppos;
- bar = RTGUI_SCROLLBAR(object);
+ if(bar->orient == RTGUI_VERTICAL)
+ {
+ if(bar->status & SBS_VERTTHUMB)
+ {
+ /* from then on mouseclick */
+ if((mouse->y-sbar_mouse_move_size.y) > 3)
+ {
+ bar->status |= SBS_DOWNTHUMB;
+ }
+ else if((mouse->y-sbar_mouse_move_size.y) < -3)
+ {
+ bar->status |= SBS_UPTHUMB;
+ }
+ else bar->status &= ~(SBS_UPTHUMB|SBS_DOWNTHUMB);
- switch (event->type)
+ if(abs(mouse->y-sbar_mouse_move_size.y) >= pos)
+ {
+ int step = abs(mouse->y-sbar_mouse_move_size.y)/pos;
+ sbar_mouse_move_size.y = mouse->y;
+
+ if(bar->status & SBS_UPTHUMB)
+ {
+ bar->value -= step;
+ if(bar->value < 0) bar->value = 0;
+ }
+ else if(bar->status & SBS_DOWNTHUMB)
+ {
+ bar->value += step;
+ if(bar->value > bar->count) bar->value = bar->count;
+ }
+ goto __exit;
+ }
+ }
+ else if(bar->status & SBS_UPARROW)
+ {
+ /* on-going push down uparrow button */
+ if(bar->value==0)return;
+ bar->value -= bar->line_step;
+ if(bar->value < 0) bar->value = 0;
+ goto __exit;
+ }
+ else if(bar->status & SBS_DOWNARROW)
+ {
+ /* on-going push down downarrow button */
+ if(bar->value==bar->count)return;
+ bar->value += bar->line_step;
+ if(bar->value > bar->count) bar->value = bar->count;
+ goto __exit;
+ }
+ /*else if(bar->status & SBS_UPSPACE)
+ {
+ bar->value -= bar->page_step;
+ if(bar->value < 0) bar->value = 0;
+ goto __exit;
+ }
+ else if(bar->status & SBS_DOWNSPACE)
+ {
+ bar->value += bar->page_step;
+ if(bar->value > bar->count) bar->value = bar->count;
+ goto __exit;
+ }*/
+ return;
+ }
+ else
+ {
+ if(bar->status & SBS_HORZTHUMB)
+ {rt_kprintf("HORZTHUMB, move event\n");
+ if((mouse->x-sbar_mouse_move_size.x) > 5)
+ {
+ bar->status |= SBS_RIGHTTHUMB;
+ }
+ else if((mouse->x-sbar_mouse_move_size.x) < -5)
+ {
+ bar->status |= SBS_LEFTTHUMB;
+ }
+ if(abs(mouse->x-sbar_mouse_move_size.x) > pos)
+ {
+ int step = abs(mouse->x-sbar_mouse_move_size.x)/pos;
+ sbar_mouse_move_size.x = mouse->x;
+ if(bar->status & SBS_LEFTTHUMB)
+ {
+ bar->value -= step;
+ if(bar->value < 0) bar->value = 0;
+ }
+ else if(bar->status & SBS_RIGHTTHUMB)
+ {
+ bar->value += step;
+ if(bar->value > bar->count) bar->value = bar->count;
+ }
+ goto __exit;
+ }
+ }
+ else if(bar->status & SBS_LEFTARROW)
+ {
+ if(bar->value==0)return;
+ bar->value -= bar->line_step;
+ if(bar->value < 0) bar->value = 0;
+ goto __exit;
+ }
+ else if(bar->status & SBS_RIGHTARROW)
+ {
+ if(bar->value==bar->count)return;
+ bar->value += bar->line_step;
+ if(bar->value > bar->count) bar->value = bar->count;
+ goto __exit;
+ }
+ /*else if(bar->status & SBS_LEFTSPACE)
+ {
+ bar->value -= bar->page_step;
+ if(bar->value < bar->min) bar->value = bar->min;
+ goto __exit;
+ }
+ else if(bar->status & SBS_RIGHTSPACE)
+ {
+ bar->value += bar->page_step;
+ if(bar->value > bar->count-1) bar->value = bar->count-1;
+ goto __exit;
+ }*/
+ return;
+ }
+
+__exit:
+ rtgui_scrollbar_ondraw(bar);
+ if(bar->widget_link != RT_NULL && bar->on_scroll != RT_NULL)
+ {
+ rtgui_widget_focus(bar->widget_link);
+ bar->on_scroll(RTGUI_OBJECT(bar->widget_link), event);
+ }
+}
+
+
+rt_bool_t rtgui_scrollbar_event_handler(rtgui_object_t *object, rtgui_event_t *event)
+{
+ rtgui_widget_t *widget = RTGUI_WIDGET(object);
+ rtgui_scrollbar_t* bar = RTGUI_SCROLLBAR(object);
+
+ switch(event->type)
{
case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL)
- widget->on_draw(RTGUI_OBJECT(widget), event);
+ if(widget->on_draw != RT_NULL)
+ widget->on_draw(object, event);
else
#endif
{
- rtgui_theme_draw_scrollbar(bar);
+ if(!RTGUI_WIDGET_IS_HIDE(bar))
+ rtgui_scrollbar_ondraw(bar);
}
-
break;
case RTGUI_EVENT_MOUSE_BUTTON:
- if (RTGUI_WIDGET_IS_ENABLE(widget) && !RTGUI_WIDGET_IS_HIDE(widget))
+ if(RTGUI_WIDGET_IS_ENABLE(widget))
{
#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_mouseclick != RT_NULL)
+ if(widget->on_mouseclick != RT_NULL)
{
- widget->on_mouseclick(RTGUI_OBJECT(widget), event);
+ widget->on_mouseclick(object, event);
}
else
#endif
{
- _rtgui_scrollbar_on_mouseclick(widget, event);
+ _rtgui_scrollbar_on_mouseclick(bar, event);
}
}
-
break;
+ case RTGUI_EVENT_MOUSE_MOTION:
+ if(RTGUI_WIDGET_IS_ENABLE(widget))
+ {
+ _rtgui_scrollbar_on_mousemotion(bar, event);
+ }
default:
return rtgui_widget_event_handler(object, event);
@@ -308,76 +666,71 @@ rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_object *object,
return RT_FALSE;
}
-struct rtgui_scrollbar* rtgui_scrollbar_create(int orient, rtgui_rect_t* r)
+void rtgui_scrollbar_set_orientation(rtgui_scrollbar_t* bar, int orient)
{
- struct rtgui_scrollbar* bar;
+ RT_ASSERT(bar != RT_NULL);
- bar = (struct rtgui_scrollbar*) rtgui_widget_create (RTGUI_SCROLLBAR_TYPE);
- if (bar != RT_NULL)
- {
- if (r != RT_NULL)
- {
- rtgui_widget_set_rect(RTGUI_WIDGET(bar), r);
- if (orient == RTGUI_VERTICAL)
- bar->thumb_size = (r->x2 - r->x1);
- else
- bar->thumb_size = (r->y2 - r->y1);
- }
+ bar->orient = orient;
+}
- bar->orient = orient;
- }
+/* get active area length */
+rt_uint32_t get_sbar_active_len(rtgui_scrollbar_t *bar)
+{
+ rtgui_rect_t rect;
+
+ rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
- return bar;
+ if(bar->orient & RTGUI_VERTICAL)
+ return rtgui_rect_height(rect) - 2*rtgui_rect_width(rect);
+ else
+ return rtgui_rect_width(rect) - 2*rtgui_rect_height(rect);
}
-void rtgui_scrollbar_destroy(struct rtgui_scrollbar* bar)
+void rtgui_scrollbar_set_thumbbar_len(rtgui_scrollbar_t* bar)
{
- rtgui_widget_destroy(RTGUI_WIDGET(bar));
+ double size=0;
+ rt_uint32_t len,w;
+
+ RT_ASSERT(bar != RT_NULL);
+
+ /* Make sure called rtgui_scrollbar_set_range(),before you use under code. */
+ size = bar->page_step;
+ size /= bar->count+bar->page_step;
+ size *= get_sbar_active_len(bar);
+ len = (rt_uint32_t)size ;
+
+ w = bar->thumb_w;
+
+ if(len < w/2) len = w/2;
+
+ bar->thumb_len = len;
}
-void rtgui_scrollbar_set_orientation(rtgui_scrollbar_t* bar, int orientation)
+/*
+* please use them with below step:
+* 1.SetLineStep();2.SetPageStep();3.SetRange();
+*/
+
+void rtgui_scrollbar_set_line_step(rtgui_scrollbar_t* bar, int step)
{
RT_ASSERT(bar != RT_NULL);
- bar->orient = orientation;
-#ifndef RTGUI_USING_SMALL_SIZE
- if (bar->orient == RTGUI_HORIZONTAL)
- {
- /* horizontal */
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_WIDTH);
- rtgui_widget_set_miniheight(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_HEIGHT);
- }
- else
- {
- /* vertical */
- rtgui_widget_set_miniwidth(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_HEIGHT);
- rtgui_widget_set_miniheight(RTGUI_WIDGET(bar), RTGUI_DEFAULT_SB_WIDTH);
- }
-#endif
+ bar->line_step = step;
}
-void rtgui_scrollbar_set_range(struct rtgui_scrollbar* bar, int min, int max)
+void rtgui_scrollbar_set_page_step(rtgui_scrollbar_t* bar, int step)
{
RT_ASSERT(bar != RT_NULL);
- if (min >= max )
- {
- RTGUI_WIDGET_DISABLE(bar);
- return;
- }
-
- bar->min_position = (rt_int16_t)min;
- bar->max_position = (rt_int16_t)max;
+ bar->page_step = step;
}
-void rtgui_scrollbar_set_page_step(struct rtgui_scrollbar* bar, int step)
+void rtgui_scrollbar_set_range(rtgui_scrollbar_t* bar, int count)
{
RT_ASSERT(bar != RT_NULL);
- bar->page_step = step;
-
/* disable or enable scrollbar */
- if (bar->page_step > (bar->max_position - bar->min_position))
+ if(bar->page_step >= count)
{
/* disable bar */
RTGUI_WIDGET_DISABLE(bar);
@@ -387,34 +740,51 @@ void rtgui_scrollbar_set_page_step(struct rtgui_scrollbar* bar, int step)
/* enable bar */
RTGUI_WIDGET_ENABLE(bar);
}
+
+ /* thumb step count = item_count-item_per_page */
+ bar->count = (rt_int16_t)(count-bar->page_step);
+ rtgui_scrollbar_set_thumbbar_len(bar);
}
-void rtgui_scrollbar_set_line_step(struct rtgui_scrollbar* bar, int step)
+/* use VALUE change be binding widget's frist item. */
+void rtgui_scrollbar_set_value(rtgui_scrollbar_t* bar, rt_int16_t value)
{
RT_ASSERT(bar != RT_NULL);
- bar->line_step = step;
+ bar->value = value;
+
+ if(bar->value < 0) bar->value = 0;
+
+ rtgui_widget_update(RTGUI_WIDGET(bar));
}
-rt_int16_t rtgui_scrollbar_get_value(struct rtgui_scrollbar* bar)
+void rtgui_scrollbar_set_onscroll(rtgui_scrollbar_t* bar, rtgui_event_handler_ptr handler)
{
- RT_ASSERT(bar != RT_NULL);
+ if(bar == RT_NULL || handler == RT_NULL) return;
- return bar->thumb_position;
+ bar->on_scroll = handler;
}
-void rtgui_scrollbar_set_value(struct rtgui_scrollbar* bar, rt_int16_t position)
+void rtgui_scrollbar_hide(rtgui_scrollbar_t* bar)
{
+ rtgui_rect_t rect;
+ struct rtgui_dc* dc;
+
RT_ASSERT(bar != RT_NULL);
- bar->thumb_position = position;
- rtgui_widget_update(RTGUI_WIDGET(bar));
-}
+ /* begin drawing */
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(bar));
+ if(dc == RT_NULL)return;
-void rtgui_scrollbar_set_onscroll(struct rtgui_scrollbar* bar,
- rtgui_event_handler_ptr handler)
-{
- if (bar == RT_NULL || handler == RT_NULL) return;
+ RTGUI_WIDGET_HIDE(bar);
- bar->on_scroll = handler;
+ /* begin drawing */
+ rtgui_widget_get_rect(RTGUI_WIDGET(bar), &rect);
+ if((RTGUI_WIDGET(bar))->parent != RT_NULL)
+ RTGUI_DC_BC(dc) = RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(bar)->parent);
+ else
+ RTGUI_DC_BC(dc) = RTGUI_RGB(225, 228, 220);
+ rtgui_dc_fill_rect(dc,&rect);
+
+ rtgui_dc_end_drawing(dc);
}
diff --git a/components/rtgui/widgets/slider.c b/components/rtgui/widgets/slider.c
index a7367c1883..e592183f07 100644
--- a/components/rtgui/widgets/slider.c
+++ b/components/rtgui/widgets/slider.c
@@ -16,289 +16,289 @@
#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
+#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 rt_bool_t rtgui_slider_onunfocus(struct rtgui_object* object, rtgui_event_t* event);
+static rt_bool_t rtgui_slider_onunfocus(struct rtgui_object *object, rtgui_event_t *event);
static void _rtgui_slider_constructor(rtgui_slider_t *slider)
{
- rtgui_rect_t rect = {0, 0, RTGUI_SLIDER_DEFAULT_WIDTH, RTGUI_SLIDER_DEFAULT_HEIGHT};
+ 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_object_set_event_handler(RTGUI_OBJECT(slider), rtgui_slider_event_handler);
- rtgui_widget_set_onunfocus(RTGUI_WIDGET(slider), rtgui_slider_onunfocus);
- /* 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;
+ /* init widget and set event handler */
+ RTGUI_WIDGET(slider)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+ rtgui_widget_set_rect(RTGUI_WIDGET(slider), &rect);
+ rtgui_object_set_event_handler(RTGUI_OBJECT(slider), rtgui_slider_event_handler);
+ rtgui_widget_set_onunfocus(RTGUI_WIDGET(slider), rtgui_slider_onunfocus);
+ /* 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;
- slider->on_changed = RT_NULL;
+ slider->ticks = 10;
+ slider->thumb_width = 8;
+ slider->on_changed = RT_NULL;
}
-DEFINE_CLASS_TYPE(slider, "slider",
- RTGUI_WIDGET_TYPE,
- _rtgui_slider_constructor,
- RT_NULL,
- sizeof(struct rtgui_slider));
+DEFINE_CLASS_TYPE(slider, "slider",
+ RTGUI_WIDGET_TYPE,
+ _rtgui_slider_constructor,
+ RT_NULL,
+ sizeof(struct rtgui_slider));
-static void rtgui_slider_onmouse(struct rtgui_slider* slider, struct rtgui_event_mouse* event)
+static void rtgui_slider_onmouse(struct rtgui_slider *slider, struct rtgui_event_mouse *event)
{
- RT_ASSERT(slider != RT_NULL);
- RT_ASSERT(event != RT_NULL);
+ 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 (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 (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;
- }
+ 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);
- if (slider->on_changed != RT_NULL) /* invoke callback function */
- slider->on_changed(RTGUI_WIDGET(slider), RT_NULL);
- }
+ rtgui_widget_focus(RTGUI_WIDGET(slider));
+ rtgui_slider_set_value(slider, sel);
+ if (slider->on_changed != RT_NULL) /* invoke callback function */
+ slider->on_changed(RTGUI_WIDGET(slider), RT_NULL);
+ }
}
-static rt_bool_t rtgui_slider_onkey(struct rtgui_slider* slider, struct rtgui_event_kbd *event)
+static rt_bool_t rtgui_slider_onkey(struct rtgui_slider *slider, struct rtgui_event_kbd *event)
{
- RT_ASSERT(slider != RT_NULL);
- RT_ASSERT(event != RT_NULL);
+ RT_ASSERT(slider != RT_NULL);
+ RT_ASSERT(event != RT_NULL);
- if (!(RTGUI_KBD_IS_UP(event)))
- return RT_TRUE;
+ if (!(RTGUI_KBD_IS_UP(event)))
+ return RT_TRUE;
- if (slider->orient == RTGUI_HORIZONTAL)
- {
- if (event->key == RTGUIK_RIGHT)
- {
- if (slider->value > slider->min)
- slider->value++;
- }
- else if (event->key == RTGUIK_LEFT)
- {
- if (slider->value < slider->max)
- slider->value--;
- }
- }
- else
- {
- if (event->key == RTGUIK_UP)
- {
- if (slider->value > slider->min)
- slider->value--;
- }
- else if (event->key == RTGUIK_DOWN)
- {
- if (slider->value < slider->max)
- slider->value++;
- }
- }
+ if (slider->orient == RTGUI_HORIZONTAL)
+ {
+ if (event->key == RTGUIK_RIGHT)
+ {
+ if (slider->value > slider->min)
+ slider->value++;
+ }
+ else if (event->key == RTGUIK_LEFT)
+ {
+ if (slider->value < slider->max)
+ slider->value--;
+ }
+ }
+ else
+ {
+ if (event->key == RTGUIK_UP)
+ {
+ if (slider->value > slider->min)
+ slider->value--;
+ }
+ else if (event->key == RTGUIK_DOWN)
+ {
+ if (slider->value < slider->max)
+ slider->value++;
+ }
+ }
- /* update widget */
- rtgui_widget_update(RTGUI_WIDGET(slider));
- if (slider->on_changed != RT_NULL) /* invoke callback function */
- slider->on_changed(RTGUI_WIDGET(slider), RT_NULL);
+ /* update widget */
+ rtgui_widget_update(RTGUI_WIDGET(slider));
+ if (slider->on_changed != RT_NULL) /* invoke callback function */
+ slider->on_changed(RTGUI_WIDGET(slider), RT_NULL);
- return RT_TRUE;
+ return RT_TRUE;
}
rt_bool_t rtgui_slider_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_widget *widget;
- struct rtgui_slider* slider;
+ struct rtgui_widget *widget;
+ struct rtgui_slider *slider;
- RT_ASSERT(object != RT_NULL);
- RT_ASSERT(event != RT_NULL);
+ RT_ASSERT(object != RT_NULL);
+ RT_ASSERT(event != RT_NULL);
- widget = RTGUI_WIDGET(object);
- slider = RTGUI_SLIDER(object);
+ widget = RTGUI_WIDGET(object);
+ slider = RTGUI_SLIDER(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL)
- widget->on_draw(RTGUI_OBJECT(widget), event);
- else
+ if (widget->on_draw != RT_NULL)
+ widget->on_draw(RTGUI_OBJECT(widget), event);
+ else
#endif
- {
- rtgui_theme_draw_slider(slider);
- }
+ {
+ rtgui_theme_draw_slider(slider);
+ }
- break;
+ break;
- case RTGUI_EVENT_KBD:
- if (!RTGUI_WIDGET_IS_ENABLE(widget) || RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
+ case RTGUI_EVENT_KBD:
+ if (!RTGUI_WIDGET_IS_ENABLE(widget) || RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_key != RT_NULL)
- return widget->on_key(RTGUI_OBJECT(widget), event);
- else
+ if (widget->on_key != RT_NULL)
+ return widget->on_key(RTGUI_OBJECT(widget), event);
+ else
#endif
- return rtgui_slider_onkey(slider, (struct rtgui_event_kbd *)event);
+ return rtgui_slider_onkey(slider, (struct rtgui_event_kbd *)event);
- case RTGUI_EVENT_MOUSE_BUTTON:
- if (!RTGUI_WIDGET_IS_ENABLE(widget) || RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
+ case RTGUI_EVENT_MOUSE_BUTTON:
+ if (!RTGUI_WIDGET_IS_ENABLE(widget) || RTGUI_WIDGET_IS_HIDE(widget)) return RT_FALSE;
#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_mouseclick != RT_NULL)
- widget->on_mouseclick(RTGUI_OBJECT(widget), event);
- else
+ if (widget->on_mouseclick != RT_NULL)
+ widget->on_mouseclick(RTGUI_OBJECT(widget), event);
+ else
#endif
- {
- rtgui_slider_onmouse(slider, (struct rtgui_event_mouse*)event);
- }
- break;
+ {
+ rtgui_slider_onmouse(slider, (struct rtgui_event_mouse *)event);
+ }
+ break;
- default:
- return rtgui_widget_event_handler(object, event);
- }
+ default:
+ return rtgui_widget_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_slider_event_handler);
-struct rtgui_slider* rtgui_slider_create(rt_size_t min, rt_size_t max, int orient)
+struct rtgui_slider *rtgui_slider_create(rt_size_t min, rt_size_t max, int orient)
{
- struct rtgui_slider* slider;
+ struct rtgui_slider *slider;
- slider = (struct rtgui_slider*) rtgui_widget_create (RTGUI_SLIDER_TYPE);
+ 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;
+ /* set proper of control */
+ slider->min = min;
+ slider->max = max;
+ slider->value = min;
- slider->ticks = 10;
- slider->thumb_width = 8;
+ slider->ticks = 10;
+ slider->thumb_width = 8;
- rtgui_slider_set_orientation(slider, orient);
- }
+ rtgui_slider_set_orientation(slider, orient);
+ }
- return slider;
+ return slider;
}
RTM_EXPORT(rtgui_slider_create);
-void rtgui_slider_set_range(struct rtgui_slider* slider, rt_size_t min, rt_size_t max)
+void rtgui_slider_set_range(struct rtgui_slider *slider, rt_size_t min, rt_size_t max)
{
- RT_ASSERT(slider != RT_NULL);
+ RT_ASSERT(slider != RT_NULL);
- slider->max = max;
- slider->min = min;
+ slider->max = max;
+ slider->min = min;
}
RTM_EXPORT(rtgui_slider_set_range);
-void rtgui_slider_set_value(struct rtgui_slider* slider, rt_size_t value)
+void rtgui_slider_set_value(struct rtgui_slider *slider, rt_size_t value)
{
- RT_ASSERT(slider != RT_NULL);
+ RT_ASSERT(slider != RT_NULL);
- if (RTGUI_WIDGET_IS_ENABLE(slider))
- {
- if (value < slider->min) value = slider->min;
- if (value > slider->max) value = slider->max;
+ if (RTGUI_WIDGET_IS_ENABLE(slider))
+ {
+ 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);
- }
- }
+ if (slider->value != value)
+ {
+ slider->value = value;
+ rtgui_theme_draw_slider(slider);
+ }
+ }
}
RTM_EXPORT(rtgui_slider_set_value);
-void rtgui_slider_set_orientation(struct rtgui_slider* slider, int orientation)
+void rtgui_slider_set_orientation(struct rtgui_slider *slider, int orientation)
{
- RT_ASSERT(slider != RT_NULL);
+ RT_ASSERT(slider != RT_NULL);
- /* set orientation */
- slider->orient = orientation;
+ /* 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);
- }
+ 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
}
RTM_EXPORT(rtgui_slider_set_orientation);
-rt_size_t rtgui_slider_get_value(struct rtgui_slider* slider)
+rt_size_t rtgui_slider_get_value(struct rtgui_slider *slider)
{
- RT_ASSERT(slider != RT_NULL);
+ RT_ASSERT(slider != RT_NULL);
- return slider->value;
+ return slider->value;
}
RTM_EXPORT(rtgui_slider_get_value);
-static rt_bool_t rtgui_slider_onunfocus(struct rtgui_object* object, rtgui_event_t* event)
+static rt_bool_t rtgui_slider_onunfocus(struct rtgui_object *object, rtgui_event_t *event)
{
- rtgui_rect_t rect;
- rtgui_widget_t *widget;
- struct rtgui_dc *dc;
+ rtgui_rect_t rect;
+ rtgui_widget_t *widget;
+ struct rtgui_dc *dc;
- RT_ASSERT(object);
- widget = RTGUI_WIDGET(object);
+ RT_ASSERT(object);
+ widget = RTGUI_WIDGET(object);
- dc = rtgui_dc_begin_drawing(widget);
- if(dc == RT_NULL) return RT_FALSE;
+ dc = rtgui_dc_begin_drawing(widget);
+ if (dc == RT_NULL) return RT_FALSE;
- rtgui_widget_get_rect(widget, &rect);
+ rtgui_widget_get_rect(widget, &rect);
- if(!RTGUI_WIDGET_IS_FOCUSED(widget))
- {
- /* only clear focus rect */
- rtgui_color_t color = RTGUI_DC_FC(dc);
- RTGUI_DC_FC(dc) = RTGUI_DC_BC(dc);
- rtgui_dc_draw_focus_rect(dc, &rect);
- RTGUI_DC_FC(dc) = color;
- }
+ if (!RTGUI_WIDGET_IS_FOCUSED(widget))
+ {
+ /* only clear focus rect */
+ rtgui_color_t color = RTGUI_DC_FC(dc);
+ RTGUI_DC_FC(dc) = RTGUI_DC_BC(dc);
+ rtgui_dc_draw_focus_rect(dc, &rect);
+ RTGUI_DC_FC(dc) = color;
+ }
- rtgui_dc_end_drawing(dc);
- return RT_TRUE;
+ rtgui_dc_end_drawing(dc);
+ return RT_TRUE;
}
diff --git a/components/rtgui/widgets/staticline.c b/components/rtgui/widgets/staticline.c
index 1c41ccedac..2187f0131c 100644
--- a/components/rtgui/widgets/staticline.c
+++ b/components/rtgui/widgets/staticline.c
@@ -4,84 +4,84 @@
static void _rtgui_staticline_constructor(rtgui_staticline_t *staticline)
{
- /* init widget and set event handler */
- rtgui_rect_t rect = {0, 0, 100, 2};
+ /* init widget and set event handler */
+ rtgui_rect_t rect = {0, 0, 100, 2};
- rtgui_widget_set_rect(RTGUI_WIDGET(staticline), &rect);
- staticline->orient= RTGUI_HORIZONTAL;
+ rtgui_widget_set_rect(RTGUI_WIDGET(staticline), &rect);
+ staticline->orient = RTGUI_HORIZONTAL;
- rtgui_object_set_event_handler(RTGUI_OBJECT(staticline), rtgui_staticline_event_handler);
+ rtgui_object_set_event_handler(RTGUI_OBJECT(staticline), rtgui_staticline_event_handler);
}
-DEFINE_CLASS_TYPE(staticline, "staticline",
- RTGUI_WIDGET_TYPE,
- _rtgui_staticline_constructor,
- RT_NULL,
- sizeof(struct rtgui_staticline));
+DEFINE_CLASS_TYPE(staticline, "staticline",
+ RTGUI_WIDGET_TYPE,
+ _rtgui_staticline_constructor,
+ RT_NULL,
+ sizeof(struct rtgui_staticline));
-rt_bool_t rtgui_staticline_event_handler(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_staticline_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_staticline* staticline;
- RTGUI_WIDGET_EVENT_HANDLER_PREPARE
+ struct rtgui_staticline *staticline;
+ RTGUI_WIDGET_EVENT_HANDLER_PREPARE
- staticline = RTGUI_STATICLINE(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
+ staticline = RTGUI_STATICLINE(object);
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
- if (widget->on_draw != RT_NULL)
- widget->on_draw(RTGUI_OBJECT(widget), event);
- else
+ if (widget->on_draw != RT_NULL)
+ widget->on_draw(RTGUI_OBJECT(widget), event);
+ else
#endif
- rtgui_theme_draw_staticline(staticline);
- break;
- default:
- return rtgui_widget_event_handler(object, event);
- }
+ rtgui_theme_draw_staticline(staticline);
+ break;
+ default:
+ return rtgui_widget_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_staticline_event_handler);
-rtgui_staticline_t * rtgui_staticline_create(int orientation)
+rtgui_staticline_t *rtgui_staticline_create(int orientation)
{
- rtgui_staticline_t* staticline;
+ rtgui_staticline_t *staticline;
- staticline = (struct rtgui_staticline*) rtgui_widget_create(RTGUI_STATICLINE_TYPE);
- if (staticline!= RT_NULL)
- {
- rtgui_staticline_set_orientation(staticline, orientation);
- }
+ staticline = (struct rtgui_staticline *) rtgui_widget_create(RTGUI_STATICLINE_TYPE);
+ if (staticline != RT_NULL)
+ {
+ rtgui_staticline_set_orientation(staticline, orientation);
+ }
- return staticline;
+ return staticline;
}
RTM_EXPORT(rtgui_staticline_create);
-void rtgui_staticline_destroy(rtgui_staticline_t* staticline)
+void rtgui_staticline_destroy(rtgui_staticline_t *staticline)
{
- rtgui_widget_destroy(RTGUI_WIDGET(staticline));
+ rtgui_widget_destroy(RTGUI_WIDGET(staticline));
}
RTM_EXPORT(rtgui_staticline_destroy);
-void rtgui_staticline_set_orientation(rtgui_staticline_t* staticline, int orientation)
+void rtgui_staticline_set_orientation(rtgui_staticline_t *staticline, int orientation)
{
- RT_ASSERT(staticline != RT_NULL);
+ RT_ASSERT(staticline != RT_NULL);
- staticline->orient = orientation;
+ staticline->orient = 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);
- }
+ 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
}
RTM_EXPORT(rtgui_staticline_set_orientation);
diff --git a/components/rtgui/widgets/textbox.c b/components/rtgui/widgets/textbox.c
index 9023624b35..9dd2cafca2 100644
--- a/components/rtgui/widgets/textbox.c
+++ b/components/rtgui/widgets/textbox.c
@@ -1,19 +1,19 @@
/*
- * 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
- * 2011-01-224 Bernard fix backspace issue.
- * 2012-06-09 asml refactor
- * 2012-06-17 Grissiom misc cleanup and merge
- */
+* 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
+* 2011-01-224 Bernard fix backspace issue.
+* 2012-06-09 asml refactor
+* 2012-06-17 Grissiom misc cleanup and merge
+*/
#include <string.h>
#include <rtgui/widgets/textbox.h>
#include <rtgui/widgets/combobox.h>
@@ -22,9 +22,9 @@
#include <ctype.h>
static void rtgui_textbox_draw_caret(rtgui_textbox_t *box, rt_uint16_t position);
-static rt_bool_t rtgui_textbox_onkey(struct rtgui_object* widget, rtgui_event_t* event);
-static rt_bool_t rtgui_textbox_onfocus(struct rtgui_object* widget, rtgui_event_t* event);
-static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_object* widget, rtgui_event_t* event);
+static rt_bool_t rtgui_textbox_onkey(struct rtgui_object *widget, rtgui_event_t *event);
+static rt_bool_t rtgui_textbox_onfocus(struct rtgui_object *widget, rtgui_event_t *event);
+static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_object *widget, rtgui_event_t *event);
static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
{
@@ -36,7 +36,7 @@ static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
rtgui_widget_set_onfocus(RTGUI_WIDGET(box), rtgui_textbox_onfocus);
rtgui_widget_set_onunfocus(RTGUI_WIDGET(box), rtgui_textbox_onunfocus);
#ifndef RTGUI_USING_SMALL_SIZE
- rtgui_widget_set_onkey(RTGUI_WIDGET(box),rtgui_textbox_onkey);
+ rtgui_widget_set_onkey(RTGUI_WIDGET(box), rtgui_textbox_onkey);
#endif
RTGUI_WIDGET_FOREGROUND(box) = black;
@@ -51,26 +51,28 @@ static void _rtgui_textbox_constructor(rtgui_textbox_t *box)
box->flag = RTGUI_TEXTBOX_SINGLE;
/* allocate default line buffer */
box->text = RT_NULL;
+ rtgui_textbox_set_mask_char(box, '*');
rtgui_font_get_metrics(RTGUI_WIDGET_FONT(box), "H", &rect);
box->font_width = rtgui_rect_width(rect);
box->on_enter = RT_NULL;
box->dis_length = 0;
+ box->first_pos = 0;
}
static void _rtgui_textbox_deconstructor(rtgui_textbox_t *textbox)
{
- if(textbox->text != RT_NULL)
+ if (textbox->text != RT_NULL)
{
rtgui_free(textbox->text);
textbox->text = RT_NULL;
}
- if(textbox->caret_timer != RT_NULL)
+ if (textbox->caret_timer != RT_NULL)
{
rtgui_timer_destory(textbox->caret_timer);
textbox->caret_timer = RT_NULL;
}
- if(textbox->caret != RT_NULL)
+ if (textbox->caret != RT_NULL)
{
rtgui_free(textbox->caret);
textbox->caret = RT_NULL;
@@ -78,14 +80,14 @@ static void _rtgui_textbox_deconstructor(rtgui_textbox_t *textbox)
}
DEFINE_CLASS_TYPE(textbox, "textbox",
- RTGUI_WIDGET_TYPE,
- _rtgui_textbox_constructor,
- _rtgui_textbox_deconstructor,
- sizeof(struct rtgui_textbox));
+ RTGUI_WIDGET_TYPE,
+ _rtgui_textbox_constructor,
+ _rtgui_textbox_deconstructor,
+ sizeof(struct rtgui_textbox));
static void rtgui_textbox_get_caret_rect(rtgui_textbox_t *box, rtgui_rect_t *rect, rt_uint16_t position)
{
- int font_h,box_h;
+ int font_h, box_h;
rtgui_rect_t item_rect;
RT_ASSERT(box != RT_NULL);
@@ -119,11 +121,11 @@ static void rtgui_textbox_init_caret(rtgui_textbox_t *box, rt_uint16_t position)
rtgui_widget_rect_to_device(RTGUI_WIDGET(box), &rect);
if (box->caret == RT_NULL)
- box->caret = rtgui_malloc(rtgui_rect_width(rect)*rtgui_rect_height(rect)*sizeof(rtgui_color_t));
+ box->caret = rtgui_malloc(rtgui_rect_width(rect) * rtgui_rect_height(rect) * sizeof(rtgui_color_t));
for (x = rect.x1; x < rect.x2; x++)
{
- for(y = rect.y1; y < rect.y2; y++)
+ for (y = rect.y1; y < rect.y2; y++)
{
rtgui_graphic_driver_get_default()->ops->get_pixel(&color, x, y);
*(box->caret + ofs) = color;
@@ -135,7 +137,7 @@ static void rtgui_textbox_init_caret(rtgui_textbox_t *box, rt_uint16_t position)
/* draw caret */
static void rtgui_textbox_draw_caret(rtgui_textbox_t *box, rt_uint16_t position)
{
- int x,y;
+ int x, y;
rtgui_color_t color;
rtgui_rect_t rect;
int ofs = 0;
@@ -151,13 +153,13 @@ static void rtgui_textbox_draw_caret(rtgui_textbox_t *box, rt_uint16_t position)
rect = box->caret_rect;
- for(x = rect.x1; x < rect.x2; x++)
+ for (x = rect.x1; x < rect.x2; x++)
{
- for(y = rect.y1; y < rect.y2; y++)
+ for (y = rect.y1; y < rect.y2; y++)
{
color = *(box->caret + ofs);
ofs++;
- if(box->flag & RTGUI_TEXTBOX_CARET_SHOW)
+ if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
{
color = ~color;
}
@@ -168,20 +170,20 @@ static void rtgui_textbox_draw_caret(rtgui_textbox_t *box, rt_uint16_t position)
rtgui_dc_end_drawing(dc);
}
-static void rtgui_textbox_timeout(rtgui_timer_t* timer, void* parameter)
+static void rtgui_textbox_timeout(rtgui_timer_t *timer, void *parameter)
{
- rtgui_textbox_t* box;
+ rtgui_textbox_t *box;
box = RTGUI_TEXTBOX(parameter);
/* set caret flag */
- if(box->flag & RTGUI_TEXTBOX_CARET_SHOW)
+ if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
box->flag &= ~RTGUI_TEXTBOX_CARET_SHOW;
else
box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
- rtgui_textbox_draw_caret(box,box->position);
+ rtgui_textbox_draw_caret(box, box->position);
}
-static void rtgui_textbox_onmouse(rtgui_textbox_t* box, struct rtgui_event_mouse* event)
+static void rtgui_textbox_onmouse(rtgui_textbox_t *box, struct rtgui_event_mouse *event)
{
rt_size_t length;
rt_uint16_t posbak = box->position;
@@ -191,47 +193,47 @@ static void rtgui_textbox_onmouse(rtgui_textbox_t* box, struct rtgui_event_mouse
length = rt_strlen(box->text);
- if(event->button & RTGUI_MOUSE_BUTTON_LEFT && event->button & RTGUI_MOUSE_BUTTON_DOWN)
+ if (event->button & RTGUI_MOUSE_BUTTON_LEFT && event->button & RTGUI_MOUSE_BUTTON_DOWN)
{
rt_int32_t x;
/* single line text */
/* set caret position */
x = event->x - RTGUI_WIDGET(box)->extent.x1;
- if(x < 0)
+ if (x < 0)
{
box->position = 0;
}
- else if(x > length * box->font_width)
+ else if (x > (length - box->first_pos) * box->font_width)
{
- box->position = length;
+ box->position = length - box->first_pos;
}
else
{
box->position = x / box->font_width;
}
- if(box->flag & RTGUI_TEXTBOX_CARET_SHOW)
+ if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
{
- if(box->caret_timer != RT_NULL)
+ if (box->caret_timer != RT_NULL)
rtgui_timer_stop(box->caret_timer);
box->flag &= ~RTGUI_TEXTBOX_CARET_SHOW;
rtgui_textbox_draw_caret(box, posbak);
- if(box->caret_timer != RT_NULL)
+ if (box->caret_timer != RT_NULL)
rtgui_timer_start(box->caret_timer);
}
rtgui_textbox_init_caret(box, box->position);
box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
- rtgui_textbox_draw_caret(box,box->position);
+ rtgui_textbox_draw_caret(box, box->position);
}
}
-static rt_bool_t rtgui_textbox_onkey(struct rtgui_object* widget, rtgui_event_t* event)
+static rt_bool_t rtgui_textbox_onkey(struct rtgui_object *widget, rtgui_event_t *event)
{
- rtgui_textbox_t* box = RTGUI_TEXTBOX(widget);
- struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
+ rtgui_textbox_t *box = RTGUI_TEXTBOX(widget);
+ struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
rt_size_t length;
rt_uint16_t posbak = box->position;
@@ -255,76 +257,114 @@ static rt_bool_t rtgui_textbox_onkey(struct rtgui_object* widget, rtgui_event_t*
}
length = rt_strlen(box->text);
- if(ekbd->key == RTGUIK_DELETE)
- {/* delete latter character */
- if(box->position == length - 1)
+ if (ekbd->key == RTGUIK_DELETE)
+ {
+ /* delete latter character */
+ if (box->first_pos + box->position == length - 1)
{
- box->text[box->position] = '\0';
+ box->text[box->first_pos + box->position] = '\0';
}
else
{
char *c;
/* remove character */
- for(c = &box->text[box->position]; c[1] != '\0'; c++)
+ for (c = &box->text[box->first_pos + box->position]; c[1] != '\0'; c++)
*c = c[1];
*c = '\0';
}
}
- else if(ekbd->key == RTGUIK_BACKSPACE)
- {/* delete front character */
- if(box->position == 0)
- return RT_FALSE;
- else if(box->position == length)
+ else if (ekbd->key == RTGUIK_BACKSPACE)
+ {
+ /* delete front character */
+ if (box->position == 0)
+ {
+ if(box->first_pos > 0)
+ {
+ if(box->first_pos > box->dis_length)
+ {
+ box->first_pos -= box->dis_length;
+ box->position = box->dis_length;
+ }
+ else
+ {
+ box->position = box->first_pos;
+ box->first_pos = 0;
+ }
+ }
+ }
+ else if (box->position == length-box->first_pos)
{
- box->text[box->position-1] = '\0';
+ box->text[box->first_pos + box->position - 1] = '\0';
box->position --;
}
- else if(box->position != 0)
+ else if (box->position != 0)
{
/* remove current character */
- if(box->position != 0)
+ if (box->position != 0)
{
char *c;
/* remove character */
- for(c = &box->text[box->position - 1]; c[1] != '\0'; c++)
+ for (c = &box->text[box->position - 1]; c[1] != '\0'; c++)
*c = c[1];
*c = '\0';
}
box->position --;
}
}
- else if(ekbd->key == RTGUIK_LEFT)
- {/* move to prev */
- if(box->position > 0)
+ else if (ekbd->key == RTGUIK_LEFT)
+ {
+ /* move to prev */
+ if (box->position > 0)
{
box->position --;
}
+ else
+ {
+ if(box->first_pos > 0)
+ box->first_pos -= 1;//DEBUG
+ }
}
- else if(ekbd->key == RTGUIK_RIGHT)
- {/* move to next */
- if(box->position < length)
+ else if (ekbd->key == RTGUIK_RIGHT)
+ {
+ /* move to next */
+ if (box->first_pos + box->position < length)
{
- box->position ++;
+ if(box->position < box->dis_length)
+ box->position ++;
+ else
+ box->first_pos += 1;//DEBUG
}
}
- else if(ekbd->key == RTGUIK_HOME)
- {/* move cursor to start */
+ else if (ekbd->key == RTGUIK_HOME)
+ {
+ /* move cursor to start */
box->position = 0;
+ box->first_pos = 0;
}
- else if(ekbd->key == RTGUIK_END)
- {/* move cursor to end */
- box->position = length;
+ else if (ekbd->key == RTGUIK_END)
+ {
+ /* move cursor to end */
+ if(length > box->dis_length)
+ {
+ box->position = box->dis_length;
+ box->first_pos = length - box->dis_length;
+ }
+ else
+ {
+ box->position = length;
+ box->first_pos = 0;
+ }
}
- else if(ekbd->key == RTGUIK_RETURN)
+ else if (ekbd->key == RTGUIK_RETURN)
{
- if(box->on_enter != RT_NULL)
+ if (box->on_enter != RT_NULL)
{
box->on_enter(box, event);
}
}
- else if(ekbd->key == RTGUIK_NUMLOCK)
+ else if (ekbd->key == RTGUIK_NUMLOCK)
{
/* change numlock state */
/*
@@ -334,69 +374,73 @@ static rt_bool_t rtgui_textbox_onkey(struct rtgui_object* widget, rtgui_event_t*
}
else
{
- if(isprint(ekbd->key))
- {/* it's may print character */
+ if (isprint(ekbd->key))
+ {
+ /* it's may print character */
/* no buffer on this line */
- if(box->flag & RTGUI_TEXTBOX_DIGIT)
- {/* only input digit */
- if(!isdigit(ekbd->key))
- {/* exception: '.' and '-' */
- if(ekbd->key != '.' && ekbd->key !='-')return RT_FALSE;
- if(ekbd->key == '.' && strchr(box->text,'.'))return RT_FALSE;
+ if (box->flag & RTGUI_TEXTBOX_DIGIT)
+ {
+ /* only input digit */
+ if (!isdigit(ekbd->key))
+ {
+ /* exception: '.' and '-' */
+ if (ekbd->key != '.' && ekbd->key != '-')return RT_FALSE;
+ if (ekbd->key == '.' && strchr(box->text, '.'))return RT_FALSE;
- if(ekbd->key == '-')
+ if (ekbd->key == '-')
{
- if(length+1 > box->line_length) return RT_FALSE;
- if(length+1 > box->dis_length) return RT_FALSE;
+ if (length + 1 > box->line_length) return RT_FALSE;
- if(strchr(box->text,'-'))
+ if (strchr(box->text, '-'))
{
- char* c;
- for(c = &box->text[0]; c != &box->text[length]; c++)
- *c = *(c+1);
+ char *c;
+ for (c = &box->text[0]; c != &box->text[length]; c++)
+ *c = *(c + 1);
box->text[length] = '\0';
box->position --;
goto _exit;
}
else
{
- char* c;
- for(c = &box->text[length]; c != &box->text[0]; c--)
- *c = *(c-1);
+ char *c;
+ for (c = &box->text[length]; c != &box->text[0]; c--)
+ *c = *(c - 1);
box->text[0] = '-';
- box->text[length+1] = '\0';
+ box->text[length + 1] = '\0';
box->position ++;
goto _exit;
}
}
}
}
- if(length+1 > box->line_length) return RT_FALSE;
- if(length+1 > box->dis_length) return RT_FALSE;
+ if (length + 1 > box->line_length) return RT_FALSE;
- if(box->position <= length-1)
+ if (box->first_pos + box->position <= length - 1)
{
- char* c;
+ char *c;
- for(c = &box->text[length]; c != &box->text[box->position]; c--)
- *c = *(c-1);
- box->text[length+1] = '\0';
+ for (c = &box->text[length]; c != &box->text[box->first_pos + box->position]; c--)
+ *c = *(c - 1);
+ box->text[length + 1] = '\0';
}
- box->text[box->position] = ekbd->key;
- box->position ++;
+ box->text[box->first_pos + box->position] = ekbd->key;
+ if(box->position < box->dis_length)
+ box->position ++;
+ else
+ box->first_pos ++;
}
}
_exit:
- if(box->flag & RTGUI_TEXTBOX_CARET_SHOW)
+ if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
{
- if(box->caret_timer != RT_NULL)
+ if (box->caret_timer != RT_NULL)
rtgui_timer_stop(box->caret_timer);
box->flag &= ~RTGUI_TEXTBOX_CARET_SHOW;
rtgui_textbox_draw_caret(box, posbak);/* refresh it */
- if(box->caret_timer != RT_NULL)
+ if (box->caret_timer != RT_NULL)
rtgui_timer_start(box->caret_timer);
}
@@ -405,35 +449,35 @@ _exit:
rtgui_textbox_init_caret(box, box->position);
box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
- rtgui_textbox_draw_caret(box,box->position);
+ rtgui_textbox_draw_caret(box, box->position);
return RT_TRUE;
}
-static rt_bool_t rtgui_textbox_onfocus(struct rtgui_object* widget, rtgui_event_t* event)
+static rt_bool_t rtgui_textbox_onfocus(struct rtgui_object *widget, rtgui_event_t *event)
{
- rtgui_textbox_t* box = RTGUI_TEXTBOX(widget);
+ rtgui_textbox_t *box = RTGUI_TEXTBOX(widget);
/* if there is already a timer, don't create another one. */
if (box->caret_timer == RT_NULL)
{
- box->caret_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC,rtgui_textbox_timeout, box);
+ box->caret_timer = rtgui_timer_create(50, RT_TIMER_FLAG_PERIODIC, rtgui_textbox_timeout, box);
/* set caret to show */
box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
/* start caret timer */
- if(box->caret_timer != RT_NULL)
+ if (box->caret_timer != RT_NULL)
rtgui_timer_start(box->caret_timer);
}
return RT_TRUE;
}
-static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_object* widget, rtgui_event_t* event)
+static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_object *widget, rtgui_event_t *event)
{
- rtgui_textbox_t* box = RTGUI_TEXTBOX(widget);
+ rtgui_textbox_t *box = RTGUI_TEXTBOX(widget);
/* stop caret timer */
- if(box->caret_timer != RT_NULL)
+ if (box->caret_timer != RT_NULL)
{
rtgui_timer_stop(box->caret_timer);
rtgui_timer_destory(box->caret_timer);
@@ -441,21 +485,21 @@ static rt_bool_t rtgui_textbox_onunfocus(struct rtgui_object* widget, rtgui_even
}
/* set caret to hide */
box->flag &= ~RTGUI_TEXTBOX_CARET_SHOW;
- rtgui_textbox_draw_caret(box,box->position);
+ rtgui_textbox_draw_caret(box, box->position);
- if(box->on_enter != RT_NULL)
- box->on_enter(box,event);
+ if (box->on_enter != RT_NULL)
+ box->on_enter(box, event);
return RT_TRUE;
}
-rtgui_textbox_t* rtgui_textbox_create(const char* text, rt_uint32_t flag)
+rtgui_textbox_t *rtgui_textbox_create(const char *text, rt_uint32_t flag)
{
- rtgui_textbox_t* box;
+ rtgui_textbox_t *box;
- box = (struct rtgui_textbox*)rtgui_widget_create(RTGUI_TEXTBOX_TYPE);
- if(box != RT_NULL)
- {
+ box = (struct rtgui_textbox *)rtgui_widget_create(RTGUI_TEXTBOX_TYPE);
+ if (box != RT_NULL)
+ {
/* allocate default line buffer */
rtgui_textbox_set_value(box, text);
box->flag = flag;
@@ -464,16 +508,16 @@ rtgui_textbox_t* rtgui_textbox_create(const char* text, rt_uint32_t flag)
return box;
}
-void rtgui_textbox_destroy(rtgui_textbox_t* box)
+void rtgui_textbox_destroy(rtgui_textbox_t *box)
{
rtgui_widget_destroy(RTGUI_WIDGET(box));
}
-void rtgui_textbox_ondraw(rtgui_textbox_t* box)
+void rtgui_textbox_ondraw(rtgui_textbox_t *box)
{
/* draw button */
rtgui_rect_t rect;
- struct rtgui_dc* dc;
+ struct rtgui_dc *dc;
rtgui_color_t fc;
RT_ASSERT(box != RT_NULL);
@@ -491,7 +535,7 @@ void rtgui_textbox_ondraw(rtgui_textbox_t* box)
/* fill widget rect with white color */
RTGUI_WIDGET_BACKGROUND(box) = white;
- rtgui_dc_fill_rect(dc,&rect);
+ rtgui_dc_fill_rect(dc, &rect);
rtgui_rect_inflate(&rect, 1);
/* draw border */
@@ -500,26 +544,26 @@ void rtgui_textbox_ondraw(rtgui_textbox_t* box)
/* draw text */
RTGUI_WIDGET_FOREGROUND(box) = fc;
- if(box->text != RT_NULL)
+ if (box->text != RT_NULL)
{
rect.x1 += RTGUI_WIDGET_DEFAULT_MARGIN;
/* draw single text */
- if(box->flag & RTGUI_TEXTBOX_MASK)
+ if (box->flag & RTGUI_TEXTBOX_MASK)
{
- /* draw '*' */
+ /* draw mask char */
rt_size_t len = rt_strlen(box->text);
- if(len > 0)
+ if (len > 0)
{
char *text_mask = rtgui_malloc(len + 1);
- rt_memset(text_mask, '*', len + 1);
+ rt_memset(text_mask, box->mask_char, len + 1);
text_mask[len] = 0;
- rtgui_dc_draw_text(dc, text_mask, &rect);
+ rtgui_dc_draw_text(dc, text_mask+box->first_pos, &rect);
rtgui_free(text_mask);
}
}
else
{
- rtgui_dc_draw_text(dc, box->text, &rect);
+ rtgui_dc_draw_text(dc, box->text+box->first_pos, &rect);
}
}
@@ -527,21 +571,22 @@ void rtgui_textbox_ondraw(rtgui_textbox_t* box)
}
/* set textbox text */
-void rtgui_textbox_set_value(rtgui_textbox_t* box, const char* text)
+void rtgui_textbox_set_value(rtgui_textbox_t *box, const char *text)
{
- if(box->text != RT_NULL)
- {/* yet exist something */
+ if (box->text != RT_NULL)
+ {
+ /* yet exist something */
/* free the old text */
rtgui_free(box->text);
box->text = RT_NULL;
}
/* no something */
- box->line_length = ((rt_strlen(text)+1)/RTGUI_TEXTBOX_LINE_MAX+1)*RTGUI_TEXTBOX_LINE_MAX;
+ box->line_length = ((rt_strlen(text) + 1) / RTGUI_TEXTBOX_LINE_MAX + 1) * RTGUI_TEXTBOX_LINE_MAX;
/* allocate line buffer */
- box->text = rtgui_malloc(box->line_length);
- rt_memset(box->text, 0, box->line_length);
+ box->text = rtgui_malloc(box->line_length+1);
+ rt_memset(box->text, 0, box->line_length+1);
/* copy text */
rt_memcpy(box->text, text, rt_strlen(text) + 1);
@@ -550,30 +595,40 @@ void rtgui_textbox_set_value(rtgui_textbox_t* box, const char* text)
box->position = rt_strlen(text);
}
-const char* rtgui_textbox_get_value(rtgui_textbox_t* box)
+const char *rtgui_textbox_get_value(rtgui_textbox_t *box)
{
- return (const char*)box->text;
+ return (const char *)box->text;
}
-void rtgui_textbox_set_line_length(rtgui_textbox_t* box, rt_size_t length)
+void rtgui_textbox_set_mask_char(rtgui_textbox_t *box, const char ch)
{
- rt_uint8_t* new_line;
+ box->mask_char = ch;
+}
+
+const char rtgui_textbox_get_mask_char(rtgui_textbox_t *box)
+{
+ return box->mask_char;
+}
+
+void rtgui_textbox_set_line_length(rtgui_textbox_t *box, rt_size_t length)
+{
+ rt_uint8_t *new_line;
RT_ASSERT(box != RT_NULL);
/* invalid length */
- if(length <= 0)
+ if (length <= 0)
return;
new_line = rtgui_malloc(length);
- if(length < box->line_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));
+ rt_memcpy(new_line, (const char *)box->text, rt_strlen((const char *)box->text));
}
/* set line length */
@@ -581,48 +636,48 @@ void rtgui_textbox_set_line_length(rtgui_textbox_t* box, rt_size_t length)
}
/* get textbox text area */
-void rtgui_textbox_get_edit_rect(rtgui_textbox_t *box,rtgui_rect_t *rect)
+void rtgui_textbox_get_edit_rect(rtgui_textbox_t *box, rtgui_rect_t *rect)
{
rtgui_widget_get_rect(RTGUI_WIDGET(box), rect);
- rtgui_rect_inflate(rect,-1);
+ rtgui_rect_inflate(rect, -1);
}
-rt_bool_t rtgui_textbox_event_handler(struct rtgui_object *object, rtgui_event_t* event)
+rt_bool_t rtgui_textbox_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
rtgui_widget_t *widget = RTGUI_WIDGET(object);
- rtgui_textbox_t* box = RTGUI_TEXTBOX(object);
+ rtgui_textbox_t *box = RTGUI_TEXTBOX(object);
switch (event->type)
{
- case RTGUI_EVENT_PAINT:
+ case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
- if(widget->on_draw != RT_NULL)
- widget->on_draw(RTGUI_OBJECT(widget), event);
- else
+ if (widget->on_draw != RT_NULL)
+ widget->on_draw(RTGUI_OBJECT(widget), event);
+ else
#endif
- rtgui_textbox_ondraw(box);
- break;
+ rtgui_textbox_ondraw(box);
+ break;
- case RTGUI_EVENT_MOUSE_BUTTON:
+ case RTGUI_EVENT_MOUSE_BUTTON:
#ifndef RTGUI_USING_SMALL_SIZE
- if(widget->on_mouseclick != RT_NULL)
- widget->on_mouseclick(RTGUI_OBJECT(widget), event);
- else
+ if (widget->on_mouseclick != RT_NULL)
+ widget->on_mouseclick(RTGUI_OBJECT(widget), event);
+ else
#endif
- rtgui_textbox_onmouse(box, (struct rtgui_event_mouse*)event);
- return RT_TRUE;
+ rtgui_textbox_onmouse(box, (struct rtgui_event_mouse *)event);
+ return RT_TRUE;
- case RTGUI_EVENT_KBD:
+ case RTGUI_EVENT_KBD:
#ifndef RTGUI_USING_SMALL_SIZE
- if(widget->on_key != RT_NULL)
- widget->on_key(RTGUI_OBJECT(widget), event);
- else
+ if (widget->on_key != RT_NULL)
+ widget->on_key(RTGUI_OBJECT(widget), event);
+ else
#endif
- rtgui_textbox_onkey(RTGUI_OBJECT(box), (struct rtgui_event*)event);
- return RT_TRUE;
+ rtgui_textbox_onkey(RTGUI_OBJECT(box), (struct rtgui_event *)event);
+ return RT_TRUE;
- default:
- return rtgui_widget_event_handler(RTGUI_OBJECT(widget),event);
+ default:
+ return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
}
return RT_FALSE;
diff --git a/components/rtgui/widgets/textview.c b/components/rtgui/widgets/textview.c
index 4ae1253c14..84465391cc 100644
--- a/components/rtgui/widgets/textview.c
+++ b/components/rtgui/widgets/textview.c
@@ -15,339 +15,341 @@
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/textview.h>
-rt_inline char* _get_line_text(rtgui_textview_t *textview, rt_uint16_t index)
+rt_inline char *_get_line_text(rtgui_textview_t *textview, rt_uint16_t index)
{
- char* line;
- if (index < textview->line_count)
- {
- line = textview->lines + (index * textview->line_width);
- return line;
- }
+ char *line;
+ if (index < textview->line_count)
+ {
+ line = textview->lines + (index * textview->line_width);
+ return line;
+ }
- return RT_NULL;
+ return RT_NULL;
}
-static void _calc_line(rtgui_textview_t *textview, const char* text)
+static void _calc_line(rtgui_textview_t *textview, const char *text)
{
- char* line;
- const unsigned char* ptr;
- rt_ubase_t line_index, line_position;
+ char *line;
+ const unsigned char *ptr;
+ rt_ubase_t line_index, line_position;
- if (textview->lines != RT_NULL)
- {
- rtgui_free(textview->lines);
- textview->lines = RT_NULL;
- textview->line_count = 0;
- }
+ if (textview->lines != RT_NULL)
+ {
+ rtgui_free(textview->lines);
+ textview->lines = RT_NULL;
+ textview->line_count = 0;
+ }
- /* get line count */
- line_index = 0; line_position = 0;
- ptr = (const unsigned char*)text;
- if (*ptr == 0) return;
+ /* get line count */
+ line_index = 0;
+ line_position = 0;
+ ptr = (const unsigned char *)text;
+ if (*ptr == 0) return;
- while (*ptr != '\0')
- {
- if (*ptr == '\n')
- {
- line_index ++;
- line_position = 0;
- }
- else if (*ptr == '\r')
- {
- ptr ++;
- continue;
- }
- else if (*ptr == '\t')
- {
- line_position += 4;
- if (line_position >= textview->line_width - 1)
- {
- line_index ++;
- line_position = 0;
- }
- }
- else
- {
- if ((*ptr) >= 0x80)
- {
- /* fill cjk character */
- if (line_position + 1 >= (textview->line_width - 1))
- {
- /* split to next line */
- line_index ++;
- line_position = 0;
- }
+ while (*ptr != '\0')
+ {
+ if (*ptr == '\n')
+ {
+ line_index ++;
+ line_position = 0;
+ }
+ else if (*ptr == '\r')
+ {
+ ptr ++;
+ continue;
+ }
+ else if (*ptr == '\t')
+ {
+ line_position += 4;
+ if (line_position >= textview->line_width - 1)
+ {
+ line_index ++;
+ line_position = 0;
+ }
+ }
+ else
+ {
+ if ((*ptr) >= 0x80)
+ {
+ /* fill cjk character */
+ if (line_position + 1 >= (textview->line_width - 1))
+ {
+ /* split to next line */
+ line_index ++;
+ line_position = 0;
+ }
- line_position ++;
- line_position ++;
- }
- else
- {
- line_position ++;
- }
+ line_position ++;
+ line_position ++;
+ }
+ else
+ {
+ line_position ++;
+ }
- if (line_position >= textview->line_width - 1)
- {
- line_index ++;
- line_position = 0;
- }
- }
+ if (line_position >= textview->line_width - 1)
+ {
+ line_index ++;
+ line_position = 0;
+ }
+ }
- ptr ++;
- }
+ ptr ++;
+ }
- /* set line count */
- textview->line_count = line_index + 1;
+ /* set line count */
+ textview->line_count = line_index + 1;
- /* allocate lines */
- textview->lines = rtgui_malloc(textview->line_count * textview->line_width);
- rt_memset(textview->lines, 0, (textview->line_count * textview->line_width));
+ /* allocate lines */
+ textview->lines = rtgui_malloc(textview->line_count * textview->line_width);
+ rt_memset(textview->lines, 0, (textview->line_count * textview->line_width));
- /* fill lines */
- line_index = 0; line_position = 0;
- ptr = (const unsigned char*)text;
- line = _get_line_text(textview, line_index);
- while (*ptr)
- {
- if (*ptr == '\n')
- {
- line_index ++;
- line_position = 0;
- line = _get_line_text(textview, line_index);
- }
- else if (*ptr == '\r')
- {
- /* ignore '\r' */
- ptr ++;
- continue;
- }
- else if (*ptr == '\t')
- {
- line[line_position++] = ' ';
- line[line_position++] = ' ';
- line[line_position++] = ' ';
- line[line_position++] = ' ';
- if (line_position >= textview->line_width - 1)
- {
- line_index ++;
- line_position = 0;
- line = _get_line_text(textview, line_index);
- }
- }
- else
- {
- if ((*ptr) >= 0x80)
- {
- /* fill cjk character */
- if (line_position + 1 >= (textview->line_width - 1))
- {
- /* split to next line */
- line_index ++;
- line_position = 0;
- line = _get_line_text(textview, line_index);
- }
+ /* fill lines */
+ line_index = 0;
+ line_position = 0;
+ ptr = (const unsigned char *)text;
+ line = _get_line_text(textview, line_index);
+ while (*ptr)
+ {
+ if (*ptr == '\n')
+ {
+ line_index ++;
+ line_position = 0;
+ line = _get_line_text(textview, line_index);
+ }
+ else if (*ptr == '\r')
+ {
+ /* ignore '\r' */
+ ptr ++;
+ continue;
+ }
+ else if (*ptr == '\t')
+ {
+ line[line_position++] = ' ';
+ line[line_position++] = ' ';
+ line[line_position++] = ' ';
+ line[line_position++] = ' ';
+ if (line_position >= textview->line_width - 1)
+ {
+ line_index ++;
+ line_position = 0;
+ line = _get_line_text(textview, line_index);
+ }
+ }
+ else
+ {
+ if ((*ptr) >= 0x80)
+ {
+ /* fill cjk character */
+ if (line_position + 1 >= (textview->line_width - 1))
+ {
+ /* split to next line */
+ line_index ++;
+ line_position = 0;
+ line = _get_line_text(textview, line_index);
+ }
- line[line_position ++] = *ptr ++;
- line[line_position ++] = *ptr;
- }
- else
- {
- line[line_position ++] = *ptr;
- }
+ line[line_position ++] = *ptr ++;
+ line[line_position ++] = *ptr;
+ }
+ else
+ {
+ line[line_position ++] = *ptr;
+ }
- if (line_position >= textview->line_width - 1)
- {
- line_index ++;
- line_position = 0;
- line = _get_line_text(textview, line_index);
- }
- }
+ if (line_position >= textview->line_width - 1)
+ {
+ line_index ++;
+ line_position = 0;
+ line = _get_line_text(textview, line_index);
+ }
+ }
- ptr ++;
- }
+ ptr ++;
+ }
- textview->line_current = 0;
+ textview->line_current = 0;
}
static void _calc_width(rtgui_textview_t *textview)
{
- rtgui_rect_t rect;
- rt_uint16_t width, height;
+ rtgui_rect_t rect;
+ rt_uint16_t width, height;
- width = rtgui_rect_width(RTGUI_WIDGET(textview)->extent) - 6;
- height = rtgui_rect_height(RTGUI_WIDGET(textview)->extent);
+ width = rtgui_rect_width(RTGUI_WIDGET(textview)->extent) - 6;
+ height = rtgui_rect_height(RTGUI_WIDGET(textview)->extent);
- rtgui_font_get_metrics(RTGUI_WIDGET_FONT(textview), "W", &rect);
- textview->line_width = width / rtgui_rect_width(rect) + 1;
- textview->line_page_count = height / (rtgui_rect_height(rect) + 3);
+ rtgui_font_get_metrics(RTGUI_WIDGET_FONT(textview), "W", &rect);
+ textview->line_width = width / rtgui_rect_width(rect) + 1;
+ textview->line_page_count = height / (rtgui_rect_height(rect) + 3);
- /* set minimal value */
- if (textview->line_page_count == 0) textview->line_page_count = 1;
+ /* set minimal value */
+ if (textview->line_page_count == 0) textview->line_page_count = 1;
}
static void _draw_textview(rtgui_textview_t *textview)
{
- struct rtgui_dc* dc;
- struct rtgui_rect rect, font_rect;
- char* line;
- rt_ubase_t line_index, item_height;
+ struct rtgui_dc *dc;
+ struct rtgui_rect rect, font_rect;
+ char *line;
+ rt_ubase_t line_index, item_height;
- rtgui_font_get_metrics(RTGUI_WIDGET_FONT(textview), "W", &font_rect);
- item_height = rtgui_rect_height(font_rect) + 3;
+ rtgui_font_get_metrics(RTGUI_WIDGET_FONT(textview), "W", &font_rect);
+ item_height = rtgui_rect_height(font_rect) + 3;
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(textview));
- if (dc == RT_NULL) return ;
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(textview));
+ if (dc == RT_NULL) return ;
- /* fill rect */
- rtgui_widget_get_rect(RTGUI_WIDGET(textview), &rect);
- rtgui_dc_fill_rect(dc, &rect);
+ /* fill rect */
+ rtgui_widget_get_rect(RTGUI_WIDGET(textview), &rect);
+ rtgui_dc_fill_rect(dc, &rect);
- rect.x1 += 3;
- rect.x2 -= 3;
+ rect.x1 += 3;
+ rect.x2 -= 3;
- for (line_index = textview->line_current;
- (line_index < textview->line_current + textview->line_page_count) &&
- (line_index < textview->line_count);
- line_index ++)
- {
- line = (char* )_get_line_text(textview, line_index);
- rtgui_dc_draw_text(dc, line, &rect);
+ for (line_index = textview->line_current;
+ (line_index < textview->line_current + textview->line_page_count) &&
+ (line_index < textview->line_count);
+ line_index ++)
+ {
+ line = (char *)_get_line_text(textview, line_index);
+ rtgui_dc_draw_text(dc, line, &rect);
- rect.y1 += item_height;
- }
+ rect.y1 += item_height;
+ }
- rtgui_dc_end_drawing(dc);
+ rtgui_dc_end_drawing(dc);
}
static void _rtgui_textview_constructor(rtgui_textview_t *textview)
{
- /* init widget and set event handler */
- rtgui_object_set_event_handler(RTGUI_OBJECT(textview), rtgui_textview_event_handler);
- RTGUI_WIDGET(textview)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+ /* init widget and set event handler */
+ rtgui_object_set_event_handler(RTGUI_OBJECT(textview), rtgui_textview_event_handler);
+ RTGUI_WIDGET(textview)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- /* set field */
- textview->line_count = 0;
- textview->lines = RT_NULL;
+ /* set field */
+ textview->line_count = 0;
+ textview->lines = RT_NULL;
- textview->line_current = -1;
- textview->line_page_count = 1;
+ textview->line_current = -1;
+ textview->line_page_count = 1;
}
static void _rtgui_textview_destructor(rtgui_textview_t *textview)
{
- /* release line memory */
- rtgui_free(textview->lines);
- textview->lines = RT_NULL;
+ /* release line memory */
+ rtgui_free(textview->lines);
+ textview->lines = RT_NULL;
}
DEFINE_CLASS_TYPE(textview, "textview",
- RTGUI_WIDGET_TYPE,
- _rtgui_textview_constructor,
- _rtgui_textview_destructor,
- sizeof(struct rtgui_textview));
+ RTGUI_WIDGET_TYPE,
+ _rtgui_textview_constructor,
+ _rtgui_textview_destructor,
+ sizeof(struct rtgui_textview));
-rt_bool_t rtgui_textview_event_handler(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_textview_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_textview* textview;
- RTGUI_WIDGET_EVENT_HANDLER_PREPARE
+ struct rtgui_textview *textview;
+ RTGUI_WIDGET_EVENT_HANDLER_PREPARE
- textview = RTGUI_TEXTVIEW(object);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- _draw_textview(textview);
- break;
+ textview = RTGUI_TEXTVIEW(object);
+ switch (event->type)
+ {
+ case RTGUI_EVENT_PAINT:
+ _draw_textview(textview);
+ break;
- case RTGUI_EVENT_KBD:
- {
- struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
- if (ekbd->type == RTGUI_KEYDOWN)
- {
- rt_int16_t line_current_update;
- line_current_update = textview->line_current;
- if (ekbd->key == RTGUIK_LEFT)
- {
- if (textview->line_current > textview->line_page_count)
- {
- line_current_update -= textview->line_page_count;
- }
- else if (textview->line_current > 0)
- {
- line_current_update = 0;
- }
- }
- else if (ekbd->key == RTGUIK_RIGHT)
- {
- if (textview->line_current + textview->line_page_count < textview->line_count - 1)
- {
- line_current_update += textview->line_page_count;
- }
- }
- else if (ekbd->key == RTGUIK_UP)
- {
- if (textview->line_current > 0)
- {
- line_current_update --;
- }
- }
- else if (ekbd->key == RTGUIK_DOWN)
- {
- if (textview->line_current + textview->line_page_count < textview->line_count - 1)
- {
- line_current_update ++;
- }
- }
+ case RTGUI_EVENT_KBD:
+ {
+ struct rtgui_event_kbd *ekbd = (struct rtgui_event_kbd *)event;
+ if (ekbd->type == RTGUI_KEYDOWN)
+ {
+ rt_int16_t line_current_update;
+ line_current_update = textview->line_current;
+ if (ekbd->key == RTGUIK_LEFT)
+ {
+ if (textview->line_current > textview->line_page_count)
+ {
+ line_current_update -= textview->line_page_count;
+ }
+ else if (textview->line_current > 0)
+ {
+ line_current_update = 0;
+ }
+ }
+ else if (ekbd->key == RTGUIK_RIGHT)
+ {
+ if (textview->line_current + textview->line_page_count < textview->line_count - 1)
+ {
+ line_current_update += textview->line_page_count;
+ }
+ }
+ else if (ekbd->key == RTGUIK_UP)
+ {
+ if (textview->line_current > 0)
+ {
+ line_current_update --;
+ }
+ }
+ else if (ekbd->key == RTGUIK_DOWN)
+ {
+ if (textview->line_current + textview->line_page_count < textview->line_count - 1)
+ {
+ line_current_update ++;
+ }
+ }
- if (textview->line_current != line_current_update)
- {
- textview->line_current = line_current_update;
- rtgui_widget_update(widget);
- return RT_TRUE;
- }
- }
- break;
- }
- default:
- return rtgui_widget_event_handler(RTGUI_OBJECT(widget),event);
- }
+ if (textview->line_current != line_current_update)
+ {
+ textview->line_current = line_current_update;
+ rtgui_widget_update(widget);
+ return RT_TRUE;
+ }
+ }
+ break;
+ }
+ default:
+ return rtgui_widget_event_handler(RTGUI_OBJECT(widget), event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
-rtgui_textview_t* rtgui_textview_create(const char* text, const rtgui_rect_t *rect)
+rtgui_textview_t *rtgui_textview_create(const char *text, const rtgui_rect_t *rect)
{
- struct rtgui_textview* textview;
+ struct rtgui_textview *textview;
- textview = (struct rtgui_textview*) rtgui_widget_create(RTGUI_TEXTVIEW_TYPE);
+ textview = (struct rtgui_textview *) rtgui_widget_create(RTGUI_TEXTVIEW_TYPE);
if (textview != RT_NULL)
{
- rtgui_widget_set_rect(RTGUI_WIDGET(textview), rect);
+ rtgui_widget_set_rect(RTGUI_WIDGET(textview), rect);
- /* calculate line width and line page count */
- _calc_width(textview);
+ /* calculate line width and line page count */
+ _calc_width(textview);
- /* set text */
- _calc_line(textview, text);
+ /* set text */
+ _calc_line(textview, text);
}
return textview;
}
-void rtgui_textview_destroy(rtgui_textview_t* textview)
+void rtgui_textview_destroy(rtgui_textview_t *textview)
{
- rtgui_widget_destroy(RTGUI_WIDGET(textview));
+ rtgui_widget_destroy(RTGUI_WIDGET(textview));
}
-void rtgui_textview_set_text(rtgui_textview_t* textview, const char* text)
+void rtgui_textview_set_text(rtgui_textview_t *textview, const char *text)
{
- RT_ASSERT(textview != RT_NULL);
+ RT_ASSERT(textview != RT_NULL);
- /* calculate line width and line page count */
- _calc_width(textview);
+ /* calculate line width and line page count */
+ _calc_width(textview);
- /* set text */
- _calc_line(textview, text);
+ /* set text */
+ _calc_line(textview, text);
- /* update widget */
- rtgui_widget_update(RTGUI_WIDGET(textview));
+ /* update widget */
+ rtgui_widget_update(RTGUI_WIDGET(textview));
}
diff --git a/components/rtgui/widgets/title.c b/components/rtgui/widgets/title.c
index b9e690cb81..840669e7f6 100644
--- a/components/rtgui/widgets/title.c
+++ b/components/rtgui/widgets/title.c
@@ -15,61 +15,61 @@
#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)
+static void _rtgui_wintitle_constructor(rtgui_wintitle_t *wintitle)
{
- wintitle->title = RT_NULL;
- RTGUI_WIDGET(wintitle)->flag = RTGUI_WIDGET_FLAG_DEFAULT;
- RTGUI_WIDGET_TEXTALIGN(wintitle) = RTGUI_ALIGN_CENTER_VERTICAL;
+ wintitle->title = RT_NULL;
+ RTGUI_WIDGET(wintitle)->flag = RTGUI_WIDGET_FLAG_DEFAULT;
+ RTGUI_WIDGET_TEXTALIGN(wintitle) = RTGUI_ALIGN_CENTER_VERTICAL;
}
-static void _rtgui_wintitle_deconstructor(rtgui_wintitle_t* wintitle)
+static void _rtgui_wintitle_deconstructor(rtgui_wintitle_t *wintitle)
{
- if (wintitle->title != RT_NULL)
- rt_free(wintitle->title);
- wintitle->title = RT_NULL;
+ if (wintitle->title != RT_NULL)
+ rt_free(wintitle->title);
+ wintitle->title = RT_NULL;
}
DEFINE_CLASS_TYPE(wintitle, "wintitle",
- RTGUI_WIDGET_TYPE,
- _rtgui_wintitle_constructor,
- _rtgui_wintitle_deconstructor,
- sizeof(struct rtgui_wintitle));
+ RTGUI_WIDGET_TYPE,
+ _rtgui_wintitle_constructor,
+ _rtgui_wintitle_deconstructor,
+ sizeof(struct rtgui_wintitle));
-rtgui_wintitle_t* rtgui_wintitle_create(struct rtgui_win *window, const char* title)
+rtgui_wintitle_t *rtgui_wintitle_create(struct rtgui_win *window, const char *title)
{
- rtgui_wintitle_t* wintitle;
+ rtgui_wintitle_t *wintitle;
- wintitle = (rtgui_wintitle_t*)rtgui_widget_create(RTGUI_WINTITLE_TYPE);
- if (wintitle != RT_NULL)
- {
- rtgui_wintitle_set_title(wintitle, title);
+ wintitle = (rtgui_wintitle_t *)rtgui_widget_create(RTGUI_WINTITLE_TYPE);
+ if (wintitle != RT_NULL)
+ {
+ rtgui_wintitle_set_title(wintitle, title);
RTGUI_WIDGET(wintitle)->toplevel = window;
- }
+ }
- return wintitle;
+ return wintitle;
}
-void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle)
+void rtgui_wintitle_destroy(rtgui_wintitle_t *wintitle)
{
- rtgui_widget_destroy(RTGUI_WIDGET(wintitle));
+ rtgui_widget_destroy(RTGUI_WIDGET(wintitle));
}
-void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const char* title)
+void rtgui_wintitle_set_title(rtgui_wintitle_t *wintitle, const char *title)
{
- RT_ASSERT(wintitle != RT_NULL);
+ RT_ASSERT(wintitle != RT_NULL);
- if (wintitle->title != RT_NULL)
- {
- rt_free(wintitle->title);
- }
+ if (wintitle->title != RT_NULL)
+ {
+ rt_free(wintitle->title);
+ }
- if (title != RT_NULL) wintitle->title = (char*)rt_strdup((const char*)title);
- else wintitle->title = RT_NULL;
+ 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)
+char *rtgui_wintitle_get_title(rtgui_wintitle_t *wintitle)
{
- RT_ASSERT(wintitle != RT_NULL);
+ RT_ASSERT(wintitle != RT_NULL);
- return wintitle->title;
+ return wintitle->title;
}
diff --git a/components/rtgui/widgets/widget.c b/components/rtgui/widgets/widget.c
index 637e071d52..83c87ba1b9 100644
--- a/components/rtgui/widgets/widget.c
+++ b/components/rtgui/widgets/widget.c
@@ -22,301 +22,308 @@
static void _rtgui_widget_constructor(rtgui_widget_t *widget)
{
- if (!widget) return;
+ if (!widget) return;
- /* set default flag */
- widget->flag = RTGUI_WIDGET_FLAG_DEFAULT;
+ /* set default flag */
+ widget->flag = RTGUI_WIDGET_FLAG_DEFAULT;
- /* init list */
- rtgui_list_init(&(widget->sibling));
+ /* 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.textstyle = RTGUI_TEXTSTYLE_NORMAL;
- widget->gc.textalign = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
- widget->align = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
+ /* init gc */
+ widget->gc.foreground = default_foreground;
+ widget->gc.background = default_background;
+ widget->gc.font = rtgui_font_default();
+ widget->gc.textstyle = RTGUI_TEXTSTYLE_NORMAL;
+ widget->gc.textalign = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
+ widget->align = RTGUI_ALIGN_LEFT | RTGUI_ALIGN_TOP;
/* clear the garbage value of extent and clip */
widget->extent.x1 = widget->extent.y1 = 0;
widget->extent.x2 = widget->extent.y2 = 0;
rtgui_region_init_with_extents(&widget->clip, &widget->extent);
- /* set parent and toplevel root */
- widget->parent = RT_NULL;
- widget->toplevel = RT_NULL;
+ /* 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;
+ /* 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;
+ 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 */
- rtgui_object_set_event_handler(RTGUI_OBJECT(widget), rtgui_widget_event_handler);
+ /* set default event handler */
+ rtgui_object_set_event_handler(RTGUI_OBJECT(widget), rtgui_widget_event_handler);
- /* init user data private to 0 */
- widget->user_data = 0;
+ /* init user data private to 0 */
+ widget->user_data = 0;
- /* init clip information */
- rtgui_region_init(&(widget->clip));
+ /* init clip information */
+ rtgui_region_init(&(widget->clip));
- /* init hardware dc */
- rtgui_dc_client_init(widget);
+ /* init hardware dc */
+ rtgui_dc_client_init(widget);
}
/* Destroys the widget */
static void _rtgui_widget_destructor(rtgui_widget_t *widget)
{
- if (widget == RT_NULL) return;
+ if (widget == RT_NULL) return;
- if (widget->parent != RT_NULL && RTGUI_IS_CONTAINER(widget->parent))
- {
- /* remove widget from parent's children list */
- rtgui_list_remove(&(RTGUI_CONTAINER(widget->parent)->children), &(widget->sibling));
+ if (widget->parent != RT_NULL && RTGUI_IS_CONTAINER(widget->parent))
+ {
+ /* remove widget from parent's children list */
+ rtgui_list_remove(&(RTGUI_CONTAINER(widget->parent)->children), &(widget->sibling));
- widget->parent = RT_NULL;
- }
+ widget->parent = RT_NULL;
+ }
- /* fini clip region */
- rtgui_region_fini(&(widget->clip));
+ /* fini clip region */
+ rtgui_region_fini(&(widget->clip));
}
DEFINE_CLASS_TYPE(widget, "widget",
- RTGUI_OBJECT_TYPE,
- _rtgui_widget_constructor,
- _rtgui_widget_destructor,
- sizeof(struct rtgui_widget));
+ RTGUI_OBJECT_TYPE,
+ _rtgui_widget_constructor,
+ _rtgui_widget_destructor,
+ sizeof(struct rtgui_widget));
RTM_EXPORT(_rtgui_widget);
rtgui_widget_t *rtgui_widget_create(rtgui_type_t *widget_type)
{
- struct rtgui_widget* widget;
+ struct rtgui_widget *widget;
- widget = RTGUI_WIDGET(rtgui_object_create(widget_type));
+ widget = RTGUI_WIDGET(rtgui_object_create(widget_type));
- return widget;
+ return widget;
}
RTM_EXPORT(rtgui_widget_create);
-void rtgui_widget_destroy(rtgui_widget_t* widget)
+void rtgui_widget_destroy(rtgui_widget_t *widget)
{
- rtgui_object_destroy(RTGUI_OBJECT(widget));
+ rtgui_object_destroy(RTGUI_OBJECT(widget));
}
RTM_EXPORT(rtgui_widget_destroy);
-void rtgui_widget_set_rect(rtgui_widget_t* widget, const rtgui_rect_t* rect)
+void rtgui_widget_set_rect(rtgui_widget_t *widget, const rtgui_rect_t *rect)
{
- int delta_x, delta_y;
+ int delta_x, delta_y;
- if (widget == RT_NULL || rect == RT_NULL) return;
+ if (widget == RT_NULL || rect == RT_NULL) return;
- /* move to a logic position if it's a container widget */
- if (RTGUI_IS_CONTAINER(widget))
- {
- delta_x = rect->x1 - widget->extent.x1;
- delta_y = rect->y1 - widget->extent.y1;
+ /* move to a logic position if it's a container widget */
+ if (RTGUI_IS_CONTAINER(widget))
+ {
+ delta_x = rect->x1 - widget->extent.x1;
+ delta_y = rect->y1 - widget->extent.y1;
- rtgui_widget_move_to_logic(widget, delta_x, delta_y);
- }
+ rtgui_widget_move_to_logic(widget, delta_x, delta_y);
+ }
- /* update extent rectangle */
- widget->extent = *rect;
+ /* update extent rectangle */
+ widget->extent = *rect;
+ if (RTGUI_IS_CONTAINER(widget))
+ {
+ /* re-do layout */
+ rtgui_container_layout(RTGUI_CONTAINER(widget));
+ }
- /* reset mini width and height */
- widget->mini_width = rtgui_rect_width(widget->extent);
- widget->mini_height = rtgui_rect_height(widget->extent);
+ /* reset mini width and height */
+ widget->mini_width = rtgui_rect_width(widget->extent);
+ widget->mini_height = rtgui_rect_height(widget->extent);
- /* it's not empty, fini it */
- if (rtgui_region_not_empty(&(widget->clip)))
- {
- rtgui_region_fini(&(widget->clip));
- }
+ /* 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);
- if ((widget->parent != RT_NULL) && (widget->toplevel != RT_NULL))
- {
- /* update widget clip */
- rtgui_widget_update_clip(widget->parent);
- }
+ /* reset clip info */
+ rtgui_region_init_with_extents(&(widget->clip), rect);
+ if ((widget->parent != RT_NULL) && (widget->toplevel != RT_NULL))
+ {
+ /* update widget clip */
+ rtgui_widget_update_clip(widget->parent);
+ }
}
RTM_EXPORT(rtgui_widget_set_rect);
-void rtgui_widget_set_rectangle(rtgui_widget_t* widget, int x, int y, int width, int height)
+void rtgui_widget_set_rectangle(rtgui_widget_t *widget, int x, int y, int width, int height)
{
- rtgui_rect_t rect;
+ rtgui_rect_t rect;
- rect.x1 = x; rect.y1 = y;
- rect.x2 = x + width; rect.y2 = y + height;
+ rect.x1 = x;
+ rect.y1 = y;
+ rect.x2 = x + width;
+ rect.y2 = y + height;
- rtgui_widget_set_rect(widget, &rect);
+ rtgui_widget_set_rect(widget, &rect);
}
RTM_EXPORT(rtgui_widget_set_rectangle);
-void rtgui_widget_set_parent(rtgui_widget_t* widget, rtgui_widget_t* parent)
+void rtgui_widget_set_parent(rtgui_widget_t *widget, rtgui_widget_t *parent)
{
- /* set parent and toplevel widget */
- widget->parent = parent;
+ /* set parent and toplevel widget */
+ widget->parent = parent;
}
RTM_EXPORT(rtgui_widget_set_parent);
-void rtgui_widget_get_extent(rtgui_widget_t* widget, rtgui_rect_t *rect)
+void rtgui_widget_get_extent(rtgui_widget_t *widget, rtgui_rect_t *rect)
{
- RT_ASSERT(widget != RT_NULL);
- RT_ASSERT(rect != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(rect != RT_NULL);
- *rect = widget->extent;
+ *rect = widget->extent;
}
RTM_EXPORT(rtgui_widget_get_extent);
-void rtgui_widget_set_miniwidth(rtgui_widget_t* widget, int width)
+void rtgui_widget_set_miniwidth(rtgui_widget_t *widget, int width)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- widget->mini_width = width;
+ widget->mini_width = width;
}
RTM_EXPORT(rtgui_widget_set_miniwidth);
-void rtgui_widget_set_miniheight(rtgui_widget_t* widget, int height)
+void rtgui_widget_set_miniheight(rtgui_widget_t *widget, int height)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- widget->mini_height = height;
+ widget->mini_height = height;
}
RTM_EXPORT(rtgui_widget_set_miniheight);
/*
* 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)
+void rtgui_widget_move_to_logic(rtgui_widget_t *widget, int dx, int dy)
{
- struct rtgui_list_node* node;
- rtgui_widget_t* child;
+ struct rtgui_list_node *node;
+ rtgui_widget_t *child;
- if (widget == RT_NULL) return;
+ if (widget == RT_NULL) return;
- rtgui_rect_moveto(&(widget->extent), dx, dy);
+ 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);
+ /* 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);
- }
- }
+ rtgui_widget_move_to_logic(child, dx, dy);
+ }
+ }
}
RTM_EXPORT(rtgui_widget_move_to_logic);
-void rtgui_widget_get_rect(rtgui_widget_t* widget, rtgui_rect_t *rect)
+void rtgui_widget_get_rect(rtgui_widget_t *widget, rtgui_rect_t *rect)
{
- RT_ASSERT(widget != RT_NULL);
+ 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;
- }
+ 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;
+ }
}
RTM_EXPORT(rtgui_widget_get_rect);
/**
* set widget draw style
*/
-void rtgui_widget_set_border(rtgui_widget_t* widget, rt_uint32_t style)
+void rtgui_widget_set_border(rtgui_widget_t *widget, rt_uint32_t style)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- widget->border_style = style;
- switch(style)
- {
- case RTGUI_BORDER_NONE:
- widget->border = 0;
- break;
- case RTGUI_BORDER_SIMPLE:
- case RTGUI_BORDER_UP:
- case RTGUI_BORDER_DOWN:
- widget->border = 1;
- break;
- case RTGUI_BORDER_STATIC:
- case RTGUI_BORDER_RAISE:
- case RTGUI_BORDER_SUNKEN:
- case RTGUI_BORDER_BOX:
- case RTGUI_BORDER_EXTRA:
- widget->border = 2;
- break;
- default:
- widget->border = 2;
- break;
- }
+ widget->border_style = style;
+ switch (style)
+ {
+ case RTGUI_BORDER_NONE:
+ widget->border = 0;
+ break;
+ case RTGUI_BORDER_SIMPLE:
+ case RTGUI_BORDER_UP:
+ case RTGUI_BORDER_DOWN:
+ widget->border = 1;
+ break;
+ case RTGUI_BORDER_STATIC:
+ case RTGUI_BORDER_RAISE:
+ case RTGUI_BORDER_SUNKEN:
+ case RTGUI_BORDER_BOX:
+ case RTGUI_BORDER_EXTRA:
+ widget->border = 2;
+ break;
+ default:
+ widget->border = 2;
+ break;
+ }
}
RTM_EXPORT(rtgui_widget_set_border);
-void rtgui_widget_set_onfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
+void rtgui_widget_set_onfocus(rtgui_widget_t *widget, rtgui_event_handler_ptr handler)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- widget->on_focus_in = handler;
+ widget->on_focus_in = handler;
}
RTM_EXPORT(rtgui_widget_set_onfocus);
-void rtgui_widget_set_onunfocus(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
+void rtgui_widget_set_onunfocus(rtgui_widget_t *widget, rtgui_event_handler_ptr handler)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- widget->on_focus_out = handler;
+ widget->on_focus_out = handler;
}
RTM_EXPORT(rtgui_widget_set_onunfocus);
#ifndef RTGUI_USING_SMALL_SIZE
-void rtgui_widget_set_ondraw(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
+void rtgui_widget_set_ondraw(rtgui_widget_t *widget, rtgui_event_handler_ptr handler)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- widget->on_draw = handler;
+ widget->on_draw = handler;
}
RTM_EXPORT(rtgui_widget_set_ondraw);
-void rtgui_widget_set_onmouseclick(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
+void rtgui_widget_set_onmouseclick(rtgui_widget_t *widget, rtgui_event_handler_ptr handler)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- widget->on_mouseclick = handler;
+ widget->on_mouseclick = handler;
}
RTM_EXPORT(rtgui_widget_set_onmouseclick);
-void rtgui_widget_set_onkey(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
+void rtgui_widget_set_onkey(rtgui_widget_t *widget, rtgui_event_handler_ptr handler)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- widget->on_key = handler;
+ widget->on_key = handler;
}
RTM_EXPORT(rtgui_widget_set_onkey);
-void rtgui_widget_set_onsize(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
+void rtgui_widget_set_onsize(rtgui_widget_t *widget, rtgui_event_handler_ptr handler)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- widget->on_size = handler;
+ widget->on_size = handler;
}
RTM_EXPORT(rtgui_widget_set_onsize);
-void rtgui_widget_set_oncommand(rtgui_widget_t* widget, rtgui_event_handler_ptr handler)
+void rtgui_widget_set_oncommand(rtgui_widget_t *widget, rtgui_event_handler_ptr handler)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- widget->on_command = handler;
+ widget->on_command = handler;
}
RTM_EXPORT(rtgui_widget_set_oncommand);
#endif
@@ -328,28 +335,28 @@ RTM_EXPORT(rtgui_widget_set_oncommand);
*/
void rtgui_widget_focus(rtgui_widget_t *widget)
{
- struct rtgui_widget *old_focus;
+ struct rtgui_widget *old_focus;
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- if (!RTGUI_WIDGET_IS_FOCUSABLE(widget) || !RTGUI_WIDGET_IS_ENABLE(widget))
- return;
+ if (!RTGUI_WIDGET_IS_FOCUSABLE(widget) || !RTGUI_WIDGET_IS_ENABLE(widget))
+ return;
- old_focus = RTGUI_WIN(widget->toplevel)->focused_widget;
- if (old_focus == widget)
- return; /* it's the same focused widget */
+ old_focus = RTGUI_WIN(widget->toplevel)->focused_widget;
+ if (old_focus == widget)
+ return; /* it's the same focused widget */
- /* unfocused the old widget */
- if (old_focus != RT_NULL)
- rtgui_widget_unfocus(old_focus);
+ /* unfocused the old widget */
+ if (old_focus != RT_NULL)
+ rtgui_widget_unfocus(old_focus);
- /* set widget as focused */
- widget->flag |= RTGUI_WIDGET_FLAG_FOCUS;
- RTGUI_WIN(widget->toplevel)->focused_widget = widget;
+ /* set widget as focused */
+ widget->flag |= RTGUI_WIDGET_FLAG_FOCUS;
+ RTGUI_WIN(widget->toplevel)->focused_widget = widget;
- /* invoke on focus in call back */
- if (widget->on_focus_in != RT_NULL)
- widget->on_focus_in(RTGUI_OBJECT(widget), RT_NULL);
+ /* invoke on focus in call back */
+ if (widget->on_focus_in != RT_NULL)
+ widget->on_focus_in(RTGUI_OBJECT(widget), RT_NULL);
}
RTM_EXPORT(rtgui_widget_focus);
@@ -360,417 +367,420 @@ RTM_EXPORT(rtgui_widget_focus);
void rtgui_widget_unfocus(rtgui_widget_t *widget)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- if (!widget->toplevel || !RTGUI_WIDGET_IS_FOCUSED(widget))
- return;
+ if (!widget->toplevel || !RTGUI_WIDGET_IS_FOCUSED(widget))
+ return;
- widget->flag &= ~RTGUI_WIDGET_FLAG_FOCUS;
+ widget->flag &= ~RTGUI_WIDGET_FLAG_FOCUS;
- if (widget->on_focus_out != RT_NULL)
- widget->on_focus_out(RTGUI_OBJECT(widget), RT_NULL);
+ if (widget->on_focus_out != RT_NULL)
+ widget->on_focus_out(RTGUI_OBJECT(widget), RT_NULL);
- RTGUI_WIN(widget->toplevel)->focused_widget = RT_NULL;
+ RTGUI_WIN(widget->toplevel)->focused_widget = RT_NULL;
- /* Ergodic constituent widget, make child loss of focus */
- if(RTGUI_IS_CONTAINER(widget))
- {
- rtgui_list_t *node;
- rtgui_list_foreach(node, &(RTGUI_CONTAINER(widget)->children))
- {
- rtgui_widget_t *child = rtgui_list_entry(node, rtgui_widget_t, sibling);
- if(RTGUI_WIDGET_IS_HIDE(child)) continue;
- rtgui_widget_unfocus(child);
- }
- }
+ /* Ergodic constituent widget, make child loss of focus */
+ if (RTGUI_IS_CONTAINER(widget))
+ {
+ rtgui_list_t *node;
+ rtgui_list_foreach(node, &(RTGUI_CONTAINER(widget)->children))
+ {
+ rtgui_widget_t *child = rtgui_list_entry(node, rtgui_widget_t, sibling);
+ if (RTGUI_WIDGET_IS_HIDE(child)) continue;
+ rtgui_widget_unfocus(child);
+ }
+ }
}
RTM_EXPORT(rtgui_widget_unfocus);
-void rtgui_widget_point_to_device(rtgui_widget_t* widget, rtgui_point_t* point)
+void rtgui_widget_point_to_device(rtgui_widget_t *widget, rtgui_point_t *point)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- if (point != RT_NULL)
- {
- point->x += widget->extent.x1;
- point->y += widget->extent.y1;
- }
+ if (point != RT_NULL)
+ {
+ point->x += widget->extent.x1;
+ point->y += widget->extent.y1;
+ }
}
RTM_EXPORT(rtgui_widget_point_to_device);
-void rtgui_widget_rect_to_device(rtgui_widget_t* widget, rtgui_rect_t* rect)
+void rtgui_widget_rect_to_device(rtgui_widget_t *widget, rtgui_rect_t *rect)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- if (rect != RT_NULL)
- {
- rect->x1 += widget->extent.x1;
- rect->x2 += widget->extent.x1;
+ if (rect != RT_NULL)
+ {
+ rect->x1 += widget->extent.x1;
+ rect->x2 += widget->extent.x1;
- rect->y1 += widget->extent.y1;
- rect->y2 += widget->extent.y1;
- }
+ rect->y1 += widget->extent.y1;
+ rect->y2 += widget->extent.y1;
+ }
}
RTM_EXPORT(rtgui_widget_rect_to_device);
-void rtgui_widget_point_to_logic(rtgui_widget_t* widget, rtgui_point_t* point)
+void rtgui_widget_point_to_logic(rtgui_widget_t *widget, rtgui_point_t *point)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- if (point != RT_NULL)
- {
- point->x -= widget->extent.x1;
- point->y -= widget->extent.y1;
- }
+ if (point != RT_NULL)
+ {
+ point->x -= widget->extent.x1;
+ point->y -= widget->extent.y1;
+ }
}
RTM_EXPORT(rtgui_widget_point_to_logic);
-void rtgui_widget_rect_to_logic(rtgui_widget_t* widget, rtgui_rect_t* rect)
+void rtgui_widget_rect_to_logic(rtgui_widget_t *widget, rtgui_rect_t *rect)
{
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- if (rect != RT_NULL)
- {
- rect->x1 -= widget->extent.x1;
- rect->x2 -= widget->extent.x1;
+ if (rect != RT_NULL)
+ {
+ rect->x1 -= widget->extent.x1;
+ rect->x2 -= widget->extent.x1;
- rect->y1 -= widget->extent.y1;
- rect->y2 -= widget->extent.y1;
- }
+ rect->y1 -= widget->extent.y1;
+ rect->y2 -= widget->extent.y1;
+ }
}
RTM_EXPORT(rtgui_widget_rect_to_logic);
-struct rtgui_win* rtgui_widget_get_toplevel(rtgui_widget_t* widget)
+struct rtgui_win *rtgui_widget_get_toplevel(rtgui_widget_t *widget)
{
- rtgui_widget_t* r;
+ rtgui_widget_t *r;
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
- if (widget->toplevel)
- return widget->toplevel;
+ if (widget->toplevel)
+ return widget->toplevel;
- rt_kprintf("widget->toplevel not properly set\n");
- r = widget;
- /* get the toplevel widget */
- while (r->parent != RT_NULL)
- r = r->parent;
+ rt_kprintf("widget->toplevel not properly set\n");
+ r = widget;
+ /* get the toplevel widget */
+ while (r->parent != RT_NULL)
+ r = r->parent;
- /* set toplevel */
- widget->toplevel = RTGUI_WIN(r);
+ /* set toplevel */
+ widget->toplevel = RTGUI_WIN(r);
- return RTGUI_WIN(r);
+ return RTGUI_WIN(r);
}
RTM_EXPORT(rtgui_widget_get_toplevel);
rt_bool_t rtgui_widget_onupdate_toplvl(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_widget *widget;
- struct rtgui_event_update_toplvl *eup;
+ struct rtgui_widget *widget;
+ struct rtgui_event_update_toplvl *eup;
- RT_ASSERT(object);
- RT_ASSERT(event);
+ RT_ASSERT(object);
+ RT_ASSERT(event);
- widget = RTGUI_WIDGET(object);
- eup = (struct rtgui_event_update_toplvl*)event;
+ widget = RTGUI_WIDGET(object);
+ eup = (struct rtgui_event_update_toplvl *)event;
- widget->toplevel = eup->toplvl;
+ widget->toplevel = eup->toplvl;
- return RT_FALSE;
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_widget_onupdate_toplvl);
-rt_bool_t rtgui_widget_event_handler(struct rtgui_object* object, rtgui_event_t* event)
+rt_bool_t rtgui_widget_event_handler(struct rtgui_object *object, rtgui_event_t *event)
{
- RTGUI_WIDGET_EVENT_HANDLER_PREPARE;
+ RTGUI_WIDGET_EVENT_HANDLER_PREPARE;
- switch (event->type)
- {
- case RTGUI_EVENT_SHOW:
- return rtgui_widget_onshow(object, event);
- case RTGUI_EVENT_HIDE:
- return rtgui_widget_onhide(object, event);
- case RTGUI_EVENT_UPDATE_TOPLVL:
- return rtgui_widget_onupdate_toplvl(object, event);
+ switch (event->type)
+ {
+ case RTGUI_EVENT_SHOW:
+ return rtgui_widget_onshow(object, event);
+ case RTGUI_EVENT_HIDE:
+ return rtgui_widget_onhide(object, event);
+ case RTGUI_EVENT_UPDATE_TOPLVL:
+ return rtgui_widget_onupdate_toplvl(object, event);
#ifndef RTGUI_USING_SMALL_SIZE
- case RTGUI_EVENT_PAINT:
- if (widget->on_draw != RT_NULL)
- return widget->on_draw(RTGUI_OBJECT(widget), event);
- break;
+ case RTGUI_EVENT_PAINT:
+ if (widget->on_draw != RT_NULL)
+ return widget->on_draw(RTGUI_OBJECT(widget), event);
+ break;
- case RTGUI_EVENT_KBD:
- if (widget->on_key != RT_NULL)
- return widget->on_key(RTGUI_OBJECT(widget), event);
- break;
+ case RTGUI_EVENT_KBD:
+ if (widget->on_key != RT_NULL)
+ return widget->on_key(RTGUI_OBJECT(widget), event);
+ break;
- case RTGUI_EVENT_MOUSE_BUTTON:
- if (widget->on_mouseclick != RT_NULL)
- return widget->on_mouseclick(RTGUI_OBJECT(widget), event);
- break;
+ case RTGUI_EVENT_MOUSE_BUTTON:
+ if (widget->on_mouseclick != RT_NULL)
+ return widget->on_mouseclick(RTGUI_OBJECT(widget), event);
+ break;
- case RTGUI_EVENT_COMMAND:
- if (widget->on_command != RT_NULL)
- return widget->on_command(RTGUI_OBJECT(widget), event);
- break;
+ case RTGUI_EVENT_COMMAND:
+ if (widget->on_command != RT_NULL)
+ return widget->on_command(RTGUI_OBJECT(widget), event);
+ break;
- case RTGUI_EVENT_RESIZE:
- if (widget->on_size != RT_NULL)
- return widget->on_size(RTGUI_OBJECT(widget), event);
- break;
+ case RTGUI_EVENT_RESIZE:
+ if (widget->on_size != RT_NULL)
+ return widget->on_size(RTGUI_OBJECT(widget), event);
+ break;
#endif
- }
+ default:
+ return rtgui_object_event_handler(object, event);
+ }
- return rtgui_object_event_handler(object, event);
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_widget_event_handler);
/*
* This function updates the clip info of widget
*/
-void rtgui_widget_update_clip(rtgui_widget_t* widget)
+void rtgui_widget_update_clip(rtgui_widget_t *widget)
{
- struct rtgui_list_node* node;
- rtgui_widget_t *parent;
+ 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;
+ /* 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, there is no clip to update. */
- if (parent == RT_NULL)
- {
- return;
- }
+ parent = widget->parent;
+ /* if there is no parent, there is no clip to update. */
+ if (parent == RT_NULL)
+ {
+ return;
+ }
- /* reset clip to extent */
- rtgui_region_reset(&(widget->clip), &(widget->extent));
+ /* 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));
+ /* 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;
- }
+ /* 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));
- }
- }
+ if (parent != RT_NULL)
+ {
+ /* subtract widget clip in parent clip */
+ if (!(widget->flag & RTGUI_WIDGET_FLAG_TRANSPARENT) && RTGUI_IS_CONTAINER(parent))
+ {
+ rtgui_region_subtract_rect(&(parent->clip), &(parent->clip),
+ &(widget->extent));
+ }
+ }
- /*
- * note: since the layout widget introduction, the sibling widget will not
- * intersect.
- */
+ /*
+ * note: since the layout widget introduction, the sibling widget will not
+ * intersect.
+ */
- /* if it's a view 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);
+ /* if it's a view 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);
- }
- }
- else if (RTGUI_IS_NOTEBOOK(widget))
- {
- rtgui_widget_update_clip(rtgui_notebook_get_current(RTGUI_NOTEBOOK(widget)));
- }
+ rtgui_widget_update_clip(child);
+ }
+ }
+ else if (RTGUI_IS_NOTEBOOK(widget))
+ {
+ rtgui_widget_update_clip(rtgui_notebook_get_current(RTGUI_NOTEBOOK(widget)));
+ }
}
RTM_EXPORT(rtgui_widget_update_clip);
void rtgui_widget_show(struct rtgui_widget *widget)
{
- struct rtgui_event_show eshow;
- RT_ASSERT(widget != RT_NULL);
+ struct rtgui_event_show eshow;
+ RT_ASSERT(widget != RT_NULL);
if (!RTGUI_WIDGET_IS_HIDE(widget))
return;
- RTGUI_EVENT_SHOW_INIT(&eshow);
- if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
- {
- RTGUI_OBJECT(widget)->event_handler(
- RTGUI_OBJECT(widget),
- &eshow);
- }
+ RTGUI_EVENT_SHOW_INIT(&eshow);
+ if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
+ {
+ RTGUI_OBJECT(widget)->event_handler(
+ RTGUI_OBJECT(widget),
+ &eshow);
+ }
}
RTM_EXPORT(rtgui_widget_show);
rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_widget *widget = RTGUI_WIDGET(object);
+ struct rtgui_widget *widget = RTGUI_WIDGET(object);
if (!RTGUI_WIDGET_IS_HIDE(object))
return RT_FALSE;
- RTGUI_WIDGET_UNHIDE(widget);
+ RTGUI_WIDGET_UNHIDE(widget);
- return RT_FALSE;
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_widget_onshow);
rt_bool_t rtgui_widget_onhide(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_widget *widget = RTGUI_WIDGET(object);
+ struct rtgui_widget *widget = RTGUI_WIDGET(object);
if (RTGUI_WIDGET_IS_HIDE(object))
return RT_FALSE;
- /* hide this widget */
- RTGUI_WIDGET_HIDE(widget);
+ /* hide this widget */
+ RTGUI_WIDGET_HIDE(widget);
- if (widget->parent != RT_NULL)
- {
- rtgui_widget_t *parent;
+ if (widget->parent != RT_NULL)
+ {
+ rtgui_widget_t *parent;
- parent = widget->parent;
- /* get the no transparent parent */
- while (parent != RT_NULL && parent->flag & RTGUI_WIDGET_FLAG_TRANSPARENT)
- {
- parent = parent->parent;
- }
+ parent = widget->parent;
+ /* get the no transparent parent */
+ while (parent != RT_NULL && parent->flag & RTGUI_WIDGET_FLAG_TRANSPARENT)
+ {
+ parent = parent->parent;
+ }
- /* union widget rect */
- rtgui_region_union_rect(&(parent->clip), &(parent->clip), &(widget->extent));
- }
+ /* union widget rect */
+ rtgui_region_union_rect(&(parent->clip), &(parent->clip), &(widget->extent));
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_widget_onhide);
void rtgui_widget_hide(struct rtgui_widget *widget)
{
- struct rtgui_event_hide ehide;
- RT_ASSERT(widget != RT_NULL);
+ struct rtgui_event_hide ehide;
+ RT_ASSERT(widget != RT_NULL);
if (RTGUI_WIDGET_IS_HIDE(widget))
return;
- RTGUI_EVENT_HIDE_INIT(&ehide);
- if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
- {
- RTGUI_OBJECT(widget)->event_handler(
- RTGUI_OBJECT(widget),
- &ehide);
- }
+ RTGUI_EVENT_HIDE_INIT(&ehide);
+ if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
+ {
+ RTGUI_OBJECT(widget)->event_handler(
+ RTGUI_OBJECT(widget),
+ &ehide);
+ }
}
RTM_EXPORT(rtgui_widget_hide);
-rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t* widget)
+rtgui_color_t rtgui_widget_get_parent_foreground(rtgui_widget_t *widget)
{
- rtgui_widget_t* parent;
+ 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 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);
+ /* get parent's color */
+ if (parent != RT_NULL)
+ return RTGUI_WIDGET_FOREGROUND(parent);
- return RTGUI_WIDGET_FOREGROUND(widget);
+ return RTGUI_WIDGET_FOREGROUND(widget);
}
RTM_EXPORT(rtgui_widget_get_parent_foreground);
-rtgui_color_t rtgui_widget_get_parent_background(rtgui_widget_t* 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;
+ 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);
+ /* get parent's color */
+ if (parent != RT_NULL)
+ return RTGUI_WIDGET_BACKGROUND(parent);
- return RTGUI_WIDGET_BACKGROUND(widget);
+ return RTGUI_WIDGET_BACKGROUND(widget);
}
RTM_EXPORT(rtgui_widget_get_parent_background);
-void rtgui_widget_update(rtgui_widget_t* widget)
+void rtgui_widget_update(rtgui_widget_t *widget)
{
- struct rtgui_event_paint paint;
- RTGUI_EVENT_PAINT_INIT(&paint);
- paint.wid = RT_NULL;
+ struct rtgui_event_paint paint;
+ RTGUI_EVENT_PAINT_INIT(&paint);
+ paint.wid = RT_NULL;
- RT_ASSERT(widget != RT_NULL);
+ RT_ASSERT(widget != RT_NULL);
if (RTGUI_WIDGET_IS_HIDE(widget))
return;
- if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
- {
- RTGUI_OBJECT(widget)->event_handler(
- RTGUI_OBJECT(widget),
- &paint.parent);
- }
+ if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
+ {
+ RTGUI_OBJECT(widget)->event_handler(
+ RTGUI_OBJECT(widget),
+ &paint.parent);
+ }
}
RTM_EXPORT(rtgui_widget_update);
-rtgui_widget_t* rtgui_widget_get_next_sibling(rtgui_widget_t* widget)
+rtgui_widget_t *rtgui_widget_get_next_sibling(rtgui_widget_t *widget)
{
- rtgui_widget_t* sibling = RT_NULL;
+ rtgui_widget_t *sibling = RT_NULL;
- if (widget->sibling.next != RT_NULL)
- {
- sibling = rtgui_list_entry(widget->sibling.next, rtgui_widget_t, sibling);
- }
+ if (widget->sibling.next != RT_NULL)
+ {
+ sibling = rtgui_list_entry(widget->sibling.next, rtgui_widget_t, sibling);
+ }
- return sibling;
+ return sibling;
}
RTM_EXPORT(rtgui_widget_get_next_sibling);
-rtgui_widget_t* rtgui_widget_get_prev_sibling(rtgui_widget_t* widget)
+rtgui_widget_t *rtgui_widget_get_prev_sibling(rtgui_widget_t *widget)
{
- struct rtgui_list_node* node;
- rtgui_widget_t *sibling, *parent;
+ 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;
- }
- }
+ 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);
+ if (node != RT_NULL)
+ sibling = rtgui_list_entry(node, rtgui_widget_t, sibling);
- return sibling;
+ return sibling;
}
RTM_EXPORT(rtgui_widget_get_prev_sibling);
#ifdef RTGUI_WIDGET_DEBUG
#include <rtgui/widgets/label.h>
#include <rtgui/widgets/button.h>
-void rtgui_widget_dump(rtgui_widget_t* widget)
+void rtgui_widget_dump(rtgui_widget_t *widget)
{
- struct rtgui_object *obj;
+ struct rtgui_object *obj;
- obj = RTGUI_OBJECT(widget);
- rt_kprintf("widget type: %s ", obj->type->name);
+ obj = RTGUI_OBJECT(widget);
+ rt_kprintf("widget type: %s ", obj->type->name);
- if (RTGUI_IS_WIN(widget) == RT_TRUE)
- rt_kprintf(":%s ", RTGUI_WIN(widget)->title);
- else if ((RTGUI_IS_LABEL(widget) == RT_TRUE) || (RTGUI_IS_BUTTON(widget) == RT_TRUE))
- rt_kprintf(":%s ", RTGUI_LABEL(widget)->text);
+ if (RTGUI_IS_WIN(widget) == RT_TRUE)
+ rt_kprintf(":%s ", RTGUI_WIN(widget)->title);
+ else if ((RTGUI_IS_LABEL(widget) == RT_TRUE) || (RTGUI_IS_BUTTON(widget) == RT_TRUE))
+ rt_kprintf(":%s ", RTGUI_LABEL(widget)->text);
- rt_kprintf("extent(%d, %d) - (%d, %d)\n", widget->extent.x1,
- widget->extent.y1, widget->extent.x2, widget->extent.y2);
- // rtgui_region_dump(&(widget->clip));
+ rt_kprintf("extent(%d, %d) - (%d, %d)\n", widget->extent.x1,
+ widget->extent.y1, widget->extent.x2, widget->extent.y2);
+ // rtgui_region_dump(&(widget->clip));
}
#endif
diff --git a/components/rtgui/widgets/window.c b/components/rtgui/widgets/window.c
index c562ec2fba..cb93ee9e92 100644
--- a/components/rtgui/widgets/window.c
+++ b/components/rtgui/widgets/window.c
@@ -23,695 +23,696 @@
static void _rtgui_win_constructor(rtgui_win_t *win)
{
- /* set toplevel to self */
+ /* set toplevel to self */
RTGUI_WIDGET(win)->toplevel = win;
- /* init win property */
- win->drawing = 0;
+ /* init win property */
+ win->drawing = 0;
- /* hide win default */
- RTGUI_WIDGET_HIDE(win);
+ /* hide win default */
+ RTGUI_WIDGET_HIDE(win);
- RTGUI_WIDGET(win)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
- win->parent_window = RT_NULL;
- /* init window attribute */
- win->on_activate = RT_NULL;
- win->on_deactivate = RT_NULL;
- win->on_close = RT_NULL;
- win->on_key = RT_NULL;
- win->title = RT_NULL;
- win->modal_code = RTGUI_MODAL_OK;
+ RTGUI_WIDGET(win)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
+ win->parent_window = RT_NULL;
+ win->app = rtgui_app_self();
+ /* init window attribute */
+ win->on_activate = RT_NULL;
+ win->on_deactivate = RT_NULL;
+ win->on_close = RT_NULL;
+ win->on_key = RT_NULL;
+ win->title = RT_NULL;
+ win->modal_code = RTGUI_MODAL_OK;
- /* initialize last mouse event handled widget */
- win->last_mevent_widget = RT_NULL;
- win->focused_widget = RT_NULL;
+ /* initialize last mouse event handled widget */
+ win->last_mevent_widget = RT_NULL;
+ win->focused_widget = RT_NULL;
- /* set window hide */
- RTGUI_WIDGET_HIDE(win);
+ /* set window hide */
+ RTGUI_WIDGET_HIDE(win);
- /* set window style */
- win->style = RTGUI_WIN_STYLE_DEFAULT;
+ /* set window style */
+ win->style = RTGUI_WIN_STYLE_DEFAULT;
- win->flag = RTGUI_WIN_FLAG_INIT;
+ win->flag = RTGUI_WIN_FLAG_INIT;
- rtgui_object_set_event_handler(RTGUI_OBJECT(win), rtgui_win_event_handler);
+ rtgui_object_set_event_handler(RTGUI_OBJECT(win), rtgui_win_event_handler);
- /* init user data */
- win->user_data = 0;
+ /* init user data */
+ win->user_data = 0;
}
-static void _rtgui_win_destructor(rtgui_win_t* win)
+static void _rtgui_win_destructor(rtgui_win_t *win)
{
- struct rtgui_event_win_destroy edestroy;
+ struct rtgui_event_win_destroy edestroy;
- if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
- {
- /* destroy in server */
- RTGUI_EVENT_WIN_DESTROY_INIT(&edestroy);
- edestroy.wid = win;
- if (rtgui_server_post_event_sync(RTGUI_EVENT(&edestroy),
- sizeof(struct rtgui_event_win_destroy)) != RT_EOK)
- {
- /* destroy in server failed */
- return;
- }
- }
+ if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
+ {
+ /* destroy in server */
+ RTGUI_EVENT_WIN_DESTROY_INIT(&edestroy);
+ edestroy.wid = win;
+ if (rtgui_server_post_event_sync(RTGUI_EVENT(&edestroy),
+ sizeof(struct rtgui_event_win_destroy)) != RT_EOK)
+ {
+ /* destroy in server failed */
+ return;
+ }
+ }
- /* release field */
- if (win->title != RT_NULL)
- rt_free(win->title);
- /* release external clip info */
- win->drawing = 0;
+ /* release field */
+ if (win->title != RT_NULL)
+ rt_free(win->title);
+ /* release external clip info */
+ win->drawing = 0;
}
static rt_bool_t _rtgui_win_create_in_server(struct rtgui_win *win)
{
- if (!(win->flag & RTGUI_WIN_FLAG_CONNECTED))
- {
- struct rtgui_event_win_create ecreate;
- RTGUI_EVENT_WIN_CREATE_INIT(&ecreate);
+ if (!(win->flag & RTGUI_WIN_FLAG_CONNECTED))
+ {
+ struct rtgui_event_win_create ecreate;
+ RTGUI_EVENT_WIN_CREATE_INIT(&ecreate);
- /* send win create event to server */
- ecreate.parent_window = win->parent_window;
- ecreate.wid = win;
- ecreate.parent.user = win->style;
+ /* send win create event to server */
+ ecreate.parent_window = win->parent_window;
+ 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);
+ ecreate.extent = RTGUI_WIDGET(win)->extent;
+ rt_strncpy((char *)ecreate.title, (char *)win->title, RTGUI_NAME_MAX);
#endif
- if (rtgui_server_post_event_sync(RTGUI_EVENT(&ecreate),
- sizeof(struct rtgui_event_win_create)
- ) != RT_EOK)
- {
- rt_kprintf("create win: %s failed\n", win->title);
- return RT_FALSE;
- }
+ if (rtgui_server_post_event_sync(RTGUI_EVENT(&ecreate),
+ sizeof(struct rtgui_event_win_create)
+ ) != RT_EOK)
+ {
+ rt_kprintf("create win: %s failed\n", win->title);
+ return RT_FALSE;
+ }
- win->flag |= RTGUI_WIN_FLAG_CONNECTED;
- }
+ win->flag |= RTGUI_WIN_FLAG_CONNECTED;
+ }
- return RT_TRUE;
+ return RT_TRUE;
}
DEFINE_CLASS_TYPE(win, "win",
- RTGUI_CONTAINER_TYPE,
- _rtgui_win_constructor,
- _rtgui_win_destructor,
- sizeof(struct rtgui_win));
+ RTGUI_CONTAINER_TYPE,
+ _rtgui_win_constructor,
+ _rtgui_win_destructor,
+ sizeof(struct rtgui_win));
-rtgui_win_t* rtgui_win_create(struct rtgui_win* parent_window,
- const char* title,
- rtgui_rect_t *rect,
- rt_uint16_t style)
+rtgui_win_t *rtgui_win_create(struct rtgui_win *parent_window,
+ const char *title,
+ rtgui_rect_t *rect,
+ rt_uint16_t style)
{
- struct rtgui_win* win;
+ struct rtgui_win *win;
- /* allocate win memory */
- win = RTGUI_WIN(rtgui_widget_create(RTGUI_WIN_TYPE));
- if (win == RT_NULL)
- return RT_NULL;
+ /* allocate win memory */
+ win = RTGUI_WIN(rtgui_widget_create(RTGUI_WIN_TYPE));
+ if (win == RT_NULL)
+ return RT_NULL;
- /* set parent window */
- win->parent_window = parent_window;
+ /* set parent window */
+ win->parent_window = parent_window;
- /* set title, rect and style */
- if (title != RT_NULL)
- win->title = rt_strdup(title);
- else
- win->title = RT_NULL;
+ /* 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;
+ rtgui_widget_set_rect(RTGUI_WIDGET(win), rect);
+ win->style = style;
- if (_rtgui_win_create_in_server(win) == RT_FALSE)
- {
- goto __on_err;
- }
- return win;
+ if (_rtgui_win_create_in_server(win) == RT_FALSE)
+ {
+ goto __on_err;
+ }
+ return win;
__on_err:
- rtgui_widget_destroy(RTGUI_WIDGET(win));
- return RT_NULL;
+ rtgui_widget_destroy(RTGUI_WIDGET(win));
+ return RT_NULL;
}
RTM_EXPORT(rtgui_win_create);
-rtgui_win_t* rtgui_mainwin_create(struct rtgui_win *parent_window, const char* title, rt_uint16_t style)
+rtgui_win_t *rtgui_mainwin_create(struct rtgui_win *parent_window, const char *title, rt_uint16_t style)
{
- struct rtgui_rect rect;
+ struct rtgui_rect rect;
- /* get rect of main window */
- rtgui_get_mainwin_rect(&rect);
+ /* get rect of main window */
+ rtgui_get_mainwin_rect(&rect);
- return rtgui_win_create(parent_window, title, &rect, style);
+ return rtgui_win_create(parent_window, title, &rect, style);
}
RTM_EXPORT(rtgui_mainwin_create);
static rt_bool_t _rtgui_win_deal_close(struct rtgui_win *win,
- struct rtgui_event *event,
- rt_bool_t force_close)
+ struct rtgui_event *event,
+ rt_bool_t force_close)
{
- if (win->on_close != RT_NULL)
- {
- if ((win->on_close(RTGUI_OBJECT(win), event) == RT_FALSE) && !force_close)
- return RT_FALSE;
- }
+ if (win->on_close != RT_NULL)
+ {
+ if ((win->on_close(RTGUI_OBJECT(win), event) == RT_FALSE) && !force_close)
+ return RT_FALSE;
+ }
- rtgui_win_hiden(win);
+ rtgui_win_hiden(win);
- win->flag |= RTGUI_WIN_FLAG_CLOSED;
+ win->flag |= RTGUI_WIN_FLAG_CLOSED;
- if (win->flag & RTGUI_WIN_FLAG_MODAL)
- {
- rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
- }
- else if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
- {
- rtgui_win_destroy(win);
- }
+ if (win->flag & RTGUI_WIN_FLAG_MODAL)
+ {
+ rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
+ }
+ else if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
+ {
+ rtgui_win_destroy(win);
+ }
- return RT_TRUE;
+ return RT_TRUE;
}
-void rtgui_win_destroy(struct rtgui_win* win)
+void rtgui_win_destroy(struct rtgui_win *win)
{
- /* close the window first if it's not. */
- if (!(win->flag & RTGUI_WIN_FLAG_CLOSED))
- {
- struct rtgui_event_win_close eclose;
+ /* close the window first if it's not. */
+ if (!(win->flag & RTGUI_WIN_FLAG_CLOSED))
+ {
+ struct rtgui_event_win_close eclose;
- RTGUI_EVENT_WIN_CLOSE_INIT(&eclose);
- eclose.wid = win;
+ RTGUI_EVENT_WIN_CLOSE_INIT(&eclose);
+ eclose.wid = win;
- if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
- {
- _rtgui_win_deal_close(win,
- (struct rtgui_event*)&eclose,
- RT_TRUE);
- return;
- }
- else
- _rtgui_win_deal_close(win,
- (struct rtgui_event*)&eclose,
- RT_TRUE);
- }
+ if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
+ {
+ _rtgui_win_deal_close(win,
+ (struct rtgui_event *)&eclose,
+ RT_TRUE);
+ return;
+ }
+ else
+ _rtgui_win_deal_close(win,
+ (struct rtgui_event *)&eclose,
+ RT_TRUE);
+ }
- if (win->flag & RTGUI_WIN_FLAG_MODAL)
- {
- /* set the RTGUI_WIN_STYLE_DESTROY_ON_CLOSE flag so the window will be
- * destroyed after the event_loop */
- win->style |= RTGUI_WIN_STYLE_DESTROY_ON_CLOSE;
- rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
- }
- else
- {
- rtgui_widget_destroy(RTGUI_WIDGET(win));
- }
+ if (win->flag & RTGUI_WIN_FLAG_MODAL)
+ {
+ /* set the RTGUI_WIN_STYLE_DESTROY_ON_CLOSE flag so the window will be
+ * destroyed after the event_loop */
+ win->style |= RTGUI_WIN_STYLE_DESTROY_ON_CLOSE;
+ rtgui_win_end_modal(win, RTGUI_MODAL_CANCEL);
+ }
+ else
+ {
+ rtgui_widget_destroy(RTGUI_WIDGET(win));
+ }
}
RTM_EXPORT(rtgui_win_destroy);
/* send a close event to myself to get a consistent behavior */
-rt_bool_t rtgui_win_close(struct rtgui_win* win)
+rt_bool_t rtgui_win_close(struct rtgui_win *win)
{
- struct rtgui_event_win_close eclose;
+ struct rtgui_event_win_close eclose;
- RTGUI_EVENT_WIN_CLOSE_INIT(&eclose);
- eclose.wid = win;
- return _rtgui_win_deal_close(win,
- (struct rtgui_event*)&eclose,
- RT_FALSE);
+ RTGUI_EVENT_WIN_CLOSE_INIT(&eclose);
+ eclose.wid = win;
+ return _rtgui_win_deal_close(win,
+ (struct rtgui_event *)&eclose,
+ RT_FALSE);
}
RTM_EXPORT(rtgui_win_close);
-rt_base_t rtgui_win_show(struct rtgui_win* win, rt_bool_t is_modal)
+rt_base_t rtgui_win_show(struct rtgui_win *win, rt_bool_t is_modal)
{
- rt_base_t exit_code = -1;
- struct rtgui_app *app;
- struct rtgui_event_win_show eshow;
+ rt_base_t exit_code = -1;
+ struct rtgui_app *app;
+ struct rtgui_event_win_show eshow;
- app = rtgui_app_self();
- RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
- eshow.wid = win;
+ app = win->app;
+ RTGUI_EVENT_WIN_SHOW_INIT(&eshow);
+ eshow.wid = win;
- if (win == RT_NULL)
- return exit_code;
+ if (win == RT_NULL)
+ return exit_code;
- /* if it does not register into server, create it in server */
- if (!(win->flag & RTGUI_WIN_FLAG_CONNECTED))
- {
- if (_rtgui_win_create_in_server(win) == RT_FALSE)
- return exit_code;
- }
+ /* if it does not register into server, create it in server */
+ if (!(win->flag & RTGUI_WIN_FLAG_CONNECTED))
+ {
+ if (_rtgui_win_create_in_server(win) == RT_FALSE)
+ return exit_code;
+ }
- /* set window unhidden before notify the server */
- rtgui_widget_show(RTGUI_WIDGET(win));
+ /* set window unhidden before notify the server */
+ rtgui_widget_show(RTGUI_WIDGET(win));
- if (rtgui_server_post_event_sync(RTGUI_EVENT(&eshow),
- sizeof(struct rtgui_event_win_show)) != RT_EOK)
- {
- /* It could not be shown if a parent window is hidden. */
- rtgui_widget_hide(RTGUI_WIDGET(win));
- return exit_code;
- }
+ if (rtgui_server_post_event_sync(RTGUI_EVENT(&eshow),
+ sizeof(struct rtgui_event_win_show)) != RT_EOK)
+ {
+ /* It could not be shown if a parent window is hidden. */
+ rtgui_widget_hide(RTGUI_WIDGET(win));
+ return exit_code;
+ }
- if (win->focused_widget == RT_NULL)
- rtgui_widget_focus(RTGUI_WIDGET(win));
+ if (win->focused_widget == RT_NULL)
+ rtgui_widget_focus(RTGUI_WIDGET(win));
- /* set main window */
- if (app->main_object == RT_NULL)
- rtgui_app_set_main_win(win);
+ /* set main window */
+ if (app->main_object == RT_NULL)
+ rtgui_app_set_main_win(win);
if (is_modal == RT_TRUE)
{
- struct rtgui_app *app;
- struct rtgui_event_win_modal_enter emodal;
+ struct rtgui_app *app;
+ struct rtgui_event_win_modal_enter emodal;
- RTGUI_EVENT_WIN_MODAL_ENTER_INIT(&emodal);
- emodal.wid = win;
+ RTGUI_EVENT_WIN_MODAL_ENTER_INIT(&emodal);
+ emodal.wid = win;
- app = rtgui_app_self();
- RT_ASSERT(app != RT_NULL);
+ app = win->app;
+ RT_ASSERT(app != RT_NULL);
- win->flag |= RTGUI_WIN_FLAG_MODAL;
+ win->flag |= RTGUI_WIN_FLAG_MODAL;
- if (rtgui_server_post_event_sync((struct rtgui_event*)&emodal,
- sizeof(emodal)) != RT_EOK)
- return exit_code;
+ if (rtgui_server_post_event_sync((struct rtgui_event *)&emodal,
+ sizeof(emodal)) != RT_EOK)
+ return exit_code;
- app->modal_object = RTGUI_OBJECT(win);
+ app->modal_object = RTGUI_OBJECT(win);
- exit_code = rtgui_app_run(app);
+ exit_code = rtgui_app_run(app);
- app->modal_object = RT_NULL;
- win->flag &= ~RTGUI_WIN_FLAG_MODAL;
+ app->modal_object = RT_NULL;
+ win->flag &= ~RTGUI_WIN_FLAG_MODAL;
- if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
- {
- rtgui_win_destroy(win);
- }
+ if (win->style & RTGUI_WIN_STYLE_DESTROY_ON_CLOSE)
+ {
+ rtgui_win_destroy(win);
+ }
}
- return exit_code;
+ return exit_code;
}
RTM_EXPORT(rtgui_win_show);
-void rtgui_win_end_modal(struct rtgui_win* win, rtgui_modal_code_t modal_code)
+void rtgui_win_end_modal(struct rtgui_win *win, rtgui_modal_code_t modal_code)
{
- if (win == RT_NULL || !(win->flag & RTGUI_WIN_FLAG_MODAL))
- return;
+ if (win == RT_NULL || !(win->flag & RTGUI_WIN_FLAG_MODAL))
+ return;
- rtgui_app_exit(rtgui_app_self(), modal_code);
+ rtgui_app_exit(win->app, modal_code);
- /* remove modal mode */
- win->flag &= ~RTGUI_WIN_FLAG_MODAL;
+ /* remove modal mode */
+ win->flag &= ~RTGUI_WIN_FLAG_MODAL;
}
RTM_EXPORT(rtgui_win_end_modal);
-void rtgui_win_hiden(struct rtgui_win* win)
+void rtgui_win_hiden(struct rtgui_win *win)
{
- RT_ASSERT(win != RT_NULL);
+ RT_ASSERT(win != RT_NULL);
- if (!RTGUI_WIDGET_IS_HIDE(win) &&
- win->flag & RTGUI_WIN_FLAG_CONNECTED)
- {
- /* send hidden message to server */
- struct rtgui_event_win_hide ehide;
- RTGUI_EVENT_WIN_HIDE_INIT(&ehide);
- ehide.wid = win;
+ if (!RTGUI_WIDGET_IS_HIDE(win) &&
+ win->flag & RTGUI_WIN_FLAG_CONNECTED)
+ {
+ /* send hidden message to server */
+ struct rtgui_event_win_hide ehide;
+ RTGUI_EVENT_WIN_HIDE_INIT(&ehide);
+ ehide.wid = win;
- if (rtgui_server_post_event_sync(RTGUI_EVENT(&ehide),
- sizeof(struct rtgui_event_win_hide)) != RT_EOK)
- {
- rt_kprintf("hide win: %s failed\n", win->title);
- return;
- }
+ if (rtgui_server_post_event_sync(RTGUI_EVENT(&ehide),
+ sizeof(struct rtgui_event_win_hide)) != RT_EOK)
+ {
+ rt_kprintf("hide win: %s failed\n", win->title);
+ return;
+ }
- rtgui_widget_hide(RTGUI_WIDGET(win));
- win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
- }
+ rtgui_widget_hide(RTGUI_WIDGET(win));
+ win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
+ }
}
RTM_EXPORT(rtgui_win_hiden);
rt_err_t rtgui_win_activate(struct rtgui_win *win)
{
- struct rtgui_event_win_activate eact;
- RTGUI_EVENT_WIN_ACTIVATE_INIT(&eact);
- eact.wid = win;
+ struct rtgui_event_win_activate eact;
+ RTGUI_EVENT_WIN_ACTIVATE_INIT(&eact);
+ eact.wid = win;
- return rtgui_server_post_event_sync(RTGUI_EVENT(&eact),
- sizeof(eact));
+ return rtgui_server_post_event_sync(RTGUI_EVENT(&eact),
+ sizeof(eact));
}
RTM_EXPORT(rtgui_win_activate);
-rt_bool_t rtgui_win_is_activated(struct rtgui_win* win)
+rt_bool_t rtgui_win_is_activated(struct rtgui_win *win)
{
- RT_ASSERT(win != RT_NULL);
+ RT_ASSERT(win != RT_NULL);
- if (win->flag & RTGUI_WIN_FLAG_ACTIVATE) return RT_TRUE;
+ if (win->flag & RTGUI_WIN_FLAG_ACTIVATE) return RT_TRUE;
- return RT_FALSE;
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_win_is_activated);
-void rtgui_win_move(struct rtgui_win* win, int x, int y)
+void rtgui_win_move(struct rtgui_win *win, int x, int y)
{
- struct rtgui_event_win_move emove;
- RTGUI_EVENT_WIN_MOVE_INIT(&emove);
+ struct rtgui_event_win_move emove;
+ RTGUI_EVENT_WIN_MOVE_INIT(&emove);
- if (win == RT_NULL)
- return;
+ if (win == RT_NULL)
+ 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);
+ /* 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);
- if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
- {
- /* set win hide firstly */
- rtgui_widget_hide(RTGUI_WIDGET(win));
+ if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
+ {
+ /* set win hide firstly */
+ rtgui_widget_hide(RTGUI_WIDGET(win));
- emove.wid = win;
- emove.x = x;
- emove.y = y;
- if (rtgui_server_post_event_sync(RTGUI_EVENT(&emove),
- sizeof(struct rtgui_event_win_move)) != RT_EOK)
- {
- return;
- }
- }
+ emove.wid = win;
+ emove.x = x;
+ emove.y = y;
+ if (rtgui_server_post_event_sync(RTGUI_EVENT(&emove),
+ sizeof(struct rtgui_event_win_move)) != RT_EOK)
+ {
+ return;
+ }
+ }
- /* set window visible */
- rtgui_widget_show(RTGUI_WIDGET(win));
- return;
+ /* set window visible */
+ rtgui_widget_show(RTGUI_WIDGET(win));
+ return;
}
RTM_EXPORT(rtgui_win_move);
-static rt_bool_t rtgui_win_ondraw(struct rtgui_win* win)
+static rt_bool_t rtgui_win_ondraw(struct rtgui_win *win)
{
- struct rtgui_dc* dc;
- struct rtgui_rect rect;
- struct rtgui_event_paint event;
+ 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;
+ /* 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);
+ /* 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);
+ /* 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);
+ rtgui_dc_end_drawing(dc);
- return RT_FALSE;
+ return RT_FALSE;
}
-void rtgui_win_update_clip(struct rtgui_win* win)
+void rtgui_win_update_clip(struct rtgui_win *win)
{
- struct rtgui_container* cnt;
- struct rtgui_list_node* node;
+ struct rtgui_container *cnt;
+ struct rtgui_list_node *node;
- if (win == RT_NULL)
- return;
+ if (win == RT_NULL)
+ return;
- /* update the clip info of each child */
- cnt = RTGUI_CONTAINER(win);
- rtgui_list_foreach(node, &(cnt->children))
- {
- rtgui_widget_t* child = rtgui_list_entry(node, rtgui_widget_t, sibling);
+ /* update the clip info of each child */
+ cnt = RTGUI_CONTAINER(win);
+ rtgui_list_foreach(node, &(cnt->children))
+ {
+ rtgui_widget_t *child = rtgui_list_entry(node, rtgui_widget_t, sibling);
- rtgui_widget_update_clip(child);
- }
+ rtgui_widget_update_clip(child);
+ }
}
-rt_bool_t rtgui_win_event_handler(struct rtgui_object* object, struct rtgui_event* event)
+rt_bool_t rtgui_win_event_handler(struct rtgui_object *object, struct rtgui_event *event)
{
- struct rtgui_win* win;
+ struct rtgui_win *win;
- RT_ASSERT(object != RT_NULL);
- RT_ASSERT(event != RT_NULL);
+ RT_ASSERT(object != RT_NULL);
+ RT_ASSERT(event != RT_NULL);
- win = RTGUI_WIN(object);
+ win = RTGUI_WIN(object);
- switch (event->type)
- {
- case RTGUI_EVENT_WIN_SHOW:
- rtgui_win_show(win, RT_FALSE);
- break;
+ 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_HIDE:
+ rtgui_win_hiden(win);
+ break;
- case RTGUI_EVENT_WIN_CLOSE:
- _rtgui_win_deal_close(win, event, RT_FALSE);
- /* don't broadcast WIN_CLOSE event to others */
- return RT_TRUE;
+ case RTGUI_EVENT_WIN_CLOSE:
+ _rtgui_win_deal_close(win, event, RT_FALSE);
+ /* don't broadcast WIN_CLOSE event to others */
+ return RT_TRUE;
- case RTGUI_EVENT_WIN_MOVE:
- {
- struct rtgui_event_win_move* emove = (struct rtgui_event_win_move*)event;
+ 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;
+ /* move window */
+ rtgui_win_move(win, emove->x, emove->y);
+ }
+ break;
- case RTGUI_EVENT_WIN_ACTIVATE:
- if (RTGUI_WIDGET_IS_HIDE(win))
- {
- /* activate a hide window */
- return RT_TRUE;
- }
+ case RTGUI_EVENT_WIN_ACTIVATE:
+ if (RTGUI_WIDGET_IS_HIDE(win))
+ {
+ /* activate a hide window */
+ return RT_TRUE;
+ }
- win->flag |= RTGUI_WIN_FLAG_ACTIVATE;
- if (win->on_activate != RT_NULL)
- {
- win->on_activate(RTGUI_OBJECT(object), event);
- }
- break;
+ win->flag |= RTGUI_WIN_FLAG_ACTIVATE;
+ if (win->on_activate != RT_NULL)
+ {
+ win->on_activate(RTGUI_OBJECT(object), event);
+ }
+ break;
- case RTGUI_EVENT_WIN_DEACTIVATE:
- if (win->flag & RTGUI_WIN_FLAG_MODAL)
- {
- /* FIXME: make modal concept clear and easy. See the comment of
- * rtgui_topwin_modal_enter. */
- /* There are various reason that a modal window got deactivated:
- * 1, it has child windows and the user activate one of them.
- * 2, the application has more than one root window and the
- * user switched to one of the others.
- *
- * In any of the cases, we have nothing to do here.
- */
- }
- else
- {
- win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
- if (win->on_deactivate != RT_NULL)
- {
- win->on_deactivate(RTGUI_OBJECT(object), event);
- }
- }
- break;
+ case RTGUI_EVENT_WIN_DEACTIVATE:
+ if (win->flag & RTGUI_WIN_FLAG_MODAL)
+ {
+ /* FIXME: make modal concept clear and easy. See the comment of
+ * rtgui_topwin_modal_enter. */
+ /* There are various reason that a modal window got deactivated:
+ * 1, it has child windows and the user activate one of them.
+ * 2, the application has more than one root window and the
+ * user switched to one of the others.
+ *
+ * In any of the cases, we have nothing to do here.
+ */
+ }
+ else
+ {
+ win->flag &= ~RTGUI_WIN_FLAG_ACTIVATE;
+ if (win->on_deactivate != RT_NULL)
+ {
+ win->on_deactivate(RTGUI_OBJECT(object), event);
+ }
+ }
+ break;
- case RTGUI_EVENT_CLIP_INFO:
- /* update win clip */
- rtgui_win_update_clip(win);
- break;
+ case RTGUI_EVENT_CLIP_INFO:
+ /* update win clip */
+ rtgui_win_update_clip(win);
+ break;
- case RTGUI_EVENT_PAINT:
+ case RTGUI_EVENT_PAINT:
#ifndef RTGUI_USING_SMALL_SIZE
- if (RTGUI_WIDGET(object)->on_draw != RT_NULL)
- RTGUI_WIDGET(object)->on_draw(object, event);
- else
+ if (RTGUI_WIDGET(object)->on_draw != RT_NULL)
+ RTGUI_WIDGET(object)->on_draw(object, event);
+ else
#endif
- rtgui_win_ondraw(win);
- break;
+ rtgui_win_ondraw(win);
+ break;
- case RTGUI_EVENT_MOUSE_BUTTON:
- /* check whether has widget which handled mouse event before */
- if (win->last_mevent_widget != RT_NULL)
- {
- RTGUI_OBJECT(win->last_mevent_widget)->event_handler(
- RTGUI_OBJECT(win->last_mevent_widget),
- event);
+ case RTGUI_EVENT_MOUSE_BUTTON:
+ /* check whether has widget which handled mouse event before */
+ if (win->last_mevent_widget != RT_NULL)
+ {
+ RTGUI_OBJECT(win->last_mevent_widget)->event_handler(
+ RTGUI_OBJECT(win->last_mevent_widget),
+ event);
- /* clean last mouse event handled widget */
- win->last_mevent_widget = RT_NULL;
- }
- else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win),
- (struct rtgui_event_mouse*)event) == RT_FALSE)
- {
+ /* clean last mouse event handled widget */
+ win->last_mevent_widget = RT_NULL;
+ }
+ else if (rtgui_container_dispatch_mouse_event(RTGUI_CONTAINER(win),
+ (struct rtgui_event_mouse *)event) == RT_FALSE)
+ {
#ifndef RTGUI_USING_SMALL_SIZE
- if (RTGUI_WIDGET(object)->on_mouseclick != RT_NULL)
- {
- return RTGUI_WIDGET(object)->on_mouseclick(object, event);
- }
+ if (RTGUI_WIDGET(object)->on_mouseclick != RT_NULL)
+ {
+ return RTGUI_WIDGET(object)->on_mouseclick(object, event);
+ }
#endif
- }
- break;
+ }
+ break;
- case RTGUI_EVENT_MOUSE_MOTION:
+ case RTGUI_EVENT_MOUSE_MOTION:
#if 0
- if (rtgui_widget_dispatch_mouse_event(widget,
- (struct rtgui_event_mouse*)event) == RT_FALSE)
- {
+ 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);
- }
+ /* handle event in current widget */
+ if (widget->on_mousemotion != RT_NULL)
+ {
+ return widget->on_mousemotion(widget, event);
+ }
#endif
- }
- else return RT_TRUE;
+ }
+ else return RT_TRUE;
#endif
- break;
+ break;
- case RTGUI_EVENT_KBD:
- /* we should dispatch key event firstly */
- if (!(win->flag & RTGUI_WIN_FLAG_HANDLE_KEY))
- {
- struct rtgui_widget *widget;
- rt_bool_t res = RT_FALSE;
- /* we should dispatch the key event just once. Once entered the
- * dispatch mode, we should swtich to key handling mode. */
- win->flag |= RTGUI_WIN_FLAG_HANDLE_KEY;
+ case RTGUI_EVENT_KBD:
+ /* we should dispatch key event firstly */
+ if (!(win->flag & RTGUI_WIN_FLAG_HANDLE_KEY))
+ {
+ struct rtgui_widget *widget;
+ rt_bool_t res = RT_FALSE;
+ /* we should dispatch the key event just once. Once entered the
+ * dispatch mode, we should swtich to key handling mode. */
+ win->flag |= RTGUI_WIN_FLAG_HANDLE_KEY;
- /* dispatch the key event */
- for (widget = win->focused_widget;
- widget && !res;
- widget = widget->parent)
- {
- if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
- res = RTGUI_OBJECT(widget)->event_handler(
- RTGUI_OBJECT(widget), event);
- }
+ /* dispatch the key event */
+ for (widget = win->focused_widget;
+ widget && !res;
+ widget = widget->parent)
+ {
+ if (RTGUI_OBJECT(widget)->event_handler != RT_NULL)
+ res = RTGUI_OBJECT(widget)->event_handler(
+ RTGUI_OBJECT(widget), event);
+ }
- win->flag &= ~RTGUI_WIN_FLAG_HANDLE_KEY;
- return res;
- }
- else
- {
- /* in key handling mode(it may reach here in
- * win->focused_widget->event_handler call) */
- if (win->on_key != RT_NULL)
- return win->on_key(RTGUI_OBJECT(win), event);
- }
- break;
+ win->flag &= ~RTGUI_WIN_FLAG_HANDLE_KEY;
+ return res;
+ }
+ else
+ {
+ /* in key handling mode(it may reach here in
+ * win->focused_widget->event_handler call) */
+ if (win->on_key != RT_NULL)
+ return win->on_key(RTGUI_OBJECT(win), event);
+ }
+ break;
- case RTGUI_EVENT_COMMAND:
- if (rtgui_container_dispatch_event(RTGUI_CONTAINER(object), event) != RT_TRUE)
- {
+ case RTGUI_EVENT_COMMAND:
+ if (rtgui_container_dispatch_event(RTGUI_CONTAINER(object), event) != RT_TRUE)
+ {
#ifndef RTGUI_USING_SMALL_SIZE
- if (RTGUI_WIDGET(object)->on_command != RT_NULL)
- {
- RTGUI_WIDGET(object)->on_command(object, event);
- }
+ if (RTGUI_WIDGET(object)->on_command != RT_NULL)
+ {
+ RTGUI_WIDGET(object)->on_command(object, event);
+ }
#endif
- }
- else
+ }
+ else
return RT_TRUE;
- break;
+ break;
- default :
- return rtgui_container_event_handler(object, event);
- }
+ default :
+ return rtgui_container_event_handler(object, event);
+ }
- return RT_FALSE;
+ return RT_FALSE;
}
RTM_EXPORT(rtgui_win_event_handler);
-void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect)
+void rtgui_win_set_rect(rtgui_win_t *win, rtgui_rect_t *rect)
{
- struct rtgui_event_win_resize event;
+ struct rtgui_event_win_resize event;
- if (win == RT_NULL || rect == RT_NULL) return;
+ if (win == RT_NULL || rect == RT_NULL) return;
- RTGUI_WIDGET(win)->extent = *rect;
+ RTGUI_WIDGET(win)->extent = *rect;
- if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
- {
- /* set window resize event to server */
- RTGUI_EVENT_WIN_RESIZE_INIT(&event);
- event.wid = win;
- event.rect = *rect;
+ if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
+ {
+ /* set window resize event to server */
+ RTGUI_EVENT_WIN_RESIZE_INIT(&event);
+ event.wid = win;
+ event.rect = *rect;
- rtgui_server_post_event(&(event.parent), sizeof(struct rtgui_event_win_resize));
- }
+ rtgui_server_post_event(&(event.parent), sizeof(struct rtgui_event_win_resize));
+ }
}
RTM_EXPORT(rtgui_win_set_rect);
-void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler)
+void rtgui_win_set_onactivate(rtgui_win_t *win, rtgui_event_handler_ptr handler)
{
- if (win != RT_NULL)
- {
- win->on_activate = handler;
- }
+ if (win != RT_NULL)
+ {
+ win->on_activate = handler;
+ }
}
RTM_EXPORT(rtgui_win_set_onactivate);
-void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler)
+void rtgui_win_set_ondeactivate(rtgui_win_t *win, rtgui_event_handler_ptr handler)
{
- if (win != RT_NULL)
- {
- win->on_deactivate = handler;
- }
+ if (win != RT_NULL)
+ {
+ win->on_deactivate = handler;
+ }
}
RTM_EXPORT(rtgui_win_set_ondeactivate);
-void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler)
+void rtgui_win_set_onclose(rtgui_win_t *win, rtgui_event_handler_ptr handler)
{
- if (win != RT_NULL)
- {
- win->on_close = handler;
- }
+ if (win != RT_NULL)
+ {
+ win->on_close = handler;
+ }
}
RTM_EXPORT(rtgui_win_set_onclose);
-void rtgui_win_set_onkey(rtgui_win_t* win, rtgui_event_handler_ptr handler)
+void rtgui_win_set_onkey(rtgui_win_t *win, rtgui_event_handler_ptr handler)
{
- if (win != RT_NULL)
- {
- win->on_key = handler;
- }
+ if (win != RT_NULL)
+ {
+ win->on_key = handler;
+ }
}
RTM_EXPORT(rtgui_win_set_onkey);
-void rtgui_win_set_title(rtgui_win_t* win, const char *title)
+void rtgui_win_set_title(rtgui_win_t *win, const char *title)
{
- /* send title to server */
- if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
- {
- }
+ /* send title to server */
+ if (win->flag & RTGUI_WIN_FLAG_CONNECTED)
+ {
+ }
- /* modify in local side */
- if (win->title != RT_NULL)
- {
- rtgui_free(win->title);
- win->title = 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);
- }
+ if (title != RT_NULL)
+ {
+ win->title = rt_strdup(title);
+ }
}
RTM_EXPORT(rtgui_win_set_title);
-char* rtgui_win_get_title(rtgui_win_t* win)
+char *rtgui_win_get_title(rtgui_win_t *win)
{
- RT_ASSERT(win != RT_NULL);
+ RT_ASSERT(win != RT_NULL);
- return win->title;
+ return win->title;
}
RTM_EXPORT(rtgui_win_get_title);