修改部件事件模块

定义LCUI_WidgetKeyboardEvent结构体,用于记录键值及按键状态;
修改部件按键事件派发函数代码。
更改了部分函数的名称。
This commit is contained in:
Liu Chao
2013-10-26 17:03:47 +08:00
parent 64a3ea194b
commit da2cd2674b
2 changed files with 46 additions and 50 deletions
+19 -12
View File
@@ -80,8 +80,14 @@ typedef struct LCUI_WidgetFocusEvent_ {
LCUI_BOOL focus;
} LCUI_WidgetFocusEvent;
typedef LCUI_KeyboardEvent LCUI_WidgetKeyboardEvent;
typedef struct {
unsigned char type;
int key_code;
int key_state;
}LCUI_WidgetKeyboardEvent;
typedef LCUI_MouseButtonEvent LCUI_WidgetMouseButtonEvent;
typedef struct LCUI_WidgetMouseMotionEvent_ {
uchar_t type;
LCUI_Pos rel_pos;
@@ -122,6 +128,9 @@ Widget_DispatchEvent( LCUI_Widget *widget, LCUI_WidgetEvent *event );
/** 移除指定部件的记录,使之不再响应状态变化 */
LCUI_API void WidgetRecord_Delete( LCUI_Widget *widget );
/** 判断指定部件是否被允许响应事件 */
LCUI_API LCUI_BOOL Widget_IsAllowResponseEvent( LCUI_Widget *widget );
/* 初始化部件模块 */
LCUI_API void
LCUIModule_Widget_Init( void );
@@ -132,28 +141,26 @@ LCUIModule_Widget_End( void );
/*-------------------------------- END ---------------------------------------*/
/*--------------------------- Focus Proc ------------------------------*/
LCUI_API LCUI_BOOL
Set_Focus( LCUI_Widget *widget );
/*
/**
* 功能:为部件设置焦点
* 说明:上个获得焦点的部件会得到EVENT_FOCUSOUT事件,而当前获得焦点的部件会得到
* EVENT_FOCUSIN事件。
* */
* */
LCUI_API LCUI_BOOL Widget_SetFocus( LCUI_Widget *widget );
/* 设定部件是否能够获取焦点 */
LCUI_API void
Widget_SetFocus( LCUI_Widget *widget, LCUI_BOOL flag );
/** 设定部件是否能够获取焦点 */
LCUI_API void Widget_SetCanGetFocus( LCUI_Widget *widget, LCUI_BOOL flag );
/* 获取指定部件内的已获得焦点的子部件 */
LCUI_API LCUI_Widget*
Get_FocusWidget( LCUI_Widget *widget );
LCUI_API LCUI_BOOL
Cancel_Focus( LCUI_Widget *widget );
/*
/**
* 功能:取消指定部件的焦点
* 说明:该部件会得到EVENT_FOCUSOUT事件,并且,会将焦点转移至其它部件
* */
* */
LCUI_API LCUI_BOOL Widget_CancelFocus( LCUI_Widget *widget );
/** 复位指定部件内的子部件的焦点 */
LCUI_API LCUI_BOOL Widget_ResetFocus( LCUI_Widget* widget );
+27 -38
View File
@@ -292,8 +292,8 @@ LCUI_API void WidgetRecord_Delete( LCUI_Widget *widget )
Queue_Unlock( &widget_proc_record );
}
/* 判断指定部件是否被允许响应事件 */
static LCUI_BOOL widget_allow_response( LCUI_Widget *widget )
/** 判断指定部件是否被允许响应事件 */
LCUI_API LCUI_BOOL Widget_IsAllowResponseEvent( LCUI_Widget *widget )
{
int i, n;
LCUI_Queue *child_list;
@@ -330,11 +330,13 @@ static LCUI_BOOL widget_allow_response( LCUI_Widget *widget )
return TRUE;
}
/* 设定部件状态,该函数会将该部件及上级所有父部件添加至列表里,每次调用该函数时,会更新
/**
* 设定部件状态,该函数会将该部件及上级所有父部件添加至列表里,每次调用该函数时,会更新
* 列表中的部件记录,若部件在更新前后都在列表中有记录,则该部件及上级所有父部件都会应用
* 此状态,否则,移除多余的部件,并恢复部件的状态为NORMAL */
static void
WidgetRecord_SetWidgetState( LCUI_Widget *widget, WIDGET_STATE state )
* 此状态,否则,移除多余的部件,并恢复部件的状态为NORMAL
*/
static void WidgetRecord_SetWidgetState( LCUI_Widget *widget,
WIDGET_STATE state )
{
WidgetRecord_Reset();
while( widget ) {
@@ -363,7 +365,7 @@ LCUI_HandleMouseButtonDown( LCUI_MouseButtonEvent *event )
widget = Widget_At( NULL, pos );
if( !widget_allow_response(widget) ) {
if( !Widget_IsAllowResponseEvent(widget) ) {
return;
}
DEBUG_MSG("widget: %p\n", widget);
@@ -428,7 +430,7 @@ LCUI_HandleMouseButtonUp( LCUI_MouseButtonEvent *event )
pos.y = event->y;
widget = Widget_At( NULL, pos );
if( !widget_allow_response(widget) ) {
if( !Widget_IsAllowResponseEvent(widget) ) {
return;
}
DEBUG_MSG("widget: %p\n", widget);
@@ -477,10 +479,10 @@ LCUI_HandleMouseButtonUp( LCUI_MouseButtonEvent *event )
tmp_event.clicked.rel_pos = Widget_ToRelPos( tmp_widget, pos );
Widget_DispatchEvent( tmp_widget, &tmp_event );
}
WidgetRecord_SetWidgetState (widget, WIDGET_STATE_ACTIVE);
WidgetRecord_SetWidgetState( widget, WIDGET_STATE_ACTIVE );
}
exit_point:;
WidgetRecord_SetWidgetState (widget, WIDGET_STATE_OVERLAY);
WidgetRecord_SetWidgetState( widget, WIDGET_STATE_OVERLAY );
click_widget = NULL;
}
@@ -518,7 +520,7 @@ LCUI_HandleMouseMotion( LCUI_MouseMotionEvent *event, void *unused )
/* 如果没有部件处于按住状态 */
if( !click_widget ) {
/* 如果允许响应状态,就设置为OVERLAY状态,否则重置为NORMAL状态 */
if( widget_allow_response(widget) ) {
if( Widget_IsAllowResponseEvent(widget) ) {
WidgetRecord_SetWidgetState( widget, WIDGET_STATE_OVERLAY );
} else {
WidgetRecord_SetWidgetState( widget, WIDGET_STATE_NORMAL );
@@ -543,14 +545,14 @@ void Widget_ClearClickRecord( LCUI_Widget *widget )
}
}
static int
Widget_DispatchKeyboardEvent( LCUI_Widget *widget,
LCUI_KeyboardEvent *event )
/** 根据键盘事件,将部件事件的响应任务派发出去 */
static int Widget_DispatchKeyboardEvent( LCUI_Widget *widget,
LCUI_KeyboardEvent *event )
{
int i,n;
LCUI_EventSlot *slot;
LCUI_Task *task;
LCUI_KeyboardEvent *p_buff;
LCUI_WidgetEvent *p_buff;
if( !widget ) {
return -1;
@@ -562,13 +564,19 @@ Widget_DispatchKeyboardEvent( LCUI_Widget *widget,
}
n = Queue_GetTotal( &slot->func_data );
for(i=0; i<n; ++i) {
task = Queue_Get( &slot->func_data, i );
p_buff = malloc( sizeof(LCUI_KeyboardEvent) );
task = (LCUI_Task*)Queue_Get( &slot->func_data, i );
p_buff = (LCUI_WidgetEvent*)malloc( sizeof(LCUI_WidgetEvent) );
if( !p_buff ) {
perror( __FUNCTION__ );
abort();
}
*p_buff = *event;
p_buff->type = EVENT_KEYBOARD;
p_buff->key.key_code = event->key_code;
if( event->type == LCUI_KEYUP ) {
p_buff->key.key_state = LCUIKEYSTATE_RELEASE;
} else {
p_buff->key.key_state = LCUIKEYSTATE_PRESSED;
}
task->arg[1] = p_buff;
task->destroy_arg[1] = TRUE;
AppTasks_Add( task );
@@ -784,26 +792,7 @@ LCUI_API LCUI_BOOL Widget_ResetFocus( LCUI_Widget* widget )
return TRUE;
}
LCUI_API int
Next_FocusWidget()
{
return 0;
}
LCUI_API int
Prev_FocusWidget()
{
return 0;
}
LCUI_API int
Return_FocusToParent()
{
return 0;
}
static void
WidgetFocusProc( LCUI_KeyboardEvent *event, void *unused )
static void WidgetFocusProc( LCUI_KeyboardEvent *event, void *unused )
{
LCUI_Widget *widget = NULL, *tmp = NULL, *focus_widget;
/* 如果输入法需要处理这个键,则退出本函数 */