Thu, 28 Nov 2024 18:05:51 +0100
safely unbind radio buttons (GTK)
ui/gtk/button.c | file | annotate | diff | comparison | revisions |
--- a/ui/gtk/button.c Thu Nov 28 18:05:31 2024 +0100 +++ b/ui/gtk/button.c Thu Nov 28 18:05:51 2024 +0100 @@ -391,6 +391,23 @@ event->callback(&e, event->userdata); } +typedef struct UiRadioButtonData { + UiInteger *value; + UiVarEventData *eventdata; + UiBool first; +} UiRadioButtonData; + +static void destroy_radiobutton(GtkWidget *w, UiRadioButtonData *data) { + ui_destroy_vardata(w, data->eventdata); + if(data->first) { + g_slist_free(data->value->obj); + data->value->obj = NULL; + data->value->get = NULL; + data->value->set = NULL; + } + free(data); +} + UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs args) { UiObject* current = uic_current_obj(obj); @@ -435,18 +452,21 @@ event->callback = NULL; event->userdata = NULL; + UiRadioButtonData *rbdata = malloc(sizeof(UiRadioButtonData)); + rbdata->value = rgroup; + rbdata->eventdata = event; + rbdata->first = first; + g_signal_connect( rbutton, "toggled", G_CALLBACK(ui_radio_obs), event); - if(first) { - g_signal_connect( + g_signal_connect( rbutton, "destroy", - G_CALLBACK(ui_destroy_vardata), - event); - } + G_CALLBACK(destroy_radiobutton), + rbdata); } if(args.onchange) {