[gtk+/wip/otte/icon-size: 10/20] image: Change getters
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/otte/icon-size: 10/20] image: Change getters
- Date: Fri, 10 Nov 2017 21:04:55 +0000 (UTC)
commit 1683230afabcce1707307d0c66af416bdb109bb9
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 | 5 +--
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 | 58 +++++++++++++++++----------------
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 | 9 ++---
14 files changed, 56 insertions(+), 82 deletions(-)
---
diff --git a/demos/gtk-demo/clipboard.c b/demos/gtk-demo/clipboard.c
index 4a038d6..39d159f 100644
--- a/demos/gtk-demo/clipboard.c
+++ b/demos/gtk-demo/clipboard.c
@@ -68,7 +68,6 @@ static GdkPixbuf *
get_image_pixbuf (GtkImage *image)
{
const gchar *icon_name;
- GtkIconSize size;
GtkIconTheme *icon_theme;
int width;
@@ -77,9 +76,9 @@ get_image_pixbuf (GtkImage *image)
case GTK_IMAGE_PIXBUF:
return g_object_ref (gtk_image_get_pixbuf (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_screen (gtk_widget_get_screen (GTK_WIDGET (image)));
- gtk_icon_size_lookup (size, &width, NULL);
+ gtk_icon_size_lookup (GTK_ICON_SIZE_BUTTON, &width, NULL);
return gtk_icon_theme_load_icon (icon_theme,
icon_name,
width,
diff --git a/demos/icon-browser/iconbrowserwin.c b/demos/icon-browser/iconbrowserwin.c
index 7645dca..c59fd48 100644
--- a/demos/icon-browser/iconbrowserwin.c
+++ b/demos/icon-browser/iconbrowserwin.c
@@ -775,7 +775,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 ca53949..10629ca 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -1508,6 +1508,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 dc398c8..a83a993 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 490a66d..0683004 100644
--- a/gtk/gtkaboutdialog.c
+++ b/gtk/gtkaboutdialog.c
@@ -991,12 +991,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;
@@ -1890,16 +1885,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 1cefee5..75fa520 100644
--- a/gtk/gtkbutton.c
+++ b/gtk/gtkbutton.c
@@ -1390,11 +1390,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 d788270..63f33f2 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -1164,10 +1164,6 @@ gtk_image_get_animation (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
@@ -1175,33 +1171,25 @@ gtk_image_get_animation (GtkImage *image)
* 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;
- g_return_if_fail (GTK_IS_IMAGE (image));
+ g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
priv = image->priv;
- if (icon_name)
- *icon_name = _gtk_icon_helper_get_icon_name (priv->icon_helper);
-
- 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
@@ -1209,24 +1197,20 @@ 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;
- g_return_if_fail (GTK_IS_IMAGE (image));
+ g_return_val_if_fail (GTK_IS_IMAGE (image), NULL);
priv = image->priv;
- if (gicon)
- *gicon = _gtk_icon_helper_peek_gicon (priv->icon_helper);
-
- if (size)
- *size = _gtk_icon_helper_get_icon_size (priv->icon_helper);
+ return _gtk_icon_helper_peek_gicon (priv->icon_helper);
}
/**
@@ -1649,3 +1633,21 @@ gtk_image_get_pixel_size (GtkImage *image)
return _gtk_icon_helper_get_pixel_size (image->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 e187032..e5a20d9 100644
--- a/gtk/gtkimage.h
+++ b/gtk/gtkimage.h
@@ -162,15 +162,13 @@ GdkPixbuf* gtk_image_get_pixbuf (GtkImage *image);
GDK_AVAILABLE_IN_ALL
GdkPixbufAnimation* gtk_image_get_animation (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_90
+GtkIconSize gtk_image_get_icon_size (GtkImage *image);
G_END_DECLS
diff --git a/gtk/gtkmodelbutton.c b/gtk/gtkmodelbutton.c
index 21dceec..1d1f839 100644
--- a/gtk/gtkmodelbutton.c
+++ b/gtk/gtkmodelbutton.c
@@ -503,11 +503,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 7c5264c..92fbaea 100644
--- a/gtk/gtkmodelmenuitem.c
+++ b/gtk/gtkmodelmenuitem.c
@@ -224,7 +224,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 61dd1f5..b9306a7 100644
--- a/gtk/gtkplacesviewrow.c
+++ b/gtk/gtkplacesviewrow.c
@@ -216,16 +216,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 93e28ec..8e7e933 100644
--- a/gtk/gtkshortcutsshortcut.c
+++ b/gtk/gtkshortcutsshortcut.c
@@ -368,12 +368,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 ab6a43a..74d4c25 100644
--- a/gtk/gtktoolbutton.c
+++ b/gtk/gtktoolbutton.c
@@ -719,14 +719,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_PIXBUF)
diff --git a/tests/testdnd2.c b/tests/testdnd2.c
index 029c24d..7b7c508 100644
--- a/tests/testdnd2.c
+++ b/tests/testdnd2.c
@@ -3,8 +3,6 @@
static GdkPixbuf *
get_image_pixbuf (GtkImage *image)
{
- const gchar *icon_name;
- GtkIconSize size;
GtkIconTheme *icon_theme;
int width;
@@ -13,11 +11,10 @@ get_image_pixbuf (GtkImage *image)
case GTK_IMAGE_PIXBUF:
return g_object_ref (gtk_image_get_pixbuf (image));
case GTK_IMAGE_ICON_NAME:
- gtk_image_get_icon_name (image, &icon_name, &size);
icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (image)));
- gtk_icon_size_lookup (size, &width, NULL);
+ gtk_icon_size_lookup (GTK_ICON_SIZE_DIALOG, &width, NULL);
return gtk_icon_theme_load_icon (icon_theme,
- icon_name,
+ gtk_image_get_icon_name (image),
width,
GTK_ICON_LOOKUP_GENERIC_FALLBACK,
NULL);
@@ -175,7 +172,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]