From 53b49593c19c0759a96e00f608d8c07632fe225a Mon Sep 17 00:00:00 2001 From: Liu Chao Date: Sun, 15 Mar 2015 22:53:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=92=88=E5=AF=B9=E9=83=A8=E4=BB=B6=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=B7=BB=E5=8A=A0=E7=9B=B8=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/LCUI/gui/widget_event.h | 12 ++++++++++++ include/LCUI/kernel/main.h | 1 + src/gui/widget_base.c | 19 +++++++++++++++++++ src/gui/widget_task.c | 24 ++++++++++++++++++++++-- 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/include/LCUI/gui/widget_event.h b/include/LCUI/gui/widget_event.h index c43247b5..3bbe65d1 100644 --- a/include/LCUI/gui/widget_event.h +++ b/include/LCUI/gui/widget_event.h @@ -43,7 +43,12 @@ LCUI_BEGIN_HEADER enum WidgetEventType { + WET_CREATE, + WET_DESTROY, + WET_MOVE, WET_RESIZE, + WET_SHOW, + WET_HIDE, WET_KEYDOWN, WET_KEYUP, @@ -60,6 +65,13 @@ enum WidgetEventType { WET_USER }; +/** 面向系统级的事件附加数据的结构,主要用于响应全局部件的事件 */ +typedef struct LCUI_BaseWidgetEvent { + int type; + LCUI_Widget widget; +} LCUI_BaseWidgetEvent; + +/** 面向部件级的事件内容结构 */ typedef struct LCUI_WidgetEvent { int type; /**< 事件类型标识号 */ const char *type_name; /**< 事件类型名称 */ diff --git a/include/LCUI/kernel/main.h b/include/LCUI/kernel/main.h index ababc140..5b2cbe6f 100755 --- a/include/LCUI/kernel/main.h +++ b/include/LCUI/kernel/main.h @@ -59,6 +59,7 @@ enum SystemEventType { LCUI_MOUSEDOWN, /**< 鼠标触发的按钮按下事件 */ LCUI_MOUSEUP, /**< 鼠标触发的按钮释放事件 */ LCUI_INPUT, /**< 输入法触发的文本输入事件 */ + LCUI_WIDGET, LCUI_USER = 100 /**< 用户事件,可以把这个当成系统事件与用户事件的分界 */ }; diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index 71b78983..7bb0de44 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -143,13 +143,22 @@ int $(Front)( LCUI_Widget widget ) /** 部件析构函数 */ static void $(OnDestroy)( void *arg ) { + LCUI_SystemEvent e; + LCUI_BaseWidgetEvent *p_data; LCUI_Widget widget = (LCUI_Widget)arg; + Widget_DestroyTaskBox( widget ); LCUIEventBox_Destroy( widget->event ); widget->event = NULL; LinkedList_Destroy( &widget->children ); LinkedList_Destroy( &widget->children_show ); DirtyRectList_Destroy( &widget->dirty_rects ); + + e.type = LCUI_WIDGET; + p_data = NEW_ONE(LCUI_BaseWidgetEvent); + p_data->type = WET_DESTROY; + p_data->widget = widget; + LCUI_PostEvent( &e ); } /** 构造函数 */ @@ -194,10 +203,20 @@ static void $(Init)( LCUI_Widget widget ) /** 新建一个GUI部件 */ LCUI_Widget $(New)( const char *type_name ) { + LCUI_SystemEvent e; + LCUI_BaseWidgetEvent *p_data; LCUI_Widget widget = NEW_ONE(struct LCUI_WidgetFull); + $(Init)(widget); LinkedList_AddData( &LCUIRootWidget->children, widget ); LinkedList_AddData( &LCUIRootWidget->children_show, widget ); + + e.type = LCUI_WIDGET; + p_data = NEW_ONE(LCUI_BaseWidgetEvent); + p_data->type = WET_CREATE; + p_data->widget = widget; + LCUI_PostEvent( &e ); + return widget; } diff --git a/src/gui/widget_task.c b/src/gui/widget_task.c index d159f933..3a17d931 100644 --- a/src/gui/widget_task.c +++ b/src/gui/widget_task.c @@ -80,13 +80,33 @@ static void HandleMove( LCUI_Widget w, LCUI_WidgetTask *t ) /** 处理尺寸调整 */ static void HandleResize( LCUI_Widget w, LCUI_WidgetTask *t ) { - + LCUI_SystemEvent e; + LCUI_BaseWidgetEvent *p_data; + + // code ... + + e.type = LCUI_WIDGET; + p_data = (LCUI_BaseWidgetEvent*) + malloc(sizeof(LCUI_BaseWidgetEvent)); + p_data->type = WET_CREATE; + p_data->widget = w; + LCUI_PostEvent( &e ); } /** 处理可见性 */ static void HandleVisibility( LCUI_Widget w, LCUI_WidgetTask *t ) { - + LCUI_SystemEvent e; + LCUI_BaseWidgetEvent *p_data; + + // code ... + + e.type = LCUI_WIDGET; + p_data = (LCUI_BaseWidgetEvent*) + malloc(sizeof(LCUI_BaseWidgetEvent)); + p_data->type = t->visible ? WET_SHOW:WET_HIDE; + p_data->widget = w; + LCUI_PostEvent( &e ); } /** 处理透明度 */