ui/gtk/button.c

changeset 108
77254bd6dccb
parent 103
6606616eca9f
child 109
c3dfcb8f0be7
--- a/ui/gtk/button.c	Sat Apr 05 17:57:04 2025 +0200
+++ b/ui/gtk/button.c	Sun Jul 20 22:04:39 2025 +0200
@@ -73,6 +73,7 @@
         event->callback = onclick;
         event->value = event_value;
         event->customdata = NULL;
+        event->customint = 0;
 
         g_signal_connect(
                 button,
@@ -96,13 +97,13 @@
     return button;
 }
 
-UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs args) {
+UIWIDGET ui_button_create(UiObject *obj, UiButtonArgs *args) {
     UiObject* current = uic_current_obj(obj);
-    GtkWidget *button = ui_create_button(obj, args.label, args.icon, args.onclick, args.onclickdata, 0, FALSE);
-    ui_set_name_and_style(button, args.name, args.style_class);
-    ui_set_widget_groups(obj->ctx, button, args.groups);
-    UI_APPLY_LAYOUT1(current, args);
-    current->container->add(current->container, button, FALSE);
+    GtkWidget *button = ui_create_button(obj, args->label, args->icon, args->onclick, args->onclickdata, 0, FALSE);
+    ui_set_name_and_style(button, args->name, args->style_class);
+    ui_set_widget_groups(obj->ctx, button, args->groups);
+    UI_APPLY_LAYOUT2(current, args);
+    current->container->add(current->container, button);
     return button;
 }
 
@@ -113,6 +114,7 @@
     e.window = event->obj->window;
     e.document = event->obj->ctx->document;
     e.eventdata = NULL;
+    e.eventdatatype = 0;
     e.intval = event->value;
     e.set = ui_get_setop();
     event->callback(&e, event->userdata);
@@ -137,6 +139,7 @@
     e.window = event->obj->window;
     e.document = event->obj->ctx->document;
     e.eventdata = event->var->value;
+    e.eventdatatype = UI_EVENT_DATA_INTEGER_VALUE;
     e.intval = i->get(i);
     e.set = ui_get_setop();
     
@@ -149,6 +152,7 @@
     e.window = event->obj->window;
     e.document = event->obj->ctx->document;
     e.eventdata = NULL;
+    e.eventdatatype = 0;
     e.intval = gtk_toggle_button_get_active(widget);
     e.set = ui_get_setop();
     event->callback(&e, event->userdata);    
@@ -240,6 +244,7 @@
         event->callback = onchange;
         event->value = 0;
         event->customdata = NULL;
+        event->customint = 0;
         
         g_signal_connect(
                 widget,
@@ -260,6 +265,7 @@
         event->callback = NULL;
         event->value = enable_state;
         event->customdata = NULL;
+        event->customint = 0;
         
         g_signal_connect(
                 widget,
@@ -274,29 +280,29 @@
     }
 }
 
-static UIWIDGET togglebutton_create(UiObject *obj, GtkWidget *widget, UiToggleArgs args) {
+static UIWIDGET togglebutton_create(UiObject *obj, GtkWidget *widget, UiToggleArgs *args) {
     UiObject* current = uic_current_obj(obj);
     
     ui_setup_togglebutton(
             obj,
             widget,
-            args.label,
-            args.icon,
-            args.varname,
-            args.value,
-            args.onchange,
-            args.onchangedata,
-            args.enable_group);
-    ui_set_name_and_style(widget, args.name, args.style_class);
-    ui_set_widget_groups(obj->ctx, widget, args.groups);
+            args->label,
+            args->icon,
+            args->varname,
+            args->value,
+            args->onchange,
+            args->onchangedata,
+            args->enable_group);
+    ui_set_name_and_style(widget, args->name, args->style_class);
+    ui_set_widget_groups(obj->ctx, widget, args->groups);
     
-    UI_APPLY_LAYOUT1(current, args);
-    current->container->add(current->container, widget, FALSE);
+    UI_APPLY_LAYOUT2(current, args);
+    current->container->add(current->container, widget);
     
     return widget;
 }
 
-UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs args) {
+UIWIDGET ui_togglebutton_create(UiObject* obj, UiToggleArgs *args) {
     return togglebutton_create(obj, gtk_toggle_button_new(), args);
 }
 
@@ -320,6 +326,7 @@
     e.window = event->obj->window;
     e.document = event->obj->ctx->document;
     e.eventdata = NULL;
+    e.eventdatatype = 0;
     e.intval = gtk_check_button_get_active(widget);
     e.set = ui_get_setop();
     event->callback(&e, event->userdata);    
@@ -333,39 +340,39 @@
     }
 }
 
-UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) {
+UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs *args) {
     UiObject* current = uic_current_obj(obj);
     
-    GtkWidget *widget = gtk_check_button_new_with_label(args.label); 
+    GtkWidget *widget = gtk_check_button_new_with_label(args->label); 
     ui_bind_togglebutton(
             obj,
             widget,
             ui_check_button_get,
             ui_check_button_set,
-            args.varname,
-            args.value,
+            args->varname,
+            args->value,
             (ui_toggled_func)ui_checkbox_callback,
-            args.onchange,
-            args.onchangedata,
+            args->onchange,
+            args->onchangedata,
             (ui_toggled_func)ui_checkbox_enable_state,
-            args.enable_group);
+            args->enable_group);
     
-    ui_set_name_and_style(widget, args.name, args.style_class);
-    ui_set_widget_groups(obj->ctx, widget, args.groups);
+    ui_set_name_and_style(widget, args->name, args->style_class);
+    ui_set_widget_groups(obj->ctx, widget, args->groups);
     
-    UI_APPLY_LAYOUT1(current, args);
-    current->container->add(current->container, widget, FALSE);
+    UI_APPLY_LAYOUT2(current, args);
+    current->container->add(current->container, widget);
     
     return widget;
 }
 
 #else
-UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs args) {
+UIWIDGET ui_checkbox_create(UiObject* obj, UiToggleArgs *args) {
     return togglebutton_create(obj, gtk_check_button_new(), args);
 }
 #endif
 
-UIWIDGET ui_switch_create(UiObject* obj, UiToggleArgs args) {
+UIWIDGET ui_switch_create(UiObject* obj, UiToggleArgs *args) {
 #ifdef UI_GTK3
     return NULL; // TODO
 #else
@@ -391,6 +398,7 @@
     e.window = event->obj->window;
     e.document = event->obj->ctx->document;
     e.eventdata = NULL;
+    e.eventdatatype = 0;
     e.intval = RADIOBUTTON_GET_ACTIVE(widget);
     e.set = ui_get_setop();
     event->callback(&e, event->userdata);    
@@ -415,13 +423,13 @@
     free(data);
 }
 
-UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs args) {
+UIWIDGET ui_radiobutton_create(UiObject *obj, UiToggleArgs *args) {
     UiObject* current = uic_current_obj(obj);
     
     GSList *rg = NULL;
     UiInteger *rgroup;
     
-    UiVar* var = uic_widget_var(obj->ctx, current->ctx, args.value, args.varname, UI_VAR_INTEGER);
+    UiVar* var = uic_widget_var(obj->ctx, current->ctx, args->value, args->varname, UI_VAR_INTEGER);
     
     UiBool first = FALSE;
     if(var) {
@@ -432,9 +440,9 @@
         }
     }
     
-    GtkWidget *rbutton = RADIOBUTTON_NEW(rg, args.label); 
-    ui_set_name_and_style(rbutton, args.name, args.style_class);
-    ui_set_widget_groups(obj->ctx, rbutton, args.groups);
+    GtkWidget *rbutton = RADIOBUTTON_NEW(rg, args->label); 
+    ui_set_name_and_style(rbutton, args->name, args->style_class);
+    ui_set_widget_groups(obj->ctx, rbutton, args->groups);
     if(rgroup) {
 #if GTK_MAJOR_VERSION >= 4
         if(rg) {
@@ -476,13 +484,14 @@
                 rbdata);
     }
     
-    if(args.onchange) {
+    if(args->onchange) {
         UiEventData *event = malloc(sizeof(UiEventData));
         event->obj = obj;
-        event->userdata = args.onchangedata;
-        event->callback = args.onchange;
+        event->userdata = args->onchangedata;
+        event->callback = args->onchange;
         event->value = 0;
         event->customdata = NULL;
+        event->customint = 0;
         
         g_signal_connect(
                 rbutton,
@@ -496,8 +505,8 @@
                 event);
     }
     
-    UI_APPLY_LAYOUT1(current, args);
-    current->container->add(current->container, rbutton, FALSE);
+    UI_APPLY_LAYOUT2(current, args);
+    current->container->add(current->container, rbutton);
     
     return rbutton;
 }
@@ -510,6 +519,7 @@
     e.window = event->obj->window;
     e.document = event->obj->ctx->document;
     e.eventdata = NULL;
+    e.eventdatatype = 0;
     e.intval = i->get(i);
     
     ui_notify_evt(i->observers, &e);

mercurial