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 selection_align = PANGO_ALIGN_LEFT;
518 selection_is_italic = TRUE;
519 selection_is_bold = TRUE;
520 selection_text_color = 0;
522 is_first_object = TRUE;
524 for (p = view->selected_object_list; p != NULL; p = p->next) {
526 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
527 if (!gl_label_object_can_text (object))
530 font_family = gl_label_object_get_font_family (object);
531 if (font_family != NULL) {
532 if (selection_font_family == NULL)
533 selection_font_family = g_strdup (font_family);
535 if (strcmp (font_family, selection_font_family) != 0)
536 is_same_font_family = FALSE;
537 g_free (font_family);
540 font_size = gl_label_object_get_font_size (object);
542 text_color_node = gl_label_object_get_text_color (object);
543 if (text_color_node->field_flag) {
544 /* If a merge field is set we use the default color for merged color*/
545 text_color = GL_COLOR_MERGE_DEFAULT;
548 text_color = text_color_node->color;
550 gl_color_node_free (&text_color_node);
552 is_italic = gl_label_object_get_font_italic_flag (object);
553 is_bold = gl_label_object_get_font_weight (object) == PANGO_WEIGHT_BOLD;
554 align = gl_label_object_get_text_alignment (object);
556 if (is_first_object) {
557 selection_font_size = font_size;
558 selection_text_color = text_color;
559 selection_is_italic = is_italic;
560 selection_is_bold = is_bold;
561 selection_align = align;
563 if (font_size != selection_font_size)
564 is_same_font_size = FALSE;
565 if (text_color != selection_text_color)
566 is_same_text_color = FALSE;
567 if (is_italic != selection_is_italic)
568 is_same_is_italic = FALSE;
569 if (is_bold != selection_is_bold)
570 is_same_is_bold = FALSE;
571 if (align != selection_align)
572 is_same_align = FALSE;
574 is_first_object = FALSE;
577 if (is_same_font_family && (selection_font_family != NULL))
578 gl_debug (DEBUG_PROPERTY_BAR, "same font family = %s",
579 selection_font_family);
580 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
581 is_same_font_family?selection_font_family:"");
582 g_free (selection_font_family);
584 if (is_same_font_size) {
585 gl_debug (DEBUG_PROPERTY_BAR, "same font size = %g",
586 selection_font_size);
587 gtk_spin_button_set_value (GTK_SPIN_BUTTON (property_bar->priv->font_size_spin),
588 selection_font_size);
590 gtk_entry_set_text (GTK_ENTRY (property_bar->priv->font_size_spin), "");
593 if (is_same_text_color) {
594 gl_debug (DEBUG_PROPERTY_BAR, "same text color = %08x", selection_text_color);
595 gdk_color = gl_color_to_gdk_color (selection_text_color);
596 color_combo_set_color (COLOR_COMBO (property_bar->priv->text_color_combo),
601 if (is_same_is_italic)
602 gl_debug (DEBUG_PROPERTY_BAR, "same italic flag = %d",
603 selection_is_italic);
604 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_italic_toggle),
605 selection_is_italic && is_same_is_italic);
608 gl_debug (DEBUG_PROPERTY_BAR, "same bold flag = %d",
610 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_bold_toggle),
611 selection_is_bold && is_same_is_bold);
614 gl_debug (DEBUG_PROPERTY_BAR, "same align");
615 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio),
616 (selection_align == PANGO_ALIGN_LEFT) &&
618 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio),
619 (selection_align == PANGO_ALIGN_CENTER) &&
621 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio),
622 (selection_align == PANGO_ALIGN_RIGHT) &&
627 update_fill_color (glView *view,
628 glUIPropertyBar *property_bar)
630 gboolean can, is_first_object;
631 gboolean is_same_fill_color;
633 glLabelObject *object;
634 guint selection_fill_color, fill_color;
636 glColorNode *fill_color_node;
638 can = gl_view_can_selection_fill (view);
639 set_fill_items_sensitive (property_bar, can);
644 is_same_fill_color = TRUE;
645 is_first_object = TRUE;
646 selection_fill_color = 0;
648 for (p = view->selected_object_list; p != NULL; p = p->next) {
650 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
651 if (!gl_label_object_can_fill (object))
654 fill_color_node = gl_label_object_get_fill_color (object);
655 if (fill_color_node->field_flag) {
656 /* If a merge field is set we use the default color for merged color*/
657 fill_color = GL_COLOR_FILL_MERGE_DEFAULT;
660 fill_color = fill_color_node->color;
662 gl_color_node_free (&fill_color_node);
664 if (is_first_object) {
665 selection_fill_color = fill_color;
667 if (fill_color != selection_fill_color)
668 is_same_fill_color = FALSE;
670 is_first_object = FALSE;
673 if (is_same_fill_color) {
674 gl_debug (DEBUG_PROPERTY_BAR, "same fill color = %08x", selection_fill_color);
675 gdk_color = gl_color_to_gdk_color (selection_fill_color);
676 color_combo_set_color (COLOR_COMBO (property_bar->priv->fill_color_combo),
683 update_line_color (glView *view,
684 glUIPropertyBar *property_bar)
686 gboolean can, is_first_object;
687 gboolean is_same_line_color;
689 glLabelObject *object;
690 guint selection_line_color, line_color;
691 glColorNode *line_color_node;
694 can = gl_view_can_selection_line_color (view);
695 set_line_color_items_sensitive (property_bar, can);
700 is_same_line_color = TRUE;
701 is_first_object = TRUE;
702 selection_line_color = 0;
704 for (p = view->selected_object_list; p != NULL; p = p->next) {
706 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
707 if (!gl_label_object_can_line_color (object))
710 line_color_node = gl_label_object_get_line_color (object);
711 if (line_color_node->field_flag) {
712 /* If a merge field is set we use the default color for merged color*/
713 line_color = GL_COLOR_MERGE_DEFAULT;
716 line_color = line_color_node->color;
718 gl_color_node_free (&line_color_node);
720 if (is_first_object) {
721 selection_line_color = line_color;
723 if (line_color != selection_line_color)
724 is_same_line_color = FALSE;
726 is_first_object = FALSE;
729 if (is_same_line_color) {
730 gl_debug (DEBUG_PROPERTY_BAR, "same line color = %08x", selection_line_color);
731 gdk_color = gl_color_to_gdk_color (selection_line_color);
732 color_combo_set_color (COLOR_COMBO (property_bar->priv->line_color_combo),
739 update_line_width (glView *view,
740 glUIPropertyBar *property_bar)
742 gboolean can, is_first_object;
743 gboolean is_same_line_width;
745 glLabelObject *object;
746 gdouble selection_line_width, line_width;
748 can = gl_view_can_selection_line_width (view);
749 set_line_width_items_sensitive (property_bar, can);
754 is_same_line_width = TRUE;
755 is_first_object = TRUE;
756 selection_line_width = 0;
758 for (p = view->selected_object_list; p != NULL; p = p->next) {
760 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
761 if (!gl_label_object_can_line_width (object))
764 line_width = gl_label_object_get_line_width (object);
766 if (is_first_object) {
767 selection_line_width = line_width;
769 if (line_width != selection_line_width)
770 is_same_line_width = FALSE;
772 is_first_object = FALSE;
775 if (is_same_line_width) {
776 gl_debug (DEBUG_PROPERTY_BAR, "same line width = %g", selection_line_width);
777 gtk_spin_button_set_value (GTK_SPIN_BUTTON (property_bar->priv->line_width_spin),
778 selection_line_width);
780 gtk_entry_set_text (GTK_ENTRY (property_bar->priv->line_width_spin), "");
785 selection_changed_cb (glUIPropertyBar *property_bar)
787 glView *view = property_bar->priv->view;
789 gl_debug (DEBUG_PROPERTY_BAR, "START");
791 g_return_if_fail (view && GL_IS_VIEW (view));
792 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
794 property_bar->priv->stop_signals = TRUE;
796 if (gl_view_is_selection_empty (view)) {
798 /* No selection: make all controls active. */
799 reset_to_default_properties (view, property_bar);
800 set_doc_items_sensitive (property_bar, TRUE);
804 update_text_properties (view, property_bar);
805 update_fill_color (view, property_bar);
806 update_line_color (view, property_bar);
807 update_line_width (view, property_bar);
811 property_bar->priv->stop_signals = FALSE;
813 gl_debug (DEBUG_PROPERTY_BAR, "END");
816 /*--------------------------------------------------------------------------*/
817 /* PRIVATE. Font family entry changed. */
818 /*--------------------------------------------------------------------------*/
820 font_family_changed_cb (GtkComboBox *combo,
821 glUIPropertyBar *property_bar)
825 if (property_bar->priv->stop_signals)
828 gl_debug (DEBUG_PROPERTY_BAR, "START");
830 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
831 selection_changed_cb,
834 font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
835 if ( strlen(font_family) ) {
836 gl_view_set_selection_font_family (property_bar->priv->view,
838 gl_view_set_default_font_family (property_bar->priv->view,
841 g_free (font_family);
843 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
844 selection_changed_cb,
847 gl_debug (DEBUG_PROPERTY_BAR, "END");
850 /*--------------------------------------------------------------------------*/
851 /* PRIVATE. Font size spin button changed. */
852 /*--------------------------------------------------------------------------*/
854 font_size_changed_cb (GtkSpinButton *spin,
855 glUIPropertyBar *property_bar)
859 if (property_bar->priv->stop_signals)
862 gl_debug (DEBUG_PROPERTY_BAR, "START");
864 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
865 selection_changed_cb,
868 font_size = gtk_spin_button_get_value (spin);
870 gl_view_set_selection_font_size (property_bar->priv->view,
872 gl_view_set_default_font_size (property_bar->priv->view,
875 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
876 selection_changed_cb,
879 gl_debug (DEBUG_PROPERTY_BAR, "END");
882 /*--------------------------------------------------------------------------*/
883 /* PRIVATE. Text color combo changed. */
884 /*--------------------------------------------------------------------------*/
886 text_color_changed_cb (ColorCombo *cc,
891 glUIPropertyBar *property_bar)
893 glColorNode *text_color_node;
895 if (property_bar->priv->stop_signals)
898 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
900 gl_debug (DEBUG_PROPERTY_BAR, "START");
902 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
903 selection_changed_cb,
906 text_color_node = gl_color_node_new_default ();
907 text_color_node->color = gl_color_from_gdk_color (gdk_color);
909 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d",
910 text_color_node->color, custom, by_user, is_default);
913 text_color_node->color = gl_prefs->default_text_color;
914 gl_view_set_selection_text_color (property_bar->priv->view,
916 gl_view_set_default_text_color (property_bar->priv->view,
917 gl_prefs->default_text_color);
921 gl_view_set_selection_text_color (property_bar->priv->view,
923 gl_view_set_default_text_color (property_bar->priv->view,
924 text_color_node->color);
928 gl_color_node_free (&text_color_node);
930 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
931 selection_changed_cb,
934 gl_debug (DEBUG_PROPERTY_BAR, "END");
937 /*--------------------------------------------------------------------------*/
938 /* PRIVATE. Fill color combo changed. */
939 /*--------------------------------------------------------------------------*/
941 fill_color_changed_cb (ColorCombo *cc,
946 glUIPropertyBar *property_bar)
948 glColorNode *fill_color_node;
950 if (property_bar->priv->stop_signals)
953 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
955 gl_debug (DEBUG_PROPERTY_BAR, "START");
957 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
958 selection_changed_cb,
961 fill_color_node = gl_color_node_new_default ();
963 fill_color_node->color = gl_color_from_gdk_color (gdk_color);
965 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d",
966 fill_color_node->color, custom, by_user, is_default);
970 fill_color_node->color = GL_COLOR_NONE;
971 gl_view_set_selection_fill_color (property_bar->priv->view,
973 gl_view_set_default_fill_color (property_bar->priv->view,
974 fill_color_node->color);
978 gl_view_set_selection_fill_color (property_bar->priv->view,
980 gl_view_set_default_fill_color (property_bar->priv->view,
981 fill_color_node->color);
984 gl_color_node_free (&fill_color_node);
986 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
987 selection_changed_cb,
990 gl_debug (DEBUG_PROPERTY_BAR, "END");
993 /*--------------------------------------------------------------------------*/
994 /* PRIVATE. Line color combo changed. */
995 /*--------------------------------------------------------------------------*/
997 line_color_changed_cb (ColorCombo *cc,
1001 gboolean is_default,
1002 glUIPropertyBar *property_bar)
1004 glColorNode *line_color_node;
1006 if (property_bar->priv->stop_signals)
1009 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
1011 gl_debug (DEBUG_PROPERTY_BAR, "START");
1013 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1014 selection_changed_cb,
1017 line_color_node = gl_color_node_new_default ();
1018 line_color_node->color = gl_color_from_gdk_color (gdk_color);
1020 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d",
1021 line_color_node->color, custom, by_user, is_default);
1024 line_color_node->color = GL_COLOR_NONE;
1025 gl_view_set_selection_line_color (property_bar->priv->view,
1027 gl_view_set_default_line_color (property_bar->priv->view,
1028 line_color_node->color);
1032 gl_view_set_selection_line_color (property_bar->priv->view,
1034 gl_view_set_default_line_color (property_bar->priv->view,
1035 line_color_node->color);
1038 gl_color_node_free (&line_color_node);
1040 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1041 selection_changed_cb,
1044 gl_debug (DEBUG_PROPERTY_BAR, "END");
1047 /*--------------------------------------------------------------------------*/
1048 /* PRIVATE. Line width spin button changed. */
1049 /*--------------------------------------------------------------------------*/
1051 line_width_changed_cb (GtkSpinButton *spin,
1052 glUIPropertyBar *property_bar)
1056 if (property_bar->priv->stop_signals)
1059 gl_debug (DEBUG_PROPERTY_BAR, "START");
1061 if (property_bar->priv->view) {
1063 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1064 selection_changed_cb,
1067 line_width = gtk_spin_button_get_value (spin);
1069 gl_view_set_selection_line_width (property_bar->priv->view,
1071 gl_view_set_default_line_width (property_bar->priv->view,
1074 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1075 selection_changed_cb,
1080 gl_debug (DEBUG_PROPERTY_BAR, "END");
1083 /*---------------------------------------------------------------------------*/
1084 /* PRIVATE. Font bold toggled callback. */
1085 /*---------------------------------------------------------------------------*/
1087 font_bold_toggled_cb (GtkToggleToolButton *toggle,
1088 glUIPropertyBar *property_bar)
1094 if (property_bar->priv->stop_signals)
1097 gl_debug (DEBUG_PROPERTY_BAR, "START");
1099 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1100 selection_changed_cb,
1103 state = gtk_toggle_tool_button_get_active (toggle);
1105 weight = state ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
1107 gl_view_set_selection_font_weight (property_bar->priv->view, weight);
1108 gl_view_set_default_font_weight (property_bar->priv->view, weight);
1110 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1111 selection_changed_cb,
1114 gl_debug (DEBUG_PROPERTY_BAR, "END");
1117 /*---------------------------------------------------------------------------*/
1118 /* PRIVATE. Font italic toggled callback. */
1119 /*---------------------------------------------------------------------------*/
1121 font_italic_toggled_cb (GtkToggleToolButton *toggle,
1122 glUIPropertyBar *property_bar)
1126 if (property_bar->priv->stop_signals)
1129 gl_debug (DEBUG_PROPERTY_BAR, "START");
1131 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1132 selection_changed_cb,
1135 state = gtk_toggle_tool_button_get_active (toggle);
1137 gl_view_set_selection_font_italic_flag (property_bar->priv->view, state);
1138 gl_view_set_default_font_italic_flag (property_bar->priv->view, state);
1140 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1141 selection_changed_cb,
1144 gl_debug (DEBUG_PROPERTY_BAR, "END");
1147 /*---------------------------------------------------------------------------*/
1148 /* PRIVATE. Text align toggled callback. */
1149 /*---------------------------------------------------------------------------*/
1151 text_align_toggled_cb (GtkToggleToolButton *toggle,
1152 glUIPropertyBar *property_bar)
1154 if (property_bar->priv->stop_signals)
1157 gl_debug (DEBUG_PROPERTY_BAR, "START");
1159 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1160 selection_changed_cb,
1163 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio)))
1165 gl_view_set_selection_text_alignment (property_bar->priv->view,
1167 gl_view_set_default_text_alignment (property_bar->priv->view,
1171 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio)))
1173 gl_view_set_selection_text_alignment (property_bar->priv->view,
1174 PANGO_ALIGN_CENTER);
1175 gl_view_set_default_text_alignment (property_bar->priv->view,
1176 PANGO_ALIGN_CENTER);
1179 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio)))
1181 gl_view_set_selection_text_alignment (property_bar->priv->view,
1183 gl_view_set_default_text_alignment (property_bar->priv->view,
1187 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1188 selection_changed_cb,
1191 gl_debug (DEBUG_PROPERTY_BAR, "END");
1195 /*****************************************************************************/
1196 /* Construct color combo "Custom widget". */
1197 /*****************************************************************************/
1199 gl_ui_property_bar_construct_color_combo (gchar *name,
1205 GtkWidget *color_combo;
1209 GdkColor *gdk_color;
1211 GdkPixbuf *pixbuf = NULL;
1216 cg_name = "text_color_group";
1217 color = gl_prefs->default_text_color;
1218 no_color = _("Default");
1219 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_text_24, FALSE, NULL);
1223 cg_name = "line_color_group";
1224 color = gl_prefs->default_line_color;
1225 no_color = _("No line");
1226 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_pencil_24, FALSE, NULL);
1231 cg_name = "fill_color_group";
1232 color = gl_prefs->default_fill_color;
1233 no_color = _("No fill");
1234 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_bucket_fill_24, FALSE, NULL);
1239 cg = color_group_fetch (cg_name, NULL);
1240 gdk_color = gl_color_to_gdk_color (color);
1241 color_combo = color_combo_new (pixbuf, no_color, gdk_color, cg);
1244 color_combo_box_set_preview_relief (COLOR_COMBO(color_combo), GTK_RELIEF_NORMAL);
1246 g_object_unref (G_OBJECT (pixbuf));
1251 /*---------------------------------------------------------------------------*/
1252 /* PRIVATE. Set sensitivity of doc controls. */
1253 /*---------------------------------------------------------------------------*/
1255 set_doc_items_sensitive (glUIPropertyBar *property_bar,
1258 gtk_widget_set_sensitive (property_bar->priv->font_family_combo, state);
1259 gtk_widget_set_sensitive (property_bar->priv->font_size_spin, state);
1260 gtk_widget_set_sensitive (property_bar->priv->font_bold_toggle, state);
1261 gtk_widget_set_sensitive (property_bar->priv->font_italic_toggle, state);
1262 gtk_widget_set_sensitive (property_bar->priv->text_align_left_radio, state);
1263 gtk_widget_set_sensitive (property_bar->priv->text_align_center_radio, state);
1264 gtk_widget_set_sensitive (property_bar->priv->text_align_right_radio, state);
1265 gtk_widget_set_sensitive (property_bar->priv->text_color_combo, state);
1266 gtk_widget_set_sensitive (property_bar->priv->fill_color_combo, state);
1267 gtk_widget_set_sensitive (property_bar->priv->line_color_combo, state);
1268 gtk_widget_set_sensitive (property_bar->priv->line_width_spin, state);
1271 /*---------------------------------------------------------------------------*/
1272 /* PRIVATE. Set sensitivity of text related controls. */
1273 /*---------------------------------------------------------------------------*/
1275 set_text_items_sensitive (glUIPropertyBar *property_bar,
1278 gtk_widget_set_sensitive (property_bar->priv->font_family_combo, state);
1279 gtk_widget_set_sensitive (property_bar->priv->font_size_spin, state);
1280 gtk_widget_set_sensitive (property_bar->priv->font_bold_toggle, state);
1281 gtk_widget_set_sensitive (property_bar->priv->font_italic_toggle, state);
1282 gtk_widget_set_sensitive (property_bar->priv->text_align_left_radio, state);
1283 gtk_widget_set_sensitive (property_bar->priv->text_align_center_radio, state);
1284 gtk_widget_set_sensitive (property_bar->priv->text_align_right_radio, state);
1285 gtk_widget_set_sensitive (property_bar->priv->text_color_combo, state);
1288 /*---------------------------------------------------------------------------*/
1289 /* PRIVATE. Set sensitivity of fill related controls. */
1290 /*---------------------------------------------------------------------------*/
1292 set_fill_items_sensitive (glUIPropertyBar *property_bar,
1295 gtk_widget_set_sensitive (property_bar->priv->fill_color_combo, state);
1298 /*---------------------------------------------------------------------------*/
1299 /* PRIVATE. Set sensitivity of line color related controls. */
1300 /*---------------------------------------------------------------------------*/
1302 set_line_color_items_sensitive (glUIPropertyBar *property_bar,
1305 gtk_widget_set_sensitive (property_bar->priv->line_color_combo, state);
1308 /*---------------------------------------------------------------------------*/
1309 /* PRIVATE. Set sensitivity of line width related controls. */
1310 /*---------------------------------------------------------------------------*/
1312 set_line_width_items_sensitive (glUIPropertyBar *property_bar,
1315 gtk_widget_set_sensitive (property_bar->priv->line_width_spin, state);