Sun, 05 Jan 2025 10:30:39 +0100
implement gtk4 menubar
ui/gtk/menu.c | file | annotate | diff | comparison | revisions | |
ui/gtk/menu.h | file | annotate | diff | comparison | revisions | |
ui/gtk/window.c | file | annotate | diff | comparison | revisions |
--- 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,
--- 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);
--- 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);