1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
4 * (GLABELS) Label and Business Card Creation program for GNOME
6 * object-editor.c: object properties editor module
8 * Copyright (C) 2003 Jim Evins <evins@snaught.com>.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "object-editor.h"
28 #include <glib/gi18n.h>
29 #include <gtk/gtktogglebutton.h>
30 #include <gtk/gtkspinbutton.h>
31 #include <gtk/gtkcombobox.h>
35 #include "color-combo.h"
39 #include "object-editor-private.h"
43 /*===========================================*/
45 /*===========================================*/
47 /*===========================================*/
48 /* Private data types */
49 /*===========================================*/
51 /*===========================================*/
53 /*===========================================*/
55 /*===========================================*/
56 /* Local function prototypes */
57 /*===========================================*/
59 static void align_toggle_cb (GtkToggleButton *toggle,
60 glObjectEditor *editor);
61 static void text_radio_toggled_cb (glObjectEditor *editor);
64 /*--------------------------------------------------------------------------*/
65 /* PRIVATE. Prepare size page. */
66 /*--------------------------------------------------------------------------*/
68 gl_object_editor_prepare_text_page (glObjectEditor *editor)
70 GList *family_names = NULL;
72 gl_debug (DEBUG_EDITOR, "START");
74 /* Extract widgets from XML tree. */
75 gl_util_get_builder_widgets (editor->priv->gui,
76 "text_page_vbox", &editor->priv->text_page_vbox,
77 "text_family_combo", &editor->priv->text_family_combo,
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_color_combo = gl_color_combo_new (NULL,
94 GL_COLOR_TEXT_DEFAULT,
95 gl_prefs->default_text_color);
96 gtk_container_add (GTK_CONTAINER (editor->priv->text_color_hbox),
97 editor->priv->text_color_combo);
99 gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->text_family_combo));
100 gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->text_color_key_combo));
102 /* Load family names */
103 family_names = gl_util_get_font_family_list ();
104 gl_util_combo_box_set_strings (GTK_COMBO_BOX(editor->priv->text_family_combo),
106 gl_util_font_family_list_free (family_names);
109 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio), TRUE);
110 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
111 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
114 gtk_widget_show_all (editor->priv->text_page_vbox);
116 /* Connect signals */
117 g_signal_connect_swapped (G_OBJECT (editor->priv->text_family_combo),
119 G_CALLBACK (gl_object_editor_changed_cb),
121 g_signal_connect_swapped (G_OBJECT (editor->priv->text_size_spin),
123 G_CALLBACK (gl_object_editor_changed_cb),
125 g_signal_connect_swapped (G_OBJECT (editor->priv->text_bold_toggle),
127 G_CALLBACK (gl_object_editor_changed_cb),
129 g_signal_connect_swapped (G_OBJECT (editor->priv->text_italic_toggle),
131 G_CALLBACK (gl_object_editor_changed_cb),
133 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_combo),
135 G_CALLBACK (gl_object_editor_changed_cb),
137 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_combo),
139 G_CALLBACK (gl_object_editor_changed_cb),
141 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_radio),
143 G_CALLBACK (text_radio_toggled_cb),
145 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_radio),
147 G_CALLBACK (text_radio_toggled_cb),
150 g_signal_connect (G_OBJECT (editor->priv->text_left_toggle),
152 G_CALLBACK (align_toggle_cb),
154 g_signal_connect (G_OBJECT (editor->priv->text_center_toggle),
156 G_CALLBACK (align_toggle_cb),
158 g_signal_connect (G_OBJECT (editor->priv->text_right_toggle),
160 G_CALLBACK (align_toggle_cb),
163 g_signal_connect_swapped (G_OBJECT (editor->priv->text_line_spacing_spin),
165 G_CALLBACK (gl_object_editor_changed_cb),
168 g_signal_connect_swapped (G_OBJECT (editor->priv->text_auto_shrink_check),
170 G_CALLBACK (gl_object_editor_changed_cb),
173 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);
218 /*****************************************************************************/
219 /* Set font family. */
220 /*****************************************************************************/
222 gl_object_editor_set_font_family (glObjectEditor *editor,
223 const gchar *font_family)
226 gchar *good_font_family;
228 gl_debug (DEBUG_EDITOR, "START");
230 editor->priv->stop_signals = TRUE;
232 /* Make sure we have a valid font family. if not provide a good default. */
233 family_names = gl_util_get_font_family_list ();
234 if (g_list_find_custom (family_names, font_family, (GCompareFunc)g_utf8_collate)) {
235 good_font_family = g_strdup (font_family);
237 if (family_names != NULL) {
238 good_font_family = g_strdup (family_names->data); /* 1st entry */
240 good_font_family = NULL;
243 gl_util_font_family_list_free (family_names);
244 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->text_family_combo), good_font_family);
245 g_free (good_font_family);
247 editor->priv->stop_signals = FALSE;
249 gl_debug (DEBUG_EDITOR, "END");
252 /*****************************************************************************/
253 /* Query font family. */
254 /*****************************************************************************/
256 gl_object_editor_get_font_family (glObjectEditor *editor)
260 gl_debug (DEBUG_EDITOR, "START");
262 font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->text_family_combo));
264 gl_debug (DEBUG_EDITOR, "END");
269 /*****************************************************************************/
271 /*****************************************************************************/
273 gl_object_editor_set_font_size (glObjectEditor *editor,
276 gl_debug (DEBUG_EDITOR, "START");
278 editor->priv->stop_signals = TRUE;
280 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_size_spin),
283 editor->priv->stop_signals = FALSE;
285 gl_debug (DEBUG_EDITOR, "END");
288 /*****************************************************************************/
289 /* Query font size. */
290 /*****************************************************************************/
292 gl_object_editor_get_font_size (glObjectEditor *editor)
296 gl_debug (DEBUG_EDITOR, "START");
299 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_size_spin));
301 gl_debug (DEBUG_EDITOR, "END");
306 /*****************************************************************************/
307 /* Set font weight. */
308 /*****************************************************************************/
310 gl_object_editor_set_font_weight (glObjectEditor *editor,
311 PangoWeight font_weight)
313 gl_debug (DEBUG_EDITOR, "START");
315 editor->priv->stop_signals = TRUE;
317 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle),
318 (font_weight == PANGO_WEIGHT_BOLD));
320 editor->priv->stop_signals = FALSE;
322 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");
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");
366 /*****************************************************************************/
367 /* Query font italic flag. */
368 /*****************************************************************************/
370 gl_object_editor_get_font_italic_flag (glObjectEditor *editor)
372 gboolean italic_flag;
374 gl_debug (DEBUG_EDITOR, "START");
377 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
378 (editor->priv->text_italic_toggle));
380 gl_debug (DEBUG_EDITOR, "END");
385 /*****************************************************************************/
386 /* Set text alignment. */
387 /*****************************************************************************/
389 gl_object_editor_set_text_alignment (glObjectEditor *editor,
390 PangoAlignment align)
392 gl_debug (DEBUG_EDITOR, "START");
394 editor->priv->stop_signals = TRUE;
396 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle),
397 (align == PANGO_ALIGN_LEFT));
398 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle),
399 (align == PANGO_ALIGN_CENTER));
400 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle),
401 (align == PANGO_ALIGN_RIGHT));
403 editor->priv->stop_signals = FALSE;
405 gl_debug (DEBUG_EDITOR, "END");
408 /*****************************************************************************/
409 /* Query text alignment. */
410 /*****************************************************************************/
412 gl_object_editor_get_text_alignment (glObjectEditor *editor)
414 PangoAlignment align;
416 gl_debug (DEBUG_EDITOR, "START");
418 if (gtk_toggle_button_get_active
419 (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle))) {
420 align = PANGO_ALIGN_LEFT;
422 if (gtk_toggle_button_get_active
423 (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle))) {
424 align = PANGO_ALIGN_RIGHT;
426 if (gtk_toggle_button_get_active
427 (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle))) {
428 align = PANGO_ALIGN_CENTER;
430 align = PANGO_ALIGN_LEFT; /* Should not happen. */
433 gl_debug (DEBUG_EDITOR, "END");
438 /*****************************************************************************/
439 /* Set text color. */
440 /*****************************************************************************/
442 gl_object_editor_set_text_color (glObjectEditor *editor,
444 glColorNode *text_color_node)
446 gl_debug (DEBUG_EDITOR, "START");
448 editor->priv->stop_signals = TRUE;
450 gl_debug (DEBUG_EDITOR, "color field %s(%d) / %X", text_color_node->key, text_color_node->field_flag, text_color_node->color);
452 gtk_widget_set_sensitive (editor->priv->text_color_key_radio, merge_flag);
454 if ( text_color_node->color == GL_COLOR_NONE ) {
456 gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->text_color_combo));
460 gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
461 text_color_node->color);
464 if (!text_color_node->field_flag) {
465 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
466 (editor->priv->text_color_radio), TRUE);
467 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
468 gl_debug (DEBUG_EDITOR, "color field false 0");
469 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
472 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
473 (editor->priv->text_color_key_radio), TRUE);
474 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
475 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
477 gl_debug (DEBUG_EDITOR, "color field true 1");
478 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->text_color_key_combo), "");
479 gl_debug (DEBUG_EDITOR, "color field true 2");
482 editor->priv->stop_signals = FALSE;
484 gl_debug (DEBUG_EDITOR, "END");
487 /*****************************************************************************/
488 /* Query text color. */
489 /*****************************************************************************/
491 gl_object_editor_get_text_color (glObjectEditor *editor)
494 glColorNode *color_node;
497 gl_debug (DEBUG_EDITOR, "START");
499 color_node = gl_color_node_new_default ();
501 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_key_radio))) {
502 color_node->field_flag = TRUE;
503 color_node->color = gl_prefs->default_text_color;
505 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->text_color_key_combo));
507 color_node->field_flag = FALSE;
508 color_node->key = NULL;
509 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
513 color_node->color = gl_prefs->default_text_color;
515 color_node->color = color;
519 gl_debug (DEBUG_EDITOR, "END");
525 /*****************************************************************************/
526 /* Set text line spacing. */
527 /*****************************************************************************/
529 gl_object_editor_set_text_line_spacing (glObjectEditor *editor,
530 gdouble text_line_spacing)
532 gl_debug (DEBUG_EDITOR, "START");
534 editor->priv->stop_signals = TRUE;
536 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_line_spacing_spin),
539 editor->priv->stop_signals = FALSE;
541 gl_debug (DEBUG_EDITOR, "END");
544 /*****************************************************************************/
545 /* Query text line spacing. */
546 /*****************************************************************************/
548 gl_object_editor_get_text_line_spacing (glObjectEditor *editor)
550 gdouble text_line_spacing;
552 gl_debug (DEBUG_EDITOR, "START");
555 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_line_spacing_spin));
557 gl_debug (DEBUG_EDITOR, "END");
559 return text_line_spacing;
562 /*****************************************************************************/
563 /* Set auto shrink checkbox. */
564 /*****************************************************************************/
566 gl_object_editor_set_text_auto_shrink (glObjectEditor *editor,
567 gboolean auto_shrink)
569 gl_debug (DEBUG_EDITOR, "START");
571 editor->priv->stop_signals = TRUE;
573 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check),
576 editor->priv->stop_signals = FALSE;
578 gl_debug (DEBUG_EDITOR, "END");
581 /*****************************************************************************/
582 /* Query auto shrink checkbox. */
583 /*****************************************************************************/
584 gboolean gl_object_editor_get_text_auto_shrink (glObjectEditor *editor)
586 gboolean auto_shrink;
588 gl_debug (DEBUG_EDITOR, "START");
591 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check));
593 gl_debug (DEBUG_EDITOR, "END");
598 /*--------------------------------------------------------------------------*/
599 /* PRIVATE. color radio callback. */
600 /*--------------------------------------------------------------------------*/
602 text_radio_toggled_cb (glObjectEditor *editor)
604 if (editor->priv->stop_signals) return;
606 gl_debug (DEBUG_EDITOR, "START");
608 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio))) {
609 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
610 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
612 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
613 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
617 /* Emit our "changed" signal */
618 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
620 gl_debug (DEBUG_EDITOR, "END");