1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
5 * Copyright (C) 2006-2007 Red Hat, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
22 * Author: Matthias Clasen <mclasen@redhat.com>
23 * Clemens N. Buss <cebuzz@gmail.com>
30 #include "gemblemedicon.h"
36 * SECTION:gemblemedicon
37 * @short_description: Icon with emblems
39 * @see_also: #GIcon, #GLoadableIcon, #GThemedIcon, #GEmblem
41 * #GEmblemedIcon is an implementation of #GIcon that supports
42 * adding an emblem to an icon. Adding multiple emblems to an
43 * icon is ensured via g_emblemed_icon_add_emblem().
45 * Note that #GEmblemedIcon allows no control over the position
46 * of the emblems. See also #GEmblem for more information.
49 static void g_emblemed_icon_icon_iface_init (GIconIface *iface);
53 GObject parent_instance;
59 struct _GEmblemedIconClass
61 GObjectClass parent_class;
64 G_DEFINE_TYPE_WITH_CODE (GEmblemedIcon, g_emblemed_icon, G_TYPE_OBJECT,
65 G_IMPLEMENT_INTERFACE (G_TYPE_ICON,
66 g_emblemed_icon_icon_iface_init))
70 g_emblemed_icon_finalize (GObject *object)
72 GEmblemedIcon *emblemed;
74 emblemed = G_EMBLEMED_ICON (object);
76 g_object_unref (emblemed->icon);
77 g_list_foreach (emblemed->emblems, (GFunc) g_object_unref, NULL);
79 (*G_OBJECT_CLASS (g_emblemed_icon_parent_class)->finalize) (object);
83 g_emblemed_icon_class_init (GEmblemedIconClass *klass)
85 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
86 gobject_class->finalize = g_emblemed_icon_finalize;
90 g_emblemed_icon_init (GEmblemedIcon *emblemed)
95 * g_emblemed_icon_new:
99 * Creates a new emblemed icon for @icon with the emblem @emblem.
101 * Returns: a new #GIcon
106 g_emblemed_icon_new (GIcon *icon,
109 GEmblemedIcon *emblemed;
111 g_return_val_if_fail (G_IS_ICON (icon), NULL);
112 g_return_val_if_fail (!G_IS_EMBLEM (icon), NULL);
113 g_return_val_if_fail (G_IS_EMBLEM (emblem), NULL);
115 emblemed = G_EMBLEMED_ICON (g_object_new (G_TYPE_EMBLEMED_ICON, NULL));
116 emblemed->icon = g_object_ref (icon);
118 g_emblemed_icon_add_emblem (emblemed, emblem);
120 return G_ICON (emblemed);
125 * g_emblemed_icon_get_icon:
126 * @emblemed: a #GEmblemedIcon
128 * Gets the main icon for @emblemed.
130 * Returns: a #GIcon that is owned by @emblemed
135 g_emblemed_icon_get_icon (GEmblemedIcon *emblemed)
137 g_return_val_if_fail (G_IS_EMBLEMED_ICON (emblemed), NULL);
139 return emblemed->icon;
143 * g_emblemed_icon_get_emblems:
144 * @emblemed: a #GEmblemedIcon
146 * Gets the list of emblems for the @icon.
148 * Returns: a #GList of #GEmblem <!-- -->s that is owned by @emblemed
154 g_emblemed_icon_get_emblems (GEmblemedIcon *emblemed)
156 g_return_val_if_fail (G_IS_EMBLEMED_ICON (emblemed), NULL);
158 return emblemed->emblems;
163 * g_emblemed_icon_add_emblem:
164 * @emblemed: a #GEmblemedIcon
165 * @emblem: a #GEmblem
167 * Adds @emblem to the #GList of #GEmblem <!-- -->s.
169 * Returns: a #GList of #GEmblem <!-- -->s that is owned by @emblemed
174 g_emblemed_icon_add_emblem (GEmblemedIcon *emblemed,
177 g_return_if_fail (G_IS_EMBLEMED_ICON (emblemed));
178 g_return_if_fail (G_IS_EMBLEM (emblem));
180 g_object_ref (emblem);
181 emblemed->emblems = g_list_append (emblemed->emblems, emblem);
185 g_emblemed_icon_hash (GIcon *icon)
187 GEmblemedIcon *emblemed = G_EMBLEMED_ICON (icon);
189 guint hash = g_icon_hash (emblemed->icon);
191 for (list = emblemed->emblems; list != NULL; list = list->next)
192 hash ^= g_icon_hash (G_ICON (list->data));
198 g_emblem_comp (GEmblem *a,
201 guint hash_a = g_icon_hash (G_ICON (a));
202 guint hash_b = g_icon_hash (G_ICON (b));
214 g_emblemed_icon_equal (GIcon *icon1,
217 GEmblemedIcon *emblemed1 = G_EMBLEMED_ICON (icon1);
218 GEmblemedIcon *emblemed2 = G_EMBLEMED_ICON (icon2);
219 GList *list1, *list2;
221 if (!g_icon_equal (emblemed1->icon, emblemed2->icon))
224 list1 = emblemed1->emblems;
225 list2 = emblemed2->emblems;
227 list1 = g_list_sort (list1, (GCompareFunc) g_emblem_comp);
228 list2 = g_list_sort (list2, (GCompareFunc) g_emblem_comp);
230 while (list1 && list2)
232 if (!g_icon_equal (G_ICON (list1->data), G_ICON (list2->data)))
239 return list1 == NULL && list2 == NULL;
243 g_emblemed_icon_icon_iface_init (GIconIface *iface)
245 iface->hash = g_emblemed_icon_hash;
246 iface->equal = g_emblemed_icon_equal;
249 #define __G_EMBLEMED_ICON_C__
250 #include "gioaliasdef.c"