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; }
/** 初始化 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 ); } }
Dict *StrDict_Create( void *(*val_dup)(void*, const void*), void(*val_del)(void*, void*) ) { DictType *dtype = NEW( DictType, 1 ); dtype->hashFunction = Dict_KeyHash; dtype->keyCompare = Dict_KeyCompare; dtype->keyDestructor = Dict_KeyDestructor; dtype->keyDup = Dict_KeyDup; dtype->valDup = val_dup; dtype->valDestructor = val_del; return Dict_Create( dtype, dtype ); }