mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-29 18:48:09 +08:00
add widget_on_with_tag/wuidget_off_by_tag
This commit is contained in:
parent
da97174117
commit
aac47ce517
@ -2,6 +2,7 @@
|
||||
|
||||
* 2019/10/23
|
||||
* 修改clone出来的edit的显示问题。
|
||||
* 增加widget\_on\_with\_tag和widget\_off\_by\_tag,方便一次注销多个同类事件。
|
||||
|
||||
* 2019/10/19
|
||||
* 完善主题切换功能。
|
||||
|
@ -932,13 +932,18 @@ ret_t widget_dispatch(widget_t* widget, event_t* e) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t widget_on(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx) {
|
||||
int32_t widget_on_with_tag(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx,
|
||||
uint32_t tag) {
|
||||
return_value_if_fail(widget != NULL && on_event != NULL, RET_BAD_PARAMS);
|
||||
if (widget->emitter == NULL) {
|
||||
widget->emitter = emitter_create();
|
||||
}
|
||||
|
||||
return emitter_on(widget->emitter, type, on_event, ctx);
|
||||
return emitter_on_with_tag(widget->emitter, type, on_event, ctx, tag);
|
||||
}
|
||||
|
||||
int32_t widget_on(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx) {
|
||||
return widget_on_with_tag(widget, type, on_event, ctx, 0);
|
||||
}
|
||||
|
||||
int32_t widget_child_on(widget_t* widget, const char* name, uint32_t type, event_func_t on_event,
|
||||
@ -953,6 +958,13 @@ ret_t widget_off(widget_t* widget, int32_t id) {
|
||||
return emitter_off(widget->emitter, id);
|
||||
}
|
||||
|
||||
ret_t widget_off_by_tag(widget_t* widget, int32_t tag) {
|
||||
return_value_if_fail(widget != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(widget->emitter != NULL, RET_BAD_PARAMS);
|
||||
|
||||
return emitter_off_by_tag(widget->emitter, tag);
|
||||
}
|
||||
|
||||
ret_t widget_off_by_func(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx) {
|
||||
return_value_if_fail(widget != NULL && on_event != NULL, RET_BAD_PARAMS);
|
||||
return_value_if_fail(widget->emitter != NULL, RET_BAD_PARAMS);
|
||||
|
@ -1143,6 +1143,24 @@ ret_t widget_set_sensitive(widget_t* widget, bool_t sensitive);
|
||||
*/
|
||||
int32_t widget_on(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx);
|
||||
|
||||
/**
|
||||
* @method widget_on_with_tag
|
||||
* 注册指定tag的事件处理函数。
|
||||
*
|
||||
* > 注册时指定一个tag,可用widget\_off\_by\_tag注销相同tag的事件处理函数。
|
||||
*
|
||||
* @annotation ["scriptable:custom"]
|
||||
* @param {widget_t*} widget 控件对象。
|
||||
* @param {uint32_t} type 事件类型。
|
||||
* @param {event_func_t} on_event 事件处理函数。
|
||||
* @param {void*} ctx 事件处理函数上下文。
|
||||
* @param {uint32_t} tag tag。
|
||||
*
|
||||
* @return {int32_t} 返回id,用于widget_off。
|
||||
*/
|
||||
int32_t widget_on_with_tag(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx,
|
||||
uint32_t tag);
|
||||
|
||||
/**
|
||||
* @method widget_off
|
||||
* 注销指定事件的处理函数。
|
||||
@ -1171,8 +1189,7 @@ int32_t widget_child_on(widget_t* widget, const char* name, uint32_t type, event
|
||||
|
||||
/**
|
||||
* @method widget_off_by_func
|
||||
* 注销指定事件的处理函数。
|
||||
* 仅用于辅助实现脚本绑定。
|
||||
* 注销指定函数的事件处理函数。
|
||||
* @param {widget_t*} widget 控件对象。
|
||||
* @param {uint32_t} type 事件类型。
|
||||
* @param {event_func_t} on_event 事件处理函数。
|
||||
@ -1182,6 +1199,16 @@ int32_t widget_child_on(widget_t* widget, const char* name, uint32_t type, event
|
||||
*/
|
||||
ret_t widget_off_by_func(widget_t* widget, uint32_t type, event_func_t on_event, void* ctx);
|
||||
|
||||
/**
|
||||
* @method widget_off_by_tag
|
||||
* 注销指定tag的事件处理函数。
|
||||
* @param {widget_t*} widget 控件对象。
|
||||
* @param {uint32_t} tag tag。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t widget_off_by_tag(widget_t* widget, uint32_t tag);
|
||||
|
||||
/**
|
||||
* @method widget_invalidate
|
||||
* 请求重绘指定的区域,如果widget->dirty已经为TRUE,直接返回。
|
||||
|
@ -190,7 +190,7 @@ TEST(ComboBox, clone) {
|
||||
|
||||
w2 = widget_clone(w1, NULL);
|
||||
ASSERT_EQ(widget_equal(w1, w2), TRUE);
|
||||
|
||||
|
||||
widget_destroy(w1);
|
||||
widget_destroy(w2);
|
||||
}
|
||||
|
@ -199,3 +199,30 @@ TEST(Emitter, remove_item) {
|
||||
|
||||
emitter_destroy(emitter);
|
||||
}
|
||||
|
||||
TEST(Emitter, off_by_tag) {
|
||||
uint32_t type = 12;
|
||||
emitter_t* emitter = emitter_create();
|
||||
|
||||
emitter_on_with_tag(emitter, type, on_remove, NULL, 1);
|
||||
emitter_on_with_tag(emitter, type, on_remove, NULL, 1);
|
||||
|
||||
emitter_on_with_tag(emitter, type, on_remove, NULL, 2);
|
||||
emitter_on_with_tag(emitter, type, on_remove, NULL, 3);
|
||||
|
||||
emitter_on_with_tag(emitter, type, on_remove, NULL, 1);
|
||||
emitter_on_with_tag(emitter, type, on_remove, NULL, 1);
|
||||
|
||||
ASSERT_EQ(emitter_size(emitter), 6);
|
||||
|
||||
ASSERT_EQ(emitter_off_by_tag(emitter, 1), RET_OK);
|
||||
ASSERT_EQ(emitter_size(emitter), 2);
|
||||
|
||||
ASSERT_EQ(emitter_off_by_tag(emitter, 3), RET_OK);
|
||||
ASSERT_EQ(emitter_size(emitter), 1);
|
||||
|
||||
ASSERT_EQ(emitter_off_by_tag(emitter, 2), RET_OK);
|
||||
ASSERT_EQ(emitter_size(emitter), 0);
|
||||
|
||||
emitter_destroy(emitter);
|
||||
}
|
||||
|
@ -1103,3 +1103,30 @@ TEST(Widget, feedback1) {
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
||||
|
||||
TEST(Widget, off) {
|
||||
widget_t* w = button_create(NULL, 0, 0, 0, 0);
|
||||
|
||||
ASSERT_EQ(widget_on(w, EVT_MOVE, widget_log_events, NULL) > 0, TRUE);
|
||||
ASSERT_EQ(emitter_size(w->emitter), 1);
|
||||
ASSERT_EQ(widget_off_by_func(w, EVT_MOVE, widget_log_events, NULL), RET_OK);
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
||||
|
||||
TEST(Widget, off_by_tag) {
|
||||
widget_t* w = button_create(NULL, 0, 0, 0, 0);
|
||||
|
||||
ASSERT_EQ(widget_on_with_tag(w, EVT_MOVE, widget_log_events, NULL, 1) > 0, TRUE);
|
||||
ASSERT_EQ(widget_on_with_tag(w, EVT_MOVE, widget_log_events, NULL, 1) > 0, TRUE);
|
||||
ASSERT_EQ(widget_on_with_tag(w, EVT_MOVE, widget_log_events, NULL, 1) > 0, TRUE);
|
||||
ASSERT_EQ(widget_on_with_tag(w, EVT_MOVE, widget_log_events, NULL, 2) > 0, TRUE);
|
||||
ASSERT_EQ(widget_on_with_tag(w, EVT_MOVE, widget_log_events, NULL, 2) > 0, TRUE);
|
||||
|
||||
ASSERT_EQ(emitter_size(w->emitter), 5);
|
||||
|
||||
ASSERT_EQ(widget_off_by_tag(w, 1), RET_OK);
|
||||
ASSERT_EQ(emitter_size(w->emitter), 2);
|
||||
|
||||
widget_destroy(w);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user