47 |
47 |
48 UiContainerPrivate *ctn = ui_obj_container(obj); |
48 UiContainerPrivate *ctn = ui_obj_container(obj); |
49 UI_APPLY_LAYOUT(ctn->layout, args); |
49 UI_APPLY_LAYOUT(ctn->layout, args); |
50 |
50 |
51 Widget parent = ctn->prepare(ctn, xargs, &n); |
51 Widget parent = ctn->prepare(ctn, xargs, &n); |
52 |
52 |
53 XmString label = NULL; |
53 XmString label = NULL; |
54 if(args.label) { |
54 if(args.label) { |
55 label = XmStringCreateLocalized((char*)args.label); |
55 label = XmStringCreateLocalized((char*)args.label); |
56 XtSetArg(xargs[n], XmNlabelString, label); n++; |
56 XtSetArg(xargs[n], XmNlabelString, label); n++; |
57 } |
57 } |
237 i->value = value; |
237 i->value = value; |
238 XmToggleButtonSetState(togglebutton, (Boolean)value, False); |
238 XmToggleButtonSetState(togglebutton, (Boolean)value, False); |
239 } |
239 } |
240 |
240 |
241 static void destroy_list(Widget w, CxList *list, XtPointer d) { |
241 static void destroy_list(Widget w, CxList *list, XtPointer d) { |
242 cxListDestroy(list); |
242 cxListFree(list); |
243 } |
243 } |
244 |
244 |
245 static void radiobutton_changed(Widget w, UiVarEventData *event, XmToggleButtonCallbackStruct *tb) { |
245 static void radiobutton_changed(Widget w, UiVarEventData *event, XmToggleButtonCallbackStruct *tb) { |
246 if(event->value > 0) { |
246 if(event->value > 0) { |
247 // button in configured to enable/disable states |
247 // button in configured to enable/disable states |
287 } |
287 } |
288 |
288 |
289 if(value) { |
289 if(value) { |
290 ui_notify_evt(value->observers, &e); |
290 ui_notify_evt(value->observers, &e); |
291 } |
291 } |
|
292 } |
|
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); |
292 } |
341 } |
293 |
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; |