2
* This file is part of libslab.
4
* Copyright (c) 2006 Novell, Inc.
6
* Libslab is free software; you can redistribute it and/or modify it under the
7
* terms of the GNU Lesser General Public License as published by the Free
8
* Software Foundation; either version 2 of the License, or (at your option)
11
* Libslab is distributed in the hope that it will be useful, but WITHOUT ANY
12
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with libslab; if not, write to the Free Software Foundation, Inc., 51
18
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "themed-icon.h"
23
#include "gnome-utils.h"
25
static void themed_icon_class_init (ThemedIconClass *);
26
static void themed_icon_init (ThemedIcon *);
27
static void themed_icon_finalize (GObject *);
28
static void themed_icon_get_property (GObject *, guint, GValue *, GParamSpec *);
29
static void themed_icon_set_property (GObject *, guint, const GValue *, GParamSpec *);
31
static void themed_icon_show (GtkWidget *);
32
static void themed_icon_style_set (GtkWidget *, GtkStyle *);
46
#define THEMED_ICON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), THEMED_ICON_TYPE, ThemedIconPrivate))
48
G_DEFINE_TYPE (ThemedIcon, themed_icon, GTK_TYPE_IMAGE)
50
static void themed_icon_class_init (ThemedIconClass * themed_icon_class)
52
GObjectClass *g_obj_class = G_OBJECT_CLASS (themed_icon_class);
53
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (themed_icon_class);
55
g_obj_class->get_property = themed_icon_get_property;
56
g_obj_class->set_property = themed_icon_set_property;
57
g_obj_class->finalize = themed_icon_finalize;
59
widget_class->show = themed_icon_show;
60
widget_class->style_set = themed_icon_style_set;
62
g_type_class_add_private (themed_icon_class, sizeof (ThemedIconPrivate));
64
g_object_class_install_property (g_obj_class, PROP_ICON_ID, g_param_spec_string ("icon-id",
65
"icon-id", "the identifier of the icon", NULL,
66
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
68
g_object_class_install_property (g_obj_class, PROP_ICON_SIZE,
69
g_param_spec_enum ("icon-size", "icon-size", "the size of the icon",
70
GTK_TYPE_ICON_SIZE, GTK_ICON_SIZE_BUTTON,
71
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
75
themed_icon_init (ThemedIcon * icon)
77
ThemedIconPrivate *priv = THEMED_ICON_GET_PRIVATE (icon);
79
priv->icon_loaded = FALSE;
83
themed_icon_new (const gchar * id, GtkIconSize size)
85
GtkWidget *icon = GTK_WIDGET (g_object_new (
86
THEMED_ICON_TYPE, "icon-id", id, "icon-size", size, NULL));
92
themed_icon_finalize (GObject * object)
94
ThemedIcon *icon = THEMED_ICON (object);
97
(*G_OBJECT_CLASS (themed_icon_parent_class)->finalize) (object);
101
themed_icon_get_property (GObject * g_obj, guint prop_id, GValue * value, GParamSpec * param_spec)
103
ThemedIcon *icon = THEMED_ICON (g_obj);
108
g_value_set_string (value, icon->id);
112
g_value_set_enum (value, icon->size);
121
themed_icon_set_property (GObject * g_obj, guint prop_id, const GValue * value,
122
GParamSpec * param_spec)
124
ThemedIcon *icon = THEMED_ICON (g_obj);
129
icon->id = g_strdup (g_value_get_string (value));
131
/* gtk_image_load_by_id (GTK_IMAGE (icon), icon->size, icon->id); */
136
icon->size = g_value_get_enum (value);
138
/* gtk_image_load_by_id (GTK_IMAGE (icon), icon->size, icon->id); */
148
themed_icon_show (GtkWidget * widget)
150
ThemedIcon *icon = THEMED_ICON (widget);
151
ThemedIconPrivate *priv = THEMED_ICON_GET_PRIVATE (icon);
153
if (!priv->icon_loaded)
154
priv->icon_loaded = load_image_by_id (GTK_IMAGE (icon), icon->size, icon->id);
156
(*GTK_WIDGET_CLASS (themed_icon_parent_class)->show) (widget);
160
themed_icon_style_set (GtkWidget * widget, GtkStyle * prev_style)
162
ThemedIcon *icon = THEMED_ICON (widget);
164
load_image_by_id (GTK_IMAGE (icon), icon->size, icon->id);