/** 追加子部件 */ 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; }
/** 处理样式标签 */ const wchar_t* StyleTagStack_ScanBeginTag( LCUI_StyleTagStack *tags, const wchar_t *str ) { const wchar_t *q; LCUI_StyleTagData data; /* 开始处理样式标签 */ q = scan_style_tag_data( str, &data ); DEBUG_MSG2("handle_style_tag():%p\n", q); if( q ) { DEBUG_MSG2("add style data\n"); /* 将标签样式数据加入队列 */ LinkedList_AddData( tags, &data ); } return q; }
/** 绑定指定ID的事件 */ int $(BindById)( LCUI_EventBox box, int event_id, EventCallBack func, void *func_data, void (*destroy_data)(void*) ) { LCUI_RBTreeNode *node; LCUI_EventSlot *slot; LCUI_EventHandler *handler; node = RBTree_Search( &box->event_slot, event_id ); if( !node ) { return -1; } slot = (LCUI_EventSlot*)node->data; handler = NEW_ONE(LCUI_EventHandler); handler->id = ++box->handler_id; handler->func = func; handler->func_data = func_data; handler->destroy_data = destroy_data; LinkedList_AddData( &slot->handlers, handler ); RBTree_Insert( &box->event_handler, handler->id, (void*)(slot->id) ); return handler->id; }