[gtk+] Drop gtk_icon_size_lookup



commit 0d23606653fdb3473d7f56f1df14dd0f5572da97
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Nov 14 23:30:58 2017 -0500

    Drop gtk_icon_size_lookup
    
    Add a new, private gtk_image_get_image_size to replace it, and
    update the remaining callers in a suitable way.

 demos/gtk-demo/clipboard.c    |    4 +--
 demos/gtk-demo/toolpalette.c  |    4 +--
 gtk/a11y/gtkimageaccessible.c |   42 ++-------------------------
 gtk/gtkcellrendererspinner.c  |   26 ++++++++++++----
 gtk/gtkicontheme.c            |   63 -----------------------------------------
 gtk/gtkicontheme.h            |    5 ---
 gtk/gtkimage.c                |   10 ++++++
 gtk/gtkimageprivate.h         |    5 +++
 gtk/gtkprintunixdialog.c      |   19 ------------
 gtk/gtktoolbutton.c           |   48 +++++++++++++++----------------
 tests/testdnd2.c              |    3 +-
 11 files changed, 63 insertions(+), 166 deletions(-)
---
diff --git a/demos/gtk-demo/clipboard.c b/demos/gtk-demo/clipboard.c
index 859017f..9fc2cd9 100644
--- a/demos/gtk-demo/clipboard.c
+++ b/demos/gtk-demo/clipboard.c
@@ -69,7 +69,6 @@ get_image_surface (GtkImage *image)
 {
   const gchar *icon_name;
   GtkIconTheme *icon_theme;
-  int width;
 
   switch (gtk_image_get_storage_type (image))
     {
@@ -78,8 +77,7 @@ get_image_surface (GtkImage *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)));
-      gtk_icon_size_lookup (GTK_ICON_SIZE_INHERIT, &width, NULL);
-      return gtk_icon_theme_load_surface (icon_theme, icon_name, width, 1, NULL, 
GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
+      return gtk_icon_theme_load_surface (icon_theme, icon_name, 48, 1, NULL, 
GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
     default:
       g_warning ("Image storage type %d not handled",
                  gtk_image_get_storage_type (image));
diff --git a/demos/gtk-demo/toolpalette.c b/demos/gtk-demo/toolpalette.c
index 922e499..164f6c9 100644
--- a/demos/gtk-demo/toolpalette.c
+++ b/demos/gtk-demo/toolpalette.c
@@ -39,14 +39,12 @@ canvas_item_new (GtkWidget     *widget,
   const gchar *icon_name;
   GdkPixbuf *pixbuf;
   GtkIconTheme *icon_theme;
-  int width;
 
   icon_name = gtk_tool_button_get_icon_name (button);
   icon_theme = gtk_icon_theme_get_for_display (gtk_widget_get_display (widget));
-  gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE, &width, NULL);
   pixbuf = gtk_icon_theme_load_icon (icon_theme,
                                      icon_name,
-                                     width,
+                                     48,
                                      GTK_ICON_LOOKUP_GENERIC_FALLBACK,
                                      NULL);
 
diff --git a/gtk/a11y/gtkimageaccessible.c b/gtk/a11y/gtkimageaccessible.c
index 543152e..e4837d1 100644
--- a/gtk/a11y/gtkimageaccessible.c
+++ b/gtk/a11y/gtkimageaccessible.c
@@ -21,6 +21,7 @@
 #include <gtk/gtk.h>
 #include "gtkimageaccessible.h"
 #include "gtktoolbarprivate.h"
+#include "gtkimageprivate.h"
 #include "gtkintl.h"
 
 struct _GtkImageAccessiblePrivate
@@ -252,7 +253,6 @@ gtk_image_accessible_get_image_size (AtkImage *image,
 {
   GtkWidget* widget;
   GtkImage *gtk_image;
-  GtkImageType image_type;
 
   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (image));
   if (widget == NULL)
@@ -264,44 +264,8 @@ gtk_image_accessible_get_image_size (AtkImage *image,
 
   gtk_image = GTK_IMAGE (widget);
 
-  image_type = gtk_image_get_storage_type (gtk_image);
-  switch (image_type)
-    {
-    case GTK_IMAGE_SURFACE:
-      {
-        cairo_surface_t *surface;
-
-        surface = gtk_image_get_surface (gtk_image);
-        *height = cairo_image_surface_get_height (surface);
-        *width = cairo_image_surface_get_width (surface);
-        break;
-      }
-    case GTK_IMAGE_TEXTURE:
-      {
-        GdkTexture *texture;
-
-        texture = gtk_image_get_texture (gtk_image);
-        *height = gdk_texture_get_height (texture);
-        *width = gdk_texture_get_width (texture);
-        break;
-      }
-    case GTK_IMAGE_ICON_NAME:
-    case GTK_IMAGE_GICON:
-      {
-        GtkIconSize size;
-
-        g_object_get (gtk_image, "icon-size", &size, NULL);
-        gtk_icon_size_lookup (size, width, height);
-        break;
-      }
-    case GTK_IMAGE_EMPTY:
-    default:
-      {
-        *height = -1;
-        *width = -1;
-        break;
-      }
-    }
+  if (gtk_image_get_storage_type (gtk_image) != GTK_IMAGE_EMPTY)
+    gtk_image_get_image_size (gtk_image, width, height);
 }
 
 static gboolean
diff --git a/gtk/gtkcellrendererspinner.c b/gtk/gtkcellrendererspinner.c
index 11b8ff9..46282ea 100644
--- a/gtk/gtkcellrendererspinner.c
+++ b/gtk/gtkcellrendererspinner.c
@@ -28,11 +28,13 @@
 #include "config.h"
 
 #include "gtkcellrendererspinner.h"
-#include "gtkicontheme.h"
+#include "gtkiconhelperprivate.h"
 #include "gtkintl.h"
 #include "gtksettings.h"
 #include "gtksnapshot.h"
 #include "gtktypebuiltins.h"
+#include "gtkstylecontextprivate.h"
+#include "gtkcssnumbervalueprivate.h"
 
 #include <math.h>
 
@@ -186,12 +188,22 @@ gtk_cell_renderer_spinner_update_size (GtkCellRendererSpinner *cell,
                                        GtkWidget              *widget)
 {
   GtkCellRendererSpinnerPrivate *priv = cell->priv;
-
-  if (!gtk_icon_size_lookup (priv->icon_size, &priv->size, NULL))
-    {
-      g_warning ("Invalid icon size %u", priv->icon_size);
-      priv->size = 24;
-    }
+  GtkStyleContext *context;
+  GtkIconHelper icon_helper;
+  GtkCssNode *node;
+  GtkCssStyle *style;
+
+  context = gtk_widget_get_style_context (widget);
+  gtk_style_context_save (context);
+
+  gtk_style_context_add_class (context, "spinner");
+  node = gtk_style_context_get_node (context);
+  gtk_icon_size_set_style_classes (node, priv->icon_size);
+  style = gtk_css_node_get_style (node);
+  priv->size = _gtk_css_number_value_get (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SIZE), 100);
+
+  gtk_icon_helper_destroy (&icon_helper);
+  gtk_style_context_restore (context);
 }
 
 static void
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index 239ea4e..5250672 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -5347,66 +5347,3 @@ gtk_icon_info_new_for_file (GFile *file,
 
  return info;
 }
-
-typedef struct _IconSize IconSize;
-
-struct _IconSize
-{
-  int width;
-  int height;
-};
-
-static const IconSize icon_sizes[] = {
-  [GTK_ICON_SIZE_INHERIT] = {
-    .width = 16,
-    .height = 16,
-  },
-  [GTK_ICON_SIZE_NORMAL] = {
-    .width = 16,
-    .height = 16,
-  },
-  [GTK_ICON_SIZE_LARGE] = {
-    .width = 32,
-    .height = 32,
-  },
-};
-
-/**
- * gtk_icon_size_lookup:
- * @size: (type int): an icon size (#GtkIconSize)
- * @width: (out) (optional): location to store icon width
- * @height: (out) (optional): location to store icon height
- *
- * Obtains the pixel size of a semantic icon size @size:
- * #GTK_ICON_NORMAL, #GTK_ICON_SIZE_LARGE, etc.  This function
- * isn’t normally needed, gtk_icon_theme_load_icon() is the usual
- * way to get an icon for rendering, then just look at the size of
- * the rendered pixbuf. The rendered pixbuf may not even correspond to
- * the width/height returned by gtk_icon_size_lookup(), because themes
- * are free to render the pixbuf however they like, including changing
- * the usual size.
- *
- * Returns: %TRUE if @size was a valid size
- */
-gboolean
-gtk_icon_size_lookup (GtkIconSize  size,
-                      gint        *widthp,
-                      gint        *heightp)
-{
-  GTK_NOTE (MULTIHEAD,
-            g_warning ("gtk_icon_size_lookup ()) is not multihead safe"));
-
-  if (size == (GtkIconSize)-1)
-    return FALSE;
-
-  if (size >= G_N_ELEMENTS (icon_sizes))
-    return FALSE;
-
-  if (widthp)
-    *widthp = icon_sizes[size].width;
-
-  if (heightp)
-    *heightp = icon_sizes[size].height;
-
-  return TRUE;
-}
diff --git a/gtk/gtkicontheme.h b/gtk/gtkicontheme.h
index b9447ba..360e73d 100644
--- a/gtk/gtkicontheme.h
+++ b/gtk/gtkicontheme.h
@@ -345,11 +345,6 @@ GdkPixbuf *           gtk_icon_info_load_symbolic_for_context_finish (GtkIconInf
                                                                      gboolean         *was_symbolic,
                                                                      GError          **error);
 
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_icon_size_lookup (GtkIconSize  size,
-                               gint        *width,
-                               gint        *height);
-
 
 G_END_DECLS
 
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 3c289b3..c8837a1 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -1399,3 +1399,13 @@ gtk_image_get_icon_size (GtkImage *image)
 
   return priv->icon_size;
 }
+
+void
+gtk_image_get_image_size (GtkImage *image,
+                          int      *width,
+                          int      *height)
+{
+  GtkImagePrivate *priv = gtk_image_get_instance_private (image);
+
+  _gtk_icon_helper_get_size (&priv->icon_helper, width, height);
+}
diff --git a/gtk/gtkimageprivate.h b/gtk/gtkimageprivate.h
index 58b1804..04b99c1 100644
--- a/gtk/gtkimageprivate.h
+++ b/gtk/gtkimageprivate.h
@@ -38,6 +38,11 @@ void            gtk_image_set_from_definition           (GtkImage
 
 GtkImageDefinition * gtk_image_get_definition           (GtkImage *image);
 
+void            gtk_image_get_image_size                (GtkImage               *image,
+                                                         int                    *width,
+                                                         int                    *height);
+
+
 G_END_DECLS
 
 #endif /* __GTK_IMAGE_H__ */
diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c
index 5b31d59..25b9e64 100644
--- a/gtk/gtkprintunixdialog.c
+++ b/gtk/gtkprintunixdialog.c
@@ -134,7 +134,6 @@ static void     gtk_print_unix_dialog_get_property (GObject            *object,
                                                     guint               prop_id,
                                                     GValue             *value,
                                                     GParamSpec         *pspec);
-static void     gtk_print_unix_dialog_style_updated (GtkWidget          *widget);
 static void     unschedule_idle_mark_conflicts     (GtkPrintUnixDialog *dialog);
 static void     selected_printer_changed           (GtkTreeSelection   *selection,
                                                     GtkPrintUnixDialog *dialog);
@@ -406,7 +405,6 @@ gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
   object_class->set_property = gtk_print_unix_dialog_set_property;
   object_class->get_property = gtk_print_unix_dialog_get_property;
 
-  widget_class->style_updated = gtk_print_unix_dialog_style_updated;
   widget_class->destroy = gtk_print_unix_dialog_destroy;
 
   g_object_class_install_property (object_class,
@@ -2303,23 +2301,6 @@ draw_collate (GtkDrawingArea *da,
 }
 
 static void
-gtk_print_unix_dialog_style_updated (GtkWidget *widget)
-{
-  GtkPrintUnixDialog *dialog = (GtkPrintUnixDialog *)widget;
-  GtkPrintUnixDialogPrivate *priv = dialog->priv;
-  gint size;
-  gfloat scale;
-
-  GTK_WIDGET_CLASS (gtk_print_unix_dialog_parent_class)->style_updated (widget);
-
-  gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE, &size, NULL);
-  scale = size / 48.0;
-
-  gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (priv->collate_image), (50 + 20) * scale);
-  gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (priv->collate_image), (15 + 26) * scale);
-}
-
-static void
 update_page_range_entry_sensitivity (GtkWidget *button,
                                     GtkPrintUnixDialog *dialog)
 {
diff --git a/gtk/gtktoolbutton.c b/gtk/gtktoolbutton.c
index ce6f63b..d8685e7 100644
--- a/gtk/gtktoolbutton.c
+++ b/gtk/gtktoolbutton.c
@@ -21,7 +21,7 @@
 #include "config.h"
 #include "gtktoolbutton.h"
 #include "gtkbutton.h"
-#include "gtkimage.h"
+#include "gtkimageprivate.h"
 #include "gtklabel.h"
 #include "gtkbox.h"
 #include "gtkintl.h"
@@ -716,33 +716,31 @@ clone_image_menu_size (GtkImage *image)
     }
   else if (storage_type == GTK_IMAGE_SURFACE)
     {
-      gint width, height;
+      int width, height;
+      cairo_surface_t *src_surface, *dest_surface;
+      GtkWidget *cloned_image;
+      gint scale = gtk_widget_get_scale_factor (GTK_WIDGET (image));
+      cairo_t *cr;
 
-      if (gtk_icon_size_lookup (GTK_ICON_SIZE_NORMAL, &width, &height))
-        {
-          cairo_surface_t *src_surface, *dest_surface;
-          GtkWidget *cloned_image;
-          gint scale = gtk_widget_get_scale_factor (GTK_WIDGET (image));
-          cairo_t *cr;
-
-          src_surface = gtk_image_get_surface (image);
-          dest_surface =
-            gdk_window_create_similar_image_surface (gtk_widget_get_window (GTK_WIDGET(image)),
+      gtk_image_get_image_size (image, &width, &height);
+
+      src_surface = gtk_image_get_surface (image);
+      dest_surface =
+            gdk_window_create_similar_image_surface (gtk_widget_get_window (GTK_WIDGET (image)),
                                                      CAIRO_FORMAT_ARGB32,
                                                      width * scale, height * scale, scale);
-          cr = cairo_create (dest_surface);
-          cairo_set_source_surface (cr, src_surface, 0, 0);
-          cairo_scale (cr,
-                       width / cairo_image_surface_get_width (src_surface),
-                       height / cairo_image_surface_get_height (src_surface));
-          cairo_paint (cr);
-          cairo_destroy (cr);
-
-          cloned_image = gtk_image_new_from_surface (dest_surface);
-          cairo_surface_destroy (dest_surface);
-
-         return cloned_image;
-       }
+      cr = cairo_create (dest_surface);
+      cairo_set_source_surface (cr, src_surface, 0, 0);
+      cairo_scale (cr,
+                   width / cairo_image_surface_get_width (src_surface),
+                   height / cairo_image_surface_get_height (src_surface));
+      cairo_paint (cr);
+      cairo_destroy (cr);
+
+      cloned_image = gtk_image_new_from_surface (dest_surface);
+      cairo_surface_destroy (dest_surface);
+
+      return cloned_image;
     }
 
   return NULL;
diff --git a/tests/testdnd2.c b/tests/testdnd2.c
index 2b4f405..d2f5f24 100644
--- a/tests/testdnd2.c
+++ b/tests/testdnd2.c
@@ -6,7 +6,7 @@ get_image_surface (GtkImage *image,
 {
   GtkIconTheme *icon_theme;
   const char *icon_name;
-  int width;
+  int width = 48;
   cairo_surface_t *surface;
 
   switch (gtk_image_get_storage_type (image))
@@ -18,7 +18,6 @@ get_image_surface (GtkImage *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)));
-      gtk_icon_size_lookup (GTK_ICON_SIZE_LARGE, &width, NULL);
       *out_size = width;
       return gtk_icon_theme_load_surface (icon_theme, icon_name, width, 1, NULL, 
GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
     default:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]