-static void
-ensure_pixbuf_for_icon_name (GtkImage *image,
- GtkStateFlags state)
-{
- GtkImagePrivate *priv = image->priv;
- GdkScreen *screen;
- GtkIconTheme *icon_theme;
- GtkSettings *settings;
- gint width, height;
- gint *sizes, *s, dist;
- GtkIconInfo *info;
- GtkIconLookupFlags flags;
-
- g_return_if_fail (priv->storage_type == GTK_IMAGE_ICON_NAME);
-
- screen = gtk_widget_get_screen (GTK_WIDGET (image));
- icon_theme = gtk_icon_theme_get_for_screen (screen);
- settings = gtk_settings_get_for_screen (screen);
- flags = GTK_ICON_LOOKUP_USE_BUILTIN;
- if (priv->data.name.pixbuf == NULL ||
- (priv->was_symbolic && priv->last_rendered_state != state))
- {
- priv->last_rendered_state = state;
- if (priv->data.name.pixbuf)
- {
- g_object_unref (priv->data.name.pixbuf);
- priv->data.name.pixbuf = NULL;
- }
- if (priv->pixel_size != -1)
- {
- width = height = priv->pixel_size;
- flags |= GTK_ICON_LOOKUP_FORCE_SIZE;
- }
- else if (!gtk_icon_size_lookup_for_settings (settings,
- priv->icon_size,
- &width, &height))
- {
- if (priv->icon_size == -1)
- {
- /* Find an available size close to 48 */
- sizes = gtk_icon_theme_get_icon_sizes (icon_theme, priv->data.name.icon_name);
- dist = 100;
- 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", priv->icon_size);
- width = height = 24;
- }
- }
-
- info = gtk_icon_theme_lookup_icon (icon_theme,
- priv->data.name.icon_name,
- MIN (width, height), flags);
- if (info)
- {
- GtkStyleContext *context;
- gboolean was_symbolic;
-
- context = gtk_widget_get_style_context (GTK_WIDGET (image));
- priv->data.name.pixbuf =
- gtk_icon_info_load_symbolic_for_context (info,
- context,
- &was_symbolic,
- NULL);
- priv->was_symbolic = was_symbolic;
- gtk_icon_info_free (info);
- }
-
- if (priv->data.name.pixbuf == NULL)
- {
- priv->data.name.pixbuf =
- gtk_widget_render_icon_pixbuf (GTK_WIDGET (image),
- GTK_STOCK_MISSING_IMAGE,
- priv->icon_size);
- priv->was_symbolic = FALSE;
- }
- }