summaryrefslogtreecommitdiff
path: root/components/rtgui/widgets/widget.c
diff options
context:
space:
mode:
authorbernard.xiong <[email protected]>2010-08-10 07:25:08 +0000
committerbernard.xiong <[email protected]>2010-08-10 07:25:08 +0000
commitaa35bccfee9008d03f8a1f7de79655f409a39228 (patch)
tree26563564ceec9f384a1721c156fad18176c7e45f /components/rtgui/widgets/widget.c
parent50eb24dfe7675d3606c33aefd008f0ad13ee6c3e (diff)
fix view focus bug.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@840 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/rtgui/widgets/widget.c')
-rw-r--r--components/rtgui/widgets/widget.c51
1 files changed, 34 insertions, 17 deletions
diff --git a/components/rtgui/widgets/widget.c b/components/rtgui/widgets/widget.c
index e046087287..81ee2d797b 100644
--- a/components/rtgui/widgets/widget.c
+++ b/components/rtgui/widgets/widget.c
@@ -250,37 +250,31 @@ void rtgui_widget_set_oncommand(rtgui_widget_t* widget, rtgui_event_handler_ptr
*/
void rtgui_widget_focus(rtgui_widget_t *widget)
{
- rtgui_widget_t *focused;
rtgui_container_t *parent;
RT_ASSERT(widget != RT_NULL);
- if (!widget->parent || !RTGUI_WIDGET_IS_FOCUSABLE(widget) || !RTGUI_WIDGET_IS_ENABLE(widget))
+ if (!widget->parent || !widget->toplevel) return;
+ if (!RTGUI_WIDGET_IS_FOCUSABLE(widget) || !RTGUI_WIDGET_IS_ENABLE(widget))
return;
/* set widget as focused */
widget->flag |= RTGUI_WIDGET_FLAG_FOCUS;
- /* get parent container */
- parent = RTGUI_CONTAINER(widget->parent);
-
- /* get old focused widget */
- focused = parent->focused;
- if (focused == widget) return ; /* it's the same focused widget */
+ /* get root parent container and old focused widget */
+ parent = RTGUI_CONTAINER(widget->toplevel);
+ if (parent->focused == widget) return ; /* it's the same focused widget */
- if (focused != RT_NULL)
- rtgui_widget_unfocus(focused);
+ /* unfocused the old widget */
+ if (parent->focused != RT_NULL) rtgui_widget_unfocus(parent->focused);
/* set widget as focused widget in parent link */
- parent->focused = widget;
- while (RTGUI_WIDGET(parent)->parent != RT_NULL)
+ parent = RTGUI_CONTAINER(widget->parent);
+ do
{
- parent = RTGUI_CONTAINER(RTGUI_WIDGET(parent)->parent);
parent->focused = widget;
-
- /* if the parent is hide, break it */
- if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(parent))) break;
- }
+ parent = RTGUI_CONTAINER(RTGUI_WIDGET(parent)->parent);
+ } while ((parent != RT_NULL) && !RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(parent)));
/* invoke on focus in call back */
if (widget->on_focus_in != RT_NULL)
@@ -559,3 +553,26 @@ rtgui_widget_t* rtgui_widget_get_prev_sibling(rtgui_widget_t* widget)
return sibling;
}
+
+#ifdef RTGUI_WIDGET_DEBUG
+#include <rtgui/widgets/label.h>
+#include <rtgui/widgets/button.h>
+void rtgui_widget_dump(rtgui_widget_t* widget)
+{
+ struct rtgui_object *obj;
+
+ obj = RTGUI_OBJECT(widget);
+ rt_kprintf("widget type: %s ", obj->type->name);
+
+ if (RTGUI_IS_VIEW(widget) == RT_TRUE)
+ rt_kprintf(":%s ", RTGUI_VIEW(widget)->title);
+ if (RTGUI_IS_WIN(widget) == RT_TRUE)
+ rt_kprintf(":%s ", RTGUI_WIN(widget)->title);
+ 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));
+}
+#endif