From 1a73a9c8e678134478d99bafc3c0857a61072082 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 27 Mar 2010 00:50:41 -0700 Subject: Phase 1 - unify/reconcile copy-n-paste edit madness of Fill and Stroke edit panes. (bzr r9238) --- src/widgets/fill-style.cpp | 568 ++++++++++++++++++++++++++------------------- 1 file changed, 331 insertions(+), 237 deletions(-) (limited to 'src/widgets/fill-style.cpp') diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index 3f2018b91..09c6951ad 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -35,159 +35,184 @@ #include "widgets/sp-widget.h" #include "xml/repr.h" -#include "widgets/fill-style.h" +#include "fill-style.h" +#include "fill-n-stroke-factory.h" // These can be deleted once we sort out the libart dependence. #define ART_WIND_RULE_NONZERO 0 -static void sp_fill_style_widget_construct ( SPWidget *spw, - SPPaintSelector *psel ); +/* Fill */ -static void sp_fill_style_widget_modify_selection ( SPWidget *spw, - Inkscape::Selection *selection, - guint flags, - SPPaintSelector *psel ); +static void fillnstroke_constructed(SPWidget *spw, SPPaintSelector *psel); +static void fillnstroke_fillrule_changed(SPPaintSelector *psel, SPPaintSelector::FillRule mode, SPWidget *spw); -static void sp_fill_style_widget_change_subselection ( Inkscape::Application *inkscape, SPDesktop *desktop, SPWidget *spw ); +static void fillnstroke_selection_modified(SPWidget *spw, Inkscape::Selection *selection, guint flags, SPPaintSelector *psel); +static void fillnstroke_selection_changed(SPWidget *spw, Inkscape::Selection *selection, SPPaintSelector *psel); +static void fillnstroke_subselection_changed(Inkscape::Application *inkscape, SPDesktop *desktop, SPWidget *spw); -static void sp_fill_style_widget_change_selection ( SPWidget *spw, - Inkscape::Selection *selection, - SPPaintSelector *psel ); +static void fillnstroke_paint_mode_changed(SPPaintSelector *psel, SPPaintSelector::Mode mode, SPWidget *spw); +static void fillnstroke_paint_dragged(SPPaintSelector *psel, SPWidget *spw); +static void fillnstroke_paint_changed(SPPaintSelector *psel, SPWidget *spw); -static void sp_fill_style_widget_update (SPWidget *spw); +static void fillnstroke_transientize_called(Inkscape::Application *inkscape, SPDesktop *desktop, SPWidget *spw); -static void sp_fill_style_widget_paint_mode_changed( SPPaintSelector *psel, - SPPaintSelector::Mode mode, - SPWidget *spw ); -static void sp_fill_style_widget_fillrule_changed( SPPaintSelector *psel, - SPPaintSelector::FillRule mode, - SPWidget *spw ); +static void fillnstroke_performUpdate(SPWidget *spw); -static void sp_fill_style_widget_paint_dragged (SPPaintSelector *psel, SPWidget *spw ); -static void sp_fill_style_widget_paint_changed (SPPaintSelector *psel, SPWidget *spw ); - -GtkWidget * -sp_fill_style_widget_new (void) +GtkWidget *sp_fill_style_widget_new(void) { - GtkWidget *spw = sp_widget_new_global (INKSCAPE); - - GtkWidget *vb = gtk_vbox_new (FALSE, 0); - gtk_widget_show (vb); - gtk_container_add (GTK_CONTAINER (spw), vb); - - GtkWidget *psel = sp_paint_selector_new (true); // with fillrule selector - gtk_widget_show (psel); - gtk_box_pack_start (GTK_BOX (vb), psel, TRUE, TRUE, 0); - g_object_set_data (G_OBJECT (spw), "paint-selector", psel); - - g_signal_connect ( G_OBJECT (psel), "mode_changed", - G_CALLBACK (sp_fill_style_widget_paint_mode_changed), - spw ); - - g_signal_connect ( G_OBJECT (psel), "dragged", - G_CALLBACK (sp_fill_style_widget_paint_dragged), - spw ); - - g_signal_connect ( G_OBJECT (psel), "changed", - G_CALLBACK (sp_fill_style_widget_paint_changed), - spw ); - - g_signal_connect ( G_OBJECT (psel), "fillrule_changed", - G_CALLBACK (sp_fill_style_widget_fillrule_changed), - spw ); - + return Inkscape::Widgets::createStyleWidget( FILL ); +} - g_signal_connect ( G_OBJECT (spw), "construct", - G_CALLBACK (sp_fill_style_widget_construct), psel); +/** + * Create the fill or stroke style widget, and hook up all the signals. + */ +GtkWidget *Inkscape::Widgets::createStyleWidget( FillOrStroke kind ) +{ + GtkWidget *spw = sp_widget_new_global(INKSCAPE); + + // with or without fillrule selector + GtkWidget *psel = sp_paint_selector_new(kind == FILL); + gtk_widget_show(psel); + gtk_container_add(GTK_CONTAINER(spw), psel); + g_object_set_data(G_OBJECT(spw), "paint-selector", psel); + g_object_set_data(G_OBJECT(spw), "kind", GINT_TO_POINTER(kind)); + + if (kind == FILL) { + g_signal_connect( G_OBJECT(spw), "construct", + G_CALLBACK(fillnstroke_constructed), + psel ); + } //FIXME: switch these from spw signals to global inkscape object signals; spw just retranslates //those anyway; then eliminate spw - g_signal_connect ( G_OBJECT (spw), "modify_selection", - G_CALLBACK (sp_fill_style_widget_modify_selection), psel); - - g_signal_connect ( G_OBJECT (spw), "change_selection", - G_CALLBACK (sp_fill_style_widget_change_selection), psel); + g_signal_connect( G_OBJECT(spw), "modify_selection", + G_CALLBACK(fillnstroke_selection_modified), + psel ); + + g_signal_connect( G_OBJECT(spw), "change_selection", + G_CALLBACK(fillnstroke_selection_changed), + psel ); + + g_signal_connect( INKSCAPE, "change_subselection", + G_CALLBACK(fillnstroke_subselection_changed), + spw ); + + if (kind == STROKE) { + g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop", + G_CALLBACK(fillnstroke_transientize_called), + spw ); + } - g_signal_connect (INKSCAPE, "change_subselection", G_CALLBACK (sp_fill_style_widget_change_subselection), spw); + g_signal_connect( G_OBJECT(psel), "mode_changed", + G_CALLBACK(fillnstroke_paint_mode_changed), + spw ); - sp_fill_style_widget_update (SP_WIDGET (spw)); + g_signal_connect( G_OBJECT(psel), "dragged", + G_CALLBACK(fillnstroke_paint_dragged), + spw ); - return spw; + g_signal_connect( G_OBJECT(psel), "changed", + G_CALLBACK(fillnstroke_paint_changed), + spw ); -} // end of sp_fill_style_widget_new() + if (kind == FILL) { + g_signal_connect( G_OBJECT(psel), "fillrule_changed", + G_CALLBACK(fillnstroke_fillrule_changed), + spw ); + } + fillnstroke_performUpdate(SP_WIDGET(spw)); + return spw; +} -static void -sp_fill_style_widget_construct( SPWidget *spw, SPPaintSelector */*psel*/ ) +static void fillnstroke_constructed( SPWidget *spw, SPPaintSelector * /*psel*/ ) { #ifdef SP_FS_VERBOSE - g_print ( "Fill style widget constructed: inkscape %p\n", + FillOrStroke kind = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(spw), "kind")) ? FILL : STROKE; + g_print( "[%s] style widget constructed: inkscape %p\n", + (kind == FILL) ? "fill" : "style", spw->inkscape ); #endif if (spw->inkscape) { - sp_fill_style_widget_update (spw); + fillnstroke_performUpdate(spw); } -} // end of sp_fill_style_widget_construct() +} -static void -sp_fill_style_widget_modify_selection( SPWidget *spw, - Inkscape::Selection */*selection*/, - guint flags, - SPPaintSelector */*psel*/ ) +/** + * On signal modified, invokes an update of the fill or stroke style paint object. + */ +static void fillnstroke_selection_modified( SPWidget *spw, + Inkscape::Selection * /*selection*/, + guint flags, + SPPaintSelector * /*psel*/ ) { if (flags & ( SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_PARENT_MODIFIED_FLAG | - SP_OBJECT_STYLE_MODIFIED_FLAG) ) - { + SP_OBJECT_STYLE_MODIFIED_FLAG) ) { #ifdef SP_FS_VERBOSE - g_message("sp_fill_style_widget_modify_selection()"); + g_message("fillnstroke_selection_modified()"); #endif - sp_fill_style_widget_update (spw); + fillnstroke_performUpdate(spw); } } -static void -sp_fill_style_widget_change_subselection( Inkscape::Application */*inkscape*/, - SPDesktop */*desktop*/, - SPWidget *spw ) +/** + * On signal selection changed, invokes an update of the fill or stroke style paint object. + */ +static void fillnstroke_selection_changed( SPWidget *spw, + Inkscape::Selection * /*selection*/, + SPPaintSelector * /*psel*/ ) { - sp_fill_style_widget_update (spw); + fillnstroke_performUpdate(spw); } -static void -sp_fill_style_widget_change_selection( SPWidget *spw, - Inkscape::Selection */*selection*/, - SPPaintSelector */*psel*/ ) +/** + * On signal change subselection, invoke an update of the fill or stroke style widget. + */ +static void fillnstroke_subselection_changed( Inkscape::Application * /*inkscape*/, + SPDesktop * /*desktop*/, + SPWidget *spw ) { - sp_fill_style_widget_update (spw); + fillnstroke_performUpdate(spw); } /** -* \param sel Selection to use, or NULL. -*/ -static void -sp_fill_style_widget_update (SPWidget *spw) + * Gets the active fill or stroke style property, then sets the appropriate + * color, alpha, gradient, pattern, etc. for the paint-selector. + * + * @param sel Selection to use, or NULL. + */ +static void fillnstroke_performUpdate( SPWidget *spw ) { - if (g_object_get_data (G_OBJECT (spw), "update")) + if ( g_object_get_data(G_OBJECT(spw), "update") ) { return; + } - if (g_object_get_data (G_OBJECT (spw), "local")) { - g_object_set_data (G_OBJECT (spw), "local", GINT_TO_POINTER (FALSE)); // local change; do nothing, but reset the flag - return; + FillOrStroke kind = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(spw), "kind")) ? FILL : STROKE; + + if (kind == FILL) { + if ( g_object_get_data(G_OBJECT(spw), "local") ) { + g_object_set_data(G_OBJECT(spw), "local", GINT_TO_POINTER(FALSE)); // local change; do nothing, but reset the flag + return; + } } - g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (TRUE)); + g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE)); - SPPaintSelector *psel = SP_PAINT_SELECTOR (g_object_get_data (G_OBJECT (spw), "paint-selector")); + SPPaintSelector *psel = SP_PAINT_SELECTOR(g_object_get_data(G_OBJECT(spw), "paint-selector")); // create temporary style - SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); + SPStyle *query = sp_style_new(SP_ACTIVE_DOCUMENT); + // query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection - int result = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FILL); + int result = sp_desktop_query_style(SP_ACTIVE_DESKTOP, query, (kind == FILL) ? QUERY_STYLE_PROPERTY_FILL : QUERY_STYLE_PROPERTY_STROKE); + + SPIPaint &targPaint = (kind == FILL) ? query->fill : query->stroke; + SPIScale24 &targOpacity = (kind == FILL) ? query->fill_opacity : query->stroke_opacity; switch (result) { case QUERY_STYLE_NOTHING: @@ -201,37 +226,39 @@ sp_fill_style_widget_update (SPWidget *spw) case QUERY_STYLE_MULTIPLE_AVERAGED: // TODO: treat this slightly differently, e.g. display "averaged" somewhere in paint selector case QUERY_STYLE_MULTIPLE_SAME: { - SPPaintSelector::Mode pselmode = SPPaintSelector::getModeForStyle(*query, true); + SPPaintSelector::Mode pselmode = SPPaintSelector::getModeForStyle(*query, kind == FILL); psel->setMode(pselmode); - psel->setFillrule(query->fill_rule.computed == ART_WIND_RULE_NONZERO? - SPPaintSelector::FILLRULE_NONZERO : SPPaintSelector::FILLRULE_EVENODD); + if (kind == FILL) { + psel->setFillrule(query->fill_rule.computed == ART_WIND_RULE_NONZERO? + SPPaintSelector::FILLRULE_NONZERO : SPPaintSelector::FILLRULE_EVENODD); + } - if (query->fill.set && query->fill.isColor()) { - psel->setColorAlpha(query->fill.value.color, SP_SCALE24_TO_FLOAT(query->fill_opacity.value)); - } else if (query->fill.set && query->fill.isPaintserver()) { + if (targPaint.set && targPaint.isColor()) { + psel->setColorAlpha(targPaint.value.color, SP_SCALE24_TO_FLOAT(targOpacity.value)); + } else if (targPaint.set && targPaint.isPaintserver()) { - SPPaintServer *server = query->getFillPaintServer(); + SPPaintServer *server = (kind == FILL) ? query->getFillPaintServer() : query->getStrokePaintServer(); if (server && SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()) { SPGradient *vector = SP_GRADIENT(server)->getVector(); psel->setSwatch( vector ); - } else if (SP_IS_LINEARGRADIENT (server)) { + } else if (SP_IS_LINEARGRADIENT(server)) { SPGradient *vector = SP_GRADIENT(server)->getVector(); psel->setGradientLinear( vector ); - SPLinearGradient *lg = SP_LINEARGRADIENT (server); + SPLinearGradient *lg = SP_LINEARGRADIENT(server); psel->setGradientProperties( SP_GRADIENT_UNITS(lg), SP_GRADIENT_SPREAD(lg) ); - } else if (SP_IS_RADIALGRADIENT (server)) { + } else if (SP_IS_RADIALGRADIENT(server)) { SPGradient *vector = SP_GRADIENT(server)->getVector(); psel->setGradientRadial( vector ); - SPRadialGradient *rg = SP_RADIALGRADIENT (server); - psel->setGradientProperties( SP_GRADIENT_UNITS (rg), - SP_GRADIENT_SPREAD (rg) ); - } else if (SP_IS_PATTERN (server)) { - SPPattern *pat = pattern_getroot (SP_PATTERN (server)); + SPRadialGradient *rg = SP_RADIALGRADIENT(server); + psel->setGradientProperties( SP_GRADIENT_UNITS(rg), + SP_GRADIENT_SPREAD(rg) ); + } else if (SP_IS_PATTERN(server)) { + SPPattern *pat = pattern_getroot(SP_PATTERN(server)); psel->updatePatternList( pat ); } } @@ -247,101 +274,112 @@ sp_fill_style_widget_update (SPWidget *spw) sp_style_unref(query); - g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (FALSE)); - + g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); } - -static void -sp_fill_style_widget_paint_mode_changed( SPPaintSelector *psel, - SPPaintSelector::Mode /*mode*/, - SPWidget *spw ) +/** + * When the mode is changed, invoke a regular changed handler. + */ +static void fillnstroke_paint_mode_changed( SPPaintSelector *psel, + SPPaintSelector::Mode /*mode*/, + SPWidget *spw ) { - if (g_object_get_data (G_OBJECT (spw), "update")) + if (g_object_get_data(G_OBJECT(spw), "update")) { return; + } #ifdef SP_FS_VERBOSE - g_message("sp_fill_style_widget_paint_mode_changed(psel:%p, mode, spw:%p)", psel, spw); + g_message("fillnstroke_paint_mode_changed(psel:%p, mode, spw:%p)", psel, spw); #endif - /* TODO: Does this work? */ - /* TODO: Not really, here we have to get old color back from object */ - /* Instead of relying on paint widget having meaningful colors set */ - sp_fill_style_widget_paint_changed (psel, spw); + /* TODO: Does this work? + * Not really, here we have to get old color back from object + * Instead of relying on paint widget having meaningful colors set + */ + fillnstroke_paint_changed(psel, spw); } -static void sp_fill_style_widget_fillrule_changed( SPPaintSelector */*psel*/, - SPPaintSelector::FillRule mode, - SPWidget *spw ) +static void fillnstroke_fillrule_changed( SPPaintSelector * /*psel*/, + SPPaintSelector::FillRule mode, + SPWidget *spw ) { - if (g_object_get_data (G_OBJECT (spw), "update")) + if (g_object_get_data(G_OBJECT(spw), "update")) { return; + } SPDesktop *desktop = SP_ACTIVE_DESKTOP; - SPCSSAttr *css = sp_repr_css_attr_new (); + SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-rule", mode == SPPaintSelector::FILLRULE_EVENODD? "evenodd":"nonzero"); - sp_desktop_set_style (desktop, css); + sp_desktop_set_style(desktop, css); - sp_repr_css_attr_unref (css); + sp_repr_css_attr_unref(css); + css = 0; - sp_document_done (SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_FILL_STROKE, - _("Change fill rule")); + sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_FILL_STROKE, + _("Change fill rule")); } -static gchar const *undo_label_1 = "fill:flatcolor:1"; -static gchar const *undo_label_2 = "fill:flatcolor:2"; -static gchar const *undo_label = undo_label_1; +static gchar const *undo_F_label_1 = "fill:flatcolor:1"; +static gchar const *undo_F_label_2 = "fill:flatcolor:2"; + +static gchar const *undo_S_label_1 = "stroke:flatcolor:1"; +static gchar const *undo_S_label_2 = "stroke:flatcolor:2"; + +static gchar const *undo_F_label = undo_F_label_1; +static gchar const *undo_S_label = undo_S_label_1; /** -This is called repeatedly while you are dragging a color slider, only for flat color -modes. Previously it set the color in style but did not update the repr for efficiency, however -this was flakey and didn't buy us almost anything. So now it does the same as _changed, except -lumps all its changes for undo. + * This is called repeatedly while you are dragging a color slider, only for flat color + * modes. Previously it set the color in style but did not update the repr for efficiency, however + * this was flakey and didn't buy us almost anything. So now it does the same as _changed, except + * lumps all its changes for undo. */ -static void -sp_fill_style_widget_paint_dragged (SPPaintSelector *psel, SPWidget *spw) +static void fillnstroke_paint_dragged(SPPaintSelector *psel, SPWidget *spw) { if (!spw->inkscape) { return; } - if (g_object_get_data (G_OBJECT (spw), "update")) { + if (g_object_get_data(G_OBJECT(spw), "update")) { return; } - if (g_object_get_data (G_OBJECT (spw), "local")) { - // previous local flag not cleared yet; - // this means dragged events come too fast, so we better skip this one to speed up display - // (it's safe to do this in any case) - return; + FillOrStroke kind = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(spw), "kind")) ? FILL : STROKE; + + if (kind == FILL) { + if (g_object_get_data(G_OBJECT(spw), "local")) { + // previous local flag not cleared yet; + // this means dragged events come too fast, so we better skip this one to speed up display + // (it's safe to do this in any case) + return; + } } - g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (TRUE)); + g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE)); switch (psel->mode) { - case SPPaintSelector::MODE_COLOR_RGB: case SPPaintSelector::MODE_COLOR_CMYK: { - psel->setFlatColor( SP_ACTIVE_DESKTOP, "fill", "fill-opacity" ); - sp_document_maybe_done (sp_desktop_document(SP_ACTIVE_DESKTOP), undo_label, SP_VERB_DIALOG_FILL_STROKE, - _("Set fill color")); - g_object_set_data (G_OBJECT (spw), "local", GINT_TO_POINTER (TRUE)); // local change, do not update from selection + psel->setFlatColor( SP_ACTIVE_DESKTOP, (kind == FILL) ? "fill" : "stroke", (kind == FILL) ? "fill-opacity" : "stroke-opacity" ); + sp_document_maybe_done(sp_desktop_document(SP_ACTIVE_DESKTOP), (kind == FILL) ? undo_F_label : undo_S_label, SP_VERB_DIALOG_FILL_STROKE, + (kind == FILL) ? _("Set fill color") : _("Set stroke color")); + if (kind == FILL) { + g_object_set_data(G_OBJECT(spw), "local", GINT_TO_POINTER(TRUE)); // local change, do not update from selection + } break; } default: - g_warning ( "file %s: line %d: Paint %d should not emit 'dragged'", - __FILE__, __LINE__, psel->mode ); + g_warning( "file %s: line %d: Paint %d should not emit 'dragged'", + __FILE__, __LINE__, psel->mode ); break; - } - g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (FALSE)); + g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); } - /** This is called (at least) when: 1 paint selector mode is switched (e.g. flat color -> gradient) @@ -349,33 +387,32 @@ This is called (at least) when: 3 you changed a gradient selector parameter (e.g. spread) Must update repr. */ -static void -sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, - SPWidget *spw ) +static void fillnstroke_paint_changed( SPPaintSelector *psel, SPWidget *spw ) { #ifdef SP_FS_VERBOSE - g_message("sp_fill_style_widget_paint_changed(psel:%p, spw:%p)", psel, spw); + g_message("fillnstroke_paint_changed(psel:%p, spw:%p)", psel, spw); #endif - if (g_object_get_data (G_OBJECT (spw), "update")) { + if (g_object_get_data(G_OBJECT(spw), "update")) { return; } - g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (TRUE)); + g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE)); + + FillOrStroke kind = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(spw), "kind")) ? FILL : STROKE; SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (!desktop) { return; } - SPDocument *document = sp_desktop_document (desktop); - Inkscape::Selection *selection = sp_desktop_selection (desktop); + SPDocument *document = sp_desktop_document(desktop); + Inkscape::Selection *selection = sp_desktop_selection(desktop); GSList const *items = selection->itemList(); switch (psel->mode) { - case SPPaintSelector::MODE_EMPTY: // This should not happen. - g_warning ( "file %s: line %d: Paint %d should not emit 'changed'", - __FILE__, __LINE__, psel->mode); + g_warning( "file %s: line %d: Paint %d should not emit 'changed'", + __FILE__, __LINE__, psel->mode); break; case SPPaintSelector::MODE_MULTIPLE: // This happens when you switch multiple objects with different gradients to flat color; @@ -384,35 +421,46 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, case SPPaintSelector::MODE_NONE: { - SPCSSAttr *css = sp_repr_css_attr_new (); - sp_repr_css_set_property (css, "fill", "none"); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property(css, (kind == FILL) ? "fill" : "stroke", "none"); - sp_desktop_set_style (desktop, css); + sp_desktop_set_style(desktop, css); - sp_repr_css_attr_unref (css); + sp_repr_css_attr_unref(css); + css = 0; - sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE, - _("Remove fill")); + sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE, + (kind == FILL) ? _("Remove fill") : _("Remove stroke")); break; } case SPPaintSelector::MODE_COLOR_RGB: case SPPaintSelector::MODE_COLOR_CMYK: { - // FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed; here it results in losing release events - sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(desktop), 0); + if (kind == FILL) { + // FIXME: fix for GTK breakage, see comment in SelectedStyle::on_opacity_changed; here it results in losing release events + sp_canvas_force_full_redraw_after_interruptions(sp_desktop_canvas(desktop), 0); + } + + psel->setFlatColor( desktop, + (kind == FILL) ? "fill" : "stroke", + (kind == FILL) ? "fill-opacity" : "stroke-opacity" ); + sp_document_maybe_done(sp_desktop_document(desktop), (kind == FILL) ? undo_F_label : undo_S_label, SP_VERB_DIALOG_FILL_STROKE, + (kind == FILL) ? _("Set fill color") : _("Set stroke color")); - psel->setFlatColor( desktop, "fill", "fill-opacity" ); - sp_document_maybe_done (sp_desktop_document(desktop), undo_label, SP_VERB_DIALOG_FILL_STROKE, - _("Set fill color")); - // resume interruptibility - sp_canvas_end_forced_full_redraws(sp_desktop_canvas(desktop)); + if (kind == FILL) { + // resume interruptibility + sp_canvas_end_forced_full_redraws(sp_desktop_canvas(desktop)); + } // on release, toggle undo_label so that the next drag will not be lumped with this one - if (undo_label == undo_label_1) - undo_label = undo_label_2; - else - undo_label = undo_label_1; + if (undo_F_label == undo_F_label_1) { + undo_F_label = undo_F_label_2; + undo_S_label = undo_S_label_2; + } else { + undo_F_label = undo_F_label_1; + undo_S_label = undo_S_label_1; + } break; } @@ -425,22 +473,26 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, ? SP_GRADIENT_TYPE_LINEAR : SP_GRADIENT_TYPE_RADIAL ); - // HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs - SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_set_property(css, "fill-opacity", "1.0"); + SPCSSAttr *css = 0; + if (kind == FILL) { + // HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs + css = sp_repr_css_attr_new(); + sp_repr_css_set_property(css, "fill-opacity", "1.0"); + } SPGradient *vector = psel->getGradientVector(); if (!vector) { /* No vector in paint selector should mean that we just changed mode */ - SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); - int result = objects_query_fillstroke ((GSList *) items, query, true); + SPStyle *query = sp_style_new(SP_ACTIVE_DOCUMENT); + int result = objects_query_fillstroke(const_cast(items), query, kind == FILL); + SPIPaint &targPaint = (kind == FILL) ? query->fill : query->stroke; guint32 common_rgb = 0; if (result == QUERY_STYLE_MULTIPLE_SAME) { - if (!query->fill.isColor()) { - common_rgb = sp_desktop_get_color(desktop, true); + if (!targPaint.isColor()) { + common_rgb = sp_desktop_get_color(desktop, kind == FILL); } else { - common_rgb = query->fill.value.color.toRGBA32( 0xff ); + common_rgb = targPaint.value.color.toRGBA32( 0xff ); } vector = sp_document_default_gradient_vector(document, common_rgb); } @@ -448,33 +500,40 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, for (GSList const *i = items; i != NULL; i = i->next) { //FIXME: see above - sp_repr_css_change_recursive(SP_OBJECT_REPR(i->data), css, "style"); + if (kind == FILL) { + sp_repr_css_change_recursive(SP_OBJECT_REPR(i->data), css, "style"); + } if (!vector) { sp_item_set_gradient(SP_ITEM(i->data), - sp_gradient_vector_for_object(document, desktop, SP_OBJECT(i->data), true), - gradient_type, true); + sp_gradient_vector_for_object(document, desktop, SP_OBJECT(i->data), kind == FILL), + gradient_type, kind == FILL); } else { - sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, true); + sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, kind == FILL); } } } else { - /* We have changed from another gradient type, or modified spread/units within - * this gradient type. */ - vector = sp_gradient_ensure_vector_normalized (vector); + // We have changed from another gradient type, or modified spread/units within + // this gradient type. + vector = sp_gradient_ensure_vector_normalized(vector); for (GSList const *i = items; i != NULL; i = i->next) { //FIXME: see above - sp_repr_css_change_recursive (SP_OBJECT_REPR (i->data), css, "style"); + if (kind == FILL) { + sp_repr_css_change_recursive(SP_OBJECT_REPR(i->data), css, "style"); + } - SPGradient *gr = sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, true); + SPGradient *gr = sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, kind == FILL); psel->pushAttrsToGradient( gr ); } } - sp_repr_css_attr_unref (css); + if (css) { + sp_repr_css_attr_unref(css); + css = 0; + } - sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE, - _("Set gradient on fill")); + sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE, + (kind == FILL) ? _("Set gradient on fill") : _("Set gradient on stroke")); } break; @@ -491,66 +550,101 @@ sp_fill_style_widget_paint_changed ( SPPaintSelector *psel, } else { Inkscape::XML::Node *patrepr = SP_OBJECT_REPR(pattern); - SPCSSAttr *css = sp_repr_css_attr_new (); - gchar *urltext = g_strdup_printf ("url(#%s)", patrepr->attribute("id")); - sp_repr_css_set_property (css, "fill", urltext); + SPCSSAttr *css = sp_repr_css_attr_new(); + gchar *urltext = g_strdup_printf("url(#%s)", patrepr->attribute("id")); + sp_repr_css_set_property(css, (kind == FILL) ? "fill" : "stroke", urltext); // HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs - sp_repr_css_set_property(css, "fill-opacity", "1.0"); + if (kind == FILL) { + sp_repr_css_set_property(css, "fill-opacity", "1.0"); + } // cannot just call sp_desktop_set_style, because we don't want to touch those // objects who already have the same root pattern but through a different href // chain. FIXME: move this to a sp_item_set_pattern for (GSList const *i = items; i != NULL; i = i->next) { - SPObject *selobj = SP_OBJECT (i->data); - - SPStyle *style = SP_OBJECT_STYLE (selobj); - if (style && style->fill.isPaintserver()) { - SPObject *server = SP_OBJECT_STYLE_FILL_SERVER (selobj); - if (SP_IS_PATTERN (server) && pattern_getroot (SP_PATTERN(server)) == pattern) + Inkscape::XML::Node *selrepr = SP_OBJECT_REPR(i->data); + if ( (kind == STROKE) && !selrepr) { + continue; + } + SPObject *selobj = SP_OBJECT(i->data); + + SPStyle *style = SP_OBJECT_STYLE(selobj); + if (style && ((kind == FILL) ? style->fill : style->stroke).isPaintserver()) { + SPObject *server = (kind == FILL) ? + SP_OBJECT_STYLE_FILL_SERVER(selobj) : + SP_OBJECT_STYLE_STROKE_SERVER(selobj); + if (SP_IS_PATTERN(server) && pattern_getroot(SP_PATTERN(server)) == pattern) // only if this object's pattern is not rooted in our selected pattern, apply - continue; - } + continue; + } - sp_desktop_apply_css_recursive (selobj, css, true); - } + if (kind == FILL) { + sp_desktop_apply_css_recursive(selobj, css, true); + } else { + sp_repr_css_change_recursive(selrepr, css, "style"); + } + } - sp_repr_css_attr_unref (css); - g_free (urltext); + sp_repr_css_attr_unref(css); + css = 0; + g_free(urltext); } // end if - sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE, - _("Set pattern on fill")); - + sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE, + (kind == FILL) ? _("Set pattern on fill") : + _("Set pattern on stroke")); } // end if break; case SPPaintSelector::MODE_UNSET: if (items) { - SPCSSAttr *css = sp_repr_css_attr_new (); - sp_repr_css_unset_property (css, "fill"); + SPCSSAttr *css = sp_repr_css_attr_new(); + if (kind == FILL) { + sp_repr_css_unset_property(css, "fill"); + } else { + sp_repr_css_unset_property(css, "stroke"); + sp_repr_css_unset_property(css, "stroke-opacity"); + sp_repr_css_unset_property(css, "stroke-width"); + sp_repr_css_unset_property(css, "stroke-miterlimit"); + sp_repr_css_unset_property(css, "stroke-linejoin"); + sp_repr_css_unset_property(css, "stroke-linecap"); + sp_repr_css_unset_property(css, "stroke-dashoffset"); + sp_repr_css_unset_property(css, "stroke-dasharray"); + } - sp_desktop_set_style (desktop, css); - sp_repr_css_attr_unref (css); + sp_desktop_set_style(desktop, css); + sp_repr_css_attr_unref(css); + css = 0; - sp_document_done (document, SP_VERB_DIALOG_FILL_STROKE, - _("Unset fill")); + sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE, + (kind == FILL) ? _("Unset fill") : _("Unset stroke")); } break; default: - g_warning ( "file %s: line %d: Paint selector should not be in " - "mode %d", - __FILE__, __LINE__, psel->mode ); + g_warning( "file %s: line %d: Paint selector should not be in " + "mode %d", + __FILE__, __LINE__, + psel->mode ); break; } - g_object_set_data (G_OBJECT (spw), "update", GINT_TO_POINTER (FALSE)); + g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); } +static void fillnstroke_transientize_called(Inkscape::Application * /*inkscape*/, + SPDesktop * /*desktop*/, + SPWidget * /*spw*/ ) +{ +// TODO: Either of these will cause crashes sometimes +// sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? sp_desktop_selection(desktop) : NULL); +// ink_markers_menu_update(spw); +} + /* Local Variables: mode:c++ -- cgit v1.2.3 From 6f7686718768091807fabc8437d53e54ef220bbe Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 27 Mar 2010 13:56:03 -0700 Subject: Phase 2b - remove use of SPWidget and wire signals directly. (bzr r9241) --- src/widgets/fill-style.cpp | 113 +++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 76 deletions(-) (limited to 'src/widgets/fill-style.cpp') diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index 09c6951ad..6ea9f30b5 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -19,6 +19,7 @@ #endif #include +#include #include "desktop-handles.h" #include "desktop-style.h" @@ -32,7 +33,6 @@ #include "sp-radial-gradient.h" #include "style.h" #include "widgets/paint-selector.h" -#include "widgets/sp-widget.h" #include "xml/repr.h" #include "fill-style.h" @@ -45,20 +45,17 @@ /* Fill */ -static void fillnstroke_constructed(SPWidget *spw, SPPaintSelector *psel); -static void fillnstroke_fillrule_changed(SPPaintSelector *psel, SPPaintSelector::FillRule mode, SPWidget *spw); +static void fillnstroke_fillrule_changed(SPPaintSelector *psel, SPPaintSelector::FillRule mode, GtkWidget *spw); -static void fillnstroke_selection_modified(SPWidget *spw, Inkscape::Selection *selection, guint flags, SPPaintSelector *psel); -static void fillnstroke_selection_changed(SPWidget *spw, Inkscape::Selection *selection, SPPaintSelector *psel); -static void fillnstroke_subselection_changed(Inkscape::Application *inkscape, SPDesktop *desktop, SPWidget *spw); +static void fillnstroke_selection_modified(Inkscape::Application *inkscape, Inkscape::Selection *selection, guint flags, GtkWidget *spw); +static void fillnstroke_selection_changed(Inkscape::Application *inkscape, Inkscape::Selection *selection, GtkWidget *spw); +static void fillnstroke_subselection_changed(Inkscape::Application *inkscape, SPDesktop *desktop, GtkWidget *spw); -static void fillnstroke_paint_mode_changed(SPPaintSelector *psel, SPPaintSelector::Mode mode, SPWidget *spw); -static void fillnstroke_paint_dragged(SPPaintSelector *psel, SPWidget *spw); -static void fillnstroke_paint_changed(SPPaintSelector *psel, SPWidget *spw); +static void fillnstroke_paint_mode_changed(SPPaintSelector *psel, SPPaintSelector::Mode mode, GtkWidget *spw); +static void fillnstroke_paint_dragged(SPPaintSelector *psel, GtkWidget *spw); +static void fillnstroke_paint_changed(SPPaintSelector *psel, GtkWidget *spw); -static void fillnstroke_transientize_called(Inkscape::Application *inkscape, SPDesktop *desktop, SPWidget *spw); - -static void fillnstroke_performUpdate(SPWidget *spw); +static void fillnstroke_performUpdate(GtkWidget *spw); GtkWidget *sp_fill_style_widget_new(void) { @@ -70,7 +67,8 @@ GtkWidget *sp_fill_style_widget_new(void) */ GtkWidget *Inkscape::Widgets::createStyleWidget( FillOrStroke kind ) { - GtkWidget *spw = sp_widget_new_global(INKSCAPE); + Inkscape::Application *appInstance = INKSCAPE; + GtkWidget *spw = gtk_vbox_new(FALSE, 0); // with or without fillrule selector GtkWidget *psel = sp_paint_selector_new(kind == FILL); @@ -79,32 +77,18 @@ GtkWidget *Inkscape::Widgets::createStyleWidget( FillOrStroke kind ) g_object_set_data(G_OBJECT(spw), "paint-selector", psel); g_object_set_data(G_OBJECT(spw), "kind", GINT_TO_POINTER(kind)); - if (kind == FILL) { - g_signal_connect( G_OBJECT(spw), "construct", - G_CALLBACK(fillnstroke_constructed), - psel ); - } - -//FIXME: switch these from spw signals to global inkscape object signals; spw just retranslates -//those anyway; then eliminate spw - g_signal_connect( G_OBJECT(spw), "modify_selection", + g_signal_connect( G_OBJECT(appInstance), "modify_selection", G_CALLBACK(fillnstroke_selection_modified), - psel ); + spw ); - g_signal_connect( G_OBJECT(spw), "change_selection", + g_signal_connect( G_OBJECT(appInstance), "change_selection", G_CALLBACK(fillnstroke_selection_changed), - psel ); + spw ); - g_signal_connect( INKSCAPE, "change_subselection", + g_signal_connect( G_OBJECT(appInstance), "change_subselection", G_CALLBACK(fillnstroke_subselection_changed), spw ); - if (kind == STROKE) { - g_signal_connect( G_OBJECT(INKSCAPE), "activate_desktop", - G_CALLBACK(fillnstroke_transientize_called), - spw ); - } - g_signal_connect( G_OBJECT(psel), "mode_changed", G_CALLBACK(fillnstroke_paint_mode_changed), spw ); @@ -123,32 +107,18 @@ GtkWidget *Inkscape::Widgets::createStyleWidget( FillOrStroke kind ) spw ); } - fillnstroke_performUpdate(SP_WIDGET(spw)); + fillnstroke_performUpdate(spw); return spw; } -static void fillnstroke_constructed( SPWidget *spw, SPPaintSelector * /*psel*/ ) -{ -#ifdef SP_FS_VERBOSE - FillOrStroke kind = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(spw), "kind")) ? FILL : STROKE; - g_print( "[%s] style widget constructed: inkscape %p\n", - (kind == FILL) ? "fill" : "style", - spw->inkscape ); -#endif - if (spw->inkscape) { - fillnstroke_performUpdate(spw); - } - -} - /** * On signal modified, invokes an update of the fill or stroke style paint object. */ -static void fillnstroke_selection_modified( SPWidget *spw, - Inkscape::Selection * /*selection*/, - guint flags, - SPPaintSelector * /*psel*/ ) +void fillnstroke_selection_modified( Inkscape::Application * /*inkscape*/, + Inkscape::Selection * /*selection*/, + guint flags, + GtkWidget *spw ) { if (flags & ( SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_PARENT_MODIFIED_FLAG | @@ -163,9 +133,9 @@ static void fillnstroke_selection_modified( SPWidget *spw, /** * On signal selection changed, invokes an update of the fill or stroke style paint object. */ -static void fillnstroke_selection_changed( SPWidget *spw, - Inkscape::Selection * /*selection*/, - SPPaintSelector * /*psel*/ ) +void fillnstroke_selection_changed( Inkscape::Application * /*inkscape*/, + Inkscape::Selection */*selection*/, + GtkWidget *spw ) { fillnstroke_performUpdate(spw); } @@ -173,9 +143,9 @@ static void fillnstroke_selection_changed( SPWidget *spw, /** * On signal change subselection, invoke an update of the fill or stroke style widget. */ -static void fillnstroke_subselection_changed( Inkscape::Application * /*inkscape*/, - SPDesktop * /*desktop*/, - SPWidget *spw ) +void fillnstroke_subselection_changed( Inkscape::Application * /*inkscape*/, + SPDesktop * /*desktop*/, + GtkWidget *spw ) { fillnstroke_performUpdate(spw); } @@ -186,7 +156,7 @@ static void fillnstroke_subselection_changed( Inkscape::Application * /*inkscape * * @param sel Selection to use, or NULL. */ -static void fillnstroke_performUpdate( SPWidget *spw ) +void fillnstroke_performUpdate( GtkWidget *spw ) { if ( g_object_get_data(G_OBJECT(spw), "update") ) { return; @@ -280,9 +250,9 @@ static void fillnstroke_performUpdate( SPWidget *spw ) /** * When the mode is changed, invoke a regular changed handler. */ -static void fillnstroke_paint_mode_changed( SPPaintSelector *psel, - SPPaintSelector::Mode /*mode*/, - SPWidget *spw ) +void fillnstroke_paint_mode_changed( SPPaintSelector *psel, + SPPaintSelector::Mode /*mode*/, + GtkWidget *spw ) { if (g_object_get_data(G_OBJECT(spw), "update")) { return; @@ -299,9 +269,9 @@ static void fillnstroke_paint_mode_changed( SPPaintSelector *psel, fillnstroke_paint_changed(psel, spw); } -static void fillnstroke_fillrule_changed( SPPaintSelector * /*psel*/, - SPPaintSelector::FillRule mode, - SPWidget *spw ) +void fillnstroke_fillrule_changed( SPPaintSelector * /*psel*/, + SPPaintSelector::FillRule mode, + GtkWidget *spw ) { if (g_object_get_data(G_OBJECT(spw), "update")) { return; @@ -336,9 +306,9 @@ static gchar const *undo_S_label = undo_S_label_1; * this was flakey and didn't buy us almost anything. So now it does the same as _changed, except * lumps all its changes for undo. */ -static void fillnstroke_paint_dragged(SPPaintSelector *psel, SPWidget *spw) +void fillnstroke_paint_dragged(SPPaintSelector *psel, GtkWidget *spw) { - if (!spw->inkscape) { + if (!INKSCAPE) { return; } @@ -387,7 +357,7 @@ This is called (at least) when: 3 you changed a gradient selector parameter (e.g. spread) Must update repr. */ -static void fillnstroke_paint_changed( SPPaintSelector *psel, SPWidget *spw ) +void fillnstroke_paint_changed( SPPaintSelector *psel, GtkWidget *spw ) { #ifdef SP_FS_VERBOSE g_message("fillnstroke_paint_changed(psel:%p, spw:%p)", psel, spw); @@ -636,15 +606,6 @@ static void fillnstroke_paint_changed( SPPaintSelector *psel, SPWidget *spw ) } -static void fillnstroke_transientize_called(Inkscape::Application * /*inkscape*/, - SPDesktop * /*desktop*/, - SPWidget * /*spw*/ ) -{ -// TODO: Either of these will cause crashes sometimes -// sp_stroke_style_line_update( SP_WIDGET(spw), desktop ? sp_desktop_selection(desktop) : NULL); -// ink_markers_menu_update(spw); -} - /* Local Variables: mode:c++ -- cgit v1.2.3 From 58133b417e94e0bc15fb1624a9d6bbd7613cca5d Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 27 Mar 2010 17:42:22 -0700 Subject: Phase 3 - Convert to C++ class, but still using C-style callbacks and signals. (bzr r9244) --- src/widgets/fill-style.cpp | 270 +++++++++++++++++++++++++-------------------- 1 file changed, 150 insertions(+), 120 deletions(-) (limited to 'src/widgets/fill-style.cpp') diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index 6ea9f30b5..552668a88 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -5,9 +5,11 @@ * Lauris Kaplinski * Frank Felfe * bulia byak + * Jon A. Cruz * * Copyright (C) 1999-2005 authors * Copyright (C) 2001-2002 Ximian, Inc. + * Copyright (C) 2010 Jon A. Cruz * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -19,6 +21,7 @@ #endif #include +#include #include #include "desktop-handles.h" @@ -45,17 +48,37 @@ /* Fill */ -static void fillnstroke_fillrule_changed(SPPaintSelector *psel, SPPaintSelector::FillRule mode, GtkWidget *spw); -static void fillnstroke_selection_modified(Inkscape::Application *inkscape, Inkscape::Selection *selection, guint flags, GtkWidget *spw); -static void fillnstroke_selection_changed(Inkscape::Application *inkscape, Inkscape::Selection *selection, GtkWidget *spw); -static void fillnstroke_subselection_changed(Inkscape::Application *inkscape, SPDesktop *desktop, GtkWidget *spw); -static void fillnstroke_paint_mode_changed(SPPaintSelector *psel, SPPaintSelector::Mode mode, GtkWidget *spw); -static void fillnstroke_paint_dragged(SPPaintSelector *psel, GtkWidget *spw); -static void fillnstroke_paint_changed(SPPaintSelector *psel, GtkWidget *spw); +class FillNStroke : public Gtk::VBox +{ +public: + FillNStroke( FillOrStroke kind ); + ~FillNStroke(); + + void setFillrule( SPPaintSelector::FillRule mode ); + +private: + static void paintModeChangeCB(SPPaintSelector *psel, SPPaintSelector::Mode mode, FillNStroke *self); + static void paintChangedCB(SPPaintSelector *psel, FillNStroke *self); + static void paintDraggedCB(SPPaintSelector *psel, FillNStroke *self); + + static void fillruleChangedCB( SPPaintSelector *psel, SPPaintSelector::FillRule mode, FillNStroke *self ); + + static void selectionModifiedCB(Inkscape::Application *inkscape, Inkscape::Selection *selection, guint flags, FillNStroke *self); + static void selectionChangedCB(Inkscape::Application *inkscape, void * data, FillNStroke *self); + + void dragFromPaint(); + void updateFromPaint(); + + void performUpdate(); + + FillOrStroke kind; + SPPaintSelector *psel; + bool update; + bool local; +}; -static void fillnstroke_performUpdate(GtkWidget *spw); GtkWidget *sp_fill_style_widget_new(void) { @@ -67,87 +90,92 @@ GtkWidget *sp_fill_style_widget_new(void) */ GtkWidget *Inkscape::Widgets::createStyleWidget( FillOrStroke kind ) { - Inkscape::Application *appInstance = INKSCAPE; - GtkWidget *spw = gtk_vbox_new(FALSE, 0); - - // with or without fillrule selector - GtkWidget *psel = sp_paint_selector_new(kind == FILL); - gtk_widget_show(psel); - gtk_container_add(GTK_CONTAINER(spw), psel); - g_object_set_data(G_OBJECT(spw), "paint-selector", psel); - g_object_set_data(G_OBJECT(spw), "kind", GINT_TO_POINTER(kind)); - - g_signal_connect( G_OBJECT(appInstance), "modify_selection", - G_CALLBACK(fillnstroke_selection_modified), - spw ); + FillNStroke *filler = Gtk::manage(new FillNStroke(kind)); - g_signal_connect( G_OBJECT(appInstance), "change_selection", - G_CALLBACK(fillnstroke_selection_changed), - spw ); - - g_signal_connect( G_OBJECT(appInstance), "change_subselection", - G_CALLBACK(fillnstroke_subselection_changed), - spw ); + return GTK_WIDGET(filler->gobj()); +} +FillNStroke::FillNStroke( FillOrStroke kind ) : + Gtk::VBox(), + kind(kind), + psel(0), + update(false), + local(false) +{ + // Add and connect up the paint selector widget: + psel = sp_paint_selector_new(kind); + gtk_widget_show(GTK_WIDGET(psel)); + gtk_container_add(GTK_CONTAINER(gobj()), GTK_WIDGET(psel)); g_signal_connect( G_OBJECT(psel), "mode_changed", - G_CALLBACK(fillnstroke_paint_mode_changed), - spw ); + G_CALLBACK(paintModeChangeCB), + this ); g_signal_connect( G_OBJECT(psel), "dragged", - G_CALLBACK(fillnstroke_paint_dragged), - spw ); + G_CALLBACK(paintDraggedCB), + this ); g_signal_connect( G_OBJECT(psel), "changed", - G_CALLBACK(fillnstroke_paint_changed), - spw ); - + G_CALLBACK(paintChangedCB), + this ); if (kind == FILL) { g_signal_connect( G_OBJECT(psel), "fillrule_changed", - G_CALLBACK(fillnstroke_fillrule_changed), - spw ); + G_CALLBACK(fillruleChangedCB), + this ); } - fillnstroke_performUpdate(spw); + // connect to the app instance to get selection notifications. + // TODO FIXME should really get connected to a Desktop instead. + Inkscape::Application *appInstance = INKSCAPE; + g_signal_connect( G_OBJECT(appInstance), "modify_selection", + G_CALLBACK(selectionModifiedCB), + this ); + + g_signal_connect( G_OBJECT(appInstance), "change_selection", + G_CALLBACK(selectionChangedCB), + this ); + + g_signal_connect( G_OBJECT(appInstance), "change_subselection", + G_CALLBACK(selectionChangedCB), + this ); - return spw; + + performUpdate(); +} + +FillNStroke::~FillNStroke() +{ + psel = 0; } /** * On signal modified, invokes an update of the fill or stroke style paint object. */ -void fillnstroke_selection_modified( Inkscape::Application * /*inkscape*/, - Inkscape::Selection * /*selection*/, - guint flags, - GtkWidget *spw ) +void FillNStroke::selectionModifiedCB( Inkscape::Application * /*inkscape*/, + Inkscape::Selection */*selection*/, + guint flags, + FillNStroke *self ) { - if (flags & ( SP_OBJECT_MODIFIED_FLAG | - SP_OBJECT_PARENT_MODIFIED_FLAG | - SP_OBJECT_STYLE_MODIFIED_FLAG) ) { + if (self && + (flags & ( SP_OBJECT_MODIFIED_FLAG | + SP_OBJECT_PARENT_MODIFIED_FLAG | + SP_OBJECT_STYLE_MODIFIED_FLAG) ) ) { #ifdef SP_FS_VERBOSE - g_message("fillnstroke_selection_modified()"); + g_message("selectionModifiedCB(%p)", self); #endif - fillnstroke_performUpdate(spw); + self->performUpdate(); } } /** - * On signal selection changed, invokes an update of the fill or stroke style paint object. - */ -void fillnstroke_selection_changed( Inkscape::Application * /*inkscape*/, - Inkscape::Selection */*selection*/, - GtkWidget *spw ) -{ - fillnstroke_performUpdate(spw); -} - -/** - * On signal change subselection, invoke an update of the fill or stroke style widget. + * On signal selection changed or subselection changed, invokes an update of the fill or stroke style paint object. */ -void fillnstroke_subselection_changed( Inkscape::Application * /*inkscape*/, - SPDesktop * /*desktop*/, - GtkWidget *spw ) +void FillNStroke::selectionChangedCB( Inkscape::Application * /*inkscape*/, + void * /*data*/, + FillNStroke *self ) { - fillnstroke_performUpdate(spw); + if (self) { + self->performUpdate(); + } } /** @@ -156,24 +184,21 @@ void fillnstroke_subselection_changed( Inkscape::Application * /*inkscape*/, * * @param sel Selection to use, or NULL. */ -void fillnstroke_performUpdate( GtkWidget *spw ) +void FillNStroke::performUpdate() { - if ( g_object_get_data(G_OBJECT(spw), "update") ) { + if ( update ) { return; } - FillOrStroke kind = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(spw), "kind")) ? FILL : STROKE; - if (kind == FILL) { - if ( g_object_get_data(G_OBJECT(spw), "local") ) { - g_object_set_data(G_OBJECT(spw), "local", GINT_TO_POINTER(FALSE)); // local change; do nothing, but reset the flag + // TODO check. This probably should happen for stroke as well as fill. + if ( local ) { + local = false; // local change; do nothing, but reset the flag return; } } - g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE)); - - SPPaintSelector *psel = SP_PAINT_SELECTOR(g_object_get_data(G_OBJECT(spw), "paint-selector")); + update = true; // create temporary style SPStyle *query = sp_style_new(SP_ACTIVE_DOCUMENT); @@ -196,7 +221,7 @@ void fillnstroke_performUpdate( GtkWidget *spw ) case QUERY_STYLE_MULTIPLE_AVERAGED: // TODO: treat this slightly differently, e.g. display "averaged" somewhere in paint selector case QUERY_STYLE_MULTIPLE_SAME: { - SPPaintSelector::Mode pselmode = SPPaintSelector::getModeForStyle(*query, kind == FILL); + SPPaintSelector::Mode pselmode = SPPaintSelector::getModeForStyle(*query, kind); psel->setMode(pselmode); if (kind == FILL) { @@ -244,51 +269,49 @@ void fillnstroke_performUpdate( GtkWidget *spw ) sp_style_unref(query); - g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); + update = false; } /** * When the mode is changed, invoke a regular changed handler. */ -void fillnstroke_paint_mode_changed( SPPaintSelector *psel, +void FillNStroke::paintModeChangeCB( SPPaintSelector * /*psel*/, SPPaintSelector::Mode /*mode*/, - GtkWidget *spw ) + FillNStroke *self ) { - if (g_object_get_data(G_OBJECT(spw), "update")) { - return; - } - #ifdef SP_FS_VERBOSE - g_message("fillnstroke_paint_mode_changed(psel:%p, mode, spw:%p)", psel, spw); + g_message("paintModeChangeCB(psel, mode, self:%p)", self); #endif - - /* TODO: Does this work? - * Not really, here we have to get old color back from object - * Instead of relying on paint widget having meaningful colors set - */ - fillnstroke_paint_changed(psel, spw); + if (self && !self->update) { + self->updateFromPaint(); + } } -void fillnstroke_fillrule_changed( SPPaintSelector * /*psel*/, - SPPaintSelector::FillRule mode, - GtkWidget *spw ) +void FillNStroke::fillruleChangedCB( SPPaintSelector * /*psel*/, + SPPaintSelector::FillRule mode, + FillNStroke *self ) { - if (g_object_get_data(G_OBJECT(spw), "update")) { - return; + if (self) { + self->setFillrule(mode); } +} - SPDesktop *desktop = SP_ACTIVE_DESKTOP; +void FillNStroke::setFillrule( SPPaintSelector::FillRule mode ) +{ + if (!update) { + SPDesktop *desktop = SP_ACTIVE_DESKTOP; - SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_set_property(css, "fill-rule", mode == SPPaintSelector::FILLRULE_EVENODD? "evenodd":"nonzero"); + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property(css, "fill-rule", (mode == SPPaintSelector::FILLRULE_EVENODD) ? "evenodd":"nonzero"); - sp_desktop_set_style(desktop, css); + sp_desktop_set_style(desktop, css); - sp_repr_css_attr_unref(css); - css = 0; + sp_repr_css_attr_unref(css); + css = 0; - sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_FILL_STROKE, - _("Change fill rule")); + sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_FILL_STROKE, + _("Change fill rule")); + } } static gchar const *undo_F_label_1 = "fill:flatcolor:1"; @@ -300,26 +323,31 @@ static gchar const *undo_S_label_2 = "stroke:flatcolor:2"; static gchar const *undo_F_label = undo_F_label_1; static gchar const *undo_S_label = undo_S_label_1; + +void FillNStroke::paintDraggedCB(SPPaintSelector * /*psel*/, FillNStroke *self) +{ +#ifdef SP_FS_VERBOSE + g_message("paintDraggedCB(psel, spw:%p)", self); +#endif + if (self && !self->update) { + self->dragFromPaint(); + } +} + /** * This is called repeatedly while you are dragging a color slider, only for flat color * modes. Previously it set the color in style but did not update the repr for efficiency, however * this was flakey and didn't buy us almost anything. So now it does the same as _changed, except * lumps all its changes for undo. */ -void fillnstroke_paint_dragged(SPPaintSelector *psel, GtkWidget *spw) +void FillNStroke::dragFromPaint() { - if (!INKSCAPE) { + if (!INKSCAPE || update) { return; } - if (g_object_get_data(G_OBJECT(spw), "update")) { - return; - } - - FillOrStroke kind = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(spw), "kind")) ? FILL : STROKE; - if (kind == FILL) { - if (g_object_get_data(G_OBJECT(spw), "local")) { + if (local) { // previous local flag not cleared yet; // this means dragged events come too fast, so we better skip this one to speed up display // (it's safe to do this in any case) @@ -327,7 +355,7 @@ void fillnstroke_paint_dragged(SPPaintSelector *psel, GtkWidget *spw) } } - g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE)); + update = true; switch (psel->mode) { case SPPaintSelector::MODE_COLOR_RGB: @@ -337,7 +365,7 @@ void fillnstroke_paint_dragged(SPPaintSelector *psel, GtkWidget *spw) sp_document_maybe_done(sp_desktop_document(SP_ACTIVE_DESKTOP), (kind == FILL) ? undo_F_label : undo_S_label, SP_VERB_DIALOG_FILL_STROKE, (kind == FILL) ? _("Set fill color") : _("Set stroke color")); if (kind == FILL) { - g_object_set_data(G_OBJECT(spw), "local", GINT_TO_POINTER(TRUE)); // local change, do not update from selection + local = true; // local change, do not update from selection } break; } @@ -347,7 +375,7 @@ void fillnstroke_paint_dragged(SPPaintSelector *psel, GtkWidget *spw) __FILE__, __LINE__, psel->mode ); break; } - g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); + update = false; } /** @@ -357,22 +385,24 @@ This is called (at least) when: 3 you changed a gradient selector parameter (e.g. spread) Must update repr. */ -void fillnstroke_paint_changed( SPPaintSelector *psel, GtkWidget *spw ) +void FillNStroke::paintChangedCB( SPPaintSelector * /*psel*/, FillNStroke *self ) { #ifdef SP_FS_VERBOSE - g_message("fillnstroke_paint_changed(psel:%p, spw:%p)", psel, spw); + g_message("paintChangedCB(psel, spw:%p)", self); #endif - if (g_object_get_data(G_OBJECT(spw), "update")) { - return; + if (self && !self->update) { + self->updateFromPaint(); } - g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(TRUE)); - - FillOrStroke kind = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(spw), "kind")) ? FILL : STROKE; +} +void FillNStroke::updateFromPaint() +{ SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (!desktop) { return; } + update = true; + SPDocument *document = sp_desktop_document(desktop); Inkscape::Selection *selection = sp_desktop_selection(desktop); @@ -602,7 +632,7 @@ void fillnstroke_paint_changed( SPPaintSelector *psel, GtkWidget *spw ) break; } - g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); + update = false; } -- cgit v1.2.3 From ff6d2ea9a273ac0aa3a95ece22cd783a5b49aa23 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 28 Mar 2010 22:00:58 -0700 Subject: Purge use of SP_ACTIVE_* and encapsulate by moving 'active' desktop tracking out of lower-level panels. Fixes bug #270623. Fixed bugs: - https://launchpad.net/bugs/270623 (bzr r9252) --- src/widgets/fill-style.cpp | 120 +++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 53 deletions(-) (limited to 'src/widgets/fill-style.cpp') diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index 552668a88..63def4c87 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -24,6 +24,8 @@ #include #include +#include "desktop.h" +#include "selection.h" #include "desktop-handles.h" #include "desktop-style.h" #include "display/sp-canvas.h" @@ -49,6 +51,13 @@ /* Fill */ +Gtk::Widget *sp_fill_style_widget_new(void) +{ + return Inkscape::Widgets::createStyleWidget( FILL ); +} + + +namespace Inkscape { class FillNStroke : public Gtk::VBox { @@ -58,6 +67,8 @@ public: void setFillrule( SPPaintSelector::FillRule mode ); + void setDesktop(SPDesktop *desktop); + private: static void paintModeChangeCB(SPPaintSelector *psel, SPPaintSelector::Mode mode, FillNStroke *self); static void paintChangedCB(SPPaintSelector *psel, FillNStroke *self); @@ -65,8 +76,7 @@ private: static void fillruleChangedCB( SPPaintSelector *psel, SPPaintSelector::FillRule mode, FillNStroke *self ); - static void selectionModifiedCB(Inkscape::Application *inkscape, Inkscape::Selection *selection, guint flags, FillNStroke *self); - static void selectionChangedCB(Inkscape::Application *inkscape, void * data, FillNStroke *self); + void selectionModifiedCB(guint flags); void dragFromPaint(); void updateFromPaint(); @@ -74,33 +84,47 @@ private: void performUpdate(); FillOrStroke kind; + SPDesktop *desktop; SPPaintSelector *psel; bool update; bool local; + sigc::connection selectChangedConn; + sigc::connection subselChangedConn; + sigc::connection selectModifiedConn; }; +} // namespace Inkscape -GtkWidget *sp_fill_style_widget_new(void) +void sp_fill_style_widget_set_desktop(Gtk::Widget *widget, SPDesktop *desktop) { - return Inkscape::Widgets::createStyleWidget( FILL ); + Inkscape::FillNStroke *fs = dynamic_cast(widget); + if (fs) { + fs->setDesktop(desktop); + } } +namespace Inkscape { + /** * Create the fill or stroke style widget, and hook up all the signals. */ -GtkWidget *Inkscape::Widgets::createStyleWidget( FillOrStroke kind ) +Gtk::Widget *Inkscape::Widgets::createStyleWidget( FillOrStroke kind ) { - FillNStroke *filler = Gtk::manage(new FillNStroke(kind)); + FillNStroke *filler = new FillNStroke(kind); - return GTK_WIDGET(filler->gobj()); + return filler; } FillNStroke::FillNStroke( FillOrStroke kind ) : Gtk::VBox(), kind(kind), + desktop(0), psel(0), update(false), - local(false) + local(false), + selectChangedConn(), + subselChangedConn(), + selectModifiedConn() { // Add and connect up the paint selector widget: psel = sp_paint_selector_new(kind); @@ -123,58 +147,50 @@ FillNStroke::FillNStroke( FillOrStroke kind ) : this ); } - // connect to the app instance to get selection notifications. - // TODO FIXME should really get connected to a Desktop instead. - Inkscape::Application *appInstance = INKSCAPE; - g_signal_connect( G_OBJECT(appInstance), "modify_selection", - G_CALLBACK(selectionModifiedCB), - this ); - - g_signal_connect( G_OBJECT(appInstance), "change_selection", - G_CALLBACK(selectionChangedCB), - this ); - - g_signal_connect( G_OBJECT(appInstance), "change_subselection", - G_CALLBACK(selectionChangedCB), - this ); - - performUpdate(); } FillNStroke::~FillNStroke() { psel = 0; + selectModifiedConn.disconnect(); + subselChangedConn.disconnect(); + selectChangedConn.disconnect(); } /** * On signal modified, invokes an update of the fill or stroke style paint object. */ -void FillNStroke::selectionModifiedCB( Inkscape::Application * /*inkscape*/, - Inkscape::Selection */*selection*/, - guint flags, - FillNStroke *self ) +void FillNStroke::selectionModifiedCB( guint flags ) { - if (self && - (flags & ( SP_OBJECT_MODIFIED_FLAG | + if (flags & ( SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_PARENT_MODIFIED_FLAG | - SP_OBJECT_STYLE_MODIFIED_FLAG) ) ) { + SP_OBJECT_STYLE_MODIFIED_FLAG) ) { #ifdef SP_FS_VERBOSE - g_message("selectionModifiedCB(%p)", self); + g_message("selectionModifiedCB(%d) on %p", flags, this); #endif - self->performUpdate(); + performUpdate(); } } -/** - * On signal selection changed or subselection changed, invokes an update of the fill or stroke style paint object. - */ -void FillNStroke::selectionChangedCB( Inkscape::Application * /*inkscape*/, - void * /*data*/, - FillNStroke *self ) +void FillNStroke::setDesktop(SPDesktop *desktop) { - if (self) { - self->performUpdate(); + if (this->desktop != desktop) { + if (this->desktop) { + selectModifiedConn.disconnect(); + subselChangedConn.disconnect(); + selectChangedConn.disconnect(); + } + this->desktop = desktop; + if (desktop && desktop->selection) { + selectChangedConn = desktop->selection->connectChanged(sigc::hide(sigc::mem_fun(*this, &FillNStroke::performUpdate))); + subselChangedConn = desktop->connectToolSubselectionChanged(sigc::hide(sigc::mem_fun(*this, &FillNStroke::performUpdate))); + + // Must check flags, so can't call performUpdate() directly. + selectModifiedConn = desktop->selection->connectModified(sigc::hide<0>(sigc::mem_fun(*this, &FillNStroke::selectionModifiedCB))); + + } + performUpdate(); } } @@ -186,7 +202,7 @@ void FillNStroke::selectionChangedCB( Inkscape::Application * /*inkscape*/, */ void FillNStroke::performUpdate() { - if ( update ) { + if ( update || !desktop ) { return; } @@ -201,10 +217,10 @@ void FillNStroke::performUpdate() update = true; // create temporary style - SPStyle *query = sp_style_new(SP_ACTIVE_DOCUMENT); + SPStyle *query = sp_style_new(desktop->doc()); // query style from desktop into it. This returns a result flag and fills query with the style of subselection, if any, or selection - int result = sp_desktop_query_style(SP_ACTIVE_DESKTOP, query, (kind == FILL) ? QUERY_STYLE_PROPERTY_FILL : QUERY_STYLE_PROPERTY_STROKE); + int result = sp_desktop_query_style(desktop, query, (kind == FILL) ? QUERY_STYLE_PROPERTY_FILL : QUERY_STYLE_PROPERTY_STROKE); SPIPaint &targPaint = (kind == FILL) ? query->fill : query->stroke; SPIScale24 &targOpacity = (kind == FILL) ? query->fill_opacity : query->stroke_opacity; @@ -298,9 +314,7 @@ void FillNStroke::fillruleChangedCB( SPPaintSelector * /*psel*/, void FillNStroke::setFillrule( SPPaintSelector::FillRule mode ) { - if (!update) { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - + if (!update && desktop) { SPCSSAttr *css = sp_repr_css_attr_new(); sp_repr_css_set_property(css, "fill-rule", (mode == SPPaintSelector::FILLRULE_EVENODD) ? "evenodd":"nonzero"); @@ -309,7 +323,7 @@ void FillNStroke::setFillrule( SPPaintSelector::FillRule mode ) sp_repr_css_attr_unref(css); css = 0; - sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_FILL_STROKE, + sp_document_done(desktop->doc(), SP_VERB_DIALOG_FILL_STROKE, _("Change fill rule")); } } @@ -342,7 +356,7 @@ void FillNStroke::paintDraggedCB(SPPaintSelector * /*psel*/, FillNStroke *self) */ void FillNStroke::dragFromPaint() { - if (!INKSCAPE || update) { + if (!desktop || update) { return; } @@ -361,8 +375,8 @@ void FillNStroke::dragFromPaint() case SPPaintSelector::MODE_COLOR_RGB: case SPPaintSelector::MODE_COLOR_CMYK: { - psel->setFlatColor( SP_ACTIVE_DESKTOP, (kind == FILL) ? "fill" : "stroke", (kind == FILL) ? "fill-opacity" : "stroke-opacity" ); - sp_document_maybe_done(sp_desktop_document(SP_ACTIVE_DESKTOP), (kind == FILL) ? undo_F_label : undo_S_label, SP_VERB_DIALOG_FILL_STROKE, + psel->setFlatColor( desktop, (kind == FILL) ? "fill" : "stroke", (kind == FILL) ? "fill-opacity" : "stroke-opacity" ); + sp_document_maybe_done(desktop->doc(), (kind == FILL) ? undo_F_label : undo_S_label, SP_VERB_DIALOG_FILL_STROKE, (kind == FILL) ? _("Set fill color") : _("Set stroke color")); if (kind == FILL) { local = true; // local change, do not update from selection @@ -397,7 +411,6 @@ void FillNStroke::paintChangedCB( SPPaintSelector * /*psel*/, FillNStroke *self void FillNStroke::updateFromPaint() { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; if (!desktop) { return; } @@ -484,7 +497,7 @@ void FillNStroke::updateFromPaint() if (!vector) { /* No vector in paint selector should mean that we just changed mode */ - SPStyle *query = sp_style_new(SP_ACTIVE_DOCUMENT); + SPStyle *query = sp_style_new(desktop->doc()); int result = objects_query_fillstroke(const_cast(items), query, kind == FILL); SPIPaint &targPaint = (kind == FILL) ? query->fill : query->stroke; guint32 common_rgb = 0; @@ -635,6 +648,7 @@ void FillNStroke::updateFromPaint() update = false; } +} // namespace Inkscape /* Local Variables: -- cgit v1.2.3 From 1a93dffd72bbaa37a4e5fa25e6b6292906ce2f5f Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Mon, 29 Mar 2010 21:41:28 -0700 Subject: Fix logic to avoid too many updates while dragging color sliders. Fixes bug# 168557. Fixed bugs: - https://launchpad.net/bugs/168557 (bzr r9258) --- src/widgets/fill-style.cpp | 76 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 19 deletions(-) (limited to 'src/widgets/fill-style.cpp') diff --git a/src/widgets/fill-style.cpp b/src/widgets/fill-style.cpp index 63def4c87..15d8b6cc2 100644 --- a/src/widgets/fill-style.cpp +++ b/src/widgets/fill-style.cpp @@ -73,6 +73,7 @@ private: static void paintModeChangeCB(SPPaintSelector *psel, SPPaintSelector::Mode mode, FillNStroke *self); static void paintChangedCB(SPPaintSelector *psel, FillNStroke *self); static void paintDraggedCB(SPPaintSelector *psel, FillNStroke *self); + static gboolean dragDelayCB(gpointer data); static void fillruleChangedCB( SPPaintSelector *psel, SPPaintSelector::FillRule mode, FillNStroke *self ); @@ -86,8 +87,9 @@ private: FillOrStroke kind; SPDesktop *desktop; SPPaintSelector *psel; + guint32 lastDrag; + guint dragId; bool update; - bool local; sigc::connection selectChangedConn; sigc::connection subselChangedConn; sigc::connection selectModifiedConn; @@ -120,8 +122,9 @@ FillNStroke::FillNStroke( FillOrStroke kind ) : kind(kind), desktop(0), psel(0), + lastDrag(0), + dragId(0), update(false), - local(false), selectChangedConn(), subselChangedConn(), selectModifiedConn() @@ -152,6 +155,10 @@ FillNStroke::FillNStroke( FillOrStroke kind ) : FillNStroke::~FillNStroke() { + if (dragId) { + g_source_remove(dragId); + dragId = 0; + } psel = 0; selectModifiedConn.disconnect(); subselChangedConn.disconnect(); @@ -176,6 +183,10 @@ void FillNStroke::selectionModifiedCB( guint flags ) void FillNStroke::setDesktop(SPDesktop *desktop) { if (this->desktop != desktop) { + if (dragId) { + g_source_remove(dragId); + dragId = 0; + } if (this->desktop) { selectModifiedConn.disconnect(); subselChangedConn.disconnect(); @@ -188,7 +199,6 @@ void FillNStroke::setDesktop(SPDesktop *desktop) // Must check flags, so can't call performUpdate() directly. selectModifiedConn = desktop->selection->connectModified(sigc::hide<0>(sigc::mem_fun(*this, &FillNStroke::selectionModifiedCB))); - } performUpdate(); } @@ -206,12 +216,11 @@ void FillNStroke::performUpdate() return; } - if (kind == FILL) { - // TODO check. This probably should happen for stroke as well as fill. - if ( local ) { - local = false; // local change; do nothing, but reset the flag - return; - } + if ( dragId ) { + // local change; do nothing, but reset the flag + g_source_remove(dragId); + dragId = 0; + return; } update = true; @@ -348,6 +357,28 @@ void FillNStroke::paintDraggedCB(SPPaintSelector * /*psel*/, FillNStroke *self) } } + +gboolean FillNStroke::dragDelayCB(gpointer data) +{ + gboolean keepGoing = TRUE; + if (data) { + FillNStroke *self = reinterpret_cast(data); + if (!self->update) { + if (self->dragId) { + g_source_remove(self->dragId); + self->dragId = 0; + + self->dragFromPaint(); + self->performUpdate(); + } + keepGoing = FALSE; + } + } else { + keepGoing = FALSE; + } + return keepGoing; +} + /** * This is called repeatedly while you are dragging a color slider, only for flat color * modes. Previously it set the color in style but did not update the repr for efficiency, however @@ -360,27 +391,34 @@ void FillNStroke::dragFromPaint() return; } - if (kind == FILL) { - if (local) { - // previous local flag not cleared yet; - // this means dragged events come too fast, so we better skip this one to speed up display - // (it's safe to do this in any case) - return; - } + guint32 when = gtk_get_current_event_time(); + + // Don't attempt too many updates per second. + // Assume a base 15.625ms resolution on the timer. + if (!dragId && lastDrag && when && ((when - lastDrag) < 32)) { + // local change, do not update from selection + dragId = g_timeout_add_full(G_PRIORITY_DEFAULT, 33, dragDelayCB, this, 0); } + if (dragId) { + // previous local flag not cleared yet; + // this means dragged events come too fast, so we better skip this one to speed up display + // (it's safe to do this in any case) + return; + } + lastDrag = when; + update = true; switch (psel->mode) { case SPPaintSelector::MODE_COLOR_RGB: case SPPaintSelector::MODE_COLOR_CMYK: { + // local change, do not update from selection + dragId = g_timeout_add_full(G_PRIORITY_DEFAULT, 100, dragDelayCB, this, 0); psel->setFlatColor( desktop, (kind == FILL) ? "fill" : "stroke", (kind == FILL) ? "fill-opacity" : "stroke-opacity" ); sp_document_maybe_done(desktop->doc(), (kind == FILL) ? undo_F_label : undo_S_label, SP_VERB_DIALOG_FILL_STROKE, (kind == FILL) ? _("Set fill color") : _("Set stroke color")); - if (kind == FILL) { - local = true; // local change, do not update from selection - } break; } -- cgit v1.2.3