[gtk+/wip/matthiasc/icon-size: 6/15] image: Change getters



commit 295612171744031823e99cb4df0e90bb7f69513a
Author: Benjamin Otte <otte redhat com>
Date:   Sun Jan 22 22:58:45 2017 +0100

    image: Change getters
    
    Instead of returning the icon size with them, make
    gtk_image_get_icon_name() and gtk_image_get_gicon() only return the icon
    itself.
    
    As a benefit, we can turn them into regular getters that return values
    instead of requiring out parameters.
    
    Instead, provide gtk_image_get_icon_size() to query the icon size.

 demos/gtk-demo/clipboard.c           |    3 +-
 demos/icon-browser/iconbrowserwin.c  |    2 +-
 docs/reference/gtk/gtk4-sections.txt |    1 +
 gtk/a11y/gtkimageaccessible.c        |    7 +---
 gtk/gtkaboutdialog.c                 |   14 ++------
 gtk/gtkbutton.c                      |    4 +--
 gtk/gtkimage.c                       |   60 +++++++++++++++++----------------
 gtk/gtkimage.h                       |   10 ++---
 gtk/gtkmodelbutton.c                 |    6 +---
 gtk/gtkmodelmenuitem.c               |    2 +-
 gtk/gtkplacesviewrow.c               |    5 +--
 gtk/gtkshortcutsshortcut.c           |    7 +---
 gtk/gtktoolbutton.c                  |    8 ++--
 tests/testdnd2.c                     |    7 ++--
 14 files changed, 56 insertions(+), 80 deletions(-)
---
diff --git a/demos/gtk-demo/clipboard.c b/demos/gtk-demo/clipboard.c
index f0b4154..7fc0c5d 100644
--- a/demos/gtk-demo/clipboard.c
+++ b/demos/gtk-demo/clipboard.c
@@ -68,7 +68,6 @@ static cairo_surface_t *
 get_image_surface (GtkImage *image)
 {
   const gchar *icon_name;
-  GtkIconSize size;
   GtkIconTheme *icon_theme;
   int width;
 
@@ -77,7 +76,7 @@ get_image_surface (GtkImage *image)
     case GTK_IMAGE_SURFACE:
       return cairo_surface_reference (gtk_image_get_surface (image));
     case GTK_IMAGE_ICON_NAME:
-      gtk_image_get_icon_name (image, &icon_name, &size);
+      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 (size, &width, NULL);
       return gtk_icon_theme_load_surface (icon_theme, icon_name, width, 1, NULL, 
GTK_ICON_LOOKUP_GENERIC_FALLBACK, NULL);
diff --git a/demos/icon-browser/iconbrowserwin.c b/demos/icon-browser/iconbrowserwin.c
index bd0e0d4..4f02365 100644
--- a/demos/icon-browser/iconbrowserwin.c
+++ b/demos/icon-browser/iconbrowserwin.c
@@ -390,7 +390,7 @@ get_image_data (GtkWidget        *widget,
 
   image = gtk_bin_get_child (GTK_BIN (widget));
 
-  gtk_image_get_icon_name (GTK_IMAGE (image), &name, NULL);
+  name = gtk_image_get_icon_name (GTK_IMAGE (image));
   size = gtk_image_get_pixel_size (GTK_IMAGE (image));
 
   pixbuf = get_icon (image, name, size);
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 5d67aaa..1e796eb 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -1509,6 +1509,7 @@ gtk_image_clear
 gtk_image_new
 gtk_image_set_pixel_size
 gtk_image_get_pixel_size
+gtk_image_get_icon_size
 <SUBSECTION Standard>
 GTK_IMAGE
 GTK_IS_IMAGE
diff --git a/gtk/a11y/gtkimageaccessible.c b/gtk/a11y/gtkimageaccessible.c
index 338d894..543152e 100644
--- a/gtk/a11y/gtkimageaccessible.c
+++ b/gtk/a11y/gtkimageaccessible.c
@@ -192,17 +192,14 @@ gtk_image_accessible_get_name (AtkObject *accessible)
 
   if (storage_type == GTK_IMAGE_ICON_NAME)
     {
-      const gchar *icon_name;
-
-      gtk_image_get_icon_name (image, &icon_name, NULL);
-      image_accessible->priv->stock_name = name_from_icon_name (icon_name);
+      image_accessible->priv->stock_name = name_from_icon_name (gtk_image_get_icon_name (image));
     }
   else if (storage_type == GTK_IMAGE_GICON)
     {
       GIcon *icon;
       const gchar * const *icon_names;
 
-      gtk_image_get_gicon (image, &icon, NULL);
+      icon = gtk_image_get_gicon (image);
       if (G_IS_THEMED_ICON (icon))
         {
          icon_names = g_themed_icon_get_names (G_THEMED_ICON (icon));
diff --git a/gtk/gtkaboutdialog.c b/gtk/gtkaboutdialog.c
index 56c0c17..bfab623 100644
--- a/gtk/gtkaboutdialog.c
+++ b/gtk/gtkaboutdialog.c
@@ -961,12 +961,7 @@ gtk_about_dialog_get_property (GObject    *object,
       break;
     case PROP_LOGO_ICON_NAME:
       if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
-        {
-          const gchar *icon_name;
-
-          gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
-          g_value_set_string (value, icon_name);
-        }
+        g_value_set_string (value, gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image)));
       else
         g_value_set_string (value, NULL);
       break;
@@ -1862,16 +1857,15 @@ const gchar *
 gtk_about_dialog_get_logo_icon_name (GtkAboutDialog *about)
 {
   GtkAboutDialogPrivate *priv;
-  const gchar *icon_name = NULL;
 
   g_return_val_if_fail (GTK_IS_ABOUT_DIALOG (about), NULL);
 
   priv = about->priv;
 
-  if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) == GTK_IMAGE_ICON_NAME)
-    gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image), &icon_name, NULL);
+  if (gtk_image_get_storage_type (GTK_IMAGE (priv->logo_image)) != GTK_IMAGE_ICON_NAME)
+    return NULL;
 
