2
* This file is part of libtile.
4
* Copyright (c) 2006 Novell, Inc.
6
* Libtile 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
* Libtile 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 "nameplate-tile.h"
23
static void nameplate_tile_class_init (NameplateTileClass *);
24
static void nameplate_tile_init (NameplateTile *);
25
static void nameplate_tile_finalize (GObject *);
26
static void nameplate_tile_get_property (GObject *, guint, GValue *, GParamSpec *);
27
static void nameplate_tile_set_property (GObject *, guint, const GValue *, GParamSpec *);
28
static GObject *nameplate_tile_constructor (GType, guint, GObjectConstructParam *);
30
static void nameplate_tile_drag_begin (GtkWidget *, GdkDragContext *);
32
static void nameplate_tile_setup (NameplateTile *);
36
GtkContainer *image_ctnr;
37
GtkContainer *header_ctnr;
38
GtkContainer *subheader_ctnr;
39
} NameplateTilePrivate;
41
#define NAMEPLATE_TILE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NAMEPLATE_TILE_TYPE, NameplateTilePrivate))
47
PROP_NAMEPLATE_HEADER,
48
PROP_NAMEPLATE_SUBHEADER,
51
G_DEFINE_TYPE (NameplateTile, nameplate_tile, TILE_TYPE)
53
GtkWidget *nameplate_tile_new (const gchar * uri, GtkWidget * image, GtkWidget * header,
54
GtkWidget * subheader)
57
g_object_new (NAMEPLATE_TILE_TYPE,
59
"nameplate-image", image,
60
"nameplate-header", header,
61
"nameplate-subheader", subheader,
66
nameplate_tile_class_init (NameplateTileClass * this_class)
68
GObjectClass *g_obj_class = G_OBJECT_CLASS (this_class);
69
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (this_class);
71
g_obj_class->constructor = nameplate_tile_constructor;
72
g_obj_class->get_property = nameplate_tile_get_property;
73
g_obj_class->set_property = nameplate_tile_set_property;
74
g_obj_class->finalize = nameplate_tile_finalize;
76
widget_class->drag_begin = nameplate_tile_drag_begin;
78
g_type_class_add_private (this_class, sizeof (NameplateTilePrivate));
80
g_object_class_install_property (g_obj_class, PROP_NAMEPLATE_IMAGE,
81
g_param_spec_object ("nameplate-image", "nameplate-image", "nameplate image",
82
GTK_TYPE_WIDGET, G_PARAM_READWRITE));
84
g_object_class_install_property (g_obj_class, PROP_NAMEPLATE_HEADER,
85
g_param_spec_object ("nameplate-header", "nameplate-header", "nameplate header",
86
GTK_TYPE_WIDGET, G_PARAM_READWRITE));
88
g_object_class_install_property (g_obj_class, PROP_NAMEPLATE_SUBHEADER,
89
g_param_spec_object ("nameplate-subheader", "nameplate-subheader",
90
"nameplate subheader", GTK_TYPE_WIDGET, G_PARAM_READWRITE));
94
nameplate_tile_init (NameplateTile * this)
99
nameplate_tile_constructor (GType type, guint n_param, GObjectConstructParam * param)
102
(*G_OBJECT_CLASS (nameplate_tile_parent_class)->constructor) (type, n_param, param);
104
nameplate_tile_setup (NAMEPLATE_TILE (g_obj));
110
nameplate_tile_finalize (GObject * g_object)
112
NameplateTile *np_tile;
113
NameplateTilePrivate *priv;
115
np_tile = NAMEPLATE_TILE (g_object);
116
priv = NAMEPLATE_TILE_GET_PRIVATE (np_tile);
118
(*G_OBJECT_CLASS (nameplate_tile_parent_class)->finalize) (g_object);
122
nameplate_tile_get_property (GObject * g_object, guint prop_id, GValue * value,
123
GParamSpec * param_spec)
125
NameplateTile *np_tile = NAMEPLATE_TILE (g_object);
129
case PROP_NAMEPLATE_IMAGE:
130
g_value_set_object (value, np_tile->image);
133
case PROP_NAMEPLATE_HEADER:
134
g_value_set_object (value, np_tile->header);
137
case PROP_NAMEPLATE_SUBHEADER:
138
g_value_set_object (value, np_tile->subheader);
146
nameplate_tile_set_property (GObject * g_object, guint prop_id, const GValue * value,
147
GParamSpec * param_spec)
149
NameplateTile *this = NAMEPLATE_TILE (g_object);
150
NameplateTilePrivate *priv = NAMEPLATE_TILE_GET_PRIVATE (this);
152
GObject *widget_obj = NULL;
155
case PROP_NAMEPLATE_IMAGE:
156
case PROP_NAMEPLATE_HEADER:
157
case PROP_NAMEPLATE_SUBHEADER:
158
widget_obj = g_value_get_object (value);
166
case PROP_NAMEPLATE_IMAGE:
167
if (GTK_IS_WIDGET (widget_obj))
169
if (GTK_IS_WIDGET (this->image))
170
gtk_widget_destroy (this->image);
172
this->image = GTK_WIDGET (widget_obj);
174
gtk_container_add (priv->image_ctnr, this->image);
176
gtk_widget_show_all (this->image);
178
else if (GTK_IS_WIDGET (this->image))
179
gtk_widget_destroy (this->image);
183
case PROP_NAMEPLATE_HEADER:
184
if (GTK_IS_WIDGET (widget_obj))
186
if (GTK_IS_WIDGET (this->header))
187
gtk_widget_destroy (this->header);
189
this->header = GTK_WIDGET (widget_obj);
191
gtk_container_add (priv->header_ctnr, this->header);
193
gtk_widget_show_all (this->header);
195
else if (GTK_IS_WIDGET (this->header))
196
gtk_widget_destroy (this->header);
200
case PROP_NAMEPLATE_SUBHEADER:
201
if (GTK_IS_WIDGET (widget_obj))
203
if (GTK_IS_WIDGET (this->subheader))
204
gtk_widget_destroy (this->subheader);
206
this->subheader = GTK_WIDGET (widget_obj);
208
gtk_container_add (priv->subheader_ctnr, this->subheader);
210
gtk_widget_show_all (this->subheader);
212
else if (GTK_IS_WIDGET (this->subheader))
213
gtk_widget_destroy (this->subheader);
223
nameplate_tile_setup (NameplateTile *this)
225
NameplateTilePrivate *priv = NAMEPLATE_TILE_GET_PRIVATE (this);
228
GtkWidget *alignment;
231
priv->image_ctnr = GTK_CONTAINER (gtk_alignment_new (0.5, 0.5, 1.0, 1.0));
232
priv->header_ctnr = GTK_CONTAINER (gtk_alignment_new (0.0, 0.5, 1.0, 1.0));
233
priv->subheader_ctnr = GTK_CONTAINER (gtk_alignment_new (0.0, 0.5, 1.0, 1.0));
235
hbox = gtk_hbox_new (FALSE, 6);
236
vbox = gtk_vbox_new (FALSE, 0);
238
alignment = gtk_alignment_new (0.0, 0.5, 1.0, 0.0);
240
gtk_container_add (GTK_CONTAINER (this), hbox);
241
gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (priv->image_ctnr), FALSE, FALSE, 0);
242
gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, TRUE, 0);
244
gtk_container_add (GTK_CONTAINER (alignment), vbox);
245
gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (priv->header_ctnr), FALSE, FALSE, 0);
246
gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (priv->subheader_ctnr), FALSE, FALSE, 0);
248
if (GTK_IS_WIDGET (this->image))
249
gtk_container_add (priv->image_ctnr, this->image);
251
if (GTK_IS_WIDGET (this->header))
252
gtk_container_add (priv->header_ctnr, this->header);
254
if (GTK_IS_WIDGET (this->subheader))
255
gtk_container_add (priv->subheader_ctnr, this->subheader);
257
gtk_button_set_focus_on_click (GTK_BUTTON (this), FALSE);
261
nameplate_tile_drag_begin (GtkWidget * widget, GdkDragContext * context)
263
NameplateTile *this = NAMEPLATE_TILE (widget);
266
(*GTK_WIDGET_CLASS (nameplate_tile_parent_class)->drag_begin) (widget, context);
268
if (!this->image || !GTK_IS_IMAGE (this->image))
271
image = GTK_IMAGE (this->image);
273
switch (image->storage_type)
275
case GTK_IMAGE_PIXBUF:
276
if (image->data.pixbuf.pixbuf)
277
gtk_drag_set_icon_pixbuf (context, image->data.pixbuf.pixbuf, 0, 0);
281
case GTK_IMAGE_ICON_NAME:
282
if (image->data.name.pixbuf)
283
gtk_drag_set_icon_pixbuf (context, image->data.name.pixbuf, 0, 0);