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>
30 #include "builder-util.h"
31 #include "font-combo.h"
32 #include "color-combo-button.h"
39 /*===========================================================================*/
40 /* Private macros and constants. */
41 /*===========================================================================*/
44 /*===========================================================================*/
45 /* Private data types */
46 /*===========================================================================*/
48 struct _glUIPropertyBarPrivate {
57 GtkWidget *font_family_eventbox;
58 GtkWidget *font_family_combo;
59 GtkWidget *font_size_spin;
60 GtkWidget *font_bold_toggle;
61 GtkWidget *font_italic_toggle;
63 /* Text alignment radios */
64 GtkWidget *text_align_left_radio;
65 GtkWidget *text_align_center_radio;
66 GtkWidget *text_align_right_radio;
68 /* Text vertical alignment radios */
69 GtkWidget *text_valign_top_radio;
70 GtkWidget *text_valign_vcenter_radio;
71 GtkWidget *text_valign_bottom_radio;
74 GtkWidget *text_color_eventbox;
75 GtkWidget *text_color_button;
76 GtkWidget *fill_color_eventbox;
77 GtkWidget *fill_color_button;
78 GtkWidget *line_color_eventbox;
79 GtkWidget *line_color_button;
82 GtkWidget *line_width_spin;
84 /* Prevent recursion */
85 gboolean stop_signals;
89 /*===========================================================================*/
91 /*===========================================================================*/
94 /*===========================================================================*/
95 /* Local function prototypes */
96 /*===========================================================================*/
98 static void gl_ui_property_bar_finalize (GObject *object);
100 static void gl_ui_property_bar_construct (glUIPropertyBar *this);
102 static void selection_changed_cb (glUIPropertyBar *this,
105 static void font_family_changed_cb (GtkComboBox *combo,
106 glUIPropertyBar *this);
108 static void font_size_changed_cb (GtkSpinButton *spin,
109 glUIPropertyBar *this);
111 static void text_color_changed_cb (glColorComboButton *cc,
114 glUIPropertyBar *this);
116 static void fill_color_changed_cb (glColorComboButton *cc,
119 glUIPropertyBar *this);
121 static void line_color_changed_cb (glColorComboButton *cc,
124 glUIPropertyBar *this);
126 static void line_width_changed_cb (GtkSpinButton *spin,
127 glUIPropertyBar *this);
129 static void font_bold_toggled_cb (GtkToggleToolButton *toggle,
130 glUIPropertyBar *this);
132 static void font_italic_toggled_cb (GtkToggleToolButton *toggle,
133 glUIPropertyBar *this);
135 static void text_align_toggled_cb (GtkToggleToolButton *toggle,
136 glUIPropertyBar *this);
138 static void text_valign_toggled_cb (GtkToggleToolButton *toggle,
139 glUIPropertyBar *this);
141 static void set_doc_items_sensitive (glUIPropertyBar *this,
144 static void set_text_items_sensitive (glUIPropertyBar *this,
147 static void set_fill_items_sensitive (glUIPropertyBar *this,
150 static void set_line_color_items_sensitive (glUIPropertyBar *this,
153 static void set_line_width_items_sensitive (glUIPropertyBar *this,
157 /****************************************************************************/
158 /* Boilerplate Object stuff. */
159 /****************************************************************************/
160 G_DEFINE_TYPE (glUIPropertyBar, gl_ui_property_bar, GTK_TYPE_HBOX)
164 gl_ui_property_bar_class_init (glUIPropertyBarClass *class)
166 GObjectClass *object_class = G_OBJECT_CLASS (class);
168 gl_debug (DEBUG_PROPERTY_BAR, "START");
170 gl_ui_property_bar_parent_class = g_type_class_peek_parent (class);
172 object_class->finalize = gl_ui_property_bar_finalize;
174 gl_debug (DEBUG_PROPERTY_BAR, "END");
179 gl_ui_property_bar_init (glUIPropertyBar *this)
181 gl_debug (DEBUG_PROPERTY_BAR, "START");
183 this->priv = g_new0 (glUIPropertyBarPrivate, 1);
185 gl_debug (DEBUG_PROPERTY_BAR, "END");
190 gl_ui_property_bar_finalize (GObject *object)
192 glUIPropertyBar *this = GL_UI_PROPERTY_BAR (object);
194 gl_debug (DEBUG_PROPERTY_BAR, "START");
196 g_return_if_fail (object != NULL);
197 g_return_if_fail (GL_IS_UI_PROPERTY_BAR (object));
199 if (this->priv->label)
201 g_object_unref (G_OBJECT(this->priv->label));
203 if (this->priv->builder)
205 g_object_unref (G_OBJECT(this->priv->builder));
209 G_OBJECT_CLASS (gl_ui_property_bar_parent_class)->finalize (object);
211 gl_debug (DEBUG_PROPERTY_BAR, "END");
215 /****************************************************************************/
216 /* Create a NEW property_bar. */
217 /****************************************************************************/
219 gl_ui_property_bar_new (void)
221 glUIPropertyBar *this;
223 gl_debug (DEBUG_PROPERTY_BAR, "START");
225 this = g_object_new (GL_TYPE_UI_PROPERTY_BAR, NULL);
227 gl_ui_property_bar_construct (this);
229 gl_debug (DEBUG_PROPERTY_BAR, "END");
231 return GTK_WIDGET (this);
235 /******************************************************************************/
236 /* Initialize property toolbar. */
237 /******************************************************************************/
239 gl_ui_property_bar_construct (glUIPropertyBar *this)
241 gchar *builder_filename;
243 static gchar *object_ids[] = { "property_toolbar",
244 "adjustment1", "adjustment2",
246 GError *error = NULL;
248 gl_debug (DEBUG_PROPERTY_BAR, "START");
250 this->priv->stop_signals = TRUE;
252 builder = gtk_builder_new ();
253 builder_filename = g_build_filename (GLABELS_DATA_DIR, "ui", "property-bar.ui", NULL);
254 gtk_builder_add_objects_from_file (builder, builder_filename, object_ids, &error);
255 g_free (builder_filename);
257 g_critical ("%s\n\ngLabels may not be installed correctly!", error->message);
258 g_error_free (error);
262 gl_builder_util_get_widgets (builder,
263 "property_toolbar", &this->priv->tool_bar,
264 "font_family_eventbox", &this->priv->font_family_eventbox,
265 "font_size_spin", &this->priv->font_size_spin,
266 "font_bold_toggle", &this->priv->font_bold_toggle,
267 "font_italic_toggle", &this->priv->font_italic_toggle,
268 "text_align_left_radio", &this->priv->text_align_left_radio,
269 "text_align_center_radio", &this->priv->text_align_center_radio,
270 "text_align_right_radio", &this->priv->text_align_right_radio,
271 "text_valign_top_radio", &this->priv->text_valign_top_radio,
272 "text_valign_vcenter_radio", &this->priv->text_valign_vcenter_radio,
273 "text_valign_bottom_radio", &this->priv->text_valign_bottom_radio,
274 "text_color_eventbox", &this->priv->text_color_eventbox,
275 "fill_color_eventbox", &this->priv->fill_color_eventbox,
276 "line_color_eventbox", &this->priv->line_color_eventbox,
277 "line_width_spin", &this->priv->line_width_spin,
280 gtk_container_add (GTK_CONTAINER (this), this->priv->tool_bar);
282 this->priv->font_family_combo =
283 gl_font_combo_new (gl_prefs_model_get_default_font_family (gl_prefs));
284 gtk_container_add (GTK_CONTAINER (this->priv->font_family_eventbox),
285 this->priv->font_family_combo);
287 this->priv->text_color_button =
288 gl_color_combo_button_new ("glabels-text",
290 GL_COLOR_TEXT_DEFAULT,
291 gl_prefs_model_get_default_text_color (gl_prefs));
292 gl_color_combo_button_set_relief (GL_COLOR_COMBO_BUTTON(this->priv->text_color_button),
294 gtk_container_add (GTK_CONTAINER (this->priv->text_color_eventbox),
295 this->priv->text_color_button);
297 this->priv->fill_color_button =
298 gl_color_combo_button_new ("glabels-bucket-fill",
301 gl_prefs_model_get_default_fill_color (gl_prefs));
302 gl_color_combo_button_set_relief (GL_COLOR_COMBO_BUTTON(this->priv->fill_color_button),
304 gtk_container_add (GTK_CONTAINER (this->priv->fill_color_eventbox),
305 this->priv->fill_color_button);
307 this->priv->line_color_button =
308 gl_color_combo_button_new ("glabels-pencil",
311 gl_prefs_model_get_default_line_color (gl_prefs));
312 gl_color_combo_button_set_relief (GL_COLOR_COMBO_BUTTON(this->priv->line_color_button),
314 gtk_container_add (GTK_CONTAINER (this->priv->line_color_eventbox),
315 this->priv->line_color_button);
317 /* Save reference to gui tree so we don't lose tooltips */
318 this->priv->builder = builder;
320 set_doc_items_sensitive (this, FALSE);
322 /* Font family entry widget */
323 g_signal_connect (G_OBJECT (this->priv->font_family_combo),
324 "changed", G_CALLBACK (font_family_changed_cb), this);
326 /* Font size entry widget */
327 gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->font_size_spin),
328 gl_prefs_model_get_default_font_size (gl_prefs));
330 g_signal_connect (G_OBJECT (this->priv->font_size_spin),
331 "changed", G_CALLBACK (font_size_changed_cb), this);
334 /* Bold and Italic toggles */
335 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_bold_toggle),
336 (gl_prefs_model_get_default_font_weight (gl_prefs) == PANGO_WEIGHT_BOLD));
337 g_signal_connect (G_OBJECT (this->priv->font_bold_toggle),
338 "toggled", G_CALLBACK (font_bold_toggled_cb), this);
339 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_italic_toggle),
340 gl_prefs_model_get_default_font_italic_flag (gl_prefs));
341 g_signal_connect (G_OBJECT (this->priv->font_italic_toggle),
342 "toggled", G_CALLBACK (font_italic_toggled_cb), this);
345 /* Text alignment radio group */
346 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio),
347 (gl_prefs_model_get_default_text_alignment (gl_prefs) == PANGO_ALIGN_LEFT));
348 g_signal_connect (G_OBJECT (this->priv->text_align_left_radio),
349 "toggled", G_CALLBACK (text_align_toggled_cb), this);
350 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio),
351 (gl_prefs_model_get_default_text_alignment (gl_prefs) == PANGO_ALIGN_CENTER));
352 g_signal_connect (G_OBJECT (this->priv->text_align_center_radio),
353 "toggled", G_CALLBACK (text_align_toggled_cb), this);
354 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
355 (gl_prefs_model_get_default_text_alignment (gl_prefs) == PANGO_ALIGN_RIGHT));
356 g_signal_connect (G_OBJECT (this->priv->text_align_right_radio),
357 "toggled", G_CALLBACK (text_align_toggled_cb), this);
359 /* Text vertical alignment radio group */
360 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_top_radio), TRUE);
361 g_signal_connect (G_OBJECT (this->priv->text_valign_top_radio),
362 "toggled", G_CALLBACK (text_valign_toggled_cb), this);
363 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_vcenter_radio), FALSE);
364 g_signal_connect (G_OBJECT (this->priv->text_valign_vcenter_radio),
365 "toggled", G_CALLBACK (text_valign_toggled_cb), this);
366 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_bottom_radio), FALSE);
367 g_signal_connect (G_OBJECT (this->priv->text_valign_bottom_radio),
368 "toggled", G_CALLBACK (text_valign_toggled_cb), this);
370 /* Text color widget */
371 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->text_color_button),
372 gl_prefs_model_get_default_text_color (gl_prefs));
373 g_signal_connect (G_OBJECT (this->priv->text_color_button),
375 G_CALLBACK (text_color_changed_cb), this);
377 /* Fill color widget */
378 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->fill_color_button),
379 gl_prefs_model_get_default_fill_color (gl_prefs));
380 g_signal_connect (G_OBJECT (this->priv->fill_color_button),
382 G_CALLBACK (fill_color_changed_cb), this);
384 /* Line color widget */
385 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->line_color_button),
386 gl_prefs_model_get_default_line_color (gl_prefs));
387 g_signal_connect (G_OBJECT (this->priv->line_color_button),
389 G_CALLBACK (line_color_changed_cb), this);
391 /* Line width entry widget */
392 g_signal_connect (G_OBJECT (this->priv->line_width_spin),
394 G_CALLBACK (line_width_changed_cb), this);
396 this->priv->stop_signals = FALSE;
398 gl_debug (DEBUG_PROPERTY_BAR, "END");
402 /****************************************************************************/
403 /* Fill widgets with default values. */
404 /****************************************************************************/
406 reset_to_default_properties (glLabel *label,
407 glUIPropertyBar *this)
411 family = gl_label_get_default_font_family (label);
412 gl_font_combo_set_family (GL_FONT_COMBO (this->priv->font_family_combo), family);
415 gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->font_size_spin),
416 gl_label_get_default_font_size (label));
418 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_bold_toggle),
419 (gl_label_get_default_font_weight (label) == PANGO_WEIGHT_BOLD));
420 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_italic_toggle),
421 gl_label_get_default_font_italic_flag (label));
423 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio),
424 (gl_label_get_default_text_alignment (label) == PANGO_ALIGN_LEFT));
425 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio),
426 (gl_label_get_default_text_alignment (label) == PANGO_ALIGN_CENTER));
427 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
428 (gl_label_get_default_text_alignment (label) == PANGO_ALIGN_RIGHT));
430 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_top_radio),
431 (gl_label_get_default_text_valignment (label) == GL_VALIGN_TOP));
432 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_vcenter_radio),
433 (gl_label_get_default_text_valignment (label) == GL_VALIGN_VCENTER));
434 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_bottom_radio),
435 (gl_label_get_default_text_valignment (label) == GL_VALIGN_BOTTOM));
437 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON(this->priv->text_color_button),
438 gl_label_get_default_text_color (label));
440 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON(this->priv->fill_color_button),
441 gl_label_get_default_fill_color (label));
443 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON(this->priv->line_color_button),
444 gl_label_get_default_line_color (label));
446 gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->line_width_spin),
447 gl_label_get_default_line_width (label));
451 /****************************************************************************/
452 /* Set label associated with property_bar. */
453 /****************************************************************************/
455 gl_ui_property_bar_set_label (glUIPropertyBar *this,
458 gl_debug (DEBUG_PROPERTY_BAR, "START");
460 g_return_if_fail (label && GL_IS_LABEL (label));
462 set_doc_items_sensitive (this, TRUE);
464 reset_to_default_properties (label, this);
466 this->priv->label = GL_LABEL (g_object_ref (G_OBJECT (label)));
468 g_signal_connect_swapped (G_OBJECT(label), "selection_changed",
469 G_CALLBACK(selection_changed_cb), this);
471 g_signal_connect_swapped (G_OBJECT(label), "changed",
472 G_CALLBACK(selection_changed_cb), this);
474 gl_debug (DEBUG_PROPERTY_BAR, "END");
478 /*---------------------------------------------------------------------------*/
479 /* PRIVATE. Label "selection state changed" callback. */
480 /*---------------------------------------------------------------------------*/
482 update_text_properties (glLabel *label,
483 glUIPropertyBar *this)
485 gboolean can_text, is_first_object;
486 gboolean is_same_font_family, is_same_font_size;
487 gboolean is_same_text_color, is_same_is_italic;
488 gboolean is_same_is_bold, is_same_align, is_same_valign;
489 GList *selection_list;
491 glLabelObject *object;
492 gchar *selection_font_family, *font_family;
493 gdouble selection_font_size, font_size;
494 guint selection_text_color, text_color;
495 glColorNode *text_color_node;
496 gboolean selection_is_italic, is_italic;
497 gboolean selection_is_bold, is_bold;
498 PangoAlignment selection_align, align;
499 glValignment selection_valign, valign;
501 can_text = gl_label_can_selection_text (label);
502 set_text_items_sensitive (this, 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 selection_list = gl_label_get_selection_list (label);
524 for (p = selection_list; p != NULL; p = p->next)
527 object = GL_LABEL_OBJECT (p->data);
528 if (!gl_label_object_can_text (object))
531 font_family = gl_label_object_get_font_family (object);
532 if (font_family != NULL)
534 if (selection_font_family == NULL)
536 selection_font_family = g_strdup (font_family);
540 if (strcmp (font_family, selection_font_family) != 0)
542 is_same_font_family = FALSE;
545 g_free (font_family);
548 font_size = gl_label_object_get_font_size (object);
550 text_color_node = gl_label_object_get_text_color (object);
551 if (text_color_node->field_flag)
553 /* If a merge field is set we use the default color for merged color*/
554 text_color = GL_COLOR_MERGE_DEFAULT;
559 text_color = text_color_node->color;
561 gl_color_node_free (&text_color_node);
563 is_italic = gl_label_object_get_font_italic_flag (object);
564 is_bold = gl_label_object_get_font_weight (object) == PANGO_WEIGHT_BOLD;
565 align = gl_label_object_get_text_alignment (object);
566 valign = gl_label_object_get_text_valignment (object);
570 selection_font_size = font_size;
571 selection_text_color = text_color;
572 selection_is_italic = is_italic;
573 selection_is_bold = is_bold;
574 selection_align = align;
575 selection_valign = valign;
579 if (font_size != selection_font_size)
580 is_same_font_size = FALSE;
581 if (text_color != selection_text_color)
582 is_same_text_color = FALSE;
583 if (is_italic != selection_is_italic)
584 is_same_is_italic = FALSE;
585 if (is_bold != selection_is_bold)
586 is_same_is_bold = FALSE;
587 if (align != selection_align)
588 is_same_align = FALSE;
589 if (valign != selection_valign)
590 is_same_valign = FALSE;
592 is_first_object = FALSE;
595 g_list_free (selection_list);
597 if (is_same_font_family && (selection_font_family != NULL))
598 gl_debug (DEBUG_PROPERTY_BAR, "same font family = %s",
599 selection_font_family);
600 gl_font_combo_set_family (GL_FONT_COMBO (this->priv->font_family_combo),
601 is_same_font_family?selection_font_family:"");
602 g_free (selection_font_family);
604 if (is_same_font_size)
606 gl_debug (DEBUG_PROPERTY_BAR, "same font size = %g",
607 selection_font_size);
608 gtk_spin_button_set_value (GTK_SPIN_BUTTON (this->priv->font_size_spin),
609 selection_font_size);
613 gtk_entry_set_text (GTK_ENTRY (this->priv->font_size_spin), "");
616 if (is_same_text_color)
618 gl_debug (DEBUG_PROPERTY_BAR, "same text color = %08x", selection_text_color);
619 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->text_color_button),
620 selection_text_color);
623 if (is_same_is_italic)
625 gl_debug (DEBUG_PROPERTY_BAR, "same italic flag = %d",
626 selection_is_italic);
628 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_italic_toggle),
629 selection_is_italic && is_same_is_italic);
633 gl_debug (DEBUG_PROPERTY_BAR, "same bold flag = %d",
636 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_bold_toggle),
637 selection_is_bold && is_same_is_bold);
640 gl_debug (DEBUG_PROPERTY_BAR, "same align");
641 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio),
642 (selection_align == PANGO_ALIGN_LEFT) &&
644 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio),
645 (selection_align == PANGO_ALIGN_CENTER) &&
647 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
648 (selection_align == PANGO_ALIGN_RIGHT) &&
652 gl_debug (DEBUG_PROPERTY_BAR, "same valign");
653 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_top_radio),
654 (selection_valign == GL_VALIGN_TOP) &&
656 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_vcenter_radio),
657 (selection_valign == GL_VALIGN_VCENTER) &&
659 gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_bottom_radio),
660 (selection_valign == GL_VALIGN_BOTTOM) &&
666 update_fill_color (glLabel *label,
667 glUIPropertyBar *this)
669 gboolean can, is_first_object;
670 gboolean is_same_fill_color;
671 GList *selection_list;
673 glLabelObject *object;
674 guint selection_fill_color, fill_color;
675 glColorNode *fill_color_node;
677 can = gl_label_can_selection_fill (label);
678 set_fill_items_sensitive (this, can);
683 is_same_fill_color = TRUE;
684 is_first_object = TRUE;
685 selection_fill_color = 0;
687 selection_list = gl_label_get_selection_list (label);
689 for (p = selection_list; p != NULL; p = p->next)
692 object = GL_LABEL_OBJECT (p->data);
693 if (!gl_label_object_can_fill (object))
696 fill_color_node = gl_label_object_get_fill_color (object);
697 if (fill_color_node->field_flag)
699 /* If a merge field is set we use the default color for merged color*/
700 fill_color = GL_COLOR_FILL_MERGE_DEFAULT;
705 fill_color = fill_color_node->color;
707 gl_color_node_free (&fill_color_node);
711 selection_fill_color = fill_color;
715 if (fill_color != selection_fill_color)
717 is_same_fill_color = FALSE;
720 is_first_object = FALSE;
723 g_list_free (selection_list);
725 if (is_same_fill_color)
727 gl_debug (DEBUG_PROPERTY_BAR, "same fill color = %08x", selection_fill_color);
728 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->fill_color_button),
729 selection_fill_color);
735 update_line_color (glLabel *label,
736 glUIPropertyBar *this)
738 gboolean can, is_first_object;
739 gboolean is_same_line_color;
740 GList *selection_list;
742 glLabelObject *object;
743 guint selection_line_color, line_color;
744 glColorNode *line_color_node;
746 can = gl_label_can_selection_line_color (label);
747 set_line_color_items_sensitive (this, can);
752 is_same_line_color = TRUE;
753 is_first_object = TRUE;
754 selection_line_color = 0;
756 selection_list = gl_label_get_selection_list (label);
758 for (p = selection_list; p != NULL; p = p->next)
761 object = GL_LABEL_OBJECT (p->data);
762 if (!gl_label_object_can_line_color (object))
765 line_color_node = gl_label_object_get_line_color (object);
766 if (line_color_node->field_flag)
768 /* If a merge field is set we use the default color for merged color*/
769 line_color = GL_COLOR_MERGE_DEFAULT;
774 line_color = line_color_node->color;
776 gl_color_node_free (&line_color_node);
780 selection_line_color = line_color;
784 if (line_color != selection_line_color)
786 is_same_line_color = FALSE;
789 is_first_object = FALSE;
792 g_list_free (selection_list);
794 if (is_same_line_color)
796 gl_debug (DEBUG_PROPERTY_BAR, "same line color = %08x", selection_line_color);
797 gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->line_color_button),
798 selection_line_color);
804 update_line_width (glLabel *label,
805 glUIPropertyBar *this)
807 gboolean can, is_first_object;
808 gboolean is_same_line_width;
809 GList *selection_list;
811 glLabelObject *object;
812 gdouble selection_line_width, line_width;
814 can = gl_label_can_selection_line_width (label);
815 set_line_width_items_sensitive (this, can);
820 is_same_line_width = TRUE;
821 is_first_object = TRUE;
822 selection_line_width = 0;
824 selection_list = gl_label_get_selection_list (label);
826 for (p = selection_list; p != NULL; p = p->next)
829 object = GL_LABEL_OBJECT (p->data);
830 if (!gl_label_object_can_line_width (object))
833 line_width = gl_label_object_get_line_width (object);
837 selection_line_width = line_width;
841 if (line_width != selection_line_width)
843 is_same_line_width = FALSE;
846 is_first_object = FALSE;
849 g_list_free (selection_list);
851 if (is_same_line_width)
853 gl_debug (DEBUG_PROPERTY_BAR, "same line width = %g", selection_line_width);
854 gtk_spin_button_set_value (GTK_SPIN_BUTTON (this->priv->line_width_spin),
855 selection_line_width);
859 gtk_entry_set_text (GTK_ENTRY (this->priv->line_width_spin), "");
865 selection_changed_cb (glUIPropertyBar *this,
868 g_return_if_fail (label && GL_IS_LABEL (label));
869 g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
871 if (this->priv->stop_signals) return;
872 this->priv->stop_signals = TRUE;
874 gl_debug (DEBUG_PROPERTY_BAR, "START");
876 if (gl_label_is_selection_empty (label))
878 /* No selection: make all controls active. */
879 reset_to_default_properties (label, this);
880 set_doc_items_sensitive (this, TRUE);
884 update_text_properties (label, this);
885 update_fill_color (label, this);
886 update_line_color (label, this);
887 update_line_width (label, this);
890 gl_debug (DEBUG_PROPERTY_BAR, "END");
892 this->priv->stop_signals = FALSE;
896 /*--------------------------------------------------------------------------*/
897 /* PRIVATE. Font family entry changed. */
898 /*--------------------------------------------------------------------------*/
900 font_family_changed_cb (GtkComboBox *combo,
901 glUIPropertyBar *this)
905 if (this->priv->stop_signals) return;
906 this->priv->stop_signals = TRUE;
908 gl_debug (DEBUG_PROPERTY_BAR, "START");
910 font_family = gl_font_combo_get_family (GL_FONT_COMBO (combo));
911 if ( *font_family != '\0' )
913 gl_label_set_selection_font_family (this->priv->label, font_family);
914 gl_label_set_default_font_family (this->priv->label, font_family);
916 g_free (font_family);
918 gl_debug (DEBUG_PROPERTY_BAR, "END");
920 this->priv->stop_signals = FALSE;
924 /*--------------------------------------------------------------------------*/
925 /* PRIVATE. Font size spin button changed. */
926 /*--------------------------------------------------------------------------*/
928 font_size_changed_cb (GtkSpinButton *spin,
929 glUIPropertyBar *this)
933 if (this->priv->stop_signals) return;
934 this->priv->stop_signals = TRUE;
936 gl_debug (DEBUG_PROPERTY_BAR, "START");
938 font_size = gtk_spin_button_get_value (spin);
940 gl_label_set_selection_font_size (this->priv->label,
942 gl_label_set_default_font_size (this->priv->label,
945 gl_debug (DEBUG_PROPERTY_BAR, "END");
947 this->priv->stop_signals = FALSE;
951 /*--------------------------------------------------------------------------*/
952 /* PRIVATE. Text color combo changed. */
953 /*--------------------------------------------------------------------------*/
955 text_color_changed_cb (glColorComboButton *cc,
958 glUIPropertyBar *this)
960 glColorNode *text_color_node;
962 g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
964 if (this->priv->stop_signals) return;
965 this->priv->stop_signals = TRUE;
967 gl_debug (DEBUG_PROPERTY_BAR, "START");
969 text_color_node = gl_color_node_new_default ();
970 text_color_node->color = color;
972 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
977 text_color_node->color = gl_prefs_model_get_default_text_color (gl_prefs);
978 gl_label_set_selection_text_color (this->priv->label,
980 gl_label_set_default_text_color (this->priv->label,
981 text_color_node->color);
985 gl_label_set_selection_text_color (this->priv->label,
987 gl_label_set_default_text_color (this->priv->label,
988 text_color_node->color);
991 gl_color_node_free (&text_color_node);
993 gl_debug (DEBUG_PROPERTY_BAR, "END");
995 this->priv->stop_signals = FALSE;
999 /*--------------------------------------------------------------------------*/
1000 /* PRIVATE. Fill color combo changed. */
1001 /*--------------------------------------------------------------------------*/
1003 fill_color_changed_cb (glColorComboButton *cc,
1005 gboolean is_default,
1006 glUIPropertyBar *this)
1008 glColorNode *fill_color_node;
1010 g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
1012 if (this->priv->stop_signals) return;
1013 this->priv->stop_signals = TRUE;
1015 gl_debug (DEBUG_PROPERTY_BAR, "START");
1017 fill_color_node = gl_color_node_new_default ();
1019 fill_color_node->color = color;
1021 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
1027 fill_color_node->color = GL_COLOR_NONE;
1028 gl_label_set_selection_fill_color (this->priv->label,
1030 gl_label_set_default_fill_color (this->priv->label,
1031 fill_color_node->color);
1035 gl_label_set_selection_fill_color (this->priv->label,
1037 gl_label_set_default_fill_color (this->priv->label,
1038 fill_color_node->color);
1040 gl_color_node_free (&fill_color_node);
1042 gl_debug (DEBUG_PROPERTY_BAR, "END");
1044 this->priv->stop_signals = FALSE;
1048 /*--------------------------------------------------------------------------*/
1049 /* PRIVATE. Line color combo changed. */
1050 /*--------------------------------------------------------------------------*/
1052 line_color_changed_cb (glColorComboButton *cc,
1054 gboolean is_default,
1055 glUIPropertyBar *this)
1057 glColorNode *line_color_node;
1059 g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
1061 if (this->priv->stop_signals) return;
1062 this->priv->stop_signals = TRUE;
1064 gl_debug (DEBUG_PROPERTY_BAR, "START");
1066 line_color_node = gl_color_node_new_default ();
1067 line_color_node->color = color;
1069 gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
1074 line_color_node->color = GL_COLOR_NONE;
1075 gl_label_set_selection_line_color (this->priv->label,
1077 gl_label_set_default_line_color (this->priv->label,
1078 line_color_node->color);
1082 gl_label_set_selection_line_color (this->priv->label,
1084 gl_label_set_default_line_color (this->priv->label,
1085 line_color_node->color);
1087 gl_color_node_free (&line_color_node);
1089 gl_debug (DEBUG_PROPERTY_BAR, "END");
1091 this->priv->stop_signals = FALSE;
1095 /*--------------------------------------------------------------------------*/
1096 /* PRIVATE. Line width spin button changed. */
1097 /*--------------------------------------------------------------------------*/
1099 line_width_changed_cb (GtkSpinButton *spin,
1100 glUIPropertyBar *this)
1104 if (this->priv->stop_signals) return;
1105 this->priv->stop_signals = TRUE;
1107 gl_debug (DEBUG_PROPERTY_BAR, "START");
1109 if (this->priv->label)
1111 line_width = gtk_spin_button_get_value (spin);
1113 gl_label_set_selection_line_width (this->priv->label,
1115 gl_label_set_default_line_width (this->priv->label,
1119 gl_debug (DEBUG_PROPERTY_BAR, "END");
1121 this->priv->stop_signals = FALSE;
1125 /*---------------------------------------------------------------------------*/
1126 /* PRIVATE. Font bold toggled callback. */
1127 /*---------------------------------------------------------------------------*/
1129 font_bold_toggled_cb (GtkToggleToolButton *toggle,
1130 glUIPropertyBar *this)
1136 if (this->priv->stop_signals) return;
1137 this->priv->stop_signals = TRUE;
1139 gl_debug (DEBUG_PROPERTY_BAR, "START");
1141 state = gtk_toggle_tool_button_get_active (toggle);
1143 weight = state ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
1145 gl_label_set_selection_font_weight (this->priv->label, weight);
1146 gl_label_set_default_font_weight (this->priv->label, weight);
1148 gl_debug (DEBUG_PROPERTY_BAR, "END");
1150 this->priv->stop_signals = FALSE;
1154 /*---------------------------------------------------------------------------*/
1155 /* PRIVATE. Font italic toggled callback. */
1156 /*---------------------------------------------------------------------------*/
1158 font_italic_toggled_cb (GtkToggleToolButton *toggle,
1159 glUIPropertyBar *this)
1163 if (this->priv->stop_signals) return;
1164 this->priv->stop_signals = TRUE;
1166 gl_debug (DEBUG_PROPERTY_BAR, "START");
1168 state = gtk_toggle_tool_button_get_active (toggle);
1170 gl_label_set_selection_font_italic_flag (this->priv->label, state);
1171 gl_label_set_default_font_italic_flag (this->priv->label, state);
1173 gl_debug (DEBUG_PROPERTY_BAR, "END");
1175 this->priv->stop_signals = FALSE;
1179 /*---------------------------------------------------------------------------*/
1180 /* PRIVATE. Text align toggled callback. */
1181 /*---------------------------------------------------------------------------*/
1183 text_align_toggled_cb (GtkToggleToolButton *toggle,
1184 glUIPropertyBar *this)
1186 if (this->priv->stop_signals) return;
1187 this->priv->stop_signals = TRUE;
1189 gl_debug (DEBUG_PROPERTY_BAR, "START");
1191 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio)))
1193 gl_label_set_selection_text_alignment (this->priv->label,
1195 gl_label_set_default_text_alignment (this->priv->label,
1199 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio)))
1201 gl_label_set_selection_text_alignment (this->priv->label,
1202 PANGO_ALIGN_CENTER);
1203 gl_label_set_default_text_alignment (this->priv->label,
1204 PANGO_ALIGN_CENTER);
1207 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio)))
1209 gl_label_set_selection_text_alignment (this->priv->label,
1211 gl_label_set_default_text_alignment (this->priv->label,
1215 gl_debug (DEBUG_PROPERTY_BAR, "END");
1217 this->priv->stop_signals = FALSE;
1221 /*---------------------------------------------------------------------------*/
1222 /* PRIVATE. Text vertical align toggled callback. */
1223 /*---------------------------------------------------------------------------*/
1225 text_valign_toggled_cb (GtkToggleToolButton *toggle,
1226 glUIPropertyBar *this)
1228 if (this->priv->stop_signals) return;
1229 this->priv->stop_signals = TRUE;
1231 gl_debug (DEBUG_PROPERTY_BAR, "START");
1233 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_top_radio)))
1235 gl_label_set_selection_text_valignment (this->priv->label,
1237 gl_label_set_default_text_valignment (this->priv->label,
1241 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_vcenter_radio)))
1243 gl_label_set_selection_text_valignment (this->priv->label,
1245 gl_label_set_default_text_valignment (this->priv->label,
1249 if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_valign_bottom_radio)))
1251 gl_label_set_selection_text_valignment (this->priv->label,
1253 gl_label_set_default_text_valignment (this->priv->label,
1257 gl_debug (DEBUG_PROPERTY_BAR, "END");
1259 this->priv->stop_signals = FALSE;
1263 /*---------------------------------------------------------------------------*/
1264 /* PRIVATE. Set sensitivity of doc controls. */
1265 /*---------------------------------------------------------------------------*/
1267 set_doc_items_sensitive (glUIPropertyBar *this,
1270 gtk_widget_set_sensitive (this->priv->font_family_combo, state);
1271 gtk_widget_set_sensitive (this->priv->font_size_spin, state);
1272 gtk_widget_set_sensitive (this->priv->font_bold_toggle, state);
1273 gtk_widget_set_sensitive (this->priv->font_italic_toggle, state);
1274 gtk_widget_set_sensitive (this->priv->text_align_left_radio, state);
1275 gtk_widget_set_sensitive (this->priv->text_align_center_radio, state);
1276 gtk_widget_set_sensitive (this->priv->text_align_right_radio, state);
1277 gtk_widget_set_sensitive (this->priv->text_valign_top_radio, state);
1278 gtk_widget_set_sensitive (this->priv->text_valign_vcenter_radio, state);
1279 gtk_widget_set_sensitive (this->priv->text_valign_bottom_radio, state);
1280 gtk_widget_set_sensitive (this->priv->text_color_button, state);
1281 gtk_widget_set_sensitive (this->priv->fill_color_button, state);
1282 gtk_widget_set_sensitive (this->priv->line_color_button, state);
1283 gtk_widget_set_sensitive (this->priv->line_width_spin, state);
1287 /*---------------------------------------------------------------------------*/
1288 /* PRIVATE. Set sensitivity of text related controls. */
1289 /*---------------------------------------------------------------------------*/
1291 set_text_items_sensitive (glUIPropertyBar *this,
1294 gtk_widget_set_sensitive (this->priv->font_family_combo, state);
1295 gtk_widget_set_sensitive (this->priv->font_size_spin, state);
1296 gtk_widget_set_sensitive (this->priv->font_bold_toggle, state);
1297 gtk_widget_set_sensitive (this->priv->font_italic_toggle, state);
1298 gtk_widget_set_sensitive (this->priv->text_align_left_radio, state);
1299 gtk_widget_set_sensitive (this->priv->text_align_center_radio, state);
1300 gtk_widget_set_sensitive (this->priv->text_align_right_radio, state);
1301 gtk_widget_set_sensitive (this->priv->text_valign_top_radio, state);
1302 gtk_widget_set_sensitive (this->priv->text_valign_vcenter_radio, state);
1303 gtk_widget_set_sensitive (this->priv->text_valign_bottom_radio, state);
1304 gtk_widget_set_sensitive (this->priv->text_color_button, state);
1308 /*---------------------------------------------------------------------------*/
1309 /* PRIVATE. Set sensitivity of fill related controls. */
1310 /*---------------------------------------------------------------------------*/
1312 set_fill_items_sensitive (glUIPropertyBar *this,
1315 gtk_widget_set_sensitive (this->priv->fill_color_button, state);
1319 /*---------------------------------------------------------------------------*/
1320 /* PRIVATE. Set sensitivity of line color related controls. */
1321 /*---------------------------------------------------------------------------*/
1323 set_line_color_items_sensitive (glUIPropertyBar *this,
1326 gtk_widget_set_sensitive (this->priv->line_color_button, state);
1330 /*---------------------------------------------------------------------------*/
1331 /* PRIVATE. Set sensitivity of line width related controls. */
1332 /*---------------------------------------------------------------------------*/
1334 set_line_width_items_sensitive (glUIPropertyBar *this,
1337 gtk_widget_set_sensitive (this->priv->line_width_spin, state);
1343 * Local Variables: -- emacs
1345 * c-basic-offset: 8 -- emacs
1346 * tab-width: 8 -- emacs
1347 * indent-tabs-mode: nil -- emacs