2 * (GLABELS) Label and Business Card Creation program for GNOME
4 * label_line.c: GLabels label line 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-line.h"
29 /*========================================================*/
31 /*========================================================*/
33 struct _glLabelLinePrivate {
38 /*========================================================*/
39 /* Private globals. */
40 /*========================================================*/
42 static GObjectClass *parent_class = NULL;
44 static guint instance = 0;
46 /*========================================================*/
47 /* Private function prototypes. */
48 /*========================================================*/
50 static void gl_label_line_class_init (glLabelLineClass *klass);
51 static void gl_label_line_instance_init (glLabelLine *lline);
52 static void gl_label_line_finalize (GObject *object);
54 static void copy (glLabelObject *dst_object,
55 glLabelObject *src_object);
57 static void set_line_color (glLabelObject *object,
60 static void set_line_width (glLabelObject *object,
63 static guint get_line_color (glLabelObject *object);
65 static gdouble get_line_width (glLabelObject *object);
69 /*****************************************************************************/
70 /* Boilerplate object stuff. */
71 /*****************************************************************************/
73 gl_label_line_get_type (void)
75 static GType type = 0;
79 sizeof (glLabelLineClass),
82 (GClassInitFunc) gl_label_line_class_init,
87 (GInstanceInitFunc) gl_label_line_instance_init,
90 type = g_type_register_static (GL_TYPE_LABEL_OBJECT,
91 "glLabelLine", &info, 0);
98 gl_label_line_class_init (glLabelLineClass *klass)
100 GObjectClass *object_class = (GObjectClass *) klass;
101 glLabelObjectClass *label_object_class = (glLabelObjectClass *) klass;
103 parent_class = g_type_class_peek_parent (klass);
105 label_object_class->copy = copy;
106 label_object_class->set_line_color = set_line_color;
107 label_object_class->set_line_width = set_line_width;
108 label_object_class->get_line_color = get_line_color;
109 label_object_class->get_line_width = get_line_width;
111 object_class->finalize = gl_label_line_finalize;
115 gl_label_line_instance_init (glLabelLine *lline)
117 lline->private = g_new0 (glLabelLinePrivate, 1);
121 gl_label_line_finalize (GObject *object)
125 g_return_if_fail (object && GL_IS_LABEL_LINE (object));
127 lline = GL_LABEL_LINE (object);
129 g_free (lline->private);
131 G_OBJECT_CLASS (parent_class)->finalize (object);
134 /*****************************************************************************/
135 /* NEW label "line" object. */
136 /*****************************************************************************/
138 gl_label_line_new (glLabel *label)
142 lline = g_object_new (gl_label_line_get_type(), NULL);
144 gl_label_object_set_parent (GL_LABEL_OBJECT(lline), label);
146 return G_OBJECT (lline);
149 /*****************************************************************************/
150 /* Copy object contents. */
151 /*****************************************************************************/
153 copy (glLabelObject *dst_object,
154 glLabelObject *src_object)
156 glLabelLine *lline = (glLabelLine *)src_object;
157 glLabelLine *new_lline = (glLabelLine *)dst_object;
161 gl_debug (DEBUG_LABEL, "START");
163 g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
164 g_return_if_fail (new_lline && GL_IS_LABEL_LINE (new_lline));
166 line_width = get_line_width (src_object);
167 line_color = get_line_color (src_object);
169 set_line_width (dst_object, line_width);
170 set_line_color (dst_object, line_color);
172 gl_debug (DEBUG_LABEL, "END");
176 /*---------------------------------------------------------------------------*/
177 /* PRIVATE. Set line color method. */
178 /*---------------------------------------------------------------------------*/
180 set_line_color (glLabelObject *object,
183 glLabelLine *lline = (glLabelLine *)object;
185 g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
187 if ( lline->private->line_color != line_color ) {
188 lline->private->line_color = line_color;
189 gl_label_object_emit_changed (GL_LABEL_OBJECT(lline));
193 /*---------------------------------------------------------------------------*/
194 /* PRIVATE. Set line width method. */
195 /*---------------------------------------------------------------------------*/
197 set_line_width (glLabelObject *object,
200 glLabelLine *lline = (glLabelLine *)object;
202 g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
204 if ( lline->private->line_width != line_width ) {
205 lline->private->line_width = line_width;
206 gl_label_object_emit_changed (GL_LABEL_OBJECT(lline));
211 /*---------------------------------------------------------------------------*/
212 /* PRIVATE. Get line color method. */
213 /*---------------------------------------------------------------------------*/
215 get_line_width (glLabelObject *object)
217 glLabelLine *lline = (glLabelLine *)object;
219 g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0.0);
221 return lline->private->line_width;
224 /*---------------------------------------------------------------------------*/
225 /* PRIVATE. Get line width method. */
226 /*---------------------------------------------------------------------------*/
228 get_line_color (glLabelObject *object)
230 glLabelLine *lline = (glLabelLine *)object;
232 g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0);
234 return lline->private->line_color;