[Xfce4-commits] <libxfcegui4:xfce-4.6> Revert "redo how icon sizing works for the apps menu"

Nick Schermer noreply at xfce.org
Wed Jan 20 10:26:02 CET 2010


Updating branch refs/heads/xfce-4.6
         to 51bef833e35b29a3545f9f2fc969eabd0213c402 (commit)
       from 3d752d2143af8aeed8d1fe1ec64a7e7673dc2526 (commit)

commit 51bef833e35b29a3545f9f2fc969eabd0213c402
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Jan 19 20:09:44 2010 +0100

    Revert "redo how icon sizing works for the apps menu"
    
    This reverts commit e9aba8edc828113dfc4a4eef4cf14bc5a4932b7e.

 libxfcegui4/xfce-appmenuitem.c |  139 +++++++++++++++++++--------------------
 1 files changed, 68 insertions(+), 71 deletions(-)

diff --git a/libxfcegui4/xfce-appmenuitem.c b/libxfcegui4/xfce-appmenuitem.c
index 3362f7a..b72d30d 100644
--- a/libxfcegui4/xfce-appmenuitem.c
+++ b/libxfcegui4/xfce-appmenuitem.c
@@ -72,15 +72,15 @@ static void xfce_app_menu_item_get_property(GObject *object,
                                             guint prop_id,
                                             GValue *value,
                                             GParamSpec *pspec);
+static void xfce_app_menu_item_size_request(GtkWidget *widget,
+                                            GtkRequisition *req);
 static void xfce_app_menu_item_finalize(GObject *object);
 
-static void xfce_app_menu_item_realize(GtkWidget *widget);
-
-static void xfce_app_menu_item_update_icon(XfceAppMenuItem *app_menu_item);
-
 static void _command_activate_cb(GtkMenuItem *menu_item,
                                  gpointer user_data);
 
+static gint _xfce_app_menu_item_icon_size = -1;
+
 
 G_DEFINE_TYPE(XfceAppMenuItem, xfce_app_menu_item, GTK_TYPE_IMAGE_MENU_ITEM)
 
@@ -222,7 +222,7 @@ xfce_app_menu_item_class_init(XfceAppMenuItemClass *klass)
     
     g_type_class_add_private(klass, sizeof(XfceAppMenuItemPriv));
     
-    widget_class->realize = xfce_app_menu_item_realize;
+    widget_class->size_request = xfce_app_menu_item_size_request;
     
     gobject_class->finalize = xfce_app_menu_item_finalize;
     gobject_class->set_property = xfce_app_menu_item_set_property;
@@ -257,6 +257,11 @@ xfce_app_menu_item_class_init(XfceAppMenuItemClass *klass)
             g_param_spec_boolean("use-underline", _("Use underline"),
                                  _("Whether or not to use an underscore in the label as a keyboard mnemonic"),
                                  FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE));
+    
+    if(-1 == _xfce_app_menu_item_icon_size) {
+        gtk_icon_size_lookup(GTK_ICON_SIZE_MENU,
+                             &_xfce_app_menu_item_icon_size, NULL);
+    }
 }
 
 static void
@@ -356,6 +361,43 @@ xfce_app_menu_item_get_property(GObject *object, guint prop_id, GValue *value,
 }
 
 static void
+xfce_app_menu_item_size_request(GtkWidget *widget,
+                                GtkRequisition *req)
+{
+
+    XfceAppMenuItem *app_menu_item = XFCE_APP_MENU_ITEM(widget);
+    GtkWidget *img;
+    GdkPixbuf *pix;
+    
+    if(app_menu_item->priv->icon_path && !app_menu_item->priv->icon_set) {
+        img = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(app_menu_item));
+        if(!img) {
+            img = gtk_image_new();
+            gtk_widget_show(img);
+            gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(app_menu_item), img);
+        }
+        
+        pix = gdk_pixbuf_new_from_file_at_size(app_menu_item->priv->icon_path,
+                                               _xfce_app_menu_item_icon_size,
+                                               _xfce_app_menu_item_icon_size,
+                                               NULL);
+        
+        if(pix) {
+            gtk_image_set_from_pixbuf(GTK_IMAGE(img), pix);
+            g_object_unref(G_OBJECT(pix));
+            app_menu_item->priv->icon_set = TRUE;
+        } else {
+            g_free(app_menu_item->priv->icon_path);
+            app_menu_item->priv->icon_path = NULL;
+        }
+    }
+    
+    /* let the parent do its magic */
+    GTK_WIDGET_CLASS(xfce_app_menu_item_parent_class)->size_request(widget,
+                                                                    req);
+}
+
+static void
 xfce_app_menu_item_finalize(GObject *object)
 {
     XfceAppMenuItem *app_menu_item = XFCE_APP_MENU_ITEM(object);
@@ -373,50 +415,34 @@ xfce_app_menu_item_finalize(GObject *object)
 }
 
 static void
