diff options
| author | [email protected] <[email protected]> | 2012-12-14 03:34:24 +0000 |
|---|---|---|
| committer | [email protected] <[email protected]> | 2012-12-14 03:34:24 +0000 |
| commit | 601eb6fe70aa10e4bf62f7a68915dc1ad7b37553 (patch) | |
| tree | 129551544b46d6005dfdab4d4d9b09648114df15 /components/rtgui/widgets/button.c | |
| parent | 5927bf0ac16df159910058ceffc798d07cbdc973 (diff) | |
sync RTGUI with github(https://github.com/RT-Thread/RTGUI) c4b8c0ac2a3de482357b88d584931831aed7c8ae
As always, full log is in GitHub.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2481 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'components/rtgui/widgets/button.c')
| -rw-r--r-- | components/rtgui/widgets/button.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/components/rtgui/widgets/button.c b/components/rtgui/widgets/button.c index 6f1f7984f3..ca15acb89a 100644 --- a/components/rtgui/widgets/button.c +++ b/components/rtgui/widgets/button.c @@ -156,10 +156,24 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object *object, struct rtgui_e { /* set the last mouse event handled widget */ struct rtgui_win *win; + /* need callback */ + rt_bool_t need_cb = RT_FALSE; win = RTGUI_WIN(RTGUI_WIDGET(btn)->toplevel); win->last_mevent_widget = RTGUI_WIDGET(btn); + /* we need to decide whether the callback will be invoked + * before the flag has changed. Moreover, we cannot invoke + * it directly here, because the button might be destroyed + * in the callback. If that happens, program will crash on + * the following code. We need to make sure that the + * callbacks are invoke at the very last step. */ + if ((btn->flag & RTGUI_BUTTON_FLAG_PRESS) + && (emouse->button & RTGUI_MOUSE_BUTTON_UP)) + { + need_cb = RT_TRUE; + } + /* it's a normal button */ if (emouse->button & RTGUI_MOUSE_BUTTON_DOWN) { @@ -173,20 +187,16 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object *object, struct rtgui_e /* draw button */ rtgui_theme_draw_button(btn); + if (need_cb) + { + if (btn->on_button) + 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); + if (widget->on_mouseclick) + 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); } } - } return RT_TRUE; |
