]> git.sur5r.net Git - glabels/blob - glabels2/src/label-box.c
Initial revision
[glabels] / glabels2 / src / label-box.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  label_box.c:  GLabels label box 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-box.h"
26
27 #include "debug.h"
28
29 /*========================================================*/
30 /* Private types.                                         */
31 /*========================================================*/
32
33 struct _glLabelBoxPrivate {
34         gdouble          line_width;
35         guint            line_color;
36         guint            fill_color;
37 };
38
39 /*========================================================*/
40 /* Private globals.                                       */
41 /*========================================================*/
42
43 static GObjectClass *parent_class = NULL;
44
45 static guint instance = 0;
46
47 /*========================================================*/
48 /* Private function prototypes.                           */
49 /*========================================================*/
50
51 static void gl_label_box_class_init (glLabelBoxClass *klass);
52 static void gl_label_box_instance_init (glLabelBox *lbox);
53 static void gl_label_box_finalize (GObject *object);
54
55 \f
56 /*****************************************************************************/
57 /* Boilerplate object stuff.                                                 */
58 /*****************************************************************************/
59 GType
60 gl_label_box_get_type (void)
61 {
62         static GType type = 0;
63
64         if (!type) {
65                 GTypeInfo info = {
66                         sizeof (glLabelBoxClass),
67                         NULL,
68                         NULL,
69                         (GClassInitFunc) gl_label_box_class_init,
70                         NULL,
71                         NULL,
72                         sizeof (glLabelBox),
73                         0,
74                         (GInstanceInitFunc) gl_label_box_instance_init,
75                 };
76
77                 type = g_type_register_static (GL_TYPE_LABEL_OBJECT,
78                                                "glLabelBox", &info, 0);
79         }
80
81         return type;
82 }
83
84 static void
85 gl_label_box_class_init (glLabelBoxClass *klass)
86 {
87         GObjectClass *object_class = (GObjectClass *) klass;
88
89         parent_class = g_type_class_peek_parent (klass);
90
91         object_class->finalize = gl_label_box_finalize;
92 }
93
94 static void
95 gl_label_box_instance_init (glLabelBox *lbox)
96 {
97         lbox->private = g_new0 (glLabelBoxPrivate, 1);
98 }
99
100 static void
101 gl_label_box_finalize (GObject *object)
102 {
103         glLabelBox *lbox;
104
105         g_return_if_fail (object && GL_IS_LABEL_BOX (object));
106
107         lbox = GL_LABEL_BOX (object);
108
109         g_free (lbox->private);
110
111         G_OBJECT_CLASS (parent_class)->finalize (object);
112 }
113
114 /*****************************************************************************/
115 /* NEW label "box" object.                                                   */
116 /*****************************************************************************/
117 GObject *
118 gl_label_box_new (glLabel *label)
119 {
120         glLabelBox *lbox;
121
122         lbox = g_object_new (gl_label_box_get_type(), NULL);
123
124         gl_label_object_set_parent (GL_LABEL_OBJECT(lbox), label);
125
126         return G_OBJECT (lbox);
127 }
128
129 /*****************************************************************************/
130 /* Duplicate object.                                                         */
131 /*****************************************************************************/
132 glLabelBox *
133 gl_label_box_dup (glLabelBox *lbox,
134                   glLabel *label)
135 {
136         glLabelBox *new_lbox;
137         gdouble    x, y, w, h, line_width;
138         guint      line_color, fill_color;
139
140         gl_debug (DEBUG_LABEL, "START");
141
142         g_return_if_fail (lbox && GL_IS_LABEL_BOX (lbox));
143         g_return_if_fail (label && GL_IS_LABEL (label));
144
145         new_lbox = GL_LABEL_BOX(gl_label_box_new (label));
146
147         gl_label_object_get_position (GL_LABEL_OBJECT(lbox), &x, &y);
148         gl_label_object_get_size     (GL_LABEL_OBJECT(lbox), &w, &h);
149
150         gl_label_object_set_position (GL_LABEL_OBJECT(new_lbox),  x,  y);
151         gl_label_object_set_size     (GL_LABEL_OBJECT(new_lbox),  w,  h);
152
153         line_width = gl_label_box_get_line_width (lbox);
154         line_color = gl_label_box_get_line_color (lbox);
155         fill_color = gl_label_box_get_fill_color (lbox);
156
157         gl_label_box_set_line_width (new_lbox, line_width);
158         gl_label_box_set_line_color (new_lbox, line_color);
159         gl_label_box_set_fill_color (new_lbox, fill_color);
160
161
162         gl_debug (DEBUG_LABEL, "END");
163
164         return new_lbox;
165 }
166
167
168 /*****************************************************************************/
169 /* Set object params.                                                        */
170 /*****************************************************************************/
171 void
172 gl_label_box_set_line_width (glLabelBox *lbox,
173                              gdouble    line_width)
174 {
175         g_return_if_fail (lbox && GL_IS_LABEL_BOX (lbox));
176
177         if ( lbox->private->line_width != line_width ) {
178                 lbox->private->line_width = line_width;
179                 gl_label_object_emit_changed (GL_LABEL_OBJECT(lbox));
180         }
181 }
182
183 void
184 gl_label_box_set_line_color (glLabelBox *lbox,
185                              guint      line_color)
186 {
187         g_return_if_fail (lbox && GL_IS_LABEL_BOX (lbox));
188
189         if ( lbox->private->line_color != line_color ) {
190                 lbox->private->line_color = line_color;
191                 gl_label_object_emit_changed (GL_LABEL_OBJECT(lbox));
192         }
193 }
194
195 void
196 gl_label_box_set_fill_color (glLabelBox *lbox,
197                              guint      fill_color)
198 {
199         g_return_if_fail (lbox && GL_IS_LABEL_BOX (lbox));
200
201         if ( lbox->private->fill_color != fill_color ) {
202                 lbox->private->fill_color = fill_color;
203                 gl_label_object_emit_changed (GL_LABEL_OBJECT(lbox));
204         }
205 }
206
207 /*****************************************************************************/
208 /* Get object params.                                                        */
209 /*****************************************************************************/
210 gdouble
211 gl_label_box_get_line_width (glLabelBox *lbox)
212 {
213         g_return_val_if_fail (lbox && GL_IS_LABEL_BOX (lbox), 0.0);
214
215         return lbox->private->line_width;
216 }
217
218 guint
219 gl_label_box_get_line_color (glLabelBox *lbox)
220 {
221         g_return_val_if_fail (lbox && GL_IS_LABEL_BOX (lbox), 0);
222
223         return lbox->private->line_color;
224 }
225
226 guint
227 gl_label_box_get_fill_color (glLabelBox *lbox)
228 {
229         g_return_val_if_fail (lbox && GL_IS_LABEL_BOX (lbox), 0);
230
231         return lbox->private->fill_color;
232 }
233