remove icons that will never be displayed
[claws.git] / src / stock_pixmap.c
index 69af4606fa6cceb51bc581188df9d64a49da2e61..429fb6146312a18aad9556dadbf16acb29f1e82e 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2012 Hiroyuki Yamamoto and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 #include "defs.h"
 #include <glib.h>
-#include <gtk/gtkwidget.h>
-#include <gtk/gtkimage.h>
+#include <gtk/gtk.h>
 #include <string.h>
 #include <dirent.h>
 
+#include "config.h"
 #include "stock_pixmap.h"
 #include "gtkutils.h"
 #include "utils.h"
@@ -58,6 +58,7 @@
 #include "pixmaps/locked.xpm"
 #include "pixmaps/new.xpm"
 #include "pixmaps/replied.xpm"
+#include "pixmaps/replied_and_forwarded.xpm"
 #include "pixmaps/close.xpm"
 #include "pixmaps/down_arrow.xpm"
 #include "pixmaps/up_arrow.xpm"
@@ -85,6 +86,7 @@
 #include "pixmaps/queue_open.xpm"
 #include "pixmaps/queue_open_hrm.xpm"
 #include "pixmaps/claws-mail_icon.xpm"
+#include "pixmaps/claws-mail_compose_logo.xpm"
 #ifndef GENERIC_UMPC
 #include "pixmaps/claws-mail_logo.xpm"
 #else
 #include "pixmaps/privacy_failed.xpm"
 #include "pixmaps/privacy_unknown.xpm"
 #include "pixmaps/privacy_expired.xpm"
-#include "pixmaps/privacy_warn.xpm"                 
+#include "pixmaps/privacy_warn.xpm"
 #include "pixmaps/privacy_emblem_encrypted.xpm"
 #include "pixmaps/privacy_emblem_signed.xpm"
 #include "pixmaps/privacy_emblem_passed.xpm"
 #include "pixmaps/privacy_emblem_failed.xpm"
 #include "pixmaps/privacy_emblem_warn.xpm"
-#include "pixmaps/mime_message.xpm"                  
+#include "pixmaps/mime_message.xpm"
 #include "pixmaps/address_search.xpm"
 #include "pixmaps/check_spelling.xpm"
 
 #include "pixmaps/trash_hrm_mark.xpm"
 #include "pixmaps/drafts_close_mark.xpm"
 #include "pixmaps/drafts_open_mark.xpm"
-#include "pixmaps/dir_noselect.xpm"
+#include "pixmaps/dir_noselect_close.xpm"
+#include "pixmaps/dir_noselect_close_mark.xpm"
+#include "pixmaps/dir_noselect_open.xpm"
+#include "pixmaps/dir_subs_close_mark.xpm"
+#include "pixmaps/dir_subs_close.xpm"
+#include "pixmaps/dir_subs_open.xpm"
 #include "pixmaps/spam.xpm"
 #include "pixmaps/spam_btn.xpm"
 #include "pixmaps/ham_btn.xpm"
