2 * object-editor-bc-page.c
3 * Copyright (C) 2003-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 "object-editor.h"
25 #include <glib/gi18n.h>
30 #include "color-combo.h"
32 #include "combo-util.h"
33 #include "builder-util.h"
35 #include "object-editor-private.h"
40 /*===========================================*/
42 /*===========================================*/
45 /*===========================================*/
46 /* Private data types */
47 /*===========================================*/
50 /*===========================================*/
52 /*===========================================*/
55 /*===========================================*/
56 /* Local function prototypes */
57 /*===========================================*/
59 static void style_changed_cb (glObjectEditor *editor);
60 static void bc_radio_toggled_cb (glObjectEditor *editor);
63 /*--------------------------------------------------------------------------*/
64 /* PRIVATE. Prepare size page. */
65 /*--------------------------------------------------------------------------*/
67 gl_object_editor_prepare_bc_page (glObjectEditor *editor)
71 gl_debug (DEBUG_EDITOR, "START");
73 /* Extract widgets from XML tree. */
74 gl_builder_util_get_widgets (editor->priv->builder,
75 "bc_page_vbox", &editor->priv->bc_page_vbox,
76 "bc_style_combo", &editor->priv->bc_style_combo,
77 "bc_text_check", &editor->priv->bc_text_check,
78 "bc_cs_check", &editor->priv->bc_cs_check,
79 "bc_color_hbox", &editor->priv->bc_color_hbox,
80 "bc_key_combo", &editor->priv->bc_key_combo,
81 "bc_key_radio", &editor->priv->bc_key_radio,
82 "bc_color_radio", &editor->priv->bc_color_radio,
83 "data_format_label", &editor->priv->data_format_label,
84 "data_ex_label", &editor->priv->data_ex_label,
85 "data_digits_label", &editor->priv->data_digits_label,
86 "data_digits_spin", &editor->priv->data_digits_spin,
89 editor->priv->data_format_fixed_flag = FALSE;
91 editor->priv->bc_color_combo = gl_color_combo_new (_("Default"),
93 gl_prefs_model_get_default_line_color (gl_prefs));
94 gtk_box_pack_start (GTK_BOX (editor->priv->bc_color_hbox),
95 editor->priv->bc_color_combo,
98 gl_combo_util_add_text_model ( GTK_COMBO_BOX(editor->priv->bc_style_combo));
99 gl_combo_util_add_text_model ( GTK_COMBO_BOX(editor->priv->bc_key_combo));
101 /* Load barcode styles */
102 styles = gl_barcode_get_styles_list ();
103 gl_combo_util_set_strings (GTK_COMBO_BOX(editor->priv->bc_style_combo),
105 gl_barcode_free_styles_list (styles);
108 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->bc_color_radio), TRUE);
109 gtk_widget_set_sensitive (editor->priv->bc_color_combo, TRUE);
110 gtk_widget_set_sensitive (editor->priv->bc_key_combo, FALSE);
113 gtk_widget_show_all (editor->priv->bc_page_vbox);
115 /* Connect signals */
116 g_signal_connect_swapped (G_OBJECT (editor->priv->bc_style_combo),
118 G_CALLBACK (style_changed_cb),
120 g_signal_connect_swapped (G_OBJECT (editor->priv->bc_text_check),
122 G_CALLBACK (gl_object_editor_changed_cb),
124 g_signal_connect_swapped (G_OBJECT (editor->priv->bc_cs_check),
126 G_CALLBACK (gl_object_editor_changed_cb),
128 g_signal_connect_swapped (G_OBJECT (editor->priv->bc_color_combo),
130 G_CALLBACK (gl_object_editor_changed_cb),
132 g_signal_connect_swapped (G_OBJECT (editor->priv->bc_key_combo),
134 G_CALLBACK (gl_object_editor_changed_cb),
136 g_signal_connect_swapped (G_OBJECT (editor->priv->bc_color_radio),
138 G_CALLBACK (bc_radio_toggled_cb),
140 g_signal_connect_swapped (G_OBJECT (editor->priv->bc_key_radio),
142 G_CALLBACK (bc_radio_toggled_cb),
144 g_signal_connect_swapped (G_OBJECT (editor->priv->data_digits_spin),
146 G_CALLBACK (gl_object_editor_changed_cb),
149 gl_debug (DEBUG_EDITOR, "END");
153 /*--------------------------------------------------------------------------*/
154 /* PRIVATE. Callback for when style has changed. */
155 /*--------------------------------------------------------------------------*/
157 style_changed_cb (glObjectEditor *editor)
159 gchar *style_string = NULL;
161 gchar *ex_string = NULL;
164 if (editor->priv->stop_signals) return;
167 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->bc_style_combo));
169 /* Don't emit if entry is empty. */
170 if ( *style_string != 0 ) {
171 id = gl_barcode_name_to_id (style_string);
173 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(editor->priv->bc_text_check),
174 gl_barcode_can_text (id));
175 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(editor->priv->bc_cs_check),
176 gl_barcode_can_csum (id));
178 gtk_widget_set_sensitive (editor->priv->bc_text_check,
179 gl_barcode_text_optional (id));
180 gtk_widget_set_sensitive (editor->priv->bc_cs_check,
181 gl_barcode_csum_optional (id));
183 editor->priv->data_format_fixed_flag = !gl_barcode_can_freeform (id);
184 digits = gtk_spin_button_get_value (GTK_SPIN_BUTTON (editor->priv->data_digits_spin));
185 if (editor->priv->data_format_fixed_flag) {
186 digits = gl_barcode_get_prefered_n(id);
187 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->data_digits_spin),
191 ex_string = gl_barcode_default_digits (id, digits);
192 gtk_label_set_text (GTK_LABEL(editor->priv->data_ex_label), ex_string);
194 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->data_literal_radio))) {
195 gtk_widget_set_sensitive (editor->priv->data_format_label, FALSE);
196 gtk_widget_set_sensitive (editor->priv->data_ex_label, FALSE);
197 gtk_widget_set_sensitive (editor->priv->data_digits_label, FALSE);
198 gtk_widget_set_sensitive (editor->priv->data_digits_spin, FALSE);
200 gtk_widget_set_sensitive (editor->priv->data_format_label, TRUE);
201 gtk_widget_set_sensitive (editor->priv->data_ex_label, TRUE);
202 gtk_widget_set_sensitive (editor->priv->data_digits_label,
203 !editor->priv->data_format_fixed_flag);
204 gtk_widget_set_sensitive (editor->priv->data_digits_spin,
205 !editor->priv->data_format_fixed_flag);
208 /* Emit our "changed" signal */
209 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
212 g_free (style_string);
217 /*****************************************************************************/
218 /* Set barcode style. */
219 /*****************************************************************************/
221 gl_object_editor_set_bc_style (glObjectEditor *editor,
224 gboolean checksum_flag,
227 const gchar *style_string;
230 gl_debug (DEBUG_EDITOR, "START");
232 editor->priv->stop_signals = TRUE;
234 style_string = gl_barcode_id_to_name (id);
236 gl_combo_util_set_active_text (GTK_COMBO_BOX (editor->priv->bc_style_combo),
239 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->bc_text_check),
242 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->bc_cs_check),
245 gtk_widget_set_sensitive (editor->priv->bc_text_check,
246 gl_barcode_text_optional (id));
247 gtk_widget_set_sensitive (editor->priv->bc_cs_check,
248 gl_barcode_csum_optional (id));
250 editor->priv->data_format_fixed_flag = !gl_barcode_can_freeform (id);
252 if (editor->priv->data_format_fixed_flag) {
253 format_digits = gl_barcode_get_prefered_n (id);
256 ex_string = gl_barcode_default_digits (id, format_digits);
257 gtk_label_set_text (GTK_LABEL(editor->priv->data_ex_label), ex_string);
260 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->data_digits_spin),
263 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->data_literal_radio))) {
264 gtk_widget_set_sensitive (editor->priv->data_format_label, FALSE);
265 gtk_widget_set_sensitive (editor->priv->data_ex_label, FALSE);
266 gtk_widget_set_sensitive (editor->priv->data_digits_label, FALSE);
267 gtk_widget_set_sensitive (editor->priv->data_digits_spin, FALSE);
269 gtk_widget_set_sensitive (editor->priv->data_format_label, TRUE);
270 gtk_widget_set_sensitive (editor->priv->data_ex_label, TRUE);
271 gtk_widget_set_sensitive (editor->priv->data_digits_label,
272 !editor->priv->data_format_fixed_flag);
273 gtk_widget_set_sensitive (editor->priv->data_digits_spin,
274 !editor->priv->data_format_fixed_flag);
277 editor->priv->stop_signals = FALSE;
279 gl_debug (DEBUG_EDITOR, "END");
283 /*****************************************************************************/
284 /* Query barcode style. */
285 /*****************************************************************************/
287 gl_object_editor_get_bc_style (glObjectEditor *editor,
290 gboolean *checksum_flag,
291 guint *format_digits)
295 gl_debug (DEBUG_EDITOR, "START");
298 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->bc_style_combo));
299 *id = g_strdup (gl_barcode_name_to_id (style_string));
302 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->bc_text_check));
305 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->bc_cs_check));
309 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->data_digits_spin));
311 g_free (style_string);
313 gl_debug (DEBUG_EDITOR, "END");
317 /*****************************************************************************/
319 /*****************************************************************************/
321 gl_object_editor_set_bc_color (glObjectEditor *editor,
323 glColorNode *color_node)
325 gl_debug (DEBUG_EDITOR, "START");
327 editor->priv->stop_signals = TRUE;
329 gtk_widget_set_sensitive (editor->priv->bc_key_radio, merge_flag);
331 if ( color_node->color == GL_COLOR_NONE ) {
333 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->bc_color_combo));
337 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->bc_color_combo),
341 if (!color_node->field_flag || !merge_flag) {
342 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
343 (editor->priv->bc_color_radio), TRUE);
344 gtk_widget_set_sensitive (editor->priv->bc_color_combo, TRUE);
345 gtk_widget_set_sensitive (editor->priv->bc_key_combo, FALSE);
348 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
349 (editor->priv->bc_key_radio), TRUE);
350 gtk_widget_set_sensitive (editor->priv->bc_color_combo, FALSE);
351 gtk_widget_set_sensitive (editor->priv->bc_key_combo, TRUE);
353 gl_combo_util_set_active_text (GTK_COMBO_BOX (editor->priv->bc_key_combo),
357 editor->priv->stop_signals = FALSE;
359 gl_debug (DEBUG_EDITOR, "END");
363 /*****************************************************************************/
364 /* Query bc color. */
365 /*****************************************************************************/
367 gl_object_editor_get_bc_color (glObjectEditor *editor)
370 glColorNode *color_node;
373 gl_debug (DEBUG_EDITOR, "START");
375 color_node = gl_color_node_new_default ();
377 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->bc_key_radio))) {
378 color_node->field_flag = TRUE;
379 color_node->color = gl_prefs_model_get_default_line_color (gl_prefs);
381 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->bc_key_combo));
383 color_node->field_flag = FALSE;
384 color_node->key = NULL;
385 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->bc_color_combo),
389 color_node->color = gl_prefs_model_get_default_line_color (gl_prefs);
391 color_node->color = color;
395 gl_debug (DEBUG_EDITOR, "END");
401 /*--------------------------------------------------------------------------*/
402 /* PRIVATE. barcode color radio callback. */
403 /*--------------------------------------------------------------------------*/
405 bc_radio_toggled_cb (glObjectEditor *editor)
407 if (editor->priv->stop_signals) return;
409 gl_debug (DEBUG_EDITOR, "START");
411 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->bc_color_radio))) {
412 gtk_widget_set_sensitive (editor->priv->bc_color_combo, TRUE);
413 gtk_widget_set_sensitive (editor->priv->bc_key_combo, FALSE);
415 gtk_widget_set_sensitive (editor->priv->bc_color_combo, FALSE);
416 gtk_widget_set_sensitive (editor->priv->bc_key_combo, TRUE);
420 /* Emit our "changed" signal */
421 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
423 gl_debug (DEBUG_EDITOR, "END");
429 * Local Variables: -- emacs
431 * c-basic-offset: 8 -- emacs
432 * tab-width: 8 -- emacs
433 * indent-tabs-mode: nil -- emacs