fix getvaluefunc not used by menu lists (GTK) newapi

Sun, 09 Jun 2024 16:21:51 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 09 Jun 2024 16:21:51 +0200
branch
newapi
changeset 286
f6ca4bbbe2a6
parent 285
034015dfd3de
child 287
5370ea7e45a2

fix getvaluefunc not used by menu lists (GTK)

ui/gtk/menu.c file | annotate | diff | comparison | revisions
ui/gtk/menu.h file | annotate | diff | comparison | revisions
--- a/ui/gtk/menu.c	Sun Jun 09 16:14:05 2024 +0200
+++ b/ui/gtk/menu.c	Sun Jun 09 16:21:51 2024 +0200
@@ -243,6 +243,7 @@
     ls->menu = GTK_MENU_SHELL(p);
     ls->index = index;
     ls->oldcount = 0;
+    ls->getvalue = il->getvalue;
     
     UiVar* var = uic_create_var(ui_global_context(), il->varname, UI_VAR_LIST);
     ls->list = var->value;
@@ -274,15 +275,19 @@
         }
     }
     
-    char *str = ui_list_first(list->list);
-    if(str) {
+    void* elm = ui_list_first(list->list);
+    if(elm) {
         GtkWidget *widget = gtk_separator_menu_item_new();
         gtk_menu_shell_insert(list->menu, widget, list->index);
         gtk_widget_show(widget);
     }
+    
+    ui_getvaluefunc getvalue = list->getvalue;
     int i = 1;
-    while(str) {
-        GtkWidget *widget = gtk_menu_item_new_with_label(str);
+    while(elm) {
+        char *label = (char*) (getvalue ? getvalue(elm, 0) : elm);
+        
+        GtkWidget *widget = gtk_menu_item_new_with_label(label);
         gtk_menu_shell_insert(list->menu, widget, list->index + i);
         gtk_widget_show(widget);
         
@@ -307,7 +312,7 @@
                 event);
         }
         
-        str = ui_list_next(list->list);
+        elm = ui_list_next(list->list);
         i++;
     }
     
--- a/ui/gtk/menu.h	Sun Jun 09 16:14:05 2024 +0200
+++ b/ui/gtk/menu.h	Sun Jun 09 16:21:51 2024 +0200
@@ -44,13 +44,14 @@
 typedef void(*ui_menu_add_f)(GtkWidget *, int, UiMenuItemI*, UiObject*);
 
 struct UiActiveMenuItemList {
-    UiObject     *object;
-    GtkMenuShell *menu;
-    int          index;
-    int          oldcount;
-    UiList       *list;
-    ui_callback  callback;
-    void         *userdata;
+    UiObject         *object;
+    GtkMenuShell     *menu;
+    int              index;
+    int              oldcount;
+    UiList           *list;
+    ui_getvaluefunc getvalue;
+    ui_callback     callback;
+    void            *userdata;
 };
 
 GtkWidget *ui_create_menubar(UiObject *obj);

mercurial