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
233
234
235
236
237
|
/*
* render_button.c
* Copyright (C) John Stebbins 2008-2018 <stebbins@stebbins>
*
* render_button.c is free software.
*
* You may redistribute it and/or modify it under the terms of the
* GNU General Public License, as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* render_button.c 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with main.c. If not, write to:
* The Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301, USA.
*/
#include "marshalers.h"
#include "renderer_button.h"
#define MyGdkRectangle const GdkRectangle
/* Some boring function declarations: GObject type system stuff */
static void custom_cell_renderer_button_init (CustomCellRendererButton *cellprogress);
static void custom_cell_renderer_button_class_init (CustomCellRendererButtonClass *klass);
static void custom_cell_renderer_button_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec);
static void custom_cell_renderer_button_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
static void custom_cell_renderer_button_finalize (GObject *gobject);
// My customized part that adds "clicked" signal
static gboolean
custom_cell_renderer_button_activate (
GtkCellRenderer *cell,
GdkEvent *event,
GtkWidget *widget,
const gchar *path,
MyGdkRectangle *background_area,
MyGdkRectangle *cell_area,
GtkCellRendererState flags);
enum {
CLICKED,
LAST_SIGNAL
};
static guint button_cell_signals[LAST_SIGNAL] = { 0 };
static gpointer parent_class;
/***************************************************************************
*
* custom_cell_renderer_button_get_type: here we register our type with
* the GObject type system if we
* haven't done so yet. Everything
* else is done in the callbacks.
*
***************************************************************************/
GType
custom_cell_renderer_button_get_type (void)
{
static GType cell_button_type = 0;
if (cell_button_type == 0)
{
static const GTypeInfo cell_button_info =
{
sizeof (CustomCellRendererButtonClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) custom_cell_renderer_button_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (CustomCellRendererButton),
0, /* n_preallocs */
(GInstanceInitFunc) custom_cell_renderer_button_init,
};
/* Derive from GtkCellRendererPixbuf */
cell_button_type = g_type_register_static (GTK_TYPE_CELL_RENDERER_PIXBUF,
"CustomCellRendererButton",
&cell_button_info,
0);
}
return cell_button_type;
}
/***************************************************************************
*
* custom_cell_renderer_button_init: set some default properties of the
* parent (GtkCellRendererPixbuf).
*
***************************************************************************/
static void
custom_cell_renderer_button_init (CustomCellRendererButton *cellbutton)
{
g_object_set(cellbutton, "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE, NULL);
g_object_set(cellbutton, "xpad", 2, NULL);
g_object_set(cellbutton, "ypad", 2, NULL);
}
/***************************************************************************
*
* custom_cell_renderer_button_class_init:
*
* set up our own get_property and set_property functions, and
* override the parent's functions that we need to implement.
* If you want cells that can be activated on their own (ie. not
* just the whole row selected) or cells that are editable, you
* will need to override 'activate' and 'start_editing' as well.
*
***************************************************************************/
static void
custom_cell_renderer_button_class_init (CustomCellRendererButtonClass *klass)
{
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS(klass);
GObjectClass *object_class = G_OBJECT_CLASS(klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = custom_cell_renderer_button_finalize;
/* Hook up functions to set and get our
* custom cell renderer properties */
object_class->get_property = custom_cell_renderer_button_get_property;
object_class->set_property = custom_cell_renderer_button_set_property;
// Override activate
cell_class->activate = custom_cell_renderer_button_activate;
button_cell_signals[CLICKED] =
g_signal_new (g_intern_static_string ("clicked"),
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (CustomCellRendererButtonClass, clicked),
NULL, NULL,
ghb_marshal_VOID__STRING,
G_TYPE_NONE, 1,
G_TYPE_STRING);
}
/***************************************************************************
*
* custom_cell_renderer_button_finalize: free any resources here
*
***************************************************************************/
static void
custom_cell_renderer_button_finalize (GObject *object)
{
/*
If you need to do anything with the renderer button ...
CustomCellRendererProgress *cellrendererbutton = CUSTOM_CELL_RENDERER_BUTTON(object);
*/
/* Free any dynamically allocated resources here */
(* G_OBJECT_CLASS (parent_class)->finalize) (object);
}
/***************************************************************************
*
* custom_cell_renderer_button_get_property: as it says
*
***************************************************************************/
static void
custom_cell_renderer_button_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *psec)
{
//CustomCellRendererButton *cellbutton = CUSTOM_CELL_RENDERER_BUTTON(object);
switch (param_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, psec);
break;
}
}
/***************************************************************************
*
* custom_cell_renderer_button_set_property: as it says
*
***************************************************************************/
static void
custom_cell_renderer_button_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
{
//CustomCellRendererButton *cellbutton = CUSTOM_CELL_RENDERER_BUTTON(object);
switch (param_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
break;
}
}
/***************************************************************************
*
* custom_cell_renderer_button_new: return a new cell renderer instance
*
***************************************************************************/
GtkCellRenderer *
custom_cell_renderer_button_new (void)
{
return g_object_new(CUSTOM_TYPE_CELL_RENDERER_BUTTON, NULL);
}
static gboolean
custom_cell_renderer_button_activate (
GtkCellRenderer *cell,
GdkEvent *event,
GtkWidget *widget,
const gchar *path,
MyGdkRectangle *background_area,
MyGdkRectangle *cell_area,
GtkCellRendererState flags)
{
g_debug("custom_cell_renderer_button_activate ()\n");
g_signal_emit (cell, button_cell_signals[CLICKED], 0, path);
return TRUE;
}
|