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 GList *family_names = NULL;
75 gl_debug (DEBUG_EDITOR, "START");
77 /* Extract widgets from XML tree. */
78 gl_util_get_builder_widgets (editor->priv->builder,
79 "text_page_vbox", &editor->priv->text_page_vbox,
80 "text_family_hbox", &editor->priv->text_family_hbox,
81 "text_size_spin", &editor->priv->text_size_spin,
82 "text_bold_toggle", &editor->priv->text_bold_toggle,
83 "text_italic_toggle", &editor->priv->text_italic_toggle,
84 "text_color_hbox", &editor->priv->text_color_hbox,
85 "text_color_radio", &editor->priv->text_color_radio,
86 "text_color_key_radio", &editor->priv->text_color_key_radio,
87 "text_color_key_combo", &editor->priv->text_color_key_combo,
88 "text_left_toggle", &editor->priv->text_left_toggle,
89 "text_center_toggle", &editor->priv->text_center_toggle,
90 "text_right_toggle", &editor->priv->text_right_toggle,
91 "text_line_spacing_spin", &editor->priv->text_line_spacing_spin,
92 "text_auto_shrink_check", &editor->priv->text_auto_shrink_check,
95 editor->priv->text_family_combo = gl_font_combo_new ("Sans");
96 gtk_box_pack_start (GTK_BOX (editor->priv->text_family_hbox),
97 editor->priv->text_family_combo,
100 editor->priv->text_color_combo = gl_color_combo_new (_("Default"),
101 GL_COLOR_TEXT_DEFAULT,
102 gl_prefs->default_text_color);
103 gtk_box_pack_start (GTK_BOX (editor->priv->text_color_hbox),
104 editor->priv->text_color_combo,
107 gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->text_color_key_combo));
110 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio), TRUE);
111 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
112 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
115 gtk_widget_show_all (editor->priv->text_page_vbox);
117 /* Connect signals */
118 g_signal_connect_swapped (G_OBJECT (editor->priv->text_family_combo),
120 G_CALLBACK (gl_object_editor_changed_cb),
122 g_signal_connect_swapped (G_OBJECT (editor->priv->text_size_spin),
124 G_CALLBACK (gl_object_editor_changed_cb),
126 g_signal_connect_swapped (G_OBJECT (editor->priv->text_bold_toggle),
128 G_CALLBACK (gl_object_editor_changed_cb),
130 g_signal_connect_swapped (G_OBJECT (editor->priv->text_italic_toggle),
132 G_CALLBACK (gl_object_editor_changed_cb),
134 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_combo),
136 G_CALLBACK (gl_object_editor_changed_cb),
138 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_combo),
140 G_CALLBACK (gl_object_editor_changed_cb),
142 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_radio),
144 G_CALLBACK (text_radio_toggled_cb),
146 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_radio),
148 G_CALLBACK (text_radio_toggled_cb),
151 g_signal_connect (G_OBJECT (editor->priv->text_left_toggle),
153 G_CALLBACK (align_toggle_cb),
155 g_signal_connect (G_OBJECT (editor->priv->text_center_toggle),
157 G_CALLBACK (align_toggle_cb),
159 g_signal_connect (G_OBJECT (editor->priv->text_right_toggle),
161 G_CALLBACK (align_toggle_cb),
164 g_signal_connect_swapped (G_OBJECT (editor->priv->text_line_spacing_spin),
166 G_CALLBACK (gl_object_editor_changed_cb),
169 g_signal_connect_swapped (G_OBJECT (editor->priv->text_auto_shrink_check),
171 G_CALLBACK (gl_object_editor_changed_cb),
174 gl_debug (DEBUG_EDITOR, "END");
178 /*--------------------------------------------------------------------------*/
179 /* PRIVATE. Alignment togglebutton callback. */
180 /*--------------------------------------------------------------------------*/
182 align_toggle_cb (GtkToggleButton *toggle,
183 glObjectEditor *editor)
185 if (editor->priv->stop_signals) return;
187 if (gtk_toggle_button_get_active (toggle)) {
189 if (GTK_WIDGET (toggle) == GTK_WIDGET (editor->priv->text_left_toggle)) {
190 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
191 (editor->priv->text_center_toggle),
193 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
194 (editor->priv->text_right_toggle),
196 } else if (GTK_WIDGET (toggle) ==
197 GTK_WIDGET (editor->priv->text_center_toggle)) {
198 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
199 (editor->priv->text_left_toggle),
201 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
202 (editor->priv->text_right_toggle),
204 } else if (GTK_WIDGET (toggle) ==
205 GTK_WIDGET (editor->priv->text_right_toggle)) {
206 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
207 (editor->priv->text_left_toggle),
209 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
210 (editor->priv->text_center_toggle),
214 /* Emit our "changed" signal */
215 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
221 /*****************************************************************************/
222 /* Set font family. */
223 /*****************************************************************************/
225 gl_object_editor_set_font_family (glObjectEditor *editor,
226 const gchar *font_family)
229 gchar *old_font_family;
230 gchar *good_font_family;
232 gl_debug (DEBUG_EDITOR, "START");
234 editor->priv->stop_signals = TRUE;
236 old_font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
238 if ( !old_font_family || g_utf8_collate( old_font_family, font_family ) )
241 /* Make sure we have a valid font family. if not provide a good default. */
242 family_names = gl_font_util_get_all_families ();
243 if (g_list_find_custom (family_names, font_family, (GCompareFunc)g_utf8_collate)) {
244 good_font_family = g_strdup (font_family);
246 if (family_names != NULL) {
247 good_font_family = g_strdup (family_names->data); /* 1st entry */
249 good_font_family = NULL;
252 gl_font_combo_set_family (GL_FONT_COMBO (editor->priv->text_family_combo), good_font_family);
253 g_free (good_font_family);
256 g_free (old_font_family);
258 editor->priv->stop_signals = FALSE;
260 gl_debug (DEBUG_EDITOR, "END");
264 /*****************************************************************************/
265 /* Query font family. */
266 /*****************************************************************************/
268 gl_object_editor_get_font_family (glObjectEditor *editor)
272 gl_debug (DEBUG_EDITOR, "START");
274 font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
276 gl_debug (DEBUG_EDITOR, "END");
282 /*****************************************************************************/
284 /*****************************************************************************/
286 gl_object_editor_set_font_size (glObjectEditor *editor,
289 gl_debug (DEBUG_EDITOR, "START");
291 editor->priv->stop_signals = TRUE;
293 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_size_spin),
296 editor->priv->stop_signals = FALSE;
298 gl_debug (DEBUG_EDITOR, "END");
302 /*****************************************************************************/
303 /* Query font size. */
304 /*****************************************************************************/
306 gl_object_editor_get_font_size (glObjectEditor *editor)
310 gl_debug (DEBUG_EDITOR, "START");
313 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_size_spin));
315 gl_debug (DEBUG_EDITOR, "END");
321 /*****************************************************************************/
322 /* Set font weight. */
323 /*****************************************************************************/
325 gl_object_editor_set_font_weight (glObjectEditor *editor,
326 PangoWeight font_weight)
328 gl_debug (DEBUG_EDITOR, "START");
330 editor->priv->stop_signals = TRUE;
332 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle),
333 (font_weight == PANGO_WEIGHT_BOLD));
335 editor->priv->stop_signals = FALSE;
337 gl_debug (DEBUG_EDITOR, "END");
341 /*****************************************************************************/
342 /* Query font weight. */
343 /*****************************************************************************/
345 gl_object_editor_get_font_weight (glObjectEditor *editor)
347 PangoWeight font_weight;
349 gl_debug (DEBUG_EDITOR, "START");
351 if (gtk_toggle_button_get_active
352 (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle))) {
353 font_weight = PANGO_WEIGHT_BOLD;
355 font_weight = PANGO_WEIGHT_NORMAL;
358 gl_debug (DEBUG_EDITOR, "END");
364 /*****************************************************************************/
365 /* Set font italic flag. */
366 /*****************************************************************************/
368 gl_object_editor_set_font_italic_flag (glObjectEditor *editor,
369 gboolean font_italic_flag)
371 gl_debug (DEBUG_EDITOR, "START");
373 editor->priv->stop_signals = TRUE;
375 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_italic_toggle),
378 editor->priv->stop_signals = FALSE;
380 gl_debug (DEBUG_EDITOR, "END");
384 /*****************************************************************************/
385 /* Query font italic flag. */
386 /*****************************************************************************/
388 gl_object_editor_get_font_italic_flag (glObjectEditor *editor)
390 gboolean italic_flag;
392 gl_debug (DEBUG_EDITOR, "START");
395 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
396 (editor->priv->text_italic_toggle));
398 gl_debug (DEBUG_EDITOR, "END");
404 /*****************************************************************************/
405 /* Set text alignment. */
406 /*****************************************************************************/
408 gl_object_editor_set_text_alignment (glObjectEditor *editor,
409 PangoAlignment align)
411 gl_debug (DEBUG_EDITOR, "START");
413 editor->priv->stop_signals = TRUE;
415 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle),
416 (align == PANGO_ALIGN_LEFT));
417 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle),
418 (align == PANGO_ALIGN_CENTER));
419 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle),
420 (align == PANGO_ALIGN_RIGHT));
422 editor->priv->stop_signals = FALSE;
424 gl_debug (DEBUG_EDITOR, "END");
428 /*****************************************************************************/
429 /* Query text alignment. */
430 /*****************************************************************************/
432 gl_object_editor_get_text_alignment (glObjectEditor *editor)
434 PangoAlignment align;
436 gl_debug (DEBUG_EDITOR, "START");
438 if (gtk_toggle_button_get_active
439 (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle))) {
440 align = PANGO_ALIGN_LEFT;
442 if (gtk_toggle_button_get_active
443 (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle))) {
444 align = PANGO_ALIGN_RIGHT;
446 if (gtk_toggle_button_get_active
447 (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle))) {
448 align = PANGO_ALIGN_CENTER;
450 align = PANGO_ALIGN_LEFT; /* Should not happen. */
453 gl_debug (DEBUG_EDITOR, "END");
459 /*****************************************************************************/
460 /* Set text color. */
461 /*****************************************************************************/
463 gl_object_editor_set_text_color (glObjectEditor *editor,
465 glColorNode *text_color_node)
467 gl_debug (DEBUG_EDITOR, "START");
469 editor->priv->stop_signals = TRUE;
471 gl_debug (DEBUG_EDITOR, "color field %s(%d) / %X", text_color_node->key, text_color_node->field_flag, text_color_node->color);
473 gtk_widget_set_sensitive (editor->priv->text_color_key_radio, merge_flag);
475 if ( text_color_node->color == GL_COLOR_NONE ) {
477 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->text_color_combo));
481 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
482 text_color_node->color);
485 if (!text_color_node->field_flag) {
486 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
487 (editor->priv->text_color_radio), TRUE);
488 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
489 gl_debug (DEBUG_EDITOR, "color field false 0");
490 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
493 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
494 (editor->priv->text_color_key_radio), TRUE);
495 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
496 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
498 gl_debug (DEBUG_EDITOR, "color field true 1");
499 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->text_color_key_combo), "");
500 gl_debug (DEBUG_EDITOR, "color field true 2");
503 editor->priv->stop_signals = FALSE;
505 gl_debug (DEBUG_EDITOR, "END");
509 /*****************************************************************************/
510 /* Query text color. */
511 /*****************************************************************************/
513 gl_object_editor_get_text_color (glObjectEditor *editor)
516 glColorNode *color_node;
519 gl_debug (DEBUG_EDITOR, "START");
521 color_node = gl_color_node_new_default ();
523 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_key_radio))) {
524 color_node->field_flag = TRUE;
525 color_node->color = gl_prefs->default_text_color;
527 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->text_color_key_combo));
529 color_node->field_flag = FALSE;
530 color_node->key = NULL;
531 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
535 color_node->color = gl_prefs->default_text_color;
537 color_node->color = color;
541 gl_debug (DEBUG_EDITOR, "END");
547 /*****************************************************************************/
548 /* Set text line spacing. */
549 /*****************************************************************************/
551 gl_object_editor_set_text_line_spacing (glObjectEditor *editor,
552 gdouble text_line_spacing)
554 gl_debug (DEBUG_EDITOR, "START");
556 editor->priv->stop_signals = TRUE;
558 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_line_spacing_spin),
561 editor->priv->stop_signals = FALSE;
563 gl_debug (DEBUG_EDITOR, "END");
567 /*****************************************************************************/
568 /* Query text line spacing. */
569 /*****************************************************************************/
571 gl_object_editor_get_text_line_spacing (glObjectEditor *editor)
573 gdouble text_line_spacing;
575 gl_debug (DEBUG_EDITOR, "START");
578 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_line_spacing_spin));
580 gl_debug (DEBUG_EDITOR, "END");
582 return text_line_spacing;
586 /*****************************************************************************/
587 /* Set auto shrink checkbox. */
588 /*****************************************************************************/
590 gl_object_editor_set_text_auto_shrink (glObjectEditor *editor,
591 gboolean auto_shrink)
593 gl_debug (DEBUG_EDITOR, "START");
595 editor->priv->stop_signals = TRUE;
597 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check),
600 editor->priv->stop_signals = FALSE;
602 gl_debug (DEBUG_EDITOR, "END");
606 /*****************************************************************************/
607 /* Query auto shrink checkbox. */
608 /*****************************************************************************/
609 gboolean gl_object_editor_get_text_auto_shrink (glObjectEditor *editor)
611 gboolean auto_shrink;
613 gl_debug (DEBUG_EDITOR, "START");
616 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check));
618 gl_debug (DEBUG_EDITOR, "END");
624 /*--------------------------------------------------------------------------*/
625 /* PRIVATE. color radio callback. */
626 /*--------------------------------------------------------------------------*/
628 text_radio_toggled_cb (glObjectEditor *editor)
630 if (editor->priv->stop_signals) return;
632 gl_debug (DEBUG_EDITOR, "START");
634 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio))) {
635 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
636 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
638 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
639 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
643 /* Emit our "changed" signal */
644 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
646 gl_debug (DEBUG_EDITOR, "END");
652 * Local Variables: -- emacs
654 * c-basic-offset: 8 -- emacs
655 * tab-width: 8 -- emacs
656 * indent-tabs-mode: nil -- emacs