From: Jim Evins Date: Wed, 17 Dec 2003 00:30:21 +0000 (+0000) Subject: Modifications to track properties of selected objects. This addresses Bug #839801... X-Git-Tag: glabels-2_3_0~518 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=00dd4521fae11dda1e5a53c5adb4edd044bb9689;p=glabels Modifications to track properties of selected objects. This addresses Bug #839801. Patch provided by Emmanuel Pacaud . git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@376 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/src/mygal/widget-color-combo.c b/glabels2/src/mygal/widget-color-combo.c index e67e305b..f25b375c 100644 --- a/glabels2/src/mygal/widget-color-combo.c +++ b/glabels2/src/mygal/widget-color-combo.c @@ -103,6 +103,8 @@ color_combo_set_color_internal (ColorCombo *cc, GdkColor *color) pixbuf, 1, color_y + 1); g_object_unref (color_pixbuf); + + gtk_widget_queue_draw (GTK_WIDGET (cc)); } static void diff --git a/glabels2/src/ui-property-bar.c b/glabels2/src/ui-property-bar.c index a71cb199..e61015ad 100644 --- a/glabels2/src/ui-property-bar.c +++ b/glabels2/src/ui-property-bar.c @@ -102,8 +102,7 @@ static void gl_ui_property_bar_finalize (GObject *object); static void gl_ui_property_bar_construct (glUIPropertyBar *property_bar, BonoboUIComponent *ui_component); -static void selection_changed_cb (glView *view, - glUIPropertyBar *property_bar); +static void selection_changed_cb (glUIPropertyBar *property_bar); static void font_family_changed_cb (GtkEntry *entry, glUIPropertyBar *property_bar); @@ -260,6 +259,7 @@ gl_ui_property_bar_construct (glUIPropertyBar *property_bar, gl_debug (DEBUG_PROPERTY_BAR, "START"); + property_bar->stop_signals = TRUE; property_bar->ui_component = ui_component; /* Font family entry widget */ @@ -267,7 +267,7 @@ gl_ui_property_bar_construct (glUIPropertyBar *property_bar, family_names = gnome_font_family_list (); gtk_combo_set_popdown_strings (GTK_COMBO (wcombo), family_names); property_bar->font_family_entry = GTK_COMBO (wcombo)->entry; - gtk_combo_set_value_in_list (GTK_COMBO(wcombo), TRUE, FALSE); + gtk_combo_set_value_in_list (GTK_COMBO(wcombo), TRUE, TRUE); gtk_entry_set_editable (GTK_ENTRY (property_bar->font_family_entry), FALSE); gtk_widget_set_size_request (wcombo, 200, -1); @@ -397,31 +397,22 @@ gl_ui_property_bar_construct (glUIPropertyBar *property_bar, gl_ui_util_set_verb_list_sensitive (ui_component, doc_verbs, FALSE); + property_bar->stop_signals = FALSE; + gl_debug (DEBUG_PROPERTY_BAR, "END"); } /****************************************************************************/ -/* Set view associated with property_bar. */ +/* Fill widgets with default values. */ /****************************************************************************/ -void -gl_ui_property_bar_set_view (glUIPropertyBar *property_bar, - glView *view) +static void +reset_to_default_properties (glView *view, + glUIPropertyBar *property_bar) { - glLabel *label; GList *family_names; gchar *good_font_family; GdkColor *gdk_color; - gl_debug (DEBUG_PROPERTY_BAR, "START"); - - g_return_if_fail (view && GL_IS_VIEW (view)); - label = view->label; - g_return_if_fail (label && GL_IS_LABEL (label)); - - gl_ui_util_set_verb_list_sensitive (property_bar->ui_component, doc_verbs, TRUE); - - property_bar->view = GL_VIEW (g_object_ref (G_OBJECT (view))); - /* Make sure we have a valid font family. if not provide a good default. */ family_names = gnome_font_family_list (); if (g_list_find_custom (family_names, @@ -436,6 +427,7 @@ gl_ui_property_bar_set_view (glUIPropertyBar *property_bar, } } gtk_entry_set_text (GTK_ENTRY (property_bar->font_family_entry), good_font_family); + g_free (good_font_family); gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->font_size_spin), view->default_font_size); @@ -471,9 +463,34 @@ gl_ui_property_bar_set_view (glUIPropertyBar *property_bar, gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->line_width_spin), view->default_line_width); +} + +/****************************************************************************/ +/* Set view associated with property_bar. */ +/****************************************************************************/ +void +gl_ui_property_bar_set_view (glUIPropertyBar *property_bar, + glView *view) +{ + glLabel *label; + + gl_debug (DEBUG_PROPERTY_BAR, "START"); + + g_return_if_fail (view && GL_IS_VIEW (view)); + label = view->label; + g_return_if_fail (label && GL_IS_LABEL (label)); + + gl_ui_util_set_verb_list_sensitive (property_bar->ui_component, doc_verbs, TRUE); + + property_bar->view = GL_VIEW (g_object_ref (G_OBJECT (view))); - g_signal_connect (G_OBJECT(view), "selection_changed", - G_CALLBACK(selection_changed_cb), property_bar); + reset_to_default_properties (view, property_bar); + + g_signal_connect_swapped (G_OBJECT(view), "selection_changed", + G_CALLBACK(selection_changed_cb), property_bar); + + g_signal_connect_swapped (G_OBJECT(view->label), "changed", + G_CALLBACK(selection_changed_cb), property_bar); gl_debug (DEBUG_PROPERTY_BAR, "END"); } @@ -481,41 +498,309 @@ gl_ui_property_bar_set_view (glUIPropertyBar *property_bar, /*---------------------------------------------------------------------------*/ /* PRIVATE. View "selection state changed" callback. */ /*---------------------------------------------------------------------------*/ + +static void +update_text_properties (glView *view, + glUIPropertyBar *property_bar) +{ + gboolean can_text, is_first_object; + gboolean is_same_font_family, is_same_font_size; + gboolean is_same_text_color, is_same_is_italic; + gboolean is_same_is_bold, is_same_justification; + GList *p; + glLabelObject *object; + gchar *selection_font_family, *font_family; + gdouble selection_font_size, font_size; + guint selection_text_color, text_color; + gboolean selection_is_italic, is_italic; + gboolean selection_is_bold, is_bold; + GtkJustification selection_justification, justification; + GdkColor *gdk_color; + + can_text = gl_view_can_selection_text (view); + gl_ui_util_set_verb_list_sensitive (property_bar->ui_component, + text_verbs, + can_text); + if (!can_text) + return; + + is_same_is_italic = + is_same_is_bold = + is_same_justification = + is_same_text_color = + is_same_font_size = + is_same_font_family = TRUE; + selection_font_family = NULL; + selection_font_size = -1; + is_first_object = TRUE; + + for (p = view->selected_object_list; p != NULL; p = p->next) { + + object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data)); + if (!gl_label_object_can_text (object)) + continue; + + font_family = gl_label_object_get_font_family (object); + if (font_family != NULL) { + if (selection_font_family == NULL) + selection_font_family = g_strdup (font_family); + else + if (strcmp (font_family, selection_font_family) != 0) + is_same_font_family = FALSE; + g_free (font_family); + } + + font_size = gl_label_object_get_font_size (object); + text_color = gl_label_object_get_text_color (object); + is_italic = gl_label_object_get_font_italic_flag (object); + is_bold = gl_label_object_get_font_weight (object) == GNOME_FONT_BOLD; + justification = gl_label_object_get_text_alignment (object); + + if (is_first_object) { + selection_font_size = font_size; + selection_text_color = text_color; + selection_is_italic = is_italic; + selection_is_bold = is_bold; + selection_justification = justification; + } else { + if (font_size != selection_font_size) + is_same_font_size = FALSE; + if (text_color != selection_text_color) + is_same_text_color = FALSE; + if (is_italic != selection_is_italic) + is_same_is_italic = FALSE; + if (is_bold != selection_is_bold) + is_same_is_bold = FALSE; + if (justification != selection_justification) + is_same_justification = FALSE; + } + is_first_object = FALSE; + } + + if (is_same_font_family && (selection_font_family != NULL)) + gl_debug (DEBUG_PROPERTY_BAR, "same font family = %s", + selection_font_family); + gtk_entry_set_text (GTK_ENTRY (property_bar->font_family_entry), + is_same_font_family?selection_font_family:""); + g_free (selection_font_family); + + if (is_same_font_size) { + gl_debug (DEBUG_PROPERTY_BAR, "same font size = %g", + selection_font_size); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (property_bar->font_size_spin), + selection_font_size); + } else { + gtk_entry_set_text (GTK_ENTRY (property_bar->font_size_spin), ""); + } + + if (is_same_text_color) { + gl_debug (DEBUG_PROPERTY_BAR, "same text color = %08x", selection_text_color); + gdk_color = gl_color_to_gdk_color (selection_text_color); + color_combo_set_color (COLOR_COMBO (property_bar->text_color_combo), + gdk_color); + g_free (gdk_color); + } + + if (is_same_is_italic) + gl_debug (DEBUG_PROPERTY_BAR, "same italic flag = %d", + selection_is_italic); + gl_ui_util_set_verb_state (property_bar->ui_component, + "/commands/PropFontItalic", + selection_is_italic && is_same_is_italic); + + if (is_same_is_bold) + gl_debug (DEBUG_PROPERTY_BAR, "same bold flag = %d", + selection_is_bold); + gl_ui_util_set_verb_state (property_bar->ui_component, + "/commands/PropFontBold", + selection_is_bold && is_same_is_bold); + + if (is_same_justification) + gl_debug (DEBUG_PROPERTY_BAR, "same justification"); + gl_ui_util_set_verb_state (property_bar->ui_component, + "/commands/PropTextAlignRight", + (selection_justification == GTK_JUSTIFY_RIGHT) && + is_same_justification); + gl_ui_util_set_verb_state (property_bar->ui_component, + "/commands/PropTextAlignLeft", + (selection_justification == GTK_JUSTIFY_LEFT) && + is_same_justification); + gl_ui_util_set_verb_state (property_bar->ui_component, + "/commands/PropTextAlignCenter", + (selection_justification == GTK_JUSTIFY_CENTER) && + is_same_justification); +} + +static void +update_fill_color (glView *view, + glUIPropertyBar *property_bar) +{ + gboolean can, is_first_object; + gboolean is_same_fill_color; + GList *p; + glLabelObject *object; + guint selection_fill_color, fill_color; + GdkColor *gdk_color; + + can = gl_view_can_selection_fill (view); + gl_ui_util_set_verb_list_sensitive (property_bar->ui_component, + fill_verbs, + can); + if (!can) + return; + + is_same_fill_color = TRUE; + is_first_object = TRUE; + + for (p = view->selected_object_list; p != NULL; p = p->next) { + + object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data)); + if (!gl_label_object_can_fill (object)) + continue; + + fill_color = gl_label_object_get_fill_color (object); + + if (is_first_object) { + selection_fill_color = fill_color; + } else { + if (fill_color != selection_fill_color) + is_same_fill_color = FALSE; + } + is_first_object = FALSE; + } + + if (is_same_fill_color) { + gl_debug (DEBUG_PROPERTY_BAR, "same fill color = %08x", selection_fill_color); + gdk_color = gl_color_to_gdk_color (selection_fill_color); + color_combo_set_color (COLOR_COMBO (property_bar->fill_color_combo), + gdk_color); + g_free (gdk_color); + } +} + +static void +update_line_color (glView *view, + glUIPropertyBar *property_bar) +{ + gboolean can, is_first_object; + gboolean is_same_line_color; + GList *p; + glLabelObject *object; + guint selection_line_color, line_color; + GdkColor *gdk_color; + + can = gl_view_can_selection_line_color (view); + gl_ui_util_set_verb_list_sensitive (property_bar->ui_component, + line_color_verbs, + can); + if (!can) + return; + + is_same_line_color = TRUE; + is_first_object = TRUE; + + for (p = view->selected_object_list; p != NULL; p = p->next) { + + object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data)); + if (!gl_label_object_can_line_color (object)) + continue; + + line_color = gl_label_object_get_line_color (object); + + if (is_first_object) { + selection_line_color = line_color; + } else { + if (line_color != selection_line_color) + is_same_line_color = FALSE; + } + is_first_object = FALSE; + } + + if (is_same_line_color) { + gl_debug (DEBUG_PROPERTY_BAR, "same line color = %08x", selection_line_color); + gdk_color = gl_color_to_gdk_color (selection_line_color); + color_combo_set_color (COLOR_COMBO (property_bar->line_color_combo), + gdk_color); + g_free (gdk_color); + } +} + +static void +update_line_width (glView *view, + glUIPropertyBar *property_bar) +{ + gboolean can, is_first_object; + gboolean is_same_line_width; + GList *p; + glLabelObject *object; + gdouble selection_line_width, line_width; + + can = gl_view_can_selection_line_width (view); + gl_ui_util_set_verb_list_sensitive (property_bar->ui_component, + line_width_verbs, + can); + if (!can) + return; + + is_same_line_width = TRUE; + is_first_object = TRUE; + + for (p = view->selected_object_list; p != NULL; p = p->next) { + + object = gl_view_object_get_object(GL_VIEW_OBJECT (p->data)); + if (!gl_label_object_can_line_width (object)) + continue; + + line_width = gl_label_object_get_line_width (object); + + if (is_first_object) { + selection_line_width = line_width; + } else { + if (line_width != selection_line_width) + is_same_line_width = FALSE; + } + is_first_object = FALSE; + } + + if (is_same_line_width) { + gl_debug (DEBUG_PROPERTY_BAR, "same line width = %g", selection_line_width); + gtk_spin_button_set_value (GTK_SPIN_BUTTON (property_bar->line_width_spin), + selection_line_width); + } else { + gtk_entry_set_text (GTK_ENTRY (property_bar->line_width_spin), ""); + } +} + static void -selection_changed_cb (glView *view, - glUIPropertyBar *property_bar) +selection_changed_cb (glUIPropertyBar *property_bar) { + glView *view = property_bar->view; + gl_debug (DEBUG_PROPERTY_BAR, "START"); g_return_if_fail (view && GL_IS_VIEW (view)); g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar)); + property_bar->stop_signals = TRUE; + if (gl_view_is_selection_empty (view)) { /* No selection: make all controls active. */ + reset_to_default_properties (view, property_bar); gl_ui_util_set_verb_list_sensitive (property_bar->ui_component, doc_verbs, TRUE); } else { - gl_ui_util_set_verb_list_sensitive (property_bar->ui_component, - text_verbs, - gl_view_can_selection_text (view)); - - gl_ui_util_set_verb_list_sensitive (property_bar->ui_component, - fill_verbs, - gl_view_can_selection_fill (view)); - - gl_ui_util_set_verb_list_sensitive (property_bar->ui_component, - line_color_verbs, - gl_view_can_selection_line_color (view)); - - gl_ui_util_set_verb_list_sensitive (property_bar->ui_component, - line_width_verbs, - gl_view_can_selection_line_width (view)); + update_text_properties (view, property_bar); + update_fill_color (view, property_bar); + update_line_color (view, property_bar); + update_line_width (view, property_bar); } + property_bar->stop_signals = FALSE; + gl_debug (DEBUG_PROPERTY_BAR, "END"); } @@ -528,8 +813,15 @@ font_family_changed_cb (GtkEntry *entry, { gchar *font_family; + if (property_bar->stop_signals) + return; + gl_debug (DEBUG_PROPERTY_BAR, "START"); + g_signal_handlers_block_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + font_family = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1); if ( strlen(font_family) ) { gl_view_set_selection_font_family (property_bar->view, @@ -538,6 +830,12 @@ font_family_changed_cb (GtkEntry *entry, font_family); } g_free (font_family); + + g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + + gl_debug (DEBUG_PROPERTY_BAR, "END"); } /*--------------------------------------------------------------------------*/ @@ -549,8 +847,15 @@ font_size_changed_cb (GtkSpinButton *spin, { gdouble font_size; + if (property_bar->stop_signals) + return; + gl_debug (DEBUG_PROPERTY_BAR, "START"); + g_signal_handlers_block_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + font_size = gtk_spin_button_get_value (spin); gl_view_set_selection_font_size (property_bar->view, @@ -558,6 +863,10 @@ font_size_changed_cb (GtkSpinButton *spin, gl_view_set_default_font_size (property_bar->view, font_size); + g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + gl_debug (DEBUG_PROPERTY_BAR, "END"); } @@ -574,10 +883,17 @@ text_color_changed_cb (ColorCombo *cc, { guint text_color; + if (property_bar->stop_signals) + return; + g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar)); gl_debug (DEBUG_PROPERTY_BAR, "START"); + g_signal_handlers_block_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + text_color = gl_color_from_gdk_color (gdk_color); gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d", @@ -599,6 +915,10 @@ text_color_changed_cb (ColorCombo *cc, } + g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + gl_debug (DEBUG_PROPERTY_BAR, "END"); } @@ -615,10 +935,17 @@ fill_color_changed_cb (ColorCombo *cc, { guint fill_color; + if (property_bar->stop_signals) + return; + g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar)); gl_debug (DEBUG_PROPERTY_BAR, "START"); + g_signal_handlers_block_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + fill_color = gl_color_from_gdk_color (gdk_color); gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d", @@ -640,6 +967,10 @@ fill_color_changed_cb (ColorCombo *cc, } + g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + gl_debug (DEBUG_PROPERTY_BAR, "END"); } @@ -656,10 +987,17 @@ line_color_changed_cb (ColorCombo *cc, { guint line_color; + if (property_bar->stop_signals) + return; + g_return_if_fail (property_bar && GL_IS_UI_PROPERTY_BAR (property_bar)); gl_debug (DEBUG_PROPERTY_BAR, "START"); + g_signal_handlers_block_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + line_color = gl_color_from_gdk_color (gdk_color); gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d", @@ -681,6 +1019,10 @@ line_color_changed_cb (ColorCombo *cc, } + g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + gl_debug (DEBUG_PROPERTY_BAR, "END"); } @@ -693,8 +1035,15 @@ line_width_changed_cb (GtkSpinButton *spin, { gdouble line_width; + if (property_bar->stop_signals) + return; + gl_debug (DEBUG_PROPERTY_BAR, "START"); + g_signal_handlers_block_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + line_width = gtk_spin_button_get_value (spin); gl_view_set_selection_line_width (property_bar->view, @@ -702,6 +1051,10 @@ line_width_changed_cb (GtkSpinButton *spin, gl_view_set_default_line_width (property_bar->view, line_width); + g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + gl_debug (DEBUG_PROPERTY_BAR, "END"); } @@ -717,8 +1070,15 @@ prop_item_toggled_cb (BonoboUIComponent *ui_component, { gboolean s; + if (property_bar->stop_signals) + return; + gl_debug (DEBUG_PROPERTY_BAR, ""); + g_signal_handlers_block_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + s = (strcmp (state, "1") == 0); /* @@ -730,14 +1090,12 @@ prop_item_toggled_cb (BonoboUIComponent *ui_component, gl_view_set_selection_font_weight (property_bar->view, weight); gl_view_set_default_font_weight (property_bar->view, weight); - return; } if (strcmp (path, "PropFontItalic") == 0) { gl_view_set_selection_font_italic_flag (property_bar->view, s); gl_view_set_default_font_italic_flag (property_bar->view, s); - return; } @@ -758,7 +1116,6 @@ prop_item_toggled_cb (BonoboUIComponent *ui_component, gl_ui_util_set_verb_state (ui_component, "/commands/PropTextAlignRight", FALSE); - return; } if (s && (strcmp (path, "PropTextAlignCenter") == 0)) @@ -775,7 +1132,6 @@ prop_item_toggled_cb (BonoboUIComponent *ui_component, gl_ui_util_set_verb_state (ui_component, "/commands/PropTextAlignRight", FALSE); - return; } if (s && (strcmp (path, "PropTextAlignRight") == 0)) @@ -792,9 +1148,12 @@ prop_item_toggled_cb (BonoboUIComponent *ui_component, gl_ui_util_set_verb_state (ui_component, "/commands/PropTextAlignCenter", FALSE); - return; } + g_signal_handlers_unblock_by_func (G_OBJECT(property_bar->view->label), + selection_changed_cb, + property_bar); + } /*---------------------------------------------------------------------------------------*/ diff --git a/glabels2/src/ui-property-bar.h b/glabels2/src/ui-property-bar.h index 48eae841..bb3fead1 100644 --- a/glabels2/src/ui-property-bar.h +++ b/glabels2/src/ui-property-bar.h @@ -59,6 +59,8 @@ struct _glUIPropertyBar { GtkWidget *line_color_combo; GtkWidget *line_width_spin; + + gboolean stop_signals; }; struct _glUIPropertyBarClass {