Skip to content

Commit 19992d1

Browse files
committed
feat(gui): Widget_SetAttribute() will call proto->setattr()
1 parent 12247ce commit 19992d1

2 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/gui/builder.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,6 @@ static int ParseWidget(XMLParserContext ctx, xmlNodePtr node)
229229
prop_name = malloc(strsize((const char*)prop->name));
230230
strtolower(prop_name, (const char*)prop->name);
231231
Widget_SetAttribute(w, prop_name, prop_val);
232-
if (w->proto && w->proto->setattr) {
233-
w->proto->setattr(w, prop_name, prop_val);
234-
}
235232
free(prop_name);
236233
}
237234
if (prop_val) {

src/gui/widget_attribute.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ int Widget_SetAttributeEx(LCUI_Widget w, const char *name, void *value,
8686

8787
int Widget_SetAttribute(LCUI_Widget w, const char *name, const char *value)
8888
{
89+
int ret;
8990
char *value_str;
91+
9092
if (strcmp(name, "disabled") == 0) {
9193
if (!value || strcmp(value, "false") != 0) {
9294
Widget_SetDisabled(w, TRUE);
@@ -95,16 +97,21 @@ int Widget_SetAttribute(LCUI_Widget w, const char *name, const char *value)
9597
}
9698
return 0;
9799
}
98-
if (!value) {
99-
return Widget_SetAttributeEx(w, name, NULL, LCUI_STYPE_NONE,
100-
NULL);
100+
if (value) {
101+
value_str = strdup2(value);
102+
if (!value_str) {
103+
return -ENOMEM;
104+
}
105+
ret = Widget_SetAttributeEx(w, name, value_str,
106+
LCUI_STYPE_STRING, free);
107+
} else {
108+
ret = Widget_SetAttributeEx(w, name, NULL, LCUI_STYPE_NONE,
109+
NULL);
101110
}
102-
value_str = strdup2(value);
103-
if (!value_str) {
104-
return -ENOMEM;
111+
if (w->proto && w->proto->setattr) {
112+
w->proto->setattr(w, name, value);
105113
}
106-
return Widget_SetAttributeEx(w, name, value_str, LCUI_STYPE_STRING,
107-
free);
114+
return ret;
108115
}
109116

110117
const char *Widget_GetAttribute(LCUI_Widget w, const char *name)

0 commit comments

Comments
 (0)