fix toolbar item groups newapi

Tue, 29 Oct 2024 11:17:59 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 29 Oct 2024 11:17:59 +0100
branch
newapi
changeset 367
1c3af8e31d8e
parent 366
799c8f60b9f1
child 368
02ea96c6ae64

fix toolbar item groups

ui/common/menu.c file | annotate | diff | comparison | revisions
ui/common/menu.h file | annotate | diff | comparison | revisions
ui/common/toolbar.c file | annotate | diff | comparison | revisions
ui/common/toolbar.h file | annotate | diff | comparison | revisions
ui/gtk/toolbar.c file | annotate | diff | comparison | revisions
ui/gtk/toolkit.c file | annotate | diff | comparison | revisions
ui/gtk/toolkit.h file | annotate | diff | comparison | revisions
ui/ui/toolbar.h file | annotate | diff | comparison | revisions
--- a/ui/common/menu.c	Tue Oct 29 10:43:59 2024 +0100
+++ b/ui/common/menu.c	Tue Oct 29 11:17:59 2024 +0100
@@ -67,7 +67,7 @@
     return s ? strdup(s) : NULL;
 }
 
-static int* copy_groups(const int* groups, size_t *ngroups) {
+int* uic_copy_groups(const int* groups, size_t *ngroups) {
     *ngroups = 0;
     if (!groups) {
         return NULL;
@@ -135,7 +135,7 @@
     item->icon = nl_strdup(args.icon);
     item->userdata = args.onclickdata;
     item->callback = args.onclick;
-    item->groups = copy_groups(args.groups, &item->ngroups);
+    item->groups = uic_copy_groups(args.groups, &item->ngroups);
 
     add_item((UiMenuItemI*)item);
 }
@@ -171,7 +171,7 @@
     item->varname = nl_strdup(args.varname);
     item->userdata = args.onchangedata;
     item->callback = args.onchange;
-    item->groups = copy_groups(args.groups, &item->ngroups);
+    item->groups = uic_copy_groups(args.groups, &item->ngroups);
     
     add_item((UiMenuItemI*)item);
 }
@@ -193,7 +193,7 @@
     item->varname = nl_strdup(args.varname);
     item->userdata = args.onchangedata;
     item->callback = args.onchange;
-    item->groups = copy_groups(args.groups, &item->ngroups);
+    item->groups = uic_copy_groups(args.groups, &item->ngroups);
 
     add_item((UiMenuItemI*)item);
 }
--- a/ui/common/menu.h	Tue Oct 29 10:43:59 2024 +0100
+++ b/ui/common/menu.h	Tue Oct 29 11:17:59 2024 +0100
@@ -120,6 +120,8 @@
 
 void uic_add_menu_to_stack(UiMenu* menu);
 
+int* uic_copy_groups(const int* groups, size_t *ngroups);
+
 #ifdef __cplusplus
 }
 #endif
--- a/ui/common/toolbar.c	Tue Oct 29 10:43:59 2024 +0100
+++ b/ui/common/toolbar.c	Tue Oct 29 11:17:59 2024 +0100
@@ -27,6 +27,7 @@
  */
 
 #include "toolbar.h"
+#include "menu.h"
 
 #include <string.h>
 
@@ -47,25 +48,26 @@
     return str ? strdup(str) : NULL;
 }
 