@@ -196,8 +203,8 @@ typedef struct _StockPixmapData     StockPixmapData;
 struct _StockPixmapData
 {
        gchar **data;
-       GdkPixmap *pixmap;
-       GdkBitmap *mask;
+       cairo_surface_t *pixmap;
+       cairo_pattern_t *mask;
        gchar *file;
        gchar *icon_path;
        GdkPixbuf *pixbuf;
@@ -208,10 +215,8 @@ typedef struct _OverlayData OverlayData;
 struct _OverlayData
 {
        gboolean is_pixmap;
-       GdkPixmap *base_pixmap;
-       GdkBitmap *base_mask;
-       GdkPixmap *overlay_pixmap;
-       GdkBitmap *overlay_mask;
+       cairo_surface_t *base_pixmap;
+       cairo_surface_t *overlay_pixmap;
        
        GdkPixbuf *base_pixbuf;
        GdkPixbuf *overlay_pixbuf;
@@ -276,7 +281,7 @@ static StockPixmapData pixmaps[] =
        {interface_xpm                          , NULL, NULL, "interface", NULL},
        {jpilot_xpm                             , NULL, NULL, "jpilot", NULL},
        {key_xpm                                , NULL, NULL, "key", NULL},
-       {key_gpg_signed_xpm                     , NULL, NULL, "key_gpg_signed_xpm", NULL},
+       {key_gpg_signed_xpm                     , NULL, NULL, "key_gpg_signed", NULL},
        {ldap_xpm                               , NULL, NULL, "ldap", NULL},
        {linewrapcurrent_xpm                    , NULL, NULL, "linewrapcurrent", NULL},
        {linewrap_xpm                           , NULL, NULL, "linewrap", NULL},
@@ -307,6 +312,7 @@ static StockPixmapData pixmaps[] =
        {outbox_open_mark_xpm                   , NULL, NULL, "outbox_open_mark", NULL},
        {outbox_open_hrm_mark_xpm               , NULL, NULL, "outbox_open_hrm_mark", NULL},
        {replied_xpm                            , NULL, NULL, "replied", NULL},
+       {replied_and_forwarded_xpm      , NULL, NULL, "replied_and_forwarded", NULL},
        {paste_xpm                              , NULL, NULL, "paste", NULL},
        {preferences_xpm                        , NULL, NULL, "preferences", NULL},
        {properties_xpm                         , NULL, NULL, "properties", NULL},
@@ -370,12 +376,18 @@ static StockPixmapData pixmaps[] =
        {delete_btn_xpm                         , NULL, NULL, "delete_btn", NULL},
        {cancel_xpm                             , NULL, NULL, "cancel", NULL},
        {trash_btn_xpm                          , NULL, NULL, "trash_btn", NULL},
+       {claws_mail_compose_logo_xpm            , NULL, NULL, "claws_mail_compose_logo", NULL},
 #ifndef GENERIC_UMPC
        {claws_mail_logo_xpm                    , NULL, NULL, "claws_mail_logo", NULL},
 #else
        {claws_mail_logo_small_xpm              , NULL, NULL, "claws_mail_logo_small", NULL},
 #endif
-        {dir_noselect_xpm                       , NULL, NULL, "dir_noselect" , NULL},
+        {dir_noselect_close_xpm                 , NULL, NULL, "dir_noselect_close" , NULL},
+        {dir_noselect_close_mark_xpm            , NULL, NULL, "dir_noselect_close_mark" , NULL},
+        {dir_noselect_open_xpm                  , NULL, NULL, "dir_noselect_open" , NULL},
+        {dir_subs_close_mark_xpm                , NULL, NULL, "dir_subs_close_mark" , NULL},
+        {dir_subs_close_xpm                     , NULL, NULL, "dir_subs_close" , NULL},
+        {dir_subs_open_xpm                      , NULL, NULL, "dir_subs_open" , NULL},
         {spam_xpm                               , NULL, NULL, "spam" , NULL},
         {spam_btn_xpm                           , NULL, NULL, "spam_btn" , NULL},
         {ham_btn_xpm                            , NULL, NULL, "ham_btn" , NULL},
@@ -397,14 +409,13 @@ static StockPixmapData pixmaps[] =
 };
 
 /* return newly constructed GtkPixmap from GdkPixmap */
-GtkWidget *stock_pixmap_widget(GtkWidget *window, StockPixmap icon)
+GtkWidget *stock_pixmap_widget(StockPixmap icon)
 {
        GdkPixbuf *pixbuf;
 
-       g_return_val_if_fail(window != NULL, NULL);
-       g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
+       cm_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
 
-       if (stock_pixbuf_gdk(window, icon, &pixbuf) != -1)
+       if (stock_pixbuf_gdk(icon, &pixbuf) != -1)
                return gtk_image_new_from_pixbuf(pixbuf);
        
        return NULL;
@@ -413,7 +424,7 @@ GtkWidget *stock_pixmap_widget(GtkWidget *window, StockPixmap icon)
 /*!
  *\brief       
  */
-gint stock_pixbuf_gdk(GtkWidget *window, StockPixmap icon, GdkPixbuf **pixbuf)
+gint stock_pixbuf_gdk(StockPixmap icon, GdkPixbuf **pixbuf)
 {
        StockPixmapData *pix_d;
        static const char *extension[]={".png", ".xpm", NULL};
@@ -423,7 +434,7 @@ gint stock_pixbuf_gdk(GtkWidget *window, StockPixmap icon, GdkPixbuf **pixbuf)
        if (pixbuf)
                *pixbuf = NULL;
                
-       g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
+       cm_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
 
        pix_d = &pixmaps[icon];
 
@@ -477,7 +488,7 @@ try_next_extension:
                }
        }
 
-       g_return_val_if_fail(pix_d->pixbuf != NULL, -1);
+       cm_return_val_if_fail(pix_d->pixbuf != NULL, -1);
 
        if (pixbuf)
                *pixbuf = pix_d->pixbuf;
@@ -487,96 +498,22 @@ try_next_extension:
        return 0;
 }
 
