/** 追加子部件 */ int $(Append)( LCUI_Widget container, LCUI_Widget widget ) { int i, n; LCUI_Widget old_container; LCUI_WidgetEvent e; DEBUG_MSG("container: %p, widget: %p\n", container, widget); if( !container || !widget || container == widget->parent ) { return -1; } if( container == widget ) { return -2; } if( widget->parent ) { old_container = widget->parent; } else { goto remove_done; } /* 移除在之前的容器中的记录 */ n = LinkedList_GetTotal( &old_container->children ); for( i=0; i<n; ++i ) { LinkedList_Goto( &old_container->children, i ); if( LinkedList_Get(&old_container->children) == widget ) { LinkedList_Delete( &old_container->children ); break; } } /* 如果是从根级部件中移出,则触发 WET_REMOVE 事件 */ if( i < n && old_container == LCUIRootWidget ) { e.type_name = "TopLevelWidget"; e.target = widget; Widget_PostEvent( LCUIRootWidget, &e, (int*)WET_REMOVE ); } n = LinkedList_GetTotal( &old_container->children_show ); for( i=0; i<n; ++i ) { LinkedList_Goto( &old_container->children_show, i ); if( LinkedList_Get(&old_container->children_show) == widget ) { LinkedList_Delete( &old_container->children_show ); break; } } remove_done: widget->parent = container; LinkedList_AddData( &container->children, widget ); LinkedList_AddData( &container->children_show, widget ); /* 如果是添加至根部件内,则触发 WET_ADD 事件 */ if( container == LCUIRootWidget ) { int ret; e.type_name = "TopLevelWidget"; e.target = widget; ret = Widget_PostEvent( LCUIRootWidget, &e, (int*)WET_ADD ); DEBUG_MSG("post done, ret = %d\n", ret); } Widget_UpdateTaskStatus( widget ); DEBUG_MSG("tip\n"); return 0; }
int ScrollLoading_Update( ScrollLoading ctx ) { LCUI_Widget w; LinkedListNode *node; LCUI_WidgetEventRec e; int count = 0, top, bottom; e.type = ctx->event_id; e.cancel_bubble = TRUE; bottom = top = ctx->top; bottom += ctx->container->box.padding.height; if( !ctx->top_child ) { node = ctx->container->children_show.head.next; ctx->top_child = node->data; } if( !ctx->top_child ) { return 0; } if( ctx->top_child->box.border.top > bottom ) { node = Widget_GetNode( ctx->top_child ); ctx->top_child = NULL; while( node ) { w = node->data; if( w->box.border.y < bottom ) { ctx->top_child = w; break; } node = node->prev; } if( !ctx->top_child ) { return 0; } } node = Widget_GetNode( ctx->top_child ); while( node ) { w = node->data; if( w->box.border.y > bottom ) { break; } if( w->box.border.y + w->box.border.height >= top ) { Widget_PostEvent( w, &e, NULL, NULL ); ++count; } node = node->next; } return count; }
/** 部件析构函数 */ static void $(OnDestroy)( void *arg ) { LCUI_WidgetEvent e; 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 ); /* 如果是从根级部件中移出,则触发 WET_REMOVE 事件 */ if( widget->parent == LCUIRootWidget ) { e.type_name = "TopLevelWidget"; e.target = widget; Widget_PostEvent( LCUIRootWidget, &e, (int*)WET_REMOVE ); } }