client/uiclient.c

changeset 948
94bc57d63128
parent 944
cc23aad6335e
child 953
c98404829cd3
equal deleted inserted replaced
947:a335a12936ce 948:94bc57d63128
48 cxMapPut(msg_types, "vbox", msg_vbox); 48 cxMapPut(msg_types, "vbox", msg_vbox);
49 cxMapPut(msg_types, "hbox", msg_vbox); 49 cxMapPut(msg_types, "hbox", msg_vbox);
50 cxMapPut(msg_types, "grid", msg_vbox); 50 cxMapPut(msg_types, "grid", msg_vbox);
51 cxMapPut(msg_types, "end", msg_end); 51 cxMapPut(msg_types, "end", msg_end);
52 cxMapPut(msg_types, "button", msg_button); 52 cxMapPut(msg_types, "button", msg_button);
53 cxMapPut(msg_types, "toggle", msg_togglebutton);
53 54
54 objects = cxHashMapCreateSimple(CX_STORE_POINTERS); 55 objects = cxHashMapCreateSimple(CX_STORE_POINTERS);
55 } 56 }
56 57
57 static cxmutstr jsonobj_getstring(const CxJsonValue *obj, const char *name) { 58 static cxmutstr jsonobj_getstring(const CxJsonValue *obj, const char *name) {
250 ui_button_args_free(args); 251 ui_button_args_free(args);
251 client_reg_widget(obj, id, w); 252 client_reg_widget(obj, id, w);
252 253
253 return 0; 254 return 0;
254 } 255 }
256
257 int msg_togglebutton(UiObject *parent, const CxJsonValue *value) {
258 CxJsonValue *args_value = cxJsonObjGet(value, "args");
259 cxmutstr id = jsonobj_getstring(value, "id");
260 if(!id.ptr) {
261 return 1;
262 }
263 UiObject *obj = get_msg_obj(parent, value);
264 if(!obj) {
265 return 1;
266 }
267
268 CxJsonValue *button_type = cxJsonObjGet(value, "button_type");
269 if(!button_type || button_type->type != CX_JSON_INTEGER) {
270 return 1;
271 }
272
273 CxJsonValue *val = cxJsonObjGet(value, "value");
274 UiInteger *i = NULL;
275 if(val && val->type == CX_JSON_STRING) {
276 i = ui_int_new(obj->ctx, val->value.string.ptr);
277 }
278
279 UiToggleArgs *args = json2toggle_args(args_value);
280 UIWIDGET w;
281 switch(button_type->value.integer) {
282 default: {
283 w = ui_togglebutton_create(obj, args);
284 break;
285 }
286 case 1: {
287 w = ui_checkbox_create(obj, args);
288 break;
289 }
290 case 2: {
291 w = ui_switch_create(obj, args);
292 break;
293 }
294 }
295 ui_toggle_args_free(args);
296 client_reg_widget(obj, id, w);
297
298 return 0;
299 }

mercurial