ui/motif/button.c

branch
newapi
changeset 419
7d15cad351fc
parent 406
0ebf9d7b23e8
equal deleted inserted replaced
418:a57268d20ed9 419:7d15cad351fc
289 if(value) { 289 if(value) {
290 ui_notify_evt(value->observers, &e); 290 ui_notify_evt(value->observers, &e);
291 } 291 }
292 } 292 }
293 293
294 void ui_bind_radiobutton(UiObject *obj, Widget rbutton, UiInteger *value, const char *varname, ui_callback onchange, void *onchangedata, int enable_group) {
295 UiVar* var = uic_widget_var(obj->ctx, obj->ctx, value, varname, UI_VAR_INTEGER);
296 if(var) {
297 UiInteger *value = var->value;
298 CxList *rb = value->obj;
299 if(!rb) {
300 // first button in the radiobutton group
301 // create a list for all buttons and use the list as value obj
302 rb = cxArrayListCreateSimple(CX_STORE_POINTERS, 4);
303 value->obj = rb;
304 value->get = ui_radiobutton_get;
305 value->set = ui_radiobutton_set;
306
307 // the first radio button is also responsible for cleanup
308 XtAddCallback(
309 rbutton,
310 XmNdestroyCallback,
311 (XtCallbackProc)destroy_list,
312 rb);
313 }
314 cxListAdd(rb, rbutton);
315
316 // set the radiobutton state, if the value is already set
317 if(cxListSize(rb) == value->value) {
318 XmToggleButtonSetState(rbutton, True, False);
319 }
320 }
321
322 // the radio button needs to handle change events to update all
323 // other buttons in the radio button group
324 UiVarEventData *event = malloc(sizeof(UiVarEventData));
325 event->obj = obj;
326 event->callback = onchange;
327 event->userdata = onchangedata;
328 event->observers = NULL;
329 event->var = var;
330 event->value = enable_group;
331 XtAddCallback(
332 rbutton,
333 XmNvalueChangedCallback,
334 (XtCallbackProc)radiobutton_changed,
335 event);
336 XtAddCallback(
337 rbutton,
338 XmNdestroyCallback,
339 (XtCallbackProc)ui_destroy_eventdata,
340 event);
341 }
342
294 UIWIDGET ui_radiobutton_create(UiObject* obj, UiToggleArgs args) { 343 UIWIDGET ui_radiobutton_create(UiObject* obj, UiToggleArgs args) {
295 Arg xargs[16]; 344 Arg xargs[16];
296 int n = 0; 345 int n = 0;
297 346
298 UiContainerPrivate *ctn = ui_obj_container(obj); 347 UiContainerPrivate *ctn = ui_obj_container(obj);

mercurial