-static UiToolbarItemArgs itemargs_copy(UiToolbarItemArgs args) {
+static UiToolbarItemArgs itemargs_copy(UiToolbarItemArgs args, size_t *ngroups) {
     UiToolbarItemArgs newargs;
     newargs.label = nl_strdup(args.label);
     newargs.stockid = nl_strdup(args.stockid);
     newargs.icon = nl_strdup(args.icon);
     newargs.onclick = args.onclick;
     newargs.onclickdata = args.onclickdata;
+    newargs.groups = uic_copy_groups(args.groups, ngroups);
     return newargs;
 }
 
 void ui_toolbar_item_create(const char* name, UiToolbarItemArgs args) {
     UiToolbarItem* item = malloc(sizeof(UiToolbarItem));
     item->item.type = UI_TOOLBAR_ITEM;
-    item->args = itemargs_copy(args);
+    item->args = itemargs_copy(args, &item->ngroups);
     cxMapPut(toolbar_items, name, item);
 }
 
 
-static UiToolbarToggleItemArgs toggleitemargs_copy(UiToolbarToggleItemArgs args) {
+static UiToolbarToggleItemArgs toggleitemargs_copy(UiToolbarToggleItemArgs args, size_t *ngroups) {
     UiToolbarToggleItemArgs newargs;
     newargs.label = nl_strdup(args.label);
     newargs.stockid = nl_strdup(args.stockid);
@@ -73,13 +75,14 @@
     newargs.varname = nl_strdup(args.varname);
     newargs.onchange = args.onchange;
     newargs.onchangedata = args.onchangedata;
+    newargs.groups = uic_copy_groups(args.groups, ngroups);
     return newargs;
 }
 
 void ui_toolbar_toggleitem_create(const char* name, UiToolbarToggleItemArgs args) {
     UiToolbarToggleItem* item = malloc(sizeof(UiToolbarToggleItem));
     item->item.type = UI_TOOLBAR_TOGGLEITEM;
-    item->args = toggleitemargs_copy(args);
+    item->args = toggleitemargs_copy(args, &item->ngroups);
     cxMapPut(toolbar_items, name, item);
 }
 
--- a/ui/common/toolbar.h	Tue Oct 29 10:43:59 2024 +0100
+++ b/ui/common/toolbar.h	Tue Oct 29 11:17:59 2024 +0100
@@ -62,11 +62,13 @@
 struct UiToolbarItem {
     UiToolbarItemI item;
     UiToolbarItemArgs args;
+    size_t ngroups;
 };
 
 struct UiToolbarToggleItem {
     UiToolbarItemI item;
     UiToolbarToggleItemArgs args;
+    size_t ngroups;
 };
 
 struct UiToolbarMenuItem {
--- a/ui/gtk/toolbar.c	Tue Oct 29 10:43:59 2024 +0100
+++ b/ui/gtk/toolbar.c	Tue Oct 29 11:17:59 2024 +0100
@@ -145,6 +145,8 @@
     }
     gtk_tool_item_set_is_important(button, TRUE);
     
+    ui_set_widget_ngroups(obj->ctx, GTK_WIDGET(button), item->args.groups, item->ngroups);
+    
     if(item->args.onclick) {
         UiEventData *event = cxMalloc(
                 obj->ctx->allocator,
@@ -189,6 +191,7 @@
             set_toolbutton_icon(button, item->args.icon);
         }    
     }
+    ui_set_widget_ngroups(obj->ctx, GTK_WIDGET(button), item->args.groups, item->ngroups);
     
     UiVar* var = uic_widget_var(obj->ctx, obj->ctx, NULL, item->args.varname, UI_VAR_INTEGER);
     if(var) {
@@ -406,6 +409,7 @@
     if(item->args.icon) {
         ui_button_set_icon_name(button, item->args.icon);
     }
+    ui_set_widget_groups(obj->ctx, button, item->args.groups);
     
     gtk_header_bar_pack_start(hb, button);
     
--- a/ui/gtk/toolkit.c	Tue Oct 29 10:43:59 2024 +0100
+++ b/ui/gtk/toolkit.c	Tue Oct 29 11:17:59 2024 +0100
@@ -431,8 +431,13 @@
     if(!groups) {
         return;
     }
-    
     size_t ngroups = uic_group_array_size(groups);
-    uic_add_group_widget_i(ctx, widget, (ui_enablefunc)ui_set_enabled, groups, ngroups);
-    ui_set_enabled(widget, FALSE);
+    ui_set_widget_ngroups(ctx, widget, groups, ngroups);
 }
+
+void ui_set_widget_ngroups(UiContext *ctx, GtkWidget *widget, const int *groups, size_t ngroups) {
+    if(ngroups > 0) {
+        uic_add_group_widget_i(ctx, widget, (ui_enablefunc)ui_set_enabled, groups, ngroups);
+        ui_set_enabled(widget, FALSE);
+    }
+}
--- a/ui/gtk/toolkit.h	Tue Oct 29 10:43:59 2024 +0100
+++ b/ui/gtk/toolkit.h	Tue Oct 29 11:17:59 2024 +0100
@@ -164,6 +164,7 @@
 
 void ui_set_name_and_style(GtkWidget *widget, const char *name, const char *style);
 void ui_set_widget_groups(UiContext *ctx, GtkWidget *widget, const int *groups);
+void ui_set_widget_ngroups(UiContext *ctx, GtkWidget *widget, const int *groups, size_t ngroups);
 
 void ui_destroy_userdata(GtkWidget *object, void *userdata);
 void ui_destroy_vardata(GtkWidget *object, UiVarEventData *data);
--- a/ui/ui/toolbar.h	Tue Oct 29 10:43:59 2024 +0100
+++ b/ui/ui/toolbar.h	Tue Oct 29 11:17:59 2024 +0100
@@ -82,23 +82,6 @@
 UIEXPORT void ui_toolbar_toggleitem_create(const char* name, UiToolbarToggleItemArgs args);
 UIEXPORT void ui_toolbar_menu_create(const char* name, UiToolbarMenuArgs args);
 
-
-void ui_toolitem_deprecated(char *name, char *label, ui_callback f, void *udata);
-void ui_toolitem_st(char *name, char *stockid, ui_callback f, void *udata);
-void ui_toolitem_sti(char *name, char *stockid, ui_callback f, void *udata);
-void ui_toolitem_stgr(char *name, char *stockid, ui_callback f, void *udata, ...);
-void ui_toolitem_stgri(char *name, char *stockid, ui_callback f, void *userdata, ...);
-void ui_toolitem_img(char *name, char *label, char *img, ui_callback f, void *udata);
-
-void ui_toolitem_toggle(const char *name, const char *label, const char *img, UiInteger *i);
-void ui_toolitem_toggle_st_deprecated(const char *name, const char *stockid, UiInteger *i);
-void ui_toolitem_toggle_nv_deprecated(const char *name, const char *label, const char *img, const char *intvar);
-void ui_toolitem_toggle_stnv_deprecated(const char *name, const char *stockid, const char *intvar);
-
-void ui_toolbar_combobox_deprecated(char *name, UiList *list, ui_getvaluefunc getvalue, ui_callback f, void *udata);
-void ui_toolbar_combobox_str_deprecated(char *name, UiList *list, ui_callback f, void *udata);
-void ui_toolbar_combobox_nv_deprecated(char *name, char *listname, ui_getvaluefunc getvalue, ui_callback f, void *udata);
-
 UIEXPORT void ui_toolbar_add_default(const char *name, enum UiToolbarPos pos);
 
 

mercurial