From 7b950bf75ad46b8899aed65fe00849825395d1bb Mon Sep 17 00:00:00 2001 From: Ordissimo Date: Sun, 27 Oct 2024 21:16:03 +0100 Subject: [PATCH] Add menu functions --- libgtk/utils-gtk.c | 42 ++++++++++++++++++++++++++++++++++++++++++ libgtk/utils-gtk.h | 2 ++ 2 files changed, 44 insertions(+) diff --git a/libgtk/utils-gtk.c b/libgtk/utils-gtk.c index 4d9043c..958bc23 100644 --- a/libgtk/utils-gtk.c +++ b/libgtk/utils-gtk.c @@ -88,3 +88,45 @@ gtk_window_set_position_with_mouse (GtkWindow *window) } } */ + +void +create_item ( GMenu *menu, + const gchar *const label, + const gchar *const action, + const gchar *const icon, + const gchar *const target, + const gchar *const accel ) +{ + g_return_if_fail ( G_IS_MENU ( menu ) ); + + GMenuItem *item = g_menu_item_new ( NULL, NULL ); + g_menu_item_set_attribute ( item, G_MENU_ATTRIBUTE_LABEL, "s", label, NULL ); + g_menu_item_set_attribute ( item, G_MENU_ATTRIBUTE_ACTION, "s", action, NULL ); + g_menu_item_set_attribute ( item, G_MENU_ATTRIBUTE_ICON, "s", icon, NULL ); + + if ( target ) + { + g_menu_item_set_attribute ( item, "target", "s", target, NULL ); + } + + g_menu_item_set_attribute ( item, "accel", "s", accel, NULL ); + g_menu_append_item ( menu, item ); + + g_object_unref ( item ); +} + +void +create_submenu_item ( GMenu *menu, + GMenu *submenu, + const gchar *const label ) +{ + g_return_if_fail ( G_IS_MENU ( menu ) ); + + GMenuItem *item = g_menu_item_new ( NULL, NULL ); + + g_menu_item_set_attribute ( item, G_MENU_ATTRIBUTE_LABEL, "s", label, NULL ); + g_menu_item_set_submenu ( item, G_MENU_MODEL ( submenu ) ); + g_menu_append_item ( menu, item ); + + g_object_unref ( item ); +} diff --git a/libgtk/utils-gtk.h b/libgtk/utils-gtk.h index e871338..40a4b8b 100644 --- a/libgtk/utils-gtk.h +++ b/libgtk/utils-gtk.h @@ -28,5 +28,7 @@ void gtk_container_set_border_width (GtkWidget *widget, int width); void gtk_box_pack_start (GtkBox *box, GtkWidget* child, gboolean expand, gboolean fill, guint padding); void gtk_box_pack_end (GtkBox *box, GtkWidget* child, gboolean expand, gboolean fill, guint padding); // void gtk_window_set_position_with_mouse (GtkWindow *window); +void create_submenu_item (GMenu *menu, GMenu *submenu, const gchar *const label); +void create_item (GMenu *menu, const gchar *const label, const gchar *const action, const gchar *const icon, const gchar *const target, const gchar *const accel); #endif