]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkiconfactory.c
Make sure the RTL variants are used for media icons update following the
[~andy/gtk] / gtk / gtkiconfactory.c
index 4d1565b4dd50798a5cbba950b14607581293d0aa..daa68c63cb432abb405d2d83b4c8f99824453f86 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
+#include <config.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
+#include "gtkalias.h"
 #include <pango/pango-utils.h> /* For pango_scan_* */
 #include "gtkiconfactory.h"
 #include "stock-icons/gtkstockpixbufs.h"
@@ -37,6 +39,7 @@
 #include "gtkwidget.h"
 #include "gtkintl.h"
 
+
 static GSList *all_icon_factories = NULL;
 
 typedef enum {
@@ -694,6 +697,62 @@ get_default_icons (GtkIconFactory *factory)
             16, stock_up_arrow_16,
             24, stock_up_arrow_24);
 
+  add_icon2 (factory, GTK_STOCK_FILE,
+            16, stock_file_16,
+            24, stock_file_24);
+
+  add_icon2 (factory, GTK_STOCK_DIRECTORY,
+            16, stock_directory_16,
+            24, stock_directory_24);
+
+  add_icon2 (factory, GTK_STOCK_ABOUT,
+            16, stock_about_16,
+            24, stock_about_24);
+
+  add_icon2 (factory, GTK_STOCK_CONNECT,
+            16, stock_connect_16,
+            24, stock_connect_24);
+
+  add_icon2 (factory, GTK_STOCK_DISCONNECT,
+            16, stock_disconnect_16,
+            24, stock_disconnect_24);
+
+  add_icon2 (factory, GTK_STOCK_EDIT,
+            16, stock_edit_16,
+            24, stock_edit_24);
+
+  add_icon_bidi2 (factory, GTK_STOCK_MEDIA_FORWARD,
+            16, stock_media_forward_16, stock_media_rewind_16,
+            24, stock_media_forward_24, stock_media_rewind_24);
+
+  add_icon_bidi2 (factory, GTK_STOCK_MEDIA_NEXT,
+            16, stock_media_next_16, stock_media_previous_16,
+            24, stock_media_next_24, stock_media_previous_24);
+
+  add_icon2 (factory, GTK_STOCK_MEDIA_PAUSE,
+            16, stock_media_pause_16,
+            24, stock_media_pause_24);
+
+  add_icon_bidi2 (factory, GTK_STOCK_MEDIA_PLAY,
+            16, stock_media_play_16, stock_media_play_rtl_16,
+            24, stock_media_play_24, stock_media_play_rtl_24);
+
+  add_icon_bidi2 (factory, GTK_STOCK_MEDIA_PREVIOUS,
+            16, stock_media_previous_16, stock_media_next_16,
+            24, stock_media_previous_24, stock_media_next_24);
+
+  add_icon2 (factory, GTK_STOCK_MEDIA_RECORD,
+            16, stock_media_record_16,
+            24, stock_media_record_24);
+
+  add_icon_bidi2 (factory, GTK_STOCK_MEDIA_REWIND,
+            16, stock_media_rewind_16, stock_media_forward_16,
+            24, stock_media_rewind_24, stock_media_forward_24);
+
+  add_icon2 (factory, GTK_STOCK_MEDIA_STOP,
+            16, stock_media_stop_16,
+            24, stock_media_stop_24);
+
   /* Generic size only */
 
   add_icon (factory, GTK_STOCK_CLEAR, 24, stock_clear_24);
