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 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 property_bar->priv->gui = glade_xml_new (GLABELS_GLADE_DIR "property-bar.glade",
185 if (!property_bar->priv->gui) {
186 g_critical ("Could not open property-bar.glade. gLabels may not be installed correctly!");
190 gl_debug (DEBUG_PROPERTY_BAR, "END");
194 gl_ui_property_bar_finalize (GObject *object)
196 glUIPropertyBar *property_bar = GL_UI_PROPERTY_BAR (object);
198 gl_debug (DEBUG_PROPERTY_BAR, "START");
200 g_return_if_fail (object != NULL);
201 g_return_if_fail (GL_IS_UI_PROPERTY_BAR (object));
203 if (property_bar->priv->view) {
204 g_object_unref (G_OBJECT(property_bar->priv->view));
206 g_free (property_bar->priv);
208 G_OBJECT_CLASS (gl_ui_property_bar_parent_class)->finalize (object);
210 gl_debug (DEBUG_PROPERTY_BAR, "END");
213 /****************************************************************************/
214 /* Create a NEW property_bar. */
215 /****************************************************************************/
217 gl_ui_property_bar_new (void)
219 glUIPropertyBar *property_bar;
221 gl_debug (DEBUG_PROPERTY_BAR, "START");
223 property_bar = g_object_new (GL_TYPE_UI_PROPERTY_BAR, NULL);
225 gl_ui_property_bar_construct (property_bar);
227 gl_debug (DEBUG_PROPERTY_BAR, "END");
229 return GTK_WIDGET (property_bar);
232 /******************************************************************************/
233 /* Initialize property toolbar. */
234 /******************************************************************************/
236 gl_ui_property_bar_construct (glUIPropertyBar *property_bar)
238 GList *family_names = NULL;
242 gl_debug (DEBUG_PROPERTY_BAR, "START");
244 property_bar->priv->stop_signals = TRUE;
246 property_bar->priv->tool_bar = glade_xml_get_widget (property_bar->priv->gui,
248 gtk_container_add (GTK_CONTAINER (property_bar), property_bar->priv->tool_bar);
250 property_bar->priv->font_family_combo =
251 glade_xml_get_widget (property_bar->priv->gui, "font_family_combo");
252 property_bar->priv->font_size_spin =
253 glade_xml_get_widget (property_bar->priv->gui, "font_size_spin");
254 property_bar->priv->font_bold_toggle =
255 glade_xml_get_widget (property_bar->priv->gui, "font_bold_toggle");
256 property_bar->priv->font_italic_toggle =
257 glade_xml_get_widget (property_bar->priv->gui, "font_italic_toggle");
258 property_bar->priv->text_align_left_radio =
259 glade_xml_get_widget (property_bar->priv->gui, "text_align_left_radio");
260 property_bar->priv->text_align_center_radio =
261 glade_xml_get_widget (property_bar->priv->gui, "text_align_center_radio");
262 property_bar->priv->text_align_right_radio =
263 glade_xml_get_widget (property_bar->priv->gui, "text_align_right_radio");
264 property_bar->priv->text_color_combo =
265 glade_xml_get_widget (property_bar->priv->gui, "text_color_combo");
266 property_bar->priv->fill_color_combo =
267 glade_xml_get_widget (property_bar->priv->gui, "fill_color_combo");
268 property_bar->priv->line_color_combo =
269 glade_xml_get_widget (property_bar->priv->gui, "line_color_combo");
270 property_bar->priv->line_width_spin =
271 glade_xml_get_widget (property_bar->priv->gui, "line_width_spin");
273 set_doc_items_sensitive (property_bar, FALSE);
275 /* Font family entry widget */
276 gl_util_combo_box_add_text_model (GTK_COMBO_BOX (property_bar->priv->font_family_combo));
277 family_names = gl_util_get_font_family_list ();
278 gl_util_combo_box_set_strings (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
280 gtk_widget_set_size_request (property_bar->priv->font_family_combo, 200, -1);
282 /* Make sure we have a valid font. if not provide a good default. */
283 family_node = g_list_find_custom (family_names,
284 gl_prefs->default_font_family,
285 (GCompareFunc)g_utf8_collate);
287 gtk_combo_box_set_active (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
288 g_list_position (family_names,
291 gtk_combo_box_set_active (GTK_COMBO_BOX (property_bar->priv->font_family_combo), 0);
293 gl_util_font_family_list_free (family_names);
295 g_signal_connect (G_OBJECT (property_bar->priv->font_family_combo),
296 "changed", G_CALLBACK (font_family_changed_cb), property_bar);
298 /* Font size entry widget */
299 gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->priv->font_size_spin),
300 gl_prefs->default_font_size);
302 g_signal_connect (G_OBJECT (property_bar->priv->font_size_spin),
303 "changed", G_CALLBACK (font_size_changed_cb), property_bar);
306 /* Bold and Italic toggles */
307 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_bold_toggle),
308 (gl_prefs->default_font_weight == PANGO_WEIGHT_BOLD));
309 g_signal_connect (G_OBJECT (property_bar->priv->font_bold_toggle),
310 "toggled", G_CALLBACK (font_bold_toggled_cb), property_bar);
311 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_italic_toggle),
312 gl_prefs->default_font_italic_flag);
313 g_signal_connect (G_OBJECT (property_bar->priv->font_italic_toggle),
314 "toggled", G_CALLBACK (font_italic_toggled_cb), property_bar);
317 /* Text alignment radio group */
318 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio),
319 (gl_prefs->default_text_alignment == PANGO_ALIGN_LEFT));
320 g_signal_connect (G_OBJECT (property_bar->priv->text_align_left_radio),
321 "toggled", G_CALLBACK (text_align_toggled_cb), property_bar);
322 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio),
323 (gl_prefs->default_text_alignment == PANGO_ALIGN_CENTER));
324 g_signal_connect (G_OBJECT (property_bar->priv->text_align_center_radio),
325 "toggled", G_CALLBACK (text_align_toggled_cb), property_bar);
326 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio),
327 (gl_prefs->default_text_alignment == PANGO_ALIGN_RIGHT));
328 g_signal_connect (G_OBJECT (property_bar->priv->text_align_right_radio),
329 "toggled", G_CALLBACK (text_align_toggled_cb), property_bar);
331 /* Text color widget */
332 gdk_color = gl_color_to_gdk_color (gl_prefs->default_text_color);
333 color_combo_set_color (COLOR_COMBO (property_bar->priv->text_color_combo), gdk_color);
335 g_signal_connect (G_OBJECT (property_bar->priv->text_color_combo),
337 G_CALLBACK (text_color_changed_cb), property_bar);
339 /* Fill color widget */
340 gdk_color = gl_color_to_gdk_color (gl_prefs->default_fill_color);
341 color_combo_set_color (COLOR_COMBO (property_bar->priv->fill_color_combo), gdk_color);
343 g_signal_connect (G_OBJECT (property_bar->priv->fill_color_combo),
345 G_CALLBACK (fill_color_changed_cb), property_bar);
347 /* Line color widget */
348 gdk_color = gl_color_to_gdk_color (gl_prefs->default_line_color);
349 color_combo_set_color (COLOR_COMBO (property_bar->priv->line_color_combo), gdk_color);
351 g_signal_connect (G_OBJECT (property_bar->priv->line_color_combo),
353 G_CALLBACK (line_color_changed_cb), property_bar);
355 /* Line width entry widget */
356 g_signal_connect (G_OBJECT (property_bar->priv->line_width_spin),
358 G_CALLBACK (line_width_changed_cb), property_bar);
360 property_bar->priv->stop_signals = FALSE;
362 gl_debug (DEBUG_PROPERTY_BAR, "END");
365 /****************************************************************************/
366 /* Fill widgets with default values. */
367 /****************************************************************************/
369 reset_to_default_properties (glView *view,
370 glUIPropertyBar *property_bar)
373 gchar *good_font_family;
376 /* Make sure we have a valid font. if not provide a good default. */
377 family_names = gl_util_get_font_family_list ();
378 if (g_list_find_custom (family_names,
379 view->default_font_family,
380 (GCompareFunc)g_utf8_collate)) {
381 good_font_family = g_strdup (view->default_font_family);
383 if (family_names != NULL) {
384 good_font_family = g_strdup (family_names->data); /* 1st entry */
386 good_font_family = NULL;
389 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
391 g_free (good_font_family);
392 gl_util_font_family_list_free (family_names);
394 gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->priv->font_size_spin),
395 view->default_font_size);
397 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_bold_toggle),
398 (view->default_font_weight == PANGO_WEIGHT_BOLD));
399 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_italic_toggle),
400 view->default_font_italic_flag);
402 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio),
403 (view->default_text_alignment == PANGO_ALIGN_LEFT));
404 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio),
405 (view->default_text_alignment == PANGO_ALIGN_CENTER));
406 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio),
407 (view->default_text_alignment == PANGO_ALIGN_RIGHT));
409 gdk_color = gl_color_to_gdk_color (view->default_text_color);
410 color_combo_set_color (COLOR_COMBO(property_bar->priv->text_color_combo), gdk_color);
413 gdk_color = gl_color_to_gdk_color (view->default_fill_color);
414 color_combo_set_color (COLOR_COMBO(property_bar->priv->fill_color_combo), gdk_color);
417 gdk_color = gl_color_to_gdk_color (view->default_line_color);
418 color_combo_set_color (COLOR_COMBO(property_bar->priv->line_color_combo), gdk_color);
421 gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->priv->line_width_spin),
422 view->default_line_width);
425 /****************************************************************************/
426 /* Set view associated with property_bar. */
427 /****************************************************************************/
429 gl_ui_property_bar_set_view (glUIPropertyBar *property_bar,
434 gl_debug (DEBUG_PROPERTY_BAR, "START");
436 g_return_if_fail (view && GL_IS_VIEW (view));
438 g_return_if_fail (label && GL_IS_LABEL (label));
440 set_doc_items_sensitive (property_bar, TRUE);
442 property_bar->priv->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
444 reset_to_default_properties (view, property_bar);
446 g_signal_connect_swapped (G_OBJECT(view), "selection_changed",
447 G_CALLBACK(selection_changed_cb), property_bar);
449 g_signal_connect_swapped (G_OBJECT(view->label), "changed",
450 G_CALLBACK(selection_changed_cb), property_bar);
452 gl_debug (DEBUG_PROPERTY_BAR, "END");
455 /****************************************************************************/
456 /** Set visiblity of property bar's tooltips. */
457 /****************************************************************************/
459 gl_ui_property_bar_set_tooltips (glUIPropertyBar *property_bar,
462 GtkTooltipsData *data;
464 gl_debug (DEBUG_PROPERTY_BAR, "START");
466 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR(property_bar));
468 /* HACK: peek into one of our widgets to get the tooltips group created by libglade. */
469 data = gtk_tooltips_data_get (property_bar->priv->font_size_spin);
470 g_return_if_fail (data);
473 gtk_tooltips_enable (data->tooltips);
475 gtk_tooltips_disable (data->tooltips);
478 gl_debug (DEBUG_PROPERTY_BAR, "END");
481 /*---------------------------------------------------------------------------*/
482 /* PRIVATE. View "selection state changed" callback. */
483 /*---------------------------------------------------------------------------*/
485 update_text_properties (glView *view,
486 glUIPropertyBar *property_bar)
488 gboolean can_text, is_first_object;
489 gboolean is_same_font_family, is_same_font_size;
490 gboolean is_same_text_color, is_same_is_italic;
491 gboolean is_same_is_bold, is_same_align;
493 glLabelObject *object;
494 gchar *selection_font_family, *font_family;
495 gdouble selection_font_size, font_size;
496 guint selection_text_color, text_color;
497 glColorNode *text_color_node;
498 gboolean selection_is_italic, is_italic;
499 gboolean selection_is_bold, is_bold;
500 PangoAlignment selection_align, align;
503 can_text = gl_view_can_selection_text (view);
504 set_text_items_sensitive (property_bar, can_text);
514 is_same_font_family = TRUE;
515 selection_font_family = NULL;
516 selection_font_size = -1;
517 is_first_object = TRUE;
519 for (p = view->selected_object_list; p != NULL; p = p->next) {
521 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
522 if (!gl_label_object_can_text (object))
525 font_family = gl_label_object_get_font_family (object);
526 if (font_family != NULL) {
527 if (selection_font_family == NULL)
528 selection_font_family = g_strdup (font_family);
530 if (strcmp (font_family, selection_font_family) != 0)
531 is_same_font_family = FALSE;
532 g_free (font_family);
535 font_size = gl_label_object_get_font_size (object);
537 text_color_node = gl_label_object_get_text_color (object);
538 if (text_color_node->field_flag) {
539 /* If a merge field is set we use the default color for merged color*/
540 text_color = GL_COLOR_MERGE_DEFAULT;
543 text_color = text_color_node->color;
545 gl_color_node_free (&text_color_node);
547 is_italic = gl_label_object_get_font_italic_flag (object);
548 is_bold = gl_label_object_get_font_weight (object) == PANGO_WEIGHT_BOLD;
549 align = gl_label_object_get_text_alignment (object);
551 if (is_first_object) {
552 selection_font_size = font_size;
553 selection_text_color = text_color;
554 selection_is_italic = is_italic;
555 selection_is_bold = is_bold;
556 selection_align = align;
558 if (font_size != selection_font_size)
559 is_same_font_size = FALSE;
560 if (text_color != selection_text_color)
561 is_same_text_color = FALSE;
562 if (is_italic != selection_is_italic)
563 is_same_is_italic = FALSE;
564 if (is_bold != selection_is_bold)
565 is_same_is_bold = FALSE;
566 if (align != selection_align)
567 is_same_align = FALSE;
569 is_first_object = FALSE;
572 if (is_same_font_family && (selection_font_family != NULL))
573 gl_debug (DEBUG_PROPERTY_BAR, "same font family = %s",
574 selection_font_family);
575 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
576 is_same_font_family?selection_font_family:"");
577 g_free (selection_font_family);
579 if (is_same_font_size) {
580 gl_debug (DEBUG_PROPERTY_BAR, "same font size = %g",
581 selection_font_size);
582 gtk_spin_button_set_value (GTK_SPIN_BUTTON (property_bar->priv->font_size_spin),
583 selection_font_size);
585 gtk_entry_set_text (GTK_ENTRY (property_bar->priv->font_size_spin), "");
588 if (is_same_text_color) {
589 gl_debug (DEBUG_PROPERTY_BAR, "same text color = %08x", selection_text_color);
590 gdk_color = gl_color_to_gdk_color (selection_text_color);
591 color_combo_set_color (COLOR_COMBO (property_bar->priv->text_color_combo),
596 if (is_same_is_italic)
597 gl_debug (DEBUG_PROPERTY_BAR, "same italic flag = %d",
598 selection_is_italic);
599 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_italic_toggle),
600 selection_is_italic && is_same_is_italic);
603 gl_debug (DEBUG_PROPERTY_BAR, "same bold flag = %d",
605 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_bold_toggle),
606 selection_is_bold && is_same_is_bold);
609 gl_debug (DEBUG_PROPERTY_BAR, "same align");
610 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio),
611 (selection_align == PANGO_ALIGN_LEFT) &&
613 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio),
614 (selection_align == PANGO_ALIGN_CENTER) &&
616 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio),
617 (selection_align == PANGO_ALIGN_RIGHT) &&
622 update_fill_color (glView *view,
623 glUIPropertyBar *property_bar)
625 gboolean can, is_first_object;
626 gboolean is_same_fill_color;
628 glLabelObject *object;
629 guint selection_fill_color, fill_color;
631 glColorNode *fill_color_node;
633 can = gl_view_can_selection_fill (view);
634 set_fill_items_sensitive (property_bar, can);
639 is_same_fill_color = TRUE;
640 is_first_object = TRUE;
642 for (p = view->selected_object_list; p != NULL; p = p->next) {
644 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
645 if (!gl_label_object_can_fill (object))
648 fill_color_node = gl_label_object_get_fill_color (object);
649 if (fill_color_node->field_flag) {
650 /* If a merge field is set we use the default color for merged color*/
651 fill_color = GL_COLOR_FILL_MERGE_DEFAULT;
654 fill_color = fill_color_node->color;
656 gl_color_node_free (&fill_color_node);
658 if (is_first_object) {
659 selection_fill_color = fill_color;
661 if (fill_color != selection_fill_color)
662 is_same_fill_color = FALSE;
664 is_first_object = FALSE;
667 if (is_same_fill_color) {
668 gl_debug (DEBUG_PROPERTY_BAR, "same fill color = %08x", selection_fill_color);
669 gdk_color = gl_color_to_gdk_color (selection_fill_color);
670 color_combo_set_color (COLOR_COMBO (property_bar->priv->fill_color_combo),
677 update_line_color (glView *view,
678 glUIPropertyBar *property_bar)
680 gboolean can, is_first_object;
681 gboolean is_same_line_color;
683 glLabelObject *object;
684 guint selection_line_color, line_color;
685 glColorNode *line_color_node;
688 can = gl_view_can_selection_line_color (view);
689 set_line_color_items_sensitive (property_bar, can);
694 is_same_line_color = TRUE;
695 is_first_object = TRUE;
697 for (p = view->selected_object_list; p != NULL; p = p->next) {
699 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
700 if (!gl_label_object_can_line_color (object))
703 line_color_node = gl_label_object_get_line_color (object);
704 if (line_color_node->field_flag) {
705 /* If a merge field is set we use the default color for merged color*/
706 line_color = GL_COLOR_MERGE_DEFAULT;
709 line_color = line_color_node->color;
711 gl_color_node_free (&line_color_node);
713 if (is_first_object) {
714 selection_line_color = line_color;
716 if (line_color != selection_line_color)
717 is_same_line_color = FALSE;
719 is_first_object = FALSE;
722 if (is_same_line_color) {
723 gl_debug (DEBUG_PROPERTY_BAR, "same line color = %08x", selection_line_color);
724 gdk_color = gl_color_to_gdk_color (selection_line_color);
725 color_combo_set_color (COLOR_COMBO (property_bar->priv->line_color_combo),
732 update_line_width (glView *view,
733 glUIPropertyBar *property_bar)
735 gboolean can, is_first_object;
736 gboolean is_same_line_width;
738 glLabelObject *object;
739 gdouble selection_line_width, line_width;
741 can = gl_view_can_selection_line_width (view);
742 set_line_width_items_sensitive (property_bar, can);
747 is_same_line_width = TRUE;
748 is_first_object = TRUE;
750 for (p = view->selected_object_list; p != NULL; p = p->next) {
752 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
753 if (!gl_label_object_can_line_width (object))
756 line_width = gl_label_object_get_line_width (object);
758 if (is_first_object) {
759 selection_line_width = line_width;
761 if (line_width != selection_line_width)
762 is_same_line_width = FALSE;
764 is_first_object = FALSE;
767 if (is_same_line_width) {
768 gl_debug (DEBUG_PROPERTY_BAR, "same line width = %g", selection_line_width);
769 gtk_spin_button_set_value (GTK_SPIN_BUTTON (property_bar->priv->line_width_spin),
770 selection_line_width);
772 gtk_entry_set_text (GTK_ENTRY (property_bar->priv->line_width_spin), "");
777 selection_changed_cb (glUIPropertyBar *property_bar)
779 glView *view = property_bar->priv->view;
781 gl_debug (DEBUG_PROPERTY_BAR, "START");
783 g_return_if_fail (view && GL_IS_VIEW (view));
784 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
786 property_bar->priv->stop_signals = TRUE;
788 if (gl_view_is_selection_empty (view)) {
790 /* No selection: make all controls active. */
791 reset_to_default_properties (view, property_bar);
792 set_doc_items_sensitive (property_bar, TRUE);
796 update_text_properties (view, property_bar);
797 update_fill_color (view, property_bar);
798 update_line_color (view, property_bar);
799 update_line_width (view, property_bar);
803 property_bar->priv->stop_signals = FALSE;
805 gl_debug (DEBUG_PROPERTY_BAR, "END");
808 /*--------------------------------------------------------------------------*/
809 /* PRIVATE. Font family entry changed. */
810 /*--------------------------------------------------------------------------*/
812 font_family_changed_cb (GtkComboBox *combo,
813 glUIPropertyBar *property_bar)
817 if (property_bar->priv->stop_signals)
820 gl_debug (DEBUG_PROPERTY_BAR, "START");
822 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
823 selection_changed_cb,
826 font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
827 if ( strlen(font_family) ) {
828 gl_view_set_selection_font_family (property_bar->priv->view,
830 gl_view_set_default_font_family (property_bar->priv->view,
833 g_free (font_family);
835 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
836 selection_changed_cb,
839 gl_debug (DEBUG_PROPERTY_BAR, "END");
842 /*--------------------------------------------------------------------------*/
843 /* PRIVATE. Font size spin button changed. */
844 /*--------------------------------------------------------------------------*/
846 font_size_changed_cb (GtkSpinButton *spin,
847 glUIPropertyBar *property_bar)
851 if (property_bar->priv->stop_signals)
854 gl_debug (DEBUG_PROPERTY_BAR, "START");
856 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
857 selection_changed_cb,
860 font_size = gtk_spin_button_get_value (spin);
862 gl_view_set_selection_font_size (property_bar->priv->view,
864 gl_view_set_default_font_size (property_bar->priv->view,
867 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
868 selection_changed_cb,
871 gl_debug (DEBUG_PROPERTY_BAR, "END");
874 /*--------------------------------------------------------------------------*/
875 /* PRIVATE. Text color combo changed. */
876 /*--------------------------------------------------------------------------*/
878 text_color_changed_cb (ColorCombo *cc,
883 glUIPropertyBar *property_bar)
885 glColorNode *text_color_node;
887 if (property_bar->priv->stop_signals)
890 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
892 gl_debug (DEBUG_PROPERTY_BAR, "START");
894 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
895 selection_changed_cb,
898 text_color_node = gl_color_node_new_default ();
899 text_color_node->color = gl_color_from_gdk_color (gdk_color);
901 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d",
902 text_color_node->color, custom, by_user, is_default);
905 text_color_node->color = gl_prefs->default_text_color;
906 gl_view_set_selection_text_color (property_bar->priv->view,
908 gl_view_set_default_text_color (property_bar->priv->view,
909 gl_prefs->default_text_color);
913 gl_view_set_selection_text_color (property_bar->priv->view,
915 gl_view_set_default_text_color (property_bar->priv->view,
916 text_color_node->color);
920 gl_color_node_free (&text_color_node);
922 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
923 selection_changed_cb,
926 gl_debug (DEBUG_PROPERTY_BAR, "END");
929 /*--------------------------------------------------------------------------*/
930 /* PRIVATE. Fill color combo changed. */
931 /*--------------------------------------------------------------------------*/
933 fill_color_changed_cb (ColorCombo *cc,
938 glUIPropertyBar *property_bar)
940 glColorNode *fill_color_node;
942 if (property_bar->priv->stop_signals)
945 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
947 gl_debug (DEBUG_PROPERTY_BAR, "START");
949 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
950 selection_changed_cb,
953 fill_color_node = gl_color_node_new_default ();
955 fill_color_node->color = gl_color_from_gdk_color (gdk_color);
957 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d",
958 fill_color_node->color, custom, by_user, is_default);
962 fill_color_node->color = GL_COLOR_NONE;
963 gl_view_set_selection_fill_color (property_bar->priv->view,
965 gl_view_set_default_fill_color (property_bar->priv->view,
966 fill_color_node->color);
970 gl_view_set_selection_fill_color (property_bar->priv->view,
972 gl_view_set_default_fill_color (property_bar->priv->view,
973 fill_color_node->color);
976 gl_color_node_free (&fill_color_node);
978 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
979 selection_changed_cb,
982 gl_debug (DEBUG_PROPERTY_BAR, "END");
985 /*--------------------------------------------------------------------------*/
986 /* PRIVATE. Line color combo changed. */
987 /*--------------------------------------------------------------------------*/
989 line_color_changed_cb (ColorCombo *cc,
994 glUIPropertyBar *property_bar)
996 glColorNode *line_color_node;
998 if (property_bar->priv->stop_signals)
1001 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
1003 gl_debug (DEBUG_PROPERTY_BAR, "START");
1005 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1006 selection_changed_cb,
1009 line_color_node = gl_color_node_new_default ();
1010 line_color_node->color = gl_color_from_gdk_color (gdk_color);
1012 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d",
1013 line_color_node->color, custom, by_user, is_default);
1016 line_color_node->color = GL_COLOR_NONE;
1017 gl_view_set_selection_line_color (property_bar->priv->view,
1019 gl_view_set_default_line_color (property_bar->priv->view,
1020 line_color_node->color);
1024 gl_view_set_selection_line_color (property_bar->priv->view,
1026 gl_view_set_default_line_color (property_bar->priv->view,
1027 line_color_node->color);
1030 gl_color_node_free (&line_color_node);
1032 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1033 selection_changed_cb,
1036 gl_debug (DEBUG_PROPERTY_BAR, "END");
1039 /*--------------------------------------------------------------------------*/
1040 /* PRIVATE. Line width spin button changed. */
1041 /*--------------------------------------------------------------------------*/
1043 line_width_changed_cb (GtkSpinButton *spin,
1044 glUIPropertyBar *property_bar)
1048 if (property_bar->priv->stop_signals)
1051 gl_debug (DEBUG_PROPERTY_BAR, "START");
1053 if (property_bar->priv->view) {
1055 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1056 selection_changed_cb,
1059 line_width = gtk_spin_button_get_value (spin);
1061 gl_view_set_selection_line_width (property_bar->priv->view,
1063 gl_view_set_default_line_width (property_bar->priv->view,
1066 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1067 selection_changed_cb,
1072 gl_debug (DEBUG_PROPERTY_BAR, "END");
1075 /*---------------------------------------------------------------------------*/
1076 /* PRIVATE. Font bold toggled callback. */
1077 /*---------------------------------------------------------------------------*/
1079 font_bold_toggled_cb (GtkToggleToolButton *toggle,
1080 glUIPropertyBar *property_bar)
1086 if (property_bar->priv->stop_signals)
1089 gl_debug (DEBUG_PROPERTY_BAR, "START");
1091 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1092 selection_changed_cb,
1095 state = gtk_toggle_tool_button_get_active (toggle);
1097 weight = state ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
1099 gl_view_set_selection_font_weight (property_bar->priv->view, weight);
1100 gl_view_set_default_font_weight (property_bar->priv->view, weight);
1102 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1103 selection_changed_cb,
1106 gl_debug (DEBUG_PROPERTY_BAR, "END");
1109 /*---------------------------------------------------------------------------*/
1110 /* PRIVATE. Font italic toggled callback. */
1111 /*---------------------------------------------------------------------------*/
1113 font_italic_toggled_cb (GtkToggleToolButton *toggle,
1114 glUIPropertyBar *property_bar)
1118 if (property_bar->priv->stop_signals)
1121 gl_debug (DEBUG_PROPERTY_BAR, "START");
1123 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1124 selection_changed_cb,
1127 state = gtk_toggle_tool_button_get_active (toggle);
1129 gl_view_set_selection_font_italic_flag (property_bar->priv->view, state);
1130 gl_view_set_default_font_italic_flag (property_bar->priv->view, state);
1132 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1133 selection_changed_cb,
1136 gl_debug (DEBUG_PROPERTY_BAR, "END");
1139 /*---------------------------------------------------------------------------*/
1140 /* PRIVATE. Text align toggled callback. */
1141 /*---------------------------------------------------------------------------*/
1143 text_align_toggled_cb (GtkToggleToolButton *toggle,
1144 glUIPropertyBar *property_bar)
1146 if (property_bar->priv->stop_signals)
1149 gl_debug (DEBUG_PROPERTY_BAR, "START");
1151 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1152 selection_changed_cb,
1155 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio)))
1157 gl_view_set_selection_text_alignment (property_bar->priv->view,
1159 gl_view_set_default_text_alignment (property_bar->priv->view,
1163 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio)))
1165 gl_view_set_selection_text_alignment (property_bar->priv->view,
1166 PANGO_ALIGN_CENTER);
1167 gl_view_set_default_text_alignment (property_bar->priv->view,
1168 PANGO_ALIGN_CENTER);
1171 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio)))
1173 gl_view_set_selection_text_alignment (property_bar->priv->view,
1175 gl_view_set_default_text_alignment (property_bar->priv->view,
1179 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1180 selection_changed_cb,
1183 gl_debug (DEBUG_PROPERTY_BAR, "END");
1187 /*****************************************************************************/
1188 /* Construct color combo "Custom widget". */
1189 /*****************************************************************************/
1191 gl_ui_property_bar_construct_color_combo (gchar *name,
1197 GtkWidget *color_combo;
1201 GdkColor *gdk_color;
1203 GdkPixbuf *pixbuf = NULL;
1208 cg_name = "text_color_group";
1209 color = gl_prefs->default_text_color;
1210 no_color = _("Default");
1211 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_text_24, FALSE, NULL);
1215 cg_name = "line_color_group";
1216 color = gl_prefs->default_line_color;
1217 no_color = _("No line");
1218 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_pencil_24, FALSE, NULL);
1223 cg_name = "fill_color_group";
1224 color = gl_prefs->default_fill_color;
1225 no_color = _("No fill");
1226 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_bucket_fill_24, FALSE, NULL);
1231 cg = color_group_fetch (cg_name, NULL);
1232 gdk_color = gl_color_to_gdk_color (color);
1233 color_combo = color_combo_new (pixbuf, no_color, gdk_color, cg);
1236 color_combo_box_set_preview_relief (COLOR_COMBO(color_combo), GTK_RELIEF_NORMAL);
1238 g_object_unref (G_OBJECT (pixbuf));
1243 /*---------------------------------------------------------------------------*/
1244 /* PRIVATE. Set sensitivity of doc controls. */
1245 /*---------------------------------------------------------------------------*/
1247 set_doc_items_sensitive (glUIPropertyBar *property_bar,
1250 gtk_widget_set_sensitive (property_bar->priv->font_family_combo, state);
1251 gtk_widget_set_sensitive (property_bar->priv->font_size_spin, state);
1252 gtk_widget_set_sensitive (property_bar->priv->font_bold_toggle, state);
1253 gtk_widget_set_sensitive (property_bar->priv->font_italic_toggle, state);
1254 gtk_widget_set_sensitive (property_bar->priv->text_align_left_radio, state);
1255 gtk_widget_set_sensitive (property_bar->priv->text_align_center_radio, state);
1256 gtk_widget_set_sensitive (property_bar->priv->text_align_right_radio, state);
1257 gtk_widget_set_sensitive (property_bar->priv->text_color_combo, state);
1258 gtk_widget_set_sensitive (property_bar->priv->fill_color_combo, state);
1259 gtk_widget_set_sensitive (property_bar->priv->line_color_combo, state);
1260 gtk_widget_set_sensitive (property_bar->priv->line_width_spin, state);
1263 /*---------------------------------------------------------------------------*/
1264 /* PRIVATE. Set sensitivity of text related controls. */
1265 /*---------------------------------------------------------------------------*/
1267 set_text_items_sensitive (glUIPropertyBar *property_bar,
1270 gtk_widget_set_sensitive (property_bar->priv->font_family_combo, state);
1271 gtk_widget_set_sensitive (property_bar->priv->font_size_spin, state);
1272 gtk_widget_set_sensitive (property_bar->priv->font_bold_toggle, state);
1273 gtk_widget_set_sensitive (property_bar->priv->font_italic_toggle, state);
1274 gtk_widget_set_sensitive (property_bar->priv->text_align_left_radio, state);
1275 gtk_widget_set_sensitive (property_bar->priv->text_align_center_radio, state);
1276 gtk_widget_set_sensitive (property_bar->priv->text_align_right_radio, state);
1277 gtk_widget_set_sensitive (property_bar->priv->text_color_combo, state);
1280 /*---------------------------------------------------------------------------*/
1281 /* PRIVATE. Set sensitivity of fill related controls. */
1282 /*---------------------------------------------------------------------------*/
1284 set_fill_items_sensitive (glUIPropertyBar *property_bar,
1287 gtk_widget_set_sensitive (property_bar->priv->fill_color_combo, state);
1290 /*---------------------------------------------------------------------------*/
1291 /* PRIVATE. Set sensitivity of line color related controls. */
1292 /*---------------------------------------------------------------------------*/
1294 set_line_color_items_sensitive (glUIPropertyBar *property_bar,
1297 gtk_widget_set_sensitive (property_bar->priv->line_color_combo, state);
1300 /*---------------------------------------------------------------------------*/
1301 /* PRIVATE. Set sensitivity of line width related controls. */
1302 /*---------------------------------------------------------------------------*/
1304 set_line_width_items_sensitive (glUIPropertyBar *property_bar,
1307 gtk_widget_set_sensitive (property_bar->priv->line_width_spin, state);