From e4f1b20211693b262939fb72a930ee7f8670606b Mon Sep 17 00:00:00 2001 From: deepend Date: Fri, 23 Jan 2026 10:48:01 -0700 Subject: [PATCH] Added a helper to create button images from stock names using GTK3 icon mapping, and used it in gtkutil_button for consistent GTK2/GTK3 handling. --- src/fe-gtk/gtkutil.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/fe-gtk/gtkutil.c b/src/fe-gtk/gtkutil.c index 15c213e1..29569461 100644 --- a/src/fe-gtk/gtkutil.c +++ b/src/fe-gtk/gtkutil.c @@ -120,6 +120,19 @@ gtkutil_icon_name_from_stock (const char *stock_name) } #endif +static GtkWidget * +gtkutil_image_new_from_stock_name (const char *stock_name) +{ +#if HAVE_GTK3 + const char *icon_name = gtkutil_icon_name_from_stock (stock_name); + + return gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); +#endif +#if !HAVE_GTK3 + return gtk_image_new_from_stock (stock_name, GTK_ICON_SIZE_MENU); +#endif +} + static void gtkutil_file_req_destroy (GtkWidget * wid, struct file_req *freq) { @@ -575,22 +588,13 @@ gtkutil_button (GtkWidget *box, char *stock, char *tip, void *callback, void *userdata, char *labeltext) { GtkWidget *wid, *img, *bbox; -#if HAVE_GTK3 - const char *icon_name; -#endif wid = gtk_button_new (); if (labeltext) { gtk_button_set_label (GTK_BUTTON (wid), labeltext); -#if HAVE_GTK3 - icon_name = gtkutil_icon_name_from_stock (stock); - img = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); -#endif -#if !HAVE_GTK3 - img = gtk_image_new_from_stock (stock, GTK_ICON_SIZE_MENU); -#endif + img = gtkutil_image_new_from_stock_name (stock); gtk_button_set_image (GTK_BUTTON (wid), img); gtk_button_set_use_underline (GTK_BUTTON (wid), TRUE); if (box) @@ -602,13 +606,7 @@ gtkutil_button (GtkWidget *box, char *stock, char *tip, void *callback, gtk_container_add (GTK_CONTAINER (wid), bbox); gtk_widget_show (bbox); -#if HAVE_GTK3 - icon_name = gtkutil_icon_name_from_stock (stock); - img = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); -#endif -#if !HAVE_GTK3 - img = gtk_image_new_from_stock (stock, GTK_ICON_SIZE_MENU); -#endif + img = gtkutil_image_new_from_stock_name (stock); gtk_container_add (GTK_CONTAINER (bbox), img); gtk_widget_show (img); gtk_box_pack_start (GTK_BOX (box), wid, 0, 0, 0);