2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * label_image.c: GLabels label image object
6 * Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "label-image.h"
27 #include "pixmaps/checkerboard.xpm"
31 /*========================================================*/
33 /*========================================================*/
35 struct _glLabelImagePrivate {
40 /*========================================================*/
41 /* Private globals. */
42 /*========================================================*/
44 static GObjectClass *parent_class = NULL;
46 static guint instance = 0;
48 /*========================================================*/
49 /* Private function prototypes. */
50 /*========================================================*/
52 static void gl_label_image_class_init (glLabelImageClass *klass);
53 static void gl_label_image_instance_init (glLabelImage *limage);
54 static void gl_label_image_finalize (GObject *object);
57 /*****************************************************************************/
58 /* Boilerplate object stuff. */
59 /*****************************************************************************/
61 gl_label_image_get_type (void)
63 static GType type = 0;
67 sizeof (glLabelImageClass),
70 (GClassInitFunc) gl_label_image_class_init,
73 sizeof (glLabelImage),
75 (GInstanceInitFunc) gl_label_image_instance_init,
78 type = g_type_register_static (GL_TYPE_LABEL_OBJECT,
79 "glLabelImage", &info, 0);
86 gl_label_image_class_init (glLabelImageClass *klass)
88 GObjectClass *object_class = (GObjectClass *) klass;
90 parent_class = g_type_class_peek_parent (klass);
92 object_class->finalize = gl_label_image_finalize;
96 gl_label_image_instance_init (glLabelImage *limage)
98 limage->private = g_new0 (glLabelImagePrivate, 1);
100 limage->private->pixbuf =
101 gdk_pixbuf_new_from_xpm_data ((const char **)
106 gl_label_image_finalize (GObject *object)
108 glLabelImage *limage;
110 g_return_if_fail (object && GL_IS_LABEL_IMAGE (object));
112 limage = GL_LABEL_IMAGE (object);
114 g_free (limage->private);
116 G_OBJECT_CLASS (parent_class)->finalize (object);
119 /*****************************************************************************/
120 /* NEW label "image" object. */
121 /*****************************************************************************/
123 gl_label_image_new (glLabel *label)
125 glLabelImage *limage;
127 limage = g_object_new (gl_label_image_get_type(), NULL);
129 gl_label_object_set_parent (GL_LABEL_OBJECT(limage), label);
131 return G_OBJECT (limage);
134 /*****************************************************************************/
135 /* Duplicate object. */
136 /*****************************************************************************/
138 gl_label_image_dup (glLabelImage *limage,
141 glLabelImage *new_limage;
145 gl_debug (DEBUG_LABEL, "START");
147 g_return_if_fail (limage && GL_IS_LABEL_IMAGE (limage));
148 g_return_if_fail (label && GL_IS_LABEL (label));
150 new_limage = GL_LABEL_IMAGE(gl_label_image_new (label));
152 gl_label_object_get_position (GL_LABEL_OBJECT(limage), &x, &y);
153 gl_label_object_get_size (GL_LABEL_OBJECT(limage), &w, &h);
155 gl_label_object_set_position (GL_LABEL_OBJECT(new_limage), x, y);
156 gl_label_object_set_size (GL_LABEL_OBJECT(new_limage), w, h);
158 filename = gl_label_image_get_filename (limage);
160 gl_label_image_set_filename (new_limage, filename);
164 gl_debug (DEBUG_LABEL, "END");
170 /*****************************************************************************/
171 /* Set object params. */
172 /*****************************************************************************/
174 gl_label_image_set_filename (glLabelImage *limage,
175 const gchar *filename)
179 gl_debug (DEBUG_LABEL, "START");
181 g_return_if_fail (limage && GL_IS_LABEL_IMAGE (limage));
183 if ( filename == NULL ) {
185 g_free (limage->private->filename);
186 limage->private->filename = NULL;
188 g_object_unref (limage->private->pixbuf);
189 limage->private->pixbuf =
190 gdk_pixbuf_new_from_xpm_data ((const char **)
193 gl_label_object_emit_changed (GL_LABEL_OBJECT(limage));
196 if ( (limage->private->filename == NULL) ||
197 (strcmp (limage->private->filename, filename) != 0) ) {
199 g_free (limage->private->filename);
200 limage->private->filename = g_strdup (filename);
202 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
203 g_object_unref (limage->private->pixbuf);
204 if ( pixbuf != NULL ) {
205 limage->private->pixbuf = pixbuf;
207 limage->private->pixbuf =
208 gdk_pixbuf_new_from_xpm_data ((const char **)
212 gl_label_object_emit_changed (GL_LABEL_OBJECT(limage));
217 gl_debug (DEBUG_LABEL, "END");
221 /*****************************************************************************/
222 /* Get object params. */
223 /*****************************************************************************/
225 gl_label_image_get_filename (glLabelImage *limage)
227 g_return_val_if_fail (limage && GL_IS_LABEL_IMAGE (limage), NULL);
229 return g_strdup (limage->private->filename);
233 gl_label_image_get_pixbuf (glLabelImage *limage)
235 g_return_val_if_fail (limage && GL_IS_LABEL_IMAGE (limage), NULL);
237 return limage->private->pixbuf;