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 editor->priv->text_page_vbox =
76 glade_xml_get_widget (editor->priv->gui, "text_page_vbox");
77 editor->priv->text_family_combo =
78 glade_xml_get_widget (editor->priv->gui, "text_family_combo");
79 editor->priv->text_size_spin =
80 glade_xml_get_widget (editor->priv->gui, "text_size_spin");
81 editor->priv->text_bold_toggle =
82 glade_xml_get_widget (editor->priv->gui, "text_bold_toggle");
83 editor->priv->text_italic_toggle =
84 glade_xml_get_widget (editor->priv->gui, "text_italic_toggle");
85 editor->priv->text_color_combo =
86 glade_xml_get_widget (editor->priv->gui, "text_color_combo");
87 editor->priv->text_color_radio =
88 glade_xml_get_widget (editor->priv->gui, "text_color_radio");
89 editor->priv->text_color_key_radio =
90 glade_xml_get_widget (editor->priv->gui, "text_color_key_radio");
91 editor->priv->text_color_key_combo =
92 glade_xml_get_widget (editor->priv->gui, "text_color_key_combo");
93 editor->priv->text_left_toggle =
94 glade_xml_get_widget (editor->priv->gui, "text_left_toggle");
95 editor->priv->text_center_toggle =
96 glade_xml_get_widget (editor->priv->gui, "text_center_toggle");
97 editor->priv->text_right_toggle =
98 glade_xml_get_widget (editor->priv->gui, "text_right_toggle");
99 editor->priv->text_line_spacing_spin =
100 glade_xml_get_widget (editor->priv->gui, "text_line_spacing_spin");
101 editor->priv->text_auto_shrink_check =
102 glade_xml_get_widget (editor->priv->gui, "text_auto_shrink_check");
104 gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->text_family_combo));
105 gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->text_color_key_combo));
107 /* Load family names */
108 family_names = gl_util_get_font_family_list ();
109 gl_util_combo_box_set_strings (GTK_COMBO_BOX(editor->priv->text_family_combo),
111 gl_util_font_family_list_free (family_names);
114 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio), TRUE);
115 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
116 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
119 gtk_widget_show_all (editor->priv->text_page_vbox);
121 /* Connect signals */
122 g_signal_connect_swapped (G_OBJECT (editor->priv->text_family_combo),
124 G_CALLBACK (gl_object_editor_changed_cb),
126 g_signal_connect_swapped (G_OBJECT (editor->priv->text_size_spin),
128 G_CALLBACK (gl_object_editor_changed_cb),
130 g_signal_connect_swapped (G_OBJECT (editor->priv->text_bold_toggle),
132 G_CALLBACK (gl_object_editor_changed_cb),
134 g_signal_connect_swapped (G_OBJECT (editor->priv->text_italic_toggle),
136 G_CALLBACK (gl_object_editor_changed_cb),
138 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_combo),
140 G_CALLBACK (gl_object_editor_changed_cb),
142 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_combo),
144 G_CALLBACK (gl_object_editor_changed_cb),
146 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_radio),
148 G_CALLBACK (text_radio_toggled_cb),
150 g_signal_connect_swapped (G_OBJECT (editor->priv->text_color_key_radio),
152 G_CALLBACK (text_radio_toggled_cb),
155 g_signal_connect (G_OBJECT (editor->priv->text_left_toggle),
157 G_CALLBACK (align_toggle_cb),
159 g_signal_connect (G_OBJECT (editor->priv->text_center_toggle),
161 G_CALLBACK (align_toggle_cb),
163 g_signal_connect (G_OBJECT (editor->priv->text_right_toggle),
165 G_CALLBACK (align_toggle_cb),
168 g_signal_connect_swapped (G_OBJECT (editor->priv->text_line_spacing_spin),
170 G_CALLBACK (gl_object_editor_changed_cb),
173 g_signal_connect_swapped (G_OBJECT (editor->priv->text_auto_shrink_check),
175 G_CALLBACK (gl_object_editor_changed_cb),
178 gl_debug (DEBUG_EDITOR, "END");
181 /*--------------------------------------------------------------------------*/
182 /* PRIVATE. Alignment togglebutton callback. */
183 /*--------------------------------------------------------------------------*/
185 align_toggle_cb (GtkToggleButton *toggle,
186 glObjectEditor *editor)
188 if (editor->priv->stop_signals) return;
190 if (gtk_toggle_button_get_active (toggle)) {
192 if (GTK_WIDGET (toggle) == GTK_WIDGET (editor->priv->text_left_toggle)) {
193 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
194 (editor->priv->text_center_toggle),
196 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
197 (editor->priv->text_right_toggle),
199 } else if (GTK_WIDGET (toggle) ==
200 GTK_WIDGET (editor->priv->text_center_toggle)) {
201 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
202 (editor->priv->text_left_toggle),
204 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
205 (editor->priv->text_right_toggle),
207 } else if (GTK_WIDGET (toggle) ==
208 GTK_WIDGET (editor->priv->text_right_toggle)) {
209 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
210 (editor->priv->text_left_toggle),
212 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
213 (editor->priv->text_center_toggle),
217 /* Emit our "changed" signal */
218 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
223 /*****************************************************************************/
224 /* Set font family. */
225 /*****************************************************************************/
227 gl_object_editor_set_font_family (glObjectEditor *editor,
228 const gchar *font_family)
231 gchar *good_font_family;
233 gl_debug (DEBUG_EDITOR, "START");
235 editor->priv->stop_signals = TRUE;
237 /* Make sure we have a valid font family. if not provide a good default. */
238 family_names = gl_util_get_font_family_list ();
239 if (g_list_find_custom (family_names, font_family, (GCompareFunc)g_utf8_collate)) {
240 good_font_family = g_strdup (font_family);
242 if (family_names != NULL) {
243 good_font_family = g_strdup (family_names->data); /* 1st entry */
245 good_font_family = NULL;
248 gl_util_font_family_list_free (family_names);
249 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->text_family_combo), good_font_family);
250 g_free (good_font_family);
252 editor->priv->stop_signals = FALSE;
254 gl_debug (DEBUG_EDITOR, "END");
257 /*****************************************************************************/
258 /* Query font family. */
259 /*****************************************************************************/
261 gl_object_editor_get_font_family (glObjectEditor *editor)
265 gl_debug (DEBUG_EDITOR, "START");
267 font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->text_family_combo));
269 gl_debug (DEBUG_EDITOR, "END");
274 /*****************************************************************************/
276 /*****************************************************************************/
278 gl_object_editor_set_font_size (glObjectEditor *editor,
281 gl_debug (DEBUG_EDITOR, "START");
283 editor->priv->stop_signals = TRUE;
285 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_size_spin),
288 editor->priv->stop_signals = FALSE;
290 gl_debug (DEBUG_EDITOR, "END");
293 /*****************************************************************************/
294 /* Query font size. */
295 /*****************************************************************************/
297 gl_object_editor_get_font_size (glObjectEditor *editor)
301 gl_debug (DEBUG_EDITOR, "START");
304 gtk_spin_button_get_value (GTK_SPIN_BUTTON(editor->priv->text_size_spin));
306 gl_debug (DEBUG_EDITOR, "END");
311 /*****************************************************************************/
312 /* Set font weight. */
313 /*****************************************************************************/
315 gl_object_editor_set_font_weight (glObjectEditor *editor,
316 PangoWeight font_weight)
318 gl_debug (DEBUG_EDITOR, "START");
320 editor->priv->stop_signals = TRUE;
322 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle),
323 (font_weight == PANGO_WEIGHT_BOLD));
325 editor->priv->stop_signals = FALSE;
327 gl_debug (DEBUG_EDITOR, "END");
330 /*****************************************************************************/
331 /* Query font weight. */
332 /*****************************************************************************/
334 gl_object_editor_get_font_weight (glObjectEditor *editor)
336 PangoWeight font_weight;
338 gl_debug (DEBUG_EDITOR, "START");
340 if (gtk_toggle_button_get_active
341 (GTK_TOGGLE_BUTTON (editor->priv->text_bold_toggle))) {
342 font_weight = PANGO_WEIGHT_BOLD;
344 font_weight = PANGO_WEIGHT_NORMAL;
347 gl_debug (DEBUG_EDITOR, "END");
352 /*****************************************************************************/
353 /* Set font italic flag. */
354 /*****************************************************************************/
356 gl_object_editor_set_font_italic_flag (glObjectEditor *editor,
357 gboolean font_italic_flag)
359 gl_debug (DEBUG_EDITOR, "START");
361 editor->priv->stop_signals = TRUE;
363 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_italic_toggle),
366 editor->priv->stop_signals = FALSE;
368 gl_debug (DEBUG_EDITOR, "END");
371 /*****************************************************************************/
372 /* Query font italic flag. */
373 /*****************************************************************************/
375 gl_object_editor_get_font_italic_flag (glObjectEditor *editor)
377 gboolean italic_flag;
379 gl_debug (DEBUG_EDITOR, "START");
382 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON
383 (editor->priv->text_italic_toggle));
385 gl_debug (DEBUG_EDITOR, "END");
390 /*****************************************************************************/
391 /* Set text alignment. */
392 /*****************************************************************************/
394 gl_object_editor_set_text_alignment (glObjectEditor *editor,
395 PangoAlignment align)
397 gl_debug (DEBUG_EDITOR, "START");
399 editor->priv->stop_signals = TRUE;
401 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle),
402 (align == PANGO_ALIGN_LEFT));
403 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle),
404 (align == PANGO_ALIGN_CENTER));
405 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle),
406 (align == PANGO_ALIGN_RIGHT));
408 editor->priv->stop_signals = FALSE;
410 gl_debug (DEBUG_EDITOR, "END");
413 /*****************************************************************************/
414 /* Query text alignment. */
415 /*****************************************************************************/
417 gl_object_editor_get_text_alignment (glObjectEditor *editor)
419 PangoAlignment align;
421 gl_debug (DEBUG_EDITOR, "START");
423 if (gtk_toggle_button_get_active
424 (GTK_TOGGLE_BUTTON (editor->priv->text_left_toggle))) {
425 align = PANGO_ALIGN_LEFT;
427 if (gtk_toggle_button_get_active
428 (GTK_TOGGLE_BUTTON (editor->priv->text_right_toggle))) {
429 align = PANGO_ALIGN_RIGHT;
431 if (gtk_toggle_button_get_active
432 (GTK_TOGGLE_BUTTON (editor->priv->text_center_toggle))) {
433 align = PANGO_ALIGN_CENTER;
435 align = PANGO_ALIGN_LEFT; /* Should not happen. */
438 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");
492 /*****************************************************************************/
493 /* Query text color. */
494 /*****************************************************************************/
496 gl_object_editor_get_text_color (glObjectEditor *editor)
499 glColorNode *color_node;
502 gl_debug (DEBUG_EDITOR, "START");
504 color_node = gl_color_node_new_default ();
506 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_key_radio))) {
507 color_node->field_flag = TRUE;
508 color_node->color = gl_prefs->default_text_color;
510 gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->text_color_key_combo));
512 color_node->field_flag = FALSE;
513 color_node->key = NULL;
514 color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->text_color_combo),
518 color_node->color = gl_prefs->default_text_color;
520 color_node->color = color;
524 gl_debug (DEBUG_EDITOR, "END");
530 /*****************************************************************************/
531 /* Set text line spacing. */
532 /*****************************************************************************/
534 gl_object_editor_set_text_line_spacing (glObjectEditor *editor,
535 gdouble text_line_spacing)
537 gl_debug (DEBUG_EDITOR, "START");
539 editor->priv->stop_signals = TRUE;
541 gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->text_line_spacing_spin),
544 editor->priv->stop_signals = FALSE;
546 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;
567 /*****************************************************************************/
568 /* Set auto shrink checkbox. */
569 /*****************************************************************************/
571 gl_object_editor_set_text_auto_shrink (glObjectEditor *editor,
572 gboolean auto_shrink)
574 gl_debug (DEBUG_EDITOR, "START");
576 editor->priv->stop_signals = TRUE;
578 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check),
581 editor->priv->stop_signals = FALSE;
583 gl_debug (DEBUG_EDITOR, "END");
586 /*****************************************************************************/
587 /* Query auto shrink checkbox. */
588 /*****************************************************************************/
589 gboolean gl_object_editor_get_text_auto_shrink (glObjectEditor *editor)
591 gboolean auto_shrink;
593 gl_debug (DEBUG_EDITOR, "START");
596 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_auto_shrink_check));
598 gl_debug (DEBUG_EDITOR, "END");
603 /*--------------------------------------------------------------------------*/
604 /* PRIVATE. color radio callback. */
605 /*--------------------------------------------------------------------------*/
607 text_radio_toggled_cb (glObjectEditor *editor)
609 if (editor->priv->stop_signals) return;
611 gl_debug (DEBUG_EDITOR, "START");
613 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio))) {
614 gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
615 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, FALSE);
617 gtk_widget_set_sensitive (editor->priv->text_color_combo, FALSE);
618 gtk_widget_set_sensitive (editor->priv->text_color_key_combo, TRUE);
622 /* Emit our "changed" signal */
623 g_signal_emit (G_OBJECT (editor), gl_object_editor_signals[CHANGED], 0);
625 gl_debug (DEBUG_EDITOR, "END");