diff options
| author | [email protected] <[email protected]> | 2012-07-20 12:37:56 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-07-20 12:37:56 +0000 |
| commit | 92a50c838d8ca2ae4027fd77b71db12fb52d86e3 (patch) | |
| tree | 08cb5a9273c78c36df97f48eea17eb2e1034a497 /components/rtgui/widgets/box.c | |
| parent | c2868be90d0f1f43ee13bacdb1c0f55a9fe34276 (diff) | |
sync with RTGUI c074ff2898b9e
Full log is in GitHub.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2222 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/rtgui/widgets/box.c')
| -rw-r--r-- | components/rtgui/widgets/box.c | 143 |
1 files changed, 29 insertions, 114 deletions
diff --git a/components/rtgui/widgets/box.c b/components/rtgui/widgets/box.c index 860245c0db..68ee608372 100644 --- a/components/rtgui/widgets/box.c +++ b/components/rtgui/widgets/box.c @@ -14,73 +14,37 @@ #include <rtgui/dc.h> #include <rtgui/widgets/box.h> -#ifndef RTGUI_USING_SMALL_SIZE static void _rtgui_box_constructor(rtgui_box_t *box) { /* init widget and set event handler */ - rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_box_event_handler); - - RTGUI_WIDGET(box)->flag |= RTGUI_WIDGET_FLAG_TRANSPARENT; - rtgui_object_set_event_handler(RTGUI_OBJECT(box), rtgui_box_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; } DEFINE_CLASS_TYPE(box, "box", - RTGUI_CONTAINER_TYPE, + RTGUI_OBJECT_TYPE, _rtgui_box_constructor, RT_NULL, sizeof(struct rtgui_box)); -rt_bool_t rtgui_box_event_handler(struct rtgui_object *widget, rtgui_event_t *event) -{ - struct rtgui_box* box = (struct rtgui_box*)widget; - - RT_ASSERT(box != RT_NULL); - - switch (event->type) - { - case RTGUI_EVENT_RESIZE: - /* re-layout */ - rtgui_box_layout(box); - break; - - default: - return rtgui_container_event_handler(RTGUI_OBJECT(box), event); - } - - return RT_FALSE; -} - -struct rtgui_box* rtgui_box_create(int orientation, rtgui_rect_t* rect) +struct rtgui_box* rtgui_box_create(int orientation, int border_size) { struct rtgui_box* box; - box = (struct rtgui_box*) rtgui_widget_create (RTGUI_BOX_TYPE); + box = (struct rtgui_box*) rtgui_object_create (RTGUI_BOX_TYPE); if (box != RT_NULL) { - /* set proper of control */ - rtgui_widget_set_rect(RTGUI_WIDGET(box), rect); box->orient = orientation; + box->border_size = border_size; } return box; } -void rtgui_box_append(struct rtgui_box* box, rtgui_widget_t* widget) -{ - /* put to box's children list */ - rtgui_container_add_child(RTGUI_CONTAINER(box), widget); -} - -void rtgui_box_delete(struct rtgui_box* box, rtgui_widget_t* widget) -{ - /* remove from box's children list */ - rtgui_container_remove_child(RTGUI_CONTAINER(box), widget); -} - static void rtgui_box_layout_vertical(rtgui_box_t* box) { rtgui_list_t *node; @@ -89,16 +53,18 @@ static void rtgui_box_layout_vertical(rtgui_box_t* box) rt_int32_t next_x, next_y; rt_int32_t total_height, space_height; struct rtgui_event_resize size_event; - + struct rtgui_widget *container_widget; + /* prepare the resize event */ RTGUI_EVENT_RESIZE_INIT(&size_event); + container_widget = RTGUI_WIDGET(box->container); /* find spaces */ space_count = 0; total_height = 0; space_height = 0; - rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) + 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 ++; @@ -108,16 +74,16 @@ static void rtgui_box_layout_vertical(rtgui_box_t* box) /* calculate the height for each spaces */ if (space_count != 0) { - space_height = (rtgui_rect_height(RTGUI_WIDGET(box)->extent) - total_height - (box->border_size << 1)) / space_count; + space_height = (rtgui_rect_height(container_widget->extent) - total_height - (box->border_size << 1)) / space_count; } /* init (x, y) and box width */ - next_x = RTGUI_WIDGET(box)->extent.x1 + box->border_size; - next_y = RTGUI_WIDGET(box)->extent.y1 + box->border_size; - box_width = rtgui_rect_width(RTGUI_WIDGET(box)->extent) - (box->border_size << 1); + next_x = container_widget->extent.x1 + box->border_size; + next_y = container_widget->extent.y1 + box->border_size; + box_width = rtgui_rect_width(container_widget->extent) - (box->border_size << 1); /* layout each widget */ - rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) + rtgui_list_foreach(node, &(box->container->children)) { rtgui_rect_t *rect; rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); @@ -170,7 +136,7 @@ static void rtgui_box_layout_vertical(rtgui_box_t* box) &size_event.parent); /* point to next height */ - next_y = rect->y2; + next_y = rect->y2 + box->border_size; } } @@ -182,16 +148,18 @@ static void rtgui_box_layout_horizontal(rtgui_box_t* box) rt_int32_t next_x, next_y; rt_int32_t total_width, space_width; struct rtgui_event_resize size_event; + struct rtgui_widget *container_widget; /* prepare the resize event */ RTGUI_EVENT_RESIZE_INIT(&size_event); + container_widget = RTGUI_WIDGET(box->container); /* find spaces */ space_count = 0; total_width = 0; space_width = 0; - rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) + 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 ++; @@ -201,16 +169,16 @@ static void rtgui_box_layout_horizontal(rtgui_box_t* box) if (space_count != 0) { /* calculate the height for each spaces */ - space_width = (rtgui_rect_width(RTGUI_WIDGET(box)->extent) - total_width) / space_count; + space_width = (rtgui_rect_width(container_widget->extent) - total_width) / space_count; } /* init (x, y) and box height */ - next_x = RTGUI_WIDGET(box)->extent.x1 + box->border_size; - next_y = RTGUI_WIDGET(box)->extent.y1 + box->border_size; - box_height = rtgui_rect_height(RTGUI_WIDGET(box)->extent) - (box->border_size << 1); + next_x = container_widget->extent.x1 + box->border_size; + next_y = container_widget->extent.y1 + box->border_size; + box_height = rtgui_rect_height(container_widget->extent) - (box->border_size << 1); /* layout each widget */ - rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) + rtgui_list_foreach(node, &(box->container->children)) { rtgui_rect_t *rect; rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); @@ -263,7 +231,7 @@ static void rtgui_box_layout_horizontal(rtgui_box_t* box) &size_event.parent); /* point to next width */ - next_x = rect->x2; + next_x = rect->x2 + box->border_size; } } @@ -271,6 +239,8 @@ void rtgui_box_layout(rtgui_box_t* box) { RT_ASSERT(box != RT_NULL); + if (box->container == RT_NULL) return; + if (box->orient & RTGUI_VERTICAL) { rtgui_box_layout_vertical(box); @@ -281,64 +251,9 @@ void rtgui_box_layout(rtgui_box_t* box) } /* update box and its children clip */ - if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(box))) - { - rtgui_widget_update_clip(RTGUI_WIDGET(box)); - } -} - -rt_uint32_t rtgui_box_get_width(rtgui_box_t* box) -{ - rtgui_list_t *node; - rt_uint32_t width; - - width = 0; - rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) + if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(box->container))) { - rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); - rt_uint32_t widget_width; - - widget_width = rtgui_rect_width(widget->extent); - if (box->orient & RTGUI_VERTICAL) - { - /* get the max width */ - if (width < widget_width) width = widget_width; - } - else - { - /* get the total width */ - width += widget_width; - } + rtgui_widget_update_clip(RTGUI_WIDGET(box->container)); } - - return width; -} - -rt_uint32_t rtgui_box_get_height(rtgui_box_t* box) -{ - rtgui_list_t *node; - rt_uint32_t height; - - height = 0; - rtgui_list_foreach(node, &(RTGUI_CONTAINER(box)->children)) - { - rtgui_widget_t* widget = rtgui_list_entry(node, struct rtgui_widget, sibling); - rt_uint32_t widget_height; - - widget_height = rtgui_rect_height(widget->extent); - if (box->orient & RTGUI_HORIZONTAL) - { - /* get the max height */ - if (height < widget_height) height = widget_height; - } - else - { - /* get the total height */ - height += widget_height; - } - } - - return height; } -#endif |
