static void Widget_SendResizeEvent(LCUI_Widget w) { LCUI_WidgetEventRec e; e.target = w; e.data = NULL; e.type = LCUI_WEVENT_RESIZE; e.cancel_bubble = TRUE; Widget_TriggerEvent(w, &e, NULL); Widget_AddTask(w, LCUI_WTASK_REFRESH); Widget_PostSurfaceEvent(w, LCUI_WEVENT_RESIZE, FALSE); }
void Widget_AddToTrash( LCUI_Widget w ) { LCUI_WidgetEventRec e = { 0 }; e.type = WET_REMOVE; w->state = WSTATE_DELETED; Widget_TriggerEvent( w, &e, NULL ); if( !w->parent ) { return; } LinkedList_Unlink( &w->parent->children, &w->node ); LinkedList_Unlink( &w->parent->children_show, &w->node_show ); LinkedList_AppendNode( &self.trash, &w->node ); Widget_PostSurfaceEvent( w, WET_REMOVE, TRUE ); }
void Widget_AddState(LCUI_Widget w, LCUI_WidgetState state) { /* 如果部件还处于未准备完毕的状态 */ if (w->state < LCUI_WSTATE_READY) { w->state |= state; /* 如果部件已经准备完毕则触发 ready 事件 */ if (w->state == LCUI_WSTATE_READY) { LCUI_WidgetEventRec e = { 0 }; e.type = LCUI_WEVENT_READY; e.cancel_bubble = TRUE; Widget_TriggerEvent(w, &e, NULL); w->state = LCUI_WSTATE_NORMAL; } } }
int Widget_UpdateEx( LCUI_Widget w, LCUI_BOOL has_timeout ) { int i; LCUI_BOOL *buffer; LinkedListNode *node, *next; /* 如果该部件没有任务需要处理、或者被其它线程占用 */ if( !w->task.for_self || LCUIMutex_TryLock( &w->mutex ) != 0 ) { goto proc_children_task; } w->task.for_self = FALSE; buffer = w->task.buffer; /* 如果有用户自定义任务 */ if( buffer[WTT_USER] ) { LCUI_WidgetClass *wc; wc = LCUIWidget_GetClass( w->type ); wc ? wc->task_handler( w ) : FALSE; } for( i = 0; i < WTT_USER; ++i ) { if( buffer[i] ) { buffer[i] = FALSE; if( self.handlers[i] ) { self.handlers[i]( w ); } } else { buffer[i] = FALSE; } } LCUIMutex_Unlock( &w->mutex ); /* 如果部件还处于未准备完毕的状态 */ if( w->state < WSTATE_READY ) { w->state |= WSTATE_UPDATED; /* 如果部件已经准备完毕则触发 ready 事件 */ if( w->state == WSTATE_READY ) { LCUI_WidgetEventRec e; e.type = WET_READY; e.cancel_bubble = TRUE; Widget_TriggerEvent( w, &e, NULL ); w->state = WSTATE_NORMAL; } } self.count += 1; proc_children_task: if( !w->task.for_children ) { return w->task.for_self; } /* 如果子级部件中有待处理的部件,则递归进去 */ w->task.for_children = FALSE; node = w->children.head.next; while( node ) { LCUI_Widget child = node->data; /* 如果当前部件有销毁任务,结点空间会连同部件一起被 * 释放,为避免因访问非法空间而出现异常,预先保存下 * 个结点。 */ next = node->next; /* 如果该级部件的任务需要留到下次再处理 */ if( Widget_UpdateEx( child, has_timeout ) ) { w->task.for_children = TRUE; } if( has_timeout ) { if( !self.is_timeout && self.count >= 50 ) { self.count = 0; if( LCUI_GetTime() >= self.timeout ) { self.is_timeout = TRUE; } } if( self.is_timeout ) { break; } } node = next; } return w->task.for_self || w->task.for_children; }