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.

This commit is contained in:
2026-01-23 10:48:01 -07:00
parent ef5d8c482a
commit e4f1b20211

View File

@@ -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);