client/args.c

changeset 1024
d218b70e1499
parent 980
39cb60b6a81b
equal deleted inserted replaced
1023:d9b6b85cc210 1024:d218b70e1499
58 static void init_common_args(const CxJsonValue *value, void *args, ArgDefaultFuncs *funcs) { 58 static void init_common_args(const CxJsonValue *value, void *args, ArgDefaultFuncs *funcs) {
59 CxJsonValue *val; 59 CxJsonValue *val;
60 60
61 // boolean args 61 // boolean args
62 val = cxJsonObjGet(value, "fill"); 62 val = cxJsonObjGet(value, "fill");
63 if(val && val->type == CX_JSON_LITERAL && val->value.literal == CX_JSON_TRUE) { 63 if(val && val->type == CX_JSON_LITERAL && val->literal == CX_JSON_TRUE) {
64 funcs->fill(args, TRUE); 64 funcs->fill(args, TRUE);
65 } 65 }
66 66
67 val = cxJsonObjGet(value, "hexpand"); 67 val = cxJsonObjGet(value, "hexpand");
68 if(val && val->type == CX_JSON_LITERAL && val->value.literal == CX_JSON_TRUE) { 68 if(val && val->type == CX_JSON_LITERAL && val->literal == CX_JSON_TRUE) {
69 funcs->hexpand(args, TRUE); 69 funcs->hexpand(args, TRUE);
70 } 70 }
71 71
72 val = cxJsonObjGet(value, "vexpand"); 72 val = cxJsonObjGet(value, "vexpand");
73 if(val && val->type == CX_JSON_LITERAL && val->value.literal == CX_JSON_TRUE) { 73 if(val && val->type == CX_JSON_LITERAL && val->literal == CX_JSON_TRUE) {
74 funcs->vexpand(args, TRUE); 74 funcs->vexpand(args, TRUE);
75 } 75 }
76 76
77 val = cxJsonObjGet(value, "hfill"); 77 val = cxJsonObjGet(value, "hfill");
78 if(val && val->type == CX_JSON_LITERAL && val->value.literal == CX_JSON_TRUE) { 78 if(val && val->type == CX_JSON_LITERAL && val->literal == CX_JSON_TRUE) {
79 funcs->hfill(args, TRUE); 79 funcs->hfill(args, TRUE);
80 } 80 }
81 81
82 val = cxJsonObjGet(value, "vfill"); 82 val = cxJsonObjGet(value, "vfill");
83 if(val && val->type == CX_JSON_LITERAL && val->value.literal == CX_JSON_TRUE) { 83 if(val && val->type == CX_JSON_LITERAL && val->literal == CX_JSON_TRUE) {
84 funcs->vfill(args, TRUE); 84 funcs->vfill(args, TRUE);
85 } 85 }
86 86
87 val = cxJsonObjGet(value, "override_defaults"); 87 val = cxJsonObjGet(value, "override_defaults");
88 if(val && val->type == CX_JSON_LITERAL && val->value.literal == CX_JSON_TRUE) { 88 if(val && val->type == CX_JSON_LITERAL && val->literal == CX_JSON_TRUE) {
89 funcs->override_defaults(args, TRUE); 89 funcs->override_defaults(args, TRUE);
90 } 90 }
91 91
92 // int args 92 // int args
93 val = cxJsonObjGet(value, "margin"); 93 val = cxJsonObjGet(value, "margin");
94 if(val && val->type == CX_JSON_INTEGER) { 94 if(val && val->type == CX_JSON_INTEGER) {
95 funcs->margin(args, (int)val->value.integer); 95 funcs->margin(args, (int)val->integer);
96 } 96 }
97 97
98 val = cxJsonObjGet(value, "margin_left"); 98 val = cxJsonObjGet(value, "margin_left");
99 if(val && val->type == CX_JSON_INTEGER) { 99 if(val && val->type == CX_JSON_INTEGER) {
100 funcs->margin_left(args, (int)val->value.integer); 100 funcs->margin_left(args, (int)val->integer);
101 } 101 }
102 102
103 val = cxJsonObjGet(value, "margin_right"); 103 val = cxJsonObjGet(value, "margin_right");
104 if(val && val->type == CX_JSON_INTEGER) { 104 if(val && val->type == CX_JSON_INTEGER) {
105 funcs->margin_right(args, (int)val->value.integer); 105 funcs->margin_right(args, (int)val->integer);
106 } 106 }
107 107
108 val = cxJsonObjGet(value, "margin_top"); 108 val = cxJsonObjGet(value, "margin_top");
109 if(val && val->type == CX_JSON_INTEGER) { 109 if(val && val->type == CX_JSON_INTEGER) {
110 funcs->margin_top(args, (int)val->value.integer); 110 funcs->margin_top(args, (int)val->integer);
111 } 111 }
112 112
113 val = cxJsonObjGet(value, "margin_bottom"); 113 val = cxJsonObjGet(value, "margin_bottom");
114 if(val && val->type == CX_JSON_INTEGER) { 114 if(val && val->type == CX_JSON_INTEGER) {
115 funcs->margin_bottom(args, (int)val->value.integer); 115 funcs->margin_bottom(args, (int)val->integer);
116 } 116 }
117 117
118 val = cxJsonObjGet(value, "colspan"); 118 val = cxJsonObjGet(value, "colspan");
119 if(val && val->type == CX_JSON_INTEGER) { 119 if(val && val->type == CX_JSON_INTEGER) {
120 funcs->colspan(args, (int)val->value.integer); 120 funcs->colspan(args, (int)val->integer);
121 } 121 }
122 122
123 val = cxJsonObjGet(value, "rowspan"); 123 val = cxJsonObjGet(value, "rowspan");
124 if(val && val->type == CX_JSON_INTEGER) { 124 if(val && val->type == CX_JSON_INTEGER) {
125 funcs->rowspan(args, (int)val->value.integer); 125 funcs->rowspan(args, (int)val->integer);
126 } 126 }
127 127
128 // string args 128 // string args
129 val = cxJsonObjGet(value, "name"); 129 val = cxJsonObjGet(value, "name");
130 if(val && val->type == CX_JSON_STRING) { 130 if(val && val->type == CX_JSON_STRING) {
131 funcs->name(args, val->value.string.ptr); 131 funcs->name(args, val->string.ptr);
132 } 132 }
133 133
134 val = cxJsonObjGet(value, "style_class"); 134 val = cxJsonObjGet(value, "style_class");
135 if(val && val->type == CX_JSON_STRING) { 135 if(val && val->type == CX_JSON_STRING) {
136 funcs->name(args, val->value.string.ptr); 136 funcs->name(args, val->string.ptr);
137 } 137 }
138 } 138 }
139 139
140 void init_states(const CxJsonValue *value, void *args, argfunc_set_intarray setarray) { 140 void init_states(const CxJsonValue *value, void *args, argfunc_set_intarray setarray) {
141 CxJsonValue *val = cxJsonObjGet(value, "states"); 141 CxJsonValue *val = cxJsonObjGet(value, "states");
142 if(!val || val->type != CX_JSON_ARRAY) { 142 if(!val || val->type != CX_JSON_ARRAY) {
143 return; 143 return;
144 } 144 }
145 145
146 int len = (int)val->value.array.array_size; 146 int len = (int)val->array.size;
147 int *states = calloc(len, sizeof(int)); 147 int *states = calloc(len, sizeof(int));
148 for(int i=0;i<len;i++) { 148 for(int i=0;i<len;i++) {
149 CxJsonValue *s = val->value.array.array[i]; 149 CxJsonValue *s = val->array.data[i];
150 if(s->type == CX_JSON_INTEGER) { 150 if(s->type == CX_JSON_INTEGER) {
151 states[i] = (int)s->value.integer; 151 states[i] = (int)s->integer;
152 } 152 }
153 } 153 }
154 154
155 setarray(args, states, len); 155 setarray(args, states, len);
156 } 156 }
163 163
164 init_common_args(value, args, &container_args); 164 init_common_args(value, args, &container_args);
165 165
166 CxJsonValue *val = cxJsonObjGet(value, "spacing"); 166 CxJsonValue *val = cxJsonObjGet(value, "spacing");
167 if(val && val->type == CX_JSON_INTEGER) { 167 if(val && val->type == CX_JSON_INTEGER) {
168 args->spacing = (int)val->value.integer; 168 args->spacing = (int)val->integer;
169 } 169 }
170 170
171 val = cxJsonObjGet(value, "columnspacing"); 171 val = cxJsonObjGet(value, "columnspacing");
172 if(val && val->type == CX_JSON_INTEGER) { 172 if(val && val->type == CX_JSON_INTEGER) {
173 args->columnspacing = (int)val->value.integer; 173 args->columnspacing = (int)val->integer;
174 } 174 }
175 175
176 val = cxJsonObjGet(value, "rowspacing"); 176 val = cxJsonObjGet(value, "rowspacing");
177 if(val && val->type == CX_JSON_INTEGER) { 177 if(val && val->type == CX_JSON_INTEGER) {
178 args->rowspacing = (int)val->value.integer; 178 args->rowspacing = (int)val->integer;
179 } 179 }
180 180
181 val = cxJsonObjGet(value, "def_hfill"); 181 val = cxJsonObjGet(value, "def_hfill");
182 if(val && val->type == CX_JSON_LITERAL && val->value.literal == CX_JSON_TRUE) { 182 if(val && val->type == CX_JSON_LITERAL && val->literal == CX_JSON_TRUE) {
183 args->def_hfill = TRUE; 183 args->def_hfill = TRUE;
184 } 184 }
185 185
186 val = cxJsonObjGet(value, "def_vfill"); 186 val = cxJsonObjGet(value, "def_vfill");
187 if(val && val->type == CX_JSON_LITERAL && val->value.literal == CX_JSON_TRUE) { 187 if(val && val->type == CX_JSON_LITERAL && val->literal == CX_JSON_TRUE) {
188 args->def_vfill = TRUE; 188 args->def_vfill = TRUE;
189 } 189 }
190 190
191 val = cxJsonObjGet(value, "def_hexpand"); 191 val = cxJsonObjGet(value, "def_hexpand");
192 if(val && val->type == CX_JSON_LITERAL && val->value.literal == CX_JSON_TRUE) { 192 if(val && val->type == CX_JSON_LITERAL && val->literal == CX_JSON_TRUE) {
193 args->def_hexpand = TRUE; 193 args->def_hexpand = TRUE;
194 } 194 }
195 195
196 val = cxJsonObjGet(value, "def_vexpand"); 196 val = cxJsonObjGet(value, "def_vexpand");
197 if(val && val->type == CX_JSON_LITERAL && val->value.literal == CX_JSON_TRUE) { 197 if(val && val->type == CX_JSON_LITERAL && val->literal == CX_JSON_TRUE) {
198 args->def_vexpand = TRUE; 198 args->def_vexpand = TRUE;
199 } 199 }
200 200
201 return args; 201 return args;
202 } 202 }
210 init_common_args(value, args, &button_args); 210 init_common_args(value, args, &button_args);
211 init_states(value, args, (argfunc_set_intarray)ui_button_args_set_states); 211 init_states(value, args, (argfunc_set_intarray)ui_button_args_set_states);
212 212
213 CxJsonValue *val = cxJsonObjGet(value, "label"); 213 CxJsonValue *val = cxJsonObjGet(value, "label");
214 if(val && val->type == CX_JSON_STRING) { 214 if(val && val->type == CX_JSON_STRING) {
215 ui_button_args_set_label(args, val->value.string.ptr); 215 ui_button_args_set_label(args, val->string.ptr);
216 } 216 }
217 217
218 val = cxJsonObjGet(value, "icon"); 218 val = cxJsonObjGet(value, "icon");
219 if(val && val->type == CX_JSON_STRING) { 219 if(val && val->type == CX_JSON_STRING) {
220 ui_button_args_set_icon(args, val->value.string.ptr); 220 ui_button_args_set_icon(args, val->string.ptr);
221 } 221 }
222 222
223 val = cxJsonObjGet(value, "tooltip"); 223 val = cxJsonObjGet(value, "tooltip");
224 if(val && val->type == CX_JSON_STRING) { 224 if(val && val->type == CX_JSON_STRING) {
225 ui_button_args_set_tooltip(args, val->value.string.ptr); 225 ui_button_args_set_tooltip(args, val->string.ptr);
226 } 226 }
227 227
228 val = cxJsonObjGet(value, "labeltype"); 228 val = cxJsonObjGet(value, "labeltype");
229 if(val && val->type == CX_JSON_INTEGER) { 229 if(val && val->type == CX_JSON_INTEGER) {
230 ui_button_args_set_labeltype(args, (int)val->value.integer); 230 ui_button_args_set_labeltype(args, (int)val->integer);
231 } 231 }
232 232
233 return args; 233 return args;
234 } 234 }
235 235
242 init_common_args(value, args, &button_args); 242 init_common_args(value, args, &button_args);
243 init_states(value, args, (argfunc_set_intarray)ui_button_args_set_states); 243 init_states(value, args, (argfunc_set_intarray)ui_button_args_set_states);
244 244
245 CxJsonValue *val = cxJsonObjGet(value, "label"); 245 CxJsonValue *val = cxJsonObjGet(value, "label");
246 if(val && val->type == CX_JSON_STRING) { 246 if(val && val->type == CX_JSON_STRING) {
247 ui_toggle_args_set_label(args, val->value.string.ptr); 247 ui_toggle_args_set_label(args, val->string.ptr);
248 } 248 }
249 249
250 val = cxJsonObjGet(value, "icon"); 250 val = cxJsonObjGet(value, "icon");
251 if(val && val->type == CX_JSON_STRING) { 251 if(val && val->type == CX_JSON_STRING) {
252 ui_toggle_args_set_icon(args, val->value.string.ptr); 252 ui_toggle_args_set_icon(args, val->string.ptr);
253 } 253 }
254 254
255 val = cxJsonObjGet(value, "tooltip"); 255 val = cxJsonObjGet(value, "tooltip");
256 if(val && val->type == CX_JSON_STRING) { 256 if(val && val->type == CX_JSON_STRING) {
257 ui_toggle_args_set_tooltip(args, val->value.string.ptr); 257 ui_toggle_args_set_tooltip(args, val->string.ptr);
258 } 258 }
259 259
260 val = cxJsonObjGet(value, "labeltype"); 260 val = cxJsonObjGet(value, "labeltype");
261 if(val && val->type == CX_JSON_INTEGER) { 261 if(val && val->type == CX_JSON_INTEGER) {
262 ui_toggle_args_set_labeltype(args, (int)val->value.integer); 262 ui_toggle_args_set_labeltype(args, (int)val->integer);
263 } 263 }
264 264
265 val = cxJsonObjGet(value, "enable_group"); 265 val = cxJsonObjGet(value, "enable_group");
266 if(val && val->type == CX_JSON_INTEGER) { 266 if(val && val->type == CX_JSON_INTEGER) {
267 ui_toggle_args_set_enablestate(args, (int)val->value.integer); 267 ui_toggle_args_set_enablestate(args, (int)val->integer);
268 } 268 }
269 269
270 return args; 270 return args;
271 } 271 }

mercurial