diff options
Diffstat (limited to 'components/rtgui/widgets/container.c')
| -rw-r--r-- | components/rtgui/widgets/container.c | 55 |
1 files changed, 19 insertions, 36 deletions
diff --git a/components/rtgui/widgets/container.c b/components/rtgui/widgets/container.c index fc23030429..f5c954ddcf 100644 --- a/components/rtgui/widgets/container.c +++ b/components/rtgui/widgets/container.c @@ -14,7 +14,7 @@ */ #include <rtgui/dc.h> #include <rtgui/rtgui_system.h> -#include <rtgui/rtgui_application.h> +#include <rtgui/rtgui_app.h> #include <rtgui/widgets/container.h> #include <rtgui/widgets/window.h> @@ -25,26 +25,17 @@ static void _rtgui_container_constructor(rtgui_container_t *container) rtgui_container_event_handler); rtgui_list_init(&(container->children)); + container->layout_box = RT_NULL; - /* container is used to 'contain'(show) widgets and dispatch events to - * them, not interact with user. So no need to grab focus. If we did it, - * some widget inherited from container(e.g. notebook) will grab the focus - * annoyingly. - * - * For example, a focusable notebook N has a widget W. When the user press - * W, N will gain the focus and W will lose it at first. Then N will set - * focus to W because it is W that eventually interact with people. N will - * yield focus and W will gain the focus again. This loop will make W - * repaint twice every time user press it. - * - * Just eliminate it. - */ - 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); + + if (container->layout_box != RT_NULL) + rtgui_object_destroy(RTGUI_OBJECT(container->layout_box)); } static void _rtgui_container_update_toplevel(rtgui_container_t* container) @@ -152,15 +143,6 @@ rt_bool_t rtgui_container_event_handler(struct rtgui_object* object, struct rtgu break; case RTGUI_EVENT_KBD: - /* let parent to handle keyboard event */ - if (widget->parent != RT_NULL && - widget->parent != RTGUI_WIDGET(widget->toplevel) && - RTGUI_OBJECT(widget->parent)->event_handler) - { - return RTGUI_OBJECT(widget->parent)->event_handler( - RTGUI_OBJECT(widget->parent), - event); - } break; case RTGUI_EVENT_MOUSE_BUTTON: @@ -169,6 +151,14 @@ rt_bool_t rtgui_container_event_handler(struct rtgui_object* object, struct rtgu 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); @@ -193,7 +183,6 @@ rtgui_container_t* rtgui_container_create(void) void rtgui_container_destroy(rtgui_container_t* container) { - rtgui_container_hide(container); rtgui_widget_destroy(RTGUI_WIDGET(container)); } @@ -296,26 +285,20 @@ rtgui_widget_t* rtgui_container_get_first_child(rtgui_container_t* container) return child; } -#ifndef RTGUI_USING_SMALL_SIZE void rtgui_container_set_box(rtgui_container_t* container, struct rtgui_box* box) { if (container == RT_NULL || box == RT_NULL) return; - rtgui_container_add_child(RTGUI_CONTAINER(container), RTGUI_WIDGET(box)); - rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(container)->extent)); + container->layout_box = box; + box->container = container; } -#endif -void rtgui_container_hide(rtgui_container_t* container) +void rtgui_container_layout(struct rtgui_container* container) { - if (container == RT_NULL) + if (container == RT_NULL || container->layout_box == RT_NULL) return; - if (RTGUI_WIDGET(container)->parent == RT_NULL) - { - RTGUI_WIDGET_HIDE(RTGUI_WIDGET(container)); - return; - } + rtgui_box_layout(container->layout_box); } |
