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 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 <glade/glade-xml.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 "mygal/widget-color-combo.h"
40 #include "stock-pixmaps/stockpixbufs.h"
46 /*===========================================================================*/
47 /* Private macros and constants. */
48 /*===========================================================================*/
50 /*===========================================================================*/
51 /* Private data types */
52 /*===========================================================================*/
54 struct _glUIPropertyBarPrivate {
63 GtkWidget *font_family_combo;
64 GtkWidget *font_size_spin;
65 GtkWidget *font_bold_toggle;
66 GtkWidget *font_italic_toggle;
68 /* Text alignemnt radios */
69 GtkWidget *text_align_left_radio;
70 GtkWidget *text_align_center_radio;
71 GtkWidget *text_align_right_radio;
74 GtkWidget *text_color_combo;
75 GtkWidget *fill_color_combo;
76 GtkWidget *line_color_combo;
79 GtkWidget *line_width_spin;
81 /* Prevent recursion */
82 gboolean stop_signals;
86 /*===========================================================================*/
88 /*===========================================================================*/
90 /*===========================================================================*/
91 /* Local function prototypes */
92 /*===========================================================================*/
94 static void gl_ui_property_bar_finalize (GObject *object);
96 static void gl_ui_property_bar_construct (glUIPropertyBar *property_bar);
98 static void selection_changed_cb (glUIPropertyBar *property_bar);
100 static void font_family_changed_cb (GtkComboBox *combo,
101 glUIPropertyBar *property_bar);
103 static void font_size_changed_cb (GtkSpinButton *spin,
104 glUIPropertyBar *property_bar);
106 static void text_color_changed_cb (ColorCombo *cc,
111 glUIPropertyBar *property_bar);
113 static void fill_color_changed_cb (ColorCombo *cc,
118 glUIPropertyBar *property_bar);
120 static void line_color_changed_cb (ColorCombo *cc,
125 glUIPropertyBar *property_bar);
127 static void line_width_changed_cb (GtkSpinButton *spin,
128 glUIPropertyBar *property_bar);
130 static void font_bold_toggled_cb (GtkToggleToolButton *toggle,
131 glUIPropertyBar *property_bar);
133 static void font_italic_toggled_cb (GtkToggleToolButton *toggle,
134 glUIPropertyBar *property_bar);
136 static void text_align_toggled_cb (GtkToggleToolButton *toggle,
137 glUIPropertyBar *property_bar);
139 static void set_doc_items_sensitive (glUIPropertyBar *property_bar,
142 static void set_text_items_sensitive (glUIPropertyBar *property_bar,
145 static void set_fill_items_sensitive (glUIPropertyBar *property_bar,
148 static void set_line_color_items_sensitive (glUIPropertyBar *property_bar,
151 static void set_line_width_items_sensitive (glUIPropertyBar *property_bar,
155 /****************************************************************************/
156 /* Boilerplate Object stuff. */
157 /****************************************************************************/
158 G_DEFINE_TYPE (glUIPropertyBar, gl_ui_property_bar, GTK_TYPE_HBOX);
161 gl_ui_property_bar_class_init (glUIPropertyBarClass *class)
163 GObjectClass *object_class = G_OBJECT_CLASS (class);
165 gl_debug (DEBUG_PROPERTY_BAR, "START");
167 gl_ui_property_bar_parent_class = g_type_class_peek_parent (class);
169 object_class->finalize = gl_ui_property_bar_finalize;
171 gl_debug (DEBUG_PROPERTY_BAR, "END");
175 gl_ui_property_bar_init (glUIPropertyBar *property_bar)
177 gl_debug (DEBUG_PROPERTY_BAR, "START");
179 property_bar->priv = g_new0 (glUIPropertyBarPrivate, 1);
181 gl_debug (DEBUG_PROPERTY_BAR, "END");
185 gl_ui_property_bar_finalize (GObject *object)
187 glUIPropertyBar *property_bar = GL_UI_PROPERTY_BAR (object);
189 gl_debug (DEBUG_PROPERTY_BAR, "START");
191 g_return_if_fail (object != NULL);
192 g_return_if_fail (GL_IS_UI_PROPERTY_BAR (object));
194 if (property_bar->priv->view)
196 g_object_unref (G_OBJECT(property_bar->priv->view));
198 if (property_bar->priv->gui)
200 g_object_unref (G_OBJECT(property_bar->priv->gui));
202 g_free (property_bar->priv);
204 G_OBJECT_CLASS (gl_ui_property_bar_parent_class)->finalize (object);
206 gl_debug (DEBUG_PROPERTY_BAR, "END");
209 /****************************************************************************/
210 /* Create a NEW property_bar. */
211 /****************************************************************************/
213 gl_ui_property_bar_new (void)
215 glUIPropertyBar *property_bar;
217 gl_debug (DEBUG_PROPERTY_BAR, "START");
219 property_bar = g_object_new (GL_TYPE_UI_PROPERTY_BAR, NULL);
221 gl_ui_property_bar_construct (property_bar);
223 gl_debug (DEBUG_PROPERTY_BAR, "END");
225 return GTK_WIDGET (property_bar);
228 /******************************************************************************/
229 /* Initialize property toolbar. */
230 /******************************************************************************/
232 gl_ui_property_bar_construct (glUIPropertyBar *property_bar)
235 GList *family_names = NULL;
239 gl_debug (DEBUG_PROPERTY_BAR, "START");
241 property_bar->priv->stop_signals = TRUE;
243 gui = glade_xml_new (GLABELS_GLADE_DIR "property-bar.glade",
244 "property_toolbar", NULL);
248 g_critical ("Could not open property-bar.glade. gLabels may not be installed correctly!");
252 property_bar->priv->tool_bar = glade_xml_get_widget (gui, "property_toolbar");
253 gtk_container_add (GTK_CONTAINER (property_bar), property_bar->priv->tool_bar);
255 property_bar->priv->font_family_combo =
256 glade_xml_get_widget (gui, "font_family_combo");
257 property_bar->priv->font_size_spin =
258 glade_xml_get_widget (gui, "font_size_spin");
259 property_bar->priv->font_bold_toggle =
260 glade_xml_get_widget (gui, "font_bold_toggle");
261 property_bar->priv->font_italic_toggle =
262 glade_xml_get_widget (gui, "font_italic_toggle");
263 property_bar->priv->text_align_left_radio =
264 glade_xml_get_widget (gui, "text_align_left_radio");
265 property_bar->priv->text_align_center_radio =
266 glade_xml_get_widget (gui, "text_align_center_radio");
267 property_bar->priv->text_align_right_radio =
268 glade_xml_get_widget (gui, "text_align_right_radio");
269 property_bar->priv->text_color_combo =
270 glade_xml_get_widget (gui, "text_color_combo");
271 property_bar->priv->fill_color_combo =
272 glade_xml_get_widget (gui, "fill_color_combo");
273 property_bar->priv->line_color_combo =
274 glade_xml_get_widget (gui, "line_color_combo");
275 property_bar->priv->line_width_spin =
276 glade_xml_get_widget (gui, "line_width_spin");
278 /* Save reference to gui tree so we don't lose tooltips */
279 property_bar->priv->gui = gui;
281 set_doc_items_sensitive (property_bar, FALSE);
283 /* Font family entry widget */
284 gl_util_combo_box_add_text_model (GTK_COMBO_BOX (property_bar->priv->font_family_combo));
285 family_names = gl_util_get_font_family_list ();
286 gl_util_combo_box_set_strings (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
288 gtk_widget_set_size_request (property_bar->priv->font_family_combo, 200, -1);
290 /* Make sure we have a valid font. if not provide a good default. */
291 family_node = g_list_find_custom (family_names,
292 gl_prefs->default_font_family,
293 (GCompareFunc)g_utf8_collate);
296 gtk_combo_box_set_active (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
297 g_list_position (family_names,
302 gtk_combo_box_set_active (GTK_COMBO_BOX (property_bar->priv->font_family_combo), 0);
305 g_signal_connect (G_OBJECT (property_bar->priv->font_family_combo),
306 "changed", G_CALLBACK (font_family_changed_cb), property_bar);
308 /* Font size entry widget */
309 gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->priv->font_size_spin),
310 gl_prefs->default_font_size);
312 g_signal_connect (G_OBJECT (property_bar->priv->font_size_spin),
313 "changed", G_CALLBACK (font_size_changed_cb), property_bar);
316 /* Bold and Italic toggles */
317 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_bold_toggle),
318 (gl_prefs->default_font_weight == PANGO_WEIGHT_BOLD));
319 g_signal_connect (G_OBJECT (property_bar->priv->font_bold_toggle),
320 "toggled", G_CALLBACK (font_bold_toggled_cb), property_bar);
321 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_italic_toggle),
322 gl_prefs->default_font_italic_flag);
323 g_signal_connect (G_OBJECT (property_bar->priv->font_italic_toggle),
324 "toggled", G_CALLBACK (font_italic_toggled_cb), property_bar);
327 /* Text alignment radio group */
328 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio),
329 (gl_prefs->default_text_alignment == PANGO_ALIGN_LEFT));
330 g_signal_connect (G_OBJECT (property_bar->priv->text_align_left_radio),
331 "toggled", G_CALLBACK (text_align_toggled_cb), property_bar);
332 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio),
333 (gl_prefs->default_text_alignment == PANGO_ALIGN_CENTER));
334 g_signal_connect (G_OBJECT (property_bar->priv->text_align_center_radio),
335 "toggled", G_CALLBACK (text_align_toggled_cb), property_bar);
336 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio),
337 (gl_prefs->default_text_alignment == PANGO_ALIGN_RIGHT));
338 g_signal_connect (G_OBJECT (property_bar->priv->text_align_right_radio),
339 "toggled", G_CALLBACK (text_align_toggled_cb), property_bar);
341 /* Text color widget */
342 gdk_color = gl_color_to_gdk_color (gl_prefs->default_text_color);
343 color_combo_set_color (COLOR_COMBO (property_bar->priv->text_color_combo), gdk_color);
345 g_signal_connect (G_OBJECT (property_bar->priv->text_color_combo),
347 G_CALLBACK (text_color_changed_cb), property_bar);
349 /* Fill color widget */
350 gdk_color = gl_color_to_gdk_color (gl_prefs->default_fill_color);
351 color_combo_set_color (COLOR_COMBO (property_bar->priv->fill_color_combo), gdk_color);
353 g_signal_connect (G_OBJECT (property_bar->priv->fill_color_combo),
355 G_CALLBACK (fill_color_changed_cb), property_bar);
357 /* Line color widget */
358 gdk_color = gl_color_to_gdk_color (gl_prefs->default_line_color);
359 color_combo_set_color (COLOR_COMBO (property_bar->priv->line_color_combo), gdk_color);
361 g_signal_connect (G_OBJECT (property_bar->priv->line_color_combo),
363 G_CALLBACK (line_color_changed_cb), property_bar);
365 /* Line width entry widget */
366 g_signal_connect (G_OBJECT (property_bar->priv->line_width_spin),
368 G_CALLBACK (line_width_changed_cb), property_bar);
370 property_bar->priv->stop_signals = FALSE;
372 gl_debug (DEBUG_PROPERTY_BAR, "END");
375 /****************************************************************************/
376 /* Fill widgets with default values. */
377 /****************************************************************************/
379 reset_to_default_properties (glView *view,
380 glUIPropertyBar *property_bar)
383 gchar *good_font_family;
386 /* Make sure we have a valid font. if not provide a good default. */
387 family_names = gl_util_get_font_family_list ();
388 if (g_list_find_custom (family_names,
389 view->default_font_family,
390 (GCompareFunc)g_utf8_collate))
392 good_font_family = g_strdup (view->default_font_family);
396 if (family_names != NULL)
398 good_font_family = g_strdup (family_names->data); /* 1st entry */
402 good_font_family = NULL;
405 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
407 g_free (good_font_family);
409 gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->priv->font_size_spin),
410 view->default_font_size);
412 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_bold_toggle),
413 (view->default_font_weight == PANGO_WEIGHT_BOLD));
414 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_italic_toggle),
415 view->default_font_italic_flag);
417 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio),
418 (view->default_text_alignment == PANGO_ALIGN_LEFT));
419 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio),
420 (view->default_text_alignment == PANGO_ALIGN_CENTER));
421 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio),
422 (view->default_text_alignment == PANGO_ALIGN_RIGHT));
424 gdk_color = gl_color_to_gdk_color (view->default_text_color);
425 color_combo_set_color (COLOR_COMBO(property_bar->priv->text_color_combo), gdk_color);
428 gdk_color = gl_color_to_gdk_color (view->default_fill_color);
429 color_combo_set_color (COLOR_COMBO(property_bar->priv->fill_color_combo), gdk_color);
432 gdk_color = gl_color_to_gdk_color (view->default_line_color);
433 color_combo_set_color (COLOR_COMBO(property_bar->priv->line_color_combo), gdk_color);
436 gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->priv->line_width_spin),
437 view->default_line_width);
440 /****************************************************************************/
441 /* Set view associated with property_bar. */
442 /****************************************************************************/
444 gl_ui_property_bar_set_view (glUIPropertyBar *property_bar,
449 gl_debug (DEBUG_PROPERTY_BAR, "START");
451 g_return_if_fail (view && GL_IS_VIEW (view));
453 g_return_if_fail (label && GL_IS_LABEL (label));
455 set_doc_items_sensitive (property_bar, TRUE);
457 property_bar->priv->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
459 reset_to_default_properties (view, property_bar);
461 g_signal_connect_swapped (G_OBJECT(view), "selection_changed",
462 G_CALLBACK(selection_changed_cb), property_bar);
464 g_signal_connect_swapped (G_OBJECT(view->label), "changed",
465 G_CALLBACK(selection_changed_cb), property_bar);
467 gl_debug (DEBUG_PROPERTY_BAR, "END");
470 /****************************************************************************/
471 /** Set visiblity of property bar's tooltips. */
472 /****************************************************************************/
474 gl_ui_property_bar_set_tooltips (glUIPropertyBar *property_bar,
477 GtkTooltipsData *data;
479 gl_debug (DEBUG_PROPERTY_BAR, "START");
481 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR(property_bar));
483 /* HACK: peek into one of our widgets to get the tooltips group created by libglade. */
484 data = gtk_tooltips_data_get (property_bar->priv->font_size_spin);
485 g_return_if_fail (data);
489 gtk_tooltips_enable (data->tooltips);
493 gtk_tooltips_disable (data->tooltips);
496 gl_debug (DEBUG_PROPERTY_BAR, "END");
499 /*---------------------------------------------------------------------------*/
500 /* PRIVATE. View "selection state changed" callback. */
501 /*---------------------------------------------------------------------------*/
503 update_text_properties (glView *view,
504 glUIPropertyBar *property_bar)
506 gboolean can_text, is_first_object;
507 gboolean is_same_font_family, is_same_font_size;
508 gboolean is_same_text_color, is_same_is_italic;
509 gboolean is_same_is_bold, is_same_align;
511 glLabelObject *object;
512 gchar *selection_font_family, *font_family;
513 gdouble selection_font_size, font_size;
514 guint selection_text_color, text_color;
515 glColorNode *text_color_node;
516 gboolean selection_is_italic, is_italic;
517 gboolean selection_is_bold, is_bold;
518 PangoAlignment selection_align, align;
521 can_text = gl_view_can_selection_text (view);
522 set_text_items_sensitive (property_bar, can_text);
532 is_same_font_family = TRUE;
533 selection_font_family = NULL;
534 selection_font_size = -1;
535 selection_align = PANGO_ALIGN_LEFT;
536 selection_is_italic = TRUE;
537 selection_is_bold = TRUE;
538 selection_text_color = 0;
540 is_first_object = TRUE;
542 for (p = view->selected_object_list; p != NULL; p = p->next)
545 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
546 if (!gl_label_object_can_text (object))
549 font_family = gl_label_object_get_font_family (object);
550 if (font_family != NULL)
552 if (selection_font_family == NULL)
554 selection_font_family = g_strdup (font_family);
558 if (strcmp (font_family, selection_font_family) != 0)
560 is_same_font_family = FALSE;
563 g_free (font_family);
566 font_size = gl_label_object_get_font_size (object);
568 text_color_node = gl_label_object_get_text_color (object);
569 if (text_color_node->field_flag)
571 /* If a merge field is set we use the default color for merged color*/
572 text_color = GL_COLOR_MERGE_DEFAULT;
577 text_color = text_color_node->color;
579 gl_color_node_free (&text_color_node);
581 is_italic = gl_label_object_get_font_italic_flag (object);
582 is_bold = gl_label_object_get_font_weight (object) == PANGO_WEIGHT_BOLD;
583 align = gl_label_object_get_text_alignment (object);
587 selection_font_size = font_size;
588 selection_text_color = text_color;
589 selection_is_italic = is_italic;
590 selection_is_bold = is_bold;
591 selection_align = align;
595 if (font_size != selection_font_size)
596 is_same_font_size = FALSE;
597 if (text_color != selection_text_color)
598 is_same_text_color = FALSE;
599 if (is_italic != selection_is_italic)
600 is_same_is_italic = FALSE;
601 if (is_bold != selection_is_bold)
602 is_same_is_bold = FALSE;
603 if (align != selection_align)
604 is_same_align = FALSE;
606 is_first_object = FALSE;
609 if (is_same_font_family && (selection_font_family != NULL))
610 gl_debug (DEBUG_PROPERTY_BAR, "same font family = %s",
611 selection_font_family);
612 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
613 is_same_font_family?selection_font_family:"");
614 g_free (selection_font_family);
616 if (is_same_font_size)
618 gl_debug (DEBUG_PROPERTY_BAR, "same font size = %g",
619 selection_font_size);
620 gtk_spin_button_set_value (GTK_SPIN_BUTTON (property_bar->priv->font_size_spin),
621 selection_font_size);
625 gtk_entry_set_text (GTK_ENTRY (property_bar->priv->font_size_spin), "");
628 if (is_same_text_color)
630 gl_debug (DEBUG_PROPERTY_BAR, "same text color = %08x", selection_text_color);
631 gdk_color = gl_color_to_gdk_color (selection_text_color);
632 color_combo_set_color (COLOR_COMBO (property_bar->priv->text_color_combo),
637 if (is_same_is_italic)
639 gl_debug (DEBUG_PROPERTY_BAR, "same italic flag = %d",
640 selection_is_italic);
642 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_italic_toggle),
643 selection_is_italic && is_same_is_italic);
647 gl_debug (DEBUG_PROPERTY_BAR, "same bold flag = %d",
650 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_bold_toggle),
651 selection_is_bold && is_same_is_bold);
654 gl_debug (DEBUG_PROPERTY_BAR, "same align");
655 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio),
656 (selection_align == PANGO_ALIGN_LEFT) &&
658 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio),
659 (selection_align == PANGO_ALIGN_CENTER) &&
661 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio),
662 (selection_align == PANGO_ALIGN_RIGHT) &&
667 update_fill_color (glView *view,
668 glUIPropertyBar *property_bar)
670 gboolean can, is_first_object;
671 gboolean is_same_fill_color;
673 glLabelObject *object;
674 guint selection_fill_color, fill_color;
676 glColorNode *fill_color_node;
678 can = gl_view_can_selection_fill (view);
679 set_fill_items_sensitive (property_bar, can);
684 is_same_fill_color = TRUE;
685 is_first_object = TRUE;
686 selection_fill_color = 0;
688 for (p = view->selected_object_list; p != NULL; p = p->next)
691 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
692 if (!gl_label_object_can_fill (object))
695 fill_color_node = gl_label_object_get_fill_color (object);
696 if (fill_color_node->field_flag)
698 /* If a merge field is set we use the default color for merged color*/
699 fill_color = GL_COLOR_FILL_MERGE_DEFAULT;
704 fill_color = fill_color_node->color;
706 gl_color_node_free (&fill_color_node);
710 selection_fill_color = fill_color;
714 if (fill_color != selection_fill_color)
716 is_same_fill_color = FALSE;
719 is_first_object = FALSE;
722 if (is_same_fill_color)
724 gl_debug (DEBUG_PROPERTY_BAR, "same fill color = %08x", selection_fill_color);
725 gdk_color = gl_color_to_gdk_color (selection_fill_color);
726 color_combo_set_color (COLOR_COMBO (property_bar->priv->fill_color_combo),
733 update_line_color (glView *view,
734 glUIPropertyBar *property_bar)
736 gboolean can, is_first_object;
737 gboolean is_same_line_color;
739 glLabelObject *object;
740 guint selection_line_color, line_color;
741 glColorNode *line_color_node;
744 can = gl_view_can_selection_line_color (view);
745 set_line_color_items_sensitive (property_bar, can);
750 is_same_line_color = TRUE;
751 is_first_object = TRUE;
752 selection_line_color = 0;
754 for (p = view->selected_object_list; p != NULL; p = p->next)
757 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
758 if (!gl_label_object_can_line_color (object))
761 line_color_node = gl_label_object_get_line_color (object);
762 if (line_color_node->field_flag)
764 /* If a merge field is set we use the default color for merged color*/
765 line_color = GL_COLOR_MERGE_DEFAULT;
770 line_color = line_color_node->color;
772 gl_color_node_free (&line_color_node);
776 selection_line_color = line_color;
780 if (line_color != selection_line_color)
782 is_same_line_color = FALSE;
785 is_first_object = FALSE;
788 if (is_same_line_color)
790 gl_debug (DEBUG_PROPERTY_BAR, "same line color = %08x", selection_line_color);
791 gdk_color = gl_color_to_gdk_color (selection_line_color);
792 color_combo_set_color (COLOR_COMBO (property_bar->priv->line_color_combo),
799 update_line_width (glView *view,
800 glUIPropertyBar *property_bar)
802 gboolean can, is_first_object;
803 gboolean is_same_line_width;
805 glLabelObject *object;
806 gdouble selection_line_width, line_width;
808 can = gl_view_can_selection_line_width (view);
809 set_line_width_items_sensitive (property_bar, can);
814 is_same_line_width = TRUE;
815 is_first_object = TRUE;
816 selection_line_width = 0;
818 for (p = view->selected_object_list; p != NULL; p = p->next)
821 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
822 if (!gl_label_object_can_line_width (object))
825 line_width = gl_label_object_get_line_width (object);
829 selection_line_width = line_width;
833 if (line_width != selection_line_width)
835 is_same_line_width = FALSE;
838 is_first_object = FALSE;
841 if (is_same_line_width)
843 gl_debug (DEBUG_PROPERTY_BAR, "same line width = %g", selection_line_width);
844 gtk_spin_button_set_value (GTK_SPIN_BUTTON (property_bar->priv->line_width_spin),
845 selection_line_width);
849 gtk_entry_set_text (GTK_ENTRY (property_bar->priv->line_width_spin), "");
854 selection_changed_cb (glUIPropertyBar *property_bar)
856 glView *view = property_bar->priv->view;
858 g_return_if_fail (view && GL_IS_VIEW (view));
859 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
861 if (property_bar->priv->stop_signals) return;
862 property_bar->priv->stop_signals = TRUE;
864 gl_debug (DEBUG_PROPERTY_BAR, "START");
866 if (gl_view_is_selection_empty (view))
868 /* No selection: make all controls active. */
869 reset_to_default_properties (view, property_bar);
870 set_doc_items_sensitive (property_bar, TRUE);
874 update_text_properties (view, property_bar);
875 update_fill_color (view, property_bar);
876 update_line_color (view, property_bar);
877 update_line_width (view, property_bar);
880 gl_debug (DEBUG_PROPERTY_BAR, "END");
882 property_bar->priv->stop_signals = FALSE;
885 /*--------------------------------------------------------------------------*/
886 /* PRIVATE. Font family entry changed. */
887 /*--------------------------------------------------------------------------*/
889 font_family_changed_cb (GtkComboBox *combo,
890 glUIPropertyBar *property_bar)
894 if (property_bar->priv->stop_signals) return;
895 property_bar->priv->stop_signals = TRUE;
897 gl_debug (DEBUG_PROPERTY_BAR, "START");
899 font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
900 if ( strlen(font_family) )
902 gl_view_set_selection_font_family (property_bar->priv->view,
904 gl_view_set_default_font_family (property_bar->priv->view,
907 g_free (font_family);
909 gl_debug (DEBUG_PROPERTY_BAR, "END");
911 property_bar->priv->stop_signals = FALSE;
914 /*--------------------------------------------------------------------------*/
915 /* PRIVATE. Font size spin button changed. */
916 /*--------------------------------------------------------------------------*/
918 font_size_changed_cb (GtkSpinButton *spin,
919 glUIPropertyBar *property_bar)
923 if (property_bar->priv->stop_signals) return;
924 property_bar->priv->stop_signals = TRUE;
926 gl_debug (DEBUG_PROPERTY_BAR, "START");
928 font_size = gtk_spin_button_get_value (spin);
930 gl_view_set_selection_font_size (property_bar->priv->view,
932 gl_view_set_default_font_size (property_bar->priv->view,
935 gl_debug (DEBUG_PROPERTY_BAR, "END");
937 property_bar->priv->stop_signals = FALSE;
940 /*--------------------------------------------------------------------------*/
941 /* PRIVATE. Text color combo changed. */
942 /*--------------------------------------------------------------------------*/
944 text_color_changed_cb (ColorCombo *cc,
949 glUIPropertyBar *property_bar)
951 glColorNode *text_color_node;
953 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
955 if (property_bar->priv->stop_signals) return;
956 property_bar->priv->stop_signals = TRUE;
958 gl_debug (DEBUG_PROPERTY_BAR, "START");
960 text_color_node = gl_color_node_new_default ();
961 text_color_node->color = gl_color_from_gdk_color (gdk_color);
963 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d",
964 text_color_node->color, custom, by_user, is_default);
968 text_color_node->color = gl_prefs->default_text_color;
969 gl_view_set_selection_text_color (property_bar->priv->view,
971 gl_view_set_default_text_color (property_bar->priv->view,
972 gl_prefs->default_text_color);
976 gl_view_set_selection_text_color (property_bar->priv->view,
978 gl_view_set_default_text_color (property_bar->priv->view,
979 text_color_node->color);
982 gl_color_node_free (&text_color_node);
984 gl_debug (DEBUG_PROPERTY_BAR, "END");
986 property_bar->priv->stop_signals = FALSE;
989 /*--------------------------------------------------------------------------*/
990 /* PRIVATE. Fill color combo changed. */
991 /*--------------------------------------------------------------------------*/
993 fill_color_changed_cb (ColorCombo *cc,
998 glUIPropertyBar *property_bar)
1000 glColorNode *fill_color_node;
1002 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
1004 if (property_bar->priv->stop_signals) return;
1005 property_bar->priv->stop_signals = TRUE;
1007 gl_debug (DEBUG_PROPERTY_BAR, "START");
1009 fill_color_node = gl_color_node_new_default ();
1011 fill_color_node->color = gl_color_from_gdk_color (gdk_color);
1013 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d",
1014 fill_color_node->color, custom, by_user, is_default);
1019 fill_color_node->color = GL_COLOR_NONE;
1020 gl_view_set_selection_fill_color (property_bar->priv->view,
1022 gl_view_set_default_fill_color (property_bar->priv->view,
1023 fill_color_node->color);
1027 gl_view_set_selection_fill_color (property_bar->priv->view,
1029 gl_view_set_default_fill_color (property_bar->priv->view,
1030 fill_color_node->color);
1032 gl_color_node_free (&fill_color_node);
1034 gl_debug (DEBUG_PROPERTY_BAR, "END");
1036 property_bar->priv->stop_signals = FALSE;
1039 /*--------------------------------------------------------------------------*/
1040 /* PRIVATE. Line color combo changed. */
1041 /*--------------------------------------------------------------------------*/
1043 line_color_changed_cb (ColorCombo *cc,
1044 GdkColor *gdk_color,
1047 gboolean is_default,
1048 glUIPropertyBar *property_bar)
1050 glColorNode *line_color_node;
1052 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
1054 if (property_bar->priv->stop_signals) return;
1055 property_bar->priv->stop_signals = TRUE;
1057 gl_debug (DEBUG_PROPERTY_BAR, "START");
1059 line_color_node = gl_color_node_new_default ();
1060 line_color_node->color = gl_color_from_gdk_color (gdk_color);
1062 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d",
1063 line_color_node->color, custom, by_user, is_default);
1067 line_color_node->color = GL_COLOR_NONE;
1068 gl_view_set_selection_line_color (property_bar->priv->view,
1070 gl_view_set_default_line_color (property_bar->priv->view,
1071 line_color_node->color);
1075 gl_view_set_selection_line_color (property_bar->priv->view,
1077 gl_view_set_default_line_color (property_bar->priv->view,
1078 line_color_node->color);
1080 gl_color_node_free (&line_color_node);
1082 gl_debug (DEBUG_PROPERTY_BAR, "END");
1084 property_bar->priv->stop_signals = FALSE;
1087 /*--------------------------------------------------------------------------*/
1088 /* PRIVATE. Line width spin button changed. */
1089 /*--------------------------------------------------------------------------*/
1091 line_width_changed_cb (GtkSpinButton *spin,
1092 glUIPropertyBar *property_bar)
1096 if (property_bar->priv->stop_signals) return;
1097 property_bar->priv->stop_signals = TRUE;
1099 gl_debug (DEBUG_PROPERTY_BAR, "START");
1101 if (property_bar->priv->view)
1103 line_width = gtk_spin_button_get_value (spin);
1105 gl_view_set_selection_line_width (property_bar->priv->view,
1107 gl_view_set_default_line_width (property_bar->priv->view,
1111 gl_debug (DEBUG_PROPERTY_BAR, "END");
1113 property_bar->priv->stop_signals = FALSE;
1116 /*---------------------------------------------------------------------------*/
1117 /* PRIVATE. Font bold toggled callback. */
1118 /*---------------------------------------------------------------------------*/
1120 font_bold_toggled_cb (GtkToggleToolButton *toggle,
1121 glUIPropertyBar *property_bar)
1127 if (property_bar->priv->stop_signals) return;
1128 property_bar->priv->stop_signals = TRUE;
1130 gl_debug (DEBUG_PROPERTY_BAR, "START");
1132 state = gtk_toggle_tool_button_get_active (toggle);
1134 weight = state ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
1136 gl_view_set_selection_font_weight (property_bar->priv->view, weight);
1137 gl_view_set_default_font_weight (property_bar->priv->view, weight);
1139 gl_debug (DEBUG_PROPERTY_BAR, "END");
1141 property_bar->priv->stop_signals = FALSE;
1144 /*---------------------------------------------------------------------------*/
1145 /* PRIVATE. Font italic toggled callback. */
1146 /*---------------------------------------------------------------------------*/
1148 font_italic_toggled_cb (GtkToggleToolButton *toggle,
1149 glUIPropertyBar *property_bar)
1153 if (property_bar->priv->stop_signals) return;
1154 property_bar->priv->stop_signals = TRUE;
1156 gl_debug (DEBUG_PROPERTY_BAR, "START");
1158 state = gtk_toggle_tool_button_get_active (toggle);
1160 gl_view_set_selection_font_italic_flag (property_bar->priv->view, state);
1161 gl_view_set_default_font_italic_flag (property_bar->priv->view, state);
1163 gl_debug (DEBUG_PROPERTY_BAR, "END");
1165 property_bar->priv->stop_signals = FALSE;
1168 /*---------------------------------------------------------------------------*/
1169 /* PRIVATE. Text align toggled callback. */
1170 /*---------------------------------------------------------------------------*/
1172 text_align_toggled_cb (GtkToggleToolButton *toggle,
1173 glUIPropertyBar *property_bar)
1175 if (property_bar->priv->stop_signals) return;
1176 property_bar->priv->stop_signals = TRUE;
1178 gl_debug (DEBUG_PROPERTY_BAR, "START");
1180 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio)))
1182 gl_view_set_selection_text_alignment (property_bar->priv->view,
1184 gl_view_set_default_text_alignment (property_bar->priv->view,
1188 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio)))
1190 gl_view_set_selection_text_alignment (property_bar->priv->view,
1191 PANGO_ALIGN_CENTER);
1192 gl_view_set_default_text_alignment (property_bar->priv->view,
1193 PANGO_ALIGN_CENTER);
1196 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio)))
1198 gl_view_set_selection_text_alignment (property_bar->priv->view,
1200 gl_view_set_default_text_alignment (property_bar->priv->view,
1204 gl_debug (DEBUG_PROPERTY_BAR, "END");
1206 property_bar->priv->stop_signals = FALSE;
1210 /*****************************************************************************/
1211 /* Construct color combo "Custom widget". */
1212 /*****************************************************************************/
1214 gl_ui_property_bar_construct_color_combo (gchar *name,
1220 GtkWidget *color_combo;
1223 GdkColor *gdk_color;
1225 GdkPixbuf *pixbuf = NULL;
1230 cg_name = "text_color_group";
1231 gdk_color = gl_color_to_gdk_color (gl_prefs->default_text_color);
1232 no_color = _("Default");
1233 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_text_24, FALSE, NULL);
1237 cg_name = "line_color_group";
1239 no_color = _("No line");
1240 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_pencil_24, FALSE, NULL);
1245 cg_name = "fill_color_group";
1247 no_color = _("No fill");
1248 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_bucket_fill_24, FALSE, NULL);
1253 cg = color_group_fetch (cg_name, NULL);
1254 color_combo = color_combo_new (pixbuf, no_color, gdk_color, cg);
1257 color_combo_box_set_preview_relief (COLOR_COMBO(color_combo), GTK_RELIEF_NORMAL);
1259 g_object_unref (G_OBJECT (pixbuf));
1264 /*---------------------------------------------------------------------------*/
1265 /* PRIVATE. Set sensitivity of doc controls. */
1266 /*---------------------------------------------------------------------------*/
1268 set_doc_items_sensitive (glUIPropertyBar *property_bar,
1271 gtk_widget_set_sensitive (property_bar->priv->font_family_combo, state);
1272 gtk_widget_set_sensitive (property_bar->priv->font_size_spin, state);
1273 gtk_widget_set_sensitive (property_bar->priv->font_bold_toggle, state);
1274 gtk_widget_set_sensitive (property_bar->priv->font_italic_toggle, state);
1275 gtk_widget_set_sensitive (property_bar->priv->text_align_left_radio, state);
1276 gtk_widget_set_sensitive (property_bar->priv->text_align_center_radio, state);
1277 gtk_widget_set_sensitive (property_bar->priv->text_align_right_radio, state);
1278 gtk_widget_set_sensitive (property_bar->priv->text_color_combo, state);
1279 gtk_widget_set_sensitive (property_bar->priv->fill_color_combo, state);
1280 gtk_widget_set_sensitive (property_bar->priv->line_color_combo, state);
1281 gtk_widget_set_sensitive (property_bar->priv->line_width_spin, state);
1284 /*---------------------------------------------------------------------------*/
1285 /* PRIVATE. Set sensitivity of text related controls. */
1286 /*---------------------------------------------------------------------------*/
1288 set_text_items_sensitive (glUIPropertyBar *property_bar,
1291 gtk_widget_set_sensitive (property_bar->priv->font_family_combo, state);
1292 gtk_widget_set_sensitive (property_bar->priv->font_size_spin, state);
1293 gtk_widget_set_sensitive (property_bar->priv->font_bold_toggle, state);
1294 gtk_widget_set_sensitive (property_bar->priv->font_italic_toggle, state);
1295 gtk_widget_set_sensitive (property_bar->priv->text_align_left_radio, state);
1296 gtk_widget_set_sensitive (property_bar->priv->text_align_center_radio, state);
1297 gtk_widget_set_sensitive (property_bar->priv->text_align_right_radio, state);
1298 gtk_widget_set_sensitive (property_bar->priv->text_color_combo, state);
1301 /*---------------------------------------------------------------------------*/
1302 /* PRIVATE. Set sensitivity of fill related controls. */
1303 /*---------------------------------------------------------------------------*/
1305 set_fill_items_sensitive (glUIPropertyBar *property_bar,
1308 gtk_widget_set_sensitive (property_bar->priv->fill_color_combo, state);
1311 /*---------------------------------------------------------------------------*/
1312 /* PRIVATE. Set sensitivity of line color related controls. */
1313 /*---------------------------------------------------------------------------*/
1315 set_line_color_items_sensitive (glUIPropertyBar *property_bar,
1318 gtk_widget_set_sensitive (property_bar->priv->line_color_combo, state);
1321 /*---------------------------------------------------------------------------*/
1322 /* PRIVATE. Set sensitivity of line width related controls. */
1323 /*---------------------------------------------------------------------------*/
1325 set_line_width_items_sensitive (glUIPropertyBar *property_bar,
1328 gtk_widget_set_sensitive (property_bar->priv->line_width_spin, state);