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 (gtk_toggle_button_get_active (toggle)) {
188 if (GTK_WIDGET (toggle) == GTK_WIDGET (editor->priv->text_left_toggle)) {
189 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
190 (editor->priv->text_center_toggle),
192 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
193 (editor->priv->text_right_toggle),
195 } else if (GTK_WIDGET (toggle) ==
196 GTK_WIDGET (editor->priv->text_center_toggle)) {
197 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
198 (editor->priv->text_left_toggle),
200 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
201 (editor->priv->text_right_toggle),
203 } else if (GTK_WIDGET (toggle) ==
204 GTK_WIDGET (editor->priv->text_right_toggle)) {
205 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
206 (editor->priv->text_left_toggle),
208 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
209 (editor->priv->text_center_toggle),
213 gl_object_editor_changed_cb (editor);
219 /*****************************************************************************/
220 /* Set font family. */
221 /*****************************************************************************/
223 gl_object_editor_set_font_family (glObjectEditor *editor,
224 const gchar *font_family)
226 gchar *old_font_family;
228 if (font_family == NULL)
233 gl_debug (DEBUG_EDITOR, "START");
236 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_family_combo),
237 gl_object_editor_changed_cb, editor);
240 old_font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
242 if ( !old_font_family || g_utf8_collate( old_font_family, font_family ) )
244 gl_font_combo_set_family (GL_FONT_COMBO (editor->priv->text_family_combo),
248 g_free (old_font_family);
251 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_family_combo),
252 gl_object_editor_changed_cb, editor);
255 gl_debug (DEBUG_EDITOR, "END");
259 /*****************************************************************************/
260 /* Query font family. */
261 /*****************************************************************************/
263 gl_object_editor_get_font_family (glObjectEditor *editor)
267 gl_debug (DEBUG_EDITOR, "START");
269 font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
271 gl_debug (DEBUG_EDITOR, "END");
277 /*****************************************************************************/
279 /*****************************************************************************/
281 gl_object_editor_set_font_size (glObjectEditor *editor,
284 gl_debug (DEBUG_EDITOR, "START");
287 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_size_spin),
288 gl_object_editor_changed_cb, editor);
291 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_size_spin),
295 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_size_spin),
296 gl_object_editor_changed_cb, editor);
299 gl_debug (DEBUG_EDITOR, "END");
303 /*****************************************************************************/
304 /* Query font size. */
305 /*****************************************************************************/
307 gl_object_editor_get_font_size (glObjectEditor *editor)
311 gl_debug (DEBUG_EDITOR, "START");
314 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_size_spin));
316 gl_debug (DEBUG_EDITOR, "END");
322 /*****************************************************************************/
323 /* Set font weight. */
324 /*****************************************************************************/
326 gl_object_editor_set_font_weight (glObjectEditor *editor,
327 PangoWeight font_weight)
329 gl_debug (DEBUG_EDITOR, "START");
332 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_bold_toggle),
333 gl_object_editor_changed_cb, editor);
336 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle),
337 (font_weight == PANGO_WEIGHT_BOLD));
340 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_bold_toggle),
341 gl_object_editor_changed_cb, editor);
344 gl_debug (DEBUG_EDITOR, "END");
348 /*****************************************************************************/
349 /* Query font weight. */
350 /*****************************************************************************/
352 gl_object_editor_get_font_weight (glObjectEditor *editor)
354 PangoWeight font_weight;
356 gl_debug (DEBUG_EDITOR, "START");
358 if (gtk_toggle_button_get_active
359 (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle))) {
360 font_weight = PANGO_WEIGHT_BOLD;
362 font_weight = PANGO_WEIGHT_NORMAL;
365 gl_debug (DEBUG_EDITOR, "END");
371 /*****************************************************************************/
372 /* Set font italic flag. */
373 /*****************************************************************************/
375 gl_object_editor_set_font_italic_flag (glObjectEditor *editor,
376 gboolean font_italic_flag)
378 gl_debug (DEBUG_EDITOR, "START");
381 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_italic_toggle),
382 gl_object_editor_changed_cb, editor);
385 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_italic_toggle),
389 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_italic_toggle),
390 gl_object_editor_changed_cb, editor);
393 gl_debug (DEBUG_EDITOR, "END");
397 /*****************************************************************************/
398 /* Query font italic flag. */
399 /*****************************************************************************/
401 gl_object_editor_get_font_italic_flag (glObjectEditor *editor)
403 gboolean italic_flag;
405 gl_debug (DEBUG_EDITOR, "START");
408 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
409 (editor->priv->text_italic_toggle));
411 gl_debug (DEBUG_EDITOR, "END");
417 /*****************************************************************************/
418 /* Set text alignment. */
419 /*****************************************************************************/
421 gl_object_editor_set_text_alignment (glObjectEditor *editor,
422 PangoAlignment align)
424 gl_debug (DEBUG_EDITOR, "START");
427 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_left_toggle), align_toggle_cb, editor);
428 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_center_toggle), align_toggle_cb, editor);
429 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_right_toggle), align_toggle_cb, editor);
432 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle),
433 (align == PANGO_ALIGN_LEFT));
434 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle),
435 (align == PANGO_ALIGN_CENTER));
436 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle),
437 (align == PANGO_ALIGN_RIGHT));
440 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_left_toggle), align_toggle_cb, editor);
441 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_center_toggle), align_toggle_cb, editor);
442 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_right_toggle), align_toggle_cb, editor);
445 gl_debug (DEBUG_EDITOR, "END");
449 /*****************************************************************************/
450 /* Query text alignment. */
451 /*****************************************************************************/
453 gl_object_editor_get_text_alignment (glObjectEditor *editor)
455 PangoAlignment align;
457 gl_debug (DEBUG_EDITOR, "START");
459 if (gtk_toggle_button_get_active
460 (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle))) {
461 align = PANGO_ALIGN_LEFT;
463 if (gtk_toggle_button_get_active
464 (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle))) {
465 align = PANGO_ALIGN_RIGHT;
467 if (gtk_toggle_button_get_active
468 (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle))) {
469 align = PANGO_ALIGN_CENTER;
471 align = PANGO_ALIGN_LEFT; /* Should not happen. */
474 gl_debug (DEBUG_EDITOR, "END");
480 /*****************************************************************************/
481 /* Set text color. */
482 /*****************************************************************************/
484 gl_object_editor_set_text_color (glObjectEditor *editor,
486 glColorNode *text_color_node)
488 gl_debug (DEBUG_EDITOR, "START");
490 if (text_color_node == NULL)
496 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_color_combo),
497 gl_object_editor_changed_cb, editor);
498 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_color_radio),
499 text_radio_toggled_cb, editor);
500 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_color_key_radio),
501 text_radio_toggled_cb, editor);
502 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_color_key_combo),
503 gl_object_editor_changed_cb, editor);
506 gl_debug (DEBUG_EDITOR, "color field %s(%d) / %X",
507 text_color_node->key, text_color_node->field_flag, text_color_node->color);
509 gtk_widget_set_sensitive (editor->priv->text_color_key_radio, merge_flag);
511 if ( text_color_node->color == GL_COLOR_NONE ) {
513 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->text_color_combo));
517 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
518 text_color_node->color);
521 if (!text_color_node->field_flag || !merge_flag)
523 gl_debug (DEBUG_EDITOR, "color field false");
524 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio), TRUE);
525 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
526 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
531 gl_debug (DEBUG_EDITOR, "color field true");
532 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_key_radio), TRUE);
533 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
534 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
536 gl_field_button_set_key (GL_FIELD_BUTTON (editor->priv->text_color_key_combo), "");
540 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_color_combo),
541 gl_object_editor_changed_cb, editor);
542 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_color_radio),
543 text_radio_toggled_cb, editor);
544 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_color_key_radio),
545 text_radio_toggled_cb, editor);
546 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_color_key_combo),
547 gl_object_editor_changed_cb, editor);
550 gl_debug (DEBUG_EDITOR, "END");
554 /*****************************************************************************/
555 /* Query text color. */
556 /*****************************************************************************/
558 gl_object_editor_get_text_color (glObjectEditor *editor)
561 glColorNode *color_node;
564 gl_debug (DEBUG_EDITOR, "START");
566 color_node = gl_color_node_new_default ();
568 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_key_radio))) {
569 color_node->field_flag = TRUE;
570 color_node->color = gl_prefs_model_get_default_text_color (gl_prefs);
572 gl_field_button_get_key (GL_FIELD_BUTTON (editor->priv->text_color_key_combo));
574 color_node->field_flag = FALSE;
575 color_node->key = NULL;
576 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
580 color_node->color = gl_prefs_model_get_default_text_color (gl_prefs);
582 color_node->color = color;
586 gl_debug (DEBUG_EDITOR, "END");
592 /*****************************************************************************/
593 /* Set text line spacing. */
594 /*****************************************************************************/
596 gl_object_editor_set_text_line_spacing (glObjectEditor *editor,
597 gdouble text_line_spacing)
599 gl_debug (DEBUG_EDITOR, "START");
602 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_line_spacing_spin),
603 gl_object_editor_changed_cb, editor);
606 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_line_spacing_spin),
610 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_line_spacing_spin),
611 gl_object_editor_changed_cb, editor);
614 gl_debug (DEBUG_EDITOR, "END");
618 /*****************************************************************************/
619 /* Query text line spacing. */
620 /*****************************************************************************/
622 gl_object_editor_get_text_line_spacing (glObjectEditor *editor)
624 gdouble text_line_spacing;
626 gl_debug (DEBUG_EDITOR, "START");
629 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_line_spacing_spin));
631 gl_debug (DEBUG_EDITOR, "END");
633 return text_line_spacing;
637 /*****************************************************************************/
638 /* Set auto shrink checkbox. */
639 /*****************************************************************************/
641 gl_object_editor_set_text_auto_shrink (glObjectEditor *editor,
642 gboolean auto_shrink)
644 gl_debug (DEBUG_EDITOR, "START");
647 g_signal_handlers_block_by_func (G_OBJECT (editor->priv->text_auto_shrink_check),
648 gl_object_editor_changed_cb, editor);
651 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check),
655 g_signal_handlers_unblock_by_func (G_OBJECT (editor->priv->text_auto_shrink_check),
656 gl_object_editor_changed_cb, editor);
659 gl_debug (DEBUG_EDITOR, "END");
663 /*****************************************************************************/
664 /* Query auto shrink checkbox. */
665 /*****************************************************************************/
666 gboolean gl_object_editor_get_text_auto_shrink (glObjectEditor *editor)
668 gboolean auto_shrink;
670 gl_debug (DEBUG_EDITOR, "START");
673 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check));
675 gl_debug (DEBUG_EDITOR, "END");
681 /*--------------------------------------------------------------------------*/
682 /* PRIVATE. color radio callback. */
683 /*--------------------------------------------------------------------------*/
685 text_radio_toggled_cb (glObjectEditor *editor)
687 gl_debug (DEBUG_EDITOR, "START");
689 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio))) {
690 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
691 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
693 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
694 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
698 gl_object_editor_changed_cb (editor);
700 gl_debug (DEBUG_EDITOR, "END");
706 * Local Variables: -- emacs
708 * c-basic-offset: 8 -- emacs
709 * tab-width: 8 -- emacs
710 * indent-tabs-mode: nil -- emacs