# HG changeset patch # User Olaf Wintermann # Date 1736069439 -3600 # Node ID 883a569cc9a3a770c66f3d8c757bb94d124b576e # Parent 9a68f8cbeffadbc81c73ee436c67954ada026d48 implement gtk4 menubar diff -r 9a68f8cbeffa -r 883a569cc9a3 ui/gtk/menu.c --- a/ui/gtk/menu.c Sun Jan 05 10:14:52 2025 +0100 +++ b/ui/gtk/menu.c Sun Jan 05 10:30:39 2025 +0100 @@ -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, diff -r 9a68f8cbeffa -r 883a569cc9a3 ui/gtk/menu.h --- a/ui/gtk/menu.h Sun Jan 05 10:14:52 2025 +0100 +++ b/ui/gtk/menu.h Sun Jan 05 10:30:39 2025 +0100 @@ -42,6 +42,8 @@ UIMENU ui_create_menu(UiMenuBuilder *builder, UiObject *obj); void ui_widget_set_contextmenu(GtkWidget *widget, UIMENU menu); +GtkWidget *ui_create_menubar(UiObject *obj); + #if GTK_MAJOR_VERSION <= 3 typedef struct UiActiveMenuItemList UiActiveMenuItemList; @@ -59,8 +61,6 @@ void *userdata; }; -GtkWidget *ui_create_menubar(UiObject *obj); - void ui_add_menu_items(GtkWidget *parent, int i, UiMenu *menu, UiObject *obj); void add_menu_widget(GtkWidget *parent, int i, UiMenuItemI *item, UiObject *obj); diff -r 9a68f8cbeffa -r 883a569cc9a3 ui/gtk/window.c --- a/ui/gtk/window.c Sun Jan 05 10:14:52 2025 +0100 +++ b/ui/gtk/window.c Sun Jan 05 10:30:39 2025 +0100 @@ -195,6 +195,14 @@ #elif GTK_MAJOR_VERSION >= 4 GtkWidget *content_box = ui_gtk_vbox_new(0); WINDOW_SET_CONTENT(obj->widget, vbox); + if(!simple) { + if(uic_get_menu_list()) { + GtkWidget *mb = ui_create_menubar(obj); + if(mb) { + BOX_ADD(vbox, mb); + } + } + } if(sidebar) { GtkWidget *paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL); GtkWidget *sidebar_vbox = ui_gtk_vbox_new(0);