Beispiel #1
0
/**
 * 功能:取消指定部件的焦点
 * 说明:该部件会得到EVENT_FOCUSOUT事件,并且,会将焦点转移至其它部件
 * */
LCUI_API LCUI_BOOL Widget_CancelFocus( LCUI_Widget *widget )
{
	int i, total, focus_pos;
	LCUI_Widget *other_widget, **focus_widget;
	LCUI_Queue *queue_ptr;
	LCUI_WidgetEvent event;

	if( !widget || !widget->focus ) {
		return FALSE;
	}

	focus_widget = &RootWidget_GetSelf()->focus_widget;
	queue_ptr = Widget_GetChildList( widget->parent );
	/* 如果该部件并没获得焦点 */
	if( *focus_widget != widget ) {
		return FALSE;
	}
	event.type = EVENT_FOCUSOUT;
	Widget_DispatchEvent( widget, &event );
	/* 寻找可获得焦点的其它部件 */
	total = Queue_GetTotal( queue_ptr );
	focus_pos = WidgetQueue_FindPos( queue_ptr, *focus_widget );
	for( i=0; i<focus_pos; ++i ) {
		other_widget = (LCUI_Widget*)Queue_Get( queue_ptr, i);
		if( other_widget && other_widget->visible
		 && other_widget->focus ) {
			event.type = EVENT_FOCUSIN;
			Widget_DispatchEvent( widget, &event );
			*focus_widget = other_widget;
			break;
		}
	}
	if( i < focus_pos ) {
		return TRUE;
	}
	/* 排在该部件前面的符合条件的部件没找到,就找排在该部件后面的 */
	for( i=focus_pos+1; i<total; ++i ) {
		other_widget = (LCUI_Widget*)Queue_Get( queue_ptr, i);
		if( other_widget && other_widget->visible
		 && other_widget->focus ) {
			event.type = EVENT_FOCUSIN;
			Widget_DispatchEvent( other_widget, &event );
			*focus_widget = other_widget;
			break;
		}
	}
	/* 没找到就复位焦点 */
	if( i >= total ) {
		*focus_widget = NULL;
	}
	return TRUE;
}
Beispiel #2
0
static void 
_DragEvent_Do(LCUI_Widget *widget, LCUI_MouseMotionEvent *event )
{
	LCUI_WidgetEvent buff;
	buff.type = EVENT_DRAG;
	buff.drag.cursor_pos.x = event->x;
	buff.drag.cursor_pos.y = event->y;
	buff.drag.new_pos.x = buff.drag.cursor_pos.x - __offset_pos.x;
	buff.drag.new_pos.y = buff.drag.cursor_pos.y - __offset_pos.y;
	buff.drag.first_click = FALSE;
	buff.drag.end_click = FALSE;
	Widget_DispatchEvent( widget, &buff );
}
Beispiel #3
0
/**
 * 功能:为部件设置焦点
 * 说明:上个获得焦点的部件会得到EVENT_FOCUSOUT事件,而当前获得焦点的部件会得到
 * EVENT_FOCUSIN事件。
 * */
LCUI_API LCUI_BOOL Widget_SetFocus( LCUI_Widget *widget )
{
	LCUI_Widget **focus_widget;
	LCUI_WidgetEvent event;

	if( widget ) {
		/* 先处理上级部件的焦点 */
		if( widget->parent ) {
			Widget_SetFocus( widget->parent );
		}
		if( !widget->focus ) {
			return FALSE;
		}
	} else {
		return FALSE;
	}
	if( widget->parent ) {
		focus_widget = &widget->parent->focus_widget;
	} else {
		focus_widget = &RootWidget_GetSelf()->focus_widget;
	}
	if( *focus_widget ) {
		/* 若之前获得焦点的是模态部件,则不能移动焦点 */
		if( (*focus_widget)->modal ) {
			return FALSE;
		}
		/* 如果上次和这次的部件不一样 */
		if( *focus_widget != widget ) {
			event.type = EVENT_FOCUSOUT;
			Widget_DispatchEvent( *focus_widget, &event );
		}
	}
	event.type = EVENT_FOCUSIN;
	Widget_DispatchEvent( widget, &event );
	/* 保存新焦点位置 */
	*focus_widget = widget;
	return TRUE;
}
Beispiel #4
0
static void 
_DragEvent_Start( LCUI_Widget *widget, LCUI_MouseButtonEvent *event )
{
	LCUI_WidgetEvent buff;
	buff.type = EVENT_DRAG;
	buff.drag.cursor_pos.x = event->x;
	buff.drag.cursor_pos.y = event->y;
	buff.drag.new_pos = Widget_GetGlobalPos( widget );
	__offset_pos.x = buff.drag.cursor_pos.x - buff.drag.new_pos.x;
	__offset_pos.y = buff.drag.cursor_pos.y - buff.drag.new_pos.y;
	buff.drag.first_click = TRUE;
	buff.drag.end_click = FALSE;
	/* 处理部件的拖动事件 */
	Widget_DispatchEvent( widget, &buff );
}
Beispiel #5
0
/** 复位指定部件内的子部件的焦点 */
LCUI_API LCUI_BOOL Widget_ResetFocus( LCUI_Widget* widget )
{
	LCUI_Widget** focus_widget;
	LCUI_WidgetEvent event;

	if( !widget ) {
		widget = RootWidget_GetSelf();
	}
	focus_widget = &widget->focus_widget;
	if( *focus_widget ) {
		event.type = EVENT_FOCUSOUT;
		Widget_DispatchEvent( *focus_widget, &event );
	}

	*focus_widget = NULL;
	return TRUE;
}
Beispiel #6
0
static LCUI_BOOL 
_DragEvent_End( LCUI_Widget *widget, LCUI_MouseButtonEvent *event )
{
	LCUI_WidgetEvent buff;
	buff.type = EVENT_DRAG;
	buff.drag.cursor_pos.x = event->x;
	buff.drag.cursor_pos.y = event->y;
	/* 若点击前后,鼠标坐标并未发生变化,则返回TRUE */
	if( old_cursor_pos.x == event->x
	 && old_cursor_pos.y == event->y ) {
		return TRUE;
	}
	buff.drag.new_pos.x = buff.drag.cursor_pos.x - __offset_pos.x;
	buff.drag.new_pos.y = buff.drag.cursor_pos.y - __offset_pos.y;
	buff.drag.first_click = FALSE;
	buff.drag.end_click = TRUE;
	Widget_DispatchEvent( widget, &buff );
	return FALSE;
}
Beispiel #7
0
/* 提交输入法输入的内容至目标 */
LCUI_API int
LCUIIME_Commit( const wchar_t *str )
{
	LCUI_Widget *widget;
	LCUI_WidgetEvent event;

	if( current_ime == NULL ) {
		return -1;
	}
	if( current_ime->func.gettarget == NULL ) {
		return -2;
	}
	widget = current_ime->func.gettarget();
	if(! widget ) {
		return -3;
	}
	/* 设置事件 */
	event.type = EVENT_INPUT;
	wcscpy( event.input.text, str );
	/* 派发事件 */
	return Widget_DispatchEvent( widget, &event );
}
Beispiel #8
0
static void LCUI_HandleMouseMotion( LCUI_Event *event, void *unused )
{
	LCUI_Pos pos;
	LCUI_Widget *tmp_widget, *widget;
	LCUI_WidgetEvent wdg_event;

	pos.x = event->motion.x;
	pos.y = event->motion.y;
	/* 获取当前鼠标游标覆盖到的部件的指针 */
	widget = Widget_At( NULL, pos );
	if( widget ) {
		tmp_widget = GetWidgetOfResponseEvent( widget, EVENT_MOUSEMOTION );
		if( tmp_widget ) {
			wdg_event.type = EVENT_MOUSEMOTION;
			pos = Widget_ToRelPos( tmp_widget, pos );
			wdg_event.mouse_motion.rel_pos = pos;
			Widget_DispatchEvent( tmp_widget, &wdg_event );
		}
	}
	
	/* 如果没有部件处于按住状态 */
	if( !click_widget ) {
		/* 如果允许响应状态,就设置为OVERLAY状态,否则重置为NORMAL状态 */
		if( Widget_IsAllowResponseEvent(widget) ) {
			WidgetRecord_SetWidgetState( widget, WIDGET_STATE_OVERLAY );
		} else {
			WidgetRecord_SetWidgetState( widget, WIDGET_STATE_NORMAL );
		}
	}
	/* 如果之前点击过部件,并且现在鼠标左键还处于按下状态,那就处理部件拖动 */
	tmp_widget = GetWidgetOfResponseEvent( click_widget, EVENT_DRAG );
	if( tmp_widget != click_widget ) {
		return;
	}
	if( tmp_widget && event->motion.state == LCUIKEYSTATE_PRESSED ) {
		DEBUG_MSG("doing drag\n");
		_DragEvent_Do( tmp_widget, &event->motion );
	}
}
Beispiel #9
0
/** 响应鼠标按键释放事件 */
static void LCUI_HandleMouseButtonUp( LCUI_MouseButtonEvent *event )
{
	LCUI_Widget *tmp_widget, *widget;
	LCUI_WidgetEvent tmp_event;
	LCUI_Pos pos;
	LCUI_BOOL can_click=TRUE;

	if( !event || event->state != LCUIKEYSTATE_RELEASE ) {
		return;
	}
	pos.x = event->x;
	pos.y = event->y;
	widget = Widget_At( NULL, pos );

	if( !Widget_IsAllowResponseEvent(widget) ) {
		return;
	}
	if( widget ) {
		pos = Widget_ToRelPos( widget, pos );
		tmp_event.type = EVENT_MOUSEBUTTON;
		tmp_event.mouse_button.x = pos.x;
		tmp_event.mouse_button.y = pos.y;
		tmp_event.mouse_button.button = event->button;
		tmp_event.mouse_button.state = event->state;
		Widget_DispatchEvent( widget, &tmp_event );
	}

	if( event->button != LCUIKEY_LEFTBUTTON ) {
		return;
	}
	DEBUG_MSG("mouse left button free, click_widget: %p\n", click_widget );
	if( !click_widget ) {
		/* 如果是点击屏幕空白处,则复位焦点 */
		Widget_ResetFocus( NULL );
		return;
	}
	/* 如果能拖动部件 */
	if( can_drag_widget ) {
		tmp_widget = GetWidgetOfResponseEvent( click_widget, EVENT_DRAG );
		if( tmp_widget && tmp_widget == click_widget ) {
			DEBUG_MSG("end drag\n");
			/* 结束部件的拖动 */
			can_click =  _DragEvent_End( tmp_widget, event );
		}
		/* 标记为不能拖动部件 */
		can_drag_widget = FALSE;
	}
	/* 如果不能处理点击,则跳转至后面的退出点 */
	if( !can_click ) {
		goto exit_point;
	}
	tmp_widget = GetWidgetOfResponseEvent( widget, EVENT_CLICKED );
	/* 如果之前点击的部件和当前点击的部件一样 */
	if( click_widget == tmp_widget ) {
		/* 如果部件有效且已经启用 */
		if( tmp_widget && tmp_widget->enabled ) {
			tmp_event.type = EVENT_CLICKED;
			pos.x = event->x;
			pos.y = event->y;
			tmp_event.clicked.rel_pos = Widget_ToRelPos( tmp_widget, pos );
			Widget_DispatchEvent( tmp_widget, &tmp_event );
		}
		WidgetRecord_SetWidgetState( widget, WIDGET_STATE_ACTIVE );
	}
exit_point:;
	WidgetRecord_SetWidgetState( widget, WIDGET_STATE_OVERLAY );
	click_widget = NULL;
}
Beispiel #10
0
/** 响应鼠标按键按下事件 */
static void LCUI_HandleMouseButtonDown( LCUI_MouseButtonEvent *event )
{
	LCUI_Widget *widget, *tmp_widget;
	LCUI_Pos pos;
	LCUI_WidgetEvent wdg_event;
	
	if( !event || event->state != LCUIKEYSTATE_PRESSED ) {
		return;
	}
	pos.x = event->x;
	pos.y = event->y;
	old_cursor_pos.x = pos.x;
	old_cursor_pos.y = pos.y;
	widget = Widget_At( NULL, pos );
	if( !Widget_IsAllowResponseEvent(widget) ) {
		return;
	}
	/* 获取能够响应此事件的部件 */
	tmp_widget = GetWidgetOfResponseEvent( widget, EVENT_MOUSEBUTTON );
	if( widget && tmp_widget ) {
		/* 开始准备事件数据 */
		pos = Widget_ToRelPos( tmp_widget, pos );
		wdg_event.type = EVENT_MOUSEBUTTON;
		wdg_event.mouse_button.x = pos.x;
		wdg_event.mouse_button.y = pos.y;
		wdg_event.mouse_button.button = event->button;
		wdg_event.mouse_button.state = event->state;
		/* 派发事件 */
		Widget_DispatchEvent( tmp_widget, &wdg_event );
	}
	if( event->button != LCUIKEY_LEFTBUTTON ) {
		return;
	}
	tmp_widget = GetWidgetOfResponseEvent( widget, EVENT_CLICKED );
	if( tmp_widget ) {
		click_widget = tmp_widget;
		tmp_widget = GetWidgetOfResponseEvent( widget, EVENT_DRAG );
		if( click_widget == tmp_widget ) {
			DEBUG_MSG("start drag\n");
			/* 开始处理部件的拖动 */
			_DragEvent_Start( tmp_widget, event );
			/* 设置标记,表示可以进行部件拖动 */
			can_drag_widget = TRUE;
		} else {
			/* 设置标记,表示不能进行部件拖动 */
			can_drag_widget = FALSE;
		}
	} else {
		click_widget = widget;
		tmp_widget = GetWidgetOfResponseEvent( widget, EVENT_DRAG );
		if( widget && tmp_widget ) {
			DEBUG_MSG("start drag\n");
			/* 开始处理部件的拖动 */
			_DragEvent_Start( tmp_widget, event );
			can_drag_widget = TRUE;
		}
	}
	/* 焦点转移给该部件 */
	Widget_SetFocus( click_widget );
	WidgetRecord_SetWidgetState( widget, WIDGET_STATE_ACTIVE );
}