3 * Copyright (C) 2003-2009 Jim Evins <evins@snaught.com>.
5 * This file is part of gLabels.
7 * gLabels is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * gLabels is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with gLabels. If not, see <http://www.gnu.org/licenses/>.
23 #include "ui-property-bar.h"
25 #include <glib/gi18n.h>
29 #include "builder-util.h"
30 #include "font-combo.h"
31 #include "color-combo-button.h"
38 /*===========================================================================*/
39 /* Private macros and constants. */
40 /*===========================================================================*/
43 /*===========================================================================*/
44 /* Private data types */
45 /*===========================================================================*/
47 struct _glUIPropertyBarPrivate {
56 GtkWidget *font_family_eventbox;
57 GtkWidget *font_family_combo;
58 GtkWidget *font_size_spin;
59 GtkWidget *font_bold_toggle;
60 GtkWidget *font_italic_toggle;
62 /* Text alignment radios */
63 GtkWidget *text_align_left_radio;
64 GtkWidget *text_align_center_radio;
65 GtkWidget *text_align_right_radio;
67 /* Text vertical alignment radios */
68 GtkWidget *text_valign_top_radio;
69 GtkWidget *text_valign_vcenter_radio;
70 GtkWidget *text_valign_bottom_radio;
73 GtkWidget *text_color_eventbox;
74 GtkWidget *text_color_button;
75 GtkWidget *fill_color_eventbox;
76 GtkWidget *fill_color_button;
77 GtkWidget *line_color_eventbox;
78 GtkWidget *line_color_button;
81 GtkWidget *line_width_spin;
83 /* Prevent recursion */
84 gboolean stop_signals;
88 /*===========================================================================*/
90 /*===========================================================================*/
93 /*===========================================================================*/
94 /* Local function prototypes */
95 /*===========================================================================*/
97 static void gl_ui_property_bar_finalize (GObject *object);
99 static void gl_ui_property_bar_construct (glUIPropertyBar *this);
101 static void selection_changed_cb (glUIPropertyBar *this,
104 static void font_family_changed_cb (GtkComboBox *combo,
105 glUIPropertyBar *this);
107 static void font_size_changed_cb (GtkSpinButton *spin,
108 glUIPropertyBar *this);
110 static void text_color_changed_cb (glColorComboButton *cc,
113 glUIPropertyBar *this);
115 static void fill_color_changed_cb (glColorComboButton *cc,
118 glUIPropertyBar *this);
120 static void line_color_changed_cb (glColorComboButton *cc,
123 glUIPropertyBar *this);
125 static void line_width_changed_cb (GtkSpinButton *spin,
126 glUIPropertyBar *this);
128 static void font_bold_toggled_cb (GtkToggleToolButton *toggle,
129 glUIPropertyBar *this);
131 static void font_italic_toggled_cb (GtkToggleToolButton *toggle,
132 glUIPropertyBar *this);
134 static void text_align_toggled_cb (GtkToggleToolButton *toggle,
135 glUIPropertyBar *this);
137 static void text_valign_toggled_cb (GtkToggleToolButton *toggle,
138 glUIPropertyBar *this);
140 static void set_doc_items_sensitive (glUIPropertyBar *this,
143 static void set_text_items_sensitive (glUIPropertyBar *this,
146 static void set_fill_items_sensitive (glUIPropertyBar *this,
149 static void set_line_color_items_sensitive (glUIPropertyBar *this,
152 static void set_line_width_items_sensitive (glUIPropertyBar *this,
156 /****************************************************************************/
157 /* Boilerplate Object stuff. */
158 /****************************************************************************/
159 G_DEFINE_TYPE (glUIPropertyBar, gl_ui_property_bar, GTK_TYPE_HBOX)
163 gl_ui_property_bar_class_init (glUIPropertyBarClass *class)
165 GObjectClass *object_class = G_OBJECT_CLASS (class);
167 gl_debug (DEBUG_PROPERTY_BAR, "START");
169 gl_ui_property_bar_parent_class = g_type_class_peek_parent (class);
171 object_class->finalize = gl_ui_property_bar_finalize;
173 gl_debug (DEBUG_PROPERTY_BAR, "END");
178 gl_ui_property_bar_init (glUIPropertyBar *this)
180 gl_debug (DEBUG_PROPERTY_BAR, "START");
182 this->priv = g_new0 (glUIPropertyBarPrivate, 1);
184 gl_debug (DEBUG_PROPERTY_BAR, "END");
189 gl_ui_property_bar_finalize (GObject *object)
191 glUIPropertyBar *this = GL_UI_PROPERTY_BAR (object);
193 gl_debug (DEBUG_PROPERTY_BAR, "START");
195 g_return_if_fail (object != NULL);
196 g_return_if_fail (GL_IS_UI_PROPERTY_BAR (object));
198 if (this->priv->label)
200 g_object_unref (G_OBJECT(this->priv->label));
202 if (this->priv->builder)
204 g_object_unref (G_OBJECT(this->priv->builder));
208 G_OBJECT_CLASS (gl_ui_property_bar_parent_class)->finalize (object);
210 gl_debug (DEBUG_PROPERTY_BAR, "END");
214 /****************************************************************************/
215 /* Create a NEW property_bar. */
216 /****************************************************************************/
218 gl_ui_property_bar_new (void)
220 glUIPropertyBar *this;
222 gl_debug (DEBUG_PROPERTY_BAR, "START");
224 this = g_object_new (GL_TYPE_UI_PROPERTY_BAR, NULL);
226 gl_ui_property_bar_construct (this);
228 gl_debug (DEBUG_PROPERTY_BAR, "END");
230 return GTK_WIDGET (this);
234 /******************************************************************************/
235 /* Initialize property toolbar. */
236 /******************************************************************************/
238 gl_ui_property_bar_construct (glUIPropertyBar *this)
240 gchar *builder_filename;
242 static gchar *object_ids[] = { "property_toolbar",
243 "adjustment1", "adjustment2",
245 GError *error = NULL;
247 gl_debug (DEBUG_PROPERTY_BAR, "START");
249 this->priv->stop_signals = TRUE;
251 builder = gtk_builder_new ();
252 builder_filename = g_build_filename (GLABELS_DATA_DIR, "ui", "property-bar.ui", NULL);
253 gtk_builder_add_objects_from_file (builder, builder_filename, object_ids, &error);
254 g_free (builder_filename);
256 g_critical ("%s\n\ngLabels may not be installed correctly!", error->message);
257 g_error_free (error);
261 gl_builder_util_get_widgets (builder,
262 "property_toolbar", &this->priv->tool_bar,
263 "font_family_eventbox", &this->priv->font_family_eventbox,
264 "font_size_spin", &this->priv->font_size_spin,
265 "font_bold_toggle", &this->priv->font_bold_toggle,
266 "font_italic_toggle", &this->priv->font_italic_toggle,
267 "text_align_left_radio", &this->priv->text_align_left_radio,
268 "text_align_center_radio", &this->priv->text_align_center_radio,
269 "text_align_right_radio", &this->priv->text_align_right_radio,
270 "text_valign_top_radio", &this->priv->text_valign_top_radio,
271 "text_valign_vcenter_radio", &this->priv->text_valign_vcenter_radio,
272 "text_valign_bottom_radio", &this->priv->text_valign_bottom_radio,
273 "text_color_eventbox", &this->priv->text_color_eventbox,
274 "fill_color_eventbox", &this->priv->fill_color_eventbox,
275 "line_color_eventbox", &this->priv->line_color_eventbox,
276 "line_width_spin", &this->priv->line_width_spin,
279 gtk_container_add (GTK_CONTAINER (this), this->priv->tool_bar);
281 this->priv->font_family_combo =
282 gl_font_combo_new (gl_prefs_model_get_default_font_family (gl_prefs));
283 gtk_container_add (GTK_CONTAINER (this->priv->font_family_eventbox),
284 this->priv->font_family_combo);
286 this->priv->text_color_button =
287 gl_color_combo_button_new ("glabels-text",
289 GL_COLOR_TEXT_DEFAULT,
290 gl_prefs_model_get_default_text_color (gl_prefs));
291 gl_color_combo_button_set_relief (GL_COLOR_COMBO_BUTTON(this->priv->text_color_button),
293 gtk_container_add (GTK_CONTAINER (this->priv->text_color_eventbox),
294 this->priv->text_color_button);
296 this->priv->fill_color_button =
297 gl_color_combo_button_new ("glabels-bucket-fill",
300 gl_prefs_model_get_default_fill_color (gl_prefs));
301 gl_color_combo_button_set_relief (GL_COLOR_COMBO_BUTTON(this->priv->fill_color_button),
303 gtk_container_add (GTK_CONTAINER (this->priv->fill_color_eventbox),
304 this->priv->fill_color_button);
306 this->priv->line_color_button =
307 gl_color_combo_button_new ("glabels-pencil",
310 gl_prefs_model_get_default_line_color (gl_prefs));
311 gl_color_combo_button_set_relief (GL_COLOR_COMBO_BUTTON(this->priv->line_color_button),
313 gtk_container_add (GTK_CONTAINER (this->priv->line_color_eventbox),
314 this->priv->line_color_button);
316 /* Save reference to gui tree so we don't lose tooltips */
317 this->priv->builder = builder;
319 set_doc_items_sensitive (this, FALSE);
321 /* Font family entry widget */
322 g_signal_connect (G_OBJECT (this->priv->font_family_combo),
323 "changed", G_CALLBACK (font_family_changed_cb), this);
325 /* Font size entry widget */
326 gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->font_size_spin),
327 gl_prefs_model_get_default_font_size (gl_prefs));
329 g_signal_connect (G_OBJECT (this->priv->font_size_spin),
330 "changed", G_CALLBACK (font_size_changed_cb), this);
333 /* Bold and Italic toggles */
334 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_bold_toggle),
335 (gl_prefs_model_get_default_font_weight (gl_prefs) == PANGO_WEIGHT_BOLD));
336 g_signal_connect (G_OBJECT (this->priv->font_bold_toggle),
337 "toggled", G_CALLBACK (font_bold_toggled_cb), this);
338 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_italic_toggle),
339 gl_prefs_model_get_default_font_italic_flag (gl_prefs));
340 g_signal_connect (G_OBJECT (this->priv->font_italic_toggle),
341 "toggled", G_CALLBACK (font_italic_toggled_cb), this);
344 /* Text alignment radio group */
345 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio),
346 (gl_prefs_model_get_default_text_alignment (gl_prefs) == PANGO_ALIGN_LEFT));
347 g_signal_connect (G_OBJECT (this->priv->text_align_left_radio),
348 "toggled", G_CALLBACK (text_align_toggled_cb), this);
349 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio),
350 (gl_prefs_model_get_default_text_alignment (gl_prefs) == PANGO_ALIGN_CENTER));
351 g_signal_connect (G_OBJECT (this->priv->text_align_center_radio),
352 "toggled", G_CALLBACK (text_align_toggled_cb), this);
353 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
354 (gl_prefs_model_get_default_text_alignment (gl_prefs) == PANGO_ALIGN_RIGHT));
355 g_signal_connect (G_OBJECT (this->priv->text_align_right_radio),
356 "toggled", G_CALLBACK (text_align_toggled_cb), this);
358 /* Text vertical alignment radio group */
359 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_top_radio), TRUE);
360 g_signal_connect (G_OBJECT (this->priv->text_valign_top_radio),
361 "toggled", G_CALLBACK (text_valign_toggled_cb), this);
362 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_vcenter_radio), FALSE);
363 g_signal_connect (G_OBJECT (this->priv->text_valign_vcenter_radio),
364 "toggled", G_CALLBACK (text_valign_toggled_cb), this);
365 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_bottom_radio), FALSE);
366 g_signal_connect (G_OBJECT (this->priv->text_valign_bottom_radio),
367 "toggled", G_CALLBACK (text_valign_toggled_cb), this);
369 /* Text color widget */
370 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->text_color_button),
371 gl_prefs_model_get_default_text_color (gl_prefs));
372 g_signal_connect (G_OBJECT (this->priv->text_color_button),
374 G_CALLBACK (text_color_changed_cb), this);
376 /* Fill color widget */
377 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->fill_color_button),
378 gl_prefs_model_get_default_fill_color (gl_prefs));
379 g_signal_connect (G_OBJECT (this->priv->fill_color_button),
381 G_CALLBACK (fill_color_changed_cb), this);
383 /* Line color widget */
384 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->line_color_button),
385 gl_prefs_model_get_default_line_color (gl_prefs));
386 g_signal_connect (G_OBJECT (this->priv->line_color_button),
388 G_CALLBACK (line_color_changed_cb), this);
390 /* Line width entry widget */
391 g_signal_connect (G_OBJECT (this->priv->line_width_spin),
393 G_CALLBACK (line_width_changed_cb), this);
395 this->priv->stop_signals = FALSE;
397 gl_debug (DEBUG_PROPERTY_BAR, "END");
401 /****************************************************************************/
402 /* Fill widgets with default values. */
403 /****************************************************************************/
405 reset_to_default_properties (glLabel *label,
406 glUIPropertyBar *this)
410 family = gl_label_get_default_font_family (label);
411 gl_font_combo_set_family (GL_FONT_COMBO (this->priv->font_family_combo), family);
414 gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->font_size_spin),
415 gl_label_get_default_font_size (label));
417 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_bold_toggle),
418 (gl_label_get_default_font_weight (label) == PANGO_WEIGHT_BOLD));
419 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_italic_toggle),
420 gl_label_get_default_font_italic_flag (label));
422 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio),
423 (gl_label_get_default_text_alignment (label) == PANGO_ALIGN_LEFT));
424 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio),
425 (gl_label_get_default_text_alignment (label) == PANGO_ALIGN_CENTER));
426 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
427 (gl_label_get_default_text_alignment (label) == PANGO_ALIGN_RIGHT));
429 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_top_radio),
430 (gl_label_get_default_text_valignment (label) == GL_VALIGN_TOP));
431 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_vcenter_radio),
432 (gl_label_get_default_text_valignment (label) == GL_VALIGN_VCENTER));
433 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_bottom_radio),
434 (gl_label_get_default_text_valignment (label) == GL_VALIGN_BOTTOM));
436 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON(this->priv->text_color_button),
437 gl_label_get_default_text_color (label));
439 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON(this->priv->fill_color_button),
440 gl_label_get_default_fill_color (label));
442 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON(this->priv->line_color_button),
443 gl_label_get_default_line_color (label));
445 gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->line_width_spin),
446 gl_label_get_default_line_width (label));
450 /****************************************************************************/
451 /* Set label associated with property_bar. */
452 /****************************************************************************/
454 gl_ui_property_bar_set_label (glUIPropertyBar *this,
457 gl_debug (DEBUG_PROPERTY_BAR, "START");
459 g_return_if_fail (label && GL_IS_LABEL (label));
461 set_doc_items_sensitive (this, TRUE);
463 reset_to_default_properties (label, this);
465 this->priv->label = GL_LABEL (g_object_ref (G_OBJECT (label)));
467 g_signal_connect_swapped (G_OBJECT(label), "selection_changed",
468 G_CALLBACK(selection_changed_cb), this);
470 g_signal_connect_swapped (G_OBJECT(label), "changed",
471 G_CALLBACK(selection_changed_cb), this);
473 gl_debug (DEBUG_PROPERTY_BAR, "END");
477 /*---------------------------------------------------------------------------*/
478 /* PRIVATE. Label "selection state changed" callback. */
479 /*---------------------------------------------------------------------------*/
481 update_text_properties (glLabel *label,
482 glUIPropertyBar *this)
484 gboolean can_text, is_first_object;
485 gboolean is_same_font_family, is_same_font_size;
486 gboolean is_same_text_color, is_same_is_italic;
487 gboolean is_same_is_bold, is_same_align, is_same_valign;
488 GList *selection_list;
490 glLabelObject *object;
491 gchar *selection_font_family, *font_family;
492 gdouble selection_font_size, font_size;
493 guint selection_text_color, text_color;
494 glColorNode *text_color_node;
495 gboolean selection_is_italic, is_italic;
496 gboolean selection_is_bold, is_bold;
497 PangoAlignment selection_align, align;
498 glValignment selection_valign, valign;
500 can_text = gl_label_can_selection_text (label);
501 set_text_items_sensitive (this, can_text);
512 is_same_font_family = TRUE;
513 selection_font_family = NULL;
514 selection_font_size = -1;
515 selection_align = PANGO_ALIGN_LEFT;
516 selection_is_italic = TRUE;
517 selection_is_bold = TRUE;
518 selection_text_color = 0;
520 is_first_object = TRUE;
522 selection_list = gl_label_get_selection_list (label);
523 for (p = selection_list; p != NULL; p = p->next)
526 object = GL_LABEL_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);
565 valign = gl_label_object_get_text_valignment (object);
569 selection_font_size = font_size;
570 selection_text_color = text_color;
571 selection_is_italic = is_italic;
572 selection_is_bold = is_bold;
573 selection_align = align;
574 selection_valign = valign;
578 if (font_size != selection_font_size)
579 is_same_font_size = FALSE;
580 if (text_color != selection_text_color)
581 is_same_text_color = FALSE;
582 if (is_italic != selection_is_italic)
583 is_same_is_italic = FALSE;
584 if (is_bold != selection_is_bold)
585 is_same_is_bold = FALSE;
586 if (align != selection_align)
587 is_same_align = FALSE;
588 if (valign != selection_valign)
589 is_same_valign = FALSE;
591 is_first_object = FALSE;
594 g_list_free (selection_list);
596 if (is_same_font_family && (selection_font_family != NULL))
597 gl_debug (DEBUG_PROPERTY_BAR, "same font family = %s",
598 selection_font_family);
599 gl_font_combo_set_family (GL_FONT_COMBO (this->priv->font_family_combo),
600 is_same_font_family?selection_font_family:"");
601 g_free (selection_font_family);
603 if (is_same_font_size)
605 gl_debug (DEBUG_PROPERTY_BAR, "same font size = %g",
606 selection_font_size);
607 gtk_spin_button_set_value (GTK_SPIN_BUTTON (this->priv->font_size_spin),
608 selection_font_size);
612 gtk_entry_set_text (GTK_ENTRY (this->priv->font_size_spin), "");
615 if (is_same_text_color)
617 gl_debug (DEBUG_PROPERTY_BAR, "same text color = %08x", selection_text_color);
618 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->text_color_button),
619 selection_text_color);
622 if (is_same_is_italic)
624 gl_debug (DEBUG_PROPERTY_BAR, "same italic flag = %d",
625 selection_is_italic);
627 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_italic_toggle),
628 selection_is_italic && is_same_is_italic);
632 gl_debug (DEBUG_PROPERTY_BAR, "same bold flag = %d",
635 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_bold_toggle),
636 selection_is_bold && is_same_is_bold);
639 gl_debug (DEBUG_PROPERTY_BAR, "same align");
640 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio),
641 (selection_align == PANGO_ALIGN_LEFT) &&
643 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio),
644 (selection_align == PANGO_ALIGN_CENTER) &&
646 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
647 (selection_align == PANGO_ALIGN_RIGHT) &&
651 gl_debug (DEBUG_PROPERTY_BAR, "same valign");
652 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_top_radio),
653 (selection_valign == GL_VALIGN_TOP) &&
655 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_vcenter_radio),
656 (selection_valign == GL_VALIGN_VCENTER) &&
658 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_bottom_radio),
659 (selection_valign == GL_VALIGN_BOTTOM) &&
665 update_fill_color (glLabel *label,
666 glUIPropertyBar *this)
668 gboolean can, is_first_object;
669 gboolean is_same_fill_color;
670 GList *selection_list;
672 glLabelObject *object;
673 guint selection_fill_color, fill_color;
674 glColorNode *fill_color_node;
676 can = gl_label_can_selection_fill (label);
677 set_fill_items_sensitive (this, can);
682 is_same_fill_color = TRUE;
683 is_first_object = TRUE;
684 selection_fill_color = 0;
686 selection_list = gl_label_get_selection_list (label);
688 for (p = selection_list; p != NULL; p = p->next)
691 object = GL_LABEL_OBJECT (p->data);
692 if (!gl_label_object_can_fill (object))
695 fill_color_node = gl_label_object_get_fill_color (object);
696 if (fill_color_node->field_flag)
698 /* If a merge field is set we use the default color for merged color*/
699 fill_color = GL_COLOR_FILL_MERGE_DEFAULT;
704 fill_color = fill_color_node->color;
706 gl_color_node_free (&fill_color_node);
710 selection_fill_color = fill_color;
714 if (fill_color != selection_fill_color)
716 is_same_fill_color = FALSE;
719 is_first_object = FALSE;
722 g_list_free (selection_list);
724 if (is_same_fill_color)
726 gl_debug (DEBUG_PROPERTY_BAR, "same fill color = %08x", selection_fill_color);
727 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->fill_color_button),
728 selection_fill_color);
734 update_line_color (glLabel *label,
735 glUIPropertyBar *this)
737 gboolean can, is_first_object;
738 gboolean is_same_line_color;
739 GList *selection_list;
741 glLabelObject *object;
742 guint selection_line_color, line_color;
743 glColorNode *line_color_node;
745 can = gl_label_can_selection_line_color (label);
746 set_line_color_items_sensitive (this, can);
751 is_same_line_color = TRUE;
752 is_first_object = TRUE;
753 selection_line_color = 0;
755 selection_list = gl_label_get_selection_list (label);
757 for (p = selection_list; p != NULL; p = p->next)
760 object = GL_LABEL_OBJECT (p->data);
761 if (!gl_label_object_can_line_color (object))
764 line_color_node = gl_label_object_get_line_color (object);
765 if (line_color_node->field_flag)
767 /* If a merge field is set we use the default color for merged color*/
768 line_color = GL_COLOR_MERGE_DEFAULT;
773 line_color = line_color_node->color;
775 gl_color_node_free (&line_color_node);
779 selection_line_color = line_color;
783 if (line_color != selection_line_color)
785 is_same_line_color = FALSE;
788 is_first_object = FALSE;
791 g_list_free (selection_list);
793 if (is_same_line_color)
795 gl_debug (DEBUG_PROPERTY_BAR, "same line color = %08x", selection_line_color);
796 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->line_color_button),
797 selection_line_color);
803 update_line_width (glLabel *label,
804 glUIPropertyBar *this)
806 gboolean can, is_first_object;
807 gboolean is_same_line_width;
808 GList *selection_list;
810 glLabelObject *object;
811 gdouble selection_line_width, line_width;
813 can = gl_label_can_selection_line_width (label);
814 set_line_width_items_sensitive (this, can);
819 is_same_line_width = TRUE;
820 is_first_object = TRUE;
821 selection_line_width = 0;
823 selection_list = gl_label_get_selection_list (label);
825 for (p = selection_list; p != NULL; p = p->next)
828 object = GL_LABEL_OBJECT (p->data);
829 if (!gl_label_object_can_line_width (object))
832 line_width = gl_label_object_get_line_width (object);
836 selection_line_width = line_width;
840 if (line_width != selection_line_width)
842 is_same_line_width = FALSE;
845 is_first_object = FALSE;
848 g_list_free (selection_list);
850 if (is_same_line_width)
852 gl_debug (DEBUG_PROPERTY_BAR, "same line width = %g", selection_line_width);
853 gtk_spin_button_set_value (GTK_SPIN_BUTTON (this->priv->line_width_spin),
854 selection_line_width);
858 gtk_entry_set_text (GTK_ENTRY (this->priv->line_width_spin), "");
864 selection_changed_cb (glUIPropertyBar *this,
867 g_return_if_fail (label && GL_IS_LABEL (label));
868 g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
870 if (this->priv->stop_signals) return;
871 this->priv->stop_signals = TRUE;
873 gl_debug (DEBUG_PROPERTY_BAR, "START");
875 if (gl_label_is_selection_empty (label))
877 /* No selection: make all controls active. */
878 reset_to_default_properties (label, this);
879 set_doc_items_sensitive (this, TRUE);
883 update_text_properties (label, this);
884 update_fill_color (label, this);
885 update_line_color (label, this);
886 update_line_width (label, this);
889 gl_debug (DEBUG_PROPERTY_BAR, "END");
891 this->priv->stop_signals = FALSE;
895 /*--------------------------------------------------------------------------*/
896 /* PRIVATE. Font family entry changed. */
897 /*--------------------------------------------------------------------------*/
899 font_family_changed_cb (GtkComboBox *combo,
900 glUIPropertyBar *this)
904 if (this->priv->stop_signals) return;
905 this->priv->stop_signals = TRUE;
907 gl_debug (DEBUG_PROPERTY_BAR, "START");
909 font_family = gl_font_combo_get_family (GL_FONT_COMBO (combo));
910 if ( *font_family != '\0' )
912 gl_label_set_selection_font_family (this->priv->label, font_family);
913 gl_label_set_default_font_family (this->priv->label, font_family);
915 g_free (font_family);
917 gl_debug (DEBUG_PROPERTY_BAR, "END");
919 this->priv->stop_signals = FALSE;
923 /*--------------------------------------------------------------------------*/
924 /* PRIVATE. Font size spin button changed. */
925 /*--------------------------------------------------------------------------*/
927 font_size_changed_cb (GtkSpinButton *spin,
928 glUIPropertyBar *this)
932 if (this->priv->stop_signals) return;
933 this->priv->stop_signals = TRUE;
935 gl_debug (DEBUG_PROPERTY_BAR, "START");
937 font_size = gtk_spin_button_get_value (spin);
939 gl_label_set_selection_font_size (this->priv->label,
941 gl_label_set_default_font_size (this->priv->label,
944 gl_debug (DEBUG_PROPERTY_BAR, "END");
946 this->priv->stop_signals = FALSE;
950 /*--------------------------------------------------------------------------*/
951 /* PRIVATE. Text color combo changed. */
952 /*--------------------------------------------------------------------------*/
954 text_color_changed_cb (glColorComboButton *cc,
957 glUIPropertyBar *this)
959 glColorNode *text_color_node;
961 g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
963 if (this->priv->stop_signals) return;
964 this->priv->stop_signals = TRUE;
966 gl_debug (DEBUG_PROPERTY_BAR, "START");
968 text_color_node = gl_color_node_new_default ();
969 text_color_node->color = color;
971 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
976 text_color_node->color = gl_prefs_model_get_default_text_color (gl_prefs);
977 gl_label_set_selection_text_color (this->priv->label,
979 gl_label_set_default_text_color (this->priv->label,
980 text_color_node->color);
984 gl_label_set_selection_text_color (this->priv->label,
986 gl_label_set_default_text_color (this->priv->label,
987 text_color_node->color);
990 gl_color_node_free (&text_color_node);
992 gl_debug (DEBUG_PROPERTY_BAR, "END");
994 this->priv->stop_signals = FALSE;
998 /*--------------------------------------------------------------------------*/
999 /* PRIVATE. Fill color combo changed. */
1000 /*--------------------------------------------------------------------------*/
1002 fill_color_changed_cb (glColorComboButton *cc,
1004 gboolean is_default,
1005 glUIPropertyBar *this)
1007 glColorNode *fill_color_node;
1009 g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
1011 if (this->priv->stop_signals) return;
1012 this->priv->stop_signals = TRUE;
1014 gl_debug (DEBUG_PROPERTY_BAR, "START");
1016 fill_color_node = gl_color_node_new_default ();
1018 fill_color_node->color = color;
1020 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
1026 fill_color_node->color = GL_COLOR_NONE;
1027 gl_label_set_selection_fill_color (this->priv->label,
1029 gl_label_set_default_fill_color (this->priv->label,
1030 fill_color_node->color);
1034 gl_label_set_selection_fill_color (this->priv->label,
1036 gl_label_set_default_fill_color (this->priv->label,
1037 fill_color_node->color);
1039 gl_color_node_free (&fill_color_node);
1041 gl_debug (DEBUG_PROPERTY_BAR, "END");
1043 this->priv->stop_signals = FALSE;
1047 /*--------------------------------------------------------------------------*/
1048 /* PRIVATE. Line color combo changed. */
1049 /*--------------------------------------------------------------------------*/
1051 line_color_changed_cb (glColorComboButton *cc,
1053 gboolean is_default,
1054 glUIPropertyBar *this)
1056 glColorNode *line_color_node;
1058 g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
1060 if (this->priv->stop_signals) return;
1061 this->priv->stop_signals = TRUE;
1063 gl_debug (DEBUG_PROPERTY_BAR, "START");
1065 line_color_node = gl_color_node_new_default ();
1066 line_color_node->color = color;
1068 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
1073 line_color_node->color = GL_COLOR_NONE;
1074 gl_label_set_selection_line_color (this->priv->label,
1076 gl_label_set_default_line_color (this->priv->label,
1077 line_color_node->color);
1081 gl_label_set_selection_line_color (this->priv->label,
1083 gl_label_set_default_line_color (this->priv->label,
1084 line_color_node->color);
1086 gl_color_node_free (&line_color_node);
1088 gl_debug (DEBUG_PROPERTY_BAR, "END");
1090 this->priv->stop_signals = FALSE;
1094 /*--------------------------------------------------------------------------*/
1095 /* PRIVATE. Line width spin button changed. */
1096 /*--------------------------------------------------------------------------*/
1098 line_width_changed_cb (GtkSpinButton *spin,
1099 glUIPropertyBar *this)
1103 if (this->priv->stop_signals) return;
1104 this->priv->stop_signals = TRUE;
1106 gl_debug (DEBUG_PROPERTY_BAR, "START");
1108 if (this->priv->label)
1110 line_width = gtk_spin_button_get_value (spin);
1112 gl_label_set_selection_line_width (this->priv->label,
1114 gl_label_set_default_line_width (this->priv->label,
1118 gl_debug (DEBUG_PROPERTY_BAR, "END");
1120 this->priv->stop_signals = FALSE;
1124 /*---------------------------------------------------------------------------*/
1125 /* PRIVATE. Font bold toggled callback. */
1126 /*---------------------------------------------------------------------------*/
1128 font_bold_toggled_cb (GtkToggleToolButton *toggle,
1129 glUIPropertyBar *this)
1135 if (this->priv->stop_signals) return;
1136 this->priv->stop_signals = TRUE;
1138 gl_debug (DEBUG_PROPERTY_BAR, "START");
1140 state = gtk_toggle_tool_button_get_active (toggle);
1142 weight = state ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
1144 gl_label_set_selection_font_weight (this->priv->label, weight);
1145 gl_label_set_default_font_weight (this->priv->label, weight);
1147 gl_debug (DEBUG_PROPERTY_BAR, "END");
1149 this->priv->stop_signals = FALSE;
1153 /*---------------------------------------------------------------------------*/
1154 /* PRIVATE. Font italic toggled callback. */
1155 /*---------------------------------------------------------------------------*/
1157 font_italic_toggled_cb (GtkToggleToolButton *toggle,
1158 glUIPropertyBar *this)
1162 if (this->priv->stop_signals) return;
1163 this->priv->stop_signals = TRUE;
1165 gl_debug (DEBUG_PROPERTY_BAR, "START");
1167 state = gtk_toggle_tool_button_get_active (toggle);
1169 gl_label_set_selection_font_italic_flag (this->priv->label, state);
1170 gl_label_set_default_font_italic_flag (this->priv->label, state);
1172 gl_debug (DEBUG_PROPERTY_BAR, "END");
1174 this->priv->stop_signals = FALSE;
1178 /*---------------------------------------------------------------------------*/
1179 /* PRIVATE. Text align toggled callback. */
1180 /*---------------------------------------------------------------------------*/
1182 text_align_toggled_cb (GtkToggleToolButton *toggle,
1183 glUIPropertyBar *this)
1185 if (this->priv->stop_signals) return;
1186 this->priv->stop_signals = TRUE;
1188 gl_debug (DEBUG_PROPERTY_BAR, "START");
1190 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio)))
1192 gl_label_set_selection_text_alignment (this->priv->label,
1194 gl_label_set_default_text_alignment (this->priv->label,
1198 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio)))
1200 gl_label_set_selection_text_alignment (this->priv->label,
1201 PANGO_ALIGN_CENTER);
1202 gl_label_set_default_text_alignment (this->priv->label,
1203 PANGO_ALIGN_CENTER);
1206 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio)))
1208 gl_label_set_selection_text_alignment (this->priv->label,
1210 gl_label_set_default_text_alignment (this->priv->label,
1214 gl_debug (DEBUG_PROPERTY_BAR, "END");
1216 this->priv->stop_signals = FALSE;
1220 /*---------------------------------------------------------------------------*/
1221 /* PRIVATE. Text vertical align toggled callback. */
1222 /*---------------------------------------------------------------------------*/
1224 text_valign_toggled_cb (GtkToggleToolButton *toggle,
1225 glUIPropertyBar *this)
1227 if (this->priv->stop_signals) return;
1228 this->priv->stop_signals = TRUE;
1230 gl_debug (DEBUG_PROPERTY_BAR, "START");
1232 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_top_radio)))
1234 gl_label_set_selection_text_valignment (this->priv->label,
1236 gl_label_set_default_text_valignment (this->priv->label,
1240 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_vcenter_radio)))
1242 gl_label_set_selection_text_valignment (this->priv->label,
1244 gl_label_set_default_text_valignment (this->priv->label,
1248 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_bottom_radio)))
1250 gl_label_set_selection_text_valignment (this->priv->label,
1252 gl_label_set_default_text_valignment (this->priv->label,
1256 gl_debug (DEBUG_PROPERTY_BAR, "END");
1258 this->priv->stop_signals = FALSE;
1262 /*---------------------------------------------------------------------------*/
1263 /* PRIVATE. Set sensitivity of doc controls. */
1264 /*---------------------------------------------------------------------------*/
1266 set_doc_items_sensitive (glUIPropertyBar *this,
1269 gtk_widget_set_sensitive (this->priv->font_family_combo, state);
1270 gtk_widget_set_sensitive (this->priv->font_size_spin, state);
1271 gtk_widget_set_sensitive (this->priv->font_bold_toggle, state);
1272 gtk_widget_set_sensitive (this->priv->font_italic_toggle, state);
1273 gtk_widget_set_sensitive (this->priv->text_align_left_radio, state);
1274 gtk_widget_set_sensitive (this->priv->text_align_center_radio, state);
1275 gtk_widget_set_sensitive (this->priv->text_align_right_radio, state);
1276 gtk_widget_set_sensitive (this->priv->text_valign_top_radio, state);
1277 gtk_widget_set_sensitive (this->priv->text_valign_vcenter_radio, state);
1278 gtk_widget_set_sensitive (this->priv->text_valign_bottom_radio, state);
1279 gtk_widget_set_sensitive (this->priv->text_color_button, state);
1280 gtk_widget_set_sensitive (this->priv->fill_color_button, state);
1281 gtk_widget_set_sensitive (this->priv->line_color_button, state);
1282 gtk_widget_set_sensitive (this->priv->line_width_spin, state);
1286 /*---------------------------------------------------------------------------*/
1287 /* PRIVATE. Set sensitivity of text related controls. */
1288 /*---------------------------------------------------------------------------*/
1290 set_text_items_sensitive (glUIPropertyBar *this,
1293 gtk_widget_set_sensitive (this->priv->font_family_combo, state);
1294 gtk_widget_set_sensitive (this->priv->font_size_spin, state);
1295 gtk_widget_set_sensitive (this->priv->font_bold_toggle, state);
1296 gtk_widget_set_sensitive (this->priv->font_italic_toggle, state);
1297 gtk_widget_set_sensitive (this->priv->text_align_left_radio, state);
1298 gtk_widget_set_sensitive (this->priv->text_align_center_radio, state);
1299 gtk_widget_set_sensitive (this->priv->text_align_right_radio, state);
1300 gtk_widget_set_sensitive (this->priv->text_valign_top_radio, state);
1301 gtk_widget_set_sensitive (this->priv->text_valign_vcenter_radio, state);
1302 gtk_widget_set_sensitive (this->priv->text_valign_bottom_radio, state);
1303 gtk_widget_set_sensitive (this->priv->text_color_button, state);
1307 /*---------------------------------------------------------------------------*/
1308 /* PRIVATE. Set sensitivity of fill related controls. */
1309 /*---------------------------------------------------------------------------*/
1311 set_fill_items_sensitive (glUIPropertyBar *this,
1314 gtk_widget_set_sensitive (this->priv->fill_color_button, state);
1318 /*---------------------------------------------------------------------------*/
1319 /* PRIVATE. Set sensitivity of line color related controls. */
1320 /*---------------------------------------------------------------------------*/
1322 set_line_color_items_sensitive (glUIPropertyBar *this,
1325 gtk_widget_set_sensitive (this->priv->line_color_button, state);
1329 /*---------------------------------------------------------------------------*/
1330 /* PRIVATE. Set sensitivity of line width related controls. */
1331 /*---------------------------------------------------------------------------*/
1333 set_line_width_items_sensitive (glUIPropertyBar *this,
1336 gtk_widget_set_sensitive (this->priv->line_width_spin, state);
1342 * Local Variables: -- emacs
1344 * c-basic-offset: 8 -- emacs
1345 * tab-width: 8 -- emacs
1346 * indent-tabs-mode: nil -- emacs