| 380 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs *args) { |
380 UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs *args) { |
| 381 return togglebutton_create(obj, gtk_check_button_new(), args); |
381 return togglebutton_create(obj, gtk_check_button_new(), args); |
| 382 } |
382 } |
| 383 #endif |
383 #endif |
| 384 |
384 |
| |
385 |
| |
386 #if GTK_MAJOR_VERSION >= 3 |
| |
387 |
| |
388 static void switch_changed( |
| |
389 GObject *gobject, |
| |
390 GParamSpec *pspec, |
| |
391 UiVarEventData *event) |
| |
392 { |
| |
393 GtkSwitch *sw = GTK_SWITCH (gobject); |
| |
394 gboolean active = gtk_switch_get_active (sw); |
| |
395 |
| |
396 UiEvent e; |
| |
397 e.obj = event->obj; |
| |
398 e.document = e.obj->ctx->document; |
| |
399 e.window = e.obj->window; |
| |
400 e.eventdata = NULL; |
| |
401 e.eventdatatype = 0; |
| |
402 e.set = ui_get_setop(); |
| |
403 |
| |
404 if(event->callback) { |
| |
405 event->callback(&e, event->userdata); |
| |
406 } |
| |
407 if(event->var) { |
| |
408 UiInteger *i = event->var->value; |
| |
409 ui_notify_evt(i->observers, &e); |
| |
410 } |
| |
411 } |
| |
412 |
| 385 UIWIDGET ui_switch_create(UiObject* obj, UiToggleArgs *args) { |
413 UIWIDGET ui_switch_create(UiObject* obj, UiToggleArgs *args) { |
| 386 #ifdef UI_GTK3 |
414 UiObject* current = uic_current_obj(obj); |
| 387 return NULL; // TODO |
415 GtkWidget *widget = gtk_switch_new(); |
| |
416 ui_set_name_and_style(widget, args->name, args->style_class); |
| |
417 ui_set_widget_groups(obj->ctx, widget, args->groups); |
| |
418 |
| |
419 UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->value, args->varname, UI_VAR_INTEGER); |
| |
420 if(var) { |
| |
421 UiInteger *value = var->value; |
| |
422 value->obj = widget; |
| |
423 value->get = ui_switch_get; |
| |
424 value->set = ui_switch_set; |
| |
425 |
| |
426 if(value->value) { |
| |
427 gtk_switch_set_active(GTK_SWITCH(widget), TRUE); |
| |
428 } |
| |
429 |
| |
430 |
| |
431 } |
| |
432 |
| |
433 UiVarEventData *event = malloc(sizeof(UiVarEventData)); |
| |
434 event->obj = obj; |
| |
435 event->callback = args->onchange; |
| |
436 event->userdata = args->onchangedata; |
| |
437 event->var = var; |
| |
438 event->observers = NULL; |
| |
439 |
| |
440 g_signal_connect( |
| |
441 widget, |
| |
442 "notify::active", |
| |
443 G_CALLBACK(switch_changed), |
| |
444 event); |
| |
445 |
| |
446 g_signal_connect( |
| |
447 widget, |
| |
448 "destroy", |
| |
449 G_CALLBACK(ui_destroy_vardata), |
| |
450 event); |
| |
451 |
| |
452 UI_APPLY_LAYOUT2(current, args); |
| |
453 current->container->add(current->container, widget); |
| |
454 |
| |
455 return widget; |
| |
456 } |
| |
457 |
| |
458 int64_t ui_switch_get(UiInteger *value) { |
| |
459 GtkSwitch *sw = GTK_SWITCH((GtkWidget*)value->obj); |
| |
460 value->value = gtk_switch_get_active(sw); |
| |
461 return value->value; |
| |
462 } |
| |
463 |
| |
464 void ui_switch_set(UiInteger *value, int64_t i) { |
| |
465 GtkSwitch *sw = GTK_SWITCH((GtkWidget*)value->obj); |
| |
466 value->value = i; |
| |
467 gtk_switch_set_active(sw, i); |
| |
468 } |
| |
469 |
| 388 #else |
470 #else |
| |
471 |
| |
472 UIWIDGET ui_switch_create(UiObject* obj, UiToggleArgs *args) { |
| 389 return ui_checkbox_create(obj, args); |
473 return ui_checkbox_create(obj, args); |
| |
474 } |
| |
475 |
| 390 #endif |
476 #endif |
| 391 } |
|
| 392 |
477 |
| 393 #if GTK_MAJOR_VERSION >= 4 |
478 #if GTK_MAJOR_VERSION >= 4 |
| 394 #define RADIOBUTTON_NEW(group, label) gtk_check_button_new_with_label(label) |
479 #define RADIOBUTTON_NEW(group, label) gtk_check_button_new_with_label(label) |
| 395 #define RADIOBUTTON_SET_GROUP(button, group) |
480 #define RADIOBUTTON_SET_GROUP(button, group) |
| 396 #define RADIOBUTTON_GET_GROUP(button) GTK_CHECK_BUTTON(button) |
481 #define RADIOBUTTON_GET_GROUP(button) GTK_CHECK_BUTTON(button) |
| 758 "activate-link", |
843 "activate-link", |
| 759 G_CALLBACK(linkbutton_activate_link), |
844 G_CALLBACK(linkbutton_activate_link), |
| 760 data); |
845 data); |
| 761 } |
846 } |
| 762 gtk_button_set_label(GTK_BUTTON(button), args->label); |
847 gtk_button_set_label(GTK_BUTTON(button), args->label); |
| |
848 #if GTK_CHECK_VERSION(4, 0, 0) |
| |
849 gtk_button_set_can_shrink(GTK_BUTTON(button), TRUE); |
| |
850 #elif GTK_MAJOR_VERSION == 3 |
| |
851 GtkWidget *child = gtk_bin_get_child(GTK_BIN(button)); |
| |
852 gtk_label_set_ellipsize(GTK_LABEL(child), PANGO_ELLIPSIZE_END); |
| |
853 #endif |
| 763 g_object_set_data(G_OBJECT(button), "ui_linkbutton", data); |
854 g_object_set_data(G_OBJECT(button), "ui_linkbutton", data); |
| 764 g_signal_connect( |
855 g_signal_connect( |
| 765 button, |
856 button, |
| 766 "destroy", |
857 "destroy", |
| 767 G_CALLBACK(ui_destroy_linkbutton), |
858 G_CALLBACK(ui_destroy_linkbutton), |
| 804 void ui_linkbutton_set(UiString *s, const char *str) { |
895 void ui_linkbutton_set(UiString *s, const char *str) { |
| 805 linkbutton_apply_value(s->obj, str); |
896 linkbutton_apply_value(s->obj, str); |
| 806 if(s->value.free) { |
897 if(s->value.free) { |
| 807 s->value.free(s->value.ptr); |
898 s->value.free(s->value.ptr); |
| 808 } |
899 } |
| |
900 #if GTK_MAJOR_VERSION == 3 |
| |
901 UiLinkButton *data = s->obj; |
| |
902 GtkWidget *child = gtk_bin_get_child(GTK_BIN(data->widget)); |
| |
903 gtk_label_set_ellipsize(GTK_LABEL(child), PANGO_ELLIPSIZE_END); |
| |
904 #endif |
| 809 } |
905 } |
| 810 |
906 |
| 811 |
907 |
| 812 void ui_linkbutton_value_set(UiString *str, const char *label, const char *uri) { |
908 void ui_linkbutton_value_set(UiString *str, const char *label, const char *uri) { |
| 813 char *value = create_linkbutton_jsonvalue(label, uri, TRUE, FALSE, TRUE); |
909 char *value = create_linkbutton_jsonvalue(label, uri, TRUE, FALSE, TRUE); |