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>
26 #include <gtk/gtktogglebutton.h>
27 #include <gtk/gtkspinbutton.h>
28 #include <gtk/gtkcombobox.h>
32 #include "color-combo.h"
34 #include "font-combo.h"
35 #include "font-util.h"
38 #include "object-editor-private.h"
43 /*===========================================*/
45 /*===========================================*/
48 /*===========================================*/
49 /* Private data types */
50 /*===========================================*/
53 /*===========================================*/
55 /*===========================================*/
58 /*===========================================*/
59 /* Local function prototypes */
60 /*===========================================*/
62 static void align_toggle_cb (GtkToggleButton *toggle,
63 glObjectEditor *editor);
64 static void text_radio_toggled_cb (glObjectEditor *editor);
67 /*--------------------------------------------------------------------------*/
68 /* PRIVATE. Prepare size page. */
69 /*--------------------------------------------------------------------------*/
71 gl_object_editor_prepare_text_page (glObjectEditor *editor)
73 gl_debug (DEBUG_EDITOR, "START");
75 /* Extract widgets from XML tree. */
76 gl_util_get_builder_widgets (editor->priv->builder,
77 "text_page_vbox", &editor->priv->text_page_vbox,
78 "text_family_hbox", &editor->priv->text_family_hbox,
79 "text_size_spin", &editor->priv->text_size_spin,
80 "text_bold_toggle", &editor->priv->text_bold_toggle,
81 "text_italic_toggle", &editor->priv->text_italic_toggle,
82 "text_color_hbox", &editor->priv->text_color_hbox,
83 "text_color_radio", &editor->priv->text_color_radio,
84 "text_color_key_radio", &editor->priv->text_color_key_radio,
85 "text_color_key_combo", &editor->priv->text_color_key_combo,
86 "text_left_toggle", &editor->priv->text_left_toggle,
87 "text_center_toggle", &editor->priv->text_center_toggle,
88 "text_right_toggle", &editor->priv->text_right_toggle,
89 "text_line_spacing_spin", &editor->priv->text_line_spacing_spin,
90 "text_auto_shrink_check", &editor->priv->text_auto_shrink_check,
93 editor->priv->text_family_combo = gl_font_combo_new ("Sans");
94 gtk_box_pack_start (GTK_BOX (editor->priv->text_family_hbox),
95 editor->priv->text_family_combo,
98 editor->priv->text_color_combo = gl_color_combo_new (_("Default"),
99 GL_COLOR_TEXT_DEFAULT,
100 gl_prefs->default_text_color);
101 gtk_box_pack_start (GTK_BOX (editor->priv->text_color_hbox),
102 editor->priv->text_color_combo,
105 gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->text_color_key_combo));
108 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio), TRUE);
109 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
110 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
113 gtk_widget_show_all (editor->priv->text_page_vbox);
115 /* Connect signals */
116 g_signal_connect_swapped (G_OBJECT (editor->priv->text_family_combo),
118 G_CALLBACK (gl_object_editor_changed_cb),
120 g_signal_connect_swapped (G_OBJECT (editor->priv->text_size_spin),
122 G_CALLBACK (gl_object_editor_changed_cb),
124 g_signal_connect_swapped (G_OBJECT (editor->priv->text_bold_toggle),
126 G_CALLBACK (gl_object_editor_changed_cb),
128 g_signal_connect_swapped (G_OBJECT (editor->priv->text_italic_toggle),
130 G_CALLBACK (gl_object_editor_changed_cb),
132 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_combo),
134 G_CALLBACK (gl_object_editor_changed_cb),
136 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_combo),
138 G_CALLBACK (gl_object_editor_changed_cb),
140 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_radio),
142 G_CALLBACK (text_radio_toggled_cb),
144 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_radio),
146 G_CALLBACK (text_radio_toggled_cb),
149 g_signal_connect (G_OBJECT (editor->priv->text_left_toggle),
151 G_CALLBACK (align_toggle_cb),
153 g_signal_connect (G_OBJECT (editor->priv->text_center_toggle),
155 G_CALLBACK (align_toggle_cb),
157 g_signal_connect (G_OBJECT (editor->priv->text_right_toggle),
159 G_CALLBACK (align_toggle_cb),
162 g_signal_connect_swapped (G_OBJECT (editor->priv->text_line_spacing_spin),
164 G_CALLBACK (gl_object_editor_changed_cb),
167 g_signal_connect_swapped (G_OBJECT (editor->priv->text_auto_shrink_check),
169 G_CALLBACK (gl_object_editor_changed_cb),
172 gl_debug (DEBUG_EDITOR, "END");
176 /*--------------------------------------------------------------------------*/
177 /* PRIVATE. Alignment togglebutton callback. */
178 /*--------------------------------------------------------------------------*/
180 align_toggle_cb (GtkToggleButton *toggle,
181 glObjectEditor *editor)
183 if (editor->priv->stop_signals) return;
185 if (gtk_toggle_button_get_active (toggle)) {
187 if (GTK_WIDGET (toggle) == GTK_WIDGET (editor->priv->text_left_toggle)) {
188 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
189 (editor->priv->text_center_toggle),
191 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
192 (editor->priv->text_right_toggle),
194 } else if (GTK_WIDGET (toggle) ==
195 GTK_WIDGET (editor->priv->text_center_toggle)) {
196 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
197 (editor->priv->text_left_toggle),
199 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
200 (editor->priv->text_right_toggle),
202 } else if (GTK_WIDGET (toggle) ==
203 GTK_WIDGET (editor->priv->text_right_toggle)) {
204 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
205 (editor->priv->text_left_toggle),
207 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
208 (editor->priv->text_center_toggle),
212 /* Emit our "changed" signal */
213 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
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 gl_debug (DEBUG_EDITOR, "START");
230 editor->priv->stop_signals = TRUE;
232 old_font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
234 if ( !old_font_family || g_utf8_collate( old_font_family, font_family ) )
236 gl_font_combo_set_family (GL_FONT_COMBO (editor->priv->text_family_combo),
240 g_free (old_font_family);
242 editor->priv->stop_signals = FALSE;
244 gl_debug (DEBUG_EDITOR, "END");
248 /*****************************************************************************/
249 /* Query font family. */
250 /*****************************************************************************/
252 gl_object_editor_get_font_family (glObjectEditor *editor)
256 gl_debug (DEBUG_EDITOR, "START");
258 font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
260 gl_debug (DEBUG_EDITOR, "END");
266 /*****************************************************************************/
268 /*****************************************************************************/
270 gl_object_editor_set_font_size (glObjectEditor *editor,
273 gl_debug (DEBUG_EDITOR, "START");
275 editor->priv->stop_signals = TRUE;
277 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_size_spin),
280 editor->priv->stop_signals = FALSE;
282 gl_debug (DEBUG_EDITOR, "END");
286 /*****************************************************************************/
287 /* Query font size. */
288 /*****************************************************************************/
290 gl_object_editor_get_font_size (glObjectEditor *editor)
294 gl_debug (DEBUG_EDITOR, "START");
297 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_size_spin));
299 gl_debug (DEBUG_EDITOR, "END");
305 /*****************************************************************************/
306 /* Set font weight. */
307 /*****************************************************************************/
309 gl_object_editor_set_font_weight (glObjectEditor *editor,
310 PangoWeight font_weight)
312 gl_debug (DEBUG_EDITOR, "START");
314 editor->priv->stop_signals = TRUE;
316 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle),
317 (font_weight == PANGO_WEIGHT_BOLD));
319 editor->priv->stop_signals = FALSE;
321 gl_debug (DEBUG_EDITOR, "END");
325 /*****************************************************************************/
326 /* Query font weight. */
327 /*****************************************************************************/
329 gl_object_editor_get_font_weight (glObjectEditor *editor)
331 PangoWeight font_weight;
333 gl_debug (DEBUG_EDITOR, "START");
335 if (gtk_toggle_button_get_active
336 (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle))) {
337 font_weight = PANGO_WEIGHT_BOLD;
339 font_weight = PANGO_WEIGHT_NORMAL;
342 gl_debug (DEBUG_EDITOR, "END");
348 /*****************************************************************************/
349 /* Set font italic flag. */
350 /*****************************************************************************/
352 gl_object_editor_set_font_italic_flag (glObjectEditor *editor,
353 gboolean font_italic_flag)
355 gl_debug (DEBUG_EDITOR, "START");
357 editor->priv->stop_signals = TRUE;
359 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_italic_toggle),
362 editor->priv->stop_signals = FALSE;
364 gl_debug (DEBUG_EDITOR, "END");
368 /*****************************************************************************/
369 /* Query font italic flag. */
370 /*****************************************************************************/
372 gl_object_editor_get_font_italic_flag (glObjectEditor *editor)
374 gboolean italic_flag;
376 gl_debug (DEBUG_EDITOR, "START");
379 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
380 (editor->priv->text_italic_toggle));
382 gl_debug (DEBUG_EDITOR, "END");
388 /*****************************************************************************/
389 /* Set text alignment. */
390 /*****************************************************************************/
392 gl_object_editor_set_text_alignment (glObjectEditor *editor,
393 PangoAlignment align)
395 gl_debug (DEBUG_EDITOR, "START");
397 editor->priv->stop_signals = TRUE;
399 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle),
400 (align == PANGO_ALIGN_LEFT));
401 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle),
402 (align == PANGO_ALIGN_CENTER));
403 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle),
404 (align == PANGO_ALIGN_RIGHT));
406 editor->priv->stop_signals = FALSE;
408 gl_debug (DEBUG_EDITOR, "END");
412 /*****************************************************************************/
413 /* Query text alignment. */
414 /*****************************************************************************/
416 gl_object_editor_get_text_alignment (glObjectEditor *editor)
418 PangoAlignment align;
420 gl_debug (DEBUG_EDITOR, "START");
422 if (gtk_toggle_button_get_active
423 (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle))) {
424 align = PANGO_ALIGN_LEFT;
426 if (gtk_toggle_button_get_active
427 (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle))) {
428 align = PANGO_ALIGN_RIGHT;
430 if (gtk_toggle_button_get_active
431 (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle))) {
432 align = PANGO_ALIGN_CENTER;
434 align = PANGO_ALIGN_LEFT; /* Should not happen. */
437 gl_debug (DEBUG_EDITOR, "END");
443 /*****************************************************************************/
444 /* Set text color. */
445 /*****************************************************************************/
447 gl_object_editor_set_text_color (glObjectEditor *editor,
449 glColorNode *text_color_node)
451 gl_debug (DEBUG_EDITOR, "START");
453 editor->priv->stop_signals = TRUE;
455 gl_debug (DEBUG_EDITOR, "color field %s(%d) / %X", text_color_node->key, text_color_node->field_flag, text_color_node->color);
457 gtk_widget_set_sensitive (editor->priv->text_color_key_radio, merge_flag);
459 if ( text_color_node->color == GL_COLOR_NONE ) {
461 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->text_color_combo));
465 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
466 text_color_node->color);
469 if (!text_color_node->field_flag) {
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 gl_debug (DEBUG_EDITOR, "color field false 0");
474 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
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_debug (DEBUG_EDITOR, "color field true 1");
483 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->text_color_key_combo), "");
484 gl_debug (DEBUG_EDITOR, "color field true 2");
487 editor->priv->stop_signals = FALSE;
489 gl_debug (DEBUG_EDITOR, "END");
493 /*****************************************************************************/
494 /* Query text color. */
495 /*****************************************************************************/
497 gl_object_editor_get_text_color (glObjectEditor *editor)
500 glColorNode *color_node;
503 gl_debug (DEBUG_EDITOR, "START");
505 color_node = gl_color_node_new_default ();
507 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_key_radio))) {
508 color_node->field_flag = TRUE;
509 color_node->color = gl_prefs->default_text_color;
511 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->text_color_key_combo));
513 color_node->field_flag = FALSE;
514 color_node->key = NULL;
515 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
519 color_node->color = gl_prefs->default_text_color;
521 color_node->color = color;
525 gl_debug (DEBUG_EDITOR, "END");
531 /*****************************************************************************/
532 /* Set text line spacing. */
533 /*****************************************************************************/
535 gl_object_editor_set_text_line_spacing (glObjectEditor *editor,
536 gdouble text_line_spacing)
538 gl_debug (DEBUG_EDITOR, "START");
540 editor->priv->stop_signals = TRUE;
542 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_line_spacing_spin),
545 editor->priv->stop_signals = FALSE;
547 gl_debug (DEBUG_EDITOR, "END");
551 /*****************************************************************************/
552 /* Query text line spacing. */
553 /*****************************************************************************/
555 gl_object_editor_get_text_line_spacing (glObjectEditor *editor)
557 gdouble text_line_spacing;
559 gl_debug (DEBUG_EDITOR, "START");
562 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_line_spacing_spin));
564 gl_debug (DEBUG_EDITOR, "END");
566 return text_line_spacing;
570 /*****************************************************************************/
571 /* Set auto shrink checkbox. */
572 /*****************************************************************************/
574 gl_object_editor_set_text_auto_shrink (glObjectEditor *editor,
575 gboolean auto_shrink)
577 gl_debug (DEBUG_EDITOR, "START");
579 editor->priv->stop_signals = TRUE;
581 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check),
584 editor->priv->stop_signals = FALSE;
586 gl_debug (DEBUG_EDITOR, "END");
590 /*****************************************************************************/
591 /* Query auto shrink checkbox. */
592 /*****************************************************************************/
593 gboolean gl_object_editor_get_text_auto_shrink (glObjectEditor *editor)
595 gboolean auto_shrink;
597 gl_debug (DEBUG_EDITOR, "START");
600 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check));
602 gl_debug (DEBUG_EDITOR, "END");
608 /*--------------------------------------------------------------------------*/
609 /* PRIVATE. color radio callback. */
610 /*--------------------------------------------------------------------------*/
612 text_radio_toggled_cb (glObjectEditor *editor)
614 if (editor->priv->stop_signals) return;
616 gl_debug (DEBUG_EDITOR, "START");
618 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio))) {
619 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
620 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
622 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
623 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
627 /* Emit our "changed" signal */
628 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
630 gl_debug (DEBUG_EDITOR, "END");
636 * Local Variables: -- emacs
638 * c-basic-offset: 8 -- emacs
639 * tab-width: 8 -- emacs
640 * indent-tabs-mode: nil -- emacs