ui/gtk/button.c

changeset 97
5a3d27b8e6b0
parent 60
ee4e4742391e
child 100
d2bd73d28ff1
--- a/ui/gtk/button.c	Wed Nov 27 18:53:11 2024 +0100
+++ b/ui/gtk/button.c	Thu Nov 28 18:03:12 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) {

mercurial