* 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"
#include "gtkwidget.h"
#include "gtkintl.h"
+
static GSList *all_icon_factories = NULL;
typedef enum {
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);
{
icon_size_set_all_from_settings (settings);
- _gtk_rc_reset_styles (settings);
+ gtk_rc_reset_styles (settings);
}
static void
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
{
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);
if (!tmp_pixbuf)
{
g_warning ("Error loading theme icon for stock: %s", error->message);
+ g_error_free (error);
return NULL;
}
* @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.
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);
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:
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
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;
if (icon_set->cache_size >= NUM_CACHED_ICONS)
{
/* Remove oldest item in the cache */
-
GSList *tmp_list;
tmp_list = icon_set->cache;
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;
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*
*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);