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 "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 (glColorCombo *cc,
109 glUIPropertyBar *property_bar);
111 static void fill_color_changed_cb (glColorCombo *cc,
114 glUIPropertyBar *property_bar);
116 static void line_color_changed_cb (glColorCombo *cc,
119 glUIPropertyBar *property_bar);
121 static void line_width_changed_cb (GtkSpinButton *spin,
122 glUIPropertyBar *property_bar);
124 static void font_bold_toggled_cb (GtkToggleToolButton *toggle,
125 glUIPropertyBar *property_bar);
127 static void font_italic_toggled_cb (GtkToggleToolButton *toggle,
128 glUIPropertyBar *property_bar);
130 static void text_align_toggled_cb (GtkToggleToolButton *toggle,
131 glUIPropertyBar *property_bar);
133 static void set_doc_items_sensitive (glUIPropertyBar *property_bar,
136 static void set_text_items_sensitive (glUIPropertyBar *property_bar,
139 static void set_fill_items_sensitive (glUIPropertyBar *property_bar,
142 static void set_line_color_items_sensitive (glUIPropertyBar *property_bar,
145 static void set_line_width_items_sensitive (glUIPropertyBar *property_bar,
149 /****************************************************************************/
150 /* Boilerplate Object stuff. */
151 /****************************************************************************/
152 G_DEFINE_TYPE (glUIPropertyBar, gl_ui_property_bar, GTK_TYPE_HBOX);
155 gl_ui_property_bar_class_init (glUIPropertyBarClass *class)
157 GObjectClass *object_class = G_OBJECT_CLASS (class);
159 gl_debug (DEBUG_PROPERTY_BAR, "START");
161 gl_ui_property_bar_parent_class = g_type_class_peek_parent (class);
163 object_class->finalize = gl_ui_property_bar_finalize;
165 gl_debug (DEBUG_PROPERTY_BAR, "END");
169 gl_ui_property_bar_init (glUIPropertyBar *property_bar)
171 gl_debug (DEBUG_PROPERTY_BAR, "START");
173 property_bar->priv = g_new0 (glUIPropertyBarPrivate, 1);
175 gl_debug (DEBUG_PROPERTY_BAR, "END");
179 gl_ui_property_bar_finalize (GObject *object)
181 glUIPropertyBar *property_bar = GL_UI_PROPERTY_BAR (object);
183 gl_debug (DEBUG_PROPERTY_BAR, "START");
185 g_return_if_fail (object != NULL);
186 g_return_if_fail (GL_IS_UI_PROPERTY_BAR (object));
188 if (property_bar->priv->view)
190 g_object_unref (G_OBJECT(property_bar->priv->view));
192 if (property_bar->priv->gui)
194 g_object_unref (G_OBJECT(property_bar->priv->gui));
196 g_free (property_bar->priv);
198 G_OBJECT_CLASS (gl_ui_property_bar_parent_class)->finalize (object);
200 gl_debug (DEBUG_PROPERTY_BAR, "END");
203 /****************************************************************************/
204 /* Create a NEW property_bar. */
205 /****************************************************************************/
207 gl_ui_property_bar_new (void)
209 glUIPropertyBar *property_bar;
211 gl_debug (DEBUG_PROPERTY_BAR, "START");
213 property_bar = g_object_new (GL_TYPE_UI_PROPERTY_BAR, NULL);
215 gl_ui_property_bar_construct (property_bar);
217 gl_debug (DEBUG_PROPERTY_BAR, "END");
219 return GTK_WIDGET (property_bar);
222 /******************************************************************************/
223 /* Initialize property toolbar. */
224 /******************************************************************************/
226 gl_ui_property_bar_construct (glUIPropertyBar *property_bar)
229 GList *family_names = NULL;
232 gl_debug (DEBUG_PROPERTY_BAR, "START");
234 property_bar->priv->stop_signals = TRUE;
236 gui = glade_xml_new (GLABELS_GLADE_DIR "property-bar.glade",
237 "property_toolbar", NULL);
241 g_critical ("Could not open property-bar.glade. gLabels may not be installed correctly!");
245 property_bar->priv->tool_bar = glade_xml_get_widget (gui, "property_toolbar");
246 gtk_container_add (GTK_CONTAINER (property_bar), property_bar->priv->tool_bar);
248 property_bar->priv->font_family_combo =
249 glade_xml_get_widget (gui, "font_family_combo");
250 property_bar->priv->font_size_spin =
251 glade_xml_get_widget (gui, "font_size_spin");
252 property_bar->priv->font_bold_toggle =
253 glade_xml_get_widget (gui, "font_bold_toggle");
254 property_bar->priv->font_italic_toggle =
255 glade_xml_get_widget (gui, "font_italic_toggle");
256 property_bar->priv->text_align_left_radio =
257 glade_xml_get_widget (gui, "text_align_left_radio");
258 property_bar->priv->text_align_center_radio =
259 glade_xml_get_widget (gui, "text_align_center_radio");
260 property_bar->priv->text_align_right_radio =
261 glade_xml_get_widget (gui, "text_align_right_radio");
262 property_bar->priv->text_color_combo =
263 glade_xml_get_widget (gui, "text_color_combo");
264 property_bar->priv->fill_color_combo =
265 glade_xml_get_widget (gui, "fill_color_combo");
266 property_bar->priv->line_color_combo =
267 glade_xml_get_widget (gui, "line_color_combo");
268 property_bar->priv->line_width_spin =
269 glade_xml_get_widget (gui, "line_width_spin");
271 /* Save reference to gui tree so we don't lose tooltips */
272 property_bar->priv->gui = gui;
274 set_doc_items_sensitive (property_bar, FALSE);
276 /* Font family entry widget */
277 gl_util_combo_box_add_text_model (GTK_COMBO_BOX (property_bar->priv->font_family_combo));
278 family_names = gl_util_get_font_family_list ();
279 gl_util_combo_box_set_strings (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
281 gtk_widget_set_size_request (property_bar->priv->font_family_combo, 200, -1);
283 /* Make sure we have a valid font. if not provide a good default. */
284 family_node = g_list_find_custom (family_names,
285 gl_prefs->default_font_family,
286 (GCompareFunc)g_utf8_collate);
289 gtk_combo_box_set_active (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
290 g_list_position (family_names,
295 gtk_combo_box_set_active (GTK_COMBO_BOX (property_bar->priv->font_family_combo), 0);
297 gl_util_font_family_list_free (family_names);
299 g_signal_connect (G_OBJECT (property_bar->priv->font_family_combo),
300 "changed", G_CALLBACK (font_family_changed_cb), property_bar);
302 /* Font size entry widget */
303 gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->priv->font_size_spin),
304 gl_prefs->default_font_size);
306 g_signal_connect (G_OBJECT (property_bar->priv->font_size_spin),
307 "changed", G_CALLBACK (font_size_changed_cb), property_bar);
310 /* Bold and Italic toggles */
311 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_bold_toggle),
312 (gl_prefs->default_font_weight == PANGO_WEIGHT_BOLD));
313 g_signal_connect (G_OBJECT (property_bar->priv->font_bold_toggle),
314 "toggled", G_CALLBACK (font_bold_toggled_cb), property_bar);
315 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_italic_toggle),
316 gl_prefs->default_font_italic_flag);
317 g_signal_connect (G_OBJECT (property_bar->priv->font_italic_toggle),
318 "toggled", G_CALLBACK (font_italic_toggled_cb), property_bar);
321 /* Text alignment radio group */
322 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio),
323 (gl_prefs->default_text_alignment == PANGO_ALIGN_LEFT));
324 g_signal_connect (G_OBJECT (property_bar->priv->text_align_left_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_center_radio),
327 (gl_prefs->default_text_alignment == PANGO_ALIGN_CENTER));
328 g_signal_connect (G_OBJECT (property_bar->priv->text_align_center_radio),
329 "toggled", G_CALLBACK (text_align_toggled_cb), property_bar);
330 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio),
331 (gl_prefs->default_text_alignment == PANGO_ALIGN_RIGHT));
332 g_signal_connect (G_OBJECT (property_bar->priv->text_align_right_radio),
333 "toggled", G_CALLBACK (text_align_toggled_cb), property_bar);
335 /* Text color widget */
336 gl_color_combo_set_color (GL_COLOR_COMBO (property_bar->priv->text_color_combo), gl_prefs->default_text_color);
337 g_signal_connect (G_OBJECT (property_bar->priv->text_color_combo),
339 G_CALLBACK (text_color_changed_cb), property_bar);
341 /* Fill color widget */
342 gl_color_combo_set_color (GL_COLOR_COMBO (property_bar->priv->fill_color_combo), gl_prefs->default_fill_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 gl_color_combo_set_color (GL_COLOR_COMBO (property_bar->priv->line_color_combo), gl_prefs->default_line_color);
349 g_signal_connect (G_OBJECT (property_bar->priv->line_color_combo),
351 G_CALLBACK (line_color_changed_cb), property_bar);
353 /* Line width entry widget */
354 g_signal_connect (G_OBJECT (property_bar->priv->line_width_spin),
356 G_CALLBACK (line_width_changed_cb), property_bar);
358 property_bar->priv->stop_signals = FALSE;
360 gl_debug (DEBUG_PROPERTY_BAR, "END");
363 /****************************************************************************/
364 /* Fill widgets with default values. */
365 /****************************************************************************/
367 reset_to_default_properties (glView *view,
368 glUIPropertyBar *property_bar)
371 gchar *good_font_family;
373 /* Make sure we have a valid font. if not provide a good default. */
374 family_names = gl_util_get_font_family_list ();
375 if (g_list_find_custom (family_names,
376 view->default_font_family,
377 (GCompareFunc)g_utf8_collate))
379 good_font_family = g_strdup (view->default_font_family);
383 if (family_names != NULL)
385 good_font_family = g_strdup (family_names->data); /* 1st entry */
389 good_font_family = NULL;
392 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
394 g_free (good_font_family);
395 gl_util_font_family_list_free (family_names);
397 gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->priv->font_size_spin),
398 view->default_font_size);
400 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_bold_toggle),
401 (view->default_font_weight == PANGO_WEIGHT_BOLD));
402 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_italic_toggle),
403 view->default_font_italic_flag);
405 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio),
406 (view->default_text_alignment == PANGO_ALIGN_LEFT));
407 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio),
408 (view->default_text_alignment == PANGO_ALIGN_CENTER));
409 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio),
410 (view->default_text_alignment == PANGO_ALIGN_RIGHT));
412 gl_color_combo_set_color (GL_COLOR_COMBO(property_bar->priv->text_color_combo), view->default_text_color);
414 gl_color_combo_set_color (GL_COLOR_COMBO(property_bar->priv->fill_color_combo), view->default_fill_color);
416 gl_color_combo_set_color (GL_COLOR_COMBO(property_bar->priv->line_color_combo), view->default_line_color);
418 gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->priv->line_width_spin),
419 view->default_line_width);
422 /****************************************************************************/
423 /* Set view associated with property_bar. */
424 /****************************************************************************/
426 gl_ui_property_bar_set_view (glUIPropertyBar *property_bar,
431 gl_debug (DEBUG_PROPERTY_BAR, "START");
433 g_return_if_fail (view && GL_IS_VIEW (view));
435 g_return_if_fail (label && GL_IS_LABEL (label));
437 set_doc_items_sensitive (property_bar, TRUE);
439 property_bar->priv->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
441 reset_to_default_properties (view, property_bar);
443 g_signal_connect_swapped (G_OBJECT(view), "selection_changed",
444 G_CALLBACK(selection_changed_cb), property_bar);
446 g_signal_connect_swapped (G_OBJECT(view->label), "changed",
447 G_CALLBACK(selection_changed_cb), property_bar);
449 gl_debug (DEBUG_PROPERTY_BAR, "END");
452 /****************************************************************************/
453 /** Set visiblity of property bar's tooltips. */
454 /****************************************************************************/
456 gl_ui_property_bar_set_tooltips (glUIPropertyBar *property_bar,
459 GtkTooltipsData *data;
461 gl_debug (DEBUG_PROPERTY_BAR, "START");
463 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR(property_bar));
465 /* HACK: peek into one of our widgets to get the tooltips group created by libglade. */
466 data = gtk_tooltips_data_get (property_bar->priv->font_size_spin);
467 g_return_if_fail (data);
471 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;
502 can_text = gl_view_can_selection_text (view);
503 set_text_items_sensitive (property_bar, can_text);
513 is_same_font_family = TRUE;
514 selection_font_family = NULL;
515 selection_font_size = -1;
516 selection_align = PANGO_ALIGN_LEFT;
517 selection_is_italic = TRUE;
518 selection_is_bold = TRUE;
519 selection_text_color = 0;
521 is_first_object = TRUE;
523 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)
533 if (selection_font_family == NULL)
535 selection_font_family = g_strdup (font_family);
539 if (strcmp (font_family, selection_font_family) != 0)
541 is_same_font_family = FALSE;
544 g_free (font_family);
547 font_size = gl_label_object_get_font_size (object);
549 text_color_node = gl_label_object_get_text_color (object);
550 if (text_color_node->field_flag)
552 /* If a merge field is set we use the default color for merged color*/
553 text_color = GL_COLOR_MERGE_DEFAULT;
558 text_color = text_color_node->color;
560 gl_color_node_free (&text_color_node);
562 is_italic = gl_label_object_get_font_italic_flag (object);
563 is_bold = gl_label_object_get_font_weight (object) == PANGO_WEIGHT_BOLD;
564 align = gl_label_object_get_text_alignment (object);
568 selection_font_size = font_size;
569 selection_text_color = text_color;
570 selection_is_italic = is_italic;
571 selection_is_bold = is_bold;
572 selection_align = align;
576 if (font_size != selection_font_size)
577 is_same_font_size = FALSE;
578 if (text_color != selection_text_color)
579 is_same_text_color = FALSE;
580 if (is_italic != selection_is_italic)
581 is_same_is_italic = FALSE;
582 if (is_bold != selection_is_bold)
583 is_same_is_bold = FALSE;
584 if (align != selection_align)
585 is_same_align = FALSE;
587 is_first_object = FALSE;
590 if (is_same_font_family && (selection_font_family != NULL))
591 gl_debug (DEBUG_PROPERTY_BAR, "same font family = %s",
592 selection_font_family);
593 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
594 is_same_font_family?selection_font_family:"");
595 g_free (selection_font_family);
597 if (is_same_font_size)
599 gl_debug (DEBUG_PROPERTY_BAR, "same font size = %g",
600 selection_font_size);
601 gtk_spin_button_set_value (GTK_SPIN_BUTTON (property_bar->priv->font_size_spin),
602 selection_font_size);
606 gtk_entry_set_text (GTK_ENTRY (property_bar->priv->font_size_spin), "");
609 if (is_same_text_color)
611 gl_debug (DEBUG_PROPERTY_BAR, "same text color = %08x", selection_text_color);
612 gl_color_combo_set_color (GL_COLOR_COMBO (property_bar->priv->text_color_combo),
613 selection_text_color);
616 if (is_same_is_italic)
618 gl_debug (DEBUG_PROPERTY_BAR, "same italic flag = %d",
619 selection_is_italic);
621 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_italic_toggle),
622 selection_is_italic && is_same_is_italic);
626 gl_debug (DEBUG_PROPERTY_BAR, "same bold flag = %d",
629 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_bold_toggle),
630 selection_is_bold && is_same_is_bold);
633 gl_debug (DEBUG_PROPERTY_BAR, "same align");
634 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio),
635 (selection_align == PANGO_ALIGN_LEFT) &&
637 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio),
638 (selection_align == PANGO_ALIGN_CENTER) &&
640 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio),
641 (selection_align == PANGO_ALIGN_RIGHT) &&
646 update_fill_color (glView *view,
647 glUIPropertyBar *property_bar)
649 gboolean can, is_first_object;
650 gboolean is_same_fill_color;
652 glLabelObject *object;
653 guint selection_fill_color, fill_color;
654 glColorNode *fill_color_node;
656 can = gl_view_can_selection_fill (view);
657 set_fill_items_sensitive (property_bar, can);
662 is_same_fill_color = TRUE;
663 is_first_object = TRUE;
664 selection_fill_color = 0;
666 for (p = view->selected_object_list; p != NULL; p = p->next)
669 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
670 if (!gl_label_object_can_fill (object))
673 fill_color_node = gl_label_object_get_fill_color (object);
674 if (fill_color_node->field_flag)
676 /* If a merge field is set we use the default color for merged color*/
677 fill_color = GL_COLOR_FILL_MERGE_DEFAULT;
682 fill_color = fill_color_node->color;
684 gl_color_node_free (&fill_color_node);
688 selection_fill_color = fill_color;
692 if (fill_color != selection_fill_color)
694 is_same_fill_color = FALSE;
697 is_first_object = FALSE;
700 if (is_same_fill_color)
702 gl_debug (DEBUG_PROPERTY_BAR, "same fill color = %08x", selection_fill_color);
703 gl_color_combo_set_color (GL_COLOR_COMBO (property_bar->priv->fill_color_combo),
704 selection_fill_color);
709 update_line_color (glView *view,
710 glUIPropertyBar *property_bar)
712 gboolean can, is_first_object;
713 gboolean is_same_line_color;
715 glLabelObject *object;
716 guint selection_line_color, line_color;
717 glColorNode *line_color_node;
719 can = gl_view_can_selection_line_color (view);
720 set_line_color_items_sensitive (property_bar, can);
725 is_same_line_color = TRUE;
726 is_first_object = TRUE;
727 selection_line_color = 0;
729 for (p = view->selected_object_list; p != NULL; p = p->next)
732 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
733 if (!gl_label_object_can_line_color (object))
736 line_color_node = gl_label_object_get_line_color (object);
737 if (line_color_node->field_flag)
739 /* If a merge field is set we use the default color for merged color*/
740 line_color = GL_COLOR_MERGE_DEFAULT;
745 line_color = line_color_node->color;
747 gl_color_node_free (&line_color_node);
751 selection_line_color = line_color;
755 if (line_color != selection_line_color)
757 is_same_line_color = FALSE;
760 is_first_object = FALSE;
763 if (is_same_line_color)
765 gl_debug (DEBUG_PROPERTY_BAR, "same line color = %08x", selection_line_color);
766 gl_color_combo_set_color (GL_COLOR_COMBO (property_bar->priv->line_color_combo),
767 selection_line_color);
772 update_line_width (glView *view,
773 glUIPropertyBar *property_bar)
775 gboolean can, is_first_object;
776 gboolean is_same_line_width;
778 glLabelObject *object;
779 gdouble selection_line_width, line_width;
781 can = gl_view_can_selection_line_width (view);
782 set_line_width_items_sensitive (property_bar, can);
787 is_same_line_width = TRUE;
788 is_first_object = TRUE;
789 selection_line_width = 0;
791 for (p = view->selected_object_list; p != NULL; p = p->next)
794 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
795 if (!gl_label_object_can_line_width (object))
798 line_width = gl_label_object_get_line_width (object);
802 selection_line_width = line_width;
806 if (line_width != selection_line_width)
808 is_same_line_width = FALSE;
811 is_first_object = FALSE;
814 if (is_same_line_width)
816 gl_debug (DEBUG_PROPERTY_BAR, "same line width = %g", selection_line_width);
817 gtk_spin_button_set_value (GTK_SPIN_BUTTON (property_bar->priv->line_width_spin),
818 selection_line_width);
822 gtk_entry_set_text (GTK_ENTRY (property_bar->priv->line_width_spin), "");
827 selection_changed_cb (glUIPropertyBar *property_bar)
829 glView *view = property_bar->priv->view;
831 g_return_if_fail (view && GL_IS_VIEW (view));
832 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
834 if (property_bar->priv->stop_signals) return;
835 property_bar->priv->stop_signals = TRUE;
837 gl_debug (DEBUG_PROPERTY_BAR, "START");
839 if (gl_view_is_selection_empty (view))
841 /* No selection: make all controls active. */
842 reset_to_default_properties (view, property_bar);
843 set_doc_items_sensitive (property_bar, TRUE);
847 update_text_properties (view, property_bar);
848 update_fill_color (view, property_bar);
849 update_line_color (view, property_bar);
850 update_line_width (view, property_bar);
853 gl_debug (DEBUG_PROPERTY_BAR, "END");
855 property_bar->priv->stop_signals = FALSE;
858 /*--------------------------------------------------------------------------*/
859 /* PRIVATE. Font family entry changed. */
860 /*--------------------------------------------------------------------------*/
862 font_family_changed_cb (GtkComboBox *combo,
863 glUIPropertyBar *property_bar)
867 if (property_bar->priv->stop_signals) return;
868 property_bar->priv->stop_signals = TRUE;
870 gl_debug (DEBUG_PROPERTY_BAR, "START");
872 font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
873 if ( strlen(font_family) )
875 gl_view_set_selection_font_family (property_bar->priv->view,
877 gl_view_set_default_font_family (property_bar->priv->view,
880 g_free (font_family);
882 gl_debug (DEBUG_PROPERTY_BAR, "END");
884 property_bar->priv->stop_signals = FALSE;
887 /*--------------------------------------------------------------------------*/
888 /* PRIVATE. Font size spin button changed. */
889 /*--------------------------------------------------------------------------*/
891 font_size_changed_cb (GtkSpinButton *spin,
892 glUIPropertyBar *property_bar)
896 if (property_bar->priv->stop_signals) return;
897 property_bar->priv->stop_signals = TRUE;
899 gl_debug (DEBUG_PROPERTY_BAR, "START");
901 font_size = gtk_spin_button_get_value (spin);
903 gl_view_set_selection_font_size (property_bar->priv->view,
905 gl_view_set_default_font_size (property_bar->priv->view,
908 gl_debug (DEBUG_PROPERTY_BAR, "END");
910 property_bar->priv->stop_signals = FALSE;
913 /*--------------------------------------------------------------------------*/
914 /* PRIVATE. Text color combo changed. */
915 /*--------------------------------------------------------------------------*/
917 text_color_changed_cb (glColorCombo *cc,
920 glUIPropertyBar *property_bar)
922 glColorNode *text_color_node;
924 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
926 if (property_bar->priv->stop_signals) return;
927 property_bar->priv->stop_signals = TRUE;
929 gl_debug (DEBUG_PROPERTY_BAR, "START");
931 text_color_node = gl_color_node_new_default ();
932 text_color_node->color = color;
934 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
939 text_color_node->color = gl_prefs->default_text_color;
940 gl_view_set_selection_text_color (property_bar->priv->view,
942 gl_view_set_default_text_color (property_bar->priv->view,
943 gl_prefs->default_text_color);
947 gl_view_set_selection_text_color (property_bar->priv->view,
949 gl_view_set_default_text_color (property_bar->priv->view,
950 text_color_node->color);
953 gl_color_node_free (&text_color_node);
955 gl_debug (DEBUG_PROPERTY_BAR, "END");
957 property_bar->priv->stop_signals = FALSE;
960 /*--------------------------------------------------------------------------*/
961 /* PRIVATE. Fill color combo changed. */
962 /*--------------------------------------------------------------------------*/
964 fill_color_changed_cb (glColorCombo *cc,
967 glUIPropertyBar *property_bar)
969 glColorNode *fill_color_node;
971 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
973 if (property_bar->priv->stop_signals) return;
974 property_bar->priv->stop_signals = TRUE;
976 gl_debug (DEBUG_PROPERTY_BAR, "START");
978 fill_color_node = gl_color_node_new_default ();
980 fill_color_node->color = color;
982 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
988 fill_color_node->color = GL_COLOR_NONE;
989 gl_view_set_selection_fill_color (property_bar->priv->view,
991 gl_view_set_default_fill_color (property_bar->priv->view,
992 fill_color_node->color);
996 gl_view_set_selection_fill_color (property_bar->priv->view,
998 gl_view_set_default_fill_color (property_bar->priv->view,
999 fill_color_node->color);
1001 gl_color_node_free (&fill_color_node);
1003 gl_debug (DEBUG_PROPERTY_BAR, "END");
1005 property_bar->priv->stop_signals = FALSE;
1008 /*--------------------------------------------------------------------------*/
1009 /* PRIVATE. Line color combo changed. */
1010 /*--------------------------------------------------------------------------*/
1012 line_color_changed_cb (glColorCombo *cc,
1014 gboolean is_default,
1015 glUIPropertyBar *property_bar)
1017 glColorNode *line_color_node;
1019 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
1021 if (property_bar->priv->stop_signals) return;
1022 property_bar->priv->stop_signals = TRUE;
1024 gl_debug (DEBUG_PROPERTY_BAR, "START");
1026 line_color_node = gl_color_node_new_default ();
1027 line_color_node->color = color;
1029 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
1034 line_color_node->color = GL_COLOR_NONE;
1035 gl_view_set_selection_line_color (property_bar->priv->view,
1037 gl_view_set_default_line_color (property_bar->priv->view,
1038 line_color_node->color);
1042 gl_view_set_selection_line_color (property_bar->priv->view,
1044 gl_view_set_default_line_color (property_bar->priv->view,
1045 line_color_node->color);
1047 gl_color_node_free (&line_color_node);
1049 gl_debug (DEBUG_PROPERTY_BAR, "END");
1051 property_bar->priv->stop_signals = FALSE;
1054 /*--------------------------------------------------------------------------*/
1055 /* PRIVATE. Line width spin button changed. */
1056 /*--------------------------------------------------------------------------*/
1058 line_width_changed_cb (GtkSpinButton *spin,
1059 glUIPropertyBar *property_bar)
1063 if (property_bar->priv->stop_signals) return;
1064 property_bar->priv->stop_signals = TRUE;
1066 gl_debug (DEBUG_PROPERTY_BAR, "START");
1068 if (property_bar->priv->view)
1070 line_width = gtk_spin_button_get_value (spin);
1072 gl_view_set_selection_line_width (property_bar->priv->view,
1074 gl_view_set_default_line_width (property_bar->priv->view,
1078 gl_debug (DEBUG_PROPERTY_BAR, "END");
1080 property_bar->priv->stop_signals = FALSE;
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) return;
1095 property_bar->priv->stop_signals = TRUE;
1097 gl_debug (DEBUG_PROPERTY_BAR, "START");
1099 state = gtk_toggle_tool_button_get_active (toggle);
1101 weight = state ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
1103 gl_view_set_selection_font_weight (property_bar->priv->view, weight);
1104 gl_view_set_default_font_weight (property_bar->priv->view, weight);
1106 gl_debug (DEBUG_PROPERTY_BAR, "END");
1108 property_bar->priv->stop_signals = FALSE;
1111 /*---------------------------------------------------------------------------*/
1112 /* PRIVATE. Font italic toggled callback. */
1113 /*---------------------------------------------------------------------------*/
1115 font_italic_toggled_cb (GtkToggleToolButton *toggle,
1116 glUIPropertyBar *property_bar)
1120 if (property_bar->priv->stop_signals) return;
1121 property_bar->priv->stop_signals = TRUE;
1123 gl_debug (DEBUG_PROPERTY_BAR, "START");
1125 state = gtk_toggle_tool_button_get_active (toggle);
1127 gl_view_set_selection_font_italic_flag (property_bar->priv->view, state);
1128 gl_view_set_default_font_italic_flag (property_bar->priv->view, state);
1130 gl_debug (DEBUG_PROPERTY_BAR, "END");
1132 property_bar->priv->stop_signals = FALSE;
1135 /*---------------------------------------------------------------------------*/
1136 /* PRIVATE. Text align toggled callback. */
1137 /*---------------------------------------------------------------------------*/
1139 text_align_toggled_cb (GtkToggleToolButton *toggle,
1140 glUIPropertyBar *property_bar)
1142 if (property_bar->priv->stop_signals) return;
1143 property_bar->priv->stop_signals = TRUE;
1145 gl_debug (DEBUG_PROPERTY_BAR, "START");
1147 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio)))
1149 gl_view_set_selection_text_alignment (property_bar->priv->view,
1151 gl_view_set_default_text_alignment (property_bar->priv->view,
1155 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio)))
1157 gl_view_set_selection_text_alignment (property_bar->priv->view,
1158 PANGO_ALIGN_CENTER);
1159 gl_view_set_default_text_alignment (property_bar->priv->view,
1160 PANGO_ALIGN_CENTER);
1163 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio)))
1165 gl_view_set_selection_text_alignment (property_bar->priv->view,
1167 gl_view_set_default_text_alignment (property_bar->priv->view,
1171 gl_debug (DEBUG_PROPERTY_BAR, "END");
1173 property_bar->priv->stop_signals = FALSE;
1177 /*****************************************************************************/
1178 /* Construct color combo "Custom widget". */
1179 /*****************************************************************************/
1181 gl_ui_property_bar_construct_color_combo (gchar *name,
1187 GtkWidget *color_combo;
1190 GdkPixbuf *pixbuf = NULL;
1195 color = gl_prefs->default_text_color;
1196 no_color = _("Default");
1197 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_text_24, FALSE, NULL);
1201 color = gl_prefs->default_line_color;
1202 no_color = _("No line");
1203 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_pencil_24, FALSE, NULL);
1208 color = gl_prefs->default_fill_color;
1209 no_color = _("No fill");
1210 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_bucket_fill_24, FALSE, NULL);
1215 color_combo = gl_color_combo_new (pixbuf, no_color, color, color);
1217 gl_color_combo_set_relief (GL_COLOR_COMBO(color_combo),
1220 g_object_unref (G_OBJECT (pixbuf));
1225 /*---------------------------------------------------------------------------*/
1226 /* PRIVATE. Set sensitivity of doc controls. */
1227 /*---------------------------------------------------------------------------*/
1229 set_doc_items_sensitive (glUIPropertyBar *property_bar,
1232 gtk_widget_set_sensitive (property_bar->priv->font_family_combo, state);
1233 gtk_widget_set_sensitive (property_bar->priv->font_size_spin, state);
1234 gtk_widget_set_sensitive (property_bar->priv->font_bold_toggle, state);
1235 gtk_widget_set_sensitive (property_bar->priv->font_italic_toggle, state);
1236 gtk_widget_set_sensitive (property_bar->priv->text_align_left_radio, state);
1237 gtk_widget_set_sensitive (property_bar->priv->text_align_center_radio, state);
1238 gtk_widget_set_sensitive (property_bar->priv->text_align_right_radio, state);
1239 gtk_widget_set_sensitive (property_bar->priv->text_color_combo, state);
1240 gtk_widget_set_sensitive (property_bar->priv->fill_color_combo, state);
1241 gtk_widget_set_sensitive (property_bar->priv->line_color_combo, state);
1242 gtk_widget_set_sensitive (property_bar->priv->line_width_spin, state);
1245 /*---------------------------------------------------------------------------*/
1246 /* PRIVATE. Set sensitivity of text related controls. */
1247 /*---------------------------------------------------------------------------*/
1249 set_text_items_sensitive (glUIPropertyBar *property_bar,
1252 gtk_widget_set_sensitive (property_bar->priv->font_family_combo, state);
1253 gtk_widget_set_sensitive (property_bar->priv->font_size_spin, state);
1254 gtk_widget_set_sensitive (property_bar->priv->font_bold_toggle, state);
1255 gtk_widget_set_sensitive (property_bar->priv->font_italic_toggle, state);
1256 gtk_widget_set_sensitive (property_bar->priv->text_align_left_radio, state);
1257 gtk_widget_set_sensitive (property_bar->priv->text_align_center_radio, state);
1258 gtk_widget_set_sensitive (property_bar->priv->text_align_right_radio, state);
1259 gtk_widget_set_sensitive (property_bar->priv->text_color_combo, state);
1262 /*---------------------------------------------------------------------------*/
1263 /* PRIVATE. Set sensitivity of fill related controls. */
1264 /*---------------------------------------------------------------------------*/
1266 set_fill_items_sensitive (glUIPropertyBar *property_bar,
1269 gtk_widget_set_sensitive (property_bar->priv->fill_color_combo, state);
1272 /*---------------------------------------------------------------------------*/
1273 /* PRIVATE. Set sensitivity of line color related controls. */
1274 /*---------------------------------------------------------------------------*/
1276 set_line_color_items_sensitive (glUIPropertyBar *property_bar,
1279 gtk_widget_set_sensitive (property_bar->priv->line_color_combo, state);
1282 /*---------------------------------------------------------------------------*/
1283 /* PRIVATE. Set sensitivity of line width related controls. */
1284 /*---------------------------------------------------------------------------*/
1286 set_line_width_items_sensitive (glUIPropertyBar *property_bar,
1289 gtk_widget_set_sensitive (property_bar->priv->line_width_spin, state);