-/* create GdkPixmap if it has not created yet */
-gint stock_pixmap_gdk(GtkWidget *window, StockPixmap icon,
-                     GdkPixmap **pixmap, GdkBitmap **mask)
-{
-       StockPixmapData *pix_d;
-       static const char *extension[]={".png", ".xpm", NULL};
-       int i = 0;
-       gboolean theme_changed = FALSE;
-
-       if (pixmap) *pixmap = NULL;
-       if (mask)   *mask   = NULL;
-
-       g_return_val_if_fail(window != NULL, -1);
-       g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, -1);
-
-       pix_d = &pixmaps[icon];
-
-       theme_changed = (strcmp2(pix_d->icon_path, prefs_common.pixmap_theme_path) != 0);
-       if (!pix_d->pixmap || theme_changed) {
-               GdkPixmap *pix = NULL;
-
-               if (theme_changed && pix_d->pixbuf) {
-                       g_object_unref(pix_d->pixbuf);
-                       pix_d->pixbuf = NULL;
-               }
-
-               if (strcmp(prefs_common.pixmap_theme_path, DEFAULT_PIXMAP_THEME) != 0) {
-                       if ( is_dir_exist(prefs_common.pixmap_theme_path) ) {
-                               char *icon_file_name; 
-try_next_extension:
-                               icon_file_name = g_strconcat(prefs_common.pixmap_theme_path,
-                                                            G_DIR_SEPARATOR_S,
-                                                            pix_d->file,
-                                                            extension[i],
-                                                            NULL);
-                               if (is_file_exist(icon_file_name))
-                                       PIXMAP_CREATE_FROM_FILE(window, pix, pix_d->mask, icon_file_name);
-                               if (pix) {
-                                       g_free(pix_d->icon_path);
-                                       pix_d->icon_path = g_strdup(prefs_common.pixmap_theme_path);
-                               }
-                               g_free(icon_file_name);
-                               if (!pix) {
-                                       i++;
-                                       if (extension[i])
-                                               goto try_next_extension;
-                               }
-                       } else {
-                               /* even the path does not exist (deleted between two sessions), so
-                               set the preferences to the internal theme */
-                               prefs_common.pixmap_theme_path = g_strdup(DEFAULT_PIXMAP_THEME);
-                       }
-               }
-               pix_d->pixmap = pix;
-       }
-
-       if (!pix_d->pixmap) {
-               PIXMAP_CREATE(window, pix_d->pixmap, pix_d->mask, pix_d->data);
-               if (pix_d->pixmap) {
-                       g_free(pix_d->icon_path);
-                       pix_d->icon_path = g_strdup(DEFAULT_PIXMAP_THEME);      
-               }
-       }
-
-       g_return_val_if_fail(pix_d->pixmap != NULL, -1);
-       
-       if (pixmap) 
-               *pixmap = pix_d->pixmap;
-       if (mask)   
-               *mask   = pix_d->mask;
-
-       return 0;
-}
-
 static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname)
 {
-       struct dirent *d;
-       DIR *dp;
+       const gchar *entry;
+       gchar *fullentry;
+       GDir *dp;
+       GError *error = NULL;
        static const char *extension[]={".png", ".xpm", NULL};
        
-       if ((dp = opendir(dirname)) == NULL) {
-               debug_print("dir %s not found, skipping theme scan", dirname?dirname:"(null)");
+       if ((dp = g_dir_open(dirname, 0, &error)) == NULL) {
+               debug_print("skipping theme scan, dir %s could not be opened: %s (%d)\n",
+                               dirname ? dirname : "(null)", error->message, error->code);
+               g_error_free(error);
                return;
        }
        
-       while ((d = readdir(dp)) != NULL) {
-               gchar *entry;
-               gchar *fullentry;
-
-               entry     = d->d_name;
+       while ((entry = g_dir_read_name(dp)) != NULL) {
                fullentry = g_strconcat(dirname, G_DIR_SEPARATOR_S, entry, NULL);
                
                if (strcmp(entry, ".") != 0 && strcmp(entry, "..") != 0 && is_dir_exist(fullentry)) {
@@ -599,7 +536,20 @@ static void stock_pixmap_find_themes_in_dir(GList **list, const gchar *dirname)
                } else 
                        g_free(fullentry);
        }
-       closedir(dp);
+       g_dir_close(dp);
+}
+
+gchar *stock_pixmap_get_system_theme_dir_for_theme(const gchar *theme)
+{
+       const gchar *sep = NULL;
+       if (theme && *theme)
+               sep = G_DIR_SEPARATOR_S;
+#ifndef G_OS_WIN32
+       return g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S,
+                          PIXMAP_THEME_DIR, sep, theme, NULL);
+#else
+       return g_strconcat(w32_get_themes_dir(), sep, theme, NULL);
+#endif
 }
 
 GList *stock_pixmap_themes_list_new(void)
@@ -612,11 +562,9 @@ GList *stock_pixmap_themes_list_new(void)
        defaulttheme = g_strdup(DEFAULT_PIXMAP_THEME);
        userthemes   = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, 
                                   PIXMAP_THEME_DIR, NULL);
