2 * object-editor-data-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>
31 #include "field-button.h"
32 #include "builder-util.h"
34 #include "object-editor-private.h"
39 /*===========================================*/
41 /*===========================================*/
44 /*===========================================*/
45 /* Private data types */
46 /*===========================================*/
49 /*===========================================*/
51 /*===========================================*/
54 /*===========================================*/
55 /* Local function prototypes */
56 /*===========================================*/
58 static void data_radio_toggled_cb (glObjectEditor *editor);
61 /*--------------------------------------------------------------------------*/
62 /* PRIVATE. Prepare data page. */
63 /*--------------------------------------------------------------------------*/
65 gl_object_editor_prepare_data_page (glObjectEditor *editor)
67 gl_debug (DEBUG_EDITOR, "START");
69 /* Extract widgets from XML tree. */
70 gl_builder_util_get_widgets (editor->priv->builder,
71 "data_page_vbox", &editor->priv->data_page_vbox,
72 "data_literal_radio", &editor->priv->data_literal_radio,
73 "data_key_radio", &editor->priv->data_key_radio,
74 "data_text_entry", &editor->priv->data_text_entry,
75 "data_key_hbox", &editor->priv->data_key_hbox,
78 editor->priv->data_key_combo = gl_field_button_new (NULL);
79 gtk_box_pack_start (GTK_BOX (editor->priv->data_key_hbox),
80 editor->priv->data_key_combo,
84 gtk_widget_show_all (editor->priv->data_page_vbox);
87 g_signal_connect_swapped (G_OBJECT (editor->priv->data_text_entry),
89 G_CALLBACK (gl_object_editor_changed_cb),
91 g_signal_connect_swapped (G_OBJECT (editor->priv->data_key_combo),
93 G_CALLBACK (gl_object_editor_changed_cb),
95 g_signal_connect_swapped (G_OBJECT (editor->priv->data_literal_radio),
97 G_CALLBACK (data_radio_toggled_cb),
99 g_signal_connect_swapped (G_OBJECT (editor->priv->data_key_radio),
101 G_CALLBACK (data_radio_toggled_cb),
104 gl_debug (DEBUG_EDITOR, "END");
108 /*--------------------------------------------------------------------------*/
109 /* PRIVATE. data radio callback. */
110 /*--------------------------------------------------------------------------*/
112 data_radio_toggled_cb (glObjectEditor *editor)
114 gl_debug (DEBUG_WDGT, "START");
116 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->data_literal_radio))) {
117 gtk_widget_set_sensitive (editor->priv->data_text_entry, TRUE);
118 gtk_widget_set_sensitive (editor->priv->data_key_combo, FALSE);
119 gtk_widget_set_sensitive (editor->priv->data_format_label, FALSE);
120 gtk_widget_set_sensitive (editor->priv->data_ex_label, FALSE);
121 gtk_widget_set_sensitive (editor->priv->data_digits_label, FALSE);
122 gtk_widget_set_sensitive (editor->priv->data_digits_spin, FALSE);
124 gtk_widget_set_sensitive (editor->priv->data_text_entry, FALSE);
125 gtk_widget_set_sensitive (editor->priv->data_key_combo, TRUE);
126 gtk_widget_set_sensitive (editor->priv->data_format_label, TRUE);
127 gtk_widget_set_sensitive (editor->priv->data_ex_label, TRUE);
128 gtk_widget_set_sensitive (editor->priv->data_digits_label,
129 !editor->priv->data_format_fixed_flag);
130 gtk_widget_set_sensitive (editor->priv->data_digits_spin,
131 !editor->priv->data_format_fixed_flag);
134 gl_object_editor_changed_cb (editor);
136 gl_debug (DEBUG_WDGT, "END");
140 /*****************************************************************************/
142 /*****************************************************************************/
144 gl_object_editor_set_data (glObjectEditor *editor,
146 glTextNode *text_node)
150 gl_debug (DEBUG_EDITOR, "START");
153 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->data_literal_radio),
154 data_radio_toggled_cb, editor);
155 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->data_key_radio),
156 data_radio_toggled_cb, editor);
157 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->data_text_entry),
158 gl_object_editor_changed_cb, editor);
159 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->data_key_combo),
160 gl_object_editor_changed_cb, editor);
163 gtk_widget_set_sensitive (editor->priv->data_key_radio, merge_flag);
165 if (!text_node->field_flag || !merge_flag)
167 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
168 (editor->priv->data_literal_radio), TRUE);
169 gtk_widget_set_sensitive (editor->priv->data_text_entry, TRUE);
170 gtk_widget_set_sensitive (editor->priv->data_key_combo, FALSE);
171 gtk_widget_set_sensitive (editor->priv->data_format_label, FALSE);
172 gtk_widget_set_sensitive (editor->priv->data_ex_label, FALSE);
173 gtk_widget_set_sensitive (editor->priv->data_digits_spin, FALSE);
174 gtk_widget_set_sensitive (editor->priv->data_digits_label, FALSE);
176 gtk_editable_delete_text (GTK_EDITABLE (editor->priv->data_text_entry), 0, -1);
178 if (text_node->data != NULL )
180 gtk_editable_insert_text (GTK_EDITABLE (editor->priv->data_text_entry),
182 strlen (text_node->data),
188 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
189 (editor->priv->data_key_radio), TRUE);
191 gtk_widget_set_sensitive (editor->priv->data_text_entry, FALSE);
192 gtk_widget_set_sensitive (editor->priv->data_key_combo, TRUE);
193 gtk_widget_set_sensitive (editor->priv->data_format_label, TRUE);
194 gtk_widget_set_sensitive (editor->priv->data_ex_label, TRUE);
195 gtk_widget_set_sensitive (editor->priv->data_digits_label,
196 !editor->priv->data_format_fixed_flag);
197 gtk_widget_set_sensitive (editor->priv->data_digits_spin,
198 !editor->priv->data_format_fixed_flag);
201 gl_field_button_set_key (GL_FIELD_BUTTON (editor->priv->data_key_combo),
206 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->data_literal_radio),
207 data_radio_toggled_cb, editor);
208 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->data_key_radio),
209 data_radio_toggled_cb, editor);
210 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->data_text_entry),
211 gl_object_editor_changed_cb, editor);
212 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->data_key_combo),
213 gl_object_editor_changed_cb, editor);
216 gl_debug (DEBUG_EDITOR, "END");
220 /*****************************************************************************/
222 /*****************************************************************************/
224 gl_object_editor_get_data (glObjectEditor *editor)
226 glTextNode *text_node;
228 gl_debug (DEBUG_EDITOR, "START");
230 text_node = g_new0(glTextNode,1);
232 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->data_literal_radio)))
234 text_node->field_flag = FALSE;
236 gtk_editable_get_chars (GTK_EDITABLE (editor->priv->data_text_entry), 0, -1);
240 text_node->field_flag = TRUE;
242 gl_field_button_get_key (GL_FIELD_BUTTON (editor->priv->data_key_combo));
245 gl_debug (DEBUG_EDITOR, "text_node: field_flag=%d, data=%s",
246 text_node->field_flag, text_node->data);
248 gl_debug (DEBUG_EDITOR, "END");
256 * Local Variables: -- emacs
258 * c-basic-offset: 8 -- emacs
259 * tab-width: 8 -- emacs
260 * indent-tabs-mode: nil -- emacs