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 * property-bar.c: gLabels property bar
8 * Copyright (C) 2003-2008 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
27 #include "ui-property-bar.h"
29 #include <glib/gi18n.h>
30 #include <gtk/gtkbuilder.h>
31 #include <gtk/gtkcombobox.h>
32 #include <gtk/gtkspinbutton.h>
33 #include <gtk/gtktoolbar.h>
34 #include <gtk/gtktoggletoolbutton.h>
35 #include <gtk/gtktooltips.h>
39 #include "color-combo.h"
40 #include "stock-pixmaps/stockpixbufs.h"
47 /*===========================================================================*/
48 /* Private macros and constants. */
49 /*===========================================================================*/
52 /*===========================================================================*/
53 /* Private data types */
54 /*===========================================================================*/
56 struct _glUIPropertyBarPrivate {
65 GtkWidget *font_family_combo;
66 GtkWidget *font_size_spin;
67 GtkWidget *font_bold_toggle;
68 GtkWidget *font_italic_toggle;
70 /* Text alignemnt radios */
71 GtkWidget *text_align_left_radio;
72 GtkWidget *text_align_center_radio;
73 GtkWidget *text_align_right_radio;
76 GtkWidget *text_color_eventbox;
77 GtkWidget *text_color_combo;
78 GtkWidget *fill_color_combo;
79 GtkWidget *fill_color_eventbox;
80 GtkWidget *line_color_combo;
81 GtkWidget *line_color_eventbox;
84 GtkWidget *line_width_spin;
86 /* Prevent recursion */
87 gboolean stop_signals;
91 /*===========================================================================*/
93 /*===========================================================================*/
96 /*===========================================================================*/
97 /* Local function prototypes */
98 /*===========================================================================*/
100 static void gl_ui_property_bar_finalize (GObject *object);
102 static void gl_ui_property_bar_construct (glUIPropertyBar *this);
104 static void selection_changed_cb (glUIPropertyBar *this);
106 static void font_family_changed_cb (GtkComboBox *combo,
107 glUIPropertyBar *this);
109 static void font_size_changed_cb (GtkSpinButton *spin,
110 glUIPropertyBar *this);
112 static void text_color_changed_cb (glColorCombo *cc,
115 glUIPropertyBar *this);
117 static void fill_color_changed_cb (glColorCombo *cc,
120 glUIPropertyBar *this);
122 static void line_color_changed_cb (glColorCombo *cc,
125 glUIPropertyBar *this);
127 static void line_width_changed_cb (GtkSpinButton *spin,
128 glUIPropertyBar *this);
130 static void font_bold_toggled_cb (GtkToggleToolButton *toggle,
131 glUIPropertyBar *this);
133 static void font_italic_toggled_cb (GtkToggleToolButton *toggle,
134 glUIPropertyBar *this);
136 static void text_align_toggled_cb (GtkToggleToolButton *toggle,
137 glUIPropertyBar *this);
139 static void set_doc_items_sensitive (glUIPropertyBar *this,
142 static void set_text_items_sensitive (glUIPropertyBar *this,
145 static void set_fill_items_sensitive (glUIPropertyBar *this,
148 static void set_line_color_items_sensitive (glUIPropertyBar *this,
151 static void set_line_width_items_sensitive (glUIPropertyBar *this,
156 /****************************************************************************/
157 /* Boilerplate Object stuff. */
158 /****************************************************************************/
159 G_DEFINE_TYPE (glUIPropertyBar, gl_ui_property_bar, GTK_TYPE_HBOX);
163 gl_ui_property_bar_class_init (glUIPropertyBarClass *class)
165 GObjectClass *object_class = G_OBJECT_CLASS (class);
167 gl_debug (DEBUG_PROPERTY_BAR, "START");
169 gl_ui_property_bar_parent_class = g_type_class_peek_parent (class);
171 object_class->finalize = gl_ui_property_bar_finalize;
173 gl_debug (DEBUG_PROPERTY_BAR, "END");
178 gl_ui_property_bar_init (glUIPropertyBar *this)
180 gl_debug (DEBUG_PROPERTY_BAR, "START");
182 this->priv = g_new0 (glUIPropertyBarPrivate, 1);
184 gl_debug (DEBUG_PROPERTY_BAR, "END");
189 gl_ui_property_bar_finalize (GObject *object)
191 glUIPropertyBar *this = GL_UI_PROPERTY_BAR (object);
193 gl_debug (DEBUG_PROPERTY_BAR, "START");
195 g_return_if_fail (object != NULL);
196 g_return_if_fail (GL_IS_UI_PROPERTY_BAR (object));
198 if (this->priv->view)
200 g_object_unref (G_OBJECT(this->priv->view));
204 g_object_unref (G_OBJECT(this->priv->gui));
208 G_OBJECT_CLASS (gl_ui_property_bar_parent_class)->finalize (object);
210 gl_debug (DEBUG_PROPERTY_BAR, "END");
214 /****************************************************************************/
215 /* Create a NEW property_bar. */
216 /****************************************************************************/
218 gl_ui_property_bar_new (void)
220 glUIPropertyBar *this;
222 gl_debug (DEBUG_PROPERTY_BAR, "START");
224 this = g_object_new (GL_TYPE_UI_PROPERTY_BAR, NULL);
226 gl_ui_property_bar_construct (this);
228 gl_debug (DEBUG_PROPERTY_BAR, "END");
230 return GTK_WIDGET (this);
234 /******************************************************************************/
235 /* Initialize property toolbar. */
236 /******************************************************************************/
238 gl_ui_property_bar_construct (glUIPropertyBar *this)
241 GError *error = NULL;
242 GList *family_names = NULL;
244 GdkPixbuf *pixbuf = NULL;
246 gl_debug (DEBUG_PROPERTY_BAR, "START");
248 this->priv->stop_signals = TRUE;
250 gui = gtk_builder_new ();
251 gtk_builder_add_from_file (gui,
252 GLABELS_BUILDER_DIR "property-bar.builder",
255 g_critical ("%s\n\ngLabels may not be installed correctly!", error->message);
256 g_error_free (error);
260 gl_util_get_builder_widgets (gui,
261 "property_toolbar", &this->priv->tool_bar,
262 "font_family_combo", &this->priv->font_family_combo,
263 "font_size_spin", &this->priv->font_size_spin,
264 "font_bold_toggle", &this->priv->font_bold_toggle,
265 "font_italic_toggle", &this->priv->font_italic_toggle,
266 "text_align_left_radio", &this->priv->text_align_left_radio,
267 "text_align_center_radio", &this->priv->text_align_center_radio,
268 "text_align_right_radio", &this->priv->text_align_right_radio,
269 "text_color_eventbox", &this->priv->text_color_eventbox,
270 "fill_color_eventbox", &this->priv->fill_color_eventbox,
271 "line_color_eventbox", &this->priv->line_color_eventbox,
272 "line_width_spin", &this->priv->line_width_spin,
275 gtk_container_add (GTK_CONTAINER (this), this->priv->tool_bar);
277 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_text_24, FALSE, NULL);
278 this->priv->text_color_combo =
279 gl_color_combo_new (pixbuf,
281 GL_COLOR_TEXT_DEFAULT,
282 gl_prefs->default_text_color);
283 gl_color_combo_set_relief (GL_COLOR_COMBO(this->priv->text_color_combo),
285 g_object_unref (G_OBJECT (pixbuf));
286 gtk_container_add (GTK_CONTAINER (this->priv->text_color_eventbox),
287 this->priv->text_color_combo);
289 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_bucket_fill_24, FALSE, NULL);
290 this->priv->fill_color_combo =
291 gl_color_combo_new (pixbuf,
294 gl_prefs->default_fill_color);
295 gl_color_combo_set_relief (GL_COLOR_COMBO(this->priv->fill_color_combo),
297 g_object_unref (G_OBJECT (pixbuf));
298 gtk_container_add (GTK_CONTAINER (this->priv->fill_color_eventbox),
299 this->priv->fill_color_combo);
301 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_pencil_24, FALSE, NULL);
302 this->priv->line_color_combo =
303 gl_color_combo_new (pixbuf,
306 gl_prefs->default_line_color);
307 gl_color_combo_set_relief (GL_COLOR_COMBO(this->priv->line_color_combo),
309 g_object_unref (G_OBJECT (pixbuf));
310 gtk_container_add (GTK_CONTAINER (this->priv->line_color_eventbox),
311 this->priv->line_color_combo);
313 /* Save reference to gui tree so we don't lose tooltips */
314 this->priv->gui = gui;
316 set_doc_items_sensitive (this, FALSE);
318 /* Font family entry widget */
319 gl_util_combo_box_add_text_model (GTK_COMBO_BOX (this->priv->font_family_combo));
320 family_names = gl_util_get_font_family_list ();
321 gl_util_combo_box_set_strings (GTK_COMBO_BOX (this->priv->font_family_combo),
323 gtk_widget_set_size_request (this->priv->font_family_combo, 200, -1);
325 /* Make sure we have a valid font. if not provide a good default. */
326 family_node = g_list_find_custom (family_names,
327 gl_prefs->default_font_family,
328 (GCompareFunc)g_utf8_collate);
331 gtk_combo_box_set_active (GTK_COMBO_BOX (this->priv->font_family_combo),
332 g_list_position (family_names,
337 gtk_combo_box_set_active (GTK_COMBO_BOX (this->priv->font_family_combo), 0);
339 gl_util_font_family_list_free (family_names);
341 g_signal_connect (G_OBJECT (this->priv->font_family_combo),
342 "changed", G_CALLBACK (font_family_changed_cb), this);
344 /* Font size entry widget */
345 gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->font_size_spin),
346 gl_prefs->default_font_size);
348 g_signal_connect (G_OBJECT (this->priv->font_size_spin),
349 "changed", G_CALLBACK (font_size_changed_cb), this);
352 /* Bold and Italic toggles */
353 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_bold_toggle),
354 (gl_prefs->default_font_weight == PANGO_WEIGHT_BOLD));
355 g_signal_connect (G_OBJECT (this->priv->font_bold_toggle),
356 "toggled", G_CALLBACK (font_bold_toggled_cb), this);
357 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_italic_toggle),
358 gl_prefs->default_font_italic_flag);
359 g_signal_connect (G_OBJECT (this->priv->font_italic_toggle),
360 "toggled", G_CALLBACK (font_italic_toggled_cb), this);
363 /* Text alignment radio group */
364 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio),
365 (gl_prefs->default_text_alignment == PANGO_ALIGN_LEFT));
366 g_signal_connect (G_OBJECT (this->priv->text_align_left_radio),
367 "toggled", G_CALLBACK (text_align_toggled_cb), this);
368 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio),
369 (gl_prefs->default_text_alignment == PANGO_ALIGN_CENTER));
370 g_signal_connect (G_OBJECT (this->priv->text_align_center_radio),
371 "toggled", G_CALLBACK (text_align_toggled_cb), this);
372 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
373 (gl_prefs->default_text_alignment == PANGO_ALIGN_RIGHT));
374 g_signal_connect (G_OBJECT (this->priv->text_align_right_radio),
375 "toggled", G_CALLBACK (text_align_toggled_cb), this);
377 /* Text color widget */
378 gl_color_combo_set_color (GL_COLOR_COMBO (this->priv->text_color_combo), gl_prefs->default_text_color);
379 g_signal_connect (G_OBJECT (this->priv->text_color_combo),
381 G_CALLBACK (text_color_changed_cb), this);
383 /* Fill color widget */
384 gl_color_combo_set_color (GL_COLOR_COMBO (this->priv->fill_color_combo), gl_prefs->default_fill_color);
385 g_signal_connect (G_OBJECT (this->priv->fill_color_combo),
387 G_CALLBACK (fill_color_changed_cb), this);
389 /* Line color widget */
390 gl_color_combo_set_color (GL_COLOR_COMBO (this->priv->line_color_combo), gl_prefs->default_line_color);
391 g_signal_connect (G_OBJECT (this->priv->line_color_combo),
393 G_CALLBACK (line_color_changed_cb), this);
395 /* Line width entry widget */
396 g_signal_connect (G_OBJECT (this->priv->line_width_spin),
398 G_CALLBACK (line_width_changed_cb), this);
400 this->priv->stop_signals = FALSE;
402 gl_debug (DEBUG_PROPERTY_BAR, "END");
406 /****************************************************************************/
407 /* Fill widgets with default values. */
408 /****************************************************************************/
410 reset_to_default_properties (glView *view,
411 glUIPropertyBar *this)
414 gchar *good_font_family;
416 /* Make sure we have a valid font. if not provide a good default. */
417 family_names = gl_util_get_font_family_list ();
418 if (g_list_find_custom (family_names,
419 view->default_font_family,
420 (GCompareFunc)g_utf8_collate))
422 good_font_family = g_strdup (view->default_font_family);
426 if (family_names != NULL)
428 good_font_family = g_strdup (family_names->data); /* 1st entry */
432 good_font_family = NULL;
435 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (this->priv->font_family_combo),
437 g_free (good_font_family);
438 gl_util_font_family_list_free (family_names);
440 gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->font_size_spin),
441 view->default_font_size);
443 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_bold_toggle),
444 (view->default_font_weight == PANGO_WEIGHT_BOLD));
445 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_italic_toggle),
446 view->default_font_italic_flag);
448 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio),
449 (view->default_text_alignment == PANGO_ALIGN_LEFT));
450 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio),
451 (view->default_text_alignment == PANGO_ALIGN_CENTER));
452 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
453 (view->default_text_alignment == PANGO_ALIGN_RIGHT));
455 gl_color_combo_set_color (GL_COLOR_COMBO(this->priv->text_color_combo), view->default_text_color);
457 gl_color_combo_set_color (GL_COLOR_COMBO(this->priv->fill_color_combo), view->default_fill_color);
459 gl_color_combo_set_color (GL_COLOR_COMBO(this->priv->line_color_combo), view->default_line_color);
461 gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->line_width_spin),
462 view->default_line_width);
466 /****************************************************************************/
467 /* Set view associated with property_bar. */
468 /****************************************************************************/
470 gl_ui_property_bar_set_view (glUIPropertyBar *this,
475 gl_debug (DEBUG_PROPERTY_BAR, "START");
477 g_return_if_fail (view && GL_IS_VIEW (view));
479 g_return_if_fail (label && GL_IS_LABEL (label));
481 set_doc_items_sensitive (this, TRUE);
483 this->priv->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
485 reset_to_default_properties (view, this);
487 g_signal_connect_swapped (G_OBJECT(view), "selection_changed",
488 G_CALLBACK(selection_changed_cb), this);
490 g_signal_connect_swapped (G_OBJECT(view->label), "changed",
491 G_CALLBACK(selection_changed_cb), this);
493 gl_debug (DEBUG_PROPERTY_BAR, "END");
497 /****************************************************************************/
498 /** Set visiblity of property bar's tooltips. */
499 /****************************************************************************/
501 gl_ui_property_bar_set_tooltips (glUIPropertyBar *this,
504 GtkTooltipsData *data;
506 gl_debug (DEBUG_PROPERTY_BAR, "START");
508 g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR(this));
510 /* HACK: peek into one of our widgets to get the tooltips group created by builder. */
511 data = gtk_tooltips_data_get (this->priv->font_size_spin);
512 g_return_if_fail (data);
516 gtk_tooltips_enable (data->tooltips);
520 gtk_tooltips_disable (data->tooltips);
523 gl_debug (DEBUG_PROPERTY_BAR, "END");
527 /*---------------------------------------------------------------------------*/
528 /* PRIVATE. View "selection state changed" callback. */
529 /*---------------------------------------------------------------------------*/
531 update_text_properties (glView *view,
532 glUIPropertyBar *this)
534 gboolean can_text, is_first_object;
535 gboolean is_same_font_family, is_same_font_size;
536 gboolean is_same_text_color, is_same_is_italic;
537 gboolean is_same_is_bold, is_same_align;
539 glLabelObject *object;
540 gchar *selection_font_family, *font_family;
541 gdouble selection_font_size, font_size;
542 guint selection_text_color, text_color;
543 glColorNode *text_color_node;
544 gboolean selection_is_italic, is_italic;
545 gboolean selection_is_bold, is_bold;
546 PangoAlignment selection_align, align;
548 can_text = gl_view_can_selection_text (view);
549 set_text_items_sensitive (this, can_text);
559 is_same_font_family = TRUE;
560 selection_font_family = NULL;
561 selection_font_size = -1;
562 selection_align = PANGO_ALIGN_LEFT;
563 selection_is_italic = TRUE;
564 selection_is_bold = TRUE;
565 selection_text_color = 0;
567 is_first_object = TRUE;
569 for (p = view->selected_object_list; p != NULL; p = p->next)
572 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
573 if (!gl_label_object_can_text (object))
576 font_family = gl_label_object_get_font_family (object);
577 if (font_family != NULL)
579 if (selection_font_family == NULL)
581 selection_font_family = g_strdup (font_family);
585 if (strcmp (font_family, selection_font_family) != 0)
587 is_same_font_family = FALSE;
590 g_free (font_family);
593 font_size = gl_label_object_get_font_size (object);
595 text_color_node = gl_label_object_get_text_color (object);
596 if (text_color_node->field_flag)
598 /* If a merge field is set we use the default color for merged color*/
599 text_color = GL_COLOR_MERGE_DEFAULT;
604 text_color = text_color_node->color;
606 gl_color_node_free (&text_color_node);
608 is_italic = gl_label_object_get_font_italic_flag (object);
609 is_bold = gl_label_object_get_font_weight (object) == PANGO_WEIGHT_BOLD;
610 align = gl_label_object_get_text_alignment (object);
614 selection_font_size = font_size;
615 selection_text_color = text_color;
616 selection_is_italic = is_italic;
617 selection_is_bold = is_bold;
618 selection_align = align;
622 if (font_size != selection_font_size)
623 is_same_font_size = FALSE;
624 if (text_color != selection_text_color)
625 is_same_text_color = FALSE;
626 if (is_italic != selection_is_italic)
627 is_same_is_italic = FALSE;
628 if (is_bold != selection_is_bold)
629 is_same_is_bold = FALSE;
630 if (align != selection_align)
631 is_same_align = FALSE;
633 is_first_object = FALSE;
636 if (is_same_font_family && (selection_font_family != NULL))
637 gl_debug (DEBUG_PROPERTY_BAR, "same font family = %s",
638 selection_font_family);
639 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (this->priv->font_family_combo),
640 is_same_font_family?selection_font_family:"");
641 g_free (selection_font_family);
643 if (is_same_font_size)
645 gl_debug (DEBUG_PROPERTY_BAR, "same font size = %g",
646 selection_font_size);
647 gtk_spin_button_set_value (GTK_SPIN_BUTTON (this->priv->font_size_spin),
648 selection_font_size);
652 gtk_entry_set_text (GTK_ENTRY (this->priv->font_size_spin), "");
655 if (is_same_text_color)
657 gl_debug (DEBUG_PROPERTY_BAR, "same text color = %08x", selection_text_color);
658 gl_color_combo_set_color (GL_COLOR_COMBO (this->priv->text_color_combo),
659 selection_text_color);
662 if (is_same_is_italic)
664 gl_debug (DEBUG_PROPERTY_BAR, "same italic flag = %d",
665 selection_is_italic);
667 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_italic_toggle),
668 selection_is_italic && is_same_is_italic);
672 gl_debug (DEBUG_PROPERTY_BAR, "same bold flag = %d",
675 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_bold_toggle),
676 selection_is_bold && is_same_is_bold);
679 gl_debug (DEBUG_PROPERTY_BAR, "same align");
680 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio),
681 (selection_align == PANGO_ALIGN_LEFT) &&
683 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio),
684 (selection_align == PANGO_ALIGN_CENTER) &&
686 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
687 (selection_align == PANGO_ALIGN_RIGHT) &&
693 update_fill_color (glView *view,
694 glUIPropertyBar *this)
696 gboolean can, is_first_object;
697 gboolean is_same_fill_color;
699 glLabelObject *object;
700 guint selection_fill_color, fill_color;
701 glColorNode *fill_color_node;
703 can = gl_view_can_selection_fill (view);
704 set_fill_items_sensitive (this, can);
709 is_same_fill_color = TRUE;
710 is_first_object = TRUE;
711 selection_fill_color = 0;
713 for (p = view->selected_object_list; p != NULL; p = p->next)
716 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
717 if (!gl_label_object_can_fill (object))
720 fill_color_node = gl_label_object_get_fill_color (object);
721 if (fill_color_node->field_flag)
723 /* If a merge field is set we use the default color for merged color*/
724 fill_color = GL_COLOR_FILL_MERGE_DEFAULT;
729 fill_color = fill_color_node->color;
731 gl_color_node_free (&fill_color_node);
735 selection_fill_color = fill_color;
739 if (fill_color != selection_fill_color)
741 is_same_fill_color = FALSE;
744 is_first_object = FALSE;
747 if (is_same_fill_color)
749 gl_debug (DEBUG_PROPERTY_BAR, "same fill color = %08x", selection_fill_color);
750 gl_color_combo_set_color (GL_COLOR_COMBO (this->priv->fill_color_combo),
751 selection_fill_color);
757 update_line_color (glView *view,
758 glUIPropertyBar *this)
760 gboolean can, is_first_object;
761 gboolean is_same_line_color;
763 glLabelObject *object;
764 guint selection_line_color, line_color;
765 glColorNode *line_color_node;
767 can = gl_view_can_selection_line_color (view);
768 set_line_color_items_sensitive (this, can);
773 is_same_line_color = TRUE;
774 is_first_object = TRUE;
775 selection_line_color = 0;
777 for (p = view->selected_object_list; p != NULL; p = p->next)
780 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
781 if (!gl_label_object_can_line_color (object))
784 line_color_node = gl_label_object_get_line_color (object);
785 if (line_color_node->field_flag)
787 /* If a merge field is set we use the default color for merged color*/
788 line_color = GL_COLOR_MERGE_DEFAULT;
793 line_color = line_color_node->color;
795 gl_color_node_free (&line_color_node);
799 selection_line_color = line_color;
803 if (line_color != selection_line_color)
805 is_same_line_color = FALSE;
808 is_first_object = FALSE;
811 if (is_same_line_color)
813 gl_debug (DEBUG_PROPERTY_BAR, "same line color = %08x", selection_line_color);
814 gl_color_combo_set_color (GL_COLOR_COMBO (this->priv->line_color_combo),
815 selection_line_color);
821 update_line_width (glView *view,
822 glUIPropertyBar *this)
824 gboolean can, is_first_object;
825 gboolean is_same_line_width;
827 glLabelObject *object;
828 gdouble selection_line_width, line_width;
830 can = gl_view_can_selection_line_width (view);
831 set_line_width_items_sensitive (this, can);
836 is_same_line_width = TRUE;
837 is_first_object = TRUE;
838 selection_line_width = 0;
840 for (p = view->selected_object_list; p != NULL; p = p->next)
843 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
844 if (!gl_label_object_can_line_width (object))
847 line_width = gl_label_object_get_line_width (object);
851 selection_line_width = line_width;
855 if (line_width != selection_line_width)
857 is_same_line_width = FALSE;
860 is_first_object = FALSE;
863 if (is_same_line_width)
865 gl_debug (DEBUG_PROPERTY_BAR, "same line width = %g", selection_line_width);
866 gtk_spin_button_set_value (GTK_SPIN_BUTTON (this->priv->line_width_spin),
867 selection_line_width);
871 gtk_entry_set_text (GTK_ENTRY (this->priv->line_width_spin), "");
877 selection_changed_cb (glUIPropertyBar *this)
879 glView *view = this->priv->view;
881 g_return_if_fail (view && GL_IS_VIEW (view));
882 g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
884 if (this->priv->stop_signals) return;
885 this->priv->stop_signals = TRUE;
887 gl_debug (DEBUG_PROPERTY_BAR, "START");
889 if (gl_view_is_selection_empty (view))
891 /* No selection: make all controls active. */
892 reset_to_default_properties (view, this);
893 set_doc_items_sensitive (this, TRUE);
897 update_text_properties (view, this);
898 update_fill_color (view, this);
899 update_line_color (view, this);
900 update_line_width (view, this);
903 gl_debug (DEBUG_PROPERTY_BAR, "END");
905 this->priv->stop_signals = FALSE;
909 /*--------------------------------------------------------------------------*/
910 /* PRIVATE. Font family entry changed. */
911 /*--------------------------------------------------------------------------*/
913 font_family_changed_cb (GtkComboBox *combo,
914 glUIPropertyBar *this)
918 if (this->priv->stop_signals) return;
919 this->priv->stop_signals = TRUE;
921 gl_debug (DEBUG_PROPERTY_BAR, "START");
923 font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
924 if ( strlen(font_family) )
926 gl_view_set_selection_font_family (this->priv->view,
928 gl_view_set_default_font_family (this->priv->view,
931 g_free (font_family);
933 gl_debug (DEBUG_PROPERTY_BAR, "END");
935 this->priv->stop_signals = FALSE;
939 /*--------------------------------------------------------------------------*/
940 /* PRIVATE. Font size spin button changed. */
941 /*--------------------------------------------------------------------------*/
943 font_size_changed_cb (GtkSpinButton *spin,
944 glUIPropertyBar *this)
948 if (this->priv->stop_signals) return;
949 this->priv->stop_signals = TRUE;
951 gl_debug (DEBUG_PROPERTY_BAR, "START");
953 font_size = gtk_spin_button_get_value (spin);
955 gl_view_set_selection_font_size (this->priv->view,
957 gl_view_set_default_font_size (this->priv->view,
960 gl_debug (DEBUG_PROPERTY_BAR, "END");
962 this->priv->stop_signals = FALSE;
966 /*--------------------------------------------------------------------------*/
967 /* PRIVATE. Text color combo changed. */
968 /*--------------------------------------------------------------------------*/
970 text_color_changed_cb (glColorCombo *cc,
973 glUIPropertyBar *this)
975 glColorNode *text_color_node;
977 g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
979 if (this->priv->stop_signals) return;
980 this->priv->stop_signals = TRUE;
982 gl_debug (DEBUG_PROPERTY_BAR, "START");
984 text_color_node = gl_color_node_new_default ();
985 text_color_node->color = color;
987 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
992 text_color_node->color = gl_prefs->default_text_color;
993 gl_view_set_selection_text_color (this->priv->view,
995 gl_view_set_default_text_color (this->priv->view,
996 gl_prefs->default_text_color);
1000 gl_view_set_selection_text_color (this->priv->view,
1002 gl_view_set_default_text_color (this->priv->view,
1003 text_color_node->color);
1006 gl_color_node_free (&text_color_node);
1008 gl_debug (DEBUG_PROPERTY_BAR, "END");
1010 this->priv->stop_signals = FALSE;
1014 /*--------------------------------------------------------------------------*/
1015 /* PRIVATE. Fill color combo changed. */
1016 /*--------------------------------------------------------------------------*/
1018 fill_color_changed_cb (glColorCombo *cc,
1020 gboolean is_default,
1021 glUIPropertyBar *this)
1023 glColorNode *fill_color_node;
1025 g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
1027 if (this->priv->stop_signals) return;
1028 this->priv->stop_signals = TRUE;
1030 gl_debug (DEBUG_PROPERTY_BAR, "START");
1032 fill_color_node = gl_color_node_new_default ();
1034 fill_color_node->color = color;
1036 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
1042 fill_color_node->color = GL_COLOR_NONE;
1043 gl_view_set_selection_fill_color (this->priv->view,
1045 gl_view_set_default_fill_color (this->priv->view,
1046 fill_color_node->color);
1050 gl_view_set_selection_fill_color (this->priv->view,
1052 gl_view_set_default_fill_color (this->priv->view,
1053 fill_color_node->color);
1055 gl_color_node_free (&fill_color_node);
1057 gl_debug (DEBUG_PROPERTY_BAR, "END");
1059 this->priv->stop_signals = FALSE;
1063 /*--------------------------------------------------------------------------*/
1064 /* PRIVATE. Line color combo changed. */
1065 /*--------------------------------------------------------------------------*/
1067 line_color_changed_cb (glColorCombo *cc,
1069 gboolean is_default,
1070 glUIPropertyBar *this)
1072 glColorNode *line_color_node;
1074 g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
1076 if (this->priv->stop_signals) return;
1077 this->priv->stop_signals = TRUE;
1079 gl_debug (DEBUG_PROPERTY_BAR, "START");
1081 line_color_node = gl_color_node_new_default ();
1082 line_color_node->color = color;
1084 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
1089 line_color_node->color = GL_COLOR_NONE;
1090 gl_view_set_selection_line_color (this->priv->view,
1092 gl_view_set_default_line_color (this->priv->view,
1093 line_color_node->color);
1097 gl_view_set_selection_line_color (this->priv->view,
1099 gl_view_set_default_line_color (this->priv->view,
1100 line_color_node->color);
1102 gl_color_node_free (&line_color_node);
1104 gl_debug (DEBUG_PROPERTY_BAR, "END");
1106 this->priv->stop_signals = FALSE;
1110 /*--------------------------------------------------------------------------*/
1111 /* PRIVATE. Line width spin button changed. */
1112 /*--------------------------------------------------------------------------*/
1114 line_width_changed_cb (GtkSpinButton *spin,
1115 glUIPropertyBar *this)
1119 if (this->priv->stop_signals) return;
1120 this->priv->stop_signals = TRUE;
1122 gl_debug (DEBUG_PROPERTY_BAR, "START");
1124 if (this->priv->view)
1126 line_width = gtk_spin_button_get_value (spin);
1128 gl_view_set_selection_line_width (this->priv->view,
1130 gl_view_set_default_line_width (this->priv->view,
1134 gl_debug (DEBUG_PROPERTY_BAR, "END");
1136 this->priv->stop_signals = FALSE;
1140 /*---------------------------------------------------------------------------*/
1141 /* PRIVATE. Font bold toggled callback. */
1142 /*---------------------------------------------------------------------------*/
1144 font_bold_toggled_cb (GtkToggleToolButton *toggle,
1145 glUIPropertyBar *this)
1151 if (this->priv->stop_signals) return;
1152 this->priv->stop_signals = TRUE;
1154 gl_debug (DEBUG_PROPERTY_BAR, "START");
1156 state = gtk_toggle_tool_button_get_active (toggle);
1158 weight = state ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
1160 gl_view_set_selection_font_weight (this->priv->view, weight);
1161 gl_view_set_default_font_weight (this->priv->view, weight);
1163 gl_debug (DEBUG_PROPERTY_BAR, "END");
1165 this->priv->stop_signals = FALSE;
1169 /*---------------------------------------------------------------------------*/
1170 /* PRIVATE. Font italic toggled callback. */
1171 /*---------------------------------------------------------------------------*/
1173 font_italic_toggled_cb (GtkToggleToolButton *toggle,
1174 glUIPropertyBar *this)
1178 if (this->priv->stop_signals) return;
1179 this->priv->stop_signals = TRUE;
1181 gl_debug (DEBUG_PROPERTY_BAR, "START");
1183 state = gtk_toggle_tool_button_get_active (toggle);
1185 gl_view_set_selection_font_italic_flag (this->priv->view, state);
1186 gl_view_set_default_font_italic_flag (this->priv->view, state);
1188 gl_debug (DEBUG_PROPERTY_BAR, "END");
1190 this->priv->stop_signals = FALSE;
1194 /*---------------------------------------------------------------------------*/
1195 /* PRIVATE. Text align toggled callback. */
1196 /*---------------------------------------------------------------------------*/
1198 text_align_toggled_cb (GtkToggleToolButton *toggle,
1199 glUIPropertyBar *this)
1201 if (this->priv->stop_signals) return;
1202 this->priv->stop_signals = TRUE;
1204 gl_debug (DEBUG_PROPERTY_BAR, "START");
1206 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio)))
1208 gl_view_set_selection_text_alignment (this->priv->view,
1210 gl_view_set_default_text_alignment (this->priv->view,
1214 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio)))
1216 gl_view_set_selection_text_alignment (this->priv->view,
1217 PANGO_ALIGN_CENTER);
1218 gl_view_set_default_text_alignment (this->priv->view,
1219 PANGO_ALIGN_CENTER);
1222 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio)))
1224 gl_view_set_selection_text_alignment (this->priv->view,
1226 gl_view_set_default_text_alignment (this->priv->view,
1230 gl_debug (DEBUG_PROPERTY_BAR, "END");
1232 this->priv->stop_signals = FALSE;
1236 /*---------------------------------------------------------------------------*/
1237 /* PRIVATE. Set sensitivity of doc controls. */
1238 /*---------------------------------------------------------------------------*/
1240 set_doc_items_sensitive (glUIPropertyBar *this,
1243 gtk_widget_set_sensitive (this->priv->font_family_combo, state);
1244 gtk_widget_set_sensitive (this->priv->font_size_spin, state);
1245 gtk_widget_set_sensitive (this->priv->font_bold_toggle, state);
1246 gtk_widget_set_sensitive (this->priv->font_italic_toggle, state);
1247 gtk_widget_set_sensitive (this->priv->text_align_left_radio, state);
1248 gtk_widget_set_sensitive (this->priv->text_align_center_radio, state);
1249 gtk_widget_set_sensitive (this->priv->text_align_right_radio, state);
1250 gtk_widget_set_sensitive (this->priv->text_color_combo, state);
1251 gtk_widget_set_sensitive (this->priv->fill_color_combo, state);
1252 gtk_widget_set_sensitive (this->priv->line_color_combo, state);
1253 gtk_widget_set_sensitive (this->priv->line_width_spin, state);
1257 /*---------------------------------------------------------------------------*/
1258 /* PRIVATE. Set sensitivity of text related controls. */
1259 /*---------------------------------------------------------------------------*/
1261 set_text_items_sensitive (glUIPropertyBar *this,
1264 gtk_widget_set_sensitive (this->priv->font_family_combo, state);
1265 gtk_widget_set_sensitive (this->priv->font_size_spin, state);
1266 gtk_widget_set_sensitive (this->priv->font_bold_toggle, state);
1267 gtk_widget_set_sensitive (this->priv->font_italic_toggle, state);
1268 gtk_widget_set_sensitive (this->priv->text_align_left_radio, state);
1269 gtk_widget_set_sensitive (this->priv->text_align_center_radio, state);
1270 gtk_widget_set_sensitive (this->priv->text_align_right_radio, state);
1271 gtk_widget_set_sensitive (this->priv->text_color_combo, state);
1275 /*---------------------------------------------------------------------------*/
1276 /* PRIVATE. Set sensitivity of fill related controls. */
1277 /*---------------------------------------------------------------------------*/
1279 set_fill_items_sensitive (glUIPropertyBar *this,
1282 gtk_widget_set_sensitive (this->priv->fill_color_combo, state);
1286 /*---------------------------------------------------------------------------*/
1287 /* PRIVATE. Set sensitivity of line color related controls. */
1288 /*---------------------------------------------------------------------------*/
1290 set_line_color_items_sensitive (glUIPropertyBar *this,
1293 gtk_widget_set_sensitive (this->priv->line_color_combo, state);
1297 /*---------------------------------------------------------------------------*/
1298 /* PRIVATE. Set sensitivity of line width related controls. */
1299 /*---------------------------------------------------------------------------*/
1301 set_line_width_items_sensitive (glUIPropertyBar *this,
1304 gtk_widget_set_sensitive (this->priv->line_width_spin, state);