-xfce_app_menu_item_realize(GtkWidget *widget)
-{
-    XfceAppMenuItem *app_menu_item = XFCE_APP_MENU_ITEM(widget);
-
-    GTK_WIDGET_CLASS(xfce_app_menu_item_parent_class)->realize(widget);
-
-    xfce_app_menu_item_update_icon(app_menu_item);
-}
-
-static void
 xfce_app_menu_item_update_icon(XfceAppMenuItem *app_menu_item)
 {
-    GtkWidget *img;
-
     if(!GTK_WIDGET_REALIZED(app_menu_item))
         return;
 
-    img = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(app_menu_item));
-    if(!img) {
-        img = gtk_image_new();
-        gtk_widget_show(img);
-        gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(app_menu_item), img);
-    } else
-        gtk_image_clear(GTK_IMAGE(img));
-
-    if(app_menu_item->priv->icon_name) {
+    if(app_menu_item->priv->icon_name)
+        gtk_image_set_from_icon_name(GTK_IMAGE(img), app_menu_item->priv->icon_name);
+    else if(app_menu_item->priv->icon_path) {
         GtkIconTheme *itheme = gtk_icon_theme_get_default();
+        GdkPixbuf *pix = gtk_icon_theme_load_icon(itheme, app_menu_item->priv->icon_path, 0, NULL);
+        if(pix) {
+            GtkWidget *img = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(app_menu_item));
 
-        if(gtk_icon_theme_has_icon(itheme, app_menu_item->priv->icon_name)) {
-            gtk_image_set_from_icon_name(GTK_IMAGE(img), app_menu_item->priv->icon_name,
-                                         GTK_ICON_SIZE_MENU);
-        }
-    } else if(app_menu_item->priv->icon_path) {
-        GdkPixbuf *pix;
-        gint w, h;
+            if(!img) {
+                img = gtk_image_new();
+                gtk_widget_show(img);
+                gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(app_menu_item), img);
+            }
 
-        gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &w, &h);
-        
-        pix = gdk_pixbuf_new_from_file_at_scale(app_menu_item->priv->icon_path,
-                                                w, h, TRUE, NULL);
-        if(pix) {
             gtk_image_set_from_pixbuf(GTK_IMAGE(img), pix);
             g_object_unref(G_OBJECT(pix));
         }
+    } else {
+        GtkWidget *img = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(app_menu_item));
+        if(img) {
+            gtk_image_set_from_icon_name(GTK_IMAGE(img), NULL);
+            gtk_image_set_from_pixbuf(GTK_IMAGE(img), NULL);
+        }
     }
 }
 
@@ -699,39 +725,10 @@ xfce_app_menu_item_set_icon_name(XfceAppMenuItem *app_menu_item,
     g_free(app_menu_item->priv->icon_path);
     app_menu_item->priv->icon_path = NULL;
 
-    if(filename) {
-        if(g_path_is_absolute(filename))
-            app_menu_item->priv->icon_path = g_strdup(filename);
-        else {
-            gchar *p, *q;
-            gsize len;
-
-            /* yes, there are really broken .desktop files out there
-             * messed up like this */
-
-            /* first make sure we aren't a weird relative path */
-            p = g_strrstr(filename, G_DIR_SEPARATOR_S);
-            if(p)
-                p++;
-            else
-                p = (gchar *)filename;
-
-            len = strlen(p);
-
-            /* now make sure we don't have an extension */
-            q = g_strrstr(p, ".");
-            if(q && (!strcmp(q, ".png") || !strcmp(q, ".svg")
-                     || !strcmp(q, ".jpg") || !strcmp(q, ".gif")
-                     || !strcmp(q, ".bmp")))
-            {
-                len -= strlen(q);
-            }
-
-            /* whatever's left... */
-            if(p[0] && len)
-                app_menu_item->priv->icon_name = g_strndup(p, len);
-        }
-    }
+    if(!strstr(filename, G_DIR_SEPARATOR_S))
+        app_menu_item->priv->icon_name = g_strdup(filename);
+    else
+        app_menu_item->priv->icon_path = g_strdup(filename);
 
     xfce_app_menu_item_update_icon(app_menu_item);
 }



More information about the Xfce4-commits mailing list