Skip to content

Commit

Permalink
Merge pull request #52 from anaselli/icon_button
Browse files Browse the repository at this point in the history
Setting icon on buttons differs from QT because it does not respect theme settings
  • Loading branch information
jreidinger committed Jan 19, 2016
2 parents 443728e + 40ec682 commit 97f3b2c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/YGPushButton.cc
Expand Up @@ -9,6 +9,7 @@
#include "YGUtils.h"
#include "YGWidget.h"
#include <string.h>
#include <libgen.h>

#include <YLayoutBox.h>
#include "ygtkratiobox.h"
Expand Down Expand Up @@ -104,13 +105,28 @@ bool m_customIcon, m_labelIcon;
if (path[0] != '/')
path = std::string (THEMEDIR) + "/" + path;

char *p = strdup(path.c_str());
char *p1 = strdup(path.c_str());
char *dname = dirname(p);
char *fname = basename(p1);
char *name = strtok (fname, ".");
GtkIconTheme * theme = gtk_icon_theme_get_default ();
gtk_icon_theme_add_resource_path (theme, dname);
gtk_icon_theme_prepend_search_path (theme, dname);
gtk_icon_theme_rescan_if_needed (theme);
GError *error = 0;
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (path.c_str(), &error);
GdkPixbuf *pixbuf = gtk_icon_theme_load_icon (theme,
name, // icon name
16, // icon size (default button size)
GTK_ICON_LOOKUP_FORCE_SIZE, // flags
&error);
free (p);
free (p1);
if (pixbuf) {
GtkWidget *image = gtk_image_new_from_pixbuf (pixbuf);
gtk_button_set_image (button, image);
// disregard gtk-button-images setting for explicitly set icons
gtk_widget_show (image);
gtk_button_set_always_show_image (button, TRUE);
g_object_unref (G_OBJECT (pixbuf));
}
else
Expand Down

0 comments on commit 97f3b2c

Please sign in to comment.