/** 初始化 LCUI 的 CSS 代码解析功能 */ void LCUI_InitCSSParser( void ) { LCUI_StyleParser new_sp, sp, sp_end; self.count = 0; self.dicttype = DictType_StringKey; self.dicttype.valDestructor = DestroyStyleParser; self.parsers = Dict_Create( &self.dicttype, NULL ); sp_end = style_parser_map + LEN( style_parser_map ); for( sp = style_parser_map; sp < sp_end; ++sp ) { new_sp = malloc( sizeof( LCUI_StyleParserRec ) ); new_sp->key = sp->key; new_sp->parse = sp->parse; if( !sp->name && sp->key >= 0 ) { const char *name = LCUI_GetStyleName( sp->key ); if( !name ) { free( new_sp ); continue; } new_sp->name = strdup( name ); } else { new_sp->name = strdup( sp->name ); } Dict_Add( self.parsers, new_sp->name, new_sp ); } }
int Widget_SetAttributeEx(LCUI_Widget w, const char *name, void *value, int value_type, void (*value_destructor)(void *)) { LCUI_WidgetAttribute attr; if (!self.available) { self.dt_attributes = DictType_StringCopyKey; self.dt_attributes.valDestructor = OnClearWidgetAttribute; self.available = TRUE; } if (!w->attributes) { w->attributes = Dict_Create(&self.dt_attributes, NULL); } attr = Dict_FetchValue(w->attributes, name); if (attr) { if (attr->value.destructor) { attr->value.destructor(attr->value.data); } } else { attr = NEW(LCUI_WidgetAttributeRec, 1); attr->name = strdup2(name); Dict_Add(w->attributes, attr->name, attr); } attr->value.data = value; attr->value.type = value_type; attr->value.destructor = value_destructor; return 0; }
int LCUI_AddCSSParser( LCUI_StyleParser sp ) { LCUI_StyleParser new_sp; if( !sp->name || strlen( sp->name ) < 1 ) { return -1; } if( Dict_FetchValue( self.parsers, sp->name ) ) { return -2; } self.count += 1; new_sp = NEW( LCUI_StyleParserRec, 1 ); new_sp->key = sp->key; new_sp->parse = sp->parse; new_sp->name = strdup( sp->name ); Dict_Add( self.parsers, new_sp->name, new_sp ); return 0; }