diff --git a/components/rtgui/include/rtgui/rtgui.h b/components/rtgui/include/rtgui/rtgui.h index b473b9d794f5326c66a669ed5283e0027c9fffa3..d35e17ec5eb1b48a5d7d7d889726abf6a0893f13 100644 --- a/components/rtgui/include/rtgui/rtgui.h +++ b/components/rtgui/include/rtgui/rtgui.h @@ -31,7 +31,7 @@ struct rtgui_font; typedef struct rtgui_win rtgui_win_t; typedef struct rtgui_workbench rtgui_workbench_t; typedef rt_bool_t (*rtgui_event_handler_ptr)(struct rtgui_object* widget, struct rtgui_event* event); -typedef void (*rtgui_onbutton_func_t)(struct rtgui_widget* widget, struct rtgui_event* event); +typedef void (*rtgui_onbutton_func_t)(struct rtgui_object* object, struct rtgui_event* event); struct rtgui_point { diff --git a/components/rtgui/include/rtgui/rtgui_config.h b/components/rtgui/include/rtgui/rtgui_config.h index f1dae17ca84a3e3b502b9485d2d98eca0f9e6e9f..33ae2ee061f7a92f0c6e38bdca22ec906d305cee 100644 --- a/components/rtgui/include/rtgui/rtgui_config.h +++ b/components/rtgui/include/rtgui/rtgui_config.h @@ -77,5 +77,5 @@ //#define RTGUI_USING_DESKTOP_WINDOW #define RTGUI_EVENT_DEBUG - +#undef RTGUI_USING_SMALL_SIZE #endif diff --git a/components/rtgui/include/rtgui/widgets/box.h b/components/rtgui/include/rtgui/widgets/box.h index 0e0b814e8bc4a3ef0d979432a1fda7728054dfc8..370b9820d3ac01ea28f84c1c382d3077a24beb8e 100644 --- a/components/rtgui/include/rtgui/widgets/box.h +++ b/components/rtgui/include/rtgui/widgets/box.h @@ -43,7 +43,7 @@ typedef struct rtgui_box rtgui_box_t; struct rtgui_box* rtgui_box_create(int orientation, rtgui_rect_t* rect); void rtgui_box_destroy(struct rtgui_box* box); -rt_bool_t rtgui_box_event_handler(rtgui_widget_t* widget, rtgui_event_t* event); +rt_bool_t rtgui_box_event_handler(struct rtgui_object* object, rtgui_event_t* event); void rtgui_box_append(rtgui_box_t* box, rtgui_widget_t* widget); void rtgui_box_layout(rtgui_box_t* box); diff --git a/components/rtgui/include/rtgui/widgets/button.h b/components/rtgui/include/rtgui/widgets/button.h index 0d7678d3587de8f7758f681bbb14c0f333f9effa..b149c5a2a27b62450429b40ed596729cbacf005e 100644 --- a/components/rtgui/include/rtgui/widgets/button.h +++ b/components/rtgui/include/rtgui/widgets/button.h @@ -57,7 +57,7 @@ struct rtgui_button rtgui_image_t *pressed_image, *unpressed_image; /* click button event handler */ - void (*on_button)(struct rtgui_widget* widget, rtgui_event_t *event); + rtgui_onbutton_func_t on_button; }; typedef struct rtgui_button rtgui_button_t; diff --git a/components/rtgui/include/rtgui/widgets/checkbox.h b/components/rtgui/include/rtgui/widgets/checkbox.h index bf226e061eb77902625e6e9c0ba47bd6a3b877c0..c23b5d79a1e146478ba21b7eb6133cb2331c1ba9 100644 --- a/components/rtgui/include/rtgui/widgets/checkbox.h +++ b/components/rtgui/include/rtgui/widgets/checkbox.h @@ -26,7 +26,7 @@ struct rtgui_checkbox rt_uint8_t status_down; /* click button event handler */ - void (*on_button)(struct rtgui_widget* widget, rtgui_event_t *event); + rtgui_onbutton_func_t on_button; }; typedef struct rtgui_checkbox rtgui_checkbox_t; diff --git a/components/rtgui/widgets/button.c b/components/rtgui/widgets/button.c index a10d04ebbff2575d0c80d6e7f87a8d4b3ffab372..aab1333b56d65c2f35e3416127835444875c397a 100644 --- a/components/rtgui/widgets/button.c +++ b/components/rtgui/widgets/button.c @@ -95,7 +95,7 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object* object, struct rtgui_e if ((btn->flag & RTGUI_BUTTON_FLAG_PRESS) && (btn->on_button != RT_NULL)) { /* call on button handler */ - btn->on_button(widget, event); + btn->on_button(RTGUI_OBJECT(widget), event); } } } @@ -137,14 +137,14 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object* object, struct rtgui_e if (btn->on_button != RT_NULL) { /* call on button handler */ - btn->on_button(widget, event); + 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(widget, event); + return widget->on_mouseclick(RTGUI_OBJECT(widget), event); #endif } } @@ -175,13 +175,13 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_object* object, struct rtgui_e /* invokes call back */ if (widget->on_mouseclick != RT_NULL && emouse->button & RTGUI_MOUSE_BUTTON_UP) - return widget->on_mouseclick(widget, event); + 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(widget, event); + btn->on_button(RTGUI_OBJECT(widget), event); } } diff --git a/components/rtgui/widgets/checkbox.c b/components/rtgui/widgets/checkbox.c index 78c3cd97c8e4deb136abe7fc125220e864c57784..6a682903d02b06d9b23b059a02b68fcb68eee4ef 100644 --- a/components/rtgui/widgets/checkbox.c +++ b/components/rtgui/widgets/checkbox.c @@ -46,7 +46,7 @@ rt_bool_t rtgui_checkbox_event_handler(struct rtgui_object* object, struct rtgui #ifndef RTGUI_USING_SMALL_SIZE if (widget->on_draw != RT_NULL) { - return widget->on_draw(widget, event); + return widget->on_draw(RTGUI_OBJECT(widget), event); } else #endif @@ -83,12 +83,12 @@ rt_bool_t rtgui_checkbox_event_handler(struct rtgui_object* object, struct rtgui /* call user callback */ if (widget->on_mouseclick != RT_NULL) { - return widget->on_mouseclick(widget, event); + return widget->on_mouseclick(RTGUI_OBJECT(widget), event); } #endif if (box->on_button != RT_NULL) { - box->on_button(widget, event); + box->on_button(RTGUI_OBJECT(widget), event); return RT_TRUE; } } diff --git a/components/rtgui/widgets/combobox.c b/components/rtgui/widgets/combobox.c index 282a975f08185d310090a4970f46eb520684a33f..5b3010677ca32c0832aeb068ae3a56aea356ac67 100644 --- a/components/rtgui/widgets/combobox.c +++ b/components/rtgui/widgets/combobox.c @@ -194,9 +194,7 @@ static rt_bool_t rtgui_combobox_onmouse_button(struct rtgui_combobox* box, struc rt_bool_t rtgui_combobox_event_handler(struct rtgui_object* object, struct rtgui_event* event) { struct rtgui_combobox *box; - - RT_ASSERT(object != RT_NULL); - RT_ASSERT(event != RT_NULL); + RTGUI_WIDGET_EVENT_HANDLER_PREPARE box = RTGUI_COMBOBOX(object); @@ -204,7 +202,8 @@ rt_bool_t rtgui_combobox_event_handler(struct rtgui_object* object, struct rtgui { case RTGUI_EVENT_PAINT: #ifndef RTGUI_USING_SMALL_SIZE - if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); + if (widget->on_draw != RT_NULL) + widget->on_draw(RTGUI_OBJECT(widget), event); else #endif rtgui_combobox_ondraw(box); diff --git a/components/rtgui/widgets/iconbox.c b/components/rtgui/widgets/iconbox.c index 1ba74e3ce258f15917bc74004e11ab10fe1d9dd8..03db07bd832c81c53e3485b3dece870c59aee819 100644 --- a/components/rtgui/widgets/iconbox.c +++ b/components/rtgui/widgets/iconbox.c @@ -49,9 +49,7 @@ DEFINE_CLASS_TYPE(iconbox, "iconbox", rt_bool_t rtgui_iconbox_event_handler(struct rtgui_object* object, struct rtgui_event* event) { struct rtgui_iconbox* iconbox; - - RT_ASSERT(object != RT_NULL); - RT_ASSERT(event != RT_NULL); + RTGUI_WIDGET_EVENT_HANDLER_PREPARE iconbox = RTGUI_ICONBOX(object); @@ -59,7 +57,8 @@ rt_bool_t rtgui_iconbox_event_handler(struct rtgui_object* object, struct rtgui_ { case RTGUI_EVENT_PAINT: #ifndef RTGUI_USING_SMALL_SIZE - if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); + if (widget->on_draw != RT_NULL) + widget->on_draw(RTGUI_OBJECT(widget), event); else #endif { diff --git a/components/rtgui/widgets/radiobox.c b/components/rtgui/widgets/radiobox.c index b886c584c42c0b9e95a3141458df6a53c9363536..b1def7af01b1c8357635f4fe2a2301895a6ec858 100644 --- a/components/rtgui/widgets/radiobox.c +++ b/components/rtgui/widgets/radiobox.c @@ -86,7 +86,8 @@ rt_bool_t rtgui_radiobox_event_handler(struct rtgui_object* object, struct rtgui { case RTGUI_EVENT_PAINT: #ifndef RTGUI_USING_SMALL_SIZE - if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); + if (widget->on_draw != RT_NULL) + widget->on_draw(RTGUI_OBJECT(widget), event); else #endif { @@ -99,7 +100,8 @@ rt_bool_t rtgui_radiobox_event_handler(struct rtgui_object* object, struct rtgui if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(radiobox))) return RT_FALSE; #ifndef RTGUI_USING_SMALL_SIZE - if (widget->on_key != RT_NULL) widget->on_key(widget, event); + if (widget->on_key != RT_NULL) + widget->on_key(RTGUI_OBJECT(widget), event); else #endif { @@ -140,7 +142,8 @@ rt_bool_t rtgui_radiobox_event_handler(struct rtgui_object* object, struct rtgui case RTGUI_EVENT_MOUSE_BUTTON: #ifndef RTGUI_USING_SMALL_SIZE - if (widget->on_mouseclick != RT_NULL) widget->on_mouseclick(widget, event); + if (widget->on_mouseclick != RT_NULL) + widget->on_mouseclick(RTGUI_OBJECT(widget), event); else #endif { diff --git a/components/rtgui/widgets/scrollbar.c b/components/rtgui/widgets/scrollbar.c index 58a3017b3cc9582d33c0faad06ad322d061e7645..257591a028d5e572a178dcaefc8383db813d98d6 100644 --- a/components/rtgui/widgets/scrollbar.c +++ b/components/rtgui/widgets/scrollbar.c @@ -274,7 +274,8 @@ rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_object *object, { case RTGUI_EVENT_PAINT: #ifndef RTGUI_USING_SMALL_SIZE - if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); + if (widget->on_draw != RT_NULL) + widget->on_draw(RTGUI_OBJECT(widget), event); else #endif { @@ -289,7 +290,7 @@ rt_bool_t rtgui_scrollbar_event_handler(struct rtgui_object *object, #ifndef RTGUI_USING_SMALL_SIZE if (widget->on_mouseclick != RT_NULL) { - widget->on_mouseclick(widget, event); + widget->on_mouseclick(RTGUI_OBJECT(widget), event); } else #endif diff --git a/components/rtgui/widgets/slider.c b/components/rtgui/widgets/slider.c index 30d29d84f90ab730025a30688077cb23af896c1d..ca71fdfaad906fcdc64d54ee16e3edc387303f1b 100644 --- a/components/rtgui/widgets/slider.c +++ b/components/rtgui/widgets/slider.c @@ -153,7 +153,8 @@ rt_bool_t rtgui_slider_event_handler(struct rtgui_object *object, struct rtgui_e { case RTGUI_EVENT_PAINT: #ifndef RTGUI_USING_SMALL_SIZE - if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); + if (widget->on_draw != RT_NULL) + widget->on_draw(RTGUI_OBJECT(widget), event); else #endif { @@ -166,7 +167,8 @@ rt_bool_t rtgui_slider_event_handler(struct rtgui_object *object, struct rtgui_e 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) widget->on_key(widget, event); + if (widget->on_key != RT_NULL) + widget->on_key(RTGUI_OBJECT(widget), event); else #endif { @@ -178,7 +180,8 @@ rt_bool_t rtgui_slider_event_handler(struct rtgui_object *object, struct rtgui_e 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(widget, event); + if (widget->on_mouseclick != RT_NULL) + widget->on_mouseclick(RTGUI_OBJECT(widget), event); else #endif { diff --git a/components/rtgui/widgets/staticline.c b/components/rtgui/widgets/staticline.c index 19a1caed49b05fad7ce7770c690b9aa176ca3474..10bdd8bad8acff5607d30889720df250a87e5b61 100644 --- a/components/rtgui/widgets/staticline.c +++ b/components/rtgui/widgets/staticline.c @@ -30,7 +30,8 @@ rt_bool_t rtgui_staticline_event_handler(struct rtgui_object* object, struct rtg { case RTGUI_EVENT_PAINT: #ifndef RTGUI_USING_SMALL_SIZE - if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); + if (widget->on_draw != RT_NULL) + widget->on_draw(RTGUI_OBJECT(widget), event); else #endif rtgui_theme_draw_staticline(staticline); diff --git a/components/rtgui/widgets/textbox.c b/components/rtgui/widgets/textbox.c index 15f2bd44ef1c3e8a437d1f6a0bf382ec9b52010f..a28b3ec5f9f680c3b572a855905bca12ee73ddf5 100644 --- a/components/rtgui/widgets/textbox.c +++ b/components/rtgui/widgets/textbox.c @@ -264,8 +264,9 @@ rt_bool_t rtgui_textbox_event_handler(struct rtgui_object* object, struct rtgui_ { case RTGUI_EVENT_PAINT: #ifndef RTGUI_USING_SMALL_SIZE - if (widget->on_draw != RT_NULL) widget->on_draw(widget, event); - else + if (widget->on_draw != RT_NULL) + widget->on_draw(RTGUI_OBJECT(widget), event); + else #endif rtgui_theme_draw_textbox(box); break; @@ -274,8 +275,9 @@ rt_bool_t rtgui_textbox_event_handler(struct rtgui_object* object, struct rtgui_ 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(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; @@ -284,7 +286,8 @@ rt_bool_t rtgui_textbox_event_handler(struct rtgui_object* object, struct rtgui_ 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) widget->on_key(widget, event); + if (widget->on_key != RT_NULL) + widget->on_key(RTGUI_OBJECT(widget), event); else #endif rtgui_textbox_onkey(box, (struct rtgui_event_kbd*)event); diff --git a/examples/gui/demo_view.c b/examples/gui/demo_view.c index d19ee9ac3df97495e9704f45786149f07de629c9..b1c1d657aa49c20f3e0753da265eddfe6f509921 100644 --- a/examples/gui/demo_view.c +++ b/examples/gui/demo_view.c @@ -130,6 +130,7 @@ void demo_view_get_logic_rect(rtgui_container_t* container, rtgui_rect_t *rect) /* 当是标准版本时,这个函数用于返回自动布局引擎box控件 */ #ifndef RTGUI_USING_SMALL_SIZE +#include struct rtgui_box* demo_view_create_box(struct rtgui_container *container, int orient) { rtgui_rect_t rect;