-       systemthemes = g_strconcat(PACKAGE_DATA_DIR, G_DIR_SEPARATOR_S,
-                                  PIXMAP_THEME_DIR, NULL);
+       systemthemes = stock_pixmap_get_system_theme_dir_for_theme(NULL);
 
        list = g_list_append(list, defaulttheme);
-       
        stock_pixmap_find_themes_in_dir(&list, userthemes);
        stock_pixmap_find_themes_in_dir(&list, systemthemes);
 
@@ -636,7 +584,8 @@ void stock_pixmap_themes_list_free(GList *list)
 
 gchar *stock_pixmap_get_name (StockPixmap icon)
 {
-       g_return_val_if_fail(icon >= 0 && icon < N_STOCK_PIXMAPS, NULL);
+       if (icon < 0 || icon >= N_STOCK_PIXMAPS)
+               return NULL;
        
        return pixmaps[icon].file;
 
@@ -653,57 +602,50 @@ StockPixmap stock_pixmap_get_icon (gchar *file)
        return -1;
 }
 
-static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, GdkEventExpose *expose,
-                                                   OverlayData *data) 
+static gboolean do_pix_draw(GtkWidget *widget, cairo_t *cr,
+                           OverlayData *data) 
 {
-       GdkDrawable *drawable = widget->window; 
-       GdkGC *gc_pix;
+       GdkWindow *drawable = gtk_widget_get_window(widget);    
        gint left = 0;
        gint top = 0;
 
        if (data->is_pixmap) {
-               g_return_val_if_fail(data->base_pixmap != NULL, FALSE);
-               g_return_val_if_fail(data->base_mask != NULL, FALSE);
+               cm_return_val_if_fail(data->base_pixmap != NULL, FALSE);
        } else {
-               g_return_val_if_fail(data->base_pixbuf != NULL, FALSE);
+               cm_return_val_if_fail(data->base_pixbuf != NULL, FALSE);
        }
-       gc_pix = gdk_gc_new((GdkWindow *)drawable);
-                                                
-       gdk_window_clear_area (drawable, expose->area.x, expose->area.y,
-                              expose->area.width, expose->area.height);
 
        if (data->highlight) {
                MainWindow *mw = NULL;
 
                mw = mainwindow_get_mainwindow();
                if (mw != NULL && mw->menubar != NULL) {
-                       GdkGC *gc_frame = gdk_gc_new((GdkWindow *)drawable);
+                       cairo_t *cr;
                        GdkColor color = gtk_widget_get_style(mw->menubar)->base[GTK_STATE_SELECTED];
 
-                       gdk_gc_set_foreground(gc_frame, &color);
-                       gdk_gc_set_line_attributes(gc_frame, 1, GDK_LINE_SOLID,
-                                       GDK_CAP_BUTT, GDK_JOIN_BEVEL);
-                       gdk_draw_rectangle(drawable, gc_frame, FALSE, data->border_x-2, data->border_y-2, 
-                                       data->base_width+3, data->base_height+3);
-                       g_object_unref(gc_frame);
+                       cr = gdk_cairo_create(drawable);
+                       gdk_cairo_set_source_color(cr, &color);
+                       cairo_set_antialias(cr, CAIRO_ANTIALIAS_NONE);
+                       cairo_set_line_width(cr, 1.);
+                       cairo_set_line_cap(cr, CAIRO_LINE_CAP_BUTT);
+                       cairo_set_line_join(cr, CAIRO_LINE_JOIN_BEVEL);
+                       cairo_rectangle(cr, data->border_x-2, data->border_y-2,
+                           data->base_width+3, data->base_height+3);
+                       cairo_stroke(cr);
+                       cairo_destroy(cr);
                }
        }
 
        if (data->is_pixmap) {
-               gdk_gc_set_tile(gc_pix, data->base_pixmap);
-               gdk_gc_set_ts_origin(gc_pix, data->border_x, data->border_y);
-               gdk_gc_set_clip_mask(gc_pix, data->base_mask);
-               gdk_gc_set_clip_origin(gc_pix, data->border_x, data->border_y);
-               gdk_gc_set_fill(gc_pix, GDK_TILED);
-               gdk_draw_rectangle(drawable, gc_pix, TRUE, data->border_x, data->border_y, 
-                          data->base_width, data->base_height);
+               cairo_set_source_surface(cr, data->base_pixmap, data->border_x, data->border_y);
+               cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
+               cairo_rectangle(cr, data->border_x, data->border_y, data->base_width, data->base_height);
+               cairo_fill(cr);
        } else {
-               gdk_draw_pixbuf(drawable, gc_pix, data->base_pixbuf, 
-                       0, 0, data->border_x, data->border_y,
-                       -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
+               gdk_cairo_set_source_pixbuf(cr, data->base_pixbuf, data->border_x, data->border_y);
+               cairo_paint(cr);
        }
 
-
        if (data->position != OVERLAY_NONE) {
 
                switch (data->position) {
@@ -716,7 +658,7 @@ static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, GdkEventE
                        case OVERLAY_TOP_CENTER:
                        case OVERLAY_MID_CENTER:
                        case OVERLAY_BOTTOM_CENTER:
-                               left = (data->base_width + data->border_x * 2  - data->overlay_width)/2;
+                               left = (data->base_width + data->border_x * 2 - data->overlay_width)/2;
                                break;
 
                        case OVERLAY_TOP_RIGHT:
@@ -738,7 +680,7 @@ static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, GdkEventE
                        case OVERLAY_MID_LEFT:
                        case OVERLAY_MID_CENTER:
                        case OVERLAY_MID_RIGHT:
-                               top = (data->base_height + data->border_y * 2  - data->overlay_height)/2;
+                               top = (data->base_height + data->border_y * 2 - data->overlay_height)/2;
                                break;
                                        
                        case OVERLAY_BOTTOM_LEFT:
@@ -751,39 +693,55 @@ static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, GdkEventE
                                break;
                }
        }
+
        if (data->position != OVERLAY_NONE) {
                if (data->is_pixmap) {
-                       g_return_val_if_fail(data->overlay_pixmap != NULL, FALSE);
-                       g_return_val_if_fail(data->overlay_mask != NULL, FALSE);
-                       gdk_gc_set_tile(gc_pix, data->overlay_pixmap);
-                       gdk_gc_set_clip_mask(gc_pix, data->overlay_mask);
-
-                       gdk_gc_set_ts_origin(gc_pix, left, top);
-                       gdk_gc_set_clip_origin(gc_pix, left, top);
-                       gdk_gc_set_fill(gc_pix, GDK_TILED);
-                       gdk_draw_rectangle(drawable, gc_pix, TRUE, left, top, 
-                                  data->overlay_width, data->overlay_height);
+                       cm_return_val_if_fail(data->overlay_pixmap != NULL, FALSE);
+                       cairo_set_source_surface(cr, data->overlay_pixmap, left, top);
+                       cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT);
+                       cairo_rectangle (cr, left, top, data->overlay_width, data->overlay_height);
+                       cairo_fill(cr);
                } else {
-                       g_return_val_if_fail(data->overlay_pixbuf != NULL, FALSE);
-                       gdk_draw_pixbuf(drawable, gc_pix, data->overlay_pixbuf, 
-                               0, 0, left, top,
-                               -1, -1, GDK_RGB_DITHER_NONE, 0, 0);
-
+      cm_return_val_if_fail(data->overlay_pixbuf != NULL, FALSE);
+      gdk_cairo_set_source_pixbuf(cr, data->overlay_pixbuf, left, top);
+      cairo_paint(cr);
                }
        }
-       g_object_unref(gc_pix);
-       
+
        return TRUE;
 }
 
