]> git.sur5r.net Git - glabels/blob - glabels2/src/label-line.c
Created generic "get" methods for text, fill and line properties for all label object...
[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                 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                 };
89
90                 type = g_type_register_static (GL_TYPE_LABEL_OBJECT,
91                                                "glLabelLine", &info, 0);
92         }
93
94         return type;
95 }
96
97 static void
98 gl_label_line_class_init (glLabelLineClass *klass)
99 {
100         GObjectClass       *object_class       = (GObjectClass *) klass;
101         glLabelObjectClass *label_object_class = (glLabelObjectClass *) klass;
102
103         parent_class = g_type_class_peek_parent (klass);
104
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;
110
111         object_class->finalize = gl_label_line_finalize;
112 }
113
114 static void
115 gl_label_line_instance_init (glLabelLine *lline)
116 {
117         lline->private = g_new0 (glLabelLinePrivate, 1);
118 }
119
120 static void
121 gl_label_line_finalize (GObject *object)
122 {
123         glLabelLine *lline;
124
125         g_return_if_fail (object && GL_IS_LABEL_LINE (object));
126
127         lline = GL_LABEL_LINE (object);
128
129         g_free (lline->private);
130
131         G_OBJECT_CLASS (parent_class)->finalize (object);
132 }
133
134 /*****************************************************************************/
135 /* NEW label "line" object.                                               */
136 /*****************************************************************************/
137 GObject *
138 gl_label_line_new (glLabel *label)
139 {
140         glLabelLine *lline;
141
142         lline = g_object_new (gl_label_line_get_type(), NULL);
143
144         gl_label_object_set_parent (GL_LABEL_OBJECT(lline), label);
145
146         return G_OBJECT (lline);
147 }
148
149 /*****************************************************************************/
150 /* Copy object contents.                                                     */
151 /*****************************************************************************/
152 static void
153 copy (glLabelObject *dst_object,
154       glLabelObject *src_object)
155 {
156         glLabelLine *lline     = (glLabelLine *)src_object;
157         glLabelLine *new_lline = (glLabelLine *)dst_object;
158         gdouble      line_width;
159         guint        line_color;
160
161         gl_debug (DEBUG_LABEL, "START");
162
163         g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
164         g_return_if_fail (new_lline && GL_IS_LABEL_LINE (new_lline));
165
166         line_width = get_line_width (src_object);
167         line_color = get_line_color (src_object);
168
169         set_line_width (dst_object, line_width);
170         set_line_color (dst_object, line_color);
171
172         gl_debug (DEBUG_LABEL, "END");
173 }
174
175
176 /*---------------------------------------------------------------------------*/
177 /* PRIVATE.  Set line color method.                                          */
178 /*---------------------------------------------------------------------------*/
179 static void
180 set_line_color (glLabelObject *object,
181                 guint          line_color)
182 {
183         glLabelLine *lline = (glLabelLine *)object;
184
185         g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
186
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));
190         }
191 }
192
193 /*---------------------------------------------------------------------------*/
194 /* PRIVATE.  Set line width method.                                          */
195 /*---------------------------------------------------------------------------*/
196 static void
197 set_line_width (glLabelObject *object,
198                 gdouble        line_width)
199 {
200         glLabelLine *lline = (glLabelLine *)object;
201
202         g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
203
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));
207         }
208 }
209
210
211 /*---------------------------------------------------------------------------*/
212 /* PRIVATE.  Get line color method.                                          */
213 /*---------------------------------------------------------------------------*/
214 static gdouble
215 get_line_width (glLabelObject *object)
216 {
217         glLabelLine *lline = (glLabelLine *)object;
218
219         g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0.0);
220
221         return lline->private->line_width;
222 }
223
224 /*---------------------------------------------------------------------------*/
225 /* PRIVATE.  Get line width method.                                          */
226 /*---------------------------------------------------------------------------*/
227 static guint
228 get_line_color (glLabelObject *object)
229 {
230         glLabelLine *lline = (glLabelLine *)object;
231
232         g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0);
233
234         return lline->private->line_color;
235 }
236