mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-12-01 16:56:34 +01:00
针对部件事件添加相关代码
This commit is contained in:
@@ -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; /**< 事件类型名称 */
|
||||
|
||||
@@ -59,6 +59,7 @@ enum SystemEventType {
|
||||
LCUI_MOUSEDOWN, /**< 鼠标触发的按钮按下事件 */
|
||||
LCUI_MOUSEUP, /**< 鼠标触发的按钮释放事件 */
|
||||
LCUI_INPUT, /**< 输入法触发的文本输入事件 */
|
||||
LCUI_WIDGET,
|
||||
LCUI_USER = 100 /**< 用户事件,可以把这个当成系统事件与用户事件的分界 */
|
||||
};
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+22
-2
@@ -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 );
|
||||
}
|
||||
|
||||
/** 处理透明度 */
|
||||
|
||||
Reference in New Issue
Block a user