]> git.sur5r.net Git - glabels/blob - glabels2/src/label-line.c
Initial revision
[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 \f
55 /*****************************************************************************/
56 /* Boilerplate object stuff.                                                 */
57 /*****************************************************************************/
58 GType
59 gl_label_line_get_type (void)
60 {
61         static GType type = 0;
62
63         if (!type) {
64                 GTypeInfo info = {
65                         sizeof (glLabelLineClass),
66                         NULL,
67                         NULL,
68                         (GClassInitFunc) gl_label_line_class_init,
69                         NULL,
70                         NULL,
71                         sizeof (glLabelLine),
72                         0,
73                         (GInstanceInitFunc) gl_label_line_instance_init,
74                 };
75
76                 type = g_type_register_static (GL_TYPE_LABEL_OBJECT,
77                                                "glLabelLine", &info, 0);
78         }
79
80         return type;
81 }
82
83 static void
84 gl_label_line_class_init (glLabelLineClass *klass)
85 {
86         GObjectClass *object_class = (GObjectClass *) klass;
87
88         parent_class = g_type_class_peek_parent (klass);
89
90         object_class->finalize = gl_label_line_finalize;
91 }
92
93 static void
94 gl_label_line_instance_init (glLabelLine *lline)
95 {
96         lline->private = g_new0 (glLabelLinePrivate, 1);
97 }
98
99 static void
100 gl_label_line_finalize (GObject *object)
101 {
102         glLabelLine *lline;
103
104         g_return_if_fail (object && GL_IS_LABEL_LINE (object));
105
106         lline = GL_LABEL_LINE (object);
107
108         g_free (lline->private);
109
110         G_OBJECT_CLASS (parent_class)->finalize (object);
111 }
112
113 /*****************************************************************************/
114 /* NEW label "line" object.                                               */
115 /*****************************************************************************/
116 GObject *
117 gl_label_line_new (glLabel *label)
118 {
119         glLabelLine *lline;
120
121         lline = g_object_new (gl_label_line_get_type(), NULL);
122
123         gl_label_object_set_parent (GL_LABEL_OBJECT(lline), label);
124
125         return G_OBJECT (lline);
126 }
127
128 /*****************************************************************************/
129 /* Duplicate object.                                                         */
130 /*****************************************************************************/
131 glLabelLine *
132 gl_label_line_dup (glLabelLine *lline,
133                       glLabel *label)
134 {
135         glLabelLine *new_lline;
136         gdouble        x, y, w, h, line_width;
137         guint          line_color;
138
139         gl_debug (DEBUG_LABEL, "START");
140
141         g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
142         g_return_if_fail (label && GL_IS_LABEL (label));
143
144         new_lline = GL_LABEL_LINE(gl_label_line_new (label));
145
146         gl_label_object_get_position (GL_LABEL_OBJECT(lline), &x, &y);
147         gl_label_object_get_size     (GL_LABEL_OBJECT(lline), &w, &h);
148
149         gl_label_object_set_position (GL_LABEL_OBJECT(new_lline),  x,  y);
150         gl_label_object_set_size     (GL_LABEL_OBJECT(new_lline),  w,  h);
151
152         line_width = gl_label_line_get_line_width (lline);
153         line_color = gl_label_line_get_line_color (lline);
154
155         gl_label_line_set_line_width (new_lline, line_width);
156         gl_label_line_set_line_color (new_lline, line_color);
157
158         gl_debug (DEBUG_LABEL, "END");
159
160         return new_lline;
161 }
162
163
164 /*****************************************************************************/
165 /* Set object params.                                                        */
166 /*****************************************************************************/
167 void
168 gl_label_line_set_line_width (glLabelLine *lline,
169                                  gdouble        line_width)
170 {
171         g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
172
173         if ( lline->private->line_width != line_width ) {
174                 lline->private->line_width = line_width;
175                 gl_label_object_emit_changed (GL_LABEL_OBJECT(lline));
176         }
177 }
178
179 void
180 gl_label_line_set_line_color (glLabelLine *lline,
181                                  guint          line_color)
182 {
183         g_return_if_fail (lline && GL_IS_LABEL_LINE (lline));
184
185         if ( lline->private->line_color != line_color ) {
186                 lline->private->line_color = line_color;
187                 gl_label_object_emit_changed (GL_LABEL_OBJECT(lline));
188         }
189 }
190
191
192 /*****************************************************************************/
193 /* Get object params.                                                        */
194 /*****************************************************************************/
195 gdouble
196 gl_label_line_get_line_width (glLabelLine *lline)
197 {
198         g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0.0);
199
200         return lline->private->line_width;
201 }
202
203 guint
204 gl_label_line_get_line_color (glLabelLine *lline)
205 {
206         g_return_val_if_fail (lline && GL_IS_LABEL_LINE (lline), 0);
207
208         return lline->private->line_color;
209 }
210