Added a GTK3 helper to build menu items with image + mnemonic label and reused it for icon menu item creation in the main menu helpers.

Added GTK3 helper builders for icon menu items in the channel list and spell entry menus, reusing them in the GTK3 branches while keeping GTK2 paths intact.
This commit is contained in:
2026-01-23 14:33:11 -07:00
parent 72b9560c32
commit 65ca665e25
3 changed files with 52 additions and 27 deletions

View File

@@ -124,12 +124,11 @@ chanlist_icon_button (const char *label, const char *icon_name,
return button;
}
#if HAVE_GTK3
static GtkWidget *
chanlist_icon_menu_item (const char *label, const char *icon_name,
GCallback callback, gpointer userdata)
chanlist_menu_item_new_with_icon (const char *label, const char *icon_name)
{
GtkWidget *item;
#if HAVE_GTK3
GtkWidget *box;
GtkWidget *image;
GtkWidget *label_widget;
@@ -142,6 +141,18 @@ chanlist_icon_menu_item (const char *label, const char *icon_name,
gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), label_widget, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (item), box);
return item;
}
#endif
static GtkWidget *
chanlist_icon_menu_item (const char *label, const char *icon_name,
GCallback callback, gpointer userdata)
{
GtkWidget *item;
#if HAVE_GTK3
item = chanlist_menu_item_new_with_icon (label, icon_name);
#endif
#if !HAVE_GTK3
GtkWidget *image;

View File

@@ -261,6 +261,26 @@ menu_toggle_item (char *label, GtkWidget *menu, void *callback, void *userdata,
return item;
}
#if HAVE_GTK3
static GtkWidget *
menu_item_new_with_image_and_label (GtkWidget *image, const char *label)
{
GtkWidget *item;
GtkWidget *box;
GtkWidget *label_widget;
item = gtk_menu_item_new ();
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
label_widget = gtk_label_new_with_mnemonic (label);
if (image)
gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), label_widget, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (item), box);
return item;
}
#endif
GtkWidget *
menu_quick_item (char *cmd, char *label, GtkWidget * menu, int flags,
gpointer userdata, char *icon)
@@ -277,10 +297,6 @@ menu_quick_item (char *cmd, char *label, GtkWidget * menu, int flags,
{
if (icon)
{
#if HAVE_GTK3
GtkWidget *box;
GtkWidget *label_widget;
#endif
/*if (flags & XCMENU_MARKUP)
item = gtk_image_menu_item_new_with_markup (label);
else*/
@@ -307,13 +323,7 @@ menu_quick_item (char *cmd, char *label, GtkWidget * menu, int flags,
}
#if HAVE_GTK3
item = gtk_menu_item_new ();
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
label_widget = gtk_label_new_with_mnemonic (label);
if (img)
gtk_box_pack_start (GTK_BOX (box), img, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), label_widget, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (item), box);
item = menu_item_new_with_image_and_label (img, label);
#endif
#if !HAVE_GTK3
item = gtk_image_menu_item_new_with_mnemonic (label);
@@ -2004,8 +2014,6 @@ create_icon_menu (char *labeltext, void *stock_name, int is_stock)
{
GtkWidget *item, *img;
#if HAVE_GTK3
GtkWidget *box;
GtkWidget *label_widget;
const char *icon_name;
#endif
@@ -2022,13 +2030,7 @@ create_icon_menu (char *labeltext, void *stock_name, int is_stock)
else
img = gtk_image_new_from_pixbuf (*((GdkPixbuf **)stock_name));
#if HAVE_GTK3
item = gtk_menu_item_new ();
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
label_widget = gtk_label_new_with_mnemonic (labeltext);
if (img)
gtk_box_pack_start (GTK_BOX (box), img, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), label_widget, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (item), box);
item = menu_item_new_with_image_and_label (img, labeltext);
#endif
#if !HAVE_GTK3
item = gtk_image_menu_item_new_with_mnemonic (labeltext);

View File

@@ -629,17 +629,15 @@ build_suggestion_menu(SexySpellEntry *entry, GtkWidget *menu, struct EnchantDict
enchant_dict_free_suggestions(dict, suggestions);
}
#if HAVE_GTK3
static GtkWidget *
sexy_spell_entry_icon_menu_item (const char *label, const char *stock_name)
sexy_spell_entry_menu_item_new_with_icon (const char *label, const char *icon_name)
{
GtkWidget *item;
#if HAVE_GTK3
GtkWidget *box;
GtkWidget *image;
GtkWidget *label_widget;
const char *icon_name;
icon_name = gtkutil_icon_name_from_stock (stock_name);
item = gtk_menu_item_new ();
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
@@ -648,6 +646,20 @@ sexy_spell_entry_icon_menu_item (const char *label, const char *stock_name)
gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (box), label_widget, FALSE, FALSE, 0);
gtk_container_add (GTK_CONTAINER (item), box);
return item;
}
#endif
static GtkWidget *
sexy_spell_entry_icon_menu_item (const char *label, const char *stock_name)
{
GtkWidget *item;
#if HAVE_GTK3
const char *icon_name;
icon_name = gtkutil_icon_name_from_stock (stock_name);
item = sexy_spell_entry_menu_item_new_with_icon (label, icon_name);
#endif
#if !HAVE_GTK3
GtkWidget *image;