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 "combo-util.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_combo", &editor->priv->text_color_key_combo,
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->default_text_color);
100 gtk_box_pack_start (GTK_BOX (editor->priv->text_color_hbox),
101 editor->priv->text_color_combo,
104 gl_combo_util_add_text_model ( GTK_COMBO_BOX(editor->priv->text_color_key_combo));
107 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio), TRUE);
108 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
109 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
112 gtk_widget_show_all (editor->priv->text_page_vbox);
114 /* Connect signals */
115 g_signal_connect_swapped (G_OBJECT (editor->priv->text_family_combo),
117 G_CALLBACK (gl_object_editor_changed_cb),
119 g_signal_connect_swapped (G_OBJECT (editor->priv->text_size_spin),
121 G_CALLBACK (gl_object_editor_changed_cb),
123 g_signal_connect_swapped (G_OBJECT (editor->priv->text_bold_toggle),
125 G_CALLBACK (gl_object_editor_changed_cb),
127 g_signal_connect_swapped (G_OBJECT (editor->priv->text_italic_toggle),
129 G_CALLBACK (gl_object_editor_changed_cb),
131 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_combo),
133 G_CALLBACK (gl_object_editor_changed_cb),
135 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_combo),
137 G_CALLBACK (gl_object_editor_changed_cb),
139 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_radio),
141 G_CALLBACK (text_radio_toggled_cb),
143 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_radio),
145 G_CALLBACK (text_radio_toggled_cb),
148 g_signal_connect (G_OBJECT (editor->priv->text_left_toggle),
150 G_CALLBACK (align_toggle_cb),
152 g_signal_connect (G_OBJECT (editor->priv->text_center_toggle),
154 G_CALLBACK (align_toggle_cb),
156 g_signal_connect (G_OBJECT (editor->priv->text_right_toggle),
158 G_CALLBACK (align_toggle_cb),
161 g_signal_connect_swapped (G_OBJECT (editor->priv->text_line_spacing_spin),
163 G_CALLBACK (gl_object_editor_changed_cb),
166 g_signal_connect_swapped (G_OBJECT (editor->priv->text_auto_shrink_check),
168 G_CALLBACK (gl_object_editor_changed_cb),
171 gl_debug (DEBUG_EDITOR, "END");
175 /*--------------------------------------------------------------------------*/
176 /* PRIVATE. Alignment togglebutton callback. */
177 /*--------------------------------------------------------------------------*/
179 align_toggle_cb (GtkToggleButton *toggle,
180 glObjectEditor *editor)
182 if (editor->priv->stop_signals) return;
184 if (gtk_toggle_button_get_active (toggle)) {
186 if (GTK_WIDGET (toggle) == GTK_WIDGET (editor->priv->text_left_toggle)) {
187 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
188 (editor->priv->text_center_toggle),
190 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
191 (editor->priv->text_right_toggle),
193 } else if (GTK_WIDGET (toggle) ==
194 GTK_WIDGET (editor->priv->text_center_toggle)) {
195 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
196 (editor->priv->text_left_toggle),
198 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
199 (editor->priv->text_right_toggle),
201 } else if (GTK_WIDGET (toggle) ==
202 GTK_WIDGET (editor->priv->text_right_toggle)) {
203 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
204 (editor->priv->text_left_toggle),
206 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
207 (editor->priv->text_center_toggle),
211 /* Emit our "changed" signal */
212 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
218 /*****************************************************************************/
219 /* Set font family. */
220 /*****************************************************************************/
222 gl_object_editor_set_font_family (glObjectEditor *editor,
223 const gchar *font_family)
225 gchar *old_font_family;
227 gl_debug (DEBUG_EDITOR, "START");
229 editor->priv->stop_signals = TRUE;
231 old_font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
233 if ( !old_font_family || g_utf8_collate( old_font_family, font_family ) )
235 gl_font_combo_set_family (GL_FONT_COMBO (editor->priv->text_family_combo),
239 g_free (old_font_family);
241 editor->priv->stop_signals = FALSE;
243 gl_debug (DEBUG_EDITOR, "END");
247 /*****************************************************************************/
248 /* Query font family. */
249 /*****************************************************************************/
251 gl_object_editor_get_font_family (glObjectEditor *editor)
255 gl_debug (DEBUG_EDITOR, "START");
257 font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
259 gl_debug (DEBUG_EDITOR, "END");
265 /*****************************************************************************/
267 /*****************************************************************************/
269 gl_object_editor_set_font_size (glObjectEditor *editor,
272 gl_debug (DEBUG_EDITOR, "START");
274 editor->priv->stop_signals = TRUE;
276 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_size_spin),
279 editor->priv->stop_signals = FALSE;
281 gl_debug (DEBUG_EDITOR, "END");
285 /*****************************************************************************/
286 /* Query font size. */
287 /*****************************************************************************/
289 gl_object_editor_get_font_size (glObjectEditor *editor)
293 gl_debug (DEBUG_EDITOR, "START");
296 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_size_spin));
298 gl_debug (DEBUG_EDITOR, "END");
304 /*****************************************************************************/
305 /* Set font weight. */
306 /*****************************************************************************/
308 gl_object_editor_set_font_weight (glObjectEditor *editor,
309 PangoWeight font_weight)
311 gl_debug (DEBUG_EDITOR, "START");
313 editor->priv->stop_signals = TRUE;
315 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle),
316 (font_weight == PANGO_WEIGHT_BOLD));
318 editor->priv->stop_signals = FALSE;
320 gl_debug (DEBUG_EDITOR, "END");
324 /*****************************************************************************/
325 /* Query font weight. */
326 /*****************************************************************************/
328 gl_object_editor_get_font_weight (glObjectEditor *editor)
330 PangoWeight font_weight;
332 gl_debug (DEBUG_EDITOR, "START");
334 if (gtk_toggle_button_get_active
335 (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle))) {
336 font_weight = PANGO_WEIGHT_BOLD;
338 font_weight = PANGO_WEIGHT_NORMAL;
341 gl_debug (DEBUG_EDITOR, "END");
347 /*****************************************************************************/
348 /* Set font italic flag. */
349 /*****************************************************************************/
351 gl_object_editor_set_font_italic_flag (glObjectEditor *editor,
352 gboolean font_italic_flag)
354 gl_debug (DEBUG_EDITOR, "START");
356 editor->priv->stop_signals = TRUE;
358 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_italic_toggle),
361 editor->priv->stop_signals = FALSE;
363 gl_debug (DEBUG_EDITOR, "END");
367 /*****************************************************************************/
368 /* Query font italic flag. */
369 /*****************************************************************************/
371 gl_object_editor_get_font_italic_flag (glObjectEditor *editor)
373 gboolean italic_flag;
375 gl_debug (DEBUG_EDITOR, "START");
378 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
379 (editor->priv->text_italic_toggle));
381 gl_debug (DEBUG_EDITOR, "END");
387 /*****************************************************************************/
388 /* Set text alignment. */
389 /*****************************************************************************/
391 gl_object_editor_set_text_alignment (glObjectEditor *editor,
392 PangoAlignment align)
394 gl_debug (DEBUG_EDITOR, "START");
396 editor->priv->stop_signals = TRUE;
398 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle),
399 (align == PANGO_ALIGN_LEFT));
400 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle),
401 (align == PANGO_ALIGN_CENTER));
402 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle),
403 (align == PANGO_ALIGN_RIGHT));
405 editor->priv->stop_signals = FALSE;
407 gl_debug (DEBUG_EDITOR, "END");
411 /*****************************************************************************/
412 /* Query text alignment. */
413 /*****************************************************************************/
415 gl_object_editor_get_text_alignment (glObjectEditor *editor)
417 PangoAlignment align;
419 gl_debug (DEBUG_EDITOR, "START");
421 if (gtk_toggle_button_get_active
422 (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle))) {
423 align = PANGO_ALIGN_LEFT;
425 if (gtk_toggle_button_get_active
426 (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle))) {
427 align = PANGO_ALIGN_RIGHT;
429 if (gtk_toggle_button_get_active
430 (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle))) {
431 align = PANGO_ALIGN_CENTER;
433 align = PANGO_ALIGN_LEFT; /* Should not happen. */
436 gl_debug (DEBUG_EDITOR, "END");
442 /*****************************************************************************/
443 /* Set text color. */
444 /*****************************************************************************/
446 gl_object_editor_set_text_color (glObjectEditor *editor,
448 glColorNode *text_color_node)
450 gl_debug (DEBUG_EDITOR, "START");
452 editor->priv->stop_signals = TRUE;
454 gl_debug (DEBUG_EDITOR, "color field %s(%d) / %X", text_color_node->key, text_color_node->field_flag, text_color_node->color);
456 gtk_widget_set_sensitive (editor->priv->text_color_key_radio, merge_flag);
458 if ( text_color_node->color == GL_COLOR_NONE ) {
460 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->text_color_combo));
464 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
465 text_color_node->color);
468 if (!text_color_node->field_flag) {
469 gl_debug (DEBUG_EDITOR, "color field false");
470 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
471 (editor->priv->text_color_radio), TRUE);
472 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
473 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
476 gl_debug (DEBUG_EDITOR, "color field true");
477 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
478 (editor->priv->text_color_key_radio), TRUE);
479 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
480 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
482 gl_combo_util_set_active_text (GTK_COMBO_BOX (editor->priv->text_color_key_combo), "");
485 editor->priv->stop_signals = FALSE;
487 gl_debug (DEBUG_EDITOR, "END");
491 /*****************************************************************************/
492 /* Query text color. */
493 /*****************************************************************************/
495 gl_object_editor_get_text_color (glObjectEditor *editor)
498 glColorNode *color_node;
501 gl_debug (DEBUG_EDITOR, "START");
503 color_node = gl_color_node_new_default ();
505 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_key_radio))) {
506 color_node->field_flag = TRUE;
507 color_node->color = gl_prefs->default_text_color;
509 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->text_color_key_combo));
511 color_node->field_flag = FALSE;
512 color_node->key = NULL;
513 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
517 color_node->color = gl_prefs->default_text_color;
519 color_node->color = color;
523 gl_debug (DEBUG_EDITOR, "END");
529 /*****************************************************************************/
530 /* Set text line spacing. */
531 /*****************************************************************************/
533 gl_object_editor_set_text_line_spacing (glObjectEditor *editor,
534 gdouble text_line_spacing)
536 gl_debug (DEBUG_EDITOR, "START");
538 editor->priv->stop_signals = TRUE;
540 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_line_spacing_spin),
543 editor->priv->stop_signals = FALSE;
545 gl_debug (DEBUG_EDITOR, "END");
549 /*****************************************************************************/
550 /* Query text line spacing. */
551 /*****************************************************************************/
553 gl_object_editor_get_text_line_spacing (glObjectEditor *editor)
555 gdouble text_line_spacing;
557 gl_debug (DEBUG_EDITOR, "START");
560 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_line_spacing_spin));
562 gl_debug (DEBUG_EDITOR, "END");
564 return text_line_spacing;
568 /*****************************************************************************/
569 /* Set auto shrink checkbox. */
570 /*****************************************************************************/
572 gl_object_editor_set_text_auto_shrink (glObjectEditor *editor,
573 gboolean auto_shrink)
575 gl_debug (DEBUG_EDITOR, "START");
577 editor->priv->stop_signals = TRUE;
579 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check),
582 editor->priv->stop_signals = FALSE;
584 gl_debug (DEBUG_EDITOR, "END");
588 /*****************************************************************************/
589 /* Query auto shrink checkbox. */
590 /*****************************************************************************/
591 gboolean gl_object_editor_get_text_auto_shrink (glObjectEditor *editor)
593 gboolean auto_shrink;
595 gl_debug (DEBUG_EDITOR, "START");
598 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check));
600 gl_debug (DEBUG_EDITOR, "END");
606 /*--------------------------------------------------------------------------*/
607 /* PRIVATE. color radio callback. */
608 /*--------------------------------------------------------------------------*/
610 text_radio_toggled_cb (glObjectEditor *editor)
612 if (editor->priv->stop_signals) return;
614 gl_debug (DEBUG_EDITOR, "START");
616 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio))) {
617 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
618 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
620 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
621 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
625 /* Emit our "changed" signal */
626 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
628 gl_debug (DEBUG_EDITOR, "END");
634 * Local Variables: -- emacs
636 * c-basic-offset: 8 -- emacs
637 * tab-width: 8 -- emacs
638 * indent-tabs-mode: nil -- emacs