-static void pixmap_with_overlay_destroy_cb(GtkObject *object, OverlayData *data) 
+#if !GTK_CHECK_VERSION(3,0,0)
+static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, GdkEventExpose *expose,
+                                                   OverlayData *data) 
+#else
+static gboolean pixmap_with_overlay_expose_event_cb(GtkWidget *widget, cairo_t *cr,
+                                                   OverlayData *data) 
+#endif
+{
+#if !GTK_CHECK_VERSION(3,0,0)
+       cairo_t *cr;
+       GdkWindow *drawable = gtk_widget_get_window(widget);    
+       gboolean result;
+
+       cr = gdk_cairo_create(drawable);
+       gdk_window_clear_area (drawable, expose->area.x, expose->area.y,
+                               expose->area.width, expose->area.height);
+
+       result = do_pix_draw(widget, cr, data);
+       cairo_destroy(cr);
+       return result;
+#else
+       return do_pix_draw(widget, cr, data);
+#endif
+}
+
+static void pixmap_with_overlay_destroy_cb(GtkWidget *object, OverlayData *data) 
 {
        if (data->is_pixmap) {
-               g_object_unref(data->base_pixmap);
-               g_object_unref(data->base_mask);
+               cairo_surface_destroy(data->base_pixmap);
                if (data->position != OVERLAY_NONE) {
-                       g_object_unref(data->overlay_pixmap);
-                       g_object_unref(data->overlay_mask);
+                       cairo_surface_destroy(data->overlay_pixmap);
                }
        } else {
                g_object_unref(data->base_pixbuf);
@@ -807,48 +765,50 @@ static void pixmap_with_overlay_destroy_cb(GtkObject *object, OverlayData *data)
  * \param border_x size of the border around the base icon (left and right)
  * \param border_y size of the border around the base icon (top and bottom)
  */
-GtkWidget *stock_pixmap_widget_with_overlay(GtkWidget *window, StockPixmap icon,
+GtkWidget *stock_pixmap_widget_with_overlay(StockPixmap icon,
                                            StockPixmap overlay, OverlayPosition pos,
                                            gint border_x, gint border_y)
 {
-       GdkPixmap *stock_pixmap = NULL;
-       GdkBitmap *stock_mask = NULL;
+       cairo_surface_t *stock_pixmap = NULL;
        GdkPixbuf *stock_pixbuf = NULL;
        GtkWidget *widget = NULL;
        GtkWidget *stock_wid = NULL;
+       GtkRequisition requisition;
        OverlayData *data = NULL;
        
        data = g_new0(OverlayData, 1);
 
-       stock_wid = stock_pixmap_widget(window, icon);
+       stock_wid = stock_pixmap_widget(icon);
+       gtk_widget_get_requisition(stock_wid, &requisition);
 
+#if !GTK_CHECK_VERSION(3, 0, 0)
        if (gtk_image_get_storage_type(GTK_IMAGE(stock_wid)) == GTK_IMAGE_PIXMAP)
                data->is_pixmap = TRUE;
        else
+#endif
                data->is_pixmap = FALSE;
 
        if (data->is_pixmap) {
-               gtk_image_get_pixmap(GTK_IMAGE(stock_wid), &stock_pixmap, &stock_mask);
-               g_object_ref(stock_pixmap);
-               g_object_ref(stock_mask);
+               cairo_t *cr = gdk_cairo_create(gtk_widget_get_window(stock_wid));
+               stock_pixmap = cairo_get_target(cr);
+               cairo_surface_reference(stock_pixmap);
+               cairo_destroy(cr);
                data->base_pixmap = stock_pixmap;
-               data->base_mask   = stock_mask;
-               data->base_height = stock_wid->requisition.height;
-               data->base_width  = stock_wid->requisition.width;
+               data->base_height = requisition.height;
+               data->base_width  = requisition.width;
                gtk_widget_destroy(stock_wid);
 
                if (pos == OVERLAY_NONE) {
                        data->overlay_pixmap = NULL;
-                       data->overlay_mask   = NULL;
                } else {
-                       stock_wid = stock_pixmap_widget(window, overlay);
-                       gtk_image_get_pixmap(GTK_IMAGE(stock_wid), &stock_pixmap, &stock_mask);
-                       g_object_ref(stock_pixmap);
-                       g_object_ref(stock_mask);
+                       stock_wid = stock_pixmap_widget(overlay);
+                       cr = gdk_cairo_create(gtk_widget_get_window(stock_wid));
+                       stock_pixmap = cairo_get_target(cr);
+                       cairo_surface_reference(stock_pixmap);
+                       cairo_destroy(cr);
                        data->overlay_pixmap = stock_pixmap;
-                       data->overlay_mask   = stock_mask;
-                       data->overlay_height = stock_wid->requisition.height;
-                       data->overlay_width  = stock_wid->requisition.width;
+                       data->overlay_height = requisition.height;
+                       data->overlay_width  = requisition.width;
 
                        gtk_widget_destroy(stock_wid);
                }
@@ -857,19 +817,18 @@ GtkWidget *stock_pixmap_widget_with_overlay(GtkWidget *window, StockPixmap icon,
                stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid));
                g_object_ref(stock_pixbuf);
                data->base_pixbuf = stock_pixbuf;
-               data->base_height = stock_wid->requisition.height;
-               data->base_width  = stock_wid->requisition.width;
+               data->base_height = requisition.height;
+               data->base_width  = requisition.width;
                gtk_widget_destroy(stock_wid);
                if (pos == OVERLAY_NONE) {
                        data->overlay_pixmap = NULL;
-                       data->overlay_mask   = NULL;
                } else {
-                       stock_wid = stock_pixmap_widget(window, overlay);
+                       stock_wid = stock_pixmap_widget(overlay);
                        stock_pixbuf = gtk_image_get_pixbuf(GTK_IMAGE(stock_wid));
                        g_object_ref(stock_pixbuf);
                        data->overlay_pixbuf = stock_pixbuf;
-                       data->overlay_height = stock_wid->requisition.height;
-                       data->overlay_width  = stock_wid->requisition.width;
+                       data->overlay_height = requisition.height;
+                       data->overlay_width  = requisition.width;
 
                        gtk_widget_destroy(stock_wid);
                }
@@ -882,8 +841,13 @@ GtkWidget *stock_pixmap_widget_with_overlay(GtkWidget *window, StockPixmap icon,
        widget = gtk_drawing_area_new();
        gtk_widget_set_size_request(widget, data->base_width + border_x * 2, 
                              data->base_height + border_y * 2);
+#if !GTK_CHECK_VERSION(3, 0, 0)
        g_signal_connect(G_OBJECT(widget), "expose_event", 
                         G_CALLBACK(pixmap_with_overlay_expose_event_cb), data);
+#else
+       g_signal_connect(G_OBJECT(widget), "draw", 
+                        G_CALLBACK(pixmap_with_overlay_expose_event_cb), data);
+#endif
        g_signal_connect(G_OBJECT(widget), "destroy",
                         G_CALLBACK(pixmap_with_overlay_destroy_cb), data);
        g_object_set_data(G_OBJECT(widget), "highlight", &(data->highlight));