ui/gtk/menu.c

changeset 101
7b3a3130be44
parent 98
16e84fac48bd
--- a/ui/gtk/menu.c	Thu Dec 12 20:01:43 2024 +0100
+++ b/ui/gtk/menu.c	Mon Jan 06 22:22:55 2025 +0100
@@ -131,7 +131,7 @@
         CxList *groups = cxArrayListCreateSimple(sizeof(int), i->ngroups);
         cxListAddArray(groups, i->groups, i->ngroups);
         uic_add_group_widget(obj->ctx, widget, (ui_enablefunc)ui_set_enabled, groups);
-        cxListDestroy(groups);
+        cxListFree(groups);
     }
 }
 
@@ -390,7 +390,25 @@
 
 #if GTK_MAJOR_VERSION >= 4
 
+GtkWidget *ui_create_menubar(UiObject *obj) {
+    UiMenu *menus_begin = uic_get_menu_list();
+    if(menus_begin == NULL) {
+        return NULL;
+    }
+    
+    GMenu *menu = g_menu_new();
+    UiMenu *ls = menus_begin;
+    while(ls) {
+        GMenu *sub_menu = g_menu_new();
+        ui_gmenu_add_menu_items(sub_menu, 0, ls, obj);
+        g_menu_append_submenu(menu, ls->label, G_MENU_MODEL(sub_menu));
+        ls = (UiMenu*)ls->item.next;
+    }
+    
 
+    // Create a menubar from the menu model
+    return gtk_popover_menu_bar_new_from_model(G_MENU_MODEL(menu));
+}
 
 static ui_gmenu_add_f createMenuItem[] = {
     /* UI_MENU                 */ ui_gmenu_add_menu,
@@ -446,7 +464,7 @@
         CxList *groups = cxArrayListCreateSimple(sizeof(int), i->ngroups);
         cxListAddArray(groups, i->groups, i->ngroups);
         uic_add_group_widget(obj->ctx, action, (ui_enablefunc)action_enable, groups);
-        cxListDestroy(groups);
+        cxListFree(groups);
     }
     
     if(i->callback != NULL) {

mercurial