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 {
61 GtkWidget *font_family_combo;
62 GtkWidget *font_size_spin;
63 GtkWidget *font_bold_toggle;
64 GtkWidget *font_italic_toggle;
66 /* Text alignemnt radios */
67 GtkWidget *text_align_left_radio;
68 GtkWidget *text_align_center_radio;
69 GtkWidget *text_align_right_radio;
72 GtkWidget *text_color_combo;
73 GtkWidget *fill_color_combo;
74 GtkWidget *line_color_combo;
77 GtkWidget *line_width_spin;
79 gboolean stop_signals;
84 /*===========================================================================*/
86 /*===========================================================================*/
88 /*===========================================================================*/
89 /* Local function prototypes */
90 /*===========================================================================*/
92 static void gl_ui_property_bar_finalize (GObject *object);
94 static void gl_ui_property_bar_construct (glUIPropertyBar *property_bar);
96 static void selection_changed_cb (glUIPropertyBar *property_bar);
98 static void font_family_changed_cb (GtkComboBox *combo,
99 glUIPropertyBar *property_bar);
101 static void font_size_changed_cb (GtkSpinButton *spin,
102 glUIPropertyBar *property_bar);
104 static void text_color_changed_cb (ColorCombo *cc,
109 glUIPropertyBar *property_bar);
111 static void fill_color_changed_cb (ColorCombo *cc,
116 glUIPropertyBar *property_bar);
118 static void line_color_changed_cb (ColorCombo *cc,
123 glUIPropertyBar *property_bar);
125 static void line_width_changed_cb (GtkSpinButton *spin,
126 glUIPropertyBar *property_bar);
128 static void font_bold_toggled_cb (GtkToggleToolButton *toggle,
129 glUIPropertyBar *property_bar);
131 static void font_italic_toggled_cb (GtkToggleToolButton *toggle,
132 glUIPropertyBar *property_bar);
134 static void text_align_toggled_cb (GtkToggleToolButton *toggle,
135 glUIPropertyBar *property_bar);
137 static void set_doc_items_sensitive (glUIPropertyBar *property_bar,
140 static void set_text_items_sensitive (glUIPropertyBar *property_bar,
143 static void set_fill_items_sensitive (glUIPropertyBar *property_bar,
146 static void set_line_color_items_sensitive (glUIPropertyBar *property_bar,
149 static void set_line_width_items_sensitive (glUIPropertyBar *property_bar,
153 /****************************************************************************/
154 /* Boilerplate Object stuff. */
155 /****************************************************************************/
156 G_DEFINE_TYPE (glUIPropertyBar, gl_ui_property_bar, GTK_TYPE_HBOX);
159 gl_ui_property_bar_class_init (glUIPropertyBarClass *class)
161 GObjectClass *object_class = G_OBJECT_CLASS (class);
163 gl_debug (DEBUG_PROPERTY_BAR, "START");
165 gl_ui_property_bar_parent_class = g_type_class_peek_parent (class);
167 object_class->finalize = gl_ui_property_bar_finalize;
169 gl_debug (DEBUG_PROPERTY_BAR, "END");
173 gl_ui_property_bar_init (glUIPropertyBar *property_bar)
175 gl_debug (DEBUG_PROPERTY_BAR, "START");
177 property_bar->priv = g_new0 (glUIPropertyBarPrivate, 1);
179 gl_debug (DEBUG_PROPERTY_BAR, "END");
183 gl_ui_property_bar_finalize (GObject *object)
185 glUIPropertyBar *property_bar = GL_UI_PROPERTY_BAR (object);
187 gl_debug (DEBUG_PROPERTY_BAR, "START");
189 g_return_if_fail (object != NULL);
190 g_return_if_fail (GL_IS_UI_PROPERTY_BAR (object));
192 if (property_bar->priv->view) {
193 g_object_unref (G_OBJECT(property_bar->priv->view));
195 g_free (property_bar->priv);
197 G_OBJECT_CLASS (gl_ui_property_bar_parent_class)->finalize (object);
199 gl_debug (DEBUG_PROPERTY_BAR, "END");
202 /****************************************************************************/
203 /* Create a NEW property_bar. */
204 /****************************************************************************/
206 gl_ui_property_bar_new (void)
208 glUIPropertyBar *property_bar;
210 gl_debug (DEBUG_PROPERTY_BAR, "START");
212 property_bar = g_object_new (GL_TYPE_UI_PROPERTY_BAR, NULL);
214 gl_ui_property_bar_construct (property_bar);
216 gl_debug (DEBUG_PROPERTY_BAR, "END");
218 return GTK_WIDGET (property_bar);
221 /******************************************************************************/
222 /* Initialize property toolbar. */
223 /******************************************************************************/
225 gl_ui_property_bar_construct (glUIPropertyBar *property_bar)
228 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);
240 g_critical ("Could not open property-bar.glade. gLabels may not be installed correctly!");
244 property_bar->priv->tool_bar = glade_xml_get_widget (gui, "property_toolbar");
245 gtk_container_add (GTK_CONTAINER (property_bar), property_bar->priv->tool_bar);
247 property_bar->priv->font_family_combo =
248 glade_xml_get_widget (gui, "font_family_combo");
249 property_bar->priv->font_size_spin =
250 glade_xml_get_widget (gui, "font_size_spin");
251 property_bar->priv->font_bold_toggle =
252 glade_xml_get_widget (gui, "font_bold_toggle");
253 property_bar->priv->font_italic_toggle =
254 glade_xml_get_widget (gui, "font_italic_toggle");
255 property_bar->priv->text_align_left_radio =
256 glade_xml_get_widget (gui, "text_align_left_radio");
257 property_bar->priv->text_align_center_radio =
258 glade_xml_get_widget (gui, "text_align_center_radio");
259 property_bar->priv->text_align_right_radio =
260 glade_xml_get_widget (gui, "text_align_right_radio");
261 property_bar->priv->text_color_combo =
262 glade_xml_get_widget (gui, "text_color_combo");
263 property_bar->priv->fill_color_combo =
264 glade_xml_get_widget (gui, "fill_color_combo");
265 property_bar->priv->line_color_combo =
266 glade_xml_get_widget (gui, "line_color_combo");
267 property_bar->priv->line_width_spin =
268 glade_xml_get_widget (gui, "line_width_spin");
270 g_object_unref (gui);
272 set_doc_items_sensitive (property_bar, FALSE);
274 /* Font family entry widget */
275 gl_util_combo_box_add_text_model (GTK_COMBO_BOX (property_bar->priv->font_family_combo));
276 family_names = gl_util_get_font_family_list ();
277 gl_util_combo_box_set_strings (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
279 gtk_widget_set_size_request (property_bar->priv->font_family_combo, 200, -1);
281 /* Make sure we have a valid font. if not provide a good default. */
282 family_node = g_list_find_custom (family_names,
283 gl_prefs->default_font_family,
284 (GCompareFunc)g_utf8_collate);
286 gtk_combo_box_set_active (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
287 g_list_position (family_names,
290 gtk_combo_box_set_active (GTK_COMBO_BOX (property_bar->priv->font_family_combo), 0);
292 gl_util_font_family_list_free (family_names);
294 g_signal_connect (G_OBJECT (property_bar->priv->font_family_combo),
295 "changed", G_CALLBACK (font_family_changed_cb), property_bar);
297 /* Font size entry widget */
298 gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->priv->font_size_spin),
299 gl_prefs->default_font_size);
301 g_signal_connect (G_OBJECT (property_bar->priv->font_size_spin),
302 "changed", G_CALLBACK (font_size_changed_cb), property_bar);
305 /* Bold and Italic toggles */
306 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_bold_toggle),
307 (gl_prefs->default_font_weight == PANGO_WEIGHT_BOLD));
308 g_signal_connect (G_OBJECT (property_bar->priv->font_bold_toggle),
309 "toggled", G_CALLBACK (font_bold_toggled_cb), property_bar);
310 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_italic_toggle),
311 gl_prefs->default_font_italic_flag);
312 g_signal_connect (G_OBJECT (property_bar->priv->font_italic_toggle),
313 "toggled", G_CALLBACK (font_italic_toggled_cb), property_bar);
316 /* Text alignment radio group */
317 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio),
318 (gl_prefs->default_text_alignment == PANGO_ALIGN_LEFT));
319 g_signal_connect (G_OBJECT (property_bar->priv->text_align_left_radio),
320 "toggled", G_CALLBACK (text_align_toggled_cb), property_bar);
321 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio),
322 (gl_prefs->default_text_alignment == PANGO_ALIGN_CENTER));
323 g_signal_connect (G_OBJECT (property_bar->priv->text_align_center_radio),
324 "toggled", G_CALLBACK (text_align_toggled_cb), property_bar);
325 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio),
326 (gl_prefs->default_text_alignment == PANGO_ALIGN_RIGHT));
327 g_signal_connect (G_OBJECT (property_bar->priv->text_align_right_radio),
328 "toggled", G_CALLBACK (text_align_toggled_cb), property_bar);
330 /* Text color widget */
331 gdk_color = gl_color_to_gdk_color (gl_prefs->default_text_color);
332 color_combo_set_color (COLOR_COMBO (property_bar->priv->text_color_combo), gdk_color);
334 g_signal_connect (G_OBJECT (property_bar->priv->text_color_combo),
336 G_CALLBACK (text_color_changed_cb), property_bar);
338 /* Fill color widget */
339 gdk_color = gl_color_to_gdk_color (gl_prefs->default_fill_color);
340 color_combo_set_color (COLOR_COMBO (property_bar->priv->fill_color_combo), gdk_color);
342 g_signal_connect (G_OBJECT (property_bar->priv->fill_color_combo),
344 G_CALLBACK (fill_color_changed_cb), property_bar);
346 /* Line color widget */
347 gdk_color = gl_color_to_gdk_color (gl_prefs->default_line_color);
348 color_combo_set_color (COLOR_COMBO (property_bar->priv->line_color_combo), gdk_color);
350 g_signal_connect (G_OBJECT (property_bar->priv->line_color_combo),
352 G_CALLBACK (line_color_changed_cb), property_bar);
354 /* Line width entry widget */
355 g_signal_connect (G_OBJECT (property_bar->priv->line_width_spin),
357 G_CALLBACK (line_width_changed_cb), property_bar);
359 property_bar->priv->stop_signals = FALSE;
361 gl_debug (DEBUG_PROPERTY_BAR, "END");
364 /****************************************************************************/
365 /* Fill widgets with default values. */
366 /****************************************************************************/
368 reset_to_default_properties (glView *view,
369 glUIPropertyBar *property_bar)
372 gchar *good_font_family;
375 /* Make sure we have a valid font. if not provide a good default. */
376 family_names = gl_util_get_font_family_list ();
377 if (g_list_find_custom (family_names,
378 view->default_font_family,
379 (GCompareFunc)g_utf8_collate)) {
380 good_font_family = g_strdup (view->default_font_family);
382 if (family_names != NULL) {
383 good_font_family = g_strdup (family_names->data); /* 1st entry */
385 good_font_family = NULL;
388 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
390 g_free (good_font_family);
391 gl_util_font_family_list_free (family_names);
393 gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->priv->font_size_spin),
394 view->default_font_size);
396 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_bold_toggle),
397 (view->default_font_weight == PANGO_WEIGHT_BOLD));
398 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_italic_toggle),
399 view->default_font_italic_flag);
401 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio),
402 (view->default_text_alignment == PANGO_ALIGN_LEFT));
403 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio),
404 (view->default_text_alignment == PANGO_ALIGN_CENTER));
405 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio),
406 (view->default_text_alignment == PANGO_ALIGN_RIGHT));
408 gdk_color = gl_color_to_gdk_color (view->default_text_color);
409 color_combo_set_color (COLOR_COMBO(property_bar->priv->text_color_combo), gdk_color);
412 gdk_color = gl_color_to_gdk_color (view->default_fill_color);
413 color_combo_set_color (COLOR_COMBO(property_bar->priv->fill_color_combo), gdk_color);
416 gdk_color = gl_color_to_gdk_color (view->default_line_color);
417 color_combo_set_color (COLOR_COMBO(property_bar->priv->line_color_combo), gdk_color);
420 gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->priv->line_width_spin),
421 view->default_line_width);
424 /****************************************************************************/
425 /* Set view associated with property_bar. */
426 /****************************************************************************/
428 gl_ui_property_bar_set_view (glUIPropertyBar *property_bar,
433 gl_debug (DEBUG_PROPERTY_BAR, "START");
435 g_return_if_fail (view && GL_IS_VIEW (view));
437 g_return_if_fail (label && GL_IS_LABEL (label));
439 set_doc_items_sensitive (property_bar, TRUE);
441 property_bar->priv->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
443 reset_to_default_properties (view, property_bar);
445 g_signal_connect_swapped (G_OBJECT(view), "selection_changed",
446 G_CALLBACK(selection_changed_cb), property_bar);
448 g_signal_connect_swapped (G_OBJECT(view->label), "changed",
449 G_CALLBACK(selection_changed_cb), property_bar);
451 gl_debug (DEBUG_PROPERTY_BAR, "END");
454 /****************************************************************************/
455 /** Set visiblity of property bar's tooltips. */
456 /****************************************************************************/
458 gl_ui_property_bar_set_tooltips (glUIPropertyBar *property_bar,
461 GtkTooltipsData *data;
463 gl_debug (DEBUG_PROPERTY_BAR, "START");
465 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR(property_bar));
467 /* HACK: peek into one of our widgets to get the tooltips group created by libglade. */
468 data = gtk_tooltips_data_get (property_bar->priv->font_size_spin);
469 g_return_if_fail (data);
472 gtk_tooltips_enable (data->tooltips);
474 gtk_tooltips_disable (data->tooltips);
477 gl_debug (DEBUG_PROPERTY_BAR, "END");
480 /*---------------------------------------------------------------------------*/
481 /* PRIVATE. View "selection state changed" callback. */
482 /*---------------------------------------------------------------------------*/
484 update_text_properties (glView *view,
485 glUIPropertyBar *property_bar)
487 gboolean can_text, is_first_object;
488 gboolean is_same_font_family, is_same_font_size;
489 gboolean is_same_text_color, is_same_is_italic;
490 gboolean is_same_is_bold, is_same_align;
492 glLabelObject *object;
493 gchar *selection_font_family, *font_family;
494 gdouble selection_font_size, font_size;
495 guint selection_text_color, text_color;
496 glColorNode *text_color_node;
497 gboolean selection_is_italic, is_italic;
498 gboolean selection_is_bold, is_bold;
499 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) {
525 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
526 if (!gl_label_object_can_text (object))
529 font_family = gl_label_object_get_font_family (object);
530 if (font_family != NULL) {
531 if (selection_font_family == NULL)
532 selection_font_family = g_strdup (font_family);
534 if (strcmp (font_family, selection_font_family) != 0)
535 is_same_font_family = FALSE;
536 g_free (font_family);
539 font_size = gl_label_object_get_font_size (object);
541 text_color_node = gl_label_object_get_text_color (object);
542 if (text_color_node->field_flag) {
543 /* If a merge field is set we use the default color for merged color*/
544 text_color = GL_COLOR_MERGE_DEFAULT;
547 text_color = text_color_node->color;
549 gl_color_node_free (&text_color_node);
551 is_italic = gl_label_object_get_font_italic_flag (object);
552 is_bold = gl_label_object_get_font_weight (object) == PANGO_WEIGHT_BOLD;
553 align = gl_label_object_get_text_alignment (object);
555 if (is_first_object) {
556 selection_font_size = font_size;
557 selection_text_color = text_color;
558 selection_is_italic = is_italic;
559 selection_is_bold = is_bold;
560 selection_align = align;
562 if (font_size != selection_font_size)
563 is_same_font_size = FALSE;
564 if (text_color != selection_text_color)
565 is_same_text_color = FALSE;
566 if (is_italic != selection_is_italic)
567 is_same_is_italic = FALSE;
568 if (is_bold != selection_is_bold)
569 is_same_is_bold = FALSE;
570 if (align != selection_align)
571 is_same_align = FALSE;
573 is_first_object = FALSE;
576 if (is_same_font_family && (selection_font_family != NULL))
577 gl_debug (DEBUG_PROPERTY_BAR, "same font family = %s",
578 selection_font_family);
579 gl_util_combo_box_set_active_text (GTK_COMBO_BOX (property_bar->priv->font_family_combo),
580 is_same_font_family?selection_font_family:"");
581 g_free (selection_font_family);
583 if (is_same_font_size) {
584 gl_debug (DEBUG_PROPERTY_BAR, "same font size = %g",
585 selection_font_size);
586 gtk_spin_button_set_value (GTK_SPIN_BUTTON (property_bar->priv->font_size_spin),
587 selection_font_size);
589 gtk_entry_set_text (GTK_ENTRY (property_bar->priv->font_size_spin), "");
592 if (is_same_text_color) {
593 gl_debug (DEBUG_PROPERTY_BAR, "same text color = %08x", selection_text_color);
594 gdk_color = gl_color_to_gdk_color (selection_text_color);
595 color_combo_set_color (COLOR_COMBO (property_bar->priv->text_color_combo),
600 if (is_same_is_italic)
601 gl_debug (DEBUG_PROPERTY_BAR, "same italic flag = %d",
602 selection_is_italic);
603 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_italic_toggle),
604 selection_is_italic && is_same_is_italic);
607 gl_debug (DEBUG_PROPERTY_BAR, "same bold flag = %d",
609 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->font_bold_toggle),
610 selection_is_bold && is_same_is_bold);
613 gl_debug (DEBUG_PROPERTY_BAR, "same align");
614 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio),
615 (selection_align == PANGO_ALIGN_LEFT) &&
617 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio),
618 (selection_align == PANGO_ALIGN_CENTER) &&
620 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio),
621 (selection_align == PANGO_ALIGN_RIGHT) &&
626 update_fill_color (glView *view,
627 glUIPropertyBar *property_bar)
629 gboolean can, is_first_object;
630 gboolean is_same_fill_color;
632 glLabelObject *object;
633 guint selection_fill_color, fill_color;
635 glColorNode *fill_color_node;
637 can = gl_view_can_selection_fill (view);
638 set_fill_items_sensitive (property_bar, can);
643 is_same_fill_color = TRUE;
644 is_first_object = TRUE;
645 selection_fill_color = 0;
647 for (p = view->selected_object_list; p != NULL; p = p->next) {
649 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
650 if (!gl_label_object_can_fill (object))
653 fill_color_node = gl_label_object_get_fill_color (object);
654 if (fill_color_node->field_flag) {
655 /* If a merge field is set we use the default color for merged color*/
656 fill_color = GL_COLOR_FILL_MERGE_DEFAULT;
659 fill_color = fill_color_node->color;
661 gl_color_node_free (&fill_color_node);
663 if (is_first_object) {
664 selection_fill_color = fill_color;
666 if (fill_color != selection_fill_color)
667 is_same_fill_color = FALSE;
669 is_first_object = FALSE;
672 if (is_same_fill_color) {
673 gl_debug (DEBUG_PROPERTY_BAR, "same fill color = %08x", selection_fill_color);
674 gdk_color = gl_color_to_gdk_color (selection_fill_color);
675 color_combo_set_color (COLOR_COMBO (property_bar->priv->fill_color_combo),
682 update_line_color (glView *view,
683 glUIPropertyBar *property_bar)
685 gboolean can, is_first_object;
686 gboolean is_same_line_color;
688 glLabelObject *object;
689 guint selection_line_color, line_color;
690 glColorNode *line_color_node;
693 can = gl_view_can_selection_line_color (view);
694 set_line_color_items_sensitive (property_bar, can);
699 is_same_line_color = TRUE;
700 is_first_object = TRUE;
701 selection_line_color = 0;
703 for (p = view->selected_object_list; p != NULL; p = p->next) {
705 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
706 if (!gl_label_object_can_line_color (object))
709 line_color_node = gl_label_object_get_line_color (object);
710 if (line_color_node->field_flag) {
711 /* If a merge field is set we use the default color for merged color*/
712 line_color = GL_COLOR_MERGE_DEFAULT;
715 line_color = line_color_node->color;
717 gl_color_node_free (&line_color_node);
719 if (is_first_object) {
720 selection_line_color = line_color;
722 if (line_color != selection_line_color)
723 is_same_line_color = FALSE;
725 is_first_object = FALSE;
728 if (is_same_line_color) {
729 gl_debug (DEBUG_PROPERTY_BAR, "same line color = %08x", selection_line_color);
730 gdk_color = gl_color_to_gdk_color (selection_line_color);
731 color_combo_set_color (COLOR_COMBO (property_bar->priv->line_color_combo),
738 update_line_width (glView *view,
739 glUIPropertyBar *property_bar)
741 gboolean can, is_first_object;
742 gboolean is_same_line_width;
744 glLabelObject *object;
745 gdouble selection_line_width, line_width;
747 can = gl_view_can_selection_line_width (view);
748 set_line_width_items_sensitive (property_bar, can);
753 is_same_line_width = TRUE;
754 is_first_object = TRUE;
755 selection_line_width = 0;
757 for (p = view->selected_object_list; p != NULL; p = p->next) {
759 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
760 if (!gl_label_object_can_line_width (object))
763 line_width = gl_label_object_get_line_width (object);
765 if (is_first_object) {
766 selection_line_width = line_width;
768 if (line_width != selection_line_width)
769 is_same_line_width = FALSE;
771 is_first_object = FALSE;
774 if (is_same_line_width) {
775 gl_debug (DEBUG_PROPERTY_BAR, "same line width = %g", selection_line_width);
776 gtk_spin_button_set_value (GTK_SPIN_BUTTON (property_bar->priv->line_width_spin),
777 selection_line_width);
779 gtk_entry_set_text (GTK_ENTRY (property_bar->priv->line_width_spin), "");
784 selection_changed_cb (glUIPropertyBar *property_bar)
786 glView *view = property_bar->priv->view;
788 gl_debug (DEBUG_PROPERTY_BAR, "START");
790 g_return_if_fail (view && GL_IS_VIEW (view));
791 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
793 property_bar->priv->stop_signals = TRUE;
795 if (gl_view_is_selection_empty (view)) {
797 /* No selection: make all controls active. */
798 reset_to_default_properties (view, property_bar);
799 set_doc_items_sensitive (property_bar, TRUE);
803 update_text_properties (view, property_bar);
804 update_fill_color (view, property_bar);
805 update_line_color (view, property_bar);
806 update_line_width (view, property_bar);
810 property_bar->priv->stop_signals = FALSE;
812 gl_debug (DEBUG_PROPERTY_BAR, "END");
815 /*--------------------------------------------------------------------------*/
816 /* PRIVATE. Font family entry changed. */
817 /*--------------------------------------------------------------------------*/
819 font_family_changed_cb (GtkComboBox *combo,
820 glUIPropertyBar *property_bar)
824 if (property_bar->priv->stop_signals)
827 gl_debug (DEBUG_PROPERTY_BAR, "START");
829 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
830 selection_changed_cb,
833 font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
834 if ( strlen(font_family) ) {
835 gl_view_set_selection_font_family (property_bar->priv->view,
837 gl_view_set_default_font_family (property_bar->priv->view,
840 g_free (font_family);
842 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
843 selection_changed_cb,
846 gl_debug (DEBUG_PROPERTY_BAR, "END");
849 /*--------------------------------------------------------------------------*/
850 /* PRIVATE. Font size spin button changed. */
851 /*--------------------------------------------------------------------------*/
853 font_size_changed_cb (GtkSpinButton *spin,
854 glUIPropertyBar *property_bar)
858 if (property_bar->priv->stop_signals)
861 gl_debug (DEBUG_PROPERTY_BAR, "START");
863 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
864 selection_changed_cb,
867 font_size = gtk_spin_button_get_value (spin);
869 gl_view_set_selection_font_size (property_bar->priv->view,
871 gl_view_set_default_font_size (property_bar->priv->view,
874 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
875 selection_changed_cb,
878 gl_debug (DEBUG_PROPERTY_BAR, "END");
881 /*--------------------------------------------------------------------------*/
882 /* PRIVATE. Text color combo changed. */
883 /*--------------------------------------------------------------------------*/
885 text_color_changed_cb (ColorCombo *cc,
890 glUIPropertyBar *property_bar)
892 glColorNode *text_color_node;
894 if (property_bar->priv->stop_signals)
897 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
899 gl_debug (DEBUG_PROPERTY_BAR, "START");
901 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
902 selection_changed_cb,
905 text_color_node = gl_color_node_new_default ();
906 text_color_node->color = gl_color_from_gdk_color (gdk_color);
908 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d",
909 text_color_node->color, custom, by_user, is_default);
912 text_color_node->color = 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 gl_prefs->default_text_color);
920 gl_view_set_selection_text_color (property_bar->priv->view,
922 gl_view_set_default_text_color (property_bar->priv->view,
923 text_color_node->color);
927 gl_color_node_free (&text_color_node);
929 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
930 selection_changed_cb,
933 gl_debug (DEBUG_PROPERTY_BAR, "END");
936 /*--------------------------------------------------------------------------*/
937 /* PRIVATE. Fill color combo changed. */
938 /*--------------------------------------------------------------------------*/
940 fill_color_changed_cb (ColorCombo *cc,
945 glUIPropertyBar *property_bar)
947 glColorNode *fill_color_node;
949 if (property_bar->priv->stop_signals)
952 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
954 gl_debug (DEBUG_PROPERTY_BAR, "START");
956 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
957 selection_changed_cb,
960 fill_color_node = gl_color_node_new_default ();
962 fill_color_node->color = gl_color_from_gdk_color (gdk_color);
964 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d",
965 fill_color_node->color, custom, by_user, is_default);
969 fill_color_node->color = GL_COLOR_NONE;
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);
977 gl_view_set_selection_fill_color (property_bar->priv->view,
979 gl_view_set_default_fill_color (property_bar->priv->view,
980 fill_color_node->color);
983 gl_color_node_free (&fill_color_node);
985 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
986 selection_changed_cb,
989 gl_debug (DEBUG_PROPERTY_BAR, "END");
992 /*--------------------------------------------------------------------------*/
993 /* PRIVATE. Line color combo changed. */
994 /*--------------------------------------------------------------------------*/
996 line_color_changed_cb (ColorCombo *cc,
1000 gboolean is_default,
1001 glUIPropertyBar *property_bar)
1003 glColorNode *line_color_node;
1005 if (property_bar->priv->stop_signals)
1008 g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar));
1010 gl_debug (DEBUG_PROPERTY_BAR, "START");
1012 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1013 selection_changed_cb,
1016 line_color_node = gl_color_node_new_default ();
1017 line_color_node->color = gl_color_from_gdk_color (gdk_color);
1019 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d",
1020 line_color_node->color, custom, by_user, is_default);
1023 line_color_node->color = GL_COLOR_NONE;
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);
1031 gl_view_set_selection_line_color (property_bar->priv->view,
1033 gl_view_set_default_line_color (property_bar->priv->view,
1034 line_color_node->color);
1037 gl_color_node_free (&line_color_node);
1039 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1040 selection_changed_cb,
1043 gl_debug (DEBUG_PROPERTY_BAR, "END");
1046 /*--------------------------------------------------------------------------*/
1047 /* PRIVATE. Line width spin button changed. */
1048 /*--------------------------------------------------------------------------*/
1050 line_width_changed_cb (GtkSpinButton *spin,
1051 glUIPropertyBar *property_bar)
1055 if (property_bar->priv->stop_signals)
1058 gl_debug (DEBUG_PROPERTY_BAR, "START");
1060 if (property_bar->priv->view) {
1062 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1063 selection_changed_cb,
1066 line_width = gtk_spin_button_get_value (spin);
1068 gl_view_set_selection_line_width (property_bar->priv->view,
1070 gl_view_set_default_line_width (property_bar->priv->view,
1073 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1074 selection_changed_cb,
1079 gl_debug (DEBUG_PROPERTY_BAR, "END");
1082 /*---------------------------------------------------------------------------*/
1083 /* PRIVATE. Font bold toggled callback. */
1084 /*---------------------------------------------------------------------------*/
1086 font_bold_toggled_cb (GtkToggleToolButton *toggle,
1087 glUIPropertyBar *property_bar)
1093 if (property_bar->priv->stop_signals)
1096 gl_debug (DEBUG_PROPERTY_BAR, "START");
1098 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1099 selection_changed_cb,
1102 state = gtk_toggle_tool_button_get_active (toggle);
1104 weight = state ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
1106 gl_view_set_selection_font_weight (property_bar->priv->view, weight);
1107 gl_view_set_default_font_weight (property_bar->priv->view, weight);
1109 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1110 selection_changed_cb,
1113 gl_debug (DEBUG_PROPERTY_BAR, "END");
1116 /*---------------------------------------------------------------------------*/
1117 /* PRIVATE. Font italic toggled callback. */
1118 /*---------------------------------------------------------------------------*/
1120 font_italic_toggled_cb (GtkToggleToolButton *toggle,
1121 glUIPropertyBar *property_bar)
1125 if (property_bar->priv->stop_signals)
1128 gl_debug (DEBUG_PROPERTY_BAR, "START");
1130 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1131 selection_changed_cb,
1134 state = gtk_toggle_tool_button_get_active (toggle);
1136 gl_view_set_selection_font_italic_flag (property_bar->priv->view, state);
1137 gl_view_set_default_font_italic_flag (property_bar->priv->view, state);
1139 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1140 selection_changed_cb,
1143 gl_debug (DEBUG_PROPERTY_BAR, "END");
1146 /*---------------------------------------------------------------------------*/
1147 /* PRIVATE. Text align toggled callback. */
1148 /*---------------------------------------------------------------------------*/
1150 text_align_toggled_cb (GtkToggleToolButton *toggle,
1151 glUIPropertyBar *property_bar)
1153 if (property_bar->priv->stop_signals)
1156 gl_debug (DEBUG_PROPERTY_BAR, "START");
1158 g_signal_handlers_block_by_func (G_OBJECT(property_bar->priv->view->label),
1159 selection_changed_cb,
1162 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_left_radio)))
1164 gl_view_set_selection_text_alignment (property_bar->priv->view,
1166 gl_view_set_default_text_alignment (property_bar->priv->view,
1170 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_center_radio)))
1172 gl_view_set_selection_text_alignment (property_bar->priv->view,
1173 PANGO_ALIGN_CENTER);
1174 gl_view_set_default_text_alignment (property_bar->priv->view,
1175 PANGO_ALIGN_CENTER);
1178 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio)))
1180 gl_view_set_selection_text_alignment (property_bar->priv->view,
1182 gl_view_set_default_text_alignment (property_bar->priv->view,
1186 g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->priv->view->label),
1187 selection_changed_cb,
1190 gl_debug (DEBUG_PROPERTY_BAR, "END");
1194 /*****************************************************************************/
1195 /* Construct color combo "Custom widget". */
1196 /*****************************************************************************/
1198 gl_ui_property_bar_construct_color_combo (gchar *name,
1204 GtkWidget *color_combo;
1208 GdkColor *gdk_color;
1210 GdkPixbuf *pixbuf = NULL;
1215 cg_name = "text_color_group";
1216 color = gl_prefs->default_text_color;
1217 no_color = _("Default");
1218 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_text_24, FALSE, NULL);
1222 cg_name = "line_color_group";
1223 color = gl_prefs->default_line_color;
1224 no_color = _("No line");
1225 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_pencil_24, FALSE, NULL);
1230 cg_name = "fill_color_group";
1231 color = gl_prefs->default_fill_color;
1232 no_color = _("No fill");
1233 pixbuf = gdk_pixbuf_new_from_inline (-1, stock_bucket_fill_24, FALSE, NULL);
1238 cg = color_group_fetch (cg_name, NULL);
1239 gdk_color = gl_color_to_gdk_color (color);
1240 color_combo = color_combo_new (pixbuf, no_color, gdk_color, cg);
1243 color_combo_box_set_preview_relief (COLOR_COMBO(color_combo), GTK_RELIEF_NORMAL);
1245 g_object_unref (G_OBJECT (pixbuf));
1250 /*---------------------------------------------------------------------------*/
1251 /* PRIVATE. Set sensitivity of doc controls. */
1252 /*---------------------------------------------------------------------------*/
1254 set_doc_items_sensitive (glUIPropertyBar *property_bar,
1257 gtk_widget_set_sensitive (property_bar->priv->font_family_combo, state);
1258 gtk_widget_set_sensitive (property_bar->priv->font_size_spin, state);
1259 gtk_widget_set_sensitive (property_bar->priv->font_bold_toggle, state);
1260 gtk_widget_set_sensitive (property_bar->priv->font_italic_toggle, state);
1261 gtk_widget_set_sensitive (property_bar->priv->text_align_left_radio, state);
1262 gtk_widget_set_sensitive (property_bar->priv->text_align_center_radio, state);
1263 gtk_widget_set_sensitive (property_bar->priv->text_align_right_radio, state);
1264 gtk_widget_set_sensitive (property_bar->priv->text_color_combo, state);
1265 gtk_widget_set_sensitive (property_bar->priv->fill_color_combo, state);
1266 gtk_widget_set_sensitive (property_bar->priv->line_color_combo, state);
1267 gtk_widget_set_sensitive (property_bar->priv->line_width_spin, state);
1270 /*---------------------------------------------------------------------------*/
1271 /* PRIVATE. Set sensitivity of text related controls. */
1272 /*---------------------------------------------------------------------------*/
1274 set_text_items_sensitive (glUIPropertyBar *property_bar,
1277 gtk_widget_set_sensitive (property_bar->priv->font_family_combo, state);
1278 gtk_widget_set_sensitive (property_bar->priv->font_size_spin, state);
1279 gtk_widget_set_sensitive (property_bar->priv->font_bold_toggle, state);
1280 gtk_widget_set_sensitive (property_bar->priv->font_italic_toggle, state);
1281 gtk_widget_set_sensitive (property_bar->priv->text_align_left_radio, state);
1282 gtk_widget_set_sensitive (property_bar->priv->text_align_center_radio, state);
1283 gtk_widget_set_sensitive (property_bar->priv->text_align_right_radio, state);
1284 gtk_widget_set_sensitive (property_bar->priv->text_color_combo, state);
1287 /*---------------------------------------------------------------------------*/
1288 /* PRIVATE. Set sensitivity of fill related controls. */
1289 /*---------------------------------------------------------------------------*/
1291 set_fill_items_sensitive (glUIPropertyBar *property_bar,
1294 gtk_widget_set_sensitive (property_bar->priv->fill_color_combo, state);
1297 /*---------------------------------------------------------------------------*/
1298 /* PRIVATE. Set sensitivity of line color related controls. */
1299 /*---------------------------------------------------------------------------*/
1301 set_line_color_items_sensitive (glUIPropertyBar *property_bar,
1304 gtk_widget_set_sensitive (property_bar->priv->line_color_combo, state);
1307 /*---------------------------------------------------------------------------*/
1308 /* PRIVATE. Set sensitivity of line width related controls. */
1309 /*---------------------------------------------------------------------------*/
1311 set_line_width_items_sensitive (glUIPropertyBar *property_bar,
1314 gtk_widget_set_sensitive (property_bar->priv->line_width_spin, state);