| 94 } |
94 } |
| 95 |
95 |
| 96 return button; |
96 return button; |
| 97 } |
97 } |
| 98 |
98 |
| 99 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs args) { |
99 UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs *args) { |
| 100 UiObject* current = uic_current_obj(obj); |
100 UiObject* current = uic_current_obj(obj); |
| 101 GtkWidget *button = ui_create_button(obj, args.label, args.icon, args.onclick, args.onclickdata, 0, FALSE); |
101 GtkWidget *button = ui_create_button(obj, args->label, args->icon, args->onclick, args->onclickdata, 0, FALSE); |
| 102 ui_set_name_and_style(button, args.name, args.style_class); |
102 ui_set_name_and_style(button, args->name, args->style_class); |
| 103 ui_set_widget_groups(obj->ctx, button, args.groups); |
103 ui_set_widget_groups(obj->ctx, button, args->groups); |
| 104 UI_APPLY_LAYOUT1(current, args); |
104 UI_APPLY_LAYOUT2(current, args); |
| 105 current->container->add(current->container, button, FALSE); |
105 current->container->add(current->container, button, FALSE); |
| 106 return button; |
106 return button; |
| 107 } |
107 } |
| 108 |
108 |
| 109 |
109 |
| 272 G_CALLBACK(ui_destroy_userdata), |
272 G_CALLBACK(ui_destroy_userdata), |
| 273 event); |
273 event); |
| 274 } |
274 } |
| 275 } |
275 } |
| 276 |
276 |
| 277 static UIWIDGET togglebutton_create(UiObject *obj, GtkWidget *widget, UiToggleArgs args) { |
277 static UIWIDGET togglebutton_create(UiObject *obj, GtkWidget *widget, UiToggleArgs *args) { |
| 278 UiObject* current = uic_current_obj(obj); |
278 UiObject* current = uic_current_obj(obj); |
| 279 |
279 |
| 280 ui_setup_togglebutton( |
280 ui_setup_togglebutton( |
| 281 obj, |
281 obj, |
| 282 widget, |
282 widget, |
| 283 args.label, |
283 args->label, |
| 284 args.icon, |
284 args->icon, |
| 285 args.varname, |
285 args->varname, |
| 286 args.value, |
286 args->value, |
| 287 args.onchange, |
287 args->onchange, |
| 288 args.onchangedata, |
288 args->onchangedata, |
| 289 args.enable_group); |
289 args->enable_group); |
| 290 ui_set_name_and_style(widget, args.name, args.style_class); |
290 ui_set_name_and_style(widget, args->name, args->style_class); |
| 291 ui_set_widget_groups(obj->ctx, widget, args.groups); |
291 ui_set_widget_groups(obj->ctx, widget, args->groups); |
| 292 |
292 |
| 293 UI_APPLY_LAYOUT1(current, args); |
293 UI_APPLY_LAYOUT2(current, args); |
| 294 current->container->add(current->container, widget, FALSE); |
294 current->container->add(current->container, widget, FALSE); |
| 295 |
295 |
| 296 return widget; |
296 return widget; |
| 297 } |
297 } |
| 298 |
298 |
| 299 UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs args) { |
299 UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs *args) { |
| 300 return togglebutton_create(obj, gtk_toggle_button_new(), args); |
300 return togglebutton_create(obj, gtk_toggle_button_new(), args); |
| 301 } |
301 } |
| 302 |
302 |
| 303 #if GTK_MAJOR_VERSION >= 4 |
303 #if GTK_MAJOR_VERSION >= 4 |
| 304 |
304 |
| 331 } else { |
331 } else { |
| 332 ui_unset_group(event->obj->ctx, event->value); |
332 ui_unset_group(event->obj->ctx, event->value); |
| 333 } |
333 } |
| 334 } |
334 } |
| 335 |
335 |
| 336 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { |
336 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs *args) { |
| 337 UiObject* current = uic_current_obj(obj); |
337 UiObject* current = uic_current_obj(obj); |
| 338 |
338 |
| 339 GtkWidget *widget = gtk_check_button_new_with_label(args.label); |
339 GtkWidget *widget = gtk_check_button_new_with_label(args->label); |
| 340 ui_bind_togglebutton( |
340 ui_bind_togglebutton( |
| 341 obj, |
341 obj, |
| 342 widget, |
342 widget, |
| 343 ui_check_button_get, |
343 ui_check_button_get, |
| 344 ui_check_button_set, |
344 ui_check_button_set, |
| 345 args.varname, |
345 args->varname, |
| 346 args.value, |
346 args->value, |
| 347 (ui_toggled_func)ui_checkbox_callback, |
347 (ui_toggled_func)ui_checkbox_callback, |
| 348 args.onchange, |
348 args->onchange, |
| 349 args.onchangedata, |
349 args->onchangedata, |
| 350 (ui_toggled_func)ui_checkbox_enable_state, |
350 (ui_toggled_func)ui_checkbox_enable_state, |
| 351 args.enable_group); |
351 args->enable_group); |
| 352 |
352 |
| 353 ui_set_name_and_style(widget, args.name, args.style_class); |
353 ui_set_name_and_style(widget, args->name, args->style_class); |
| 354 ui_set_widget_groups(obj->ctx, widget, args.groups); |
354 ui_set_widget_groups(obj->ctx, widget, args->groups); |
| 355 |
355 |
| 356 UI_APPLY_LAYOUT1(current, args); |
356 UI_APPLY_LAYOUT2(current, args); |
| 357 current->container->add(current->container, widget, FALSE); |
357 current->container->add(current->container, widget, FALSE); |
| 358 |
358 |
| 359 return widget; |
359 return widget; |
| 360 } |
360 } |
| 361 |
361 |
| 362 #else |
362 #else |
| 363 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) { |
363 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs *args) { |
| 364 return togglebutton_create(obj, gtk_check_button_new(), args); |
364 return togglebutton_create(obj, gtk_check_button_new(), args); |
| 365 } |
365 } |
| 366 #endif |
366 #endif |
| 367 |
367 |
| 368 UIWIDGET ui_switch_create(UiObject* obj, UiToggleArgs args) { |
368 UIWIDGET ui_switch_create(UiObject* obj, UiToggleArgs *args) { |
| 369 #ifdef UI_GTK3 |
369 #ifdef UI_GTK3 |
| 370 return NULL; // TODO |
370 return NULL; // TODO |
| 371 #else |
371 #else |
| 372 return ui_checkbox_create(obj, args); |
372 return ui_checkbox_create(obj, args); |
| 373 #endif |
373 #endif |
| 413 free(data->eventdata); |
413 free(data->eventdata); |
| 414 } |
414 } |
| 415 free(data); |
415 free(data); |
| 416 } |
416 } |
| 417 |
417 |
| 418 UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs args) { |
418 UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs *args) { |
| 419 UiObject* current = uic_current_obj(obj); |
419 UiObject* current = uic_current_obj(obj); |
| 420 |
420 |
| 421 GSList *rg = NULL; |
421 GSList *rg = NULL; |
| 422 UiInteger *rgroup; |
422 UiInteger *rgroup; |
| 423 |
423 |
| 424 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER); |
424 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->value, args->varname, UI_VAR_INTEGER); |
| 425 |
425 |
| 426 UiBool first = FALSE; |
426 UiBool first = FALSE; |
| 427 if(var) { |
427 if(var) { |
| 428 rgroup = var->value; |
428 rgroup = var->value; |
| 429 rg = rgroup->obj; |
429 rg = rgroup->obj; |
| 430 if(!rg) { |
430 if(!rg) { |
| 431 first = TRUE; |
431 first = TRUE; |
| 432 } |
432 } |
| 433 } |
433 } |
| 434 |
434 |
| 435 GtkWidget *rbutton = RADIOBUTTON_NEW(rg, args.label); |
435 GtkWidget *rbutton = RADIOBUTTON_NEW(rg, args->label); |
| 436 ui_set_name_and_style(rbutton, args.name, args.style_class); |
436 ui_set_name_and_style(rbutton, args->name, args->style_class); |
| 437 ui_set_widget_groups(obj->ctx, rbutton, args.groups); |
437 ui_set_widget_groups(obj->ctx, rbutton, args->groups); |
| 438 if(rgroup) { |
438 if(rgroup) { |
| 439 #if GTK_MAJOR_VERSION >= 4 |
439 #if GTK_MAJOR_VERSION >= 4 |
| 440 if(rg) { |
440 if(rg) { |
| 441 gtk_check_button_set_group(GTK_CHECK_BUTTON(rbutton), rg->data); |
441 gtk_check_button_set_group(GTK_CHECK_BUTTON(rbutton), rg->data); |
| 442 } |
442 } |
| 474 "destroy", |
474 "destroy", |
| 475 G_CALLBACK(destroy_radiobutton), |
475 G_CALLBACK(destroy_radiobutton), |
| 476 rbdata); |
476 rbdata); |
| 477 } |
477 } |
| 478 |
478 |
| 479 if(args.onchange) { |
479 if(args->onchange) { |
| 480 UiEventData *event = malloc(sizeof(UiEventData)); |
480 UiEventData *event = malloc(sizeof(UiEventData)); |
| 481 event->obj = obj; |
481 event->obj = obj; |
| 482 event->userdata = args.onchangedata; |
482 event->userdata = args->onchangedata; |
| 483 event->callback = args.onchange; |
483 event->callback = args->onchange; |
| 484 event->value = 0; |
484 event->value = 0; |
| 485 event->customdata = NULL; |
485 event->customdata = NULL; |
| 486 |
486 |
| 487 g_signal_connect( |
487 g_signal_connect( |
| 488 rbutton, |
488 rbutton, |