| 43 static CxMap *objects; |
43 static CxMap *objects; |
| 44 |
44 |
| 45 void client_init(UiMessageHandler *handler) { |
45 void client_init(UiMessageHandler *handler) { |
| 46 io = handler; |
46 io = handler; |
| 47 |
47 |
| 48 msg_types = cxHashMapCreateSimple(CX_STORE_POINTERS); |
48 msg_types = cxHashMapCreate(NULL, CX_STORE_POINTERS, 32); |
| 49 cxMapPut(msg_types, "window", msg_window); |
49 cxMapPut(msg_types, "window", msg_window); |
| 50 cxMapPut(msg_types, "sidebar_window", msg_window); |
50 cxMapPut(msg_types, "sidebar_window", msg_window); |
| 51 cxMapPut(msg_types, "splitview_window", msg_window); |
51 cxMapPut(msg_types, "splitview_window", msg_window); |
| 52 cxMapPut(msg_types, "simple_window", msg_window); |
52 cxMapPut(msg_types, "simple_window", msg_window); |
| 53 cxMapPut(msg_types, "show", msg_show); |
53 cxMapPut(msg_types, "show", msg_show); |
| 57 cxMapPut(msg_types, "grid", msg_vbox); |
57 cxMapPut(msg_types, "grid", msg_vbox); |
| 58 cxMapPut(msg_types, "end", msg_end); |
58 cxMapPut(msg_types, "end", msg_end); |
| 59 cxMapPut(msg_types, "button", msg_button); |
59 cxMapPut(msg_types, "button", msg_button); |
| 60 cxMapPut(msg_types, "toggle", msg_togglebutton); |
60 cxMapPut(msg_types, "toggle", msg_togglebutton); |
| 61 |
61 |
| 62 objects = cxHashMapCreateSimple(CX_STORE_POINTERS); |
62 objects = cxHashMapCreate(NULL, CX_STORE_POINTERS, 16); |
| 63 } |
63 } |
| 64 |
64 |
| 65 static cxmutstr jsonobj_getstring(const CxJsonValue *obj, const char *name) { |
65 static cxmutstr jsonobj_getstring(const CxJsonValue *obj, const char *name) { |
| 66 CxJsonValue *value = cxJsonObjGet(obj, name); |
66 CxJsonValue *value = cxJsonObjGet(obj, name); |
| 67 if(value->type == CX_JSON_STRING) { |
67 if(value->type == CX_JSON_STRING) { |
| 68 return value->value.string; |
68 return value->string; |
| 69 } else { |
69 } else { |
| 70 return (cxmutstr){ NULL, 0 }; |
70 return (cxmutstr){ NULL, 0 }; |
| 71 } |
71 } |
| 72 } |
72 } |
| 73 |
73 |
| 125 CxJsonValue *type = cxJsonObjGet(value, "type"); |
125 CxJsonValue *type = cxJsonObjGet(value, "type"); |
| 126 if(!type || type->type != CX_JSON_STRING) { |
126 if(!type || type->type != CX_JSON_STRING) { |
| 127 return 1; |
127 return 1; |
| 128 } |
128 } |
| 129 |
129 |
| 130 json_msg_handler handler = cxMapGet(msg_types, type->value.string); |
130 json_msg_handler handler = cxMapGet(msg_types, type->string); |
| 131 if(!handler) { |
131 if(!handler) { |
| 132 return 1; |
132 return 1; |
| 133 } |
133 } |
| 134 |
134 |
| 135 return handler(obj, value, type->value.string); |
135 return handler(obj, value, type->string); |
| 136 } |
136 } |
| 137 |
137 |
| 138 int client_handle_children(UiObject *parent, const CxJsonValue *value) { |
138 int client_handle_children(UiObject *parent, const CxJsonValue *value) { |
| 139 CxJsonValue *children = cxJsonObjGet(value, "children"); |
139 CxJsonValue *children = cxJsonObjGet(value, "children"); |
| 140 if(children && children->type == CX_JSON_ARRAY) { |
140 if(children && children->type == CX_JSON_ARRAY) { |
| 141 for(int i=0;i<children->value.array.array_size;i++) { |
141 for(int i=0;i<children->array.size;i++) { |
| 142 CxJsonValue *child = children->value.array.array[i]; |
142 CxJsonValue *child = children->array.data[i]; |
| 143 if(client_handle_json(parent, child)) { |
143 if(client_handle_json(parent, child)) { |
| 144 fprintf(stderr, "Error: invalid child\n"); |
144 fprintf(stderr, "Error: invalid child\n"); |
| 145 return 1; |
145 return 1; |
| 146 } |
146 } |
| 147 } |
147 } |
| 187 } |
187 } |
| 188 CxJsonValue *obj_id = cxJsonObjGet(value, "obj"); |
188 CxJsonValue *obj_id = cxJsonObjGet(value, "obj"); |
| 189 if(!obj_id || obj_id->type != CX_JSON_STRING) { |
189 if(!obj_id || obj_id->type != CX_JSON_STRING) { |
| 190 return NULL; |
190 return NULL; |
| 191 } |
191 } |
| 192 return client_get_mapped_obj(obj_id->value.string); |
192 return client_get_mapped_obj(obj_id->string); |
| 193 } |
193 } |
| 194 |
194 |
| 195 int msg_window(UiObject *parent, const CxJsonValue *value, cxmutstr type) { |
195 int msg_window(UiObject *parent, const CxJsonValue *value, cxmutstr type) { |
| 196 cxmutstr obj_id = jsonobj_getstring(value, "obj"); |
196 cxmutstr obj_id = jsonobj_getstring(value, "obj"); |
| 197 cxmutstr id = jsonobj_getstring(value, "id"); |
197 cxmutstr id = jsonobj_getstring(value, "id"); |
| 316 } |
316 } |
| 317 |
317 |
| 318 CxJsonValue *val = cxJsonObjGet(value, "value"); |
318 CxJsonValue *val = cxJsonObjGet(value, "value"); |
| 319 UiInteger *i = NULL; |
319 UiInteger *i = NULL; |
| 320 if(val && val->type == CX_JSON_STRING) { |
320 if(val && val->type == CX_JSON_STRING) { |
| 321 i = ui_get_int_var(obj->ctx, val->value.string.ptr); |
321 i = ui_get_int_var(obj->ctx, val->string.ptr); |
| 322 if(!i) { |
322 if(!i) { |
| 323 i = ui_int_new(obj->ctx, val->value.string.ptr); |
323 i = ui_int_new(obj->ctx, val->string.ptr); |
| 324 } |
324 } |
| 325 } |
325 } |
| 326 |
326 |
| 327 UiToggleArgs *args = json2toggle_args(args_value); |
327 UiToggleArgs *args = json2toggle_args(args_value); |
| 328 UIWIDGET w; |
328 UIWIDGET w; |
| 329 switch(button_type->value.integer) { |
329 switch(button_type->integer) { |
| 330 default: { |
330 default: { |
| 331 w = ui_togglebutton_create(obj, args); |
331 w = ui_togglebutton_create(obj, args); |
| 332 break; |
332 break; |
| 333 } |
333 } |
| 334 case 1: { |
334 case 1: { |