1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
/*
* Copyright (C) 2008 Tristan Van Berkom.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Authors:
* Tristan Van Berkom <tvb@gnome.org>
*/
#include "config.h"
#include "glade-cell-renderer-icon.h"
#include "glade-marshallers.h"
static void glade_cell_renderer_icon_get_property (GObject * object,
guint param_id,
GValue * value,
GParamSpec * pspec);
static void glade_cell_renderer_icon_set_property (GObject * object,
guint param_id,
const GValue * value,
GParamSpec * pspec);
static gboolean glade_cell_renderer_icon_activate (GtkCellRenderer * cell,
GdkEvent * event,
GtkWidget * widget,
const gchar * path,
const GdkRectangle *
background_area,
const GdkRectangle *
cell_area,
GtkCellRendererState flags);
struct _GladeCellRendererIconPrivate
{
guint active : 1;
guint activatable : 1;
};
enum
{
ACTIVATE,
LAST_SIGNAL
};
enum
{
PROP_0,
PROP_ACTIVATABLE,
PROP_ACTIVE,
};
static guint icon_cell_signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GladeCellRendererIcon, glade_cell_renderer_icon,
GTK_TYPE_CELL_RENDERER_PIXBUF)
static void glade_cell_renderer_icon_init (GladeCellRendererIcon *cellicon)
{
cellicon->priv =
G_TYPE_INSTANCE_GET_PRIVATE ((cellicon),
GLADE_TYPE_CELL_RENDERER_ICON,
GladeCellRendererIconPrivate);
cellicon->priv->activatable = TRUE;
cellicon->priv->active = FALSE;
g_object_set (G_OBJECT (cellicon), "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE,
NULL);
}
static void
glade_cell_renderer_icon_class_init (GladeCellRendererIconClass * class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
object_class->get_property = glade_cell_renderer_icon_get_property;
object_class->set_property = glade_cell_renderer_icon_set_property;
cell_class->activate = glade_cell_renderer_icon_activate;
g_object_class_install_property (object_class,
PROP_ACTIVE,
g_param_spec_boolean ("active", "Icon state",
"The icon state of the button",
FALSE,
G_PARAM_READABLE |
G_PARAM_WRITABLE));
g_object_class_install_property (object_class,
PROP_ACTIVATABLE,
g_param_spec_boolean ("activatable",
"Activatable",
"The icon button can be activated",
TRUE,
G_PARAM_READABLE |
G_PARAM_WRITABLE));
icon_cell_signals[ACTIVATE] =
g_signal_new ("activate",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (GladeCellRendererIconClass, activate),
NULL, NULL,
glade_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING);
g_type_class_add_private (class, sizeof (GladeCellRendererIconPrivate));
}
static void
glade_cell_renderer_icon_get_property (GObject * object,
guint param_id,
GValue * value, GParamSpec * pspec)
{
GladeCellRendererIcon *cellicon = GLADE_CELL_RENDERER_ICON (object);
switch (param_id)
{
case PROP_ACTIVE:
g_value_set_boolean (value, cellicon->priv->active);
break;
case PROP_ACTIVATABLE:
g_value_set_boolean (value, cellicon->priv->activatable);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
static void
glade_cell_renderer_icon_set_property (GObject * object,
guint param_id,
const GValue * value, GParamSpec * pspec)
{
GladeCellRendererIcon *cellicon = GLADE_CELL_RENDERER_ICON (object);
switch (param_id)
{
case PROP_ACTIVE:
cellicon->priv->active = g_value_get_boolean (value);
break;
case PROP_ACTIVATABLE:
cellicon->priv->activatable = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
}
}
GtkCellRenderer *
glade_cell_renderer_icon_new (void)
{
return g_object_new (GLADE_TYPE_CELL_RENDERER_ICON, NULL);
}
static gint
glade_cell_renderer_icon_activate (GtkCellRenderer * cell,
GdkEvent * event,
GtkWidget * widget,
const gchar * path,
const GdkRectangle * background_area,
const GdkRectangle * cell_area,
GtkCellRendererState flags)
{
GladeCellRendererIcon *cellicon;
cellicon = GLADE_CELL_RENDERER_ICON (cell);
if (cellicon->priv->activatable)
{
g_signal_emit (cell, icon_cell_signals[ACTIVATE], 0, path);
return TRUE;
}
return FALSE;
}
gboolean
glade_cell_renderer_icon_get_active (GladeCellRendererIcon * icon)
{
g_return_val_if_fail (GLADE_IS_CELL_RENDERER_ICON (icon), FALSE);
return icon->priv->active;
}
void
glade_cell_renderer_icon_set_active (GladeCellRendererIcon * icon,
gboolean setting)
{
g_return_if_fail (GLADE_IS_CELL_RENDERER_ICON (icon));
if (icon->priv->active != setting)
{
icon->priv->active = setting ? TRUE : FALSE;
g_object_notify (G_OBJECT (icon), "active");
}
}
gboolean
glade_cell_renderer_icon_get_activatable (GladeCellRendererIcon * icon)
{
g_return_val_if_fail (GLADE_IS_CELL_RENDERER_ICON (icon), FALSE);
return icon->priv->activatable;
}
void
glade_cell_renderer_icon_set_activatable (GladeCellRendererIcon * icon,
gboolean setting)
{
g_return_if_fail (GLADE_IS_CELL_RENDERER_ICON (icon));
if (icon->priv->activatable != setting)
{
icon->priv->activatable = setting ? TRUE : FALSE;
g_object_notify (G_OBJECT (icon), "activatable");
}
}
|