]> git.sur5r.net Git - glabels/blob - glabels2/src/label-line.c
2004-07-02 Jim Evins <evins@snaught.com>
[glabels] / glabels2 / src / label-line.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  label_line.c:  GLabels label line object
5  *
6  *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include <glib.h>
24
25 #include "label-line.h"
26
27 #include "debug.h"
28
29 /*========================================================*/
30 /* Private types.                                         */
31 /*========================================================*/
32
33 struct _glLabelLinePrivate {
34         gdouble          line_width;
35         guint            line_color;
36 };
37
38 /*========================================================*/
39 /* Private globals.                                       */
40 /*========================================================*/
41
42 static GObjectClass *parent_class = NULL;
43
44 static guint instance = 0;
45
46 /*========================================================*/
47 /* Private function prototypes.                           */
48 /*========================================================*/
49
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);
53
54 static void    copy                        (glLabelObject    *dst_object,
55                                             glLabelObject    *src_object);
56
57 static void    set_line_color              (glLabelObject    *object,
58                                             guint             line_color);
59
60 static void    set_line_width              (glLabelObject    *object,
61                                             gdouble           line_width);
62
63 static guint   get_line_color              (glLabelObject    *object);
64
65 static gdouble get_line_width              (glLabelObject    *object);
66
67
68 \f
69 /*****************************************************************************/
70 /* Boilerplate object stuff.                                                 */
71 /*****************************************************************************/
72 GType
73 gl_label_line_get_type (void)
74 {
75         static GType type = 0;
76
77         if (!type) {
78                 static const GTypeInfo info = {
79                         sizeof (glLabelLineClass),
80                         NULL,
81                         NULL,
82                         (GClassInitFunc) gl_label_line_class_init,
83                         NULL,
84                         NULL,
85                         sizeof (glLabelLine),
86                         0,
87                         (GInstanceInitFunc) gl_label_line_instance_init,
88                         NULL
89                 };
90
91                 type = g_type_register_static (GL_TYPE_LABEL_OBJECT,
92                                                "glLabelLine", &info, 0);
93         }
94
95         return type;
96 }
97
98 static void
99 gl_label_line_class_init (glLabelLineClass *klass)
100 {
101         GObjectClass       *object_class       = (GObjectClass *) klass;
102         glLabelObjectClass *label_object_class = (glLabelObjectClass *) klass;
103
104         parent_class = g_type_class_peek_parent (klass);
105
106         label_object_class->copy           = copy;
107         label_object_class->set_line_color = set_line_color;
108         label_object_class->set_line_width = set_line_width;
109         label_object_class->get_line_color = get_line_color;
110         label_object_class->get_line_width = get_line_width;
111
112         object_class->finalize = gl_label_line_finalize;
113 }
114
115 static void
116 gl_label_line_instance_init (glLabelLine *lline)
117 {
118         lline->private = g_new0 (glLabelLinePrivate, 1);
119 }
120
121 static void
122 gl_label_line_finalize (GObject *object)
123 {
124         glLabelLine *lline;
125
126         g_return_if_fail (object && GL_IS_LABEL_LINE (object));
127
128         lline = GL_LABEL_LINE (object);
129
130         g_free (lline->private);
131
132         G_OBJECT_CLASS (parent_class)->finalize (object);
133 }
134
135 /*****************************************************************************/
136 /* NEW label "line" object.                                               */
137 /*****************************************************************************/
138 GObject *
139 gl_label_line_new (glLabel *label)
140 {
141         glLabelLine *lline;
142
143         lline = g_object_new (gl_label_line_get_type(), NULL);
144
145         gl_label_object_set_parent (GL_LABEL_OBJECT(lline), label);
146
147         return G_OBJECT (lline);
148 }
149
150 /*****************************************************************************/
151 /* Copy object contents.                                                     */
152 /*****************************************************************************/
153 static void
154 copy (glLabelObject *dst_object,
155       glLabelObject *src_object)
156 {
157         glLabelLine *lline     = (glLabelLine *)src_object;
158         glLabelLine *new_lline = (glLabelLine *)dst_object;
159         gdouble      line_width;
160         guint        line_color;
161
162         gl_debug (DEBUG_LABEL, "START");
163
164         g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
165         g_return_if_fail (new_lline && GL_IS_LABEL_LINE (new_lline));
166
167         line_width = get_line_width (src_object);
168         line_color = get_line_color (src_object);
169
170         set_line_width (dst_object, line_width);
171         set_line_color (dst_object, line_color);
172
173         gl_debug (DEBUG_LABEL, "END");
174 }
175
176
177 /*---------------------------------------------------------------------------*/
178 /* PRIVATE.  Set line color method.                                          */
179 /*---------------------------------------------------------------------------*/
180 static void
181 set_line_color (glLabelObject *object,
182                 guint          line_color)
183 {
184         glLabelLine *lline = (glLabelLine *)object;
185
186         g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
187
188         if ( lline->private->line_color != line_color ) {
189                 lline->private->line_color = line_color;
190                 gl_label_object_emit_changed (GL_LABEL_OBJECT(lline));
191         }
192 }
193
194 /*---------------------------------------------------------------------------*/
195 /* PRIVATE.  Set line width method.                                          */
196 /*---------------------------------------------------------------------------*/
197 static void
198 set_line_width (glLabelObject *object,
199                 gdouble        line_width)
200 {
201         glLabelLine *lline = (glLabelLine *)object;
202
203         g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
204
205         if ( lline->private->line_width != line_width ) {
206                 lline->private->line_width = line_width;
207                 gl_label_object_emit_changed (GL_LABEL_OBJECT(lline));
208         }
209 }
210
211
212 /*---------------------------------------------------------------------------*/
213 /* PRIVATE.  Get line color method.                                          */
214 /*---------------------------------------------------------------------------*/
215 static gdouble
216 get_line_width (glLabelObject *object)
217 {
218         glLabelLine *lline = (glLabelLine *)object;
219
220         g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0.0);
221
222         return lline->private->line_width;
223 }
224
225 /*---------------------------------------------------------------------------*/
226 /* PRIVATE.  Get line width method.                                          */
227 /*---------------------------------------------------------------------------*/
228 static guint
229 get_line_color (glLabelObject *object)
230 {
231         glLabelLine *lline = (glLabelLine *)object;
232
233         g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0);
234
235         return lline->private->line_color;
236 }
237