|
41 | 41 | #include <LCUI/cursor.h>
|
42 | 42 | #include <LCUI/thread.h>
|
43 | 43 |
|
| 44 | +/* clang-format off */ |
| 45 | + |
44 | 46 | #define DBLCLICK_INTERVAL 500
|
45 | 47 |
|
46 | 48 | typedef struct TouchCapturerRec_ {
|
@@ -92,15 +94,17 @@ static struct LCUIWidgetEvnetModule {
|
92 | 94 | LinkedList touch_capturers; /**< 触点占用记录 */
|
93 | 95 | LCUI_Widget targets[WST_TOTAL]; /**< 相关的部件 */
|
94 | 96 | LinkedList events; /**< 已绑定的事件 */
|
95 |
| - LinkedList event_mappings; /**< 事件标识号和名称映射记录列表 */ |
96 |
| - RBTree event_records; /**< 当前正执行的事件的记录 */ |
97 |
| - RBTree event_names; /**< 事件名称表,以标识号作为索引 */ |
98 |
| - Dict *event_ids; /**< 事件标识号表,以事件名称作为索引 */ |
99 |
| - int base_event_id; /**< 事件标识号计数器 */ |
100 |
| - ClickRecord click; /**< 上次鼠标点击记录 */ |
101 |
| - LCUI_Mutex mutex; /**< 互斥锁 */ |
| 97 | + LinkedList event_mappings; /**< 事件标识号和名称映射记录列表 */ |
| 98 | + RBTree event_records; /**< 当前正执行的事件的记录 */ |
| 99 | + RBTree event_names; /**< 事件名称表,以标识号作为索引 */ |
| 100 | + Dict *event_ids; /**< 事件标识号表,以事件名称作为索引 */ |
| 101 | + int base_event_id; /**< 事件标识号计数器 */ |
| 102 | + ClickRecord click; /**< 上次鼠标点击记录 */ |
| 103 | + LCUI_Mutex mutex; /**< 互斥锁 */ |
102 | 104 | } self;
|
103 | 105 |
|
| 106 | +/* clang-format on */ |
| 107 | + |
104 | 108 | static void DestroyEventMapping(void *data)
|
105 | 109 | {
|
106 | 110 | EventMapping mapping = data;
|
@@ -168,6 +172,23 @@ static void DestroyWidgetEventHandler(void *arg)
|
168 | 172 | free(handler);
|
169 | 173 | }
|
170 | 174 |
|
| 175 | +static int GetEventId(const char *event_name) |
| 176 | +{ |
| 177 | + int id = LCUIWidget_GetEventId(event_name); |
| 178 | + if (id < 0) { |
| 179 | + id = LCUIWidget_AllocEventId(); |
| 180 | + LCUIWidget_SetEventName(id, event_name); |
| 181 | + } |
| 182 | + return id; |
| 183 | +} |
| 184 | + |
| 185 | +void LCUI_InitWidgetEvent(LCUI_WidgetEvent e, const char *name) |
| 186 | +{ |
| 187 | + e->type = GetEventId(name); |
| 188 | + e->cancel_bubble = FALSE; |
| 189 | + e->data = NULL; |
| 190 | +} |
| 191 | + |
171 | 192 | /**
|
172 | 193 | * 添加事件记录
|
173 | 194 | * 记录当前待处理的事件和目标部件,方便在部件被销毁时清除待处理的事件
|
@@ -422,11 +443,8 @@ int Widget_BindEvent(LCUI_Widget widget, const char *event_name,
|
422 | 443 | LCUI_WidgetEventFunc func, void *data,
|
423 | 444 | void(*destroy_data)(void *))
|
424 | 445 | {
|
425 |
| - int id = LCUIWidget_GetEventId(event_name); |
426 |
| - if (id < 0) { |
427 |
| - return -1; |
428 |
| - } |
429 |
| - return Widget_BindEventById(widget, id, func, data, destroy_data); |
| 446 | + return Widget_BindEventById(widget, GetEventId(event_name), |
| 447 | + func, data, destroy_data); |
430 | 448 | }
|
431 | 449 |
|
432 | 450 | static int CompareEventHandlerKey(void *key, void *func_data)
|
@@ -459,11 +477,7 @@ int Widget_UnbindEventByHandlerId(LCUI_Widget widget, int handler_id)
|
459 | 477 | int Widget_UnbindEvent(LCUI_Widget widget, const char *event_name,
|
460 | 478 | LCUI_WidgetEventFunc func)
|
461 | 479 | {
|
462 |
| - int id = LCUIWidget_GetEventId(event_name); |
463 |
| - if (id < 0) { |
464 |
| - return -1; |
465 |
| - } |
466 |
| - return Widget_UnbindEventById(widget, id, func); |
| 480 | + return Widget_UnbindEventById(widget, GetEventId(event_name), func); |
467 | 481 | }
|
468 | 482 |
|
469 | 483 | static LCUI_Widget Widget_GetNextAt(LCUI_Widget widget, int x, int y)
|
|
0 commit comments