3 * Copyright (C) 2001-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "view-barcode.h"
25 #include <glib/gi18n.h>
29 #include "object-editor.h"
32 #include "pixmaps/cursor_barcode.xbm"
33 #include "pixmaps/cursor_barcode_mask.xbm"
38 /*========================================================*/
39 /* Private macros and constants. */
40 /*========================================================*/
43 /*========================================================*/
45 /*========================================================*/
47 struct _glViewBarcodePrivate {
51 /*========================================================*/
52 /* Private globals. */
53 /*========================================================*/
56 /*========================================================*/
57 /* Private function prototypes. */
58 /*========================================================*/
60 static void gl_view_barcode_finalize (GObject *object);
62 static GtkWidget *construct_properties_editor (glViewObject *view_object);
64 static void update_object_from_editor_cb (glObjectEditor *editor,
65 glLabelObject *object);
67 static void update_editor_from_object_cb (glLabelObject *object,
68 glObjectEditor *editor);
70 static void update_editor_from_move_cb (glLabelObject *object,
73 glObjectEditor *editor);
75 static gboolean object_at (glViewObject *view_object,
81 /*****************************************************************************/
82 /* Boilerplate object stuff. */
83 /*****************************************************************************/
84 G_DEFINE_TYPE (glViewBarcode, gl_view_barcode, GL_TYPE_VIEW_OBJECT);
88 gl_view_barcode_class_init (glViewBarcodeClass *class)
90 GObjectClass *object_class = G_OBJECT_CLASS (class);
91 glViewObjectClass *view_object_class = GL_VIEW_OBJECT_CLASS (class);
93 gl_debug (DEBUG_VIEW, "START");
95 gl_view_barcode_parent_class = g_type_class_peek_parent (class);
97 object_class->finalize = gl_view_barcode_finalize;
99 view_object_class->construct_editor = construct_properties_editor;
100 view_object_class->object_at = object_at;
102 gl_debug (DEBUG_VIEW, "END");
107 gl_view_barcode_init (glViewBarcode *view_barcode)
109 gl_debug (DEBUG_VIEW, "START");
111 view_barcode->priv = g_new0 (glViewBarcodePrivate, 1);
113 gl_debug (DEBUG_VIEW, "END");
118 gl_view_barcode_finalize (GObject *object)
120 glViewBarcode *view_barcode = GL_VIEW_BARCODE (object);
122 gl_debug (DEBUG_VIEW, "START");
124 g_return_if_fail (object && GL_IS_VIEW_BARCODE (object));
126 g_free (view_barcode->priv);
128 G_OBJECT_CLASS (gl_view_barcode_parent_class)->finalize (object);
130 gl_debug (DEBUG_VIEW, "END");
134 /*****************************************************************************/
135 /* NEW barcode object view. */
136 /*****************************************************************************/
138 gl_view_barcode_new (glLabelBarcode *object,
141 glViewBarcode *view_barcode;
143 gl_debug (DEBUG_VIEW, "START");
145 g_return_val_if_fail (object && GL_IS_LABEL_BARCODE (object), NULL);
146 g_return_val_if_fail (view && GL_IS_VIEW (view), NULL);
148 view_barcode = g_object_new (gl_view_barcode_get_type(), NULL);
150 gl_view_object_set_object (GL_VIEW_OBJECT(view_barcode),
151 GL_LABEL_OBJECT(object),
152 GL_VIEW_OBJECT_HANDLES_BOX);
153 gl_view_object_set_view (GL_VIEW_OBJECT(view_barcode), view);
155 gl_debug (DEBUG_VIEW, "END");
157 return GL_VIEW_OBJECT (view_barcode);
161 /*****************************************************************************/
162 /* Create a properties dialog for a barcode object. */
163 /*****************************************************************************/
165 construct_properties_editor (glViewObject *view_object)
168 glViewBarcode *view_bc = (glViewBarcode *)view_object;
169 glLabelObject *object;
171 gl_debug (DEBUG_VIEW, "START");
173 object = gl_view_object_get_object (GL_VIEW_OBJECT(view_bc));
176 editor = gl_object_editor_new (GL_STOCK_BARCODE, _("Barcode object properties"),
178 GL_OBJECT_EDITOR_POSITION_PAGE,
179 GL_OBJECT_EDITOR_SIZE_PAGE,
180 GL_OBJECT_EDITOR_BC_PAGE,
181 GL_OBJECT_EDITOR_DATA_PAGE,
185 update_editor_from_object_cb (object, GL_OBJECT_EDITOR(editor));
186 update_editor_from_move_cb (object, 0, 0, GL_OBJECT_EDITOR(editor));
188 /* Connect signals. */
189 g_signal_connect (G_OBJECT (editor), "changed",
190 G_CALLBACK(update_object_from_editor_cb), object);
191 g_signal_connect (G_OBJECT (object), "changed",
192 G_CALLBACK (update_editor_from_object_cb), editor);
193 g_signal_connect (G_OBJECT (object), "moved",
194 G_CALLBACK (update_editor_from_move_cb), editor);
196 gl_debug (DEBUG_VIEW, "END");
202 /*---------------------------------------------------------------------------*/
203 /* PRIVATE. editor "changed" callback. */
204 /*---------------------------------------------------------------------------*/
206 update_object_from_editor_cb (glObjectEditor *editor,
207 glLabelObject *object)
210 glTextNode *text_node;
212 gboolean text_flag, cs_flag;
213 glColorNode *color_node;
216 gl_debug (DEBUG_VIEW, "START");
218 g_signal_handlers_block_by_func (G_OBJECT(object),
219 update_editor_from_object_cb,
221 g_signal_handlers_block_by_func (G_OBJECT(object),
222 update_editor_from_move_cb,
226 gl_object_editor_get_position (editor, &x, &y);
227 gl_label_object_set_position (object, x, y);
229 gl_object_editor_get_size (editor, &w, &h);
230 gl_label_object_set_size (object, w, h);
232 text_node = gl_object_editor_get_data (editor);
233 gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node);
234 gl_text_node_free (&text_node);
236 gl_object_editor_get_bc_style (editor, &id, &text_flag, &cs_flag, &format_digits);
237 color_node = gl_object_editor_get_bc_color (editor);
238 gl_label_barcode_set_props (GL_LABEL_BARCODE(object),
239 id, text_flag, cs_flag, format_digits);
240 gl_label_object_set_line_color (object, color_node);
241 gl_color_node_free (&color_node);
244 g_signal_handlers_unblock_by_func (G_OBJECT(object),
245 update_editor_from_object_cb,
247 g_signal_handlers_unblock_by_func (G_OBJECT(object),
248 update_editor_from_move_cb,
251 gl_debug (DEBUG_VIEW, "END");
255 /*---------------------------------------------------------------------------*/
256 /* PRIVATE. label object "changed" callback. */
257 /*---------------------------------------------------------------------------*/
259 update_editor_from_object_cb (glLabelObject *object,
260 glObjectEditor *editor)
263 glTextNode *text_node;
265 gboolean text_flag, cs_flag;
266 glColorNode *color_node;
270 gl_debug (DEBUG_VIEW, "START");
272 gl_label_object_get_size (object, &w, &h);
273 gl_object_editor_set_size (editor, w, h);
275 merge = gl_label_get_merge (GL_LABEL(object->parent));
277 gl_label_barcode_get_props (GL_LABEL_BARCODE(object),
278 &id, &text_flag, &cs_flag, &format_digits);
279 color_node = gl_label_object_get_line_color (object);
280 gl_object_editor_set_bc_style (editor, id, text_flag, cs_flag, format_digits);
281 gl_object_editor_set_bc_color (editor, (merge != NULL), color_node);
282 gl_color_node_free (&color_node);
285 text_node = gl_label_barcode_get_data (GL_LABEL_BARCODE(object));
286 gl_object_editor_set_data (editor, (merge != NULL), text_node);
287 gl_text_node_free (&text_node);
290 gl_debug (DEBUG_VIEW, "END");
294 /*---------------------------------------------------------------------------*/
295 /* PRIVATE. label object "moved" callback. */
296 /*---------------------------------------------------------------------------*/
298 update_editor_from_move_cb (glLabelObject *object,
301 glObjectEditor *editor)
305 gl_debug (DEBUG_VIEW, "START");
307 gl_label_object_get_position (object, &x, &y);
308 gl_object_editor_set_position (editor, x, y);
310 gl_debug (DEBUG_VIEW, "END");
314 /*****************************************************************************/
315 /* Is object at (x,y)? */
316 /*****************************************************************************/
318 object_at (glViewObject *view_object,
323 glLabelObject *object;
326 object = gl_view_object_get_object (view_object);
328 gl_label_object_get_size (object, &w, &h);
330 cairo_rectangle (cr, 0.0, 0.0, w, h);
332 if (cairo_in_fill (cr, x, y))
341 /*****************************************************************************/
342 /* Return apropos cursor for create object mode. */
343 /*****************************************************************************/
345 gl_view_barcode_get_create_cursor (void)
347 GdkCursor *cursor = NULL;
348 GdkPixmap *pixmap_data, *pixmap_mask;
349 GdkColor fg = { 0, 0, 0, 0 };
350 GdkColor bg = { 0, 65535, 65535, 65535 };
352 gl_debug (DEBUG_VIEW, "START");
354 pixmap_data = gdk_bitmap_create_from_data (NULL,
355 (gchar *)cursor_barcode_bits,
356 cursor_barcode_width,
357 cursor_barcode_height);
358 pixmap_mask = gdk_bitmap_create_from_data (NULL,
359 (gchar *)cursor_barcode_mask_bits,
360 cursor_barcode_mask_width,
361 cursor_barcode_mask_height);
362 cursor = gdk_cursor_new_from_pixmap (pixmap_data, pixmap_mask, &fg,
363 &bg, cursor_barcode_x_hot,
364 cursor_barcode_y_hot);
366 gl_debug (DEBUG_VIEW, "END");
372 /*****************************************************************************/
373 /* Object creation handler: button press event. */
374 /*****************************************************************************/
376 gl_view_barcode_create_button_press_event (glView *view,
381 glTextNode *text_node;
382 glColorNode *line_color_node;
384 gl_view_unselect_all (view);
386 line_color_node = gl_color_node_new_default ();
388 object = gl_label_barcode_new (view->label);
389 gl_label_object_set_position (GL_LABEL_OBJECT(object), x, y);
390 text_node = gl_text_node_new_from_text ("123456789");
391 gl_label_barcode_set_data (GL_LABEL_BARCODE(object), text_node);
392 line_color_node->color = gl_color_set_opacity (gl_view_get_default_line_color(view), 0.5);
393 gl_label_object_set_line_color (GL_LABEL_OBJECT(object),
396 gl_color_node_free (&line_color_node);
398 view->create_object = GL_LABEL_OBJECT (object);
404 /*****************************************************************************/
405 /* Object creation handler: motion event. */
406 /*****************************************************************************/
408 gl_view_barcode_create_motion_event (glView *view,
412 gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object), x, y);
416 /*****************************************************************************/
417 /* Object creation handler: button relesase event. */
418 /*****************************************************************************/
420 gl_view_barcode_create_button_release_event (glView *view,
424 glColorNode *line_color_node;
426 line_color_node = gl_color_node_new_default ();
428 gl_label_object_set_position (GL_LABEL_OBJECT(view->create_object), x, y);
429 line_color_node->color = gl_view_get_default_line_color(view);
430 gl_label_object_set_line_color (GL_LABEL_OBJECT(view->create_object), line_color_node);
431 gl_color_node_free (&line_color_node);
437 * Local Variables: -- emacs
439 * c-basic-offset: 8 -- emacs
440 * tab-width: 8 -- emacs
441 * indent-tabs-mode: nil -- emacs