2 * gtknumerableicon.c: an emblemed icon with number emblems
4 * Copyright (C) 2010 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Authors: Cosimo Cecchi <cosimoc@redhat.com>
23 * SECTION:gtknumerableicon
24 * @Title: GtkNumerableIcon
25 * @Short_description: A GIcon that allows numbered emblems
27 * GtkNumerableIcon is a subclass of #GEmblemedIcon that can
28 * show a number or short string as an emblem. The number can
29 * be overlayed on top of another emblem, if desired.
31 * It supports theming by taking font and color information
32 * from a provided #GtkStyleContext; see
33 * gtk_numerable_icon_set_style_context().
36 * <title>Typical numerable icons</title>
37 * <inlinegraphic fileref="numerableicon.png" format="PNG"/>
38 * <inlinegraphic fileref="numerableicon2.png" format="PNG"/>
43 #include "gtknumerableicon.h"
45 #include "gtkicontheme.h"
47 #include "gtkwidget.h"
48 #include "gtkwidgetpath.h"
49 #include "gtkwindow.h"
52 #include <pango/pango.h>
55 struct _GtkNumerableIconPrivate {
61 GIcon *background_icon;
62 gchar *background_icon_name;
67 PangoFontDescription *font;
68 cairo_pattern_t *background_image;
71 GtkStyleContext *style;
72 gulong style_changed_id;
74 gchar *rendered_string;
82 PROP_BACKGROUND_ICON_NAME,
86 #define DEFAULT_SURFACE_SIZE 256
87 #define DEFAULT_BORDER_SIZE DEFAULT_SURFACE_SIZE * 0.06
88 #define DEFAULT_RADIUS DEFAULT_SURFACE_SIZE / 2
90 #define DEFAULT_BACKGROUND "#000000"
91 #define DEFAULT_FOREGROUND "#ffffff"
93 static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
95 G_DEFINE_TYPE (GtkNumerableIcon, gtk_numerable_icon, G_TYPE_EMBLEMED_ICON);
98 get_surface_size (cairo_surface_t *surface)
100 return MAX (cairo_image_surface_get_width (surface), cairo_image_surface_get_height (surface));
104 get_border_size (GtkNumerableIcon *self)
106 return self->priv->border_size;
109 static cairo_surface_t *
110 draw_default_surface (GtkNumerableIcon *self)
112 cairo_surface_t *surface;
115 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
116 DEFAULT_SURFACE_SIZE, DEFAULT_SURFACE_SIZE);
118 cr = cairo_create (surface);
120 cairo_arc (cr, DEFAULT_SURFACE_SIZE / 2., DEFAULT_SURFACE_SIZE / 2.,
121 DEFAULT_RADIUS, 0., 2 * G_PI);
123 gdk_cairo_set_source_rgba (cr, self->priv->background);
126 cairo_arc (cr, DEFAULT_SURFACE_SIZE / 2., DEFAULT_SURFACE_SIZE / 2.,
127 DEFAULT_RADIUS - DEFAULT_BORDER_SIZE, 0., 2 * G_PI);
128 gdk_cairo_set_source_rgba (cr, self->priv->foreground);
131 cairo_arc (cr, DEFAULT_SURFACE_SIZE / 2., DEFAULT_SURFACE_SIZE / 2.,
132 DEFAULT_RADIUS - 2 * DEFAULT_BORDER_SIZE, 0., 2 * G_PI);
133 gdk_cairo_set_source_rgba (cr, self->priv->background);
141 static cairo_surface_t *
142 draw_from_gradient (cairo_pattern_t *pattern)
144 cairo_surface_t *surface;
145 cairo_matrix_t matrix;
148 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
149 DEFAULT_SURFACE_SIZE, DEFAULT_SURFACE_SIZE);
151 cr = cairo_create (surface);
153 /* scale the gradient points to the user space coordinates */
154 cairo_matrix_init_scale (&matrix,
155 1. / (double) DEFAULT_SURFACE_SIZE,
156 1. / (double) DEFAULT_SURFACE_SIZE);
157 cairo_pattern_set_matrix (pattern, &matrix);
159 cairo_arc (cr, DEFAULT_SURFACE_SIZE / 2., DEFAULT_SURFACE_SIZE / 2.,
160 DEFAULT_RADIUS, 0., 2 * G_PI);
162 cairo_set_source (cr, pattern);
170 /* copy the surface */
171 static cairo_surface_t *
172 draw_from_image (cairo_surface_t *image)
174 cairo_surface_t *surface;
177 surface = cairo_surface_create_similar (image, CAIRO_CONTENT_COLOR_ALPHA,
178 cairo_image_surface_get_width (image),
179 cairo_image_surface_get_height (image));
180 cr = cairo_create (surface);
182 cairo_set_source_surface (cr, image, 0, 0);
190 static cairo_surface_t *
191 draw_from_gicon (GtkNumerableIcon *self)
197 cairo_surface_t *surface;
200 if (self->priv->style != NULL)
202 screen = gtk_style_context_get_screen (self->priv->style);
203 theme = gtk_icon_theme_get_for_screen (screen);
207 theme = gtk_icon_theme_get_default ();
210 info = gtk_icon_theme_lookup_by_gicon (theme, self->priv->background_icon,
211 self->priv->icon_size,
212 GTK_ICON_LOOKUP_GENERIC_FALLBACK);
216 pixbuf = gtk_icon_info_load_icon (info, NULL);
217 gtk_icon_info_free (info);
222 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
223 gdk_pixbuf_get_width (pixbuf),
224 gdk_pixbuf_get_height (pixbuf));
226 cr = cairo_create (surface);
228 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
232 g_object_unref (pixbuf);
237 static cairo_surface_t *
238 get_image_surface (GtkNumerableIcon *self)
240 cairo_surface_t *retval = NULL, *image;
242 if (self->priv->background_icon != NULL)
244 retval = draw_from_gicon (self);
245 self->priv->border_size = 0;
247 else if (self->priv->background_image != NULL)
249 if (cairo_pattern_get_surface (self->priv->background_image, &image) == CAIRO_STATUS_SUCCESS)
250 retval = draw_from_image (image);
252 retval = draw_from_gradient (self->priv->background_image);
254 self->priv->border_size = 0;
259 retval = draw_default_surface (self);
260 self->priv->border_size = DEFAULT_BORDER_SIZE;
267 get_pango_layout (GtkNumerableIcon *self)
269 PangoContext *context;
273 if (self->priv->style != NULL)
275 screen = gtk_style_context_get_screen (self->priv->style);
276 context = gdk_pango_context_get_for_screen (screen);
277 layout = pango_layout_new (context);
279 if (self->priv->font != NULL)
280 pango_layout_set_font_description (layout, self->priv->font);
282 pango_layout_set_text (layout, self->priv->rendered_string, -1);
284 g_object_unref (context);
290 /* steal gtk text settings from the window */
291 fake = gtk_window_new (GTK_WINDOW_TOPLEVEL);
292 layout = gtk_widget_create_pango_layout (fake, self->priv->rendered_string);
293 gtk_widget_destroy (fake);
300 gtk_numerable_icon_ensure_emblem (GtkNumerableIcon *self)
303 cairo_surface_t *surface;
308 PangoAttrList *attr_list;
309 PangoAttribute *attr;
312 /* don't draw anything if the count is zero */
313 if (self->priv->rendered_string == NULL)
315 g_emblemed_icon_clear_emblems (G_EMBLEMED_ICON (self));
319 surface = get_image_surface (self);
320 cr = cairo_create (surface);
322 layout = get_pango_layout (self);
323 pango_layout_get_pixel_size (layout, &width, &height);
325 /* scale the layout to be 0.75 of the size still available for drawing */
326 scale = ((get_surface_size (surface) - 2 * get_border_size (self)) * 0.75) / (MAX (height, width));
327 attr_list = pango_attr_list_new ();
329 attr = pango_attr_scale_new (scale);
330 pango_attr_list_insert (attr_list, attr);
332 attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
333 pango_attr_list_insert (attr_list, attr);
335 pango_layout_set_attributes (layout, attr_list);
337 /* update these values */
338 pango_layout_get_pixel_size (layout, &width, &height);
340 /* move to the center */
342 get_surface_size (surface) / 2. - (gdouble) width / 2.,
343 get_surface_size (surface) / 2. - (gdouble) height / 2.);
345 gdk_cairo_set_source_rgba (cr, self->priv->foreground);
346 pango_cairo_show_layout (cr, layout);
351 gdk_pixbuf_get_from_surface (surface, 0, 0,
352 get_surface_size (surface), get_surface_size (surface));
354 emblem = g_emblem_new (G_ICON (pixbuf));
355 g_emblemed_icon_clear_emblems (G_EMBLEMED_ICON (self));
356 g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (self), emblem);
358 g_object_unref (layout);
359 g_object_unref (emblem);
360 g_object_unref (pixbuf);
362 cairo_surface_destroy (surface);
363 pango_attr_list_unref (attr_list);
367 gtk_numerable_icon_update_properties_from_style (GtkNumerableIcon *self)
369 GtkStyleContext *style = self->priv->style;
370 GtkWidgetPath *path, *saved;
371 cairo_pattern_t *pattern = NULL;
372 GdkRGBA background, foreground;
373 PangoFontDescription *font = NULL;
375 /* save an unmodified copy of the original widget path, in order
376 * to restore it later */
377 path = gtk_widget_path_copy (gtk_style_context_get_path (style));
378 saved = gtk_widget_path_copy (path);
380 if (!gtk_widget_path_is_type (path, GTK_TYPE_NUMERABLE_ICON))
382 /* append our GType to the style context to fetch appropriate colors */
383 gtk_widget_path_append_type (path, GTK_TYPE_NUMERABLE_ICON);
384 gtk_style_context_set_path (style, path);
387 gtk_style_context_get_background_color (style, gtk_style_context_get_state (style),
389 gtk_style_context_get_color (style, gtk_style_context_get_state (style),
392 if (self->priv->background != NULL)
393 gdk_rgba_free (self->priv->background);
395 self->priv->background = gdk_rgba_copy (&background);
397 if (self->priv->foreground != NULL)
398 gdk_rgba_free (self->priv->foreground);
400 self->priv->foreground = gdk_rgba_copy (&foreground);
402 gtk_style_context_get (style, gtk_style_context_get_state (style),
403 GTK_STYLE_PROPERTY_BACKGROUND_IMAGE, &pattern,
408 if (self->priv->background_image != NULL)
409 cairo_pattern_destroy (self->priv->background_image);
411 self->priv->background_image = pattern;
414 gtk_style_context_get (style, gtk_style_context_get_state (style),
415 GTK_STYLE_PROPERTY_FONT, &font,
420 if (self->priv->font != NULL)
421 pango_font_description_free (self->priv->font);
423 self->priv->font = font;
426 gtk_numerable_icon_ensure_emblem (self);
428 /* restore original widget path */
429 gtk_style_context_set_path (style, saved);
431 gtk_widget_path_free (path);
432 gtk_widget_path_free (saved);
436 gtk_numerable_icon_init_style (GtkNumerableIcon *self)
438 GtkStyleContext *style = self->priv->style;
443 gtk_numerable_icon_update_properties_from_style (self);
445 self->priv->style_changed_id =
446 g_signal_connect_swapped (style, "changed",
447 G_CALLBACK (gtk_numerable_icon_update_properties_from_style), self);
451 gtk_numerable_icon_ensure_and_replace_label (GtkNumerableIcon *self,
455 g_assert (!(label != NULL && count != 0));
457 g_free (self->priv->rendered_string);
458 self->priv->rendered_string = NULL;
462 if (self->priv->label != NULL)
464 g_free (self->priv->label);
465 self->priv->label = NULL;
467 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LABEL]);
476 self->priv->count = count;
478 /* Translators: the format here is used to build the string that will be rendered
479 * in the number emblem.
481 self->priv->rendered_string = g_strdup_printf (C_("Number format", "%d"), count);
488 if (self->priv->count != 0)
490 self->priv->count = 0;
492 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COUNT]);
495 g_free (self->priv->label);
497 if (g_strcmp0 (label, "") == 0)
499 self->priv->label = NULL;
503 self->priv->label = g_strdup (label);
504 self->priv->rendered_string = g_strdup (label);
509 real_set_background_icon (GtkNumerableIcon *self,
512 if (!g_icon_equal (self->priv->background_icon, icon))
514 g_clear_object (&self->priv->background_icon);
517 self->priv->background_icon = g_object_ref (icon);
519 gtk_numerable_icon_ensure_emblem (self);
528 gtk_numerable_icon_constructed (GObject *object)
530 GtkNumerableIcon *self = GTK_NUMERABLE_ICON (object);
532 if (G_OBJECT_CLASS (gtk_numerable_icon_parent_class)->constructed != NULL)
533 G_OBJECT_CLASS (gtk_numerable_icon_parent_class)->constructed (object);
535 gtk_numerable_icon_ensure_emblem (self);
539 gtk_numerable_icon_finalize (GObject *object)
541 GtkNumerableIcon *self = GTK_NUMERABLE_ICON (object);
543 g_free (self->priv->label);
544 g_free (self->priv->rendered_string);
546 gdk_rgba_free (self->priv->background);
547 gdk_rgba_free (self->priv->foreground);
549 pango_font_description_free (self->priv->font);
551 cairo_pattern_destroy (self->priv->background_image);
553 G_OBJECT_CLASS (gtk_numerable_icon_parent_class)->finalize (object);
557 gtk_numerable_icon_dispose (GObject *object)
559 GtkNumerableIcon *self = GTK_NUMERABLE_ICON (object);
561 if (self->priv->style_changed_id != 0)
563 g_signal_handler_disconnect (self->priv->style,
564 self->priv->style_changed_id);
565 self->priv->style_changed_id = 0;
568 g_clear_object (&self->priv->style);
569 g_clear_object (&self->priv->background_icon);
571 G_OBJECT_CLASS (gtk_numerable_icon_parent_class)->dispose (object);
575 gtk_numerable_icon_set_property (GObject *object,
580 GtkNumerableIcon *self = GTK_NUMERABLE_ICON (object);
585 gtk_numerable_icon_set_count (self, g_value_get_int (value));
588 gtk_numerable_icon_set_label (self, g_value_get_string (value));
591 gtk_numerable_icon_set_style_context (self, g_value_get_object (value));
593 case PROP_BACKGROUND_ICON:
594 gtk_numerable_icon_set_background_gicon (self, g_value_get_object (value));
596 case PROP_BACKGROUND_ICON_NAME:
597 gtk_numerable_icon_set_background_icon_name (self, g_value_get_string (value));
600 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
606 gtk_numerable_icon_get_property (GObject *object,
611 GtkNumerableIcon *self = GTK_NUMERABLE_ICON (object);
616 g_value_set_int (value, self->priv->count);
619 g_value_set_string (value, self->priv->label);
622 g_value_set_object (value, self->priv->style);
624 case PROP_BACKGROUND_ICON:
625 if (self->priv->background_icon != NULL)
626 g_value_set_object (value, self->priv->background_icon);
628 case PROP_BACKGROUND_ICON_NAME:
629 g_value_set_string (value, self->priv->background_icon_name);
632 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
638 gtk_numerable_icon_class_init (GtkNumerableIconClass *klass)
640 GObjectClass *oclass = G_OBJECT_CLASS (klass);
642 oclass->get_property = gtk_numerable_icon_get_property;
643 oclass->set_property = gtk_numerable_icon_set_property;
644 oclass->constructed = gtk_numerable_icon_constructed;
645 oclass->dispose = gtk_numerable_icon_dispose;
646 oclass->finalize = gtk_numerable_icon_finalize;
648 g_type_class_add_private (klass, sizeof (GtkNumerableIconPrivate));
650 properties[PROP_COUNT] =
651 g_param_spec_int ("count",
653 P_("The count of the emblem currently displayed"),
655 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
657 properties[PROP_LABEL] =
658 g_param_spec_string ("label",
660 P_("The label to be displayed over the icon"),
662 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
664 properties[PROP_STYLE] =
665 g_param_spec_object ("style-context",
666 P_("Icon's style context"),
667 P_("The style context to theme the icon appearance"),
668 GTK_TYPE_STYLE_CONTEXT,
669 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
671 properties[PROP_BACKGROUND_ICON] =
672 g_param_spec_object ("background-icon",
673 P_("Background icon"),
674 P_("The icon for the number emblem background"),
676 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
678 properties[PROP_BACKGROUND_ICON_NAME] =
679 g_param_spec_string ("background-icon-name",
680 P_("Background icon name"),
681 P_("The icon name for the number emblem background"),
683 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
685 g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
689 gtk_numerable_icon_init (GtkNumerableIcon *self)
694 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
695 GTK_TYPE_NUMERABLE_ICON,
696 GtkNumerableIconPrivate);
698 gdk_rgba_parse (&bg, DEFAULT_BACKGROUND);
699 gdk_rgba_parse (&fg, DEFAULT_FOREGROUND);
701 self->priv->background = gdk_rgba_copy (&bg);
702 self->priv->foreground = gdk_rgba_copy (&fg);
704 self->priv->icon_size = 48;
709 _gtk_numerable_icon_set_background_icon_size (GtkNumerableIcon *self,
712 if (self->priv->background_icon == NULL)
715 if (self->priv->icon_size != icon_size)
717 self->priv->icon_size = icon_size;
718 gtk_numerable_icon_ensure_emblem (self);
723 * gtk_numerable_icon_get_label:
724 * @self: a #GtkNumerableIcon
726 * Returns the currently displayed label of the icon, or %NULL.
728 * Returns: the currently displayed label
733 gtk_numerable_icon_get_label (GtkNumerableIcon *self)
735 g_return_val_if_fail (GTK_IS_NUMERABLE_ICON (self), NULL);
737 return self->priv->label;
741 * gtk_numerable_icon_set_label:
742 * @self: a #GtkNumerableIcon
743 * @label: (allow-none): a short label, or %NULL
745 * Sets the currently displayed value of @self to the string
746 * in @label. Setting an empty label removes the emblem.
748 * Note that this is meant for displaying short labels, such as
749 * roman numbers, or single letters. For roman numbers, consider
750 * using the Unicode characters U+2160 - U+217F. Strings longer
751 * than two characters will likely not be rendered very well.
753 * If this method is called, and a number was already set on the
754 * icon, it will automatically be reset to zero before rendering
755 * the label, i.e. the last method called between
756 * gtk_numerable_icon_set_label() and gtk_numerable_icon_set_count()
757 * has always priority.
762 gtk_numerable_icon_set_label (GtkNumerableIcon *self,
765 g_return_if_fail (GTK_IS_NUMERABLE_ICON (self));
767 if (g_strcmp0 (label, self->priv->label) != 0)
769 gtk_numerable_icon_ensure_and_replace_label (self, 0, label);
770 gtk_numerable_icon_ensure_emblem (self);
772 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LABEL]);
777 * gtk_numerable_icon_get_count:
778 * @self: a #GtkNumerableIcon
780 * Returns the value currently displayed by @self.
782 * Returns: the currently displayed value
787 gtk_numerable_icon_get_count (GtkNumerableIcon *self)
789 g_return_val_if_fail (GTK_IS_NUMERABLE_ICON (self), 0);
791 return self->priv->count;
795 * gtk_numerable_icon_set_count:
796 * @self: a #GtkNumerableIcon
797 * @count: a number between -99 and 99
799 * Sets the currently displayed value of @self to @count.
801 * The numeric value is always clamped to make it two digits, i.e.
802 * between -99 and 99. Setting a count of zero removes the emblem.
803 * If this method is called, and a label was already set on the icon,
804 * it will automatically be reset to %NULL before rendering the number,
805 * i.e. the last method called between gtk_numerable_icon_set_count()
806 * and gtk_numerable_icon_set_label() has always priority.
811 gtk_numerable_icon_set_count (GtkNumerableIcon *self,
814 g_return_if_fail (GTK_IS_NUMERABLE_ICON (self));
816 if (count != self->priv->count)
818 gtk_numerable_icon_ensure_and_replace_label (self, count, NULL);
819 gtk_numerable_icon_ensure_emblem (self);
821 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COUNT]);
826 * gtk_numerable_icon_get_style_context:
827 * @self: a #GtkNumerableIcon
829 * Returns the #GtkStyleContext used by the icon for theming,
830 * or %NULL if there's none.
832 * Returns: (transfer none): a #GtkStyleContext, or %NULL.
833 * This object is internal to GTK+ and should not be unreffed.
834 * Use g_object_ref() if you want to keep it around
839 gtk_numerable_icon_get_style_context (GtkNumerableIcon *self)
841 g_return_val_if_fail (GTK_IS_NUMERABLE_ICON (self), NULL);
843 return self->priv->style;
847 * gtk_numerable_icon_set_style_context:
848 * @self: a #GtkNumerableIcon
849 * @style: a #GtkStyleContext
851 * Updates the icon to fetch theme information from the
852 * given #GtkStyleContext.
857 gtk_numerable_icon_set_style_context (GtkNumerableIcon *self,
858 GtkStyleContext *style)
860 g_return_if_fail (GTK_IS_NUMERABLE_ICON (self));
861 g_return_if_fail (GTK_IS_STYLE_CONTEXT (style));
863 if (style != self->priv->style)
865 if (self->priv->style_changed_id != 0)
866 g_signal_handler_disconnect (self->priv->style,
867 self->priv->style_changed_id);
869 if (self->priv->style != NULL)
870 g_object_unref (self->priv->style);
872 self->priv->style = g_object_ref (style);
874 gtk_numerable_icon_init_style (self);
876 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STYLE]);
881 * gtk_numerable_icon_set_background_gicon:
882 * @self: a #GtkNumerableIcon
883 * @icon: (allow-none): a #GIcon, or %NULL
885 * Updates the icon to use @icon as the base background image.
886 * If @icon is %NULL, @self will go back using style information
887 * or default theming for its background image.
889 * If this method is called and an icon name was already set as
890 * background for the icon, @icon will be used, i.e. the last method
891 * called between gtk_numerable_icon_set_background_gicon() and
892 * gtk_numerable_icon_set_background_icon_name() has always priority.
897 gtk_numerable_icon_set_background_gicon (GtkNumerableIcon *self,
902 g_return_if_fail (GTK_IS_NUMERABLE_ICON (self));
904 if (self->priv->background_icon_name != NULL)
906 g_free (self->priv->background_icon_name);
907 self->priv->background_icon_name = NULL;
910 res = real_set_background_icon (self, icon);
913 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_BACKGROUND_ICON]);
917 * gtk_numerable_icon_get_background_gicon:
918 * @self: a #GtkNumerableIcon
920 * Returns the #GIcon that was set as the base background image, or
921 * %NULL if there's none. The caller of this function does not own
922 * a reference to the returned #GIcon.
924 * Returns: (transfer none): a #GIcon, or %NULL
929 gtk_numerable_icon_get_background_gicon (GtkNumerableIcon *self)
931 GIcon *retval = NULL;
933 g_return_val_if_fail (GTK_IS_NUMERABLE_ICON (self), NULL);
935 /* return the GIcon only if it wasn't created from an icon name */
936 if (self->priv->background_icon_name == NULL)
937 retval = self->priv->background_icon;
943 * gtk_numerable_icon_set_background_icon_name:
944 * @self: a #GtkNumerableIcon
945 * @icon_name: (allow-none): an icon name, or %NULL
947 * Updates the icon to use the icon named @icon_name from the
948 * current icon theme as the base background image. If @icon_name
949 * is %NULL, @self will go back using style information or default
950 * theming for its background image.
952 * If this method is called and a #GIcon was already set as
953 * background for the icon, @icon_name will be used, i.e. the
954 * last method called between gtk_numerable_icon_set_background_icon_name()
955 * and gtk_numerable_icon_set_background_gicon() has always priority.
960 gtk_numerable_icon_set_background_icon_name (GtkNumerableIcon *self,
961 const gchar *icon_name)
966 g_return_if_fail (GTK_IS_NUMERABLE_ICON (self));
968 if (g_strcmp0 (icon_name, self->priv->background_icon_name) != 0)
970 g_free (self->priv->background_icon_name);
971 self->priv->background_icon_name = g_strdup (icon_name);
974 if (icon_name != NULL)
975 icon = g_themed_icon_new_with_default_fallbacks (icon_name);
977 res = real_set_background_icon (self, icon);
980 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_BACKGROUND_ICON_NAME]);
983 g_object_unref (icon);
987 * gtk_numerable_icon_get_background_icon_name:
988 * @self: a #GtkNumerableIcon
990 * Returns the icon name used as the base background image,
991 * or %NULL if there's none.
993 * Returns: an icon name, or %NULL
998 gtk_numerable_icon_get_background_icon_name (GtkNumerableIcon *self)
1000 g_return_val_if_fail (GTK_IS_NUMERABLE_ICON (self), NULL);
1002 return self->priv->background_icon_name;
1006 * gtk_numerable_icon_new:
1007 * @base_icon: a #GIcon to overlay on
1009 * Creates a new unthemed #GtkNumerableIcon.
1011 * Returns: (transfer full): a new #GIcon
1016 gtk_numerable_icon_new (GIcon *base_icon)
1018 g_return_val_if_fail (G_IS_ICON (base_icon), NULL);
1020 return g_object_new (GTK_TYPE_NUMERABLE_ICON,
1026 * gtk_numerable_icon_new_with_style_context:
1027 * @base_icon: a #GIcon to overlay on
1028 * @context: a #GtkStyleContext
1030 * Creates a new #GtkNumerableIcon which will themed according
1031 * to the passed #GtkStyleContext. This is a convenience constructor
1032 * that calls gtk_numerable_icon_set_style_context() internally.
1034 * Returns: (transfer full): a new #GIcon
1039 gtk_numerable_icon_new_with_style_context (GIcon *base_icon,
1040 GtkStyleContext *context)
1042 g_return_val_if_fail (G_IS_ICON (base_icon), NULL);
1044 return g_object_new (GTK_TYPE_NUMERABLE_ICON,
1046 "style-context", context,