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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
/*
* This file is part of libtile.
*
* Copyright (c) 2006 Novell, Inc.
*
* Libtile 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 of the License, or (at your option)
* any later version.
*
* Libtile 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 libslab; if not, write to the Free Software Foundation, Inc., 51
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "nameplate-tile.h"
static void nameplate_tile_class_init (NameplateTileClass *);
static void nameplate_tile_init (NameplateTile *);
static void nameplate_tile_get_property (GObject *, guint, GValue *, GParamSpec *);
static void nameplate_tile_set_property (GObject *, guint, const GValue *, GParamSpec *);
static GObject *nameplate_tile_constructor (GType, guint, GObjectConstructParam *);
static void nameplate_tile_drag_begin (GtkWidget *, GdkDragContext *);
static void nameplate_tile_setup (NameplateTile *);
typedef struct
{
GtkContainer *image_ctnr;
GtkContainer *header_ctnr;
GtkContainer *subheader_ctnr;
} NameplateTilePrivate;
#define NAMEPLATE_TILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAMEPLATE_TILE_TYPE, NameplateTilePrivate))
enum
{
PROP_0,
PROP_NAMEPLATE_IMAGE,
PROP_NAMEPLATE_HEADER,
PROP_NAMEPLATE_SUBHEADER,
};
G_DEFINE_TYPE (NameplateTile, nameplate_tile, TILE_TYPE)
GtkWidget *nameplate_tile_new (const gchar * uri, GtkWidget * image, GtkWidget * header,
GtkWidget * subheader)
{
return GTK_WIDGET (
g_object_new (NAMEPLATE_TILE_TYPE,
"tile-uri", uri,
"nameplate-image", image,
"nameplate-header", header,
"nameplate-subheader", subheader,
NULL));
}
static void
nameplate_tile_class_init (NameplateTileClass * this_class)
{
GObjectClass *g_obj_class = G_OBJECT_CLASS (this_class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (this_class);
g_obj_class->constructor = nameplate_tile_constructor;
g_obj_class->get_property = nameplate_tile_get_property;
g_obj_class->set_property = nameplate_tile_set_property;
widget_class->drag_begin = nameplate_tile_drag_begin;
g_type_class_add_private (this_class, sizeof (NameplateTilePrivate));
g_object_class_install_property (g_obj_class, PROP_NAMEPLATE_IMAGE,
g_param_spec_object ("nameplate-image", "nameplate-image", "nameplate image",
GTK_TYPE_WIDGET, G_PARAM_READWRITE));
g_object_class_install_property (g_obj_class, PROP_NAMEPLATE_HEADER,
g_param_spec_object ("nameplate-header", "nameplate-header", "nameplate header",
GTK_TYPE_WIDGET, G_PARAM_READWRITE));
g_object_class_install_property (g_obj_class, PROP_NAMEPLATE_SUBHEADER,
g_param_spec_object ("nameplate-subheader", "nameplate-subheader",
"nameplate subheader", GTK_TYPE_WIDGET, G_PARAM_READWRITE));
}
static void
nameplate_tile_init (NameplateTile * this)
{
}
static GObject *
nameplate_tile_constructor (GType type, guint n_param, GObjectConstructParam * param)
{
GObject *g_obj =
(*G_OBJECT_CLASS (nameplate_tile_parent_class)->constructor) (type, n_param, param);
nameplate_tile_setup (NAMEPLATE_TILE (g_obj));
return g_obj;
}
static void
nameplate_tile_get_property (GObject * g_object, guint prop_id, GValue * value,
GParamSpec * param_spec)
{
NameplateTile *np_tile = NAMEPLATE_TILE (g_object);
switch (prop_id)
{
case PROP_NAMEPLATE_IMAGE:
g_value_set_object (value, np_tile->image);
break;
case PROP_NAMEPLATE_HEADER:
g_value_set_object (value, np_tile->header);
break;
case PROP_NAMEPLATE_SUBHEADER:
g_value_set_object (value, np_tile->subheader);
break;
default:
break;
}
}
static void
nameplate_tile_set_property (GObject * g_object, guint prop_id, const GValue * value,
GParamSpec * param_spec)
{
NameplateTile *this = NAMEPLATE_TILE (g_object);
NameplateTilePrivate *priv = NAMEPLATE_TILE_GET_PRIVATE (this);
GObject *widget_obj = NULL;
switch (prop_id) {
case PROP_NAMEPLATE_IMAGE:
case PROP_NAMEPLATE_HEADER:
case PROP_NAMEPLATE_SUBHEADER:
widget_obj = g_value_get_object (value);
break;
default:
break;
}
switch (prop_id)
{
case PROP_NAMEPLATE_IMAGE:
if (GTK_IS_WIDGET (widget_obj))
{
if (GTK_IS_WIDGET (this->image))
gtk_widget_destroy (this->image);
this->image = GTK_WIDGET (widget_obj);
gtk_container_add (priv->image_ctnr, this->image);
gtk_widget_show_all (this->image);
}
else if (GTK_IS_WIDGET (this->image))
gtk_widget_destroy (this->image);
break;
case PROP_NAMEPLATE_HEADER:
if (GTK_IS_WIDGET (widget_obj))
{
if (GTK_IS_WIDGET (this->header))
gtk_widget_destroy (this->header);
this->header = GTK_WIDGET (widget_obj);
gtk_container_add (priv->header_ctnr, this->header);
gtk_widget_show_all (this->header);
}
else if (GTK_IS_WIDGET (this->header))
gtk_widget_destroy (this->header);
break;
case PROP_NAMEPLATE_SUBHEADER:
if (GTK_IS_WIDGET (widget_obj))
{
if (GTK_IS_WIDGET (this->subheader))
gtk_widget_destroy (this->subheader);
this->subheader = GTK_WIDGET (widget_obj);
gtk_container_add (priv->subheader_ctnr, this->subheader);
gtk_widget_show_all (this->subheader);
}
else if (GTK_IS_WIDGET (this->subheader))
gtk_widget_destroy (this->subheader);
break;
default:
break;
}
}
static void
nameplate_tile_setup (NameplateTile *this)
{
NameplateTilePrivate *priv = NAMEPLATE_TILE_GET_PRIVATE (this);
GtkWidget *hbox;
GtkWidget *vbox;
priv->image_ctnr = GTK_CONTAINER (gtk_alignment_new (0.5, 0.5, 1.0, 1.0));
priv->header_ctnr = GTK_CONTAINER (gtk_alignment_new (0.0, 0.5, 1.0, 1.0));
priv->subheader_ctnr = GTK_CONTAINER (gtk_alignment_new (0.0, 0.5, 1.0, 1.0));
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_widget_set_halign (vbox, GTK_ALIGN_FILL);
gtk_widget_set_valign (vbox, GTK_ALIGN_CENTER);
gtk_container_add (GTK_CONTAINER (this), hbox);
gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (priv->image_ctnr), FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (priv->header_ctnr), FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (priv->subheader_ctnr), FALSE, FALSE, 0);
if (GTK_IS_WIDGET (this->image))
gtk_container_add (priv->image_ctnr, this->image);
if (GTK_IS_WIDGET (this->header))
gtk_container_add (priv->header_ctnr, this->header);
if (GTK_IS_WIDGET (this->subheader))
gtk_container_add (priv->subheader_ctnr, this->subheader);
gtk_button_set_focus_on_click (GTK_BUTTON (this), FALSE);
}
static void
nameplate_tile_drag_begin (GtkWidget * widget, GdkDragContext * context)
{
NameplateTile *this = NAMEPLATE_TILE (widget);
GtkImage *image;
const gchar *name;
(*GTK_WIDGET_CLASS (nameplate_tile_parent_class)->drag_begin) (widget, context);
if (!this->image || !GTK_IS_IMAGE (this->image))
return;
image = GTK_IMAGE (this->image);
switch (gtk_image_get_storage_type (image))
{
case GTK_IMAGE_PIXBUF:
if (gtk_image_get_pixbuf (image))
gtk_drag_set_icon_pixbuf (context, gtk_image_get_pixbuf (image), 0, 0);
break;
case GTK_IMAGE_ICON_NAME:
gtk_image_get_icon_name (image, &name, NULL);
if (name)
gtk_drag_set_icon_name (context, name, 0, 0);
break;
default:
break;
}
}
|