diff options
author | Benjamin Otte <otte@redhat.com> | 2017-01-22 22:58:45 +0100 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2017-11-15 14:22:17 -0500 |
commit | 049cc6aa013601c4e662c38df408f8956b155f0a (patch) | |
tree | 4f8359363a1b005790b6d8cbc7d7f590fa859ee7 | |
parent | f53b72e5ffc034f003801b9d4ee64328180bc297 (diff) | |
download | gtk+-049cc6aa013601c4e662c38df408f8956b155f0a.tar.gz |
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.
-rw-r--r-- | demos/gtk-demo/clipboard.c | 3 | ||||
-rw-r--r-- | demos/icon-browser/iconbrowserwin.c | 2 | ||||
-rw-r--r-- | docs/reference/gtk/gtk4-sections.txt | 1 | ||||
-rw-r--r-- | gtk/a11y/gtkimageaccessible.c | 7 | ||||
-rw-r--r-- | gtk/gtkaboutdialog.c | 14 | ||||
-rw-r--r-- | gtk/gtkbutton.c | 4 | ||||
-rw-r--r-- | gtk/gtkimage.c | 60 | ||||
-rw-r--r-- | gtk/gtkimage.h | 10 | ||||
-rw-r--r-- | gtk/gtkmodelbutton.c | 6 | ||||
-rw-r--r-- | gtk/gtkmodelmenuitem.c | 2 | ||||
-rw-r--r-- | gtk/gtkplacesviewrow.c | 5 | ||||
-rw-r--r-- | gtk/gtkshortcutsshortcut.c | 7 | ||||
-rw-r--r-- | gtk/gtktoolbutton.c | 8 | ||||
-rw-r--r-- | 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 7e01db4759..79992da572 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 d82807566e..2ec003f936 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 892641a222..819c76558e 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 338d894e22..543152eac2 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 56c0c17e77..bfab623f2a 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 b66e8971a9..06d21bf8f0 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 29947e9b2e..e010986a55 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 f7dbd3dd1f..9e041c10ee 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 63a4fd1834..edb4790f97 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 0f05e83bc3..b33d798a10 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 70d8e8df68..87fbf1414a 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 be280e9fff..2dcb96b5aa 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 b76fe1cf72..90d7066a90 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 67d0bb99ca..c4a1c98710 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); |