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 "gtkwindow.h"
51 #include <pango/pango.h>
54 struct _GtkNumerableIconPrivate {
60 GIcon *background_icon;
61 gchar *background_icon_name;
66 PangoFontDescription *font;
67 cairo_pattern_t *background_image;
70 GtkStyleContext *style;
71 gulong style_changed_id;
73 gchar *rendered_string;
81 PROP_BACKGROUND_ICON_NAME,
85 #define DEFAULT_SURFACE_SIZE 256
86 #define DEFAULT_BORDER_SIZE DEFAULT_SURFACE_SIZE * 0.06
87 #define DEFAULT_RADIUS DEFAULT_SURFACE_SIZE / 2
89 #define DEFAULT_BACKGROUND "#000000"
90 #define DEFAULT_FOREGROUND "#ffffff"
92 static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
94 G_DEFINE_TYPE (GtkNumerableIcon, gtk_numerable_icon, G_TYPE_EMBLEMED_ICON);
97 get_surface_size (cairo_surface_t *surface)
99 return MAX (cairo_image_surface_get_width (surface), cairo_image_surface_get_height (surface));
103 get_border_size (GtkNumerableIcon *self)
105 return self->priv->border_size;
108 static cairo_surface_t *
109 draw_default_surface (GtkNumerableIcon *self)
111 cairo_surface_t *surface;
114 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
115 DEFAULT_SURFACE_SIZE, DEFAULT_SURFACE_SIZE);
117 cr = cairo_create (surface);
119 cairo_arc (cr, DEFAULT_SURFACE_SIZE / 2., DEFAULT_SURFACE_SIZE / 2.,
120 DEFAULT_RADIUS, 0., 2 * G_PI);
122 gdk_cairo_set_source_rgba (cr, self->priv->background);
125 cairo_arc (cr, DEFAULT_SURFACE_SIZE / 2., DEFAULT_SURFACE_SIZE / 2.,
126 DEFAULT_RADIUS - DEFAULT_BORDER_SIZE, 0., 2 * G_PI);
127 gdk_cairo_set_source_rgba (cr, self->priv->foreground);
130 cairo_arc (cr, DEFAULT_SURFACE_SIZE / 2., DEFAULT_SURFACE_SIZE / 2.,
131 DEFAULT_RADIUS - 2 * DEFAULT_BORDER_SIZE, 0., 2 * G_PI);
132 gdk_cairo_set_source_rgba (cr, self->priv->background);
140 static cairo_surface_t *
141 draw_from_gradient (cairo_pattern_t *pattern)
143 cairo_surface_t *surface;
144 cairo_matrix_t matrix;
147 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
148 DEFAULT_SURFACE_SIZE, DEFAULT_SURFACE_SIZE);
150 cr = cairo_create (surface);
152 /* scale the gradient points to the user space coordinates */
153 cairo_matrix_init_scale (&matrix,
154 1. / (double) DEFAULT_SURFACE_SIZE,
155 1. / (double) DEFAULT_SURFACE_SIZE);
156 cairo_pattern_set_matrix (pattern, &matrix);
158 cairo_arc (cr, DEFAULT_SURFACE_SIZE / 2., DEFAULT_SURFACE_SIZE / 2.,
159 DEFAULT_RADIUS, 0., 2 * G_PI);
161 cairo_set_source (cr, pattern);
169 /* copy the surface */
170 static cairo_surface_t *
171 draw_from_image (cairo_surface_t *image)
173 cairo_surface_t *surface;
176 surface = cairo_surface_create_similar (image, CAIRO_CONTENT_COLOR_ALPHA,
177 cairo_image_surface_get_width (image),
178 cairo_image_surface_get_height (image));
179 cr = cairo_create (surface);
181 cairo_set_source_surface (cr, image, 0, 0);
189 static cairo_surface_t *
190 draw_from_gicon (GtkNumerableIcon *self)
196 cairo_surface_t *surface;
199 if (self->priv->style != NULL)
201 screen = gtk_style_context_get_screen (self->priv->style);
202 theme = gtk_icon_theme_get_for_screen (screen);
206 theme = gtk_icon_theme_get_default ();
209 info = gtk_icon_theme_lookup_by_gicon (theme, self->priv->background_icon,
210 self->priv->icon_size,
211 GTK_ICON_LOOKUP_GENERIC_FALLBACK);
215 pixbuf = gtk_icon_info_load_icon (info, NULL);
216 gtk_icon_info_free (info);
221 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
222 gdk_pixbuf_get_width (pixbuf),
223 gdk_pixbuf_get_height (pixbuf));
225 cr = cairo_create (surface);
227 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
231 g_object_unref (pixbuf);
236 static cairo_surface_t *
237 get_image_surface (GtkNumerableIcon *self)
239 cairo_surface_t *retval = NULL, *image;
241 if (self->priv->background_icon != NULL)
243 retval = draw_from_gicon (self);
244 self->priv->border_size = 0;
246 else if (self->priv->background_image != NULL)
248 if (cairo_pattern_get_surface (self->priv->background_image, &image) == CAIRO_STATUS_SUCCESS)
249 retval = draw_from_image (image);
251 retval = draw_from_gradient (self->priv->background_image);
253 self->priv->border_size = 0;
258 retval = draw_default_surface (self);
259 self->priv->border_size = DEFAULT_BORDER_SIZE;
266 get_pango_layout (GtkNumerableIcon *self)
268 PangoContext *context;
272 if (self->priv->style != NULL)
274 screen = gtk_style_context_get_screen (self->priv->style);
275 context = gdk_pango_context_get_for_screen (screen);
276 layout = pango_layout_new (context);
278 if (self->priv->font != NULL)
279 pango_layout_set_font_description (layout, self->priv->font);
281 pango_layout_set_text (layout, self->priv->rendered_string, -1);
283 g_object_unref (context);
289 /* steal gtk text settings from the window */
290 fake = gtk_window_new (GTK_WINDOW_TOPLEVEL);
291 layout = gtk_widget_create_pango_layout (fake, self->priv->rendered_string);
292 gtk_widget_destroy (fake);
299 gtk_numerable_icon_ensure_emblem (GtkNumerableIcon *self)
302 cairo_surface_t *surface;
307 PangoAttrList *attr_list;
308 PangoAttribute *attr;
311 /* don't draw anything if the count is zero */
312 if (self->priv->rendered_string == NULL)
314 g_emblemed_icon_clear_emblems (G_EMBLEMED_ICON (self));
318 surface = get_image_surface (self);
319 cr = cairo_create (surface);
321 layout = get_pango_layout (self);
322 pango_layout_get_pixel_size (layout, &width, &height);
324 /* scale the layout to be 0.75 of the size still available for drawing */
325 scale = ((get_surface_size (surface) - 2 * get_border_size (self)) * 0.75) / (MAX (height, width));
326 attr_list = pango_attr_list_new ();
328 attr = pango_attr_scale_new (scale);
329 pango_attr_list_insert (attr_list, attr);
331 attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
332 pango_attr_list_insert (attr_list, attr);
334 pango_layout_set_attributes (layout, attr_list);
336 /* update these values */
337 pango_layout_get_pixel_size (layout, &width, &height);
339 /* move to the center */
341 get_surface_size (surface) / 2. - (gdouble) width / 2.,
342 get_surface_size (surface) / 2. - (gdouble) height / 2.);
344 gdk_cairo_set_source_rgba (cr, self->priv->foreground);
345 pango_cairo_show_layout (cr, layout);
350 gdk_pixbuf_get_from_surface (surface, 0, 0,
351 get_surface_size (surface), get_surface_size (surface));
353 emblem = g_emblem_new (G_ICON (pixbuf));
354 g_emblemed_icon_clear_emblems (G_EMBLEMED_ICON (self));
355 g_emblemed_icon_add_emblem (G_EMBLEMED_ICON (self), emblem);
357 g_object_unref (layout);
358 g_object_unref (emblem);
359 g_object_unref (pixbuf);
361 cairo_surface_destroy (surface);
362 pango_attr_list_unref (attr_list);
366 gtk_numerable_icon_update_properties_from_style (GtkNumerableIcon *self)
368 GtkStyleContext *style = self->priv->style;
369 GtkWidgetPath *path, *saved;
370 cairo_pattern_t *pattern = NULL;
371 GdkRGBA background, foreground;
372 PangoFontDescription *font = NULL;
374 /* save an unmodified copy of the original widget path, in order
375 * to restore it later */
376 path = gtk_widget_path_copy (gtk_style_context_get_path (style));
377 saved = gtk_widget_path_copy (path);
379 if (!gtk_widget_path_is_type (path, GTK_TYPE_NUMERABLE_ICON))
381 /* append our GType to the style context to fetch appropriate colors */
382 gtk_widget_path_append_type (path, GTK_TYPE_NUMERABLE_ICON);
383 gtk_style_context_set_path (style, path);
386 gtk_style_context_get_background_color (style, gtk_style_context_get_state (style),
388 gtk_style_context_get_color (style, gtk_style_context_get_state (style),
391 if (self->priv->background != NULL)
392 gdk_rgba_free (self->priv->background);
394 self->priv->background = gdk_rgba_copy (&background);
396 if (self->priv->foreground != NULL)
397 gdk_rgba_free (self->priv->foreground);
399 self->priv->foreground = gdk_rgba_copy (&foreground);
401 gtk_style_context_get (style, gtk_style_context_get_state (style),
402 GTK_STYLE_PROPERTY_BACKGROUND_IMAGE, &pattern,
407 if (self->priv->background_image != NULL)
408 cairo_pattern_destroy (self->priv->background_image);
410 self->priv->background_image = pattern;
413 gtk_style_context_get (style, gtk_style_context_get_state (style),
414 GTK_STYLE_PROPERTY_FONT, &font,
419 if (self->priv->font != NULL)
420 pango_font_description_free (self->priv->font);
422 self->priv->font = font;
425 gtk_numerable_icon_ensure_emblem (self);
427 /* restore original widget path */
428 gtk_style_context_set_path (style, saved);
430 gtk_widget_path_free (path);
431 gtk_widget_path_free (saved);
435 gtk_numerable_icon_init_style (GtkNumerableIcon *self)
437 GtkStyleContext *style = self->priv->style;
442 gtk_numerable_icon_update_properties_from_style (self);
444 self->priv->style_changed_id =
445 g_signal_connect_swapped (style, "changed",
446 G_CALLBACK (gtk_numerable_icon_update_properties_from_style), self);
450 gtk_numerable_icon_ensure_and_replace_label (GtkNumerableIcon *self,
454 g_assert (!(label != NULL && count != 0));
456 g_free (self->priv->rendered_string);
457 self->priv->rendered_string = NULL;
461 if (self->priv->label != NULL)
463 g_free (self->priv->label);
464 self->priv->label = NULL;
466 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LABEL]);
475 self->priv->count = count;
477 /* Translators: the format here is used to build the string that will be rendered
478 * in the number emblem.
480 self->priv->rendered_string = g_strdup_printf (C_("Number format", "%d"), count);
487 if (self->priv->count != 0)
489 self->priv->count = 0;
491 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COUNT]);
494 g_free (self->priv->label);
496 if (g_strcmp0 (label, "") == 0)
498 self->priv->label = NULL;
502 self->priv->label = g_strdup (label);
503 self->priv->rendered_string = g_strdup (label);
508 real_set_background_icon (GtkNumerableIcon *self,
511 if (!g_icon_equal (self->priv->background_icon, icon))
513 g_clear_object (&self->priv->background_icon);
516 self->priv->background_icon = g_object_ref (icon);
518 gtk_numerable_icon_ensure_emblem (self);
527 gtk_numerable_icon_constructed (GObject *object)
529 GtkNumerableIcon *self = GTK_NUMERABLE_ICON (object);
531 if (G_OBJECT_CLASS (gtk_numerable_icon_parent_class)->constructed != NULL)
532 G_OBJECT_CLASS (gtk_numerable_icon_parent_class)->constructed (object);
534 gtk_numerable_icon_ensure_emblem (self);
538 gtk_numerable_icon_finalize (GObject *object)
540 GtkNumerableIcon *self = GTK_NUMERABLE_ICON (object);
542 g_free (self->priv->label);
543 g_free (self->priv->rendered_string);
545 gdk_rgba_free (self->priv->background);
546 gdk_rgba_free (self->priv->foreground);
548 pango_font_description_free (self->priv->font);
550 cairo_pattern_destroy (self->priv->background_image);
552 G_OBJECT_CLASS (gtk_numerable_icon_parent_class)->finalize (object);
556 gtk_numerable_icon_dispose (GObject *object)
558 GtkNumerableIcon *self = GTK_NUMERABLE_ICON (object);
560 if (self->priv->style_changed_id != 0)
562 g_signal_handler_disconnect (self->priv->style,
563 self->priv->style_changed_id);
564 self->priv->style_changed_id = 0;
567 g_clear_object (&self->priv->style);
568 g_clear_object (&self->priv->background_icon);
570 G_OBJECT_CLASS (gtk_numerable_icon_parent_class)->dispose (object);
574 gtk_numerable_icon_set_property (GObject *object,
579 GtkNumerableIcon *self = GTK_NUMERABLE_ICON (object);
584 gtk_numerable_icon_set_count (self, g_value_get_int (value));
587 gtk_numerable_icon_set_label (self, g_value_get_string (value));
590 gtk_numerable_icon_set_style_context (self, g_value_get_object (value));
592 case PROP_BACKGROUND_ICON:
593 gtk_numerable_icon_set_background_gicon (self, g_value_get_object (value));
595 case PROP_BACKGROUND_ICON_NAME:
596 gtk_numerable_icon_set_background_icon_name (self, g_value_get_string (value));
599 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
605 gtk_numerable_icon_get_property (GObject *object,
610 GtkNumerableIcon *self = GTK_NUMERABLE_ICON (object);
615 g_value_set_int (value, self->priv->count);
618 g_value_set_string (value, self->priv->label);
621 g_value_set_object (value, self->priv->style);
623 case PROP_BACKGROUND_ICON:
624 if (self->priv->background_icon != NULL)
625 g_value_set_object (value, self->priv->background_icon);
627 case PROP_BACKGROUND_ICON_NAME:
628 g_value_set_string (value, self->priv->background_icon_name);
631 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
637 gtk_numerable_icon_class_init (GtkNumerableIconClass *klass)
639 GObjectClass *oclass = G_OBJECT_CLASS (klass);
641 oclass->get_property = gtk_numerable_icon_get_property;
642 oclass->set_property = gtk_numerable_icon_set_property;
643 oclass->constructed = gtk_numerable_icon_constructed;
644 oclass->dispose = gtk_numerable_icon_dispose;
645 oclass->finalize = gtk_numerable_icon_finalize;
647 g_type_class_add_private (klass, sizeof (GtkNumerableIconPrivate));
649 properties[PROP_COUNT] =
650 g_param_spec_int ("count",
652 P_("The count of the emblem currently displayed"),
654 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
656 properties[PROP_LABEL] =
657 g_param_spec_string ("label",
659 P_("The label to be displayed over the icon"),
661 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
663 properties[PROP_STYLE] =
664 g_param_spec_object ("style-context",
665 P_("Icon's style context"),
666 P_("The style context to theme the icon appearance"),
667 GTK_TYPE_STYLE_CONTEXT,
668 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
670 properties[PROP_BACKGROUND_ICON] =
671 g_param_spec_object ("background-icon",
672 P_("Background icon"),
673 P_("The icon for the number emblem background"),
675 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
677 properties[PROP_BACKGROUND_ICON_NAME] =
678 g_param_spec_string ("background-icon-name",
679 P_("Background icon name"),
680 P_("The icon name for the number emblem background"),
682 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
684 g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
688 gtk_numerable_icon_init (GtkNumerableIcon *self)
693 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
694 GTK_TYPE_NUMERABLE_ICON,
695 GtkNumerableIconPrivate);
697 gdk_rgba_parse (&bg, DEFAULT_BACKGROUND);
698 gdk_rgba_parse (&fg, DEFAULT_FOREGROUND);
700 self->priv->background = gdk_rgba_copy (&bg);
701 self->priv->foreground = gdk_rgba_copy (&fg);
703 self->priv->icon_size = 48;
708 _gtk_numerable_icon_set_background_icon_size (GtkNumerableIcon *self,
711 if (self->priv->background_icon == NULL)
714 if (self->priv->icon_size != icon_size)
716 self->priv->icon_size = icon_size;
717 gtk_numerable_icon_ensure_emblem (self);
722 * gtk_numerable_icon_get_label:
723 * @self: a #GtkNumerableIcon
725 * Returns the currently displayed label of the icon, or %NULL.
727 * Returns: the currently displayed label
732 gtk_numerable_icon_get_label (GtkNumerableIcon *self)
734 g_return_val_if_fail (GTK_IS_NUMERABLE_ICON (self), NULL);
736 return self->priv->label;
740 * gtk_numerable_icon_set_label:
741 * @self: a #GtkNumerableIcon
742 * @label: (allow-none): a short label, or %NULL
744 * Sets the currently displayed value of @self to the string
745 * in @label. Setting an empty label removes the emblem.
747 * Note that this is meant for displaying short labels, such as
748 * roman numbers, or single letters. For roman numbers, consider
749 * using the Unicode characters U+2160 - U+217F. Strings longer
750 * than two characters will likely not be rendered very well.
752 * If this method is called, and a number was already set on the
753 * icon, it will automatically be reset to zero before rendering
754 * the label, i.e. the last method called between
755 * gtk_numerable_icon_set_label() and gtk_numerable_icon_set_count()
756 * has always priority.
761 gtk_numerable_icon_set_label (GtkNumerableIcon *self,
764 g_return_if_fail (GTK_IS_NUMERABLE_ICON (self));
766 if (g_strcmp0 (label, self->priv->label) != 0)
768 gtk_numerable_icon_ensure_and_replace_label (self, 0, label);
769 gtk_numerable_icon_ensure_emblem (self);
771 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LABEL]);
776 * gtk_numerable_icon_get_count:
777 * @self: a #GtkNumerableIcon
779 * Returns the value currently displayed by @self.
781 * Returns: the currently displayed value
786 gtk_numerable_icon_get_count (GtkNumerableIcon *self)
788 g_return_val_if_fail (GTK_IS_NUMERABLE_ICON (self), 0);
790 return self->priv->count;
794 * gtk_numerable_icon_set_count:
795 * @self: a #GtkNumerableIcon
796 * @count: a number between -99 and 99
798 * Sets the currently displayed value of @self to @count.
800 * The numeric value is always clamped to make it two digits, i.e.
801 * between -99 and 99. Setting a count of zero removes the emblem.
802 * If this method is called, and a label was already set on the icon,
803 * it will automatically be reset to %NULL before rendering the number,
804 * i.e. the last method called between gtk_numerable_icon_set_count()
805 * and gtk_numerable_icon_set_label() has always priority.
810 gtk_numerable_icon_set_count (GtkNumerableIcon *self,
813 g_return_if_fail (GTK_IS_NUMERABLE_ICON (self));
815 if (count != self->priv->count)
817 gtk_numerable_icon_ensure_and_replace_label (self, count, NULL);
818 gtk_numerable_icon_ensure_emblem (self);
820 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COUNT]);
825 * gtk_numerable_icon_get_style_context:
826 * @self: a #GtkNumerableIcon
828 * Returns the #GtkStyleContext used by the icon for theming,
829 * or %NULL if there's none.
831 * Returns: (transfer none): a #GtkStyleContext, or %NULL.
832 * This object is internal to GTK+ and should not be unreffed.
833 * Use g_object_ref() if you want to keep it around
838 gtk_numerable_icon_get_style_context (GtkNumerableIcon *self)
840 g_return_val_if_fail (GTK_IS_NUMERABLE_ICON (self), NULL);
842 return self->priv->style;
846 * gtk_numerable_icon_set_style_context:
847 * @self: a #GtkNumerableIcon
848 * @style: a #GtkStyleContext
850 * Updates the icon to fetch theme information from the
851 * given #GtkStyleContext.
856 gtk_numerable_icon_set_style_context (GtkNumerableIcon *self,
857 GtkStyleContext *style)
859 g_return_if_fail (GTK_IS_NUMERABLE_ICON (self));
860 g_return_if_fail (GTK_IS_STYLE_CONTEXT (style));
862 if (style != self->priv->style)
864 if (self->priv->style_changed_id != 0)
865 g_signal_handler_disconnect (self->priv->style,
866 self->priv->style_changed_id);
868 if (self->priv->style != NULL)
869 g_object_unref (self->priv->style);
871 self->priv->style = g_object_ref (style);
873 gtk_numerable_icon_init_style (self);
875 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_STYLE]);
880 * gtk_numerable_icon_set_background_gicon:
881 * @self: a #GtkNumerableIcon
882 * @icon: (allow-none): a #GIcon, or %NULL
884 * Updates the icon to use @icon as the base background image.
885 * If @icon is %NULL, @self will go back using style information
886 * or default theming for its background image.
888 * If this method is called and an icon name was already set as
889 * background for the icon, @icon will be used, i.e. the last method
890 * called between gtk_numerable_icon_set_background_gicon() and
891 * gtk_numerable_icon_set_background_icon_name() has always priority.
896 gtk_numerable_icon_set_background_gicon (GtkNumerableIcon *self,
901 g_return_if_fail (GTK_IS_NUMERABLE_ICON (self));
903 if (self->priv->background_icon_name != NULL)
905 g_free (self->priv->background_icon_name);
906 self->priv->background_icon_name = NULL;
909 res = real_set_background_icon (self, icon);
912 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_BACKGROUND_ICON]);
916 * gtk_numerable_icon_get_background_gicon:
917 * @self: a #GtkNumerableIcon
919 * Returns the #GIcon that was set as the base background image, or
920 * %NULL if there's none. The caller of this function does not own
921 * a reference to the returned #GIcon.
923 * Returns: (transfer none): a #GIcon, or %NULL
928 gtk_numerable_icon_get_background_gicon (GtkNumerableIcon *self)
930 GIcon *retval = NULL;
932 g_return_val_if_fail (GTK_IS_NUMERABLE_ICON (self), NULL);
934 /* return the GIcon only if it wasn't created from an icon name */
935 if (self->priv->background_icon_name == NULL)
936 retval = self->priv->background_icon;
942 * gtk_numerable_icon_set_background_icon_name:
943 * @self: a #GtkNumerableIcon
944 * @icon_name: (allow-none): an icon name, or %NULL
946 * Updates the icon to use the icon named @icon_name from the
947 * current icon theme as the base background image. If @icon_name
948 * is %NULL, @self will go back using style information or default
949 * theming for its background image.
951 * If this method is called and a #GIcon was already set as
952 * background for the icon, @icon_name will be used, i.e. the
953 * last method called between gtk_numerable_icon_set_background_icon_name()
954 * and gtk_numerable_icon_set_background_gicon() has always priority.
959 gtk_numerable_icon_set_background_icon_name (GtkNumerableIcon *self,
960 const gchar *icon_name)
965 g_return_if_fail (GTK_IS_NUMERABLE_ICON (self));
967 if (g_strcmp0 (icon_name, self->priv->background_icon_name) != 0)
969 g_free (self->priv->background_icon_name);
970 self->priv->background_icon_name = g_strdup (icon_name);
973 if (icon_name != NULL)
974 icon = g_themed_icon_new_with_default_fallbacks (icon_name);
976 res = real_set_background_icon (self, icon);
979 g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_BACKGROUND_ICON_NAME]);
982 g_object_unref (icon);
986 * gtk_numerable_icon_get_background_icon_name:
987 * @self: a #GtkNumerableIcon
989 * Returns the icon name used as the base background image,
990 * or %NULL if there's none.
992 * Returns: an icon name, or %NULL
997 gtk_numerable_icon_get_background_icon_name (GtkNumerableIcon *self)
999 g_return_val_if_fail (GTK_IS_NUMERABLE_ICON (self), NULL);
1001 return self->priv->background_icon_name;
1005 * gtk_numerable_icon_new:
1006 * @base_icon: a #GIcon to overlay on
1008 * Creates a new unthemed #GtkNumerableIcon.
1010 * Returns: (transfer full): a new #GIcon
1015 gtk_numerable_icon_new (GIcon *base_icon)
1017 g_return_val_if_fail (G_IS_ICON (base_icon), NULL);
1019 return g_object_new (GTK_TYPE_NUMERABLE_ICON,
1025 * gtk_numerable_icon_new_with_style_context:
1026 * @base_icon: a #GIcon to overlay on
1027 * @context: a #GtkStyleContext
1029 * Creates a new #GtkNumerableIcon which will themed according
1030 * to the passed #GtkStyleContext. This is a convenience constructor
1031 * that calls gtk_numerable_icon_set_style_context() internally.
1033 * Returns: (transfer full): a new #GIcon
1038 gtk_numerable_icon_new_with_style_context (GIcon *base_icon,
1039 GtkStyleContext *context)
1041 g_return_val_if_fail (G_IS_ICON (base_icon), NULL);
1043 return g_object_new (GTK_TYPE_NUMERABLE_ICON,
1045 "style-context", context,