]> git.sur5r.net Git - glabels/blob - glabels2/src/ui-property-bar.c
2a5f48a6879e600e51afe61f55cda003b08a8207
[glabels] / glabels2 / src / ui-property-bar.c
1 /*
2  *  ui-property-bar.c
3  *  Copyright (C) 2003-2009  Jim Evins <evins@snaught.com>.
4  *
5  *  This file is part of gLabels.
6  *
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.
11  *
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.
16  *
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/>.
19  */
20
21 #include <config.h>
22
23 #include "ui-property-bar.h"
24
25 #include <glib/gi18n.h>
26 #include <gtk/gtkbuilder.h>
27 #include <gtk/gtkcombobox.h>
28 #include <gtk/gtkspinbutton.h>
29 #include <gtk/gtktoolbar.h>
30 #include <gtk/gtktoggletoolbutton.h>
31 #include <string.h>
32
33 #include "util.h"
34 #include "color-combo.h"
35 #include "stock-pixmaps/stockpixbufs.h"
36 #include "prefs.h"
37 #include "color.h"
38
39 #include "debug.h"
40
41
42 /*===========================================================================*/
43 /* Private macros and constants.                                             */
44 /*===========================================================================*/
45
46
47 /*===========================================================================*/
48 /* Private data types                                                        */
49 /*===========================================================================*/
50
51 struct _glUIPropertyBarPrivate {
52
53         glView     *view;
54
55         GtkBuilder *builder;
56
57         GtkWidget  *tool_bar;
58
59         /* Font selection */
60         GtkWidget  *font_family_combo;
61         GtkWidget  *font_size_spin;
62         GtkWidget  *font_bold_toggle;
63         GtkWidget  *font_italic_toggle;
64
65         /* Text alignemnt radios */
66         GtkWidget  *text_align_left_radio;
67         GtkWidget  *text_align_center_radio;
68         GtkWidget  *text_align_right_radio;
69
70         /* Color combos */
71         GtkWidget  *text_color_eventbox;
72         GtkWidget  *text_color_combo;
73         GtkWidget  *fill_color_combo;
74         GtkWidget  *fill_color_eventbox;
75         GtkWidget  *line_color_combo;
76         GtkWidget  *line_color_eventbox;
77
78         /* Line width */
79         GtkWidget  *line_width_spin;
80
81         /* Prevent recursion */
82         gboolean    stop_signals;
83 };
84
85
86 /*===========================================================================*/
87 /* Private globals                                                           */
88 /*===========================================================================*/
89
90
91 /*===========================================================================*/
92 /* Local function prototypes                                                 */
93 /*===========================================================================*/
94
95 static void     gl_ui_property_bar_finalize      (GObject              *object);
96
97 static void     gl_ui_property_bar_construct     (glUIPropertyBar      *this);
98
99 static void     selection_changed_cb             (glUIPropertyBar      *this);
100
101 static void     font_family_changed_cb           (GtkComboBox          *combo,
102                                                   glUIPropertyBar      *this);
103
104 static void     font_size_changed_cb             (GtkSpinButton        *spin,
105                                                   glUIPropertyBar      *this);
106
107 static void     text_color_changed_cb            (glColorCombo         *cc,
108                                                   guint                 color,
109                                                   gboolean              is_default,
110                                                   glUIPropertyBar      *this);
111
112 static void     fill_color_changed_cb            (glColorCombo         *cc,
113                                                   guint                 color,
114                                                   gboolean              is_default,
115                                                   glUIPropertyBar      *this);
116
117 static void     line_color_changed_cb            (glColorCombo         *cc,
118                                                   guint                 color,
119                                                   gboolean              is_default,
120                                                   glUIPropertyBar      *this);
121
122 static void     line_width_changed_cb            (GtkSpinButton        *spin,
123                                                   glUIPropertyBar      *this);
124
125 static void     font_bold_toggled_cb             (GtkToggleToolButton  *toggle,
126                                                   glUIPropertyBar      *this);
127                                                   
128 static void     font_italic_toggled_cb           (GtkToggleToolButton  *toggle,
129                                                   glUIPropertyBar      *this);
130                                                   
131 static void     text_align_toggled_cb            (GtkToggleToolButton  *toggle,
132                                                   glUIPropertyBar      *this);
133                                                   
134 static void     set_doc_items_sensitive          (glUIPropertyBar      *this,
135                                                   gboolean              state);
136
137 static void     set_text_items_sensitive         (glUIPropertyBar      *this,
138                                                   gboolean              state);
139
140 static void     set_fill_items_sensitive         (glUIPropertyBar      *this,
141                                                   gboolean              state);
142
143 static void     set_line_color_items_sensitive   (glUIPropertyBar      *this,
144                                                   gboolean              state);
145
146 static void     set_line_width_items_sensitive   (glUIPropertyBar      *this,
147                                                   gboolean              state);
148
149
150 /****************************************************************************/
151 /* Boilerplate Object stuff.                                                */
152 /****************************************************************************/
153 G_DEFINE_TYPE (glUIPropertyBar, gl_ui_property_bar, GTK_TYPE_HBOX);
154
155
156 static void
157 gl_ui_property_bar_class_init (glUIPropertyBarClass *class)
158 {
159         GObjectClass   *object_class     = G_OBJECT_CLASS (class);
160
161         gl_debug (DEBUG_PROPERTY_BAR, "START");
162
163         gl_ui_property_bar_parent_class = g_type_class_peek_parent (class);
164
165         object_class->finalize = gl_ui_property_bar_finalize;
166
167         gl_debug (DEBUG_PROPERTY_BAR, "END");
168 }
169
170
171 static void
172 gl_ui_property_bar_init (glUIPropertyBar *this)
173 {
174         gl_debug (DEBUG_PROPERTY_BAR, "START");
175
176         this->priv = g_new0 (glUIPropertyBarPrivate, 1);
177
178         gl_debug (DEBUG_PROPERTY_BAR, "END");
179 }
180
181
182 static void
183 gl_ui_property_bar_finalize (GObject *object)
184 {
185         glUIPropertyBar *this = GL_UI_PROPERTY_BAR (object);
186
187         gl_debug (DEBUG_PROPERTY_BAR, "START");
188
189         g_return_if_fail (object != NULL);
190         g_return_if_fail (GL_IS_UI_PROPERTY_BAR (object));
191
192         if (this->priv->view)
193         {
194                 g_object_unref (G_OBJECT(this->priv->view));
195         }
196         if (this->priv->builder)
197         {
198                 g_object_unref (G_OBJECT(this->priv->builder));
199         }
200         g_free (this->priv);
201
202         G_OBJECT_CLASS (gl_ui_property_bar_parent_class)->finalize (object);
203
204         gl_debug (DEBUG_PROPERTY_BAR, "END");
205 }
206
207
208 /****************************************************************************/
209 /* Create a NEW property_bar.                                               */
210 /****************************************************************************/
211 GtkWidget *
212 gl_ui_property_bar_new (void)
213 {
214         glUIPropertyBar *this;
215
216         gl_debug (DEBUG_PROPERTY_BAR, "START");
217
218         this = g_object_new (GL_TYPE_UI_PROPERTY_BAR, NULL);
219
220         gl_ui_property_bar_construct (this);
221
222         gl_debug (DEBUG_PROPERTY_BAR, "END");
223
224         return GTK_WIDGET (this);
225 }
226
227
228 /******************************************************************************/
229 /* Initialize property toolbar.                                               */
230 /******************************************************************************/
231 static void
232 gl_ui_property_bar_construct (glUIPropertyBar   *this)
233 {
234         GtkBuilder    *builder;
235         static gchar  *object_ids[] = { "property_toolbar",
236                                         "adjustment1", "adjustment2",
237                                         NULL };
238         GError        *error = NULL;
239         GList         *family_names = NULL;
240         GList         *family_node;
241         GdkPixbuf     *pixbuf = NULL;
242
243         gl_debug (DEBUG_PROPERTY_BAR, "START");
244
245         this->priv->stop_signals = TRUE;
246
247         builder = gtk_builder_new ();
248         gtk_builder_add_objects_from_file (builder,
249                                            GLABELS_BUILDER_DIR "property-bar.builder",
250                                            object_ids,
251                                            &error);
252         if (error) {
253                 g_critical ("%s\n\ngLabels may not be installed correctly!", error->message);
254                 g_error_free (error);
255                 return;
256         }
257
258         gl_util_get_builder_widgets (builder,
259                                      "property_toolbar",        &this->priv->tool_bar,
260                                      "font_family_combo",       &this->priv->font_family_combo,
261                                      "font_size_spin",          &this->priv->font_size_spin,
262                                      "font_bold_toggle",        &this->priv->font_bold_toggle,
263                                      "font_italic_toggle",      &this->priv->font_italic_toggle,
264                                      "text_align_left_radio",   &this->priv->text_align_left_radio,
265                                      "text_align_center_radio", &this->priv->text_align_center_radio,
266                                      "text_align_right_radio",  &this->priv->text_align_right_radio,
267                                      "text_color_eventbox",     &this->priv->text_color_eventbox,
268                                      "fill_color_eventbox",     &this->priv->fill_color_eventbox,
269                                      "line_color_eventbox",     &this->priv->line_color_eventbox,
270                                      "line_width_spin",         &this->priv->line_width_spin,
271                                      NULL);
272
273         gtk_container_add (GTK_CONTAINER (this), this->priv->tool_bar);
274
275         pixbuf = gdk_pixbuf_new_from_inline (-1, stock_text_24, FALSE, NULL);
276         this->priv->text_color_combo =
277                 gl_color_combo_new (pixbuf,
278                                     _("Default"),
279                                     GL_COLOR_TEXT_DEFAULT,
280                                     gl_prefs->default_text_color);
281         gl_color_combo_set_relief (GL_COLOR_COMBO(this->priv->text_color_combo),
282                                    GTK_RELIEF_NONE);
283         g_object_unref (G_OBJECT (pixbuf));
284         gtk_container_add (GTK_CONTAINER (this->priv->text_color_eventbox),
285                            this->priv->text_color_combo);
286
287         pixbuf = gdk_pixbuf_new_from_inline (-1, stock_bucket_fill_24, FALSE, NULL);
288         this->priv->fill_color_combo =
289                 gl_color_combo_new (pixbuf,
290                                     _("No Fill"),
291                                     GL_COLOR_NO_FILL,
292                                     gl_prefs->default_fill_color);
293         gl_color_combo_set_relief (GL_COLOR_COMBO(this->priv->fill_color_combo),
294                                    GTK_RELIEF_NONE);
295         g_object_unref (G_OBJECT (pixbuf));
296         gtk_container_add (GTK_CONTAINER (this->priv->fill_color_eventbox),
297                            this->priv->fill_color_combo);
298
299         pixbuf = gdk_pixbuf_new_from_inline (-1, stock_pencil_24, FALSE, NULL);
300         this->priv->line_color_combo =
301                 gl_color_combo_new (pixbuf,
302                                     _("No Line"),
303                                     GL_COLOR_NO_LINE,
304                                     gl_prefs->default_line_color);
305         gl_color_combo_set_relief (GL_COLOR_COMBO(this->priv->line_color_combo),
306                                    GTK_RELIEF_NONE);
307         g_object_unref (G_OBJECT (pixbuf));
308         gtk_container_add (GTK_CONTAINER (this->priv->line_color_eventbox),
309                            this->priv->line_color_combo);
310
311         /* Save reference to gui tree so we don't lose tooltips */
312         this->priv->builder = builder;
313
314         set_doc_items_sensitive (this, FALSE);
315
316         /* Font family entry widget */
317         gl_util_combo_box_add_text_model (GTK_COMBO_BOX (this->priv->font_family_combo));
318         family_names = gl_util_get_font_family_list ();
319         gl_util_combo_box_set_strings (GTK_COMBO_BOX (this->priv->font_family_combo),
320                                        family_names);
321         gtk_widget_set_size_request (this->priv->font_family_combo, 200, -1);
322
323         /* Make sure we have a valid font.  if not provide a good default. */
324         family_node = g_list_find_custom (family_names,
325                                           gl_prefs->default_font_family,
326                                           (GCompareFunc)g_utf8_collate);
327         if (family_node)
328         {
329                 gtk_combo_box_set_active (GTK_COMBO_BOX (this->priv->font_family_combo),
330                                           g_list_position (family_names,
331                                                            family_node));
332         }
333         else
334         {
335                 gtk_combo_box_set_active (GTK_COMBO_BOX (this->priv->font_family_combo), 0);
336         }
337
338         g_signal_connect (G_OBJECT (this->priv->font_family_combo),
339                           "changed", G_CALLBACK (font_family_changed_cb), this);
340
341         /* Font size entry widget */
342         gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->font_size_spin),
343                                    gl_prefs->default_font_size);
344
345         g_signal_connect (G_OBJECT (this->priv->font_size_spin),
346                           "changed", G_CALLBACK (font_size_changed_cb), this);
347
348
349         /* Bold and Italic toggles */
350         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_bold_toggle),
351                                            (gl_prefs->default_font_weight == PANGO_WEIGHT_BOLD));
352         g_signal_connect (G_OBJECT (this->priv->font_bold_toggle),
353                           "toggled", G_CALLBACK (font_bold_toggled_cb), this);
354         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_italic_toggle),
355                                            gl_prefs->default_font_italic_flag);
356         g_signal_connect (G_OBJECT (this->priv->font_italic_toggle),
357                           "toggled", G_CALLBACK (font_italic_toggled_cb), this);
358
359
360         /* Text alignment radio group */
361         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio),
362                                            (gl_prefs->default_text_alignment == PANGO_ALIGN_LEFT));
363         g_signal_connect (G_OBJECT (this->priv->text_align_left_radio),
364                           "toggled", G_CALLBACK (text_align_toggled_cb), this);
365         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio),
366                                            (gl_prefs->default_text_alignment == PANGO_ALIGN_CENTER));
367         g_signal_connect (G_OBJECT (this->priv->text_align_center_radio),
368                           "toggled", G_CALLBACK (text_align_toggled_cb), this);
369         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
370                                            (gl_prefs->default_text_alignment == PANGO_ALIGN_RIGHT));
371         g_signal_connect (G_OBJECT (this->priv->text_align_right_radio),
372                           "toggled", G_CALLBACK (text_align_toggled_cb), this);
373
374         /* Text color widget */
375         gl_color_combo_set_color (GL_COLOR_COMBO (this->priv->text_color_combo), gl_prefs->default_text_color);
376         g_signal_connect (G_OBJECT (this->priv->text_color_combo),
377                           "color_changed",
378                           G_CALLBACK (text_color_changed_cb), this);
379
380         /* Fill color widget */
381         gl_color_combo_set_color (GL_COLOR_COMBO (this->priv->fill_color_combo), gl_prefs->default_fill_color);
382         g_signal_connect (G_OBJECT (this->priv->fill_color_combo),
383                           "color_changed",
384                           G_CALLBACK (fill_color_changed_cb), this);
385
386         /* Line color widget */
387         gl_color_combo_set_color (GL_COLOR_COMBO (this->priv->line_color_combo), gl_prefs->default_line_color);
388         g_signal_connect (G_OBJECT (this->priv->line_color_combo),
389                           "color_changed",
390                           G_CALLBACK (line_color_changed_cb), this);
391
392         /* Line width entry widget */
393         g_signal_connect (G_OBJECT (this->priv->line_width_spin),
394                           "changed",
395                           G_CALLBACK (line_width_changed_cb), this);
396
397         this->priv->stop_signals = FALSE;
398
399         gl_debug (DEBUG_PROPERTY_BAR, "END");
400 }
401
402
403 /****************************************************************************/
404 /* Fill widgets with default values.                                        */
405 /****************************************************************************/
406 static void
407 reset_to_default_properties (glView *view,
408                              glUIPropertyBar *this)
409 {
410         GList     *family_names;
411         gchar     *good_font_family;
412
413         /* Make sure we have a valid font.  if not provide a good default. */
414         family_names = gl_util_get_font_family_list ();
415         if (g_list_find_custom (family_names,
416                                 view->default_font_family,
417                                 (GCompareFunc)g_utf8_collate))
418         {
419                 good_font_family = g_strdup (view->default_font_family);
420         }
421         else
422         {
423                 if (family_names != NULL)
424                 {
425                         good_font_family = g_strdup (family_names->data); /* 1st entry */
426                 }
427                 else
428                 {
429                         good_font_family = NULL;
430                 }
431         }
432         gl_util_combo_box_set_active_text (GTK_COMBO_BOX (this->priv->font_family_combo),
433                                            good_font_family);
434         g_free (good_font_family);
435
436         gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->font_size_spin),
437                                    view->default_font_size);
438
439         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_bold_toggle),
440                                            (view->default_font_weight == PANGO_WEIGHT_BOLD));
441         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_italic_toggle),
442                                            view->default_font_italic_flag);
443
444         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio),
445                                            (view->default_text_alignment == PANGO_ALIGN_LEFT));
446         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio),
447                                            (view->default_text_alignment == PANGO_ALIGN_CENTER));
448         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
449                                            (view->default_text_alignment == PANGO_ALIGN_RIGHT));
450
451         gl_color_combo_set_color (GL_COLOR_COMBO(this->priv->text_color_combo), view->default_text_color);
452
453         gl_color_combo_set_color (GL_COLOR_COMBO(this->priv->fill_color_combo), view->default_fill_color);
454
455         gl_color_combo_set_color (GL_COLOR_COMBO(this->priv->line_color_combo), view->default_line_color);
456
457         gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->line_width_spin),
458                                    view->default_line_width);
459 }
460
461
462 /****************************************************************************/
463 /* Set view associated with property_bar.                                   */
464 /****************************************************************************/
465 void
466 gl_ui_property_bar_set_view (glUIPropertyBar *this,
467                              glView          *view)
468 {
469         glLabel   *label;
470
471         gl_debug (DEBUG_PROPERTY_BAR, "START");
472
473         g_return_if_fail (view && GL_IS_VIEW (view));
474         label = view->label;
475         g_return_if_fail (label && GL_IS_LABEL (label));
476
477         set_doc_items_sensitive (this, TRUE);
478
479         this->priv->view = GL_VIEW (g_object_ref (G_OBJECT (view)));
480
481         reset_to_default_properties (view, this);
482
483         g_signal_connect_swapped (G_OBJECT(view), "selection_changed",
484                                   G_CALLBACK(selection_changed_cb), this);
485
486         g_signal_connect_swapped (G_OBJECT(view->label), "changed",
487                                   G_CALLBACK(selection_changed_cb), this);
488
489         gl_debug (DEBUG_PROPERTY_BAR, "END");
490 }
491
492
493 /*---------------------------------------------------------------------------*/
494 /* PRIVATE.  View "selection state changed" callback.                        */
495 /*---------------------------------------------------------------------------*/
496 static void
497 update_text_properties (glView *view,
498                         glUIPropertyBar *this)
499 {
500         gboolean        can_text, is_first_object;
501         gboolean        is_same_font_family, is_same_font_size;
502         gboolean        is_same_text_color, is_same_is_italic;
503         gboolean        is_same_is_bold, is_same_align;
504         GList          *p;
505         glLabelObject  *object;
506         gchar          *selection_font_family, *font_family;
507         gdouble         selection_font_size, font_size;
508         guint           selection_text_color, text_color;
509         glColorNode    *text_color_node;
510         gboolean        selection_is_italic, is_italic;
511         gboolean        selection_is_bold, is_bold;
512         PangoAlignment  selection_align, align;
513
514         can_text = gl_view_can_selection_text (view);
515         set_text_items_sensitive (this, can_text);
516
517         if (!can_text) 
518                 return;
519
520         is_same_is_italic =
521         is_same_is_bold =
522         is_same_align =
523         is_same_text_color =
524         is_same_font_size =
525         is_same_font_family = TRUE;
526         selection_font_family = NULL;
527         selection_font_size = -1;
528         selection_align = PANGO_ALIGN_LEFT;
529         selection_is_italic = TRUE;
530         selection_is_bold = TRUE;
531         selection_text_color = 0;
532         
533         is_first_object = TRUE;
534         
535         for (p = view->selected_object_list; p != NULL; p = p->next)
536         {
537
538                 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
539                 if (!gl_label_object_can_text (object)) 
540                         continue;
541
542                 font_family = gl_label_object_get_font_family (object);
543                 if (font_family != NULL)
544                 {
545                         if (selection_font_family == NULL)
546                         {
547                                 selection_font_family = g_strdup (font_family);
548                         }
549                         else 
550                         {
551                                 if (strcmp (font_family, selection_font_family) != 0)
552                                 {
553                                         is_same_font_family = FALSE;
554                                 }
555                         }
556                         g_free (font_family);
557                 }       
558
559                 font_size = gl_label_object_get_font_size (object);
560                 
561                 text_color_node = gl_label_object_get_text_color (object);
562                 if (text_color_node->field_flag)
563                 {
564                         /* If a merge field is set we use the default color for merged color*/
565                         text_color = GL_COLOR_MERGE_DEFAULT;
566                         
567                 }
568                 else
569                 {
570                         text_color = text_color_node->color;
571                 }
572                 gl_color_node_free (&text_color_node);
573                 
574                 is_italic = gl_label_object_get_font_italic_flag (object);
575                 is_bold = gl_label_object_get_font_weight (object) == PANGO_WEIGHT_BOLD;
576                 align = gl_label_object_get_text_alignment (object);
577
578                 if (is_first_object)
579                 {
580                         selection_font_size = font_size;
581                         selection_text_color = text_color;
582                         selection_is_italic = is_italic;
583                         selection_is_bold = is_bold;
584                         selection_align = align;
585                 }
586                 else
587                 {
588                         if (font_size != selection_font_size) 
589                                 is_same_font_size = FALSE;
590                         if (text_color != selection_text_color)
591                                 is_same_text_color = FALSE;
592                         if (is_italic != selection_is_italic)
593                                 is_same_is_italic = FALSE;
594                         if (is_bold != selection_is_bold)
595                                 is_same_is_bold = FALSE;
596                         if (align != selection_align)
597                                 is_same_align = FALSE;
598                 }
599                 is_first_object = FALSE;
600         }
601
602         if (is_same_font_family && (selection_font_family != NULL)) 
603                 gl_debug (DEBUG_PROPERTY_BAR, "same font family = %s", 
604                           selection_font_family);
605         gl_util_combo_box_set_active_text (GTK_COMBO_BOX (this->priv->font_family_combo),
606                                            is_same_font_family?selection_font_family:"");
607         g_free (selection_font_family);
608
609         if (is_same_font_size)
610         {
611                 gl_debug (DEBUG_PROPERTY_BAR, "same font size = %g", 
612                           selection_font_size);
613                 gtk_spin_button_set_value (GTK_SPIN_BUTTON (this->priv->font_size_spin),
614                                            selection_font_size);
615         }
616         else
617         {
618                 gtk_entry_set_text (GTK_ENTRY (this->priv->font_size_spin), "");
619         }
620
621         if (is_same_text_color)
622         {
623                 gl_debug (DEBUG_PROPERTY_BAR, "same text color = %08x", selection_text_color);
624                 gl_color_combo_set_color (GL_COLOR_COMBO (this->priv->text_color_combo),
625                                           selection_text_color);
626         }
627
628         if (is_same_is_italic)
629         {
630                 gl_debug (DEBUG_PROPERTY_BAR, "same italic flag = %d", 
631                           selection_is_italic);
632         }
633         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_italic_toggle),
634                                            selection_is_italic && is_same_is_italic);
635
636         if (is_same_is_bold)
637         {
638                 gl_debug (DEBUG_PROPERTY_BAR, "same bold flag = %d",
639                           selection_is_bold);
640         }
641         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->font_bold_toggle),
642                                            selection_is_bold && is_same_is_bold);
643
644         if (is_same_align) 
645                 gl_debug (DEBUG_PROPERTY_BAR, "same align");
646         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio),
647                                            (selection_align == PANGO_ALIGN_LEFT) &&
648                                            is_same_align);
649         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio),
650                                            (selection_align == PANGO_ALIGN_CENTER) &&
651                                            is_same_align);
652         gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
653                                            (selection_align == PANGO_ALIGN_RIGHT) &&
654                                            is_same_align);
655 }
656
657
658 static void
659 update_fill_color (glView *view,
660                    glUIPropertyBar *this)
661 {
662         gboolean can, is_first_object;
663         gboolean is_same_fill_color;
664         GList *p;
665         glLabelObject *object;
666         guint selection_fill_color, fill_color;
667         glColorNode *fill_color_node;
668
669         can = gl_view_can_selection_fill (view);
670         set_fill_items_sensitive (this, can);
671
672         if (!can) 
673                 return;
674
675         is_same_fill_color = TRUE;
676         is_first_object = TRUE;
677         selection_fill_color = 0;
678         
679         for (p = view->selected_object_list; p != NULL; p = p->next)
680         {
681
682                 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
683                 if (!gl_label_object_can_fill (object)) 
684                         continue;
685
686                 fill_color_node = gl_label_object_get_fill_color (object);
687                 if (fill_color_node->field_flag)
688                 {
689                         /* If a merge field is set we use the default color for merged color*/
690                         fill_color = GL_COLOR_FILL_MERGE_DEFAULT;
691                         
692                 }
693                 else
694                 {
695                         fill_color = fill_color_node->color;
696                 }
697                 gl_color_node_free (&fill_color_node);
698
699                 if (is_first_object)
700                 {
701                         selection_fill_color = fill_color;
702                 }
703                 else
704                 {
705                         if (fill_color != selection_fill_color)
706                         {
707                                 is_same_fill_color = FALSE;
708                         }
709                 }
710                 is_first_object = FALSE;
711         }
712
713         if (is_same_fill_color)
714         {
715                 gl_debug (DEBUG_PROPERTY_BAR, "same fill color = %08x", selection_fill_color);
716                 gl_color_combo_set_color (GL_COLOR_COMBO (this->priv->fill_color_combo),
717                                           selection_fill_color);
718         }
719 }
720
721
722 static void
723 update_line_color (glView *view,
724                    glUIPropertyBar *this)
725 {
726         gboolean can, is_first_object;
727         gboolean is_same_line_color;
728         GList *p;
729         glLabelObject *object;
730         guint selection_line_color, line_color;
731         glColorNode *line_color_node;
732
733         can = gl_view_can_selection_line_color (view);
734         set_line_color_items_sensitive (this, can);
735
736         if (!can) 
737                 return;
738
739         is_same_line_color = TRUE;
740         is_first_object = TRUE;
741         selection_line_color = 0;
742         
743         for (p = view->selected_object_list; p != NULL; p = p->next)
744         {
745
746                 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
747                 if (!gl_label_object_can_line_color (object)) 
748                         continue;
749
750                 line_color_node = gl_label_object_get_line_color (object);
751                 if (line_color_node->field_flag)
752                 {
753                         /* If a merge field is set we use the default color for merged color*/
754                         line_color = GL_COLOR_MERGE_DEFAULT;
755                         
756                 }
757                 else
758                 {
759                         line_color = line_color_node->color;
760                 }
761                 gl_color_node_free (&line_color_node);
762
763                 if (is_first_object)
764                 {
765                         selection_line_color = line_color;
766                 }
767                 else
768                 {
769                         if (line_color != selection_line_color)
770                         {
771                                 is_same_line_color = FALSE;
772                         }
773                 }
774                 is_first_object = FALSE;
775         }
776
777         if (is_same_line_color)
778         {
779                 gl_debug (DEBUG_PROPERTY_BAR, "same line color = %08x", selection_line_color);
780                 gl_color_combo_set_color (GL_COLOR_COMBO (this->priv->line_color_combo),
781                                           selection_line_color);
782         }
783 }
784
785
786 static void
787 update_line_width (glView *view,
788                    glUIPropertyBar *this)
789 {
790         gboolean can, is_first_object;
791         gboolean is_same_line_width;
792         GList *p;
793         glLabelObject *object;
794         gdouble selection_line_width, line_width;
795
796         can = gl_view_can_selection_line_width (view);
797         set_line_width_items_sensitive (this, can);
798
799         if (!can) 
800                 return;
801
802         is_same_line_width = TRUE;
803         is_first_object = TRUE;
804         selection_line_width = 0;
805         
806         for (p = view->selected_object_list; p != NULL; p = p->next)
807         {
808
809                 object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data));
810                 if (!gl_label_object_can_line_width (object)) 
811                         continue;
812
813                 line_width = gl_label_object_get_line_width (object);
814
815                 if (is_first_object)
816                 {
817                         selection_line_width = line_width;
818                 }
819                 else
820                 {
821                         if (line_width != selection_line_width)
822                         {
823                                 is_same_line_width = FALSE;
824                         }
825                 }
826                 is_first_object = FALSE;
827         }
828
829         if (is_same_line_width)
830         {
831                 gl_debug (DEBUG_PROPERTY_BAR, "same line width = %g", selection_line_width);
832                 gtk_spin_button_set_value (GTK_SPIN_BUTTON (this->priv->line_width_spin),
833                                            selection_line_width);
834         }
835         else
836         {
837                 gtk_entry_set_text (GTK_ENTRY (this->priv->line_width_spin), "");
838         }
839 }
840
841
842 static void 
843 selection_changed_cb (glUIPropertyBar *this)
844 {
845         glView *view = this->priv->view;
846         
847         g_return_if_fail (view && GL_IS_VIEW (view));
848         g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
849
850         if (this->priv->stop_signals) return;
851         this->priv->stop_signals = TRUE;
852
853         gl_debug (DEBUG_PROPERTY_BAR, "START");
854
855         if (gl_view_is_selection_empty (view))
856         {
857                 /* No selection: make all controls active. */
858                 reset_to_default_properties (view, this);
859                 set_doc_items_sensitive (this, TRUE);
860         }
861         else
862         {
863                 update_text_properties (view, this);
864                 update_fill_color (view, this);
865                 update_line_color (view, this);
866                 update_line_width (view, this);
867         }
868
869         gl_debug (DEBUG_PROPERTY_BAR, "END");
870
871         this->priv->stop_signals = FALSE;
872 }
873
874
875 /*--------------------------------------------------------------------------*/
876 /* PRIVATE.  Font family entry changed.                                     */
877 /*--------------------------------------------------------------------------*/
878 static void
879 font_family_changed_cb (GtkComboBox     *combo,
880                         glUIPropertyBar *this)
881 {
882         gchar *font_family;
883
884         if (this->priv->stop_signals) return;
885         this->priv->stop_signals = TRUE;
886
887         gl_debug (DEBUG_PROPERTY_BAR, "START");
888
889         font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
890         if ( strlen(font_family) )
891         {
892                 gl_view_set_selection_font_family (this->priv->view,
893                                                    font_family);
894                 gl_view_set_default_font_family   (this->priv->view,
895                                                    font_family);
896         }
897         g_free (font_family);
898
899         gl_debug (DEBUG_PROPERTY_BAR, "END");
900
901         this->priv->stop_signals = FALSE;
902 }
903
904
905 /*--------------------------------------------------------------------------*/
906 /* PRIVATE.  Font size spin button changed.                                 */
907 /*--------------------------------------------------------------------------*/
908 static void
909 font_size_changed_cb (GtkSpinButton        *spin,
910                       glUIPropertyBar      *this)
911 {
912         gdouble font_size;
913
914         if (this->priv->stop_signals) return;
915         this->priv->stop_signals = TRUE;
916
917         gl_debug (DEBUG_PROPERTY_BAR, "START");
918
919         font_size = gtk_spin_button_get_value (spin);
920
921         gl_view_set_selection_font_size (this->priv->view,
922                                          font_size);
923         gl_view_set_default_font_size   (this->priv->view,
924                                          font_size);
925
926         gl_debug (DEBUG_PROPERTY_BAR, "END");
927
928         this->priv->stop_signals = FALSE;
929 }
930
931
932 /*--------------------------------------------------------------------------*/
933 /* PRIVATE.  Text color combo changed.                                      */
934 /*--------------------------------------------------------------------------*/
935 static void
936 text_color_changed_cb (glColorCombo         *cc,
937                        guint                 color,
938                        gboolean              is_default,
939                        glUIPropertyBar      *this)
940 {
941         glColorNode *text_color_node;
942
943         g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
944
945         if (this->priv->stop_signals) return;
946         this->priv->stop_signals = TRUE;
947
948         gl_debug (DEBUG_PROPERTY_BAR, "START");
949
950         text_color_node = gl_color_node_new_default ();
951         text_color_node->color = color;
952         
953         gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
954                   color, is_default);
955
956         if (is_default)
957         {
958                 text_color_node->color = gl_prefs->default_text_color;
959                 gl_view_set_selection_text_color (this->priv->view,
960                                                   text_color_node);
961                 gl_view_set_default_text_color   (this->priv->view,
962                                                   gl_prefs->default_text_color);
963         }
964         else
965         {
966                 gl_view_set_selection_text_color (this->priv->view,
967                                                   text_color_node);
968                 gl_view_set_default_text_color   (this->priv->view,
969                                                   text_color_node->color);
970         }
971
972         gl_color_node_free (&text_color_node);
973         
974         gl_debug (DEBUG_PROPERTY_BAR, "END");
975
976         this->priv->stop_signals = FALSE;
977 }
978
979
980 /*--------------------------------------------------------------------------*/
981 /* PRIVATE.  Fill color combo changed.                                      */
982 /*--------------------------------------------------------------------------*/
983 static void
984 fill_color_changed_cb (glColorCombo         *cc,
985                        guint                 color,
986                        gboolean              is_default,
987                        glUIPropertyBar      *this)
988 {
989         glColorNode *fill_color_node;
990
991         g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
992
993         if (this->priv->stop_signals) return;
994         this->priv->stop_signals = TRUE;
995
996         gl_debug (DEBUG_PROPERTY_BAR, "START");
997
998         fill_color_node = gl_color_node_new_default ();
999
1000         fill_color_node->color = color;
1001
1002         gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
1003                   color, is_default);
1004
1005         if (is_default)
1006         {
1007
1008                 fill_color_node->color = GL_COLOR_NONE;
1009                 gl_view_set_selection_fill_color (this->priv->view,
1010                                                   fill_color_node);
1011                 gl_view_set_default_fill_color   (this->priv->view,
1012                                                   fill_color_node->color);
1013         }
1014         else
1015         {
1016                 gl_view_set_selection_fill_color (this->priv->view,
1017                                                   fill_color_node);
1018                 gl_view_set_default_fill_color   (this->priv->view,
1019                                                   fill_color_node->color);
1020         }
1021         gl_color_node_free (&fill_color_node);
1022         
1023         gl_debug (DEBUG_PROPERTY_BAR, "END");
1024
1025         this->priv->stop_signals = FALSE;
1026 }
1027
1028
1029 /*--------------------------------------------------------------------------*/
1030 /* PRIVATE.  Line color combo changed.                                      */
1031 /*--------------------------------------------------------------------------*/
1032 static void
1033 line_color_changed_cb (glColorCombo         *cc,
1034                        guint                 color,
1035                        gboolean              is_default,
1036                        glUIPropertyBar      *this)
1037 {
1038         glColorNode *line_color_node;
1039
1040         g_return_if_fail (this && GL_IS_UI_PROPERTY_BAR (this));
1041
1042         if (this->priv->stop_signals) return;
1043         this->priv->stop_signals = TRUE;
1044
1045         gl_debug (DEBUG_PROPERTY_BAR, "START");
1046
1047         line_color_node = gl_color_node_new_default ();
1048         line_color_node->color = color;
1049
1050         gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d",
1051                   color, is_default);
1052
1053         if (is_default)
1054         {
1055                 line_color_node->color = GL_COLOR_NONE;
1056                 gl_view_set_selection_line_color (this->priv->view,
1057                                                   line_color_node);
1058                 gl_view_set_default_line_color   (this->priv->view,
1059                                                   line_color_node->color);
1060         }
1061         else
1062         {
1063                 gl_view_set_selection_line_color (this->priv->view,
1064                                                   line_color_node);
1065                 gl_view_set_default_line_color   (this->priv->view,
1066                                                   line_color_node->color);
1067         }
1068         gl_color_node_free (&line_color_node);
1069
1070         gl_debug (DEBUG_PROPERTY_BAR, "END");
1071
1072         this->priv->stop_signals = FALSE;
1073 }
1074
1075
1076 /*--------------------------------------------------------------------------*/
1077 /* PRIVATE.  Line width spin button changed.                                */
1078 /*--------------------------------------------------------------------------*/
1079 static void
1080 line_width_changed_cb (GtkSpinButton        *spin,
1081                        glUIPropertyBar      *this)
1082 {
1083         gdouble line_width;
1084
1085         if (this->priv->stop_signals) return;
1086         this->priv->stop_signals = TRUE;
1087
1088         gl_debug (DEBUG_PROPERTY_BAR, "START");
1089
1090         if (this->priv->view)
1091         {
1092                 line_width = gtk_spin_button_get_value (spin);
1093
1094                 gl_view_set_selection_line_width (this->priv->view,
1095                                                   line_width);
1096                 gl_view_set_default_line_width   (this->priv->view,
1097                                                   line_width);
1098         }
1099
1100         gl_debug (DEBUG_PROPERTY_BAR, "END");
1101
1102         this->priv->stop_signals = FALSE;
1103 }
1104
1105
1106 /*---------------------------------------------------------------------------*/
1107 /* PRIVATE.  Font bold toggled callback.                                     */
1108 /*---------------------------------------------------------------------------*/
1109 static void
1110 font_bold_toggled_cb (GtkToggleToolButton  *toggle,
1111                       glUIPropertyBar      *this)
1112 {
1113         gboolean        state;
1114         PangoWeight     weight;
1115
1116
1117         if (this->priv->stop_signals) return;
1118         this->priv->stop_signals = TRUE;
1119
1120         gl_debug (DEBUG_PROPERTY_BAR, "START");
1121
1122         state = gtk_toggle_tool_button_get_active (toggle);
1123
1124         weight = state ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL;
1125
1126         gl_view_set_selection_font_weight (this->priv->view, weight);
1127         gl_view_set_default_font_weight   (this->priv->view, weight);
1128
1129         gl_debug (DEBUG_PROPERTY_BAR, "END");
1130
1131         this->priv->stop_signals = FALSE;
1132 }
1133                                                   
1134
1135 /*---------------------------------------------------------------------------*/
1136 /* PRIVATE.  Font italic toggled callback.                                   */
1137 /*---------------------------------------------------------------------------*/
1138 static void
1139 font_italic_toggled_cb (GtkToggleToolButton  *toggle,
1140                         glUIPropertyBar      *this)
1141 {
1142         gboolean state;
1143
1144         if (this->priv->stop_signals) return;
1145         this->priv->stop_signals = TRUE;
1146
1147         gl_debug (DEBUG_PROPERTY_BAR, "START");
1148
1149         state = gtk_toggle_tool_button_get_active (toggle);
1150
1151         gl_view_set_selection_font_italic_flag (this->priv->view, state);
1152         gl_view_set_default_font_italic_flag   (this->priv->view, state);
1153
1154         gl_debug (DEBUG_PROPERTY_BAR, "END");
1155
1156         this->priv->stop_signals = FALSE;
1157 }
1158                                                   
1159
1160 /*---------------------------------------------------------------------------*/
1161 /* PRIVATE.  Text align toggled callback.                                    */
1162 /*---------------------------------------------------------------------------*/
1163 static void
1164 text_align_toggled_cb (GtkToggleToolButton  *toggle,
1165                        glUIPropertyBar      *this)
1166 {
1167         if (this->priv->stop_signals) return;
1168         this->priv->stop_signals = TRUE;
1169
1170         gl_debug (DEBUG_PROPERTY_BAR, "START");
1171
1172         if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_left_radio)))
1173         {               
1174                 gl_view_set_selection_text_alignment (this->priv->view,
1175                                                       PANGO_ALIGN_LEFT);
1176                 gl_view_set_default_text_alignment   (this->priv->view,
1177                                                       PANGO_ALIGN_LEFT);
1178         }
1179
1180         if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_center_radio)))
1181         {               
1182                 gl_view_set_selection_text_alignment (this->priv->view,
1183                                                       PANGO_ALIGN_CENTER);
1184                 gl_view_set_default_text_alignment   (this->priv->view,
1185                                                       PANGO_ALIGN_CENTER);
1186         }
1187
1188         if (gtk_toggle_tool_button_get_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio)))
1189         {
1190                 gl_view_set_selection_text_alignment (this->priv->view,
1191                                                       PANGO_ALIGN_RIGHT);
1192                 gl_view_set_default_text_alignment   (this->priv->view,
1193                                                       PANGO_ALIGN_RIGHT);
1194         }
1195
1196         gl_debug (DEBUG_PROPERTY_BAR, "END");
1197
1198         this->priv->stop_signals = FALSE;
1199 }
1200
1201
1202 /*---------------------------------------------------------------------------*/
1203 /* PRIVATE.  Set sensitivity of doc controls.                                */
1204 /*---------------------------------------------------------------------------*/
1205 static void
1206 set_doc_items_sensitive (glUIPropertyBar      *this,
1207                          gboolean              state)
1208 {
1209         gtk_widget_set_sensitive (this->priv->font_family_combo,       state);
1210         gtk_widget_set_sensitive (this->priv->font_size_spin,          state);
1211         gtk_widget_set_sensitive (this->priv->font_bold_toggle,        state);
1212         gtk_widget_set_sensitive (this->priv->font_italic_toggle,      state);
1213         gtk_widget_set_sensitive (this->priv->text_align_left_radio,   state);
1214         gtk_widget_set_sensitive (this->priv->text_align_center_radio, state);
1215         gtk_widget_set_sensitive (this->priv->text_align_right_radio,  state);
1216         gtk_widget_set_sensitive (this->priv->text_color_combo,        state);
1217         gtk_widget_set_sensitive (this->priv->fill_color_combo,        state);
1218         gtk_widget_set_sensitive (this->priv->line_color_combo,        state);
1219         gtk_widget_set_sensitive (this->priv->line_width_spin,         state);
1220 }
1221
1222
1223 /*---------------------------------------------------------------------------*/
1224 /* PRIVATE.  Set sensitivity of text related controls.                       */
1225 /*---------------------------------------------------------------------------*/
1226 static void
1227 set_text_items_sensitive (glUIPropertyBar      *this,
1228                           gboolean              state)
1229 {
1230         gtk_widget_set_sensitive (this->priv->font_family_combo,       state);
1231         gtk_widget_set_sensitive (this->priv->font_size_spin,          state);
1232         gtk_widget_set_sensitive (this->priv->font_bold_toggle,        state);
1233         gtk_widget_set_sensitive (this->priv->font_italic_toggle,      state);
1234         gtk_widget_set_sensitive (this->priv->text_align_left_radio,   state);
1235         gtk_widget_set_sensitive (this->priv->text_align_center_radio, state);
1236         gtk_widget_set_sensitive (this->priv->text_align_right_radio,  state);
1237         gtk_widget_set_sensitive (this->priv->text_color_combo,        state);
1238 }
1239
1240
1241 /*---------------------------------------------------------------------------*/
1242 /* PRIVATE.  Set sensitivity of fill related controls.                       */
1243 /*---------------------------------------------------------------------------*/
1244 static void
1245 set_fill_items_sensitive (glUIPropertyBar      *this,
1246                           gboolean              state)
1247 {
1248         gtk_widget_set_sensitive (this->priv->fill_color_combo,        state);
1249 }
1250
1251
1252 /*---------------------------------------------------------------------------*/
1253 /* PRIVATE.  Set sensitivity of line color related controls.                 */
1254 /*---------------------------------------------------------------------------*/
1255 static void
1256 set_line_color_items_sensitive (glUIPropertyBar      *this,
1257                                 gboolean              state)
1258 {
1259         gtk_widget_set_sensitive (this->priv->line_color_combo,        state);
1260 }
1261
1262
1263 /*---------------------------------------------------------------------------*/
1264 /* PRIVATE.  Set sensitivity of line width related controls.                 */
1265 /*---------------------------------------------------------------------------*/
1266 static void
1267 set_line_width_items_sensitive (glUIPropertyBar      *this,
1268                                 gboolean              state)
1269 {
1270         gtk_widget_set_sensitive (this->priv->line_width_spin,         state);
1271 }
1272
1273
1274
1275 /*
1276  * Local Variables:       -- emacs
1277  * mode: C                -- emacs
1278  * c-basic-offset: 8      -- emacs
1279  * tab-width: 8           -- emacs
1280  * indent-tabs-mode: nil  -- emacs
1281  * End:                   -- emacs
1282  */