@@ -997,7 +1056,7 @@ icon_size_settings_changed (GtkSettings  *settings,
 {
   icon_size_set_all_from_settings (settings);
 
-  _gtk_rc_reset_styles (settings);
+  gtk_rc_reset_styles (settings);
 }
 
 static void
@@ -1590,11 +1649,12 @@ render_icon_name_pixbuf (GtkIconSource    *icon_source,
   GtkIconTheme *icon_theme;
   GtkSettings *settings;
   gint width, height, pixel_size;
+  gint *sizes, *s, dist;
   GError *error = NULL;
   
   if (widget && gtk_widget_has_screen (widget))
     screen = gtk_widget_get_screen (widget);
-  else if (style->colormap)
+  else if (style && style->colormap)
     screen = gdk_colormap_get_screen (style->colormap);
   else
     {
@@ -1608,8 +1668,45 @@ render_icon_name_pixbuf (GtkIconSource    *icon_source,
 
   if (!gtk_icon_size_lookup_for_settings (settings, size, &width, &height))
     {
-      g_warning ("Invalid icon size %d\n", size);
-      width = height = 24;
+      if (size == -1)
+       {
+         /* Find an available size close to 48 
+          */
+         sizes = gtk_icon_theme_get_icon_sizes (icon_theme, icon_source->source.icon_name);
+         dist = 1000;
+         width = height = 48;
+         for (s = sizes; *s; s++)
+           {
+             if (*s == -1)
+               {
+                 width = height = 48;
+                 break;
+               }
+             if (*s < 48)
+               {
+                 if (48 - *s < dist)
+                   {
+                     width = height = *s;
+                     dist = 48 - *s;
+                   }
+               }
+             else 
+               {
+                 if (*s - 48 < dist)
+                   {
+                     width = height = *s;
+                     dist = *s - 48;
+                   }
+               }
+           }
+         
+         g_free (sizes);
+       }
+      else
+       {
+         g_warning ("Invalid icon size %d\n", size);
+         width = height = 24;
+       }
     }
 
   pixel_size = MIN (width, height);
@@ -1622,6 +1719,7 @@ render_icon_name_pixbuf (GtkIconSource    *icon_source,
   if (!tmp_pixbuf)
     {
       g_warning ("Error loading theme icon for stock: %s", error->message);
+      g_error_free (error);
       return NULL;
     }
   
@@ -1736,7 +1834,8 @@ render_fallback_image (GtkStyle          *style,
  * @style: a #GtkStyle associated with @widget, or %NULL
  * @direction: text direction
  * @state: widget state
- * @size: icon size
+ * @size: icon size. A size of (GtkIconSize)-1
+ *        means render at the size of the source and don't scale.
  * @widget: widget that will display the icon, or %NULL.
  *          The only use that is typically made of this
  *          is to determine the appropriate #GdkScreen.
@@ -1765,7 +1864,7 @@ gtk_icon_set_render_icon (GtkIconSet        *icon_set,
   GdkPixbuf *icon;
   
   g_return_val_if_fail (icon_set != NULL, NULL);
-  g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
+  g_return_val_if_fail (style == NULL || GTK_IS_STYLE (style), NULL);
 
   if (icon_set->sources == NULL)
     return render_fallback_image (style, direction, state, size, widget, detail);
@@ -2088,7 +2187,8 @@ icon_source_clear (GtkIconSource *source)
     case GTK_ICON_SOURCE_FILENAME:
       g_free (source->source.filename);
       source->source.filename = NULL;
-      g_free (source->filename_pixbuf);
+      if (source->filename_pixbuf) 
+       g_object_unref (source->filename_pixbuf);
       source->filename_pixbuf = NULL;
       break;
     case GTK_ICON_SOURCE_PIXBUF:
@@ -2596,7 +2696,7 @@ add_to_cache (GtkIconSet      *icon_set,
   CachedIcon *icon;
 
   ensure_cache_up_to_date (icon_set);
-  
+
   g_object_ref (pixbuf);
 
   /* We have to ref the style, since if the style was finalized
@@ -2606,10 +2706,10 @@ add_to_cache (GtkIconSet      *icon_set,
   
   if (style)
     g_object_ref (style);
-  
 
   icon = g_new (CachedIcon, 1);
   icon_set->cache = g_slist_prepend (icon_set->cache, icon);
+  icon_set->cache_size++;
 
   icon->style = style;
   icon->direction = direction;
@@ -2623,7 +2723,6 @@ add_to_cache (GtkIconSet      *icon_set,
   if (icon_set->cache_size >= NUM_CACHED_ICONS)
     {
       /* Remove oldest item in the cache */
-      
       GSList *tmp_list;
       
       tmp_list = icon_set->cache;
@@ -2651,10 +2750,13 @@ static void
 clear_cache (GtkIconSet *icon_set,
              gboolean    style_detach)
 {
-  GSList *tmp_list;
+  GSList *cache, *tmp_list;
   GtkStyle *last_style = NULL;
 
-  tmp_list = icon_set->cache;
+  cache = icon_set->cache;
+  icon_set->cache = NULL;
+  icon_set->cache_size = 0;
+  tmp_list = cache;
   while (tmp_list != NULL)
     {
       CachedIcon *icon = tmp_list->data;
@@ -2678,9 +2780,7 @@ clear_cache (GtkIconSet *icon_set,
       tmp_list = g_slist_next (tmp_list);
     }
 
-  g_slist_free (icon_set->cache);
-  icon_set->cache = NULL;
-  icon_set->cache_size = 0;
+  g_slist_free (cache);
 }
 
 static GSList*
@@ -2701,7 +2801,10 @@ copy_cache (GtkIconSet *icon_set,
       *icon_copy = *icon;
 
       if (icon_copy->style)
-        attach_to_style (copy_recipient, icon_copy->style);
+       {
+         attach_to_style (copy_recipient, icon_copy->style);
+         g_object_ref (icon_copy->style);
+       }
         
       g_object_ref (icon_copy->pixbuf);