Ejemplo n.º 1
0
static GdkPaintable *
ensure_paintable_for_gicon (GtkIconHelper    *self,
                            GtkCssStyle      *style,
                            GtkTextDirection  dir,
                            gint              scale,
                            GIcon            *gicon,
                            gboolean         *symbolic)
{
  GtkIconTheme *icon_theme;
  gint width, height;
  GtkIconInfo *info;
  GtkIconLookupFlags flags;
  GdkPaintable *paintable;

  icon_theme = gtk_css_icon_theme_value_get_icon_theme
    (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_THEME));
  flags = get_icon_lookup_flags (self, style, dir);

  width = height = gtk_icon_helper_get_size (self);

  info = gtk_icon_theme_lookup_by_gicon_for_scale (icon_theme,
                                                   gicon,
                                                   MIN (width, height),
                                                   scale, flags);
  if (info == NULL)
    info = gtk_icon_theme_lookup_icon (icon_theme,
                                       "image-missing",
                                       width,
                                       flags | GTK_ICON_LOOKUP_USE_BUILTIN | GTK_ICON_LOOKUP_GENERIC_FALLBACK);

  *symbolic = gtk_icon_info_is_symbolic (info);
  paintable = GDK_PAINTABLE (gtk_icon_info_load_texture (info));
  g_object_unref (info);

  if (paintable && scale != 1)
    {
      GdkPaintable *orig = paintable;

      paintable = gtk_scaler_new (orig, scale);
      g_object_unref (orig);
    }

  return paintable;
}
Ejemplo n.º 2
0
static GdkPaintable *
get_image_paintable (GtkImage *image)
{
  const gchar *icon_name;
  GtkIconTheme *icon_theme;
  GtkIconInfo *icon_info;

  switch (gtk_image_get_storage_type (image))
    {
    case GTK_IMAGE_PAINTABLE:
      return g_object_ref (gtk_image_get_paintable (image));
    case GTK_IMAGE_ICON_NAME:
      icon_name = gtk_image_get_icon_name (image);
      icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (GTK_WIDGET (image)));
      icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, 48, GTK_ICON_LOOKUP_GENERIC_FALLBACK);
      if (icon_info == NULL)
        return NULL;
      return GDK_PAINTABLE (gtk_icon_info_load_texture (icon_info));
    default:
      g_warning ("Image storage type %d not handled",
                 gtk_image_get_storage_type (image));
      return NULL;
    }
}