2 * object-editor-text-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 "font-combo.h"
33 #include "font-util.h"
34 #include "field-button.h"
35 #include "builder-util.h"
37 #include "object-editor-private.h"
42 /*===========================================*/
44 /*===========================================*/
47 /*===========================================*/
48 /* Private data types */
49 /*===========================================*/
52 /*===========================================*/
54 /*===========================================*/
57 /*===========================================*/
58 /* Local function prototypes */
59 /*===========================================*/
61 static void align_toggle_cb (GtkToggleButton *toggle,
62 glObjectEditor *editor);
63 static void text_radio_toggled_cb (glObjectEditor *editor);
66 /*--------------------------------------------------------------------------*/
67 /* PRIVATE. Prepare size page. */
68 /*--------------------------------------------------------------------------*/
70 gl_object_editor_prepare_text_page (glObjectEditor *editor)
72 gl_debug (DEBUG_EDITOR, "START");
74 /* Extract widgets from XML tree. */
75 gl_builder_util_get_widgets (editor->priv->builder,
76 "text_page_vbox", &editor->priv->text_page_vbox,
77 "text_family_hbox", &editor->priv->text_family_hbox,
78 "text_size_spin", &editor->priv->text_size_spin,
79 "text_bold_toggle", &editor->priv->text_bold_toggle,
80 "text_italic_toggle", &editor->priv->text_italic_toggle,
81 "text_color_hbox", &editor->priv->text_color_hbox,
82 "text_color_radio", &editor->priv->text_color_radio,
83 "text_color_key_radio", &editor->priv->text_color_key_radio,
84 "text_color_key_hbox", &editor->priv->text_color_key_hbox,
85 "text_left_toggle", &editor->priv->text_left_toggle,
86 "text_center_toggle", &editor->priv->text_center_toggle,
87 "text_right_toggle", &editor->priv->text_right_toggle,
88 "text_line_spacing_spin", &editor->priv->text_line_spacing_spin,
89 "text_auto_shrink_check", &editor->priv->text_auto_shrink_check,
92 editor->priv->text_family_combo = gl_font_combo_new ("Sans");
93 gtk_box_pack_start (GTK_BOX (editor->priv->text_family_hbox),
94 editor->priv->text_family_combo,
97 editor->priv->text_color_combo = gl_color_combo_new (_("Default"),
98 GL_COLOR_TEXT_DEFAULT,
99 gl_prefs_model_get_default_text_color (gl_prefs));
100 gtk_box_pack_start (GTK_BOX (editor->priv->text_color_hbox),
101 editor->priv->text_color_combo,
104 editor->priv->text_color_key_combo = gl_field_button_new (NULL);
105 gtk_box_pack_start (GTK_BOX (editor->priv->text_color_key_hbox),
106 editor->priv->text_color_key_combo,
111 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio), TRUE);
112 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
113 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
116 gtk_widget_show_all (editor->priv->text_page_vbox);
118 /* Connect signals */
119 g_signal_connect_swapped (G_OBJECT (editor->priv->text_family_combo),
121 G_CALLBACK (gl_object_editor_changed_cb),
123 g_signal_connect_swapped (G_OBJECT (editor->priv->text_size_spin),
125 G_CALLBACK (gl_object_editor_changed_cb),
127 g_signal_connect_swapped (G_OBJECT (editor->priv->text_bold_toggle),
129 G_CALLBACK (gl_object_editor_changed_cb),
131 g_signal_connect_swapped (G_OBJECT (editor->priv->text_italic_toggle),
133 G_CALLBACK (gl_object_editor_changed_cb),
135 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_combo),
137 G_CALLBACK (gl_object_editor_changed_cb),
139 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_combo),
141 G_CALLBACK (gl_object_editor_changed_cb),
143 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_radio),
145 G_CALLBACK (text_radio_toggled_cb),
147 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_radio),
149 G_CALLBACK (text_radio_toggled_cb),
152 g_signal_connect (G_OBJECT (editor->priv->text_left_toggle),
154 G_CALLBACK (align_toggle_cb),
156 g_signal_connect (G_OBJECT (editor->priv->text_center_toggle),
158 G_CALLBACK (align_toggle_cb),
160 g_signal_connect (G_OBJECT (editor->priv->text_right_toggle),
162 G_CALLBACK (align_toggle_cb),
165 g_signal_connect_swapped (G_OBJECT (editor->priv->text_line_spacing_spin),
167 G_CALLBACK (gl_object_editor_changed_cb),
170 g_signal_connect_swapped (G_OBJECT (editor->priv->text_auto_shrink_check),
172 G_CALLBACK (gl_object_editor_changed_cb),
175 gl_debug (DEBUG_EDITOR, "END");
179 /*--------------------------------------------------------------------------*/
180 /* PRIVATE. Alignment togglebutton callback. */
181 /*--------------------------------------------------------------------------*/
183 align_toggle_cb (GtkToggleButton *toggle,
184 glObjectEditor *editor)
186 if (editor->priv->stop_signals) return;
188 if (gtk_toggle_button_get_active (toggle)) {
190 if (GTK_WIDGET (toggle) == GTK_WIDGET (editor->priv->text_left_toggle)) {
191 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
192 (editor->priv->text_center_toggle),
194 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
195 (editor->priv->text_right_toggle),
197 } else if (GTK_WIDGET (toggle) ==
198 GTK_WIDGET (editor->priv->text_center_toggle)) {
199 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
200 (editor->priv->text_left_toggle),
202 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
203 (editor->priv->text_right_toggle),
205 } else if (GTK_WIDGET (toggle) ==
206 GTK_WIDGET (editor->priv->text_right_toggle)) {
207 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
208 (editor->priv->text_left_toggle),
210 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
211 (editor->priv->text_center_toggle),
215 gl_object_editor_changed_cb (editor);
221 /*****************************************************************************/
222 /* Set font family. */
223 /*****************************************************************************/
225 gl_object_editor_set_font_family (glObjectEditor *editor,
226 const gchar *font_family)
228 gchar *old_font_family;
230 if (font_family == NULL)
235 gl_debug (DEBUG_EDITOR, "START");
237 editor->priv->stop_signals = TRUE;
239 old_font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
241 if ( !old_font_family || g_utf8_collate( old_font_family, font_family ) )
243 gl_font_combo_set_family (GL_FONT_COMBO (editor->priv->text_family_combo),
247 g_free (old_font_family);
249 editor->priv->stop_signals = FALSE;
251 gl_debug (DEBUG_EDITOR, "END");
255 /*****************************************************************************/
256 /* Query font family. */
257 /*****************************************************************************/
259 gl_object_editor_get_font_family (glObjectEditor *editor)
263 gl_debug (DEBUG_EDITOR, "START");
265 font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
267 gl_debug (DEBUG_EDITOR, "END");
273 /*****************************************************************************/
275 /*****************************************************************************/
277 gl_object_editor_set_font_size (glObjectEditor *editor,
280 gl_debug (DEBUG_EDITOR, "START");
282 editor->priv->stop_signals = TRUE;
284 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_size_spin),
287 editor->priv->stop_signals = FALSE;
289 gl_debug (DEBUG_EDITOR, "END");
293 /*****************************************************************************/
294 /* Query font size. */
295 /*****************************************************************************/
297 gl_object_editor_get_font_size (glObjectEditor *editor)
301 gl_debug (DEBUG_EDITOR, "START");
304 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_size_spin));
306 gl_debug (DEBUG_EDITOR, "END");
312 /*****************************************************************************/
313 /* Set font weight. */
314 /*****************************************************************************/
316 gl_object_editor_set_font_weight (glObjectEditor *editor,
317 PangoWeight font_weight)
319 gl_debug (DEBUG_EDITOR, "START");
321 editor->priv->stop_signals = TRUE;
323 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle),
324 (font_weight == PANGO_WEIGHT_BOLD));
326 editor->priv->stop_signals = FALSE;
328 gl_debug (DEBUG_EDITOR, "END");
332 /*****************************************************************************/
333 /* Query font weight. */
334 /*****************************************************************************/
336 gl_object_editor_get_font_weight (glObjectEditor *editor)
338 PangoWeight font_weight;
340 gl_debug (DEBUG_EDITOR, "START");
342 if (gtk_toggle_button_get_active
343 (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle))) {
344 font_weight = PANGO_WEIGHT_BOLD;
346 font_weight = PANGO_WEIGHT_NORMAL;
349 gl_debug (DEBUG_EDITOR, "END");
355 /*****************************************************************************/
356 /* Set font italic flag. */
357 /*****************************************************************************/
359 gl_object_editor_set_font_italic_flag (glObjectEditor *editor,
360 gboolean font_italic_flag)
362 gl_debug (DEBUG_EDITOR, "START");
364 editor->priv->stop_signals = TRUE;
366 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_italic_toggle),
369 editor->priv->stop_signals = FALSE;
371 gl_debug (DEBUG_EDITOR, "END");
375 /*****************************************************************************/
376 /* Query font italic flag. */
377 /*****************************************************************************/
379 gl_object_editor_get_font_italic_flag (glObjectEditor *editor)
381 gboolean italic_flag;
383 gl_debug (DEBUG_EDITOR, "START");
386 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
387 (editor->priv->text_italic_toggle));
389 gl_debug (DEBUG_EDITOR, "END");
395 /*****************************************************************************/
396 /* Set text alignment. */
397 /*****************************************************************************/
399 gl_object_editor_set_text_alignment (glObjectEditor *editor,
400 PangoAlignment align)
402 gl_debug (DEBUG_EDITOR, "START");
404 editor->priv->stop_signals = TRUE;
406 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle),
407 (align == PANGO_ALIGN_LEFT));
408 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle),
409 (align == PANGO_ALIGN_CENTER));
410 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle),
411 (align == PANGO_ALIGN_RIGHT));
413 editor->priv->stop_signals = FALSE;
415 gl_debug (DEBUG_EDITOR, "END");
419 /*****************************************************************************/
420 /* Query text alignment. */
421 /*****************************************************************************/
423 gl_object_editor_get_text_alignment (glObjectEditor *editor)
425 PangoAlignment align;
427 gl_debug (DEBUG_EDITOR, "START");
429 if (gtk_toggle_button_get_active
430 (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle))) {
431 align = PANGO_ALIGN_LEFT;
433 if (gtk_toggle_button_get_active
434 (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle))) {
435 align = PANGO_ALIGN_RIGHT;
437 if (gtk_toggle_button_get_active
438 (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle))) {
439 align = PANGO_ALIGN_CENTER;
441 align = PANGO_ALIGN_LEFT; /* Should not happen. */
444 gl_debug (DEBUG_EDITOR, "END");
450 /*****************************************************************************/
451 /* Set text color. */
452 /*****************************************************************************/
454 gl_object_editor_set_text_color (glObjectEditor *editor,
456 glColorNode *text_color_node)
458 gl_debug (DEBUG_EDITOR, "START");
460 if (text_color_node == NULL)
465 editor->priv->stop_signals = TRUE;
467 gl_debug (DEBUG_EDITOR, "color field %s(%d) / %X", text_color_node->key, text_color_node->field_flag, text_color_node->color);
469 gtk_widget_set_sensitive (editor->priv->text_color_key_radio, merge_flag);
471 if ( text_color_node->color == GL_COLOR_NONE ) {
473 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->text_color_combo));
477 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
478 text_color_node->color);
481 if (!text_color_node->field_flag || !merge_flag) {
482 gl_debug (DEBUG_EDITOR, "color field false");
483 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
484 (editor->priv->text_color_radio), TRUE);
485 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
486 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
489 gl_debug (DEBUG_EDITOR, "color field true");
490 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
491 (editor->priv->text_color_key_radio), TRUE);
492 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
493 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
495 gl_field_button_set_key (GL_FIELD_BUTTON (editor->priv->text_color_key_combo), "");
498 editor->priv->stop_signals = FALSE;
500 gl_debug (DEBUG_EDITOR, "END");
504 /*****************************************************************************/
505 /* Query text color. */
506 /*****************************************************************************/
508 gl_object_editor_get_text_color (glObjectEditor *editor)
511 glColorNode *color_node;
514 gl_debug (DEBUG_EDITOR, "START");
516 color_node = gl_color_node_new_default ();
518 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_key_radio))) {
519 color_node->field_flag = TRUE;
520 color_node->color = gl_prefs_model_get_default_text_color (gl_prefs);
522 gl_field_button_get_key (GL_FIELD_BUTTON (editor->priv->text_color_key_combo));
524 color_node->field_flag = FALSE;
525 color_node->key = NULL;
526 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
530 color_node->color = gl_prefs_model_get_default_text_color (gl_prefs);
532 color_node->color = color;
536 gl_debug (DEBUG_EDITOR, "END");
542 /*****************************************************************************/
543 /* Set text line spacing. */
544 /*****************************************************************************/
546 gl_object_editor_set_text_line_spacing (glObjectEditor *editor,
547 gdouble text_line_spacing)
549 gl_debug (DEBUG_EDITOR, "START");
551 editor->priv->stop_signals = TRUE;
553 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_line_spacing_spin),
556 editor->priv->stop_signals = FALSE;
558 gl_debug (DEBUG_EDITOR, "END");
562 /*****************************************************************************/
563 /* Query text line spacing. */
564 /*****************************************************************************/
566 gl_object_editor_get_text_line_spacing (glObjectEditor *editor)
568 gdouble text_line_spacing;
570 gl_debug (DEBUG_EDITOR, "START");
573 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_line_spacing_spin));
575 gl_debug (DEBUG_EDITOR, "END");
577 return text_line_spacing;
581 /*****************************************************************************/
582 /* Set auto shrink checkbox. */
583 /*****************************************************************************/
585 gl_object_editor_set_text_auto_shrink (glObjectEditor *editor,
586 gboolean auto_shrink)
588 gl_debug (DEBUG_EDITOR, "START");
590 editor->priv->stop_signals = TRUE;
592 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check),
595 editor->priv->stop_signals = FALSE;
597 gl_debug (DEBUG_EDITOR, "END");
601 /*****************************************************************************/
602 /* Query auto shrink checkbox. */
603 /*****************************************************************************/
604 gboolean gl_object_editor_get_text_auto_shrink (glObjectEditor *editor)
606 gboolean auto_shrink;
608 gl_debug (DEBUG_EDITOR, "START");
611 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check));
613 gl_debug (DEBUG_EDITOR, "END");
619 /*--------------------------------------------------------------------------*/
620 /* PRIVATE. color radio callback. */
621 /*--------------------------------------------------------------------------*/
623 text_radio_toggled_cb (glObjectEditor *editor)
625 if (editor->priv->stop_signals) return;
627 gl_debug (DEBUG_EDITOR, "START");
629 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio))) {
630 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
631 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
633 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
634 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
638 gl_object_editor_changed_cb (editor);
640 gl_debug (DEBUG_EDITOR, "END");
646 * Local Variables: -- emacs
648 * c-basic-offset: 8 -- emacs
649 * tab-width: 8 -- emacs
650 * indent-tabs-mode: nil -- emacs