-  return icon_name;
+  return gtk_image_get_icon_name (GTK_IMAGE (priv->logo_image));
 }
 
 /**
diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c
index b66e897..06d21bf 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -1139,11 +1139,9 @@ gtk_button_get_icon_name (GtkButton *button)
 
   if (priv->child_type == ICON_CHILD)
     {
-      const char *icon_name;
       GtkWidget *child = gtk_bin_get_child (GTK_BIN (button));
-      gtk_image_get_icon_name (GTK_IMAGE (child), &icon_name, NULL);
 
-      return icon_name;
+      return gtk_image_get_icon_name (GTK_IMAGE (child));
     }
 
   return NULL;
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index 29947e9..e010986 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -1053,42 +1053,30 @@ gtk_image_get_texture (GtkImage *image)
 /**
  * gtk_image_get_icon_name:
  * @image: a #GtkImage
- * @icon_name: (out) (transfer none) (allow-none): place to store an
- *     icon name, or %NULL
- * @size: (out) (allow-none) (type int): place to store an icon size
- *     (#GtkIconSize), or %NULL
  *
  * Gets the icon name and size being displayed by the #GtkImage.
  * The storage type of the image must be %GTK_IMAGE_EMPTY or
  * %GTK_IMAGE_ICON_NAME (see gtk_image_get_storage_type()).
  * The returned string is owned by the #GtkImage and should not
  * be freed.
- * 
+ *
+ * Returns: (transfer none) (allow-none): the icon name, or %NULL
+ *
  * Since: 2.6
  **/
-void
-gtk_image_get_icon_name  (GtkImage     *image,
-                         const gchar **icon_name,
-                         GtkIconSize  *size)
+const gchar *
+gtk_image_get_icon_name (GtkImage *image)
 {
   GtkImagePrivate *priv = gtk_image_get_instance_private (image);
 
-  g_return_if_fail (GTK_IS_IMAGE (image));
-
-  if (icon_name)
-    *icon_name = _gtk_icon_helper_get_icon_name (&priv->icon_helper);
+  g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
 
-  if (size)
-    *size = _gtk_icon_helper_get_icon_size (&priv->icon_helper);
+  return _gtk_icon_helper_get_icon_name (&priv->icon_helper);
 }
 
 /**
  * gtk_image_get_gicon:
  * @image: a #GtkImage
- * @gicon: (out) (transfer none) (allow-none): place to store a
- *     #GIcon, or %NULL
- * @size: (out) (allow-none) (type int): place to store an icon size
- *     (#GtkIconSize), or %NULL
  *
  * Gets the #GIcon and size being displayed by the #GtkImage.
  * The storage type of the image must be %GTK_IMAGE_EMPTY or
@@ -1096,22 +1084,18 @@ gtk_image_get_icon_name  (GtkImage     *image,
  * The caller of this function does not own a reference to the
  * returned #GIcon.
  * 
+ * Returns: (transfer none) (allow-none): a #GIcon, or %NULL
+ *
  * Since: 2.14
  **/
-void
-gtk_image_get_gicon (GtkImage     *image,
-                    GIcon       **gicon,
-                    GtkIconSize  *size)
+GIcon *
+gtk_image_get_gicon (GtkImage *image)
 {
   GtkImagePrivate *priv = gtk_image_get_instance_private (image);
 
-  g_return_if_fail (GTK_IS_IMAGE (image));
-
-  if (gicon)
-    *gicon = _gtk_icon_helper_peek_gicon (&priv->icon_helper);
+  g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
 
-  if (size)
-    *size = _gtk_icon_helper_get_icon_size (&priv->icon_helper);
+  return _gtk_icon_helper_peek_gicon (&priv->icon_helper);
 }
 
 /**
@@ -1396,3 +1380,21 @@ gtk_image_get_pixel_size (GtkImage *image)
 
   return _gtk_icon_helper_get_pixel_size (&priv->icon_helper);
 }
+
+/**
+ * gtk_image_get_icon_size:
+ * @image: a #GtkImage
+ *
+ * Gets the icon size used by the @image when rendering icons.
+ *
+ * Returns: the image size used by icons
+ *
+ * Since: 3.90
+ **/
+GtkIconSize
+gtk_image_get_icon_size (GtkImage *image)
+{
+  g_return_val_if_fail (GTK_IS_IMAGE (image), GTK_ICON_SIZE_INVALID);
+
+  return _gtk_icon_helper_get_icon_size (image->priv->icon_helper);
+}
diff --git a/gtk/gtkimage.h b/gtk/gtkimage.h
index f7dbd3d..9e041c1 100644
--- a/gtk/gtkimage.h
+++ b/gtk/gtkimage.h
@@ -159,15 +159,13 @@ GDK_AVAILABLE_IN_3_94
 GdkTexture *gtk_image_get_texture  (GtkImage       *image);
 
 GDK_AVAILABLE_IN_ALL
-void       gtk_image_get_icon_name (GtkImage     *image,
-                                   const gchar **icon_name,
-                                   GtkIconSize  *size);
+const char *gtk_image_get_icon_name (GtkImage     *image);
 GDK_AVAILABLE_IN_ALL
-void       gtk_image_get_gicon     (GtkImage              *image,
-                                   GIcon                **gicon,
-                                   GtkIconSize           *size);
+GIcon *    gtk_image_get_gicon     (GtkImage              *image);
 GDK_AVAILABLE_IN_ALL
 gint       gtk_image_get_pixel_size (GtkImage             *image);
+GDK_AVAILABLE_IN_3_94
+GtkIconSize gtk_image_get_icon_size (GtkImage             *image);
 
 G_END_DECLS
 
diff --git a/gtk/gtkmodelbutton.c b/gtk/gtkmodelbutton.c
index 63a4fd1..edb4790 100644
--- a/gtk/gtkmodelbutton.c
+++ b/gtk/gtkmodelbutton.c
@@ -496,11 +496,7 @@ gtk_model_button_get_property (GObject    *object,
       break;
 
     case PROP_ICON:
-      {
-        GIcon *icon;
-        gtk_image_get_gicon (GTK_IMAGE (button->image), &icon, NULL);
-        g_value_set_object (value, icon);
-      }
+      g_value_set_object (value, gtk_image_get_gicon (GTK_IMAGE (button->image)));
       break;
 
     case PROP_TEXT:
diff --git a/gtk/gtkmodelmenuitem.c b/gtk/gtkmodelmenuitem.c
index 0f05e83..b33d798 100644
--- a/gtk/gtkmodelmenuitem.c
+++ b/gtk/gtkmodelmenuitem.c
@@ -213,7 +213,7 @@ gtk_model_menu_item_get_icon (GtkModelMenuItem *item)
         {
           if (GTK_IS_IMAGE (l->data))
             {
-              gtk_image_get_gicon (GTK_IMAGE (l->data), &icon, NULL);
+              icon = gtk_image_get_gicon (GTK_IMAGE (l->data));
               break;
             }
         }
diff --git a/gtk/gtkplacesviewrow.c b/gtk/gtkplacesviewrow.c
index 70d8e8d..87fbf14 100644
--- a/gtk/gtkplacesviewrow.c
+++ b/gtk/gtkplacesviewrow.c
@@ -214,16 +214,13 @@ gtk_places_view_row_get_property (GObject    *object,
                                   GParamSpec *pspec)
 {
   GtkPlacesViewRow *self;
-  GIcon *icon;
 
   self = GTK_PLACES_VIEW_ROW (object);
-  icon = NULL;
 
   switch (prop_id)
     {
     case PROP_ICON:
-      gtk_image_get_gicon (self->icon_image, &icon, NULL);
-      g_value_set_object (value, icon);
+      g_value_set_object (value, gtk_image_get_gicon (self->icon_image));
       break;
 
     case PROP_NAME:
diff --git a/gtk/gtkshortcutsshortcut.c b/gtk/gtkshortcutsshortcut.c
index be280e9..2dcb96b 100644
--- a/gtk/gtkshortcutsshortcut.c
+++ b/gtk/gtkshortcutsshortcut.c
@@ -369,12 +369,7 @@ gtk_shortcuts_shortcut_get_property (GObject    *object,
       break;
 
     case PROP_ICON:
-      {
-        GIcon *icon;
-
-        gtk_image_get_gicon (self->image, &icon, NULL);
-        g_value_set_object (value, icon);
-      }
+      g_value_set_object (value, gtk_image_get_gicon (self->image));
       break;
 
     case PROP_ICON_SET:
diff --git a/gtk/gtktoolbutton.c b/gtk/gtktoolbutton.c
index b76fe1c..90d7066 100644
--- a/gtk/gtktoolbutton.c
+++ b/gtk/gtktoolbutton.c
@@ -711,14 +711,14 @@ clone_image_menu_size (GtkImage *image)
 
   if (storage_type == GTK_IMAGE_ICON_NAME)
     {
-      const gchar *icon_name;
-      gtk_image_get_icon_name (image, &icon_name, NULL);
+      const gchar *icon_name = gtk_image_get_icon_name (image);
+
       return gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
     }
   else if (storage_type == GTK_IMAGE_GICON)
     {
-      GIcon *icon;
-      gtk_image_get_gicon (image, &icon, NULL);
+      GIcon *icon = gtk_image_get_gicon (image);
+
       return gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_MENU);
     }
   else if (storage_type == GTK_IMAGE_SURFACE)
diff --git a/tests/testdnd2.c b/tests/testdnd2.c
index fe0e2ec..684a592 100644
--- a/tests/testdnd2.c
+++ b/tests/testdnd2.c
@@ -4,8 +4,6 @@ static cairo_surface_t *
 get_image_surface (GtkImage *image,
                    int      *out_size)
 {
-  const gchar *icon_name;
-  GtkIconSize size;
   GtkIconTheme *icon_theme;
   int width;
   cairo_surface_t *surface;
@@ -17,7 +15,8 @@ get_image_surface (GtkImage *image,
       *out_size = cairo_image_surface_get_width (surface);
       return cairo_surface_reference (surface);
     case GTK_IMAGE_ICON_NAME:
-      gtk_image_get_icon_name (image, &icon_name, &size);
+<<<<<<< HEAD
+      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 (size, &width, NULL);
       *out_size = width;
@@ -175,7 +174,7 @@ image_drag_data_get (GtkWidget        *widget,
       break;
     case TARGET_TEXT:
       if (gtk_image_get_storage_type (GTK_IMAGE (data)) == GTK_IMAGE_ICON_NAME)
-        gtk_image_get_icon_name (GTK_IMAGE (data), &name, NULL);
+        name = gtk_image_get_icon_name (GTK_IMAGE (data));
       else
         name = "Boo!";
       gtk_selection_data_set_text (selection_data, name, -1);


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