Exemplo n.º 1
0
LCUI_API int WidgetMsg_AddToTask( LCUI_Widget *widget, WidgetMsgData *data_ptr )
{
	int i,n;
	LCUI_Queue *msg_func;
	LCUI_Task *task_ptr, task;
	
	/* LCUI系统消息不能作为任务让程序在主循环里处理 */
	if( data_ptr->msg_id < WIDGET_USER ) {
		return -1;
	}
	msg_func = Widget_GetMsgFunc( widget );
	if( msg_func == NULL ) {
		return -2;
	}
	n = Queue_GetTotal( msg_func );
	for(i=0; i<n; ++i) {
		task_ptr = (LCUI_Task*)Queue_Get( msg_func, i );
		if( task_ptr == NULL ) {
			continue;
		}
		if( task_ptr->id != data_ptr->msg_id ) {
			continue;
		}
		task.id = widget->app_id;
		task.func = task_ptr->func;
		task.arg[0] = widget;
		task.arg[1] = data_ptr->data.ptr;
		task.destroy_arg[0] = FALSE;
		task.destroy_arg[1] = data_ptr->need_free;
		AppTasks_Add( &task );
	}
	return 0;
}
Exemplo n.º 2
0
/** 根据键盘事件,将部件事件的响应任务派发出去 */
static int Widget_DispatchKeyboardEvent( LCUI_Widget *widget, 
					 LCUI_KeyboardEvent *event )
{
	int i,n;
	LCUI_EventSlot *slot;
	LCUI_Task *task, task_buff;
	LCUI_WidgetEvent *p_buff;

	if( !widget ) {
		return -1;
	}

	slot = EventSlots_Find( &widget->event, EVENT_KEYBOARD );
	if( !slot ) {
		return -2;
	}
	n = Queue_GetTotal( &slot->func_data );
	for(i=0; i<n; ++i) {
		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->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_buff.id = widget->app_id;
		task_buff.func = task->func;
		task_buff.arg[0] = task->arg[0];
		task_buff.arg[1] = p_buff;
		task_buff.destroy_arg[0] = task->destroy_arg[0];
		task_buff.destroy_arg[1] = TRUE;
		/* 添加至程序的任务队列 */
		AppTasks_Add( &task_buff );
	}
	return 0;
}
Exemplo n.º 3
0
/** 处理与部件事件关联的回调函数 */
LCUI_API int Widget_DispatchEvent( LCUI_Widget *widget, 
				   LCUI_WidgetEvent *event )
{
	int i,n;
	LCUI_EventSlot *slot;
	LCUI_Task *p_task, task_buff;
	LCUI_WidgetEvent *p_buff;

	if( !widget ) {
		return -1;
	}

	slot = EventSlots_Find( &widget->event, event->type );
	if( !slot ) {
		return -2;
	}
	n = Queue_GetTotal( &slot->func_data );
	for(i=0; i<n; ++i) {
		p_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;
		task_buff.id = widget->app_id;
		task_buff.func = p_task->func;
		task_buff.arg[0] = p_task->arg[0];
		task_buff.arg[1] = p_buff;
		task_buff.destroy_arg[0] = p_task->destroy_arg[0];
		task_buff.destroy_arg[1] = TRUE;
		AppTasks_Add( &task_buff );
	}
	return 0;
}