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/Makefile_insert | 1 + src/widgets/fill-n-stroke-factory.h | 34 ++ src/widgets/fill-style.cpp | 568 +++++++++++++++++++-------------- src/widgets/fill-style.h | 11 +- src/widgets/stroke-style.cpp | 606 ++++++++++++++++++++++++------------ src/widgets/stroke-style.h | 16 +- 6 files changed, 783 insertions(+), 453 deletions(-) create mode 100644 src/widgets/fill-n-stroke-factory.h (limited to 'src/widgets') diff --git a/src/widgets/Makefile_insert b/src/widgets/Makefile_insert index 5d327d8a3..313e27528 100644 --- a/src/widgets/Makefile_insert +++ b/src/widgets/Makefile_insert @@ -13,6 +13,7 @@ ink_common_sources += \ widgets/ege-paint-def.h \ widgets/fill-style.cpp \ widgets/fill-style.h \ + widgets/fill-n-stroke-factory.h \ widgets/font-selector.cpp \ widgets/font-selector.h \ widgets/gradient-image.cpp \ diff --git a/src/widgets/fill-n-stroke-factory.h b/src/widgets/fill-n-stroke-factory.h new file mode 100644 index 000000000..14cbd6a58 --- /dev/null +++ b/src/widgets/fill-n-stroke-factory.h @@ -0,0 +1,34 @@ +#ifndef SEEN_FILL_N_STROKE_FACTORY_H +#define SEEN_FILL_N_STROKE_FACTORY_H +/* Authors: + * Jon A. Cruz + * + * Copyright (C) 2010 Jon A. Cruz + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "fill-or-stroke.h" + +typedef struct _GtkWidget GtkWidget; + +namespace Inkscape { +namespace Widgets { + +GtkWidget *createStyleWidget( FillOrStroke kind ); + +} // namespace Widgets +} // namespace Inkscape + +#endif // !SEEN_FILL_N_STROKE_FACTORY_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : 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++ diff --git a/src/widgets/fill-style.h b/src/widgets/fill-style.h index 3924412ec..ea97bd486 100644 --- a/src/widgets/fill-style.h +++ b/src/widgets/fill-style.h @@ -3,7 +3,9 @@ */ /* Authors: * Lauris Kaplinski + * Jon A. Cruz * + * Copyright (C) 2010 Jon A. Cruz * Copyright (C) 2002 Lauris Kaplinski * * Released under GNU GPL, read the file 'COPYING' for more information @@ -12,14 +14,11 @@ #ifndef SEEN_DIALOGS_SP_FILL_STYLE_H #define SEEN_DIALOGS_SP_FILL_STYLE_H -#include -#include -#include "forward.h" +typedef struct _GtkWidget GtkWidget; +GtkWidget *sp_fill_style_widget_new(void); -GtkWidget *sp_fill_style_widget_new (void); - -#endif +#endif // SEEN_DIALOGS_SP_FILL_STYLE_H /* Local Variables: diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index ddd1c92d3..54678dbb8 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -25,6 +25,7 @@ #include "desktop-handles.h" #include "desktop-style.h" #include "dialogs/dialog-events.h" +#include "display/canvas-bpath.h" // for SP_STROKE_LINEJOIN_* #include "display/nr-arena.h" #include "display/nr-arena-item.h" #include "document-private.h" @@ -54,23 +55,36 @@ #include "widgets/spw-utilities.h" #include "xml/repr.h" -#include "widgets/stroke-style.h" +#include "stroke-style.h" +#include "fill-n-stroke-factory.h" +namespace Inkscape { +namespace Widgets { +GtkWidget *createStyleWidgetS( FillOrStroke kind ); +} +} + + +// These can be deleted once we sort out the libart dependence. + +#define ART_WIND_RULE_NONZERO 0 /* Paint */ -static void sp_stroke_style_paint_selection_modified (SPWidget *spw, Inkscape::Selection *selection, guint flags, SPPaintSelector *psel); -static void sp_stroke_style_paint_selection_changed (SPWidget *spw, Inkscape::Selection *selection, SPPaintSelector *psel); -static void sp_stroke_style_paint_update(SPWidget *spw); +static void fillnstroke_constructed(SPWidget *spw, SPPaintSelector *psel); +static void fillnstroke_fillrule_changed(SPPaintSelector *psel, SPPaintSelector::FillRule mode, SPWidget *spw); -static void sp_stroke_style_paint_mode_changed(SPPaintSelector *psel, SPPaintSelector::Mode mode, SPWidget *spw); -static void sp_stroke_style_paint_dragged(SPPaintSelector *psel, SPWidget *spw); -static void sp_stroke_style_paint_changed(SPPaintSelector *psel, 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_stroke_style_widget_change_subselection ( Inkscape::Application *inkscape, SPDesktop *desktop, SPWidget *spw ); -static void sp_stroke_style_widget_transientize_callback(Inkscape::Application *inkscape, - SPDesktop *desktop, - SPWidget *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_transientize_called(Inkscape::Application *inkscape, SPDesktop *desktop, SPWidget *spw); + +static void fillnstroke_performUpdate(SPWidget *spw); /** Marker selection option menus */ static Gtk::OptionMenu * marker_start_menu = NULL; @@ -86,104 +100,159 @@ static void ink_markers_menu_update(Gtk::Container* spw, SPMarkerLoc const static Inkscape::UI::Cache::SvgPreview svg_preview_cache; +GtkWidget *sp_stroke_style_paint_widget_new(void) +{ + return Inkscape::Widgets::createStyleWidgetS( STROKE ); +} + /** - * Create the stroke style widget, and hook up all the signals. + * Create the fill or stroke style widget, and hook up all the signals. */ -GtkWidget * -sp_stroke_style_paint_widget_new(void) +GtkWidget *Inkscape::Widgets::createStyleWidgetS( FillOrStroke kind ) { - GtkWidget *spw, *psel; - - spw = sp_widget_new_global(INKSCAPE); + GtkWidget *spw = sp_widget_new_global(INKSCAPE); - psel = sp_paint_selector_new(false); // without fillrule selector + // with or without fillrule selector + GtkWidget *psel = sp_paint_selector_new(kind == FILL); gtk_widget_show(psel); gtk_container_add(GTK_CONTAINER(spw), psel); - gtk_object_set_data(GTK_OBJECT(spw), "paint-selector", psel); - - gtk_signal_connect(GTK_OBJECT(spw), "modify_selection", - GTK_SIGNAL_FUNC(sp_stroke_style_paint_selection_modified), - psel); - gtk_signal_connect(GTK_OBJECT(spw), "change_selection", - GTK_SIGNAL_FUNC(sp_stroke_style_paint_selection_changed), - psel); - - g_signal_connect (INKSCAPE, "change_subselection", G_CALLBACK (sp_stroke_style_widget_change_subselection), spw); - - g_signal_connect (G_OBJECT(INKSCAPE), "activate_desktop", G_CALLBACK (sp_stroke_style_widget_transientize_callback), spw ); - - gtk_signal_connect(GTK_OBJECT(psel), "mode_changed", - GTK_SIGNAL_FUNC(sp_stroke_style_paint_mode_changed), - spw); - gtk_signal_connect(GTK_OBJECT(psel), "dragged", - GTK_SIGNAL_FUNC(sp_stroke_style_paint_dragged), - spw); - gtk_signal_connect(GTK_OBJECT(psel), "changed", - GTK_SIGNAL_FUNC(sp_stroke_style_paint_changed), - spw); - - sp_stroke_style_paint_update (SP_WIDGET(spw)); + 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(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( G_OBJECT(psel), "mode_changed", + G_CALLBACK(fillnstroke_paint_mode_changed), + spw ); + + g_signal_connect( G_OBJECT(psel), "dragged", + G_CALLBACK(fillnstroke_paint_dragged), + spw ); + + g_signal_connect( G_OBJECT(psel), "changed", + G_CALLBACK(fillnstroke_paint_changed), + spw ); + + 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 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 stroke style paint object. + * On signal modified, invokes an update of the fill or stroke style paint object. */ -static void -sp_stroke_style_paint_selection_modified( SPWidget *spw, - Inkscape::Selection */*selection*/, - guint flags, - SPPaintSelector */*psel*/ ) +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 | + if (flags & ( SP_OBJECT_MODIFIED_FLAG | + SP_OBJECT_PARENT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG) ) { - sp_stroke_style_paint_update(spw); +#ifdef SP_FS_VERBOSE + g_message("fillnstroke_selection_modified()"); +#endif + fillnstroke_performUpdate(spw); } } - /** - * On signal selection changed, invokes an update of the stroke style paint object. + * On signal selection changed, invokes an update of the fill or stroke style paint object. */ -static void -sp_stroke_style_paint_selection_changed( SPWidget *spw, - Inkscape::Selection */*selection*/, - SPPaintSelector */*psel*/ ) +static void fillnstroke_selection_changed( SPWidget *spw, + Inkscape::Selection * /*selection*/, + SPPaintSelector * /*psel*/ ) { - sp_stroke_style_paint_update (spw); + fillnstroke_performUpdate(spw); } - /** - * On signal change subselection, invoke an update of the stroke style widget. + * On signal change subselection, invoke an update of the fill or stroke style widget. */ -static void -sp_stroke_style_widget_change_subselection( Inkscape::Application */*inkscape*/, - SPDesktop */*desktop*/, - SPWidget *spw ) +static void fillnstroke_subselection_changed( Inkscape::Application * /*inkscape*/, + SPDesktop * /*desktop*/, + SPWidget *spw ) { - sp_stroke_style_paint_update (spw); + fillnstroke_performUpdate(spw); } /** - * Gets the active stroke style property, then sets the appropriate color, alpha, gradient, - * pattern, etc. for the paint-selector. + * 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 -sp_stroke_style_paint_update (SPWidget *spw) +static void fillnstroke_performUpdate( SPWidget *spw ) { - if (gtk_object_get_data(GTK_OBJECT(spw), "update")) { + if ( g_object_get_data(G_OBJECT(spw), "update") ) { return; } - gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(TRUE)); + FillOrStroke kind = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(spw), "kind")) ? FILL : STROKE; - SPPaintSelector *psel = SP_PAINT_SELECTOR(gtk_object_get_data(GTK_OBJECT(spw), "paint-selector")); + 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)); + + 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); - // query into it - int result = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKE); + 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, (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: @@ -197,36 +266,41 @@ sp_stroke_style_paint_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, false); + SPPaintSelector::Mode pselmode = SPPaintSelector::getModeForStyle(*query, kind == FILL); psel->setMode(pselmode); - if (query->stroke.set && query->stroke.isPaintserver()) { + if (kind == FILL) { + psel->setFillrule(query->fill_rule.computed == ART_WIND_RULE_NONZERO? + SPPaintSelector::FILLRULE_NONZERO : SPPaintSelector::FILLRULE_EVENODD); + } + + if (targPaint.set && targPaint.isColor()) { + psel->setColorAlpha(targPaint.value.color, SP_SCALE24_TO_FLOAT(targOpacity.value)); + } else if (targPaint.set && targPaint.isPaintserver()) { - SPPaintServer *server = SP_STYLE_STROKE_SERVER (query); + SPPaintServer *server = (kind == FILL) ? query->getFillPaintServer() : query->getStrokePaintServer(); - if (server && server->isSwatch()) { + 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); + 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)); + } else if (SP_IS_PATTERN(server)) { + SPPattern *pat = pattern_getroot(SP_PATTERN(server)); psel->updatePatternList( pat ); } - } else if (query->stroke.set && query->stroke.isColor()) { - psel->setColorAlpha(query->stroke.value.color, SP_SCALE24_TO_FLOAT(query->stroke_opacity.value)); } break; } @@ -240,83 +314,145 @@ sp_stroke_style_paint_update (SPWidget *spw) sp_style_unref(query); - gtk_object_set_data(GTK_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); + g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); } /** * When the mode is changed, invoke a regular changed handler. */ -static void -sp_stroke_style_paint_mode_changed( SPPaintSelector *psel, +static void fillnstroke_paint_mode_changed( SPPaintSelector *psel, SPPaintSelector::Mode /*mode*/, SPWidget *spw ) { - if (gtk_object_get_data(GTK_OBJECT(spw), "update")) { + 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); +#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 */ - sp_stroke_style_paint_changed(psel, spw); + fillnstroke_paint_changed(psel, spw); +} + +static void fillnstroke_fillrule_changed( SPPaintSelector * /*psel*/, + SPPaintSelector::FillRule mode, + SPWidget *spw ) +{ + if (g_object_get_data(G_OBJECT(spw), "update")) { + return; + } + + 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"); + + sp_desktop_set_style(desktop, css); + + sp_repr_css_attr_unref(css); + css = 0; + + sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_FILL_STROKE, + _("Change fill rule")); } -static gchar const *const undo_label_1 = "stroke:flatcolor:1"; -static gchar const *const undo_label_2 = "stroke: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; /** - * When a drag callback occurs on a paint selector object, if it is a RGB or CMYK - * color mode, then set the stroke opacity to psel's flat color. + * 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_stroke_style_paint_dragged(SPPaintSelector *psel, SPWidget *spw) +static void fillnstroke_paint_dragged(SPPaintSelector *psel, SPWidget *spw) { - if (gtk_object_get_data(GTK_OBJECT(spw), "update")) { + if (!spw->inkscape) { + 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")) { + // 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)); + switch (psel->mode) { case SPPaintSelector::MODE_COLOR_RGB: case SPPaintSelector::MODE_COLOR_CMYK: { - psel->setFlatColor( SP_ACTIVE_DESKTOP, "stroke", "stroke-opacity" ); - sp_document_maybe_done (sp_desktop_document(SP_ACTIVE_DESKTOP), undo_label, SP_VERB_DIALOG_FILL_STROKE, - _("Set stroke color")); + 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); + __FILE__, __LINE__, psel->mode ); break; } + g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); } /** - * When the stroke style's paint settings change, this handler updates the - * repr's stroke css style and applies the style to relevant drawing items. +This is called (at least) when: +1 paint selector mode is switched (e.g. flat color -> gradient) +2 you finished dragging a gradient node and released mouse +3 you changed a gradient selector parameter (e.g. spread) +Must update repr. */ -static void -sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw) +static void fillnstroke_paint_changed( SPPaintSelector *psel, SPWidget *spw ) { - if (gtk_object_get_data(GTK_OBJECT(spw), "update")) { +#ifdef SP_FS_VERBOSE + g_message("fillnstroke_paint_changed(psel:%p, spw:%p)", psel, spw); +#endif + 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; - SPDocument *document = sp_desktop_document (desktop); - Inkscape::Selection *selection = sp_desktop_selection (desktop); + if (!desktop) { + return; + } + 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; @@ -326,75 +462,118 @@ sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw) case SPPaintSelector::MODE_NONE: { SPCSSAttr *css = sp_repr_css_attr_new(); - sp_repr_css_set_property(css, "stroke", "none"); + 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); + css = 0; sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE, - _("Remove stroke")); + (kind == FILL) ? _("Remove fill") : _("Remove stroke")); break; } case SPPaintSelector::MODE_COLOR_RGB: case SPPaintSelector::MODE_COLOR_CMYK: { - psel->setFlatColor(desktop, "stroke", "stroke-opacity"); - sp_document_maybe_done (sp_desktop_document(desktop), undo_label, SP_VERB_DIALOG_FILL_STROKE, - _("Set stroke color")); + 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")); + + 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; } case SPPaintSelector::MODE_GRADIENT_LINEAR: case SPPaintSelector::MODE_GRADIENT_RADIAL: + case SPPaintSelector::MODE_SWATCH: if (items) { - SPGradientType const gradient_type = ( psel->mode == SPPaintSelector::MODE_GRADIENT_LINEAR + SPGradientType const gradient_type = ( psel->mode != SPPaintSelector::MODE_GRADIENT_RADIAL ? SP_GRADIENT_TYPE_LINEAR : SP_GRADIENT_TYPE_RADIAL ); + + 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, false); + 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, false); + if (!targPaint.isColor()) { + common_rgb = sp_desktop_get_color(desktop, kind == FILL); } else { - common_rgb = query->stroke.value.color.toRGBA32( 0xff ); + common_rgb = targPaint.value.color.toRGBA32( 0xff ); } vector = sp_document_default_gradient_vector(document, common_rgb); } sp_style_unref(query); for (GSList const *i = items; i != NULL; i = i->next) { + //FIXME: see above + 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), false), - gradient_type, false); + 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, false); + 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); for (GSList const *i = items; i != NULL; i = i->next) { - SPGradient *gr = sp_item_set_gradient(SP_ITEM(i->data), vector, gradient_type, false); + //FIXME: see above + 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, kind == FILL); psel->pushAttrsToGradient( gr ); } } + if (css) { + sp_repr_css_attr_unref(css); + css = 0; + } + sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE, - _("Set gradient on stroke")); + (kind == FILL) ? _("Set gradient on fill") : _("Set gradient on stroke")); } break; @@ -411,59 +590,77 @@ sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw) } 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, "stroke", 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); - for (GSList const *i = items; i != NULL; i = i->next) { - Inkscape::XML::Node *selrepr = SP_OBJECT_REPR (i->data); - SPObject *selobj = SP_OBJECT (i->data); - if (!selrepr) - continue; + // HACK: reset fill-opacity - that 0.75 is annoying; BUT remove this when we have an opacity slider for all tabs + if (kind == FILL) { + sp_repr_css_set_property(css, "fill-opacity", "1.0"); + } - SPStyle *style = SP_OBJECT_STYLE (selobj); - if (style && style->stroke.isPaintserver()) { - SPObject *server = 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; - } + // 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) { + 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; + } - sp_repr_css_change_recursive (selrepr, css, "style"); - } + 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 stroke")); + 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_SWATCH: - // TODO - break; - case SPPaintSelector::MODE_UNSET: if (items) { - SPCSSAttr *css = sp_repr_css_attr_new (); - 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_document_done (document, SP_VERB_DIALOG_FILL_STROKE, - _("Unset stroke")); + 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); + css = 0; + + sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE, + (kind == FILL) ? _("Unset fill") : _("Unset stroke")); } break; @@ -475,10 +672,19 @@ sp_stroke_style_paint_changed(SPPaintSelector *psel, SPWidget *spw) 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); +} + @@ -537,25 +743,15 @@ sp_stroke_radio_button(Gtk::RadioButton *tb, char const *icon, } -static void -sp_stroke_style_widget_transientize_callback(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); -} - /** - * Creates a copy of the marker named mname, determines its visible and renderable + * Create sa copy of the marker named mname, determines its visible and renderable * area in menu_id's bounding box, and then renders it. This allows us to fill in * preview images of each marker in the marker menu. */ static Gtk::Image * sp_marker_prev_new(unsigned psize, gchar const *mname, SPDocument *source, SPDocument *sandbox, - gchar const *menu_id, NRArena const */*arena*/, unsigned /*visionkey*/, NRArenaItem *root) + gchar const *menu_id, NRArena const * /*arena*/, unsigned /*visionkey*/, NRArenaItem *root) { // Retrieve the marker named 'mname' from the source SVG document SPObject const *marker = source->getObjectById(mname); @@ -699,7 +895,7 @@ sp_marker_menu_build (Gtk::Menu *m, GSList *marker_list, SPDocument *source, SPD * */ static void -sp_marker_list_from_doc (Gtk::Menu *m, SPDocument */*current_doc*/, SPDocument *source, SPDocument */*markers_doc*/, SPDocument *sandbox, gchar const *menu_id) +sp_marker_list_from_doc (Gtk::Menu *m, SPDocument * /*current_doc*/, SPDocument *source, SPDocument * /*markers_doc*/, SPDocument *sandbox, gchar const *menu_id) { GSList *ml = ink_marker_list_get(source); GSList *clean_ml = NULL; @@ -808,7 +1004,7 @@ ink_marker_menu_create_menu(Gtk::Menu *m, gchar const *menu_id, SPDocument *doc, * Creates a menu widget to display markers from markers.svg */ static Gtk::OptionMenu * -ink_marker_menu(Gtk::Widget */*tbl*/, gchar const *menu_id, SPDocument *sandbox) +ink_marker_menu(Gtk::Widget * /*tbl*/, gchar const *menu_id, SPDocument *sandbox) { SPDesktop *desktop = inkscape_active_desktop(); SPDocument *doc = sp_desktop_document(desktop); @@ -903,6 +1099,7 @@ sp_marker_select(Gtk::OptionMenu *mnu, Gtk::Container *spw, SPMarkerLoc const wh } sp_repr_css_attr_unref(css); + css = 0; sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE, _("Set markers")); @@ -1269,12 +1466,12 @@ sp_stroke_style_line_widget_new(void) // FIXME: we cheat and still use gtk+ signals - gtk_signal_connect(GTK_OBJECT(spw_old), "modify_selection", - GTK_SIGNAL_FUNC(sp_stroke_style_line_selection_modified), - spw); - gtk_signal_connect(GTK_OBJECT(spw_old), "change_selection", - GTK_SIGNAL_FUNC(sp_stroke_style_line_selection_changed), - spw); + g_signal_connect(G_OBJECT(spw_old), "modify_selection", + G_CALLBACK(sp_stroke_style_line_selection_modified), + spw); + g_signal_connect(G_OBJECT(spw_old), "change_selection", + G_CALLBACK(sp_stroke_style_line_selection_changed), + spw); sp_stroke_style_line_update(spw, desktop ? sp_desktop_selection(desktop) : NULL); @@ -1393,6 +1590,8 @@ sp_stroke_style_line_update(Gtk::Container *spw, Inkscape::Selection *sel) spw->set_data("update", GINT_TO_POINTER(TRUE)); + FillOrStroke kind = GPOINTER_TO_INT(spw->get_data("kind")) ? FILL : STROKE; + Gtk::Table *sset = static_cast(spw->get_data("stroke")); Gtk::Adjustment *width = static_cast(spw->get_data("width")); Gtk::Adjustment *ml = static_cast(spw->get_data("miterlimit")); @@ -1406,10 +1605,11 @@ sp_stroke_style_line_update(Gtk::Container *spw, Inkscape::Selection *sel) int result_ml = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEMITERLIMIT); int result_cap = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKECAP); int result_join = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_STROKEJOIN); + SPIPaint &targPaint = (kind == FILL) ? query->fill : query->stroke; if (!sel || sel->isEmpty()) { // Nothing selected, grey-out all controls in the stroke-style dialog - sset->set_sensitive(false); + sset->set_sensitive(false); spw->set_data("update", GINT_TO_POINTER(FALSE)); @@ -1439,7 +1639,7 @@ sp_stroke_style_line_update(Gtk::Container *spw, Inkscape::Selection *sel) // if none of the selected objects has a stroke, than quite some controls should be disabled // The markers might still be shown though, so these will not be disabled - bool enabled = (result_sw != QUERY_STYLE_NOTHING) && !query->stroke.isNoneSet(); + bool enabled = (result_sw != QUERY_STYLE_NOTHING) && !targPaint.isNoneSet(); /* No objects stroked, set insensitive */ Gtk::RadioButton *tb = NULL; tb = static_cast(spw->get_data("miter join")); @@ -1454,11 +1654,11 @@ sp_stroke_style_line_update(Gtk::Container *spw, Inkscape::Selection *sel) sb->set_sensitive(enabled); tb = static_cast(spw->get_data("cap butt")); - tb->set_sensitive(enabled); - tb = static_cast(spw->get_data("cap round")); - tb->set_sensitive(enabled); - tb = static_cast(spw->get_data("cap square")); - tb->set_sensitive(enabled); + tb->set_sensitive(enabled); + tb = static_cast(spw->get_data("cap round")); + tb->set_sensitive(enabled); + tb = static_cast(spw->get_data("cap square")); + tb->set_sensitive(enabled); dsel->set_sensitive(enabled); } @@ -1604,6 +1804,7 @@ sp_stroke_style_scale_line(Gtk::Container *spw) sp_desktop_set_style (desktop, css, false); sp_repr_css_attr_unref(css); + css = 0; sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE, _("Set stroke style")); @@ -1700,6 +1901,7 @@ sp_stroke_style_any_toggled(Gtk::ToggleButton *tb, Gtk::Container *spw) } sp_repr_css_attr_unref(css); + css = 0; sp_document_done(sp_desktop_document(desktop), SP_VERB_DIALOG_FILL_STROKE, _("Set stroke style")); diff --git a/src/widgets/stroke-style.h b/src/widgets/stroke-style.h index b947209e3..9ed7e2a92 100644 --- a/src/widgets/stroke-style.h +++ b/src/widgets/stroke-style.h @@ -3,25 +3,25 @@ */ /* Author: * Lauris Kaplinski + * Jon A. Cruz * + * Copyright (C) 2010 Jon A. Cruz * Copyright (C) 2001 Ximian, Inc. + * * Released under GNU GPL, read the file 'COPYING' for more information */ #ifndef SEEN_DIALOGS_STROKE_STYLE_H #define SEEN_DIALOGS_STROKE_STYLE_H -#include - -#include +#include -#include "forward.h" -#include "display/canvas-bpath.h" +typedef struct _GtkWidget GtkWidget; -GtkWidget *sp_stroke_style_paint_widget_new (void); -Gtk::Container *sp_stroke_style_line_widget_new (void); +GtkWidget *sp_stroke_style_paint_widget_new(void); +Gtk::Container *sp_stroke_style_line_widget_new(void); -#endif +#endif // SEEN_DIALOGS_STROKE_STYLE_H /* Local Variables: -- cgit v1.2.3 From c94f9de0a6c484f837cfce3adbfcf7f8275e8cc5 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 27 Mar 2010 01:10:31 -0700 Subject: Phase 2 - remove duplicated code and leave a single copy of each function. (bzr r9239) --- src/widgets/stroke-style.cpp | 612 +------------------------------------------ 1 file changed, 1 insertion(+), 611 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index 54678dbb8..d6a38f978 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -58,34 +58,6 @@ #include "stroke-style.h" #include "fill-n-stroke-factory.h" -namespace Inkscape { -namespace Widgets { -GtkWidget *createStyleWidgetS( FillOrStroke kind ); -} -} - - -// These can be deleted once we sort out the libart dependence. - -#define ART_WIND_RULE_NONZERO 0 - -/* Paint */ - -static void fillnstroke_constructed(SPWidget *spw, SPPaintSelector *psel); -static void fillnstroke_fillrule_changed(SPPaintSelector *psel, SPPaintSelector::FillRule mode, 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 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_transientize_called(Inkscape::Application *inkscape, SPDesktop *desktop, SPWidget *spw); - -static void fillnstroke_performUpdate(SPWidget *spw); - /** Marker selection option menus */ static Gtk::OptionMenu * marker_start_menu = NULL; static Gtk::OptionMenu * marker_mid_menu = NULL; @@ -102,591 +74,9 @@ static Inkscape::UI::Cache::SvgPreview svg_preview_cache; GtkWidget *sp_stroke_style_paint_widget_new(void) { - return Inkscape::Widgets::createStyleWidgetS( STROKE ); -} - -/** - * Create the fill or stroke style widget, and hook up all the signals. - */ -GtkWidget *Inkscape::Widgets::createStyleWidgetS( 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(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( G_OBJECT(psel), "mode_changed", - G_CALLBACK(fillnstroke_paint_mode_changed), - spw ); - - g_signal_connect( G_OBJECT(psel), "dragged", - G_CALLBACK(fillnstroke_paint_dragged), - spw ); - - g_signal_connect( G_OBJECT(psel), "changed", - G_CALLBACK(fillnstroke_paint_changed), - spw ); - - 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 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*/ ) -{ - if (flags & ( SP_OBJECT_MODIFIED_FLAG | - SP_OBJECT_PARENT_MODIFIED_FLAG | - SP_OBJECT_STYLE_MODIFIED_FLAG) ) { -#ifdef SP_FS_VERBOSE - g_message("fillnstroke_selection_modified()"); -#endif - fillnstroke_performUpdate(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*/ ) -{ - fillnstroke_performUpdate(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 ) -{ - fillnstroke_performUpdate(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") ) { - 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)); - - 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); - - // 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); - - SPIPaint &targPaint = (kind == FILL) ? query->fill : query->stroke; - SPIScale24 &targOpacity = (kind == FILL) ? query->fill_opacity : query->stroke_opacity; - - switch (result) { - case QUERY_STYLE_NOTHING: - { - /* No paint at all */ - psel->setMode(SPPaintSelector::MODE_EMPTY); - break; - } - - case QUERY_STYLE_SINGLE: - 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); - psel->setMode(pselmode); - - if (kind == FILL) { - psel->setFillrule(query->fill_rule.computed == ART_WIND_RULE_NONZERO? - SPPaintSelector::FILLRULE_NONZERO : SPPaintSelector::FILLRULE_EVENODD); - } - - if (targPaint.set && targPaint.isColor()) { - psel->setColorAlpha(targPaint.value.color, SP_SCALE24_TO_FLOAT(targOpacity.value)); - } else if (targPaint.set && targPaint.isPaintserver()) { - - 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)) { - SPGradient *vector = SP_GRADIENT(server)->getVector(); - psel->setGradientLinear( vector ); - - SPLinearGradient *lg = SP_LINEARGRADIENT(server); - psel->setGradientProperties( SP_GRADIENT_UNITS(lg), - SP_GRADIENT_SPREAD(lg) ); - } 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)); - psel->updatePatternList( pat ); - } - } - break; - } - - case QUERY_STYLE_MULTIPLE_DIFFERENT: - { - psel->setMode(SPPaintSelector::MODE_MULTIPLE); - break; - } - } - - sp_style_unref(query); - - g_object_set_data(G_OBJECT(spw), "update", GINT_TO_POINTER(FALSE)); -} - -/** - * 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")) { - return; - } - -#ifdef SP_FS_VERBOSE - g_message("fillnstroke_paint_mode_changed(psel:%p, mode, spw:%p)", psel, spw); -#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); + return Inkscape::Widgets::createStyleWidget( STROKE ); } -static void fillnstroke_fillrule_changed( SPPaintSelector * /*psel*/, - SPPaintSelector::FillRule mode, - SPWidget *spw ) -{ - if (g_object_get_data(G_OBJECT(spw), "update")) { - return; - } - - 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"); - - sp_desktop_set_style(desktop, css); - - sp_repr_css_attr_unref(css); - css = 0; - - sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_DIALOG_FILL_STROKE, - _("Change fill rule")); -} - -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. - */ -static void fillnstroke_paint_dragged(SPPaintSelector *psel, SPWidget *spw) -{ - if (!spw->inkscape) { - 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")) { - // 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)); - - switch (psel->mode) { - 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, - (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 ); - break; - } - 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) -2 you finished dragging a gradient node and released mouse -3 you changed a gradient selector parameter (e.g. spread) -Must update repr. - */ -static void fillnstroke_paint_changed( SPPaintSelector *psel, SPWidget *spw ) -{ -#ifdef SP_FS_VERBOSE - g_message("fillnstroke_paint_changed(psel:%p, spw:%p)", psel, spw); -#endif - if (g_object_get_data(G_OBJECT(spw), "update")) { - return; - } - 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); - - 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); - break; - case SPPaintSelector::MODE_MULTIPLE: - // This happens when you switch multiple objects with different gradients to flat color; - // nothing to do here. - break; - - case SPPaintSelector::MODE_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_repr_css_attr_unref(css); - css = 0; - - 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: - { - 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")); - - 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_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; - } - - case SPPaintSelector::MODE_GRADIENT_LINEAR: - case SPPaintSelector::MODE_GRADIENT_RADIAL: - case SPPaintSelector::MODE_SWATCH: - if (items) { - SPGradientType const gradient_type = ( psel->mode != SPPaintSelector::MODE_GRADIENT_RADIAL - ? SP_GRADIENT_TYPE_LINEAR - : SP_GRADIENT_TYPE_RADIAL ); - - 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(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 (!targPaint.isColor()) { - common_rgb = sp_desktop_get_color(desktop, kind == FILL); - } else { - common_rgb = targPaint.value.color.toRGBA32( 0xff ); - } - vector = sp_document_default_gradient_vector(document, common_rgb); - } - sp_style_unref(query); - - for (GSList const *i = items; i != NULL; i = i->next) { - //FIXME: see above - 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), kind == FILL), - gradient_type, kind == FILL); - } else { - 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); - for (GSList const *i = items; i != NULL; i = i->next) { - //FIXME: see above - 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, kind == FILL); - psel->pushAttrsToGradient( gr ); - } - } - - if (css) { - sp_repr_css_attr_unref(css); - css = 0; - } - - sp_document_done(document, SP_VERB_DIALOG_FILL_STROKE, - (kind == FILL) ? _("Set gradient on fill") : _("Set gradient on stroke")); - } - break; - - case SPPaintSelector::MODE_PATTERN: - - if (items) { - - SPPattern *pattern = psel->getPattern(); - if (!pattern) { - - /* No Pattern in paint selector should mean that we just - * changed mode - dont do jack. - */ - - } 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, (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 - 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) { - 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; - } - - 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); - css = 0; - g_free(urltext); - - } // end if - - 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(); - 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); - css = 0; - - 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 ); - break; - } - - 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); -} - - - /* Line */ -- 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') 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 +++++++++++++++++++++++------------------ src/widgets/paint-selector.cpp | 15 ++- src/widgets/paint-selector.h | 6 +- 3 files changed, 161 insertions(+), 130 deletions(-) (limited to 'src/widgets') 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; } diff --git a/src/widgets/paint-selector.cpp b/src/widgets/paint-selector.cpp index 288764177..d3092669a 100644 --- a/src/widgets/paint-selector.cpp +++ b/src/widgets/paint-selector.cpp @@ -352,8 +352,7 @@ sp_paint_selector_show_fillrule(SPPaintSelector *psel, bool is_fill) } -GtkWidget * -sp_paint_selector_new(bool is_fill) +SPPaintSelector *sp_paint_selector_new(FillOrStroke kind) { SPPaintSelector *psel = static_cast(gtk_type_new(SP_TYPE_PAINT_SELECTOR)); @@ -362,9 +361,9 @@ sp_paint_selector_new(bool is_fill) // This silliness is here because I don't know how to pass a parameter to the // GtkObject "constructor" (sp_paint_selector_init). Remove it when paint_selector // becomes a normal class. - sp_paint_selector_show_fillrule(psel, is_fill); + sp_paint_selector_show_fillrule(psel, kind == FILL); - return GTK_WIDGET(psel); + return psel; } void SPPaintSelector::setMode(Mode mode) @@ -1137,18 +1136,18 @@ void SPPaintSelector::setFlatColor( SPDesktop *desktop, gchar const *color_prope sp_repr_css_attr_unref(css); } -SPPaintSelector::Mode SPPaintSelector::getModeForStyle(SPStyle const & style, bool isfill) +SPPaintSelector::Mode SPPaintSelector::getModeForStyle(SPStyle const & style, FillOrStroke kind) { Mode mode = MODE_UNSET; - SPIPaint const & target = isfill ? style.fill : style.stroke; + SPIPaint const & target = (kind == FILL) ? style.fill : style.stroke; if ( !target.set ) { mode = MODE_UNSET; } else if ( target.isPaintserver() ) { - SPPaintServer const *server = isfill ? style.getFillPaintServer() : style.getStrokePaintServer(); + SPPaintServer const *server = (kind == FILL) ? style.getFillPaintServer() : style.getStrokePaintServer(); #ifdef SP_PS_VERBOSE - g_message("SPPaintSelector::getModeForStyle(%p, %d)", &style, isfill); + g_message("SPPaintSelector::getModeForStyle(%p, %d)", &style, kind); g_message("==== server:%p %s grad:%s swatch:%s", server, server->getId(), (SP_IS_GRADIENT(server)?"Y":"n"), (SP_IS_GRADIENT(server) && SP_GRADIENT(server)->getVector()->isSwatch()?"Y":"n")); #endif // SP_PS_VERBOSE diff --git a/src/widgets/paint-selector.h b/src/widgets/paint-selector.h index a3c4cb973..84209d1da 100644 --- a/src/widgets/paint-selector.h +++ b/src/widgets/paint-selector.h @@ -14,6 +14,8 @@ */ #include + +#include "fill-or-stroke.h" #include "sp-gradient-spread.h" #include "sp-gradient-units.h" @@ -75,7 +77,7 @@ struct SPPaintSelector { SPColor color; float alpha; - static Mode getModeForStyle(SPStyle const & style, bool isfill); + static Mode getModeForStyle(SPStyle const & style, FillOrStroke kind); void setMode( Mode mode ); void setFillrule( FillRule fillrule ); @@ -114,7 +116,7 @@ struct SPPaintSelectorClass { GtkType sp_paint_selector_get_type (void); -GtkWidget *sp_paint_selector_new (bool is_fill); +SPPaintSelector *sp_paint_selector_new(FillOrStroke kind); -- 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-n-stroke-factory.h | 6 +- src/widgets/fill-style.cpp | 120 ++++++++++++++++++++---------------- src/widgets/fill-style.h | 10 ++- src/widgets/stroke-style.cpp | 9 ++- src/widgets/stroke-style.h | 11 ++-- 5 files changed, 94 insertions(+), 62 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/fill-n-stroke-factory.h b/src/widgets/fill-n-stroke-factory.h index 14cbd6a58..74339a07f 100644 --- a/src/widgets/fill-n-stroke-factory.h +++ b/src/widgets/fill-n-stroke-factory.h @@ -10,12 +10,14 @@ #include "fill-or-stroke.h" -typedef struct _GtkWidget GtkWidget; +namespace Gtk { +class Widget; +} namespace Inkscape { namespace Widgets { -GtkWidget *createStyleWidget( FillOrStroke kind ); +Gtk::Widget *createStyleWidget( FillOrStroke kind ); } // namespace Widgets } // namespace Inkscape 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: diff --git a/src/widgets/fill-style.h b/src/widgets/fill-style.h index ea97bd486..ef19d7788 100644 --- a/src/widgets/fill-style.h +++ b/src/widgets/fill-style.h @@ -14,9 +14,15 @@ #ifndef SEEN_DIALOGS_SP_FILL_STYLE_H #define SEEN_DIALOGS_SP_FILL_STYLE_H -typedef struct _GtkWidget GtkWidget; +namespace Gtk { +class Widget; +} -GtkWidget *sp_fill_style_widget_new(void); +class SPDesktop; + +Gtk::Widget *sp_fill_style_widget_new(void); + +void sp_fill_style_widget_set_desktop(Gtk::Widget *widget, SPDesktop *desktop); #endif // SEEN_DIALOGS_SP_FILL_STYLE_H diff --git a/src/widgets/stroke-style.cpp b/src/widgets/stroke-style.cpp index d6a38f978..f020b0c3a 100644 --- a/src/widgets/stroke-style.cpp +++ b/src/widgets/stroke-style.cpp @@ -56,6 +56,7 @@ #include "xml/repr.h" #include "stroke-style.h" +#include "fill-style.h" // to get sp_fill_style_widget_set_desktop #include "fill-n-stroke-factory.h" /** Marker selection option menus */ @@ -72,11 +73,17 @@ static void ink_markers_menu_update(Gtk::Container* spw, SPMarkerLoc const static Inkscape::UI::Cache::SvgPreview svg_preview_cache; -GtkWidget *sp_stroke_style_paint_widget_new(void) +Gtk::Widget *sp_stroke_style_paint_widget_new(void) { return Inkscape::Widgets::createStyleWidget( STROKE ); } +void sp_stroke_style_widget_set_desktop(Gtk::Widget *widget, SPDesktop *desktop) +{ + sp_fill_style_widget_set_desktop(widget, desktop); +} + + /* Line */ diff --git a/src/widgets/stroke-style.h b/src/widgets/stroke-style.h index 9ed7e2a92..72dc5449a 100644 --- a/src/widgets/stroke-style.h +++ b/src/widgets/stroke-style.h @@ -14,13 +14,16 @@ #ifndef SEEN_DIALOGS_STROKE_STYLE_H #define SEEN_DIALOGS_STROKE_STYLE_H -#include +namespace Gtk { +class Widget; +class Container; +} -typedef struct _GtkWidget GtkWidget; - -GtkWidget *sp_stroke_style_paint_widget_new(void); +Gtk::Widget *sp_stroke_style_paint_widget_new(void); Gtk::Container *sp_stroke_style_line_widget_new(void); +void sp_stroke_style_widget_set_desktop(Gtk::Widget *widget, SPDesktop *desktop); + #endif // SEEN_DIALOGS_STROKE_STYLE_H /* -- 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') 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 From d12b9c9fa87c4fc4f7842e5d6512c4f17298cce7 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 3 Apr 2010 03:56:36 +0200 Subject: Initial fix for the inverted coordinate system bug (bzr r9281.1.1) --- src/widgets/desktop-widget.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index ab440595f..48317aa3e 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -1493,8 +1493,8 @@ sp_desktop_widget_update_vruler (SPDesktopWidget *dtw) NR::IRect viewbox = dtw->canvas->getViewboxIntegers(); double const scale = dtw->desktop->current_zoom(); - double s = viewbox.min()[Geom::Y] / -scale - dtw->ruler_origin[Geom::Y]; - double e = viewbox.max()[Geom::Y] / -scale - dtw->ruler_origin[Geom::Y]; + double s = viewbox.min()[Geom::Y] / scale - dtw->ruler_origin[Geom::Y]; + double e = viewbox.max()[Geom::Y] / scale - dtw->ruler_origin[Geom::Y]; gtk_ruler_set_range(GTK_RULER(dtw->vruler), s, e, GTK_RULER(dtw->vruler)->position, (e - s)); } @@ -1809,8 +1809,8 @@ sp_desktop_widget_update_scrollbars (SPDesktopWidget *dtw, double scale) Geom::OptRect deskarea = Geom::unify(darea, sp_item_bbox_desktop(item)); /* Canvas region we always show unconditionally */ - Geom::Rect carea( Geom::Point(deskarea->min()[Geom::X] * scale - 64, deskarea->max()[Geom::Y] * -scale - 64), - Geom::Point(deskarea->max()[Geom::X] * scale + 64, deskarea->min()[Geom::Y] * -scale + 64) ); + Geom::Rect carea( Geom::Point(deskarea->left() * scale - 64, deskarea->top() * scale - 64), + Geom::Point(deskarea->right() * scale + 64, deskarea->bottom() * scale + 64) ); Geom::Rect viewbox = dtw->canvas->getViewbox(); -- cgit v1.2.3 From a4d3cee5535b8e5ac23039f189a6e6b029ed4f6f Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 4 Apr 2010 09:46:40 -0700 Subject: Turn off debugging. (bzr r9292) --- src/widgets/sp-color-icc-selector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/sp-color-icc-selector.cpp b/src/widgets/sp-color-icc-selector.cpp index 3b4b6b711..6bd1957a8 100644 --- a/src/widgets/sp-color-icc-selector.cpp +++ b/src/widgets/sp-color-icc-selector.cpp @@ -17,7 +17,7 @@ #include "inkscape.h" #include "profile-manager.h" -#define DEBUG_LCMS +#define noDEBUG_LCMS #if ENABLE_LCMS #include "color-profile-fns.h" -- cgit v1.2.3 From 95a0c8412e84f5e0cc1d9a63fce2be75f9fa517e Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Tue, 6 Apr 2010 16:11:54 +0200 Subject: Revert the inverted coordinate system fix. 3D Boxes and guides require an XML-level backwards compatibility mechanism to fix properly, and it's too late in the 0.48 cycle to introduce it. (bzr r9298) --- src/widgets/desktop-widget.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp index 48317aa3e..ab440595f 100644 --- a/src/widgets/desktop-widget.cpp +++ b/src/widgets/desktop-widget.cpp @@ -1493,8 +1493,8 @@ sp_desktop_widget_update_vruler (SPDesktopWidget *dtw) NR::IRect viewbox = dtw->canvas->getViewboxIntegers(); double const scale = dtw->desktop->current_zoom(); - double s = viewbox.min()[Geom::Y] / scale - dtw->ruler_origin[Geom::Y]; - double e = viewbox.max()[Geom::Y] / scale - dtw->ruler_origin[Geom::Y]; + double s = viewbox.min()[Geom::Y] / -scale - dtw->ruler_origin[Geom::Y]; + double e = viewbox.max()[Geom::Y] / -scale - dtw->ruler_origin[Geom::Y]; gtk_ruler_set_range(GTK_RULER(dtw->vruler), s, e, GTK_RULER(dtw->vruler)->position, (e - s)); } @@ -1809,8 +1809,8 @@ sp_desktop_widget_update_scrollbars (SPDesktopWidget *dtw, double scale) Geom::OptRect deskarea = Geom::unify(darea, sp_item_bbox_desktop(item)); /* Canvas region we always show unconditionally */ - Geom::Rect carea( Geom::Point(deskarea->left() * scale - 64, deskarea->top() * scale - 64), - Geom::Point(deskarea->right() * scale + 64, deskarea->bottom() * scale + 64) ); + Geom::Rect carea( Geom::Point(deskarea->min()[Geom::X] * scale - 64, deskarea->max()[Geom::Y] * -scale - 64), + Geom::Point(deskarea->max()[Geom::X] * scale + 64, deskarea->min()[Geom::Y] * -scale + 64) ); Geom::Rect viewbox = dtw->canvas->getViewbox(); -- cgit v1.2.3 From 360f55458fff0b79cada7f59adf4eb710c1519fc Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Tue, 6 Apr 2010 16:47:48 +0200 Subject: Fix "show handles" button state on Ctrl+H (bzr r9299) --- src/widgets/toolbox.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 4b0d84d90..5c890333f 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -1289,6 +1289,31 @@ sp_node_toolbox_sel_modified (Inkscape::Selection *selection, guint /*flags*/, G //## Node Editing Toolbox ## //################################ +class ShowHandlesObserver + : public Inkscape::Preferences::Observer +{ +public: + ShowHandlesObserver(InkToggleAction *act) + : Inkscape::Preferences::Observer("/tools/nodes/show_handles") + , _act(act) + { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->addObserver(*this); + } + ~ShowHandlesObserver() { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->removeObserver(*this); + } + virtual void notify(Inkscape::Preferences::Entry const &v) { + gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(_act), v.getBool()); + } + static void destroy(ShowHandlesObserver *s, InkToggleAction *) { + delete s; + } +private: + InkToggleAction *_act; +}; + static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -1442,6 +1467,8 @@ static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_show_handles), desktop ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/nodes/show_handles", true) ); + ShowHandlesObserver *s = new ShowHandlesObserver(act); + g_object_weak_ref(G_OBJECT(act), (GWeakNotify) ShowHandlesObserver::destroy, (gpointer) s); } { -- cgit v1.2.3 From 959ea09c04724ff39449aab779aa7958bcfb5a9f Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 11 Apr 2010 00:26:08 -0700 Subject: Correct calligraphic toggles getting out of sync with behavior. (bzr r9311) --- src/widgets/toolbox.cpp | 113 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 88 insertions(+), 25 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 5c890333f..f12b2d1cb 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -670,9 +670,8 @@ static void delete_connection(GObject */*obj*/, sigc::connection *connection) { delete connection; } -static void purge_repr_listener( GObject* obj, GObject* tbl ) +static void purge_repr_listener( GObject* /*obj*/, GObject* tbl ) { - (void)obj; Inkscape::XML::Node* oldrepr = reinterpret_cast( g_object_get_data( tbl, "repr" ) ); if (oldrepr) { // remove old listener sp_repr_remove_listener_by_data(oldrepr, tbl); @@ -682,6 +681,84 @@ static void purge_repr_listener( GObject* obj, GObject* tbl ) } } +// ------------------------------------------------------ + +class PrefPusher : public Inkscape::Preferences::Observer +{ +public: + PrefPusher( GtkToggleAction *act, Glib::ustring const &path, void (*callback)(GObject*) = 0, GObject *cbData = 0 ); + virtual ~PrefPusher(); + + virtual void notify(Inkscape::Preferences::Entry const &new_val); + +private: + static void toggleCB( GtkToggleAction *act, PrefPusher *self ); + + void handleToggled(); + + GtkToggleAction *act; + void (*callback)(GObject*); + GObject *cbData; + bool hold; +}; + +PrefPusher::PrefPusher( GtkToggleAction *act, Glib::ustring const &path, void (*callback)(GObject*), GObject *cbData ) : + Observer(path), + act(act), + callback(callback), + cbData(cbData), + hold(false) +{ + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggleCB), this); + hold = true; + gtk_toggle_action_set_active( act, Inkscape::Preferences::get()->getBool(observed_path, true) ); + hold = false; + + Inkscape::Preferences::get()->addObserver(*this); +} + +PrefPusher::~PrefPusher() +{ + Inkscape::Preferences::get()->removeObserver(*this); +} + +void PrefPusher::toggleCB( GtkToggleAction * /*act*/, PrefPusher *self ) +{ + if (self) { + self->handleToggled(); + } +} + +void PrefPusher::handleToggled() +{ + if (!hold) { + hold = true; + Inkscape::Preferences::get()->setBool(observed_path, gtk_toggle_action_get_active( act )); + if (callback) { + (*callback)(cbData); + } + hold = false; + } +} + +void PrefPusher::notify(Inkscape::Preferences::Entry const &newVal) +{ + bool newBool = newVal.getBool(); + bool oldBool = gtk_toggle_action_get_active(act); + + if (!hold && (newBool != oldBool)) { + gtk_toggle_action_set_active( act, newBool ); + } +} + +static void delete_prefspusher(GtkObject * /*obj*/, PrefPusher *watcher ) +{ + delete watcher; +} + +// ------------------------------------------------------ + + GtkWidget * sp_toolbox_button_new_from_verb_with_doubleclick(GtkWidget *t, Inkscape::IconSize size, SPButtonType type, Inkscape::Verb *verb, Inkscape::Verb *doubleclick_verb, @@ -4840,28 +4917,13 @@ static void sp_ddc_cap_rounding_value_changed( GtkAdjustment *adj, GObject* tbl update_presets_list(tbl); } -static void sp_ddc_pressure_state_changed( GtkToggleAction *act, GObject* tbl ) -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool("/tools/calligraphic/usepressure", gtk_toggle_action_get_active( act )); - update_presets_list(tbl); -} - -static void sp_ddc_trace_background_changed( GtkToggleAction *act, GObject* tbl ) -{ - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->setBool("/tools/calligraphic/tracebackground", gtk_toggle_action_get_active( act )); - update_presets_list(tbl); -} - static void sp_ddc_tilt_state_changed( GtkToggleAction *act, GObject* tbl ) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + // TODO merge into PrefPusher GtkAction * calligraphy_angle = static_cast (g_object_get_data(tbl,"angle_action")); - prefs->setBool("/tools/calligraphic/usetilt", gtk_toggle_action_get_active( act )); - update_presets_list(tbl); - if (calligraphy_angle ) + if (calligraphy_angle ) { gtk_action_set_sensitive( calligraphy_angle, !gtk_toggle_action_get_active( act ) ); + } } @@ -5049,7 +5111,6 @@ static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject* tbl) { } } - static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -5203,8 +5264,8 @@ static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main INKSCAPE_ICON_DRAW_TRACE_BACKGROUND, Inkscape::ICON_SIZE_DECORATION ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_ddc_trace_background_changed), holder); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/calligraphic/tracebackground", false) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/calligraphic/tracebackground", update_presets_list, holder); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); g_object_set_data( holder, "tracebackground", act ); } @@ -5216,8 +5277,8 @@ static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main INKSCAPE_ICON_DRAW_USE_PRESSURE, Inkscape::ICON_SIZE_DECORATION ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_ddc_pressure_state_changed), holder); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/calligraphic/usepressure", true) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/calligraphic/usepressure", update_presets_list, holder); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); g_object_set_data( holder, "usepressure", act ); } @@ -5229,6 +5290,8 @@ static void sp_calligraphy_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main INKSCAPE_ICON_DRAW_USE_TILT, Inkscape::ICON_SIZE_DECORATION ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/calligraphic/usetilt", update_presets_list, holder); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_ddc_tilt_state_changed), holder ); gtk_action_set_sensitive( GTK_ACTION(calligraphy_angle), !prefs->getBool("/tools/calligraphic/usetilt", true) ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/calligraphic/usetilt", true) ); -- cgit v1.2.3 From 95645b92240b41fb65cddb892145eb68495087ca Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 11 Apr 2010 23:22:27 -0700 Subject: Fixed state sync for node tool booleans. Addressing bug #426032. (bzr r9316) --- src/widgets/toolbox.cpp | 808 ++++++++++++++++++++++-------------------------- 1 file changed, 378 insertions(+), 430 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index f12b2d1cb..bf1231092 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -518,20 +518,20 @@ static gchar const * ui_descr = static Glib::RefPtr create_or_fetch_actions( SPDesktop* desktop ); -void setup_snap_toolbox (GtkWidget *toolbox, SPDesktop *desktop); +static void setup_snap_toolbox(GtkWidget *toolbox, SPDesktop *desktop); -static void setup_tool_toolbox (GtkWidget *toolbox, SPDesktop *desktop); -static void update_tool_toolbox (SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox); +static void setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop); +static void update_tool_toolbox(SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox); -static void setup_aux_toolbox (GtkWidget *toolbox, SPDesktop *desktop); -static void update_aux_toolbox (SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox); +static void setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop); +static void update_aux_toolbox(SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox); -static void setup_commands_toolbox (GtkWidget *toolbox, SPDesktop *desktop); -static void update_commands_toolbox (SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox); +static void setup_commands_toolbox(GtkWidget *toolbox, SPDesktop *desktop); +static void update_commands_toolbox(SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget *toolbox); -GtkWidget * sp_toolbox_button_new_from_verb_with_doubleclick( GtkWidget *t, Inkscape::IconSize size, SPButtonType type, - Inkscape::Verb *verb, Inkscape::Verb *doubleclick_verb, - Inkscape::UI::View::View *view, GtkTooltips *tt); +static GtkWidget * sp_toolbox_button_new_from_verb_with_doubleclick( GtkWidget *t, Inkscape::IconSize size, SPButtonType type, + Inkscape::Verb *verb, Inkscape::Verb *doubleclick_verb, + Inkscape::UI::View::View *view, GtkTooltips *tt); class VerbAction : public Gtk::Action { public: @@ -665,7 +665,8 @@ void VerbAction::on_activate() *dropper_opacity_entry ; */ // should be made a private member once this is converted to class -static void delete_connection(GObject */*obj*/, sigc::connection *connection) { +static void delete_connection(GObject * /*obj*/, sigc::connection *connection) +{ connection->disconnect(); delete connection; } @@ -683,23 +684,52 @@ static void purge_repr_listener( GObject* /*obj*/, GObject* tbl ) // ------------------------------------------------------ +/** + * A simple mediator class that keeps UI controls matched to the preference values they set. + */ class PrefPusher : public Inkscape::Preferences::Observer { public: + /** + * Constructor for a boolean value that syncs to the supplied path. + * Initializes the widget to the current preference stored state and registers callbacks + * for widget changes and preference changes. + * + * @param act the widget to synchronize preference with. + * @param path the path to the preference the widget is synchronized with. + * @param callback function to invoke when changes are pushed. + * @param cbData data to be passed on to the callback function. + */ PrefPusher( GtkToggleAction *act, Glib::ustring const &path, void (*callback)(GObject*) = 0, GObject *cbData = 0 ); + + /** + * Destructor that unregisters the preference callback. + */ virtual ~PrefPusher(); + /** + * Callback method invoked when the preference setting changes. + */ virtual void notify(Inkscape::Preferences::Entry const &new_val); private: + /** + * Callback hook invoked when the widget changes. + * + * @param act the toggle action widget that was changed. + * @param self the PrefPusher instance the callback was registered to. + */ static void toggleCB( GtkToggleAction *act, PrefPusher *self ); + /** + * Method to handle the widget change. + */ void handleToggled(); GtkToggleAction *act; void (*callback)(GObject*); GObject *cbData; - bool hold; + bool freeze; }; PrefPusher::PrefPusher( GtkToggleAction *act, Glib::ustring const &path, void (*callback)(GObject*), GObject *cbData ) : @@ -707,12 +737,12 @@ PrefPusher::PrefPusher( GtkToggleAction *act, Glib::ustring const &path, void (* act(act), callback(callback), cbData(cbData), - hold(false) + freeze(false) { g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggleCB), this); - hold = true; + freeze = true; gtk_toggle_action_set_active( act, Inkscape::Preferences::get()->getBool(observed_path, true) ); - hold = false; + freeze = false; Inkscape::Preferences::get()->addObserver(*this); } @@ -731,13 +761,13 @@ void PrefPusher::toggleCB( GtkToggleAction * /*act*/, PrefPusher *self ) void PrefPusher::handleToggled() { - if (!hold) { - hold = true; + if (!freeze) { + freeze = true; Inkscape::Preferences::get()->setBool(observed_path, gtk_toggle_action_get_active( act )); if (callback) { (*callback)(cbData); } - hold = false; + freeze = false; } } @@ -746,7 +776,7 @@ void PrefPusher::notify(Inkscape::Preferences::Entry const &newVal) bool newBool = newVal.getBool(); bool oldBool = gtk_toggle_action_get_active(act); - if (!hold && (newBool != oldBool)) { + if (!freeze && (newBool != oldBool)) { gtk_toggle_action_set_active( act, newBool ); } } @@ -759,19 +789,21 @@ static void delete_prefspusher(GtkObject * /*obj*/, PrefPusher *watcher ) // ------------------------------------------------------ -GtkWidget * -sp_toolbox_button_new_from_verb_with_doubleclick(GtkWidget *t, Inkscape::IconSize size, SPButtonType type, - Inkscape::Verb *verb, Inkscape::Verb *doubleclick_verb, - Inkscape::UI::View::View *view, GtkTooltips *tt) +GtkWidget * sp_toolbox_button_new_from_verb_with_doubleclick(GtkWidget *t, Inkscape::IconSize size, SPButtonType type, + Inkscape::Verb *verb, Inkscape::Verb *doubleclick_verb, + Inkscape::UI::View::View *view, GtkTooltips *tt) { SPAction *action = verb->get_action(view); - if (!action) return NULL; + if (!action) { + return NULL; + } SPAction *doubleclick_action; - if (doubleclick_verb) + if (doubleclick_verb) { doubleclick_action = doubleclick_verb->get_action(view); - else + } else { doubleclick_action = NULL; + } /* fixme: Handle sensitive/unsensitive */ /* fixme: Implement sp_button_new_from_action */ @@ -806,7 +838,7 @@ static void trigger_sp_action( GtkAction* /*act*/, gpointer user_data ) } } -static void sp_action_action_set_sensitive (SPAction */*action*/, unsigned int sensitive, void *data) +static void sp_action_action_set_sensitive(SPAction * /*action*/, unsigned int sensitive, void *data) { if ( data ) { GtkAction* act = GTK_ACTION(data); @@ -840,7 +872,7 @@ static GtkAction* create_action_for_verb( Inkscape::Verb* verb, Inkscape::UI::Vi return act; } -Glib::RefPtr create_or_fetch_actions( SPDesktop* desktop ) +static Glib::RefPtr create_or_fetch_actions( SPDesktop* desktop ) { Inkscape::UI::View::View *view = desktop; gint verbsToUse[] = { @@ -964,14 +996,14 @@ Glib::RefPtr create_or_fetch_actions( SPDesktop* desktop ) } -void handlebox_detached(GtkHandleBox* /*handlebox*/, GtkWidget* widget, gpointer /*userData*/) +static void handlebox_detached(GtkHandleBox* /*handlebox*/, GtkWidget* widget, gpointer /*userData*/) { gtk_widget_set_size_request( widget, widget->allocation.width, widget->allocation.height ); } -void handlebox_attached(GtkHandleBox* /*handlebox*/, GtkWidget* widget, gpointer /*userData*/) +static void handlebox_attached(GtkHandleBox* /*handlebox*/, GtkWidget* widget, gpointer /*userData*/) { gtk_widget_set_size_request( widget, -1, -1 ); } @@ -1100,14 +1132,17 @@ static EgeAdjustmentAction * create_adjustment_action( gchar const *name, * Will go away during tool refactoring. */ static InkNodeTool *get_node_tool() { - if (!SP_ACTIVE_DESKTOP) return NULL; - SPEventContext *ec = SP_ACTIVE_DESKTOP->event_context; - if (!INK_IS_NODE_TOOL(ec)) return NULL; - return static_cast(ec); + InkNodeTool *tool = 0; + if (SP_ACTIVE_DESKTOP ) { + SPEventContext *ec = SP_ACTIVE_DESKTOP->event_context; + if (INK_IS_NODE_TOOL(ec)) { + tool = static_cast(ec); + } + } + return tool; } -void -sp_node_path_edit_add(void) +static void sp_node_path_edit_add(void) { InkNodeTool *nt = get_node_tool(); if (nt) { @@ -1115,8 +1150,7 @@ sp_node_path_edit_add(void) } } -void -sp_node_path_edit_delete(void) +static void sp_node_path_edit_delete(void) { InkNodeTool *nt = get_node_tool(); if (nt) { @@ -1125,8 +1159,7 @@ sp_node_path_edit_delete(void) } } -void -sp_node_path_edit_delete_segment(void) +static void sp_node_path_edit_delete_segment(void) { InkNodeTool *nt = get_node_tool(); if (nt) { @@ -1134,8 +1167,7 @@ sp_node_path_edit_delete_segment(void) } } -void -sp_node_path_edit_break(void) +static void sp_node_path_edit_break(void) { InkNodeTool *nt = get_node_tool(); if (nt) { @@ -1143,8 +1175,7 @@ sp_node_path_edit_break(void) } } -void -sp_node_path_edit_join(void) +static void sp_node_path_edit_join(void) { InkNodeTool *nt = get_node_tool(); if (nt) { @@ -1152,8 +1183,7 @@ sp_node_path_edit_join(void) } } -void -sp_node_path_edit_join_segment(void) +static void sp_node_path_edit_join_segment(void) { InkNodeTool *nt = get_node_tool(); if (nt) { @@ -1161,8 +1191,7 @@ sp_node_path_edit_join_segment(void) } } -void -sp_node_path_edit_toline(void) +static void sp_node_path_edit_toline(void) { InkNodeTool *nt = get_node_tool(); if (nt) { @@ -1170,8 +1199,7 @@ sp_node_path_edit_toline(void) } } -void -sp_node_path_edit_tocurve(void) +static void sp_node_path_edit_tocurve(void) { InkNodeTool *nt = get_node_tool(); if (nt) { @@ -1179,8 +1207,7 @@ sp_node_path_edit_tocurve(void) } } -void -sp_node_path_edit_cusp(void) +static void sp_node_path_edit_cusp(void) { InkNodeTool *nt = get_node_tool(); if (nt) { @@ -1188,8 +1215,7 @@ sp_node_path_edit_cusp(void) } } -void -sp_node_path_edit_smooth(void) +static void sp_node_path_edit_smooth(void) { InkNodeTool *nt = get_node_tool(); if (nt) { @@ -1197,8 +1223,7 @@ sp_node_path_edit_smooth(void) } } -void -sp_node_path_edit_symmetrical(void) +static void sp_node_path_edit_symmetrical(void) { InkNodeTool *nt = get_node_tool(); if (nt) { @@ -1206,8 +1231,7 @@ sp_node_path_edit_symmetrical(void) } } -void -sp_node_path_edit_auto(void) +static void sp_node_path_edit_auto(void) { InkNodeTool *nt = get_node_tool(); if (nt) { @@ -1215,43 +1239,12 @@ sp_node_path_edit_auto(void) } } -static void toggle_show_transform_handles (GtkToggleAction *act, gpointer /*data*/) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - bool show = gtk_toggle_action_get_active( act ); - prefs->setBool("/tools/nodes/show_transform_handles", show); -} - -static void toggle_show_handles (GtkToggleAction *act, gpointer /*data*/) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - bool show = gtk_toggle_action_get_active( act ); - prefs->setBool("/tools/nodes/show_handles", show); -} - -static void toggle_show_helperpath (GtkToggleAction *act, gpointer /*data*/) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - bool show = gtk_toggle_action_get_active( act ); - prefs->setBool("/tools/nodes/show_outline", show); -} - -void sp_node_path_edit_nextLPEparam (GtkAction */*act*/, gpointer data) { +static void sp_node_path_edit_nextLPEparam(GtkAction * /*act*/, gpointer data) { sp_selection_next_patheffect_param( reinterpret_cast(data) ); } -void toggle_edit_clip (GtkToggleAction *act, gpointer /*data*/) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - bool edit = gtk_toggle_action_get_active( act ); - prefs->setBool("/tools/nodes/edit_clipping_paths", edit); -} - -void toggle_edit_mask (GtkToggleAction *act, gpointer /*data*/) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - bool edit = gtk_toggle_action_get_active( act ); - prefs->setBool("/tools/nodes/edit_masks", edit); -} - /* is called when the node selection is modified */ -static void -sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tbl) +static void sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tbl) { GtkAction* xact = GTK_ACTION( g_object_get_data( tbl, "nodes_x_action" ) ); GtkAction* yact = GTK_ACTION( g_object_get_data( tbl, "nodes_y_action" ) ); @@ -1281,17 +1274,18 @@ sp_node_toolbox_coord_changed(gpointer /*shape_editor*/, GObject *tbl) Geom::Coord oldy = sp_units_get_pixels(gtk_adjustment_get_value(xadj), *unit); Geom::Point mid = nt->_selected_nodes->pointwiseBounds()->midpoint(); - if (oldx != mid[Geom::X]) + if (oldx != mid[Geom::X]) { gtk_adjustment_set_value(xadj, sp_pixels_get_units(mid[Geom::X], *unit)); - if (oldy != mid[Geom::Y]) + } + if (oldy != mid[Geom::Y]) { gtk_adjustment_set_value(yadj, sp_pixels_get_units(mid[Geom::Y], *unit)); + } } g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); } -static void -sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::Dim2 d) +static void sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::Dim2 d) { SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" ); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -1324,20 +1318,17 @@ sp_node_path_value_changed(GtkAdjustment *adj, GObject *tbl, Geom::Dim2 d) g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); } -static void -sp_node_path_x_value_changed(GtkAdjustment *adj, GObject *tbl) +static void sp_node_path_x_value_changed(GtkAdjustment *adj, GObject *tbl) { sp_node_path_value_changed(adj, tbl, Geom::X); } -static void -sp_node_path_y_value_changed(GtkAdjustment *adj, GObject *tbl) +static void sp_node_path_y_value_changed(GtkAdjustment *adj, GObject *tbl) { sp_node_path_value_changed(adj, tbl, Geom::Y); } -void -sp_node_toolbox_sel_changed (Inkscape::Selection *selection, GObject *tbl) +static void sp_node_toolbox_sel_changed(Inkscape::Selection *selection, GObject *tbl) { { GtkAction* w = GTK_ACTION( g_object_get_data( tbl, "nodes_lpeedit" ) ); @@ -1354,8 +1345,7 @@ sp_node_toolbox_sel_changed (Inkscape::Selection *selection, GObject *tbl) } } -void -sp_node_toolbox_sel_modified (Inkscape::Selection *selection, guint /*flags*/, GObject *tbl) +static void sp_node_toolbox_sel_modified(Inkscape::Selection *selection, guint /*flags*/, GObject *tbl) { sp_node_toolbox_sel_changed (selection, tbl); } @@ -1366,34 +1356,8 @@ sp_node_toolbox_sel_modified (Inkscape::Selection *selection, guint /*flags*/, G //## Node Editing Toolbox ## //################################ -class ShowHandlesObserver - : public Inkscape::Preferences::Observer -{ -public: - ShowHandlesObserver(InkToggleAction *act) - : Inkscape::Preferences::Observer("/tools/nodes/show_handles") - , _act(act) - { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->addObserver(*this); - } - ~ShowHandlesObserver() { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->removeObserver(*this); - } - virtual void notify(Inkscape::Preferences::Entry const &v) { - gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(_act), v.getBool()); - } - static void destroy(ShowHandlesObserver *s, InkToggleAction *) { - delete s; - } -private: - InkToggleAction *_act; -}; - static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); g_object_set_data( holder, "tracker", tracker ); @@ -1531,8 +1495,8 @@ static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions "node-transform", secondarySize ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_show_transform_handles), desktop ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/nodes/show_transform_handles", false) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/nodes/show_transform_handles"); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); } { @@ -1542,10 +1506,8 @@ static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions INKSCAPE_ICON_SHOW_NODE_HANDLES, secondarySize ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_show_handles), desktop ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/nodes/show_handles", true) ); - ShowHandlesObserver *s = new ShowHandlesObserver(act); - g_object_weak_ref(G_OBJECT(act), (GWeakNotify) ShowHandlesObserver::destroy, (gpointer) s); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/nodes/show_handles"); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); } { @@ -1555,8 +1517,8 @@ static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions INKSCAPE_ICON_SHOW_PATH_OUTLINE, secondarySize ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); - g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggle_show_helperpath), desktop ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/nodes/show_outline", false) ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(act), "/tools/nodes/show_outline"); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); } { @@ -1577,8 +1539,8 @@ static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions INKSCAPE_ICON_PATH_CLIP_EDIT, secondarySize ); gtk_action_group_add_action( mainActions, GTK_ACTION(inky) ); - g_signal_connect_after( G_OBJECT(inky), "toggled", G_CALLBACK(toggle_edit_clip), desktop ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(inky), prefs->getBool("/tools/nodes/edit_clipping_paths") ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(inky), "/tools/nodes/edit_clipping_paths"); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); } { @@ -1588,8 +1550,8 @@ static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions INKSCAPE_ICON_PATH_MASK_EDIT, secondarySize ); gtk_action_group_add_action( mainActions, GTK_ACTION(inky) ); - g_signal_connect_after( G_OBJECT(inky), "toggled", G_CALLBACK(toggle_edit_mask), desktop ); - gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(inky), prefs->getBool("/tools/nodes/edit_masks") ); + PrefPusher *pusher = new PrefPusher(GTK_TOGGLE_ACTION(inky), "/tools/nodes/edit_masks"); + g_signal_connect( holder, "destroy", G_CALLBACK(delete_prefspusher), pusher); } /* X coord of selected node(s) */ @@ -1665,7 +1627,7 @@ static void sp_node_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions //## Zoom Toolbox ## //######################## -static void sp_zoom_toolbox_prep(SPDesktop */*desktop*/, GtkActionGroup* /*mainActions*/, GObject* /*holder*/) +static void sp_zoom_toolbox_prep(SPDesktop * /*desktop*/, GtkActionGroup* /*mainActions*/, GObject* /*holder*/) { // no custom GtkAction setup needed } // end of sp_zoom_toolbox_prep() @@ -1870,8 +1832,7 @@ void ToolboxFactory::setOrientation(GtkWidget* toolbox, GtkOrientation orientati } } -static void -setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop) +void setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { gchar const * descr = "" @@ -1904,8 +1865,7 @@ setup_tool_toolbox(GtkWidget *toolbox, SPDesktop *desktop) "/toolbox/tools/small"); } -static void -update_tool_toolbox( SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget */*toolbox*/ ) +void update_tool_toolbox( SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget * /*toolbox*/ ) { gchar const *const tname = ( eventcontext ? gtk_type_name(GTK_OBJECT_TYPE(eventcontext)) @@ -1924,8 +1884,7 @@ update_tool_toolbox( SPDesktop *desktop, SPEventContext *eventcontext, GtkWidget } } -static void -setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop) +void setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); GtkSizeGroup* grouper = gtk_size_group_new( GTK_SIZE_GROUP_BOTH ); @@ -2009,8 +1968,7 @@ setup_aux_toolbox(GtkWidget *toolbox, SPDesktop *desktop) g_object_unref( G_OBJECT(grouper) ); } -static void -update_aux_toolbox(SPDesktop */*desktop*/, SPEventContext *eventcontext, GtkWidget *toolbox) +void update_aux_toolbox(SPDesktop * /*desktop*/, SPEventContext *eventcontext, GtkWidget *toolbox) { gchar const *tname = ( eventcontext ? gtk_type_name(GTK_OBJECT_TYPE(eventcontext)) @@ -2026,8 +1984,7 @@ update_aux_toolbox(SPDesktop */*desktop*/, SPEventContext *eventcontext, GtkWidg } } -static void -setup_commands_toolbox(GtkWidget *toolbox, SPDesktop *desktop) +void setup_commands_toolbox(GtkWidget *toolbox, SPDesktop *desktop) { gchar const * descr = "" @@ -2078,13 +2035,12 @@ setup_commands_toolbox(GtkWidget *toolbox, SPDesktop *desktop) "/toolbox/small" ); } -static void -update_commands_toolbox(SPDesktop */*desktop*/, SPEventContext */*eventcontext*/, GtkWidget */*toolbox*/) +void update_commands_toolbox(SPDesktop * /*desktop*/, SPEventContext * /*eventcontext*/, GtkWidget * /*toolbox*/) { } -void toggle_snap_callback (GtkToggleAction *act, gpointer data) { //data points to the toolbox - +static void toggle_snap_callback(GtkToggleAction *act, gpointer data) //data points to the toolbox +{ if (g_object_get_data(G_OBJECT(data), "freeze" )) { return; } @@ -2420,7 +2376,7 @@ Glib::ustring ToolboxFactory::getToolboxName(GtkWidget* toolbox) return name; } -void ToolboxFactory::updateSnapToolbox(SPDesktop *desktop, SPEventContext */*eventcontext*/, GtkWidget *toolbox) +void ToolboxFactory::updateSnapToolbox(SPDesktop *desktop, SPEventContext * /*eventcontext*/, GtkWidget *toolbox) { g_assert(desktop != NULL); g_assert(toolbox != NULL); @@ -2578,8 +2534,10 @@ static void sp_stb_magnitude_value_changed( GtkAdjustment *adj, GObject *dataKlu modmade = true; } } - if (modmade) sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, - _("Star: Change number of corners")); + if (modmade) { + sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, + _("Star: Change number of corners")); + } g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) ); } @@ -2623,8 +2581,10 @@ static void sp_stb_proportion_value_changed( GtkAdjustment *adj, GObject *dataKl } } - if (modmade) sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, - _("Star: Change spoke ratio")); + if (modmade) { + sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, + _("Star: Change spoke ratio")); + } g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) ); } @@ -2702,8 +2662,10 @@ static void sp_stb_rounded_value_changed( GtkAdjustment *adj, GObject *dataKludg modmade = true; } } - if (modmade) sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, - _("Star: Change rounding")); + if (modmade) { + sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, + _("Star: Change rounding")); + } g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) ); } @@ -2737,15 +2699,17 @@ static void sp_stb_randomized_value_changed( GtkAdjustment *adj, GObject *dataKl modmade = true; } } - if (modmade) sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, - _("Star: Change randomization")); + if (modmade) { + sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_STAR, + _("Star: Change randomization")); + } g_object_set_data( dataKludge, "freeze", GINT_TO_POINTER(FALSE) ); } static void star_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name, - gchar const */*old_value*/, gchar const */*new_value*/, + gchar const * /*old_value*/, gchar const * /*new_value*/, bool /*is_interactive*/, gpointer data) { GtkWidget *tbl = GTK_WIDGET(data); @@ -2850,7 +2814,7 @@ sp_star_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) } -static void sp_stb_defaults( GtkWidget */*widget*/, GObject *dataKludge ) +static void sp_stb_defaults( GtkWidget * /*widget*/, GObject *dataKludge ) { // FIXME: in this and all other _default functions, set some flag telling the value_changed // callbacks to lump all the changes for all selected objects in one undo step @@ -2888,11 +2852,13 @@ static void sp_stb_defaults( GtkWidget */*widget*/, GObject *dataKludge ) } -void -sp_toolbox_add_label(GtkWidget *tbl, gchar const *title, bool wide) +// public: +void sp_toolbox_add_label(GtkWidget *tbl, gchar const *title, bool wide) { GtkWidget *boxl = gtk_hbox_new(FALSE, 0); - if (wide) gtk_widget_set_size_request(boxl, MODE_LABEL_WIDTH, -1); + if (wide) { + gtk_widget_set_size_request(boxl, MODE_LABEL_WIDTH, -1); + } GtkWidget *l = gtk_label_new(NULL); gtk_label_set_markup(GTK_LABEL(l), title); gtk_box_pack_end(GTK_BOX(boxl), l, FALSE, FALSE, 0); @@ -3065,9 +3031,8 @@ static void sp_rtb_sensitivize( GObject *tbl ) } -static void -sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *value_name, - void (*setter)(SPRect *, gdouble)) +static void sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *value_name, + void (*setter)(SPRect *, gdouble)) { SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" ); @@ -3110,34 +3075,29 @@ sp_rtb_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *value_name, g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); } -static void -sp_rtb_rx_value_changed(GtkAdjustment *adj, GObject *tbl) +static void sp_rtb_rx_value_changed(GtkAdjustment *adj, GObject *tbl) { sp_rtb_value_changed(adj, tbl, "rx", sp_rect_set_visible_rx); } -static void -sp_rtb_ry_value_changed(GtkAdjustment *adj, GObject *tbl) +static void sp_rtb_ry_value_changed(GtkAdjustment *adj, GObject *tbl) { sp_rtb_value_changed(adj, tbl, "ry", sp_rect_set_visible_ry); } -static void -sp_rtb_width_value_changed(GtkAdjustment *adj, GObject *tbl) +static void sp_rtb_width_value_changed(GtkAdjustment *adj, GObject *tbl) { sp_rtb_value_changed(adj, tbl, "width", sp_rect_set_visible_width); } -static void -sp_rtb_height_value_changed(GtkAdjustment *adj, GObject *tbl) +static void sp_rtb_height_value_changed(GtkAdjustment *adj, GObject *tbl) { sp_rtb_value_changed(adj, tbl, "height", sp_rect_set_visible_height); } -static void -sp_rtb_defaults( GtkWidget */*widget*/, GObject *obj) +static void sp_rtb_defaults( GtkWidget * /*widget*/, GObject *obj) { GtkAdjustment *adj = 0; @@ -3153,8 +3113,8 @@ sp_rtb_defaults( GtkWidget */*widget*/, GObject *obj) sp_rtb_sensitivize( obj ); } -static void rect_tb_event_attr_changed(Inkscape::XML::Node */*repr*/, gchar const */*name*/, - gchar const */*old_value*/, gchar const */*new_value*/, +static void rect_tb_event_attr_changed(Inkscape::XML::Node * /*repr*/, gchar const * /*name*/, + gchar const * /*old_value*/, gchar const * /*new_value*/, bool /*is_interactive*/, gpointer data) { GObject *tbl = G_OBJECT(data); @@ -3214,8 +3174,7 @@ static Inkscape::XML::NodeEventVector rect_tb_repr_events = { /** * \param selection should not be NULL. */ -static void -sp_rect_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) +static void sp_rect_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) { int n_selected = 0; Inkscape::XML::Node *repr = NULL; @@ -3398,9 +3357,12 @@ static double box3d_normalize_angle (double a) { return angle; } -static void -box3d_set_button_and_adjustment(Persp3D *persp, Proj::Axis axis, - GtkAdjustment *adj, GtkAction *act, GtkToggleAction *tact) { +static void box3d_set_button_and_adjustment(Persp3D *persp, + Proj::Axis axis, + GtkAdjustment *adj, + GtkAction *act, + GtkToggleAction *tact) +{ // TODO: Take all selected perspectives into account but don't touch the state button if not all of them // have the same state (otherwise a call to box3d_vp_z_state_changed() is triggered and the states // are reset). @@ -3420,8 +3382,8 @@ box3d_set_button_and_adjustment(Persp3D *persp, Proj::Axis axis, } } -static void -box3d_resync_toolbar(Inkscape::XML::Node *persp_repr, GObject *data) { +static void box3d_resync_toolbar(Inkscape::XML::Node *persp_repr, GObject *data) +{ if (!persp_repr) { g_print ("No perspective given to box3d_resync_toolbar().\n"); return; @@ -3459,9 +3421,12 @@ box3d_resync_toolbar(Inkscape::XML::Node *persp_repr, GObject *data) { } } -static void box3d_persp_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const */*name*/, - gchar const */*old_value*/, gchar const */*new_value*/, - bool /*is_interactive*/, gpointer data) +static void box3d_persp_tb_event_attr_changed(Inkscape::XML::Node *repr, + gchar const * /*name*/, + gchar const * /*old_value*/, + gchar const * /*new_value*/, + bool /*is_interactive*/, + gpointer data) { GtkWidget *tbl = GTK_WIDGET(data); @@ -3499,8 +3464,7 @@ static Inkscape::XML::NodeEventVector box3d_persp_tb_repr_events = */ // FIXME: This should rather be put into persp3d-reference.cpp or something similar so that it reacts upon each // Change of the perspective, and not of the current selection (but how to refer to the toolbar then?) -static void -box3d_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) +static void box3d_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) { // Here the following should be done: If all selected boxes have finite VPs in a certain direction, // disable the angle entry fields for this direction (otherwise entering a value in them should only @@ -3532,8 +3496,7 @@ box3d_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) } } -static void -box3d_angle_value_changed(GtkAdjustment *adj, GObject *dataKludge, Proj::Axis axis) +static void box3d_angle_value_changed(GtkAdjustment *adj, GObject *dataKludge, Proj::Axis axis) { SPDesktop *desktop = (SPDesktop *) g_object_get_data( dataKludge, "desktop" ); SPDocument *document = sp_desktop_document(desktop); @@ -3563,26 +3526,23 @@ box3d_angle_value_changed(GtkAdjustment *adj, GObject *dataKludge, Proj::Axis ax } -static void -box3d_angle_x_value_changed(GtkAdjustment *adj, GObject *dataKludge) +static void box3d_angle_x_value_changed(GtkAdjustment *adj, GObject *dataKludge) { box3d_angle_value_changed(adj, dataKludge, Proj::X); } -static void -box3d_angle_y_value_changed(GtkAdjustment *adj, GObject *dataKludge) +static void box3d_angle_y_value_changed(GtkAdjustment *adj, GObject *dataKludge) { box3d_angle_value_changed(adj, dataKludge, Proj::Y); } -static void -box3d_angle_z_value_changed(GtkAdjustment *adj, GObject *dataKludge) +static void box3d_angle_z_value_changed(GtkAdjustment *adj, GObject *dataKludge) { box3d_angle_value_changed(adj, dataKludge, Proj::Z); } -static void box3d_vp_state_changed( GtkToggleAction *act, GtkAction */*box3d_angle*/, Proj::Axis axis ) +static void box3d_vp_state_changed( GtkToggleAction *act, GtkAction * /*box3d_angle*/, Proj::Axis axis ) { // TODO: Take all selected perspectives into account std::list sel_persps = sp_desktop_selection(inkscape_active_desktop())->perspList(); @@ -3751,8 +3711,7 @@ static void box3d_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, //## Spiral ## //######################## -static void -sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustring const &value_name) +static void sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustring const &value_name) { SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" ); @@ -3794,26 +3753,22 @@ sp_spl_tb_value_changed(GtkAdjustment *adj, GObject *tbl, Glib::ustring const &v g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); } -static void -sp_spl_tb_revolution_value_changed(GtkAdjustment *adj, GObject *tbl) +static void sp_spl_tb_revolution_value_changed(GtkAdjustment *adj, GObject *tbl) { sp_spl_tb_value_changed(adj, tbl, "revolution"); } -static void -sp_spl_tb_expansion_value_changed(GtkAdjustment *adj, GObject *tbl) +static void sp_spl_tb_expansion_value_changed(GtkAdjustment *adj, GObject *tbl) { sp_spl_tb_value_changed(adj, tbl, "expansion"); } -static void -sp_spl_tb_t0_value_changed(GtkAdjustment *adj, GObject *tbl) +static void sp_spl_tb_t0_value_changed(GtkAdjustment *adj, GObject *tbl) { sp_spl_tb_value_changed(adj, tbl, "t0"); } -static void -sp_spl_tb_defaults(GtkWidget */*widget*/, GtkObject *obj) +static void sp_spl_tb_defaults(GtkWidget * /*widget*/, GtkObject *obj) { GtkWidget *tbl = GTK_WIDGET(obj); @@ -3840,9 +3795,12 @@ sp_spl_tb_defaults(GtkWidget */*widget*/, GtkObject *obj) } -static void spiral_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const */*name*/, - gchar const */*old_value*/, gchar const */*new_value*/, - bool /*is_interactive*/, gpointer data) +static void spiral_tb_event_attr_changed(Inkscape::XML::Node *repr, + gchar const * /*name*/, + gchar const * /*old_value*/, + gchar const * /*new_value*/, + bool /*is_interactive*/, + gpointer data) { GtkWidget *tbl = GTK_WIDGET(data); @@ -3876,8 +3834,7 @@ static Inkscape::XML::NodeEventVector spiral_tb_repr_events = { NULL /* order_changed */ }; -static void -sp_spiral_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) +static void sp_spiral_toolbox_selection_changed(Inkscape::Selection *selection, GObject *tbl) { int n_selected = 0; Inkscape::XML::Node *repr = NULL; @@ -3993,8 +3950,7 @@ static void sp_spiral_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActio //######################## /* This is used in generic functions below to share large portions of code between pen and pencil tool */ -static Glib::ustring const -freehand_tool_name(GObject *dataKludge) +static Glib::ustring const freehand_tool_name(GObject *dataKludge) { SPDesktop *desktop = (SPDesktop *) g_object_get_data(dataKludge, "desktop"); return ( tools_isactive(desktop, TOOLS_FREEHAND_PEN) @@ -4089,7 +4045,7 @@ static void freehand_change_shape(EgeSelectOneAction* act, GObject *dataKludge) /** * \brief Generate the list of freehand advanced shape option entries. */ -GList * freehand_shape_dropdown_items_list() { +static GList * freehand_shape_dropdown_items_list() { GList *glist = NULL; glist = g_list_append (glist, _("None")); @@ -4101,8 +4057,8 @@ GList * freehand_shape_dropdown_items_list() { return glist; } -static void -freehand_add_advanced_shape_options(GtkActionGroup* mainActions, GObject* holder, bool tool_is_pencil) { +static void freehand_add_advanced_shape_options(GtkActionGroup* mainActions, GObject* holder, bool tool_is_pencil) +{ /*advanced shape options */ { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -4131,15 +4087,14 @@ freehand_add_advanced_shape_options(GtkActionGroup* mainActions, GObject* holder } } -static void sp_pen_toolbox_prep(SPDesktop */*desktop*/, GtkActionGroup* mainActions, GObject* holder) +static void sp_pen_toolbox_prep(SPDesktop * /*desktop*/, GtkActionGroup* mainActions, GObject* holder) { sp_add_freehand_mode_toggle(mainActions, holder, false); freehand_add_advanced_shape_options(mainActions, holder, false); } -static void -sp_pencil_tb_defaults(GtkWidget */*widget*/, GtkObject *obj) +static void sp_pencil_tb_defaults(GtkWidget * /*widget*/, GtkObject *obj) { GtkWidget *tbl = GTK_WIDGET(obj); @@ -4155,8 +4110,7 @@ sp_pencil_tb_defaults(GtkWidget */*widget*/, GtkObject *obj) spinbutton_defocus(GTK_OBJECT(tbl)); } -static void -sp_pencil_tb_tolerance_value_changed(GtkAdjustment *adj, GObject *tbl) +static void sp_pencil_tb_tolerance_value_changed(GtkAdjustment *adj, GObject *tbl) { // quit if run by the attr_changed listener if (g_object_get_data( tbl, "freeze" )) { @@ -4247,13 +4201,13 @@ static void sp_pencil_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActio //## Tweak ## //######################## -static void sp_tweak_width_value_changed( GtkAdjustment *adj, GObject */*tbl*/ ) +static void sp_tweak_width_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/tweak/width", adj->value * 0.01 ); } -static void sp_tweak_force_value_changed( GtkAdjustment *adj, GObject */*tbl*/ ) +static void sp_tweak_force_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/tweak/force", adj->value * 0.01 ); @@ -4271,48 +4225,39 @@ static void sp_tweak_mode_changed( EgeSelectOneAction *act, GObject *tbl ) Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setInt("/tools/tweak/mode", mode); - GtkAction *doh = GTK_ACTION(g_object_get_data( tbl, "tweak_doh")); - GtkAction *dos = GTK_ACTION(g_object_get_data( tbl, "tweak_dos")); - GtkAction *dol = GTK_ACTION(g_object_get_data( tbl, "tweak_dol")); - GtkAction *doo = GTK_ACTION(g_object_get_data( tbl, "tweak_doo")); + static gchar const* names[] = {"tweak_doh", "tweak_dos", "tweak_dol", "tweak_doo", "tweak_channels_label"}; + bool flag = ((mode == TWEAK_MODE_COLORPAINT) || (mode == TWEAK_MODE_COLORJITTER)); + for (size_t i = 0; i < G_N_ELEMENTS(names); ++i) { + GtkAction *act = GTK_ACTION(g_object_get_data( tbl, names[i] )); + if (act) { + gtk_action_set_sensitive(act, flag); + } + } GtkAction *fid = GTK_ACTION(g_object_get_data( tbl, "tweak_fidelity")); - GtkAction *dolabel = GTK_ACTION(g_object_get_data( tbl, "tweak_channels_label")); - if (mode == TWEAK_MODE_COLORPAINT || mode == TWEAK_MODE_COLORJITTER) { - if (doh) gtk_action_set_sensitive (doh, TRUE); - if (dos) gtk_action_set_sensitive (dos, TRUE); - if (dol) gtk_action_set_sensitive (dol, TRUE); - if (doo) gtk_action_set_sensitive (doo, TRUE); - if (dolabel) gtk_action_set_sensitive (dolabel, TRUE); - if (fid) gtk_action_set_sensitive (fid, FALSE); - } else { - if (doh) gtk_action_set_sensitive (doh, FALSE); - if (dos) gtk_action_set_sensitive (dos, FALSE); - if (dol) gtk_action_set_sensitive (dol, FALSE); - if (doo) gtk_action_set_sensitive (doo, FALSE); - if (dolabel) gtk_action_set_sensitive (dolabel, FALSE); - if (fid) gtk_action_set_sensitive (fid, TRUE); + if (fid) { + gtk_action_set_sensitive(fid, !flag); } } -static void sp_tweak_fidelity_value_changed( GtkAdjustment *adj, GObject */*tbl*/ ) +static void sp_tweak_fidelity_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/tweak/fidelity", adj->value * 0.01 ); } -static void tweak_toggle_doh (GtkToggleAction *act, gpointer /*data*/) { +static void tweak_toggle_doh(GtkToggleAction *act, gpointer /*data*/) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool("/tools/tweak/doh", gtk_toggle_action_get_active(act)); } -static void tweak_toggle_dos (GtkToggleAction *act, gpointer /*data*/) { +static void tweak_toggle_dos(GtkToggleAction *act, gpointer /*data*/) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool("/tools/tweak/dos", gtk_toggle_action_get_active(act)); } -static void tweak_toggle_dol (GtkToggleAction *act, gpointer /*data*/) { +static void tweak_toggle_dol(GtkToggleAction *act, gpointer /*data*/) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool("/tools/tweak/dol", gtk_toggle_action_get_active(act)); } -static void tweak_toggle_doo (GtkToggleAction *act, gpointer /*data*/) { +static void tweak_toggle_doo(GtkToggleAction *act, gpointer /*data*/) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool("/tools/tweak/doo", gtk_toggle_action_get_active(act)); } @@ -4477,8 +4422,9 @@ static void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainAction EgeOutputAction* act = ege_output_action_new( "TweakChannelsLabel", _("Channels:"), "", 0 ); ege_output_action_set_use_markup( act, TRUE ); gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); - if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) + if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) { gtk_action_set_sensitive (GTK_ACTION(act), FALSE); + } g_object_set_data( holder, "tweak_channels_label", act); } @@ -4493,8 +4439,9 @@ static void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainAction gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_doh), desktop ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/doh", true) ); - if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) + if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) { gtk_action_set_sensitive (GTK_ACTION(act), FALSE); + } g_object_set_data( holder, "tweak_doh", act); } { @@ -4508,8 +4455,9 @@ static void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainAction gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_dos), desktop ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/dos", true) ); - if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) + if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) { gtk_action_set_sensitive (GTK_ACTION(act), FALSE); + } g_object_set_data( holder, "tweak_dos", act ); } { @@ -4523,8 +4471,9 @@ static void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainAction gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_dol), desktop ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/dol", true) ); - if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) + if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) { gtk_action_set_sensitive (GTK_ACTION(act), FALSE); + } g_object_set_data( holder, "tweak_dol", act ); } { @@ -4538,8 +4487,9 @@ static void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainAction gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(tweak_toggle_doo), desktop ); gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/tweak/doo", true) ); - if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) + if (mode != TWEAK_MODE_COLORPAINT && mode != TWEAK_MODE_COLORJITTER) { gtk_action_set_sensitive (GTK_ACTION(act), FALSE); + } g_object_set_data( holder, "tweak_doo", act ); } @@ -4556,8 +4506,9 @@ static void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainAction sp_tweak_fidelity_value_changed, 0.01, 0, 100 ); gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); - if (mode == TWEAK_MODE_COLORPAINT || mode == TWEAK_MODE_COLORJITTER) + if (mode == TWEAK_MODE_COLORPAINT || mode == TWEAK_MODE_COLORJITTER) { gtk_action_set_sensitive (GTK_ACTION(eact), FALSE); + } g_object_set_data( holder, "tweak_fidelity", eact ); } @@ -4581,19 +4532,19 @@ static void sp_tweak_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainAction //## Spray ## //######################## -static void sp_spray_width_value_changed( GtkAdjustment *adj, GObject */*tbl*/ ) +static void sp_spray_width_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/spray/width", adj->value ); } -static void sp_spray_mean_value_changed( GtkAdjustment *adj, GObject */*tbl*/ ) +static void sp_spray_mean_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/spray/mean", adj->value ); } -static void sp_spray_standard_deviation_value_changed( GtkAdjustment *adj, GObject */*tbl*/ ) +static void sp_spray_standard_deviation_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/spray/standard_deviation", adj->value ); @@ -4605,26 +4556,26 @@ static void sp_spray_pressure_state_changed( GtkToggleAction *act, gpointer /*da prefs->setBool("/tools/spray/usepressure", gtk_toggle_action_get_active(act)); } -static void sp_spray_mode_changed( EgeSelectOneAction *act, GObject */*tbl*/ ) +static void sp_spray_mode_changed( EgeSelectOneAction *act, GObject * /*tbl*/ ) { int mode = ege_select_one_action_get_active( act ); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setInt("/tools/spray/mode", mode); } -static void sp_spray_population_value_changed( GtkAdjustment *adj, GObject */*tbl*/ ) +static void sp_spray_population_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/spray/population", adj->value ); } -static void sp_spray_rotation_value_changed( GtkAdjustment *adj, GObject */*tbl*/ ) +static void sp_spray_rotation_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/spray/rotation_variation", adj->value ); } -static void sp_spray_scale_value_changed( GtkAdjustment *adj, GObject */*tbl*/ ) +static void sp_spray_scale_value_changed( GtkAdjustment *adj, GObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble( "/tools/spray/scale_variation", adj->value ); @@ -4802,11 +4753,12 @@ static void sp_spray_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainAction //######################## //## Calligraphy ## //######################## -static void update_presets_list (GObject *tbl) +static void update_presets_list(GObject *tbl) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - if (g_object_get_data(tbl, "presets_blocked")) + if (g_object_get_data(tbl, "presets_blocked")) { return; + } EgeSelectOneAction *sel = static_cast(g_object_get_data(tbl, "profile_selector")); if (!sel) { @@ -4824,7 +4776,9 @@ static void update_presets_list (GObject *tbl) std::vector preset = prefs->getAllEntries(*i); for (std::vector::iterator j = preset.begin(); j != preset.end(); ++j) { Glib::ustring entry_name = j->getEntryName(); - if (entry_name == "id" || entry_name == "name") continue; + if (entry_name == "id" || entry_name == "name") { + continue; + } void *widget = g_object_get_data(tbl, entry_name.data()); if (widget) { @@ -4980,15 +4934,18 @@ static void sp_dcc_build_presets_list(GObject *tbl) update_presets_list (tbl); } -static void sp_dcc_save_profile (GtkWidget */*widget*/, GObject *tbl) +static void sp_dcc_save_profile(GtkWidget * /*widget*/, GObject *tbl) { using Inkscape::UI::Dialog::CalligraphicProfileRename; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); SPDesktop *desktop = (SPDesktop *) g_object_get_data(tbl, "desktop" ); - if (! desktop) return; + if (! desktop) { + return; + } - if (g_object_get_data(tbl, "presets_blocked")) + if (g_object_get_data(tbl, "presets_blocked")) { return; + } CalligraphicProfileRename::show(desktop); if ( !CalligraphicProfileRename::applied()) { @@ -5056,15 +5013,17 @@ static void sp_dcc_save_profile (GtkWidget */*widget*/, GObject *tbl) } -static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject* tbl) { - +static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject* tbl) +{ Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint preset_index = ege_select_one_action_get_active( act ); // This is necessary because EgeSelectOneAction spams us with GObject "changed" signal calls // even when the preset is not changed. It would be good to replace it with something more // modern. Index 0 means "No preset", so we don't do anything. - if (preset_index == 0) return; + if (preset_index == 0) { + return; + } gint save_presets_index = GPOINTER_TO_INT(g_object_get_data(tbl, "save_presets_index")); @@ -5074,8 +5033,9 @@ static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject* tbl) { return; } - if (g_object_get_data(tbl, "presets_blocked")) + if (g_object_get_data(tbl, "presets_blocked")) { return; + } // preset_index is one-based so we subtract 1 std::vector presets = prefs->getAllDirs("/tools/calligraphic/preset"); @@ -5089,7 +5049,9 @@ static void sp_ddc_change_profile(EgeSelectOneAction* act, GObject* tbl) { // Shouldn't this be std::map? for (std::vector::iterator i = preset.begin(); i != preset.end(); ++i) { Glib::ustring entry_name = i->getEntryName(); - if (entry_name == "id" || entry_name == "name") continue; + if (entry_name == "id" || entry_name == "name") { + continue; + } void *widget = g_object_get_data(tbl, entry_name.data()); if (widget) { if (GTK_IS_ADJUSTMENT(widget)) { @@ -5368,10 +5330,11 @@ sp_arctb_startend_value_changed(GtkAdjustment *adj, GObject *tbl, gchar const *v SPGenericEllipse *ge = SP_GENERICELLIPSE(item); SPArc *arc = SP_ARC(item); - if (!strcmp(value_name, "start")) + if (!strcmp(value_name, "start")) { ge->start = (adj->value * M_PI)/ 180; - else + } else { ge->end = (adj->value * M_PI)/ 180; + } sp_genericellipse_normalize(ge); ((SPObject *)arc)->updateRepr(); @@ -5442,7 +5405,7 @@ static void sp_arctb_open_state_changed( EgeSelectOneAction *act, GObject *tbl ) items != NULL; items = items->next) { - if (SP_IS_ARC((SPItem *) items->data)) { + if (SP_IS_ARC((SPItem *) items->data)) { Inkscape::XML::Node *repr = SP_OBJECT_REPR((SPItem *) items->data); repr->setAttribute("sodipodi:open", NULL); SP_OBJECT((SPItem *) items->data)->updateRepr(); @@ -5473,8 +5436,8 @@ static void sp_arctb_defaults(GtkWidget *, GObject *obj) spinbutton_defocus( GTK_OBJECT(obj) ); } -static void arc_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const */*name*/, - gchar const */*old_value*/, gchar const */*new_value*/, +static void arc_tb_event_attr_changed(Inkscape::XML::Node *repr, gchar const * /*name*/, + gchar const * /*old_value*/, gchar const * /*new_value*/, bool /*is_interactive*/, gpointer data) { GObject *tbl = G_OBJECT(data); @@ -5675,7 +5638,8 @@ static void sp_arc_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, //## Dropper ## //######################## -static void toggle_dropper_pick_alpha( GtkToggleAction* act, gpointer tbl ) { +static void toggle_dropper_pick_alpha( GtkToggleAction* act, gpointer tbl ) +{ Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setInt( "/tools/dropper/pick", gtk_toggle_action_get_active( act ) ); GtkAction* set_action = GTK_ACTION( g_object_get_data(G_OBJECT(tbl), "set_action") ); @@ -5690,7 +5654,8 @@ static void toggle_dropper_pick_alpha( GtkToggleAction* act, gpointer tbl ) { spinbutton_defocus(GTK_OBJECT(tbl)); } -static void toggle_dropper_set_alpha( GtkToggleAction* act, gpointer tbl ) { +static void toggle_dropper_set_alpha( GtkToggleAction* act, gpointer tbl ) +{ Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool( "/tools/dropper/setalpha", gtk_toggle_action_get_active( act ) ); spinbutton_defocus(GTK_OBJECT(tbl)); @@ -5704,7 +5669,7 @@ static void toggle_dropper_set_alpha( GtkToggleAction* act, gpointer tbl ) { * TODO: Add queue of last 5 or so colors selected with new swatches so that * can drag and drop places. Will provide a nice mixing palette. */ -static void sp_dropper_toolbox_prep(SPDesktop */*desktop*/, GtkActionGroup* mainActions, GObject* holder) +static void sp_dropper_toolbox_prep(SPDesktop * /*desktop*/, GtkActionGroup* mainActions, GObject* holder) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); gint pickAlpha = prefs->getInt( "/tools/dropper/pick", 1 ); @@ -5790,22 +5755,21 @@ static void sp_lpetool_mode_changed(EgeSelectOneAction *act, GObject *tbl) } } -void sp_lpetool_toolbox_sel_modified(Inkscape::Selection *selection, guint /*flags*/, GObject */*tbl*/) +static void sp_lpetool_toolbox_sel_modified(Inkscape::Selection *selection, guint /*flags*/, GObject * /*tbl*/) { SPEventContext *ec = selection->desktop()->event_context; - if (!SP_IS_LPETOOL_CONTEXT(ec)) - return; - - lpetool_update_measuring_items(SP_LPETOOL_CONTEXT(ec)); + if (SP_IS_LPETOOL_CONTEXT(ec)) { + lpetool_update_measuring_items(SP_LPETOOL_CONTEXT(ec)); + } } -void -sp_lpetool_toolbox_sel_changed(Inkscape::Selection *selection, GObject *tbl) +static void sp_lpetool_toolbox_sel_changed(Inkscape::Selection *selection, GObject *tbl) { using namespace Inkscape::LivePathEffect; SPEventContext *ec = selection->desktop()->event_context; - if (!SP_IS_LPETOOL_CONTEXT(ec)) + if (!SP_IS_LPETOOL_CONTEXT(ec)) { return; + } SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(ec); lpetool_delete_measuring_items(lc); @@ -5835,8 +5799,7 @@ sp_lpetool_toolbox_sel_changed(Inkscape::Selection *selection, GObject *tbl) } } -static void -lpetool_toggle_show_bbox (GtkToggleAction *act, gpointer data) { +static void lpetool_toggle_show_bbox(GtkToggleAction *act, gpointer data) { SPDesktop *desktop = static_cast(data); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -5849,11 +5812,12 @@ lpetool_toggle_show_bbox (GtkToggleAction *act, gpointer data) { } } -static void -lpetool_toggle_show_measuring_info (GtkToggleAction *act, GObject *tbl) { +static void lpetool_toggle_show_measuring_info(GtkToggleAction *act, GObject *tbl) +{ SPDesktop *desktop = static_cast(g_object_get_data(tbl, "desktop")); - if (!tools_isactive(desktop, TOOLS_LPETOOL)) + if (!tools_isactive(desktop, TOOLS_LPETOOL)) { return; + } GtkAction *unitact = static_cast(g_object_get_data(tbl, "lpetool_units_action")); SPLPEToolContext *lc = SP_LPETOOL_CONTEXT(desktop->event_context); @@ -5866,7 +5830,8 @@ lpetool_toggle_show_measuring_info (GtkToggleAction *act, GObject *tbl) { } } -static void lpetool_unit_changed(GtkAction* /*act*/, GObject* tbl) { +static void lpetool_unit_changed(GtkAction* /*act*/, GObject* tbl) +{ UnitTracker* tracker = reinterpret_cast(g_object_get_data(tbl, "tracker")); SPUnit const *unit = tracker->getActiveUnit(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -5880,8 +5845,8 @@ static void lpetool_unit_changed(GtkAction* /*act*/, GObject* tbl) { } } -static void -lpetool_toggle_set_bbox (GtkToggleAction *act, gpointer data) { +static void lpetool_toggle_set_bbox(GtkToggleAction *act, gpointer data) +{ SPDesktop *desktop = static_cast(data); Inkscape::Selection *selection = desktop->selection; @@ -5907,8 +5872,7 @@ lpetool_toggle_set_bbox (GtkToggleAction *act, gpointer data) { gtk_toggle_action_set_active(act, false); } -static void -sp_line_segment_build_list(GObject *tbl) +static void sp_line_segment_build_list(GObject *tbl) { g_object_set_data(tbl, "line_segment_list_blocked", GINT_TO_POINTER(TRUE)); @@ -5932,8 +5896,8 @@ sp_line_segment_build_list(GObject *tbl) g_object_set_data(tbl, "line_segment_list_blocked", GINT_TO_POINTER(FALSE)); } -static void -sp_lpetool_change_line_segment_type(EgeSelectOneAction* act, GObject* tbl) { +static void sp_lpetool_change_line_segment_type(EgeSelectOneAction* act, GObject* tbl) +{ using namespace Inkscape::LivePathEffect; // quit if run by the attr_changed listener @@ -5955,8 +5919,8 @@ sp_lpetool_change_line_segment_type(EgeSelectOneAction* act, GObject* tbl) { g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); } -static void -lpetool_open_lpe_dialog (GtkToggleAction *act, gpointer data) { +static void lpetool_open_lpe_dialog(GtkToggleAction *act, gpointer data) +{ SPDesktop *desktop = static_cast(data); if (tools_isactive(desktop, TOOLS_LPETOOL)) { @@ -6198,40 +6162,34 @@ static void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActio //## Text Toolbox ## //######################## /* -static void -sp_text_letter_changed(GtkAdjustment *adj, GtkWidget *tbl) +static void sp_text_letter_changed(GtkAdjustment *adj, GtkWidget *tbl) { //Call back for letter sizing spinbutton } -static void -sp_text_line_changed(GtkAdjustment *adj, GtkWidget *tbl) +static void sp_text_line_changed(GtkAdjustment *adj, GtkWidget *tbl) { //Call back for line height spinbutton } -static void -sp_text_horiz_kern_changed(GtkAdjustment *adj, GtkWidget *tbl) +static void sp_text_horiz_kern_changed(GtkAdjustment *adj, GtkWidget *tbl) { //Call back for horizontal kerning spinbutton } -static void -sp_text_vert_kern_changed(GtkAdjustment *adj, GtkWidget *tbl) +static void sp_text_vert_kern_changed(GtkAdjustment *adj, GtkWidget *tbl) { //Call back for vertical kerning spinbutton } -static void -sp_text_letter_rotation_changed(GtkAdjustment *adj, GtkWidget *tbl) +static void sp_text_letter_rotation_changed(GtkAdjustment *adj, GtkWidget *tbl) { //Call back for letter rotation spinbutton }*/ namespace { -void -sp_text_toolbox_selection_changed (Inkscape::Selection */*selection*/, GObject *tbl) +static void sp_text_toolbox_selection_changed(Inkscape::Selection * /*selection*/, GObject *tbl) { // quit if run by the _changed callbacks if (g_object_get_data(G_OBJECT(tbl), "freeze")) { @@ -6324,25 +6282,19 @@ sp_text_toolbox_selection_changed (Inkscape::Selection */*selection*/, GObject * g_object_set_data (G_OBJECT (button), "block", gpointer(1)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); g_object_set_data (G_OBJECT (button), "block", gpointer(0)); - } - else - { + } else { if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) { GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "text-start")); g_object_set_data (G_OBJECT (button), "block", gpointer(1)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); g_object_set_data (G_OBJECT (button), "block", gpointer(0)); - } - else if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) - { + } else if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) { GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "text-middle")); g_object_set_data (G_OBJECT (button), "block", gpointer(1)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); g_object_set_data (G_OBJECT (button), "block", gpointer(0)); - } - else if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_END) - { + } else if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_END) { GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "text-end")); g_object_set_data (G_OBJECT (button), "block", gpointer(1)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); @@ -6387,12 +6339,9 @@ sp_text_toolbox_selection_changed (Inkscape::Selection */*selection*/, GObject * GtkWidget *button1 = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "orientation-vertical")); g_object_set_data (G_OBJECT (button1), "block", gpointer(1)); - if (query->writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB) - { + if (query->writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); - } - else - { + } else { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button1), TRUE); } g_object_set_data (G_OBJECT (button), "block", gpointer(0)); @@ -6404,21 +6353,18 @@ sp_text_toolbox_selection_changed (Inkscape::Selection */*selection*/, GObject * g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); } -void -sp_text_toolbox_selection_modified (Inkscape::Selection *selection, guint /*flags*/, GObject *tbl) +static void sp_text_toolbox_selection_modified(Inkscape::Selection *selection, guint /*flags*/, GObject *tbl) { sp_text_toolbox_selection_changed (selection, tbl); } -void -sp_text_toolbox_subselection_changed (gpointer /*tc*/, GObject *tbl) +static void sp_text_toolbox_subselection_changed(gpointer /*tc*/, GObject *tbl) { sp_text_toolbox_selection_changed (NULL, tbl); } -void -sp_text_toolbox_family_changed (GtkComboBoxEntry *, - GObject *tbl) +static void sp_text_toolbox_family_changed(GtkComboBoxEntry *, + GObject *tbl) { // quit if run by the _changed callbacks if (g_object_get_data(G_OBJECT(tbl), "freeze")) { @@ -6501,14 +6447,11 @@ sp_text_toolbox_family_changed (GtkComboBoxEntry *, } // If querying returned nothing, set the default style of the tool (for new texts) - if (result_fontspec == QUERY_STYLE_NOTHING) - { + if (result_fontspec == QUERY_STYLE_NOTHING) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->mergeStyle("/tools/text/style", css); sp_text_edit_dialog_default_set_insensitive (); //FIXME: Replace trough a verb - } - else - { + } else { sp_desktop_set_style (desktop, css, true, true); } @@ -6528,12 +6471,15 @@ sp_text_toolbox_family_changed (GtkComboBoxEntry *, } -void -sp_text_toolbox_anchoring_toggled (GtkRadioButton *button, - gpointer data) +static void sp_text_toolbox_anchoring_toggled(GtkRadioButton *button, + gpointer data) { - if (g_object_get_data (G_OBJECT (button), "block")) return; - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) return; + if (g_object_get_data (G_OBJECT (button), "block")) { + return; + } + if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) { + return; + } int prop = GPOINTER_TO_INT(data); SPDesktop *desktop = SP_ACTIVE_DESKTOP; @@ -6556,8 +6502,9 @@ sp_text_toolbox_anchoring_toggled (GtkRadioButton *button, Geom::OptRect bbox = item->getBounds(Geom::identity(), SPItem::GEOMETRIC_BBOX); - if (!bbox) + if (!bbox) { continue; + } double width = bbox->dimensions()[axis]; // If you want to align within some frame, other than the text's own bbox, calculate // the left and right (or top and bottom for tb text) slacks of the text inside that @@ -6668,11 +6615,12 @@ sp_text_toolbox_anchoring_toggled (GtkRadioButton *button, gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); } -void -sp_text_toolbox_style_toggled (GtkToggleButton *button, - gpointer data) +static void sp_text_toolbox_style_toggled(GtkToggleButton *button, + gpointer data) { - if (g_object_get_data (G_OBJECT (button), "block")) return; + if (g_object_get_data (G_OBJECT (button), "block")) { + return; + } SPDesktop *desktop = SP_ACTIVE_DESKTOP; SPCSSAttr *css = sp_repr_css_attr_new (); @@ -6772,9 +6720,8 @@ sp_text_toolbox_style_toggled (GtkToggleButton *button, gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); } -void -sp_text_toolbox_orientation_toggled (GtkRadioButton *button, - gpointer data) +static void sp_text_toolbox_orientation_toggled(GtkRadioButton *button, + gpointer data) { if (g_object_get_data (G_OBJECT (button), "block")) { return; @@ -6819,21 +6766,22 @@ sp_text_toolbox_orientation_toggled (GtkRadioButton *button, gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); } -gboolean -sp_text_toolbox_family_keypress (GtkWidget */*w*/, GdkEventKey *event, GObject *tbl) +static gboolean sp_text_toolbox_family_keypress(GtkWidget * /*w*/, GdkEventKey *event, GObject *tbl) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (!desktop) return FALSE; + if (!desktop) { + return FALSE; + } switch (get_group0_keyval (event)) { case GDK_KP_Enter: // chosen case GDK_Return: // unfreeze and update, which will defocus g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); - sp_text_toolbox_family_changed (NULL, tbl); + sp_text_toolbox_family_changed (NULL, tbl); return TRUE; // I consumed the event break; - case GDK_Escape: + case GDK_Escape: // defocus gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); return TRUE; // I consumed the event @@ -6842,11 +6790,12 @@ sp_text_toolbox_family_keypress (GtkWidget */*w*/, GdkEventKey *event, GObject * return FALSE; } -gboolean -sp_text_toolbox_family_list_keypress (GtkWidget */*w*/, GdkEventKey *event, GObject */*tbl*/) +static gboolean sp_text_toolbox_family_list_keypress(GtkWidget * /*w*/, GdkEventKey *event, GObject * /*tbl*/) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (!desktop) return FALSE; + if (!desktop) { + return FALSE; + } switch (get_group0_keyval (event)) { case GDK_KP_Enter: @@ -6867,9 +6816,8 @@ sp_text_toolbox_family_list_keypress (GtkWidget */*w*/, GdkEventKey *event, GObj } -void -sp_text_toolbox_size_changed (GtkComboBox *cbox, - GObject *tbl) +static void sp_text_toolbox_size_changed(GtkComboBox *cbox, + GObject *tbl) { // quit if run by the _changed callbacks if (g_object_get_data(G_OBJECT(tbl), "freeze")) { @@ -6935,11 +6883,12 @@ sp_text_toolbox_size_changed (GtkComboBox *cbox, g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); } -gboolean -sp_text_toolbox_size_focusout (GtkWidget */*w*/, GdkEventFocus */*event*/, GObject *tbl) +static gboolean sp_text_toolbox_size_focusout(GtkWidget * /*w*/, GdkEventFocus * /*event*/, GObject *tbl) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (!desktop) return FALSE; + if (!desktop) { + return FALSE; + } if (!g_object_get_data (tbl, "esc-pressed")) { g_object_set_data (tbl, "enter-pressed", gpointer(1)); @@ -6951,11 +6900,12 @@ sp_text_toolbox_size_focusout (GtkWidget */*w*/, GdkEventFocus */*event*/, GObje } -gboolean -sp_text_toolbox_size_keypress (GtkWidget */*w*/, GdkEventKey *event, GObject *tbl) +static gboolean sp_text_toolbox_size_keypress(GtkWidget * /*w*/, GdkEventKey *event, GObject *tbl) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (!desktop) return FALSE; + if (!desktop) { + return FALSE; + } switch (get_group0_keyval (event)) { case GDK_Escape: // defocus @@ -6979,32 +6929,29 @@ sp_text_toolbox_size_keypress (GtkWidget */*w*/, GdkEventKey *event, GObject *tb // While editing font name in the entry, disable family_changed by freezing, otherwise completion // does not work! -gboolean -sp_text_toolbox_entry_focus_in (GtkWidget *entry, - GdkEventFocus */*event*/, - GObject *tbl) +static gboolean sp_text_toolbox_entry_focus_in(GtkWidget *entry, + GdkEventFocus * /*event*/, + GObject *tbl) { g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); gtk_entry_select_region (GTK_ENTRY (entry), 0, -1); // select all return FALSE; } -gboolean -sp_text_toolbox_entry_focus_out (GtkWidget *entry, - GdkEventFocus */*event*/, - GObject *tbl) +static gboolean sp_text_toolbox_entry_focus_out(GtkWidget *entry, + GdkEventFocus * /*event*/, + GObject *tbl) { g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); gtk_entry_select_region (GTK_ENTRY (entry), 0, 0); // deselect return FALSE; } -void -cell_data_func (GtkCellLayout */*cell_layout*/, - GtkCellRenderer *cell, - GtkTreeModel *tree_model, - GtkTreeIter *iter, - gpointer /*data*/) +static void cell_data_func(GtkCellLayout * /*cell_layout*/, + GtkCellRenderer *cell, + GtkTreeModel *tree_model, + GtkTreeIter *iter, + gpointer /*data*/) { gchar *family; gtk_tree_model_get(tree_model, iter, 0, &family, -1); @@ -7031,10 +6978,10 @@ cell_data_func (GtkCellLayout */*cell_layout*/, g_free(family_escaped); } -gboolean text_toolbox_completion_match_selected(GtkEntryCompletion */*widget*/, - GtkTreeModel *model, - GtkTreeIter *iter, - GObject *tbl) +static gboolean text_toolbox_completion_match_selected(GtkEntryCompletion * /*widget*/, + GtkTreeModel *model, + GtkTreeIter *iter, + GObject *tbl) { // We intercept this signal so as to fire family_changed at once (without it, you'd have to // press Enter again after choosing a completion) @@ -7050,8 +6997,8 @@ gboolean text_toolbox_completion_match_selected(GtkEntryCompletion */*widget*/, } -static void -cbe_add_completion (GtkComboBoxEntry *cbe, GObject *tbl){ +static void cbe_add_completion(GtkComboBoxEntry *cbe, GObject *tbl) +{ GtkEntry *entry; GtkEntryCompletion *completion; GtkTreeModel *model; @@ -7071,9 +7018,9 @@ cbe_add_completion (GtkComboBoxEntry *cbe, GObject *tbl){ g_object_unref(completion); } -void sp_text_toolbox_family_popnotify(GtkComboBox *widget, - void */*property*/, - GObject *tbl) +static void sp_text_toolbox_family_popnotify(GtkComboBox *widget, + void * /*property*/, + GObject *tbl) { // while the drop-down is open, we disable font family changing, reenabling it only when it closes @@ -7109,22 +7056,23 @@ void sp_text_toolbox_family_popnotify(GtkComboBox *widget, } // update - sp_text_toolbox_family_changed (NULL, tbl); + sp_text_toolbox_family_changed (NULL, tbl); break; } - } + } } } // regardless of whether we updated, defocus the widget SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (desktop) + if (desktop) { gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); + } //g_print("POP: notify: HIDDEN\n"); } } -GtkWidget *sp_text_toolbox_new (SPDesktop *desktop) +GtkWidget *sp_text_toolbox_new(SPDesktop *desktop) { GtkToolbar *tbl = GTK_TOOLBAR(gtk_toolbar_new()); GtkIconSize secondarySize = static_cast(ToolboxFactory::prefToSize("/toolbox/secondary", 1)); @@ -7150,7 +7098,7 @@ GtkWidget *sp_text_toolbox_new (SPDesktop *desktop) g_signal_connect (G_OBJECT (font_sel->gobj()), "key-press-event", G_CALLBACK(sp_text_toolbox_family_list_keypress), tbl); cbe_add_completion(font_sel->gobj(), G_OBJECT(tbl)); - + gtk_toolbar_append_widget( tbl, (GtkWidget*) font_sel->gobj(), "", ""); g_object_set_data (G_OBJECT (tbl), "family-entry-combo", font_sel); @@ -7163,7 +7111,7 @@ GtkWidget *sp_text_toolbox_new (SPDesktop *desktop) g_signal_connect (G_OBJECT (entry), "activate", G_CALLBACK (sp_text_toolbox_family_changed), tbl); g_signal_connect (G_OBJECT (font_sel->gobj()), "changed", G_CALLBACK (sp_text_toolbox_family_changed), tbl); - g_signal_connect (G_OBJECT (font_sel->gobj()), "notify::popup-shown", + g_signal_connect (G_OBJECT (font_sel->gobj()), "notify::popup-shown", G_CALLBACK (sp_text_toolbox_family_popnotify), tbl); g_signal_connect (G_OBJECT (entry), "key-press-event", G_CALLBACK(sp_text_toolbox_family_keypress), tbl); g_signal_connect (G_OBJECT (entry), "focus-in-event", G_CALLBACK (sp_text_toolbox_entry_focus_in), tbl); @@ -7352,7 +7300,7 @@ GtkWidget *sp_text_toolbox_new (SPDesktop *desktop) //## Connector ## //######################### -static void sp_connector_mode_toggled( GtkToggleAction* act, GtkObject */*tbl*/ ) +static void sp_connector_mode_toggled( GtkToggleAction* act, GtkObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool("/tools/connector/mode", @@ -7376,8 +7324,7 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl Inkscape::Selection * selection = sp_desktop_selection(desktop); SPDocument *doc = sp_desktop_document(desktop); - if (!sp_document_get_undo_sensitive(doc)) - { + if (!sp_document_get_undo_sensitive(doc)) { return; } @@ -7409,8 +7356,7 @@ static void sp_connector_orthogonal_toggled( GtkToggleAction* act, GObject *tbl l = l->next; } - if (!modmade) - { + if (!modmade) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool("/tools/connector/orthogonal", is_orthog); } @@ -7427,8 +7373,7 @@ static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) Inkscape::Selection * selection = sp_desktop_selection(desktop); SPDocument *doc = sp_desktop_document(desktop); - if (!sp_document_get_undo_sensitive(doc)) - { + if (!sp_document_get_undo_sensitive(doc)) { return; } @@ -7459,8 +7404,7 @@ static void connector_curvature_changed(GtkAdjustment *adj, GObject* tbl) l = l->next; } - if (!modmade) - { + if (!modmade) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setDouble(Glib::ustring("/tools/connector/curvature"), newValue); } @@ -7477,8 +7421,7 @@ static void connector_spacing_changed(GtkAdjustment *adj, GObject* tbl) SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" ); SPDocument *doc = sp_desktop_document(desktop); - if (!sp_document_get_undo_sensitive(doc)) - { + if (!sp_document_get_undo_sensitive(doc)) { return; } @@ -7486,7 +7429,7 @@ static void connector_spacing_changed(GtkAdjustment *adj, GObject* tbl) if ( !repr->attribute("inkscape:connector-spacing") && ( adj->value == defaultConnSpacing )) { - // Don't need to update the repr if the attribute doesn't + // Don't need to update the repr if the attribute doesn't // exist and it is being set to the default value -- as will // happen at startup. return; @@ -7522,7 +7465,9 @@ static void connector_spacing_changed(GtkAdjustment *adj, GObject* tbl) static void sp_connector_graph_layout(void) { - if (!SP_ACTIVE_DESKTOP) return; + if (!SP_ACTIVE_DESKTOP) { + return; + } Inkscape::Preferences *prefs = Inkscape::Preferences::get(); // hack for clones, see comment in align-and-distribute.cpp @@ -7536,14 +7481,14 @@ static void sp_connector_graph_layout(void) sp_document_done(sp_desktop_document(SP_ACTIVE_DESKTOP), SP_VERB_DIALOG_ALIGN_DISTRIBUTE, _("Arrange connector network")); } -static void sp_directed_graph_layout_toggled( GtkToggleAction* act, GtkObject */*tbl*/ ) +static void sp_directed_graph_layout_toggled( GtkToggleAction* act, GtkObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool("/tools/connector/directedlayout", gtk_toggle_action_get_active( act )); } -static void sp_nooverlaps_graph_layout_toggled( GtkToggleAction* act, GtkObject */*tbl*/ ) +static void sp_nooverlaps_graph_layout_toggled( GtkToggleAction* act, GtkObject * /*tbl*/ ) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool("/tools/connector/avoidoverlaplayout", @@ -7558,7 +7503,7 @@ static void connector_length_changed(GtkAdjustment *adj, GObject* /*tbl*/) } static void connector_tb_event_attr_changed(Inkscape::XML::Node *repr, - gchar const *name, gchar const */*old_value*/, gchar const */*new_value*/, + gchar const *name, gchar const * /*old_value*/, gchar const * /*new_value*/, bool /*is_interactive*/, gpointer data) { GtkWidget *tbl = GTK_WIDGET(data); @@ -7585,8 +7530,9 @@ static void sp_connector_new_connection_point(GtkWidget *, GObject *tbl) SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" ); SPConnectorContext* cc = SP_CONNECTOR_CONTEXT(desktop->event_context); - if (cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE) + if (cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE) { cc_create_connection_point(cc); + } } static void sp_connector_remove_connection_point(GtkWidget *, GObject *tbl) @@ -7594,8 +7540,9 @@ static void sp_connector_remove_connection_point(GtkWidget *, GObject *tbl) SPDesktop *desktop = (SPDesktop *) g_object_get_data( tbl, "desktop" ); SPConnectorContext* cc = SP_CONNECTOR_CONTEXT(desktop->event_context); - if (cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE) + if (cc->mode == SP_CONNECTOR_CONTEXT_EDITING_MODE) { cc_remove_connection_point(cc); + } } static Inkscape::XML::NodeEventVector connector_tb_repr_events = { @@ -7805,13 +7752,13 @@ static void paintbucket_channels_changed(EgeSelectOneAction* act, GObject* /*tbl flood_channels_set_channels( channels ); } -static void paintbucket_threshold_changed(GtkAdjustment *adj, GObject */*tbl*/) +static void paintbucket_threshold_changed(GtkAdjustment *adj, GObject * /*tbl*/) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setInt("/tools/paintbucket/threshold", (gint)adj->value); } -static void paintbucket_autogap_changed(EgeSelectOneAction* act, GObject */*tbl*/) +static void paintbucket_autogap_changed(EgeSelectOneAction* act, GObject * /*tbl*/) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->setBool("/tools/paintbucket/autogap", ege_select_one_action_get_active( act )); @@ -7827,7 +7774,7 @@ static void paintbucket_offset_changed(GtkAdjustment *adj, GObject *tbl) prefs->setString("/tools/paintbucket/offsetunits", sp_unit_get_abbreviation(unit)); } -static void paintbucket_defaults (GtkWidget *, GObject *tbl) +static void paintbucket_defaults(GtkWidget *, GObject *tbl) { // FIXME: make defaults settable via Inkscape Options struct KeyValue { @@ -7898,8 +7845,9 @@ static void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* main // Create the units menu. UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); Glib::ustring stored_unit = prefs->getString("/tools/paintbucket/offsetunits"); - if (!stored_unit.empty()) + if (!stored_unit.empty()) { tracker->setActiveUnit(sp_unit_get_by_abbreviation(stored_unit.data())); + } g_object_set_data( holder, "tracker", tracker ); { GtkAction* act = tracker->createAction( "PaintbucketUnitsAction", _("Units"), ("") ); -- cgit v1.2.3 From 1b36b306bc0068e94b300966a50060c07c4f428f Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Mon, 12 Apr 2010 02:10:41 -0700 Subject: Leave uninitialized bools in preferences to the default 'false' value. Code should initialize those explicitly and not count on GUI widgets to do so. (bzr r9318) --- src/widgets/toolbox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/widgets') diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index bf1231092..0b690504f 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -741,7 +741,7 @@ PrefPusher::PrefPusher( GtkToggleAction *act, Glib::ustring const &path, void (* { g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(toggleCB), this); freeze = true; - gtk_toggle_action_set_active( act, Inkscape::Preferences::get()->getBool(observed_path, true) ); + gtk_toggle_action_set_active( act, Inkscape::Preferences::get()->getBool(observed_path) ); freeze = false; Inkscape::Preferences::get()->addObserver(*this); -- cgit v1.2.3 From b8170886d4e5916e800965a1924072fd219df696 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 16 Apr 2010 14:19:33 +0200 Subject: Second step in fixing changing of font faces. (bzr r9340) --- src/widgets/toolbox.cpp | 99 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 25 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 0b690504f..96695ac20 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -6189,6 +6189,12 @@ static void sp_text_letter_rotation_changed(GtkAdjustment *adj, GtkWidget *tbl) namespace { +/* + * This function sets up the text-tool tool-controls, setting the entry boxes + * etc. to the values from the current selection or the default if no selection. + * It is called whenever a text selection is changed, including stepping cursor + * through text. + */ static void sp_text_toolbox_selection_changed(Inkscape::Selection * /*selection*/, GObject *tbl) { // quit if run by the _changed callbacks @@ -6198,28 +6204,36 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection * /*selection* g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); + gtk_widget_hide (GTK_WIDGET (g_object_get_data (G_OBJECT(tbl), "warning-image"))); + + /* + * Query from current selection: + * Font family (font-family) + * Style (font-weight, font-style, font-stretch, font-variant, font-align) + * Numbers (font-size, letter-spacing, word-spacing, line-height, text-anchor, writing-mode) + * Font specification (Inkscape private attribute) + */ SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); - int result_family = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); - - int result_style = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE); + int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); + int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE); + int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + // Used later: + int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); - int result_numbers = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); - - gtk_widget_hide (GTK_WIDGET (g_object_get_data (G_OBJECT(tbl), "warning-image"))); - - // If querying returned nothing, read the style from the text tool prefs (default style for new texts) + /* + * If no text in selection (querying returned nothing), read the style from + * the /tools/text preferencess (default style for new texts). Return if + * tool bar already set to these preferences. + */ if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING || result_numbers == QUERY_STYLE_NOTHING) { - // there are no texts in selection, read from prefs + // There are no texts in selection, read from preferences. sp_style_read_from_prefs(query, "/tools/text"); if (g_object_get_data(tbl, "text_style_from_prefs")) { - // do not reset the toolbar style from prefs if we already did it last time + // Do not reset the toolbar style from prefs if we already did it last time. sp_style_unref(query); g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); return; @@ -6229,20 +6243,28 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection * /*selection* g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(FALSE)); } + /* + * If we have valid query data for text (font-family, font-specification) set toolbar accordingly. + */ if (query->text) { if (result_family == QUERY_STYLE_MULTIPLE_DIFFERENT) { + + // Don't set a font family if multiple styles are selected. GtkWidget *entry = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "family-entry")); gtk_entry_set_text (GTK_ENTRY (entry), ""); } else if (query->text->font_specification.value || query->text->font_family.value) { + // At the moment (April 2010), font-specification isn't set unless actually + // set on current tspan (parent look up is disabled). Gtk::ComboBoxEntry *combo = (Gtk::ComboBoxEntry *) (g_object_get_data (G_OBJECT (tbl), "family-entry-combo")); GtkEntry *entry = GTK_ENTRY (g_object_get_data (G_OBJECT (tbl), "family-entry")); // Get the font that corresponds Glib::ustring familyName; + // This tries to use font-specification first and then font-family. font_instance * font = font_factory::Default()->FaceFromStyle(query); if (font) { familyName = font_factory::Default()->GetUIFamilyString(font->descr); @@ -6267,7 +6289,7 @@ static void sp_text_toolbox_selection_changed(Inkscape::Selection * /*selection* combo->set_active (iter); } - //Size + //Size (average of text selected) { GtkWidget *cbox = GTK_WIDGET(g_object_get_data(G_OBJECT(tbl), "combo-box-size")); gchar *const str = g_strdup_printf("%.5g", query->font_size.computed); @@ -6391,6 +6413,12 @@ static void sp_text_toolbox_family_changed(GtkComboBoxEntry *, Glib::ustring fontSpec = query->text->font_specification.set ? query->text->font_specification.value : ""; if (fontSpec.empty()) { + + // Must query all to fill font-family, font-style, font-weight, font-specification + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE); + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + // Construct a new font specification if it does not yet exist font_instance * fontFromStyle = font_factory::Default()->FaceFromStyle(query); fontSpec = font_factory::Default()->ConstructFontSpecification(fontFromStyle); @@ -6399,6 +6427,7 @@ static void sp_text_toolbox_family_changed(GtkComboBoxEntry *, if (!fontSpec.empty()) { + // Now we have existing font specification, replace family. Glib::ustring newFontSpec = font_factory::Default()->ReplaceFontSpecificationFamily(fontSpec, family); if (!newFontSpec.empty()) { @@ -6630,17 +6659,20 @@ static void sp_text_toolbox_style_toggled(GtkToggleButton *button, SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); - int result_fontspec = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); - - //int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); - //int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE); - //int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); + // font_specification will not be set unless defined explicitely on a tspan. + // This needs to be fixed. Glib::ustring fontSpec = query->text->font_specification.set ? query->text->font_specification.value : ""; Glib::ustring newFontSpec = ""; if (fontSpec.empty()) { + + // Must query all to fill font-family, font-style, font-weight, font-specification + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE); + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + // Construct a new font specification if it does not yet exist font_instance * fontFromStyle = font_factory::Default()->FaceFromStyle(query); fontSpec = font_factory::Default()->ConstructFontSpecification(fontFromStyle); @@ -6652,12 +6684,20 @@ static void sp_text_toolbox_style_toggled(GtkToggleButton *button, { case 0: { + // Bold if (!fontSpec.empty()) { newFontSpec = font_factory::Default()->FontSpecificationSetBold(fontSpec, active); if (!newFontSpec.empty()) { - // Don't even set the bold if the font didn't exist on the system - sp_repr_css_set_property (css, "font-weight", active ? "bold" : "normal" ); - nochange = false; + + font_instance * font = font_factory::Default()->FaceFromFontSpecification(newFontSpec.c_str()); + if (font) { + gchar c[256]; + font->Attribute( "weight", c, 256); + sp_repr_css_set_property (css, "font-weight", c); + font->Unref(); + font = NULL; + nochange = false; + } } } // set or reset the button according @@ -6677,11 +6717,20 @@ static void sp_text_toolbox_style_toggled(GtkToggleButton *button, case 1: { + // Italic/Oblique if (!fontSpec.empty()) { newFontSpec = font_factory::Default()->FontSpecificationSetItalic(fontSpec, active); if (!newFontSpec.empty()) { - // Don't even set the italic if the font didn't exist on the system - sp_repr_css_set_property (css, "font-style", active ? "italic" : "normal"); + // Don't even set the italic/oblique if the font didn't exist on the system + if( active ) { + if( newFontSpec.find( "Italic" ) != Glib::ustring::npos ) { + sp_repr_css_set_property (css, "font-style", "italic"); + } else { + sp_repr_css_set_property (css, "font-style", "oblique"); + } + } else { + sp_repr_css_set_property (css, "font-style", "normal"); + } nochange = false; } } -- cgit v1.2.3 From cc9182818c5ea40751c2db85af3b0346bdae7611 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 23 Apr 2010 12:59:44 +0200 Subject: Converted text toolbar to GTK toolbar. Moved Bold and Italics buttons to group font items together. Added items for line-height, word-spacing, and letter-spacing. Added ink-comboboxentry-action to wrap a GtkComboBoxEntry widget: Options: Pop-up completion menu. Use of external cell_data_func for formatting (e.g. font preview). Adjustable GtkEntry width. Display warning icon/tooltip if entry isn't in list. (bzr r9365) --- src/widgets/toolbox.cpp | 1860 +++++++++++++++++++++++++---------------------- 1 file changed, 983 insertions(+), 877 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 96695ac20..66f77a18d 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -12,10 +12,11 @@ * Josh Andler * Jon A. Cruz * Maximilian Albert + * Tavmjong Bah * * Copyright (C) 2004 David Turner * Copyright (C) 2003 MenTaLguY - * Copyright (C) 1999-2008 authors + * Copyright (C) 1999-2010 authors * Copyright (C) 2001-2002 Ximian, Inc. * * Released under GNU GPL, read the file 'COPYING' for more information @@ -56,6 +57,7 @@ #include "../helper/unit-tracker.h" #include "icon.h" #include "../ink-action.h" +#include "../ink-comboboxentry-action.h" #include "../inkscape.h" #include "../interface.h" #include "../libnrtype/font-instance.h" @@ -105,6 +107,7 @@ #include "toolbox.h" #define ENABLE_TASK_SUPPORT 1 +//#define DEBUG_TEXT using Inkscape::UnitTracker; using Inkscape::UI::UXManager; @@ -139,11 +142,9 @@ static GtkWidget *sp_empty_toolbox_new(SPDesktop *desktop); static void sp_connector_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder); static void sp_paintbucket_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder); static void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder); +static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder); static void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder); -namespace { GtkWidget *sp_text_toolbox_new (SPDesktop *desktop); } - - #if ENABLE_TASK_SUPPORT static void fireTaskChange( EgeSelectOneAction *act, SPDesktop *dt ) { @@ -235,7 +236,7 @@ static struct { SP_VERB_CONTEXT_ERASER_PREFS, "/tools/eraser", _("TBD")}, { "SPLPEToolContext", "lpetool_toolbox", 0, sp_lpetool_toolbox_prep, "LPEToolToolbar", SP_VERB_CONTEXT_LPETOOL_PREFS, "/tools/lpetool", _("TBD")}, - { "SPTextContext", "text_toolbox", sp_text_toolbox_new, 0, 0, + { "SPTextContext", "text_toolbox", 0, sp_text_toolbox_prep, "TextToolbar", SP_VERB_INVALID, 0, 0}, { "SPDropperContext", "dropper_toolbox", 0, sp_dropper_toolbox_prep, "DropperToolbar", SP_VERB_INVALID, 0, 0}, @@ -478,6 +479,21 @@ static gchar const * ui_descr = " " " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " " " " " @@ -6161,257 +6177,109 @@ static void sp_eraser_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActio //######################## //## Text Toolbox ## //######################## -/* -static void sp_text_letter_changed(GtkAdjustment *adj, GtkWidget *tbl) -{ - //Call back for letter sizing spinbutton -} -static void sp_text_line_changed(GtkAdjustment *adj, GtkWidget *tbl) -{ - //Call back for line height spinbutton -} +// Functions for debugging: +#ifdef DEBUG_TEXT -static void sp_text_horiz_kern_changed(GtkAdjustment *adj, GtkWidget *tbl) -{ - //Call back for horizontal kerning spinbutton -} +static void sp_print_font( SPStyle *query ) { -static void sp_text_vert_kern_changed(GtkAdjustment *adj, GtkWidget *tbl) -{ - //Call back for vertical kerning spinbutton -} + bool family_set = query->text->font_family.set; + bool style_set = query->font_style.set; + bool fontspec_set = query->text->font_specification.set; -static void sp_text_letter_rotation_changed(GtkAdjustment *adj, GtkWidget *tbl) -{ - //Call back for letter rotation spinbutton -}*/ + std::cout << " Family set? " << family_set + << " Style set? " << style_set + << " FontSpec set? " << fontspec_set + << std::endl; + std::cout << " Family: " + << (query->text->font_family.value ? query->text->font_family.value : "No value") + << " Style: " << query->font_style.computed + << " Weight: " << query->font_weight.computed + << " FontSpec: " + << (query->text->font_specification.value ? query->text->font_specification.value : "No value") + << std::endl; +} + +static void sp_print_fontweight( SPStyle *query ) { + const gchar* names[] = {"100", "200", "300", "400", "500", "600", "700", "800", "900", + "NORMAL", "BOLD", "LIGHTER", "BOLDER", "Out of range"}; + // Missing book = 380 + int index = query->font_weight.computed; + if( index < 0 || index > 13 ) index = 13; + std::cout << " Weight: " << names[ index ] + << " (" << query->font_weight.computed << ")" << std::endl; -namespace { +} -/* - * This function sets up the text-tool tool-controls, setting the entry boxes - * etc. to the values from the current selection or the default if no selection. - * It is called whenever a text selection is changed, including stepping cursor - * through text. - */ -static void sp_text_toolbox_selection_changed(Inkscape::Selection * /*selection*/, GObject *tbl) -{ - // quit if run by the _changed callbacks - if (g_object_get_data(G_OBJECT(tbl), "freeze")) { - return; - } +static void sp_print_fontstyle( SPStyle *query ) { - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); + const gchar* names[] = {"NORMAL", "ITALIC", "OBLIQUE", "Out of range"}; + int index = query->font_style.computed; + if( index < 0 || index > 3 ) index = 3; + std::cout << " Style: " << names[ index ] << std::endl; - gtk_widget_hide (GTK_WIDGET (g_object_get_data (G_OBJECT(tbl), "warning-image"))); +} +#endif - /* - * Query from current selection: - * Font family (font-family) - * Style (font-weight, font-style, font-stretch, font-variant, font-align) - * Numbers (font-size, letter-spacing, word-spacing, line-height, text-anchor, writing-mode) - * Font specification (Inkscape private attribute) - */ - SPStyle *query = - sp_style_new (SP_ACTIVE_DOCUMENT); +// Format family drop-down menu. +static void cell_data_func(GtkCellLayout * /*cell_layout*/, + GtkCellRenderer *cell, + GtkTreeModel *tree_model, + GtkTreeIter *iter, + gpointer /*data*/) +{ + gchar *family; + gtk_tree_model_get(tree_model, iter, 0, &family, -1); + gchar *const family_escaped = g_markup_escape_text(family, -1); - int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); - int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE); - int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); - // Used later: - int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + int show_sample = prefs->getInt("/tools/text/show_sample_in_list", 1); + if (show_sample) { - /* - * If no text in selection (querying returned nothing), read the style from - * the /tools/text preferencess (default style for new texts). Return if - * tool bar already set to these preferences. - */ - if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING || result_numbers == QUERY_STYLE_NOTHING) { - // There are no texts in selection, read from preferences. + Glib::ustring sample = prefs->getString("/tools/text/font_sample"); + gchar *const sample_escaped = g_markup_escape_text(sample.data(), -1); - sp_style_read_from_prefs(query, "/tools/text"); + std::stringstream markup; + markup << family_escaped << " " << sample_escaped << ""; + g_object_set (G_OBJECT (cell), "markup", markup.str().c_str(), NULL); - if (g_object_get_data(tbl, "text_style_from_prefs")) { - // Do not reset the toolbar style from prefs if we already did it last time. - sp_style_unref(query); - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); - return; - } - g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(TRUE)); + g_free(sample_escaped); } else { - g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(FALSE)); - } - - /* - * If we have valid query data for text (font-family, font-specification) set toolbar accordingly. - */ - if (query->text) - { - if (result_family == QUERY_STYLE_MULTIPLE_DIFFERENT) { - - // Don't set a font family if multiple styles are selected. - GtkWidget *entry = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "family-entry")); - gtk_entry_set_text (GTK_ENTRY (entry), ""); - - } else if (query->text->font_specification.value || query->text->font_family.value) { - - // At the moment (April 2010), font-specification isn't set unless actually - // set on current tspan (parent look up is disabled). - Gtk::ComboBoxEntry *combo = (Gtk::ComboBoxEntry *) (g_object_get_data (G_OBJECT (tbl), "family-entry-combo")); - GtkEntry *entry = GTK_ENTRY (g_object_get_data (G_OBJECT (tbl), "family-entry")); - - // Get the font that corresponds - Glib::ustring familyName; - - // This tries to use font-specification first and then font-family. - font_instance * font = font_factory::Default()->FaceFromStyle(query); - if (font) { - familyName = font_factory::Default()->GetUIFamilyString(font->descr); - font->Unref(); - font = NULL; - } - - gtk_entry_set_text (GTK_ENTRY (entry), familyName.c_str()); - - Gtk::TreeIter iter; - try { - Gtk::TreePath path = Inkscape::FontLister::get_instance()->get_row_for_font (familyName); - Glib::RefPtr model = combo->get_model(); - iter = model->get_iter(path); - } catch (...) { - g_warning("Family name %s does not have an entry in the font lister.", familyName.c_str()); - sp_style_unref(query); - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); - return; - } - - combo->set_active (iter); - } - - //Size (average of text selected) - { - GtkWidget *cbox = GTK_WIDGET(g_object_get_data(G_OBJECT(tbl), "combo-box-size")); - gchar *const str = g_strdup_printf("%.5g", query->font_size.computed); - gtk_entry_set_text(GTK_ENTRY(GTK_BIN(cbox)->child), str); - g_free(str); - } - - //Anchor - if (query->text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) - { - GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "text-fill")); - g_object_set_data (G_OBJECT (button), "block", gpointer(1)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); - g_object_set_data (G_OBJECT (button), "block", gpointer(0)); - } else { - if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) - { - GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "text-start")); - g_object_set_data (G_OBJECT (button), "block", gpointer(1)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); - g_object_set_data (G_OBJECT (button), "block", gpointer(0)); - } else if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) { - GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "text-middle")); - g_object_set_data (G_OBJECT (button), "block", gpointer(1)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); - g_object_set_data (G_OBJECT (button), "block", gpointer(0)); - } else if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_END) { - GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "text-end")); - g_object_set_data (G_OBJECT (button), "block", gpointer(1)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); - g_object_set_data (G_OBJECT (button), "block", gpointer(0)); - } - } - - //Style - { - GtkToggleButton *button = GTK_TOGGLE_BUTTON (g_object_get_data (G_OBJECT (tbl), "style-bold")); - - gboolean active = gtk_toggle_button_get_active (button); - gboolean check = ((query->font_weight.computed >= SP_CSS_FONT_WEIGHT_700) && (query->font_weight.computed != SP_CSS_FONT_WEIGHT_NORMAL) && (query->font_weight.computed != SP_CSS_FONT_WEIGHT_LIGHTER)); - - if (active != check) - { - g_object_set_data (G_OBJECT (button), "block", gpointer(1)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), check); - g_object_set_data (G_OBJECT (button), "block", gpointer(0)); - } - } - - { - GtkToggleButton *button = GTK_TOGGLE_BUTTON (g_object_get_data (G_OBJECT (tbl), "style-italic")); - - gboolean active = gtk_toggle_button_get_active (button); - gboolean check = (query->font_style.computed != SP_CSS_FONT_STYLE_NORMAL); - - if (active != check) - { - g_object_set_data (G_OBJECT (button), "block", gpointer(1)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), check); - g_object_set_data (G_OBJECT (button), "block", gpointer(0)); - } - } - - //Orientation - //locking both buttons, changing one affect all group (both) - GtkWidget *button = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "orientation-horizontal")); - g_object_set_data (G_OBJECT (button), "block", gpointer(1)); - - GtkWidget *button1 = GTK_WIDGET (g_object_get_data (G_OBJECT (tbl), "orientation-vertical")); - g_object_set_data (G_OBJECT (button1), "block", gpointer(1)); - - if (query->writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); - } else { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button1), TRUE); - } - g_object_set_data (G_OBJECT (button), "block", gpointer(0)); - g_object_set_data (G_OBJECT (button1), "block", gpointer(0)); + g_object_set (G_OBJECT (cell), "markup", family_escaped, NULL); } - sp_style_unref(query); - - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); -} - -static void sp_text_toolbox_selection_modified(Inkscape::Selection *selection, guint /*flags*/, GObject *tbl) -{ - sp_text_toolbox_selection_changed (selection, tbl); + g_free(family); + g_free(family_escaped); } -static void sp_text_toolbox_subselection_changed(gpointer /*tc*/, GObject *tbl) +// Font family +static void sp_text_fontfamily_value_changed( Ink_ComboBoxEntry_Action *act, GObject *tbl ) { - sp_text_toolbox_selection_changed (NULL, tbl); -} +#ifdef DEBUG_TEXT + std::cout << std::endl; + std::cout << "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM" << std::endl; + std::cout << "sp_text_fontfamily_value_changed: " << std::endl; +#endif -static void sp_text_toolbox_family_changed(GtkComboBoxEntry *, - GObject *tbl) -{ - // quit if run by the _changed callbacks + // quit if run by the _changed callbacks if (g_object_get_data(G_OBJECT(tbl), "freeze")) { return; } - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - GtkWidget *entry = GTK_WIDGET (g_object_get_data (tbl, "family-entry")); - const gchar* family = gtk_entry_get_text (GTK_ENTRY (entry)); - - //g_print ("family changed to: %s\n", family); - - SPStyle *query = - sp_style_new (SP_ACTIVE_DOCUMENT); - - int result_fontspec = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); + gchar *family = ink_comboboxentry_action_get_active_text( act ); +#ifdef DEBUG_TEXT + std::cout << " New family: " << family << std::endl; +#endif - SPCSSAttr *css = sp_repr_css_attr_new (); + // First try to get the old font spec from the stored value + SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); + int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); - // First try to get the font spec from the stored value Glib::ustring fontSpec = query->text->font_specification.set ? query->text->font_specification.value : ""; + // If that didn't work, try to get font spec from style if (fontSpec.empty()) { // Must query all to fill font-family, font-style, font-weight, font-specification @@ -6421,14 +6289,44 @@ static void sp_text_toolbox_family_changed(GtkComboBoxEntry *, // Construct a new font specification if it does not yet exist font_instance * fontFromStyle = font_factory::Default()->FaceFromStyle(query); - fontSpec = font_factory::Default()->ConstructFontSpecification(fontFromStyle); - fontFromStyle->Unref(); + if( fontFromStyle ) { + fontSpec = font_factory::Default()->ConstructFontSpecification(fontFromStyle); + fontFromStyle->Unref(); + } +#ifdef DEBUG_TEXT + std::cout << " Fontspec not defined, reconstructed from style :" << fontSpec << ":" << std::endl; + sp_print_font( query ); +#endif + } + + // And if that didn't work use default + if( fontSpec.empty() ) { + sp_style_read_from_prefs(query, "/tools/text"); +#ifdef DEBUG_TEXT + std::cout << " read style from prefs:" << std::endl; + sp_print_font( query ); +#endif + // Construct a new font specification if it does not yet exist + font_instance * fontFromStyle = font_factory::Default()->FaceFromStyle(query); + if( fontFromStyle ) { + fontSpec = font_factory::Default()->ConstructFontSpecification(fontFromStyle); + fontFromStyle->Unref(); + } +#ifdef DEBUG_TEXT + std::cout << " Fontspec not defined, reconstructed from style :" << fontSpec << ":" << std::endl; + sp_print_font( query ); +#endif } + SPCSSAttr *css = sp_repr_css_attr_new (); if (!fontSpec.empty()) { - // Now we have existing font specification, replace family. - Glib::ustring newFontSpec = font_factory::Default()->ReplaceFontSpecificationFamily(fontSpec, family); + // Now we have a font specification, replace family. + Glib::ustring newFontSpec = font_factory::Default()->ReplaceFontSpecificationFamily(fontSpec, family); + +#ifdef DEBUG_TEXT + std::cout << " New FontSpec from ReplaceFontSpecificationFamily :" << newFontSpec << ":" << std::endl; +#endif if (!newFontSpec.empty()) { @@ -6465,230 +6363,157 @@ static void sp_text_toolbox_family_changed(GtkComboBoxEntry *, } } else { - // If the old font on selection (or default) was not existing on the system, + + // newFontSpec empty + // If the old font on selection (or default) does not exist on the system, + // or the new font family does not exist, // ReplaceFontSpecificationFamily does not work. In that case we fall back to blindly // setting the family reported by the family chooser. - //g_print ("fallback setting family: %s\n", family); + // g_print ("fallback setting family: %s\n", family); sp_repr_css_set_property (css, "-inkscape-font-specification", family); sp_repr_css_set_property (css, "font-family", family); + // Shoud we set other css font attributes? } - } - // If querying returned nothing, set the default style of the tool (for new texts) - if (result_fontspec == QUERY_STYLE_NOTHING) { + } // fontSpec not empty or not + + // If querying returned nothing, update default style. + if (result_fontspec == QUERY_STYLE_NOTHING) + { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->mergeStyle("/tools/text/style", css); - sp_text_edit_dialog_default_set_insensitive (); //FIXME: Replace trough a verb - } else { - sp_desktop_set_style (desktop, css, true, true); + sp_text_edit_dialog_default_set_insensitive (); //FIXME: Replace through a verb + } + else + { + sp_desktop_set_style (SP_ACTIVE_DESKTOP, css, true, true); } sp_style_unref(query); + g_free (family); + + // Save for undo sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT, _("Text: Change font family")); sp_repr_css_attr_unref (css); - gtk_widget_hide (GTK_WIDGET (g_object_get_data (G_OBJECT(tbl), "warning-image"))); - // unfreeze g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); // focus to canvas - gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); -} + gtk_widget_grab_focus (GTK_WIDGET((SP_ACTIVE_DESKTOP)->canvas)); +#ifdef DEBUG_TEXT + std::cout << "sp_text_toolbox_fontfamily_changes: exit" << std::endl; + std::cout << "MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM" << std::endl; + std::cout << std::endl; +#endif +} -static void sp_text_toolbox_anchoring_toggled(GtkRadioButton *button, - gpointer data) +// Font size +static void sp_text_fontsize_value_changed( Ink_ComboBoxEntry_Action *act, GObject *tbl ) { - if (g_object_get_data (G_OBJECT (button), "block")) { + // quit if run by the _changed callbacks + if (g_object_get_data(G_OBJECT(tbl), "freeze")) { return; } - if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) { + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); + + gchar *text = ink_comboboxentry_action_get_active_text( act ); + gchar *endptr; + gdouble size = g_strtod( text, &endptr ); + if (endptr == text) { // Conversion failed, non-numeric input. + g_warning( "Conversion of size text to double failed, input: %s\n", text ); + g_free( text ); return; } - int prop = GPOINTER_TO_INT(data); + g_free( text ); + + // Set css font size. + SPCSSAttr *css = sp_repr_css_attr_new (); + Inkscape::CSSOStringStream osfs; + osfs << size << "px"; // For now always use px + sp_repr_css_set_property (css, "font-size", osfs.str().c_str()); + // Apply font size to selected objects. SPDesktop *desktop = SP_ACTIVE_DESKTOP; + sp_desktop_set_style (desktop, css, true, true); - // move the x of all texts to preserve the same bbox - Inkscape::Selection *selection = sp_desktop_selection(desktop); - for (GSList const *items = selection->itemList(); items != NULL; items = items->next) { - if (SP_IS_TEXT((SPItem *) items->data)) { - SPItem *item = SP_ITEM(items->data); + // Save for undo + sp_document_maybe_done (sp_desktop_document (SP_ACTIVE_DESKTOP), "ttb:size", SP_VERB_NONE, + _("Text: Change font size")); - unsigned writing_mode = SP_OBJECT_STYLE(item)->writing_mode.value; - // below, variable names suggest horizontal move, but we check the writing direction - // and move in the corresponding axis - int axis; - if (writing_mode == SP_CSS_WRITING_MODE_LR_TB || writing_mode == SP_CSS_WRITING_MODE_RL_TB) { - axis = NR::X; - } else { - axis = NR::Y; - } + // If no selected objects, set default. + SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); + int result_numbers = + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + if (result_numbers == QUERY_STYLE_NOTHING) + { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->mergeStyle("/tools/text/style", css); + } + sp_style_unref(query); - Geom::OptRect bbox - = item->getBounds(Geom::identity(), SPItem::GEOMETRIC_BBOX); - if (!bbox) { - continue; - } - double width = bbox->dimensions()[axis]; - // If you want to align within some frame, other than the text's own bbox, calculate - // the left and right (or top and bottom for tb text) slacks of the text inside that - // frame (currently unused) - double left_slack = 0; - double right_slack = 0; - unsigned old_align = SP_OBJECT_STYLE(item)->text_align.value; - double move = 0; - if (old_align == SP_CSS_TEXT_ALIGN_START || old_align == SP_CSS_TEXT_ALIGN_LEFT) { - switch (prop) { - case 0: - move = -left_slack; - break; - case 1: - move = width/2 + (right_slack - left_slack)/2; - break; - case 2: - move = width + right_slack; - break; - } - } else if (old_align == SP_CSS_TEXT_ALIGN_CENTER) { - switch (prop) { - case 0: - move = -width/2 - left_slack; - break; - case 1: - move = (right_slack - left_slack)/2; - break; - case 2: - move = width/2 + right_slack; - break; - } - } else if (old_align == SP_CSS_TEXT_ALIGN_END || old_align == SP_CSS_TEXT_ALIGN_RIGHT) { - switch (prop) { - case 0: - move = -width - left_slack; - break; - case 1: - move = -width/2 + (right_slack - left_slack)/2; - break; - case 2: - move = right_slack; - break; - } - } - Geom::Point XY = SP_TEXT(item)->attributes.firstXY(); - if (axis == NR::X) { - XY = XY + Geom::Point (move, 0); - } else { - XY = XY + Geom::Point (0, move); - } - SP_TEXT(item)->attributes.setFirstXY(XY); - SP_OBJECT(item)->updateRepr(); - SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); - } - } - - SPCSSAttr *css = sp_repr_css_attr_new (); - switch (prop) - { - case 0: - { - sp_repr_css_set_property (css, "text-anchor", "start"); - sp_repr_css_set_property (css, "text-align", "start"); - break; - } - case 1: - { - sp_repr_css_set_property (css, "text-anchor", "middle"); - sp_repr_css_set_property (css, "text-align", "center"); - break; - } - - case 2: - { - sp_repr_css_set_property (css, "text-anchor", "end"); - sp_repr_css_set_property (css, "text-align", "end"); - break; - } - - case 3: - { - sp_repr_css_set_property (css, "text-anchor", "start"); - sp_repr_css_set_property (css, "text-align", "justify"); - break; - } - } - - SPStyle *query = - sp_style_new (SP_ACTIVE_DOCUMENT); - int result_numbers = - sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); - - // If querying returned nothing, read the style from the text tool prefs (default style for new texts) - if (result_numbers == QUERY_STYLE_NOTHING) - { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - prefs->mergeStyle("/tools/text/style", css); - } - - sp_style_unref(query); - - sp_desktop_set_style (desktop, css, true, true); - sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT, - _("Text: Change alignment")); sp_repr_css_attr_unref (css); - gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); } -static void sp_text_toolbox_style_toggled(GtkToggleButton *button, - gpointer data) +// Handles both Bold and Italic/Oblique +static void sp_text_style_changed( InkToggleAction* act, GObject *tbl ) { - if (g_object_get_data (G_OBJECT (button), "block")) { + // quit if run by the _changed callbacks + if (g_object_get_data(G_OBJECT(tbl), "freeze")) { return; } + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - SPCSSAttr *css = sp_repr_css_attr_new (); - int prop = GPOINTER_TO_INT(data); - bool active = gtk_toggle_button_get_active (button); - - SPStyle *query = - sp_style_new (SP_ACTIVE_DOCUMENT); + // Called by Bold or Italics button? + const gchar* name = gtk_action_get_name( GTK_ACTION( act ) ); + gint prop = (strcmp(name, "TextBoldAction") == 0) ? 0 : 1; + // First query font-specification, this is the most complete font face description. + SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); int result_fontspec = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); // font_specification will not be set unless defined explicitely on a tspan. - // This needs to be fixed. + // This should be fixed! Glib::ustring fontSpec = query->text->font_specification.set ? query->text->font_specification.value : ""; - Glib::ustring newFontSpec = ""; if (fontSpec.empty()) { - - // Must query all to fill font-family, font-style, font-weight, font-specification + // Construct a new font specification if it does not yet exist + // Must query font-family, font-style, font-weight, to find correct font face. sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE); sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); - // Construct a new font specification if it does not yet exist font_instance * fontFromStyle = font_factory::Default()->FaceFromStyle(query); - fontSpec = font_factory::Default()->ConstructFontSpecification(fontFromStyle); - fontFromStyle->Unref(); + if( fontFromStyle ) { + fontSpec = font_factory::Default()->ConstructFontSpecification(fontFromStyle); + fontFromStyle->Unref(); + } } - bool nochange = true; + // Now that we have the old face, find the new face. + Glib::ustring newFontSpec = ""; + SPCSSAttr *css = sp_repr_css_attr_new (); + gboolean nochange = true; + gboolean active = gtk_toggle_action_get_active( GTK_TOGGLE_ACTION(act) ); + switch (prop) { case 0: { // Bold if (!fontSpec.empty()) { + newFontSpec = font_factory::Default()->FontSpecificationSetBold(fontSpec, active); + if (!newFontSpec.empty()) { + // Set weight if we found font. font_instance * font = font_factory::Default()->FaceFromFontSpecification(newFontSpec.c_str()); if (font) { gchar c[256]; @@ -6696,22 +6521,19 @@ static void sp_text_toolbox_style_toggled(GtkToggleButton *button, sp_repr_css_set_property (css, "font-weight", c); font->Unref(); font = NULL; - nochange = false; } + nochange = false; } } - // set or reset the button according + // Reset button if no change. + // The reset code didn't work in 0.47 and doesn't here... one must prevent an infinite loop + /* if(nochange) { - gboolean check = gtk_toggle_button_get_active (button); - - if (active != check) - { - g_object_set_data (G_OBJECT (button), "block", gpointer(1)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), active); - g_object_set_data (G_OBJECT (button), "block", gpointer(0)); - } + gtk_action_block_activate( GTK_ACTION(act) ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), !active ); + gtk_action_unblock_activate( GTK_ACTION(act) ); } - + */ break; } @@ -6719,8 +6541,11 @@ static void sp_text_toolbox_style_toggled(GtkToggleButton *button, { // Italic/Oblique if (!fontSpec.empty()) { + newFontSpec = font_factory::Default()->FontSpecificationSetItalic(fontSpec, active); + if (!newFontSpec.empty()) { + // Don't even set the italic/oblique if the font didn't exist on the system if( active ) { if( newFontSpec.find( "Italic" ) != Glib::ustring::npos ) { @@ -6734,16 +6559,15 @@ static void sp_text_toolbox_style_toggled(GtkToggleButton *button, nochange = false; } } + // Reset button if no change. + // The reset code didn't work in 0.47... one must prevent an infinite loop + /* if(nochange) { - gboolean check = gtk_toggle_button_get_active (button); - - if (active != check) - { - g_object_set_data (G_OBJECT (button), "block", gpointer(1)); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), active); - g_object_set_data (G_OBJECT (button), "block", gpointer(0)); - } + gtk_action_block_activate( GTK_ACTION(act) ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), !active ); + gtk_action_unblock_activate( GTK_ACTION(act) ); } + */ break; } } @@ -6752,7 +6576,7 @@ static void sp_text_toolbox_style_toggled(GtkToggleButton *button, sp_repr_css_set_property (css, "-inkscape-font-specification", newFontSpec.c_str()); } - // If querying returned nothing, read the style from the text tool prefs (default style for new texts) + // If querying returned nothing, update default style. if (result_fontspec == QUERY_STYLE_NOTHING) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -6761,36 +6585,135 @@ static void sp_text_toolbox_style_toggled(GtkToggleButton *button, sp_style_unref(query); + // Do we need to update other CSS values? + SPDesktop *desktop = SP_ACTIVE_DESKTOP; sp_desktop_set_style (desktop, css, true, true); sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT, _("Text: Change font style")); sp_repr_css_attr_unref (css); - gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); } -static void sp_text_toolbox_orientation_toggled(GtkRadioButton *button, - gpointer data) +static void sp_text_align_mode_changed( EgeSelectOneAction *act, GObject *tbl ) { - if (g_object_get_data (G_OBJECT (button), "block")) { + // quit if run by the _changed callbacks + if (g_object_get_data(G_OBJECT(tbl), "freeze")) { return; } + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - SPCSSAttr *css = sp_repr_css_attr_new (); - int prop = GPOINTER_TO_INT(data); + int mode = ege_select_one_action_get_active( act ); - switch (prop) + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setInt("/tools/text/align_mode", mode); + + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + + // move the x of all texts to preserve the same bbox + Inkscape::Selection *selection = sp_desktop_selection(desktop); + for (GSList const *items = selection->itemList(); items != NULL; items = items->next) { + if (SP_IS_TEXT((SPItem *) items->data)) { + SPItem *item = SP_ITEM(items->data); + + unsigned writing_mode = SP_OBJECT_STYLE(item)->writing_mode.value; + // below, variable names suggest horizontal move, but we check the writing direction + // and move in the corresponding axis + int axis; + if (writing_mode == SP_CSS_WRITING_MODE_LR_TB || writing_mode == SP_CSS_WRITING_MODE_RL_TB) { + axis = NR::X; + } else { + axis = NR::Y; + } + + Geom::OptRect bbox + = item->getBounds(Geom::identity(), SPItem::GEOMETRIC_BBOX); + if (!bbox) + continue; + double width = bbox->dimensions()[axis]; + // If you want to align within some frame, other than the text's own bbox, calculate + // the left and right (or top and bottom for tb text) slacks of the text inside that + // frame (currently unused) + double left_slack = 0; + double right_slack = 0; + unsigned old_align = SP_OBJECT_STYLE(item)->text_align.value; + double move = 0; + if (old_align == SP_CSS_TEXT_ALIGN_START || old_align == SP_CSS_TEXT_ALIGN_LEFT) { + switch (mode) { + case 0: + move = -left_slack; + break; + case 1: + move = width/2 + (right_slack - left_slack)/2; + break; + case 2: + move = width + right_slack; + break; + } + } else if (old_align == SP_CSS_TEXT_ALIGN_CENTER) { + switch (mode) { + case 0: + move = -width/2 - left_slack; + break; + case 1: + move = (right_slack - left_slack)/2; + break; + case 2: + move = width/2 + right_slack; + break; + } + } else if (old_align == SP_CSS_TEXT_ALIGN_END || old_align == SP_CSS_TEXT_ALIGN_RIGHT) { + switch (mode) { + case 0: + move = -width - left_slack; + break; + case 1: + move = -width/2 + (right_slack - left_slack)/2; + break; + case 2: + move = right_slack; + break; + } + } + Geom::Point XY = SP_TEXT(item)->attributes.firstXY(); + if (axis == NR::X) { + XY = XY + Geom::Point (move, 0); + } else { + XY = XY + Geom::Point (0, move); + } + SP_TEXT(item)->attributes.setFirstXY(XY); + SP_OBJECT(item)->updateRepr(); + SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); + } + } + + SPCSSAttr *css = sp_repr_css_attr_new (); + switch (mode) { case 0: { - sp_repr_css_set_property (css, "writing-mode", "lr"); + sp_repr_css_set_property (css, "text-anchor", "start"); + sp_repr_css_set_property (css, "text-align", "start"); break; } - case 1: { - sp_repr_css_set_property (css, "writing-mode", "tb"); + sp_repr_css_set_property (css, "text-anchor", "middle"); + sp_repr_css_set_property (css, "text-align", "center"); + break; + } + + case 2: + { + sp_repr_css_set_property (css, "text-anchor", "end"); + sp_repr_css_set_property (css, "text-align", "end"); + break; + } + + case 3: + { + sp_repr_css_set_property (css, "text-anchor", "start"); + sp_repr_css_set_property (css, "text-align", "justify"); break; } } @@ -6800,549 +6723,732 @@ static void sp_text_toolbox_orientation_toggled(GtkRadioButton *button, int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); - // If querying returned nothing, read the style from the text tool prefs (default style for new texts) + // If querying returned nothing, update default style. if (result_numbers == QUERY_STYLE_NOTHING) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->mergeStyle("/tools/text/style", css); } + sp_style_unref(query); + sp_desktop_set_style (desktop, css, true, true); sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT, - _("Text: Change orientation")); + _("Text: Change alignment")); sp_repr_css_attr_unref (css); gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); -} - -static gboolean sp_text_toolbox_family_keypress(GtkWidget * /*w*/, GdkEventKey *event, GObject *tbl) -{ - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (!desktop) { - return FALSE; - } - - switch (get_group0_keyval (event)) { - case GDK_KP_Enter: // chosen - case GDK_Return: - // unfreeze and update, which will defocus - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); - sp_text_toolbox_family_changed (NULL, tbl); - return TRUE; // I consumed the event - break; - case GDK_Escape: - // defocus - gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); - return TRUE; // I consumed the event - break; - } - return FALSE; -} - -static gboolean sp_text_toolbox_family_list_keypress(GtkWidget * /*w*/, GdkEventKey *event, GObject * /*tbl*/) -{ - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (!desktop) { - return FALSE; - } - switch (get_group0_keyval (event)) { - case GDK_KP_Enter: - case GDK_Return: - case GDK_Escape: // defocus - gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); - return TRUE; // I consumed the event - break; - case GDK_w: - case GDK_W: - if (event->state & GDK_CONTROL_MASK) { - gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); - return TRUE; // I consumed the event - } - break; - } - return FALSE; + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); } - -static void sp_text_toolbox_size_changed(GtkComboBox *cbox, - GObject *tbl) +static void sp_text_lineheight_value_changed( GtkAdjustment *adj, GObject *tbl ) { - // quit if run by the _changed callbacks + // quit if run by the _changed callbacks if (g_object_get_data(G_OBJECT(tbl), "freeze")) { return; } - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - - // If this is not from selecting a size in the list (in which case get_active will give the - // index of the selected item, otherwise -1) and not from user pressing Enter/Return, do not - // process this event. This fixes GTK's stupid insistence on sending an activate change every - // time any character gets typed or deleted, which made this control nearly unusable in 0.45. - if (gtk_combo_box_get_active (cbox) < 0 && !g_object_get_data (tbl, "enter-pressed")) { - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); - return; - } - - gdouble value = -1; - { - gchar *endptr; - gchar *const text = gtk_combo_box_get_active_text(cbox); - if (text) { - value = g_strtod(text, &endptr); - if (endptr == text) { // Conversion failed, non-numeric input. - value = -1; - } - g_free(text); - } - } - if (value <= 0) { - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); - return; // could not parse value - } - + // At the moment this handles only numerical values (i.e. no percent). + // Set css line height. SPCSSAttr *css = sp_repr_css_attr_new (); Inkscape::CSSOStringStream osfs; - osfs << value; - sp_repr_css_set_property (css, "font-size", osfs.str().c_str()); + osfs << adj->value*100 << "%"; + sp_repr_css_set_property (css, "line-height", osfs.str().c_str()); - SPStyle *query = - sp_style_new (SP_ACTIVE_DOCUMENT); + // Apply line-height to selected objects. + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + sp_desktop_set_style (desktop, css, true, true); + + // Save for undo + sp_document_maybe_done (sp_desktop_document (SP_ACTIVE_DESKTOP), "ttb:line-height", SP_VERB_NONE, + _("Text: Change line-height")); + + // If no selected objects, set default. + SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); - - // If querying returned nothing, read the style from the text tool prefs (default style for new texts) if (result_numbers == QUERY_STYLE_NOTHING) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); prefs->mergeStyle("/tools/text/style", css); } - sp_style_unref(query); - sp_desktop_set_style (desktop, css, true, true); - sp_document_maybe_done (sp_desktop_document (SP_ACTIVE_DESKTOP), "ttb:size", SP_VERB_NONE, - _("Text: Change font size")); sp_repr_css_attr_unref (css); - gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); } -static gboolean sp_text_toolbox_size_focusout(GtkWidget * /*w*/, GdkEventFocus * /*event*/, GObject *tbl) +static void sp_text_wordspacing_value_changed( GtkAdjustment *adj, GObject *tbl ) { - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (!desktop) { - return FALSE; - } - - if (!g_object_get_data (tbl, "esc-pressed")) { - g_object_set_data (tbl, "enter-pressed", gpointer(1)); - GtkComboBox *cbox = GTK_COMBO_BOX(g_object_get_data (G_OBJECT (tbl), "combo-box-size")); - sp_text_toolbox_size_changed (cbox, tbl); - g_object_set_data (tbl, "enter-pressed", gpointer(0)); + // quit if run by the _changed callbacks + if (g_object_get_data(G_OBJECT(tbl), "freeze")) { + return; } - return FALSE; // I consumed the event -} + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); + // At the moment this handles only numerical values (i.e. no em unit). + // Set css word-spacing + SPCSSAttr *css = sp_repr_css_attr_new (); + Inkscape::CSSOStringStream osfs; + osfs << adj->value; + sp_repr_css_set_property (css, "word-spacing", osfs.str().c_str()); + + // Apply word-spacing to selected objects. + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + sp_desktop_set_style (desktop, css, true, true); + + // Save for undo + sp_document_maybe_done (sp_desktop_document (SP_ACTIVE_DESKTOP), "ttb:word-spacing", SP_VERB_NONE, + _("Text: Change word-spacing")); + + // If no selected objects, set default. + SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); + int result_numbers = + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + if (result_numbers == QUERY_STYLE_NOTHING) + { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->mergeStyle("/tools/text/style", css); + } + sp_style_unref(query); + + sp_repr_css_attr_unref (css); + + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); +} -static gboolean sp_text_toolbox_size_keypress(GtkWidget * /*w*/, GdkEventKey *event, GObject *tbl) +static void sp_text_letterspacing_value_changed( GtkAdjustment *adj, GObject *tbl ) { + // quit if run by the _changed callbacks + if (g_object_get_data(G_OBJECT(tbl), "freeze")) { + return; + } + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); + + // At the moment this handles only numerical values (i.e. no em unit). + // Set css letter-spacing + SPCSSAttr *css = sp_repr_css_attr_new (); + Inkscape::CSSOStringStream osfs; + osfs << adj->value; + sp_repr_css_set_property (css, "letter-spacing", osfs.str().c_str()); + + // Apply letter-spacing to selected objects. SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (!desktop) { - return FALSE; + sp_desktop_set_style (desktop, css, true, true); + + // Save for undo + sp_document_maybe_done (sp_desktop_document (SP_ACTIVE_DESKTOP), "ttb:letter-spacing", SP_VERB_NONE, + _("Text: Change letter-spacing")); + + // If no selected objects, set default. + SPStyle *query = sp_style_new (SP_ACTIVE_DOCUMENT); + int result_numbers = + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + if (result_numbers == QUERY_STYLE_NOTHING) + { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->mergeStyle("/tools/text/style", css); + } + sp_style_unref(query); + + sp_repr_css_attr_unref (css); + + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); +} + +static void sp_text_orientation_mode_changed( EgeSelectOneAction *act, GObject *tbl ) +{ + // quit if run by the _changed callbacks + if (g_object_get_data(G_OBJECT(tbl), "freeze")) { + return; } + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); + + int mode = ege_select_one_action_get_active( act ); - switch (get_group0_keyval (event)) { - case GDK_Escape: // defocus - g_object_set_data (tbl, "esc-pressed", gpointer(1)); - gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); - g_object_set_data (tbl, "esc-pressed", gpointer(0)); - return TRUE; // I consumed the event + SPCSSAttr *css = sp_repr_css_attr_new (); + switch (mode) + { + case 0: + { + sp_repr_css_set_property (css, "writing-mode", "lr"); break; - case GDK_Return: // defocus - case GDK_KP_Enter: - g_object_set_data (tbl, "enter-pressed", gpointer(1)); - GtkComboBox *cbox = GTK_COMBO_BOX(g_object_get_data (G_OBJECT (tbl), "combo-box-size")); - sp_text_toolbox_size_changed (cbox, tbl); - gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); - g_object_set_data (tbl, "enter-pressed", gpointer(0)); - return TRUE; // I consumed the event + } + + case 1: + { + sp_repr_css_set_property (css, "writing-mode", "tb"); break; + } } - return FALSE; + + SPStyle *query = + sp_style_new (SP_ACTIVE_DOCUMENT); + int result_numbers = + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + + // If querying returned nothing, update default style. + if (result_numbers == QUERY_STYLE_NOTHING) + { + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->mergeStyle("/tools/text/style", css); + } + + sp_desktop_set_style (SP_ACTIVE_DESKTOP, css, true, true); + sp_document_done (sp_desktop_document (SP_ACTIVE_DESKTOP), SP_VERB_CONTEXT_TEXT, + _("Text: Change orientation")); + sp_repr_css_attr_unref (css); + + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); } -// While editing font name in the entry, disable family_changed by freezing, otherwise completion -// does not work! -static gboolean sp_text_toolbox_entry_focus_in(GtkWidget *entry, - GdkEventFocus * /*event*/, - GObject *tbl) +/* + * This function sets up the text-tool tool-controls, setting the entry boxes + * etc. to the values from the current selection or the default if no selection. + * It is called whenever a text selection is changed, including stepping cursor + * through text. + */ +static void sp_text_toolbox_selection_changed(Inkscape::Selection */*selection*/, GObject *tbl) { +#ifdef DEBUG_TEXT + static int count = 0; + ++count; + std::cout << std::endl; + std::cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << std::endl; + std::cout << "sp_text_toolbox_selection_changed: start " << count << std::endl; + + std::cout << " Selected items:" << std::endl; + for (GSList const *items = sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(); + items != NULL; + items = items->next) + { + const gchar* id = SP_OBJECT_ID((SPItem *) items->data); + std::cout << " " << id << std::endl; + } +#endif + + // quit if run by the _changed callbacks + if (g_object_get_data(G_OBJECT(tbl), "freeze")) { +#ifdef DEBUG_TEXT + std::cout << " Frozen, returning" << std::endl; + std::cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << std::endl; + std::cout << std::endl; +#endif + return; + } g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); - gtk_entry_select_region (GTK_ENTRY (entry), 0, -1); // select all - return FALSE; + + /* + * Query from current selection: + * Font family (font-family) + * Style (font-weight, font-style, font-stretch, font-variant, font-align) + * Numbers (font-size, letter-spacing, word-spacing, line-height, text-anchor, writing-mode) + * Font specification (Inkscape private attribute) + */ + SPStyle *query = + sp_style_new (SP_ACTIVE_DOCUMENT); + int result_family = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTFAMILY); + int result_style = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTSTYLE); + int result_numbers = sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONTNUMBERS); + // Used later: + sp_desktop_query_style (SP_ACTIVE_DESKTOP, query, QUERY_STYLE_PROPERTY_FONT_SPECIFICATION); + + /* + * If no text in selection (querying returned nothing), read the style from + * the /tools/text preferencess (default style for new texts). Return if + * tool bar already set to these preferences. + */ + if (result_family == QUERY_STYLE_NOTHING || result_style == QUERY_STYLE_NOTHING || result_numbers == QUERY_STYLE_NOTHING) { + // There are no texts in selection, read from preferences. + sp_style_read_from_prefs(query, "/tools/text"); +#ifdef DEBUG_TEXT + std::cout << " read style from prefs:" << std::endl; + sp_print_font( query ); +#endif + if (g_object_get_data(tbl, "text_style_from_prefs")) { + // Do not reset the toolbar style from prefs if we already did it last time + sp_style_unref(query); + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); +#ifdef DEBUG_TEXT + std::cout << " text_style_from_prefs: toolbar already set" << std:: endl; + std::cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << std::endl; + std::cout << std::endl; +#endif + return; + } + + g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(TRUE)); + } else { + g_object_set_data(tbl, "text_style_from_prefs", GINT_TO_POINTER(FALSE)); + } + + // If we have valid query data for text (font-family, font-specification) set toolbar accordingly. + if (query->text) + { + // Font family + if( query->text->font_family.value ) { + gchar *fontFamily = query->text->font_family.value; + + Ink_ComboBoxEntry_Action* fontFamilyAction = + INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontFamilyAction" ) ); + ink_comboboxentry_action_set_active_text( fontFamilyAction, fontFamily ); + } + + // Size (average of text selected) + double size = query->font_size.computed; + gchar size_text[G_ASCII_DTOSTR_BUF_SIZE]; + g_ascii_dtostr (size_text, sizeof (size_text), size); + + Ink_ComboBoxEntry_Action* fontSizeAction = + INK_COMBOBOXENTRY_ACTION( g_object_get_data( tbl, "TextFontSizeAction" ) ); + ink_comboboxentry_action_set_active_text( fontSizeAction, size_text ); + + // Weight (Bold) + // Note: in the enumeration, normal and lighter come at the end so we must explicitly test for them. + gboolean boldSet = ((query->font_weight.computed >= SP_CSS_FONT_WEIGHT_700) && + (query->font_weight.computed != SP_CSS_FONT_WEIGHT_NORMAL) && + (query->font_weight.computed != SP_CSS_FONT_WEIGHT_LIGHTER)); + + InkToggleAction* textBoldAction = INK_TOGGLE_ACTION( g_object_get_data( tbl, "TextBoldAction" ) ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(textBoldAction), boldSet ); + + + // Style (Italic/Oblique) + gboolean italicSet = (query->font_style.computed != SP_CSS_FONT_STYLE_NORMAL); + + InkToggleAction* textItalicAction = INK_TOGGLE_ACTION( g_object_get_data( tbl, "TextItalicAction" ) ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(textItalicAction), italicSet ); + + + // Alignment + // Note: SVG 1.1 doesn't include text-align, SVG 1.2 Tiny doesn't include text-align="justify" + // text-align="justify" was a draft SVG 1.2 item (along with flowed text). + // Only flowed text can be left and right justified at the same time. + // Check if we have flowed text and disable botton. + // NEED: ege_select_one_action_set_sensitve( ) + /* + gboolean isFlow = false; + for (GSList const *items = sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(); + items != NULL; + items = items->next) { + const gchar* id = SP_OBJECT_ID((SPItem *) items->data); + std::cout << " " << id << std::endl; + if( SP_IS_FLOWTEXT(( SPItem *) items->data )) { + isFlow = true; + std::cout << " Found flowed text" << std::endl; + break; + } + } + if( isFlow ) { + // enable justify button + } else { + // disable justify button + } + */ + + int activeButton = 0; + if (query->text_align.computed == SP_CSS_TEXT_ALIGN_JUSTIFY) + { + activeButton = 3; + } else { + if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_START) activeButton = 0; + if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_MIDDLE) activeButton = 1; + if (query->text_anchor.computed == SP_CSS_TEXT_ANCHOR_END) activeButton = 2; + } + EgeSelectOneAction* textAlignAction = EGE_SELECT_ONE_ACTION( g_object_get_data( tbl, "TextAlignAction" ) ); + ege_select_one_action_set_active( textAlignAction, activeButton ); + + + // Line height (spacing) + double height; + if (query->line_height.normal) { + height = Inkscape::Text::Layout::LINE_HEIGHT_NORMAL; + } else { + if (query->line_height.unit == SP_CSS_UNIT_PERCENT) { + height = query->line_height.value; + } else { + height = query->line_height.computed; + } + } + + GtkAction* lineHeightAction = GTK_ACTION( g_object_get_data( tbl, "TextLineHeightAction" ) ); + GtkAdjustment *lineHeightAdjustment = + ege_adjustment_action_get_adjustment(EGE_ADJUSTMENT_ACTION( lineHeightAction )); + gtk_adjustment_set_value( lineHeightAdjustment, height ); + + + // Word spacing + double wordSpacing; + if (query->word_spacing.normal) wordSpacing = 0.0; + else wordSpacing = query->word_spacing.computed; // Assume no units (change in desktop-style.cpp) + + GtkAction* wordSpacingAction = GTK_ACTION( g_object_get_data( tbl, "TextWordSpacingAction" ) ); + GtkAdjustment *wordSpacingAdjustment = + ege_adjustment_action_get_adjustment(EGE_ADJUSTMENT_ACTION( wordSpacingAction )); + gtk_adjustment_set_value( wordSpacingAdjustment, wordSpacing ); + + + // Letter spacing + double letterSpacing; + if (query->letter_spacing.normal) letterSpacing = 0.0; + else letterSpacing = query->letter_spacing.computed; // Assume no units (change in desktop-style.cpp) + + GtkAction* letterSpacingAction = GTK_ACTION( g_object_get_data( tbl, "TextLetterSpacingAction" ) ); + GtkAdjustment *letterSpacingAdjustment = + ege_adjustment_action_get_adjustment(EGE_ADJUSTMENT_ACTION( letterSpacingAction )); + gtk_adjustment_set_value( letterSpacingAdjustment, letterSpacing ); + + + // Orientation + int activeButton2 = (query->writing_mode.computed == SP_CSS_WRITING_MODE_LR_TB ? 0 : 1); + + EgeSelectOneAction* textOrientationAction = + EGE_SELECT_ONE_ACTION( g_object_get_data( tbl, "TextOrientationAction" ) ); + ege_select_one_action_set_active( textOrientationAction, activeButton2 ); + + + } // if( query->text ) + +#ifdef DEBUG_TEXT + std::cout << " GUI: fontfamily.value: " + << (query->text->font_family.value ? query->text->font_family.value : "No value") + << std::endl; + std::cout << " GUI: font_size.computed: " << query->font_size.computed << std::endl; + std::cout << " GUI: font_weight.computed: " << query->font_weight.computed << std::endl; + std::cout << " GUI: font_style.computed: " << query->font_style.computed << std::endl; + std::cout << " GUI: text_anchor.computed: " << query->text_anchor.computed << std::endl; + std::cout << " GUI: text_align.computed: " << query->text_align.computed << std::endl; + std::cout << " GUI: line_height.computed: " << query->line_height.computed + << " line_height.value: " << query->line_height.value + << " line_height.unit: " << query->line_height.unit << std::endl; + std::cout << " GUI: word_spacing.computed: " << query->word_spacing.computed + << " word_spacing.value: " << query->word_spacing.value + << " word_spacing.unit: " << query->word_spacing.unit << std::endl; + std::cout << " GUI: letter_spacing.computed: " << query->letter_spacing.computed + << " letter_spacing.value: " << query->letter_spacing.value + << " letter_spacing.unit: " << query->letter_spacing.unit << std::endl; + std::cout << " GUI: writing_mode.computed: " << query->writing_mode.computed << std::endl; + std::cout << "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&" << std::endl; + std::cout << std::endl; +#endif + + sp_style_unref(query); + + g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); + } -static gboolean sp_text_toolbox_entry_focus_out(GtkWidget *entry, - GdkEventFocus * /*event*/, - GObject *tbl) +static void sp_text_toolbox_selection_modified(Inkscape::Selection *selection, guint /*flags*/, GObject *tbl) { - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); - gtk_entry_select_region (GTK_ENTRY (entry), 0, 0); // deselect - return FALSE; + sp_text_toolbox_selection_changed (selection, tbl); } -static void cell_data_func(GtkCellLayout * /*cell_layout*/, - GtkCellRenderer *cell, - GtkTreeModel *tree_model, - GtkTreeIter *iter, - gpointer /*data*/) +void +sp_text_toolbox_subselection_changed (gpointer /*tc*/, GObject *tbl) { - gchar *family; - gtk_tree_model_get(tree_model, iter, 0, &family, -1); - gchar *const family_escaped = g_markup_escape_text(family, -1); + sp_text_toolbox_selection_changed (NULL, tbl); +} +// Define all the "widgets" in the toolbar. +static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions, GObject* holder) +{ Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - int show_sample = prefs->getInt("/tools/text/show_sample_in_list", 1); - if (show_sample) { + Inkscape::IconSize secondarySize = ToolboxFactory::prefToSize("/toolbox/secondary", 1); - Glib::ustring sample = prefs->getString("/tools/text/font_sample"); - gchar *const sample_escaped = g_markup_escape_text(sample.data(), -1); + // Is this used? + UnitTracker* tracker = new UnitTracker( SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE ); + tracker->setActiveUnit( sp_desktop_namedview(desktop)->doc_units ); + g_object_set_data( holder, "tracker", tracker ); - std::stringstream markup; - markup << family_escaped << " " << sample_escaped << ""; - g_object_set (G_OBJECT (cell), "markup", markup.str().c_str(), NULL); + /* Font family */ + { + // Font list + Glib::RefPtr store = Inkscape::FontLister::get_instance()->get_font_list(); + GtkListStore* model = store->gobj(); + + Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontFamilyAction", + _("Font Family"), + _("Select Font Family"), + NULL, + GTK_TREE_MODEL(model), + -1, // Set width + (gpointer)cell_data_func ); // Cell layout + ink_comboboxentry_action_popup_enable( act ); // Enable entry completion + gchar *const warning = _("Font not found on system"); + ink_comboboxentry_action_set_warning( act, warning ); // Show icon with tooltip if missing font + g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontfamily_value_changed), holder ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + g_object_set_data( holder, "TextFontFamilyAction", act ); + } - g_free(sample_escaped); - } else { - g_object_set (G_OBJECT (cell), "markup", family_escaped, NULL); + /* Font size */ + { + // List of font sizes for drop-down menu + GtkListStore* model_size = gtk_list_store_new( 1, G_TYPE_STRING ); + gchar const *const sizes[] = { + "4", "6", "8", "9", "10", "11", "12", "13", "14", "16", + "18", "20", "22", "24", "28", "32", "36", "40", "48", "56", + "64", "72", "144" + }; + for( unsigned int i = 0; i < G_N_ELEMENTS(sizes); ++i ) { + GtkTreeIter iter; + gtk_list_store_append( model_size, &iter ); + gtk_list_store_set( model_size, &iter, 0, sizes[i], -1 ); + } + + Ink_ComboBoxEntry_Action* act = ink_comboboxentry_action_new( "TextFontSizeAction", + _("Font Size"), + _("Select Font Size"), + NULL, + GTK_TREE_MODEL(model_size), + 4 ); // Width in characters + g_signal_connect( G_OBJECT(act), "changed", G_CALLBACK(sp_text_fontsize_value_changed), holder ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + g_object_set_data( holder, "TextFontSizeAction", act ); } - g_free(family); - g_free(family_escaped); -} + /* Style - Bold */ + { + InkToggleAction* act = ink_toggle_action_new( "TextBoldAction", // Name + _("Toggle Bold"), // Label + _("Toggle On/Off Bold Style"), // Tooltip + GTK_STOCK_BOLD, // Icon (inkId) + secondarySize ); // Icon size + gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_text_style_changed), holder ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/text/bold", false) ); + g_object_set_data( holder, "TextBoldAction", act ); + } -static gboolean text_toolbox_completion_match_selected(GtkEntryCompletion * /*widget*/, - GtkTreeModel *model, - GtkTreeIter *iter, - GObject *tbl) -{ - // We intercept this signal so as to fire family_changed at once (without it, you'd have to - // press Enter again after choosing a completion) - gchar *family = 0; - gtk_tree_model_get(model, iter, 0, &family, -1); + /* Style - Italic/Oblique */ + { + InkToggleAction* act = ink_toggle_action_new( "TextItalicAction", // Name + _("Toggle Italic/Oblique"), // Label + _("Toggle On/Off Italic/Oblique Style"),// Tooltip + GTK_STOCK_ITALIC, // Icon (inkId) + secondarySize ); // Icon size + gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(sp_text_style_changed), holder ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs->getBool("/tools/text/italic", false) ); + g_object_set_data( holder, "TextItalicAction", act ); + } - GtkEntry *entry = GTK_ENTRY (g_object_get_data (G_OBJECT (tbl), "family-entry")); - gtk_entry_set_text (GTK_ENTRY (entry), family); + /* Alignment */ + { + GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING ); - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); - sp_text_toolbox_family_changed (NULL, tbl); - return TRUE; -} - - -static void cbe_add_completion(GtkComboBoxEntry *cbe, GObject *tbl) -{ - GtkEntry *entry; - GtkEntryCompletion *completion; - GtkTreeModel *model; - - entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(cbe))); - completion = gtk_entry_completion_new(); - model = gtk_combo_box_get_model(GTK_COMBO_BOX(cbe)); - gtk_entry_completion_set_model(completion, model); - gtk_entry_completion_set_text_column(completion, 0); - gtk_entry_completion_set_inline_completion(completion, FALSE); - gtk_entry_completion_set_inline_selection(completion, FALSE); - gtk_entry_completion_set_popup_completion(completion, TRUE); - gtk_entry_set_completion(entry, completion); - - g_signal_connect (G_OBJECT (completion), "match-selected", G_CALLBACK (text_toolbox_completion_match_selected), tbl); - - g_object_unref(completion); -} - -static void sp_text_toolbox_family_popnotify(GtkComboBox *widget, - void * /*property*/, - GObject *tbl) -{ - // while the drop-down is open, we disable font family changing, reenabling it only when it closes - - gboolean shown; - g_object_get (G_OBJECT(widget), "popup-shown", &shown, NULL); - if (shown) { - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(TRUE) ); - //g_print("POP: notify: SHOWN\n"); - } else { - g_object_set_data( tbl, "freeze", GINT_TO_POINTER(FALSE) ); - - // stupid GTK doesn't let us attach to events in the drop-down window, so we peek here to - // find out if the drop down was closed by Enter and if so, manually update (only - // necessary on Windows, on Linux it updates itself - what a mess, but we'll manage) - GdkEvent *ev = gtk_get_current_event(); - if (ev) { - //g_print ("ev type: %d\n", ev->type); - if (ev->type == GDK_KEY_PRESS) { - switch (get_group0_keyval ((GdkEventKey *) ev)) { - case GDK_KP_Enter: // chosen - case GDK_Return: - { - // make sure the chosen one is inserted into the entry - GtkComboBox *combo = GTK_COMBO_BOX (((Gtk::ComboBox *) (g_object_get_data (tbl, "family-entry-combo")))->gobj()); - GtkTreeModel *model = gtk_combo_box_get_model(combo); - GtkTreeIter iter; - gboolean has_active = gtk_combo_box_get_active_iter (combo, &iter); - if (has_active) { - gchar *family; - gtk_tree_model_get(model, &iter, 0, &family, -1); - GtkEntry *entry = GTK_ENTRY (g_object_get_data (G_OBJECT (tbl), "family-entry")); - gtk_entry_set_text (GTK_ENTRY (entry), family); - } - - // update - sp_text_toolbox_family_changed (NULL, tbl); - break; - } - } - } - } - - // regardless of whether we updated, defocus the widget - SPDesktop *desktop = SP_ACTIVE_DESKTOP; - if (desktop) { - gtk_widget_grab_focus (GTK_WIDGET(desktop->canvas)); - } - //g_print("POP: notify: HIDDEN\n"); - } -} - -GtkWidget *sp_text_toolbox_new(SPDesktop *desktop) -{ - GtkToolbar *tbl = GTK_TOOLBAR(gtk_toolbar_new()); - GtkIconSize secondarySize = static_cast(ToolboxFactory::prefToSize("/toolbox/secondary", 1)); + GtkTreeIter iter; - gtk_object_set_data(GTK_OBJECT(tbl), "dtw", desktop->canvas); - gtk_object_set_data(GTK_OBJECT(tbl), "desktop", desktop); + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("Align left"), + 1, _("Align left"), + 2, GTK_STOCK_JUSTIFY_LEFT, + -1 ); - GtkTooltips *tt = gtk_tooltips_new(); - - ////////////Family - Glib::RefPtr store = Inkscape::FontLister::get_instance()->get_font_list(); - Gtk::ComboBoxEntry *font_sel = Gtk::manage(new Gtk::ComboBoxEntry(store)); - - gtk_rc_parse_string ( - "style \"dropdown-as-list-style\"\n" - "{\n" - " GtkComboBox::appears-as-list = 1\n" - "}\n" - "widget \"*.toolbox-fontfamily-list\" style \"dropdown-as-list-style\""); - gtk_widget_set_name(GTK_WIDGET (font_sel->gobj()), "toolbox-fontfamily-list"); - gtk_tooltips_set_tip (tt, GTK_WIDGET (font_sel->gobj()), _("Select font family (Alt+X to access)"), ""); - - g_signal_connect (G_OBJECT (font_sel->gobj()), "key-press-event", G_CALLBACK(sp_text_toolbox_family_list_keypress), tbl); - - cbe_add_completion(font_sel->gobj(), G_OBJECT(tbl)); - - gtk_toolbar_append_widget( tbl, (GtkWidget*) font_sel->gobj(), "", ""); - g_object_set_data (G_OBJECT (tbl), "family-entry-combo", font_sel); - - // expand the field a bit so as to view more of the previews in the drop-down - GtkRequisition req; - gtk_widget_size_request (GTK_WIDGET (font_sel->gobj()), &req); - gtk_widget_set_size_request (GTK_WIDGET (font_sel->gobj()), MIN(req.width + 50, 500), -1); - - GtkWidget* entry = (GtkWidget*) font_sel->get_entry()->gobj(); - g_signal_connect (G_OBJECT (entry), "activate", G_CALLBACK (sp_text_toolbox_family_changed), tbl); - - g_signal_connect (G_OBJECT (font_sel->gobj()), "changed", G_CALLBACK (sp_text_toolbox_family_changed), tbl); - g_signal_connect (G_OBJECT (font_sel->gobj()), "notify::popup-shown", - G_CALLBACK (sp_text_toolbox_family_popnotify), tbl); - g_signal_connect (G_OBJECT (entry), "key-press-event", G_CALLBACK(sp_text_toolbox_family_keypress), tbl); - g_signal_connect (G_OBJECT (entry), "focus-in-event", G_CALLBACK (sp_text_toolbox_entry_focus_in), tbl); - g_signal_connect (G_OBJECT (entry), "focus-out-event", G_CALLBACK (sp_text_toolbox_entry_focus_out), tbl); - - gtk_object_set_data(GTK_OBJECT(entry), "altx-text", entry); - g_object_set_data (G_OBJECT (tbl), "family-entry", entry); - - GtkCellRenderer *cell = gtk_cell_renderer_text_new (); - gtk_cell_layout_clear( GTK_CELL_LAYOUT(font_sel->gobj()) ); - gtk_cell_layout_pack_start( GTK_CELL_LAYOUT(font_sel->gobj()) , cell , TRUE ); - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT(font_sel->gobj()), cell, GtkCellLayoutDataFunc (cell_data_func), NULL, NULL); - - GtkWidget *image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, secondarySize); - GtkWidget *box = gtk_event_box_new (); - gtk_container_add (GTK_CONTAINER (box), image); - gtk_toolbar_append_widget( tbl, box, "", ""); - g_object_set_data (G_OBJECT (tbl), "warning-image", box); - gtk_tooltips_set_tip (tt, box, _("This font is currently not installed on your system. Inkscape will use the default font instead."), ""); - gtk_widget_hide (GTK_WIDGET (box)); - g_signal_connect_swapped (G_OBJECT (tbl), "show", G_CALLBACK (gtk_widget_hide), box); - - ////////////Size - gchar const *const sizes[] = { - "4", "6", "8", "9", "10", "11", "12", "13", "14", - "16", "18", "20", "22", "24", "28", - "32", "36", "40", "48", "56", "64", "72", "144" - }; + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("Align center"), + 1, _("Align center"), + 2, GTK_STOCK_JUSTIFY_CENTER, + -1 ); + + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("Align right"), + 1, _("Align right"), + 2, GTK_STOCK_JUSTIFY_RIGHT, + -1 ); - GtkWidget *cbox = gtk_combo_box_entry_new_text (); - for (unsigned int i = 0; i < G_N_ELEMENTS(sizes); ++i) { - gtk_combo_box_append_text(GTK_COMBO_BOX(cbox), sizes[i]); - } - gtk_widget_set_size_request (cbox, 80, -1); - gtk_toolbar_append_widget( tbl, cbox, "", ""); - g_object_set_data (G_OBJECT (tbl), "combo-box-size", cbox); - g_signal_connect (G_OBJECT (cbox), "changed", G_CALLBACK (sp_text_toolbox_size_changed), tbl); - gtk_signal_connect(GTK_OBJECT(gtk_bin_get_child(GTK_BIN(cbox))), "key-press-event", GTK_SIGNAL_FUNC(sp_text_toolbox_size_keypress), tbl); - gtk_signal_connect(GTK_OBJECT(gtk_bin_get_child(GTK_BIN(cbox))), "focus-out-event", GTK_SIGNAL_FUNC(sp_text_toolbox_size_focusout), tbl); - - ////////////Text anchor - GtkWidget *group = gtk_radio_button_new (NULL); - GtkWidget *row = gtk_hbox_new (FALSE, 4); - g_object_set_data (G_OBJECT (tbl), "anchor-group", group); - - // left - GtkWidget *rbutton = group; - gtk_button_set_relief (GTK_BUTTON (rbutton), GTK_RELIEF_NONE); - gtk_container_add (GTK_CONTAINER (rbutton), gtk_image_new_from_stock (GTK_STOCK_JUSTIFY_LEFT, secondarySize)); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (rbutton), FALSE); - - gtk_box_pack_start (GTK_BOX (row), rbutton, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (tbl), "text-start", rbutton); - g_signal_connect (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_anchoring_toggled), gpointer(0)); - gtk_tooltips_set_tip(tt, rbutton, _("Align left"), NULL); - - // center - rbutton = gtk_radio_button_new (gtk_radio_button_group (GTK_RADIO_BUTTON (group))); - gtk_button_set_relief (GTK_BUTTON (rbutton), GTK_RELIEF_NONE); - gtk_container_add (GTK_CONTAINER (rbutton), gtk_image_new_from_stock (GTK_STOCK_JUSTIFY_CENTER, secondarySize)); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (rbutton), FALSE); - - gtk_box_pack_start (GTK_BOX (row), rbutton, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (tbl), "text-middle", rbutton); - g_signal_connect (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_anchoring_toggled), gpointer (1)); - gtk_tooltips_set_tip(tt, rbutton, _("Center"), NULL); - - // right - rbutton = gtk_radio_button_new (gtk_radio_button_group (GTK_RADIO_BUTTON (group))); - gtk_button_set_relief (GTK_BUTTON (rbutton), GTK_RELIEF_NONE); - gtk_container_add (GTK_CONTAINER (rbutton), gtk_image_new_from_stock (GTK_STOCK_JUSTIFY_RIGHT, secondarySize)); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (rbutton), FALSE); - - gtk_box_pack_start (GTK_BOX (row), rbutton, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (tbl), "text-end", rbutton); - g_signal_connect (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_anchoring_toggled), gpointer(2)); - gtk_tooltips_set_tip(tt, rbutton, _("Align right"), NULL); - - // fill - rbutton = gtk_radio_button_new (gtk_radio_button_group (GTK_RADIO_BUTTON (group))); - gtk_button_set_relief (GTK_BUTTON (rbutton), GTK_RELIEF_NONE); - gtk_container_add (GTK_CONTAINER (rbutton), gtk_image_new_from_stock (GTK_STOCK_JUSTIFY_FILL, secondarySize)); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (rbutton), FALSE); - - gtk_box_pack_start (GTK_BOX (row), rbutton, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (tbl), "text-fill", rbutton); - g_signal_connect (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_anchoring_toggled), gpointer(3)); - gtk_tooltips_set_tip(tt, rbutton, _("Justify"), NULL); - - gtk_toolbar_append_widget( tbl, row, "", ""); - - //spacer - gtk_toolbar_append_widget( tbl, gtk_vseparator_new(), "", "" ); - - ////////////Text style - row = gtk_hbox_new (FALSE, 4); - - // bold - rbutton = gtk_toggle_button_new (); - gtk_button_set_relief (GTK_BUTTON (rbutton), GTK_RELIEF_NONE); - gtk_container_add (GTK_CONTAINER (rbutton), gtk_image_new_from_stock (GTK_STOCK_BOLD, secondarySize)); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (rbutton), FALSE); - gtk_tooltips_set_tip(tt, rbutton, _("Bold"), NULL); - - gtk_box_pack_start (GTK_BOX (row), rbutton, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (tbl), "style-bold", rbutton); - g_signal_connect (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_style_toggled), gpointer(0)); - - // italic - rbutton = gtk_toggle_button_new (); - gtk_button_set_relief (GTK_BUTTON (rbutton), GTK_RELIEF_NONE); - gtk_container_add (GTK_CONTAINER (rbutton), gtk_image_new_from_stock (GTK_STOCK_ITALIC, secondarySize)); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (rbutton), FALSE); - gtk_tooltips_set_tip(tt, rbutton, _("Italic"), NULL); - - gtk_box_pack_start (GTK_BOX (row), rbutton, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (tbl), "style-italic", rbutton); - g_signal_connect (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_style_toggled), gpointer (1)); - - gtk_toolbar_append_widget( tbl, row, "", ""); - - //spacer - gtk_toolbar_append_widget( tbl, gtk_vseparator_new(), "", "" ); - - // Text orientation - group = gtk_radio_button_new (NULL); - row = gtk_hbox_new (FALSE, 4); - g_object_set_data (G_OBJECT (tbl), "orientation-group", group); - - // horizontal - rbutton = group; - gtk_button_set_relief (GTK_BUTTON (rbutton), GTK_RELIEF_NONE); - gtk_container_add (GTK_CONTAINER (rbutton), - sp_icon_new (static_cast(secondarySize), INKSCAPE_ICON_FORMAT_TEXT_DIRECTION_HORIZONTAL)); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (rbutton), FALSE); - gtk_tooltips_set_tip(tt, rbutton, _("Horizontal text"), NULL); - - gtk_box_pack_start (GTK_BOX (row), rbutton, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (tbl), "orientation-horizontal", rbutton); - g_signal_connect (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_orientation_toggled), gpointer(0)); - - // vertical - rbutton = gtk_radio_button_new (gtk_radio_button_group (GTK_RADIO_BUTTON (group))); - gtk_button_set_relief (GTK_BUTTON (rbutton), GTK_RELIEF_NONE); - gtk_container_add (GTK_CONTAINER (rbutton), - sp_icon_new (static_cast(secondarySize), INKSCAPE_ICON_FORMAT_TEXT_DIRECTION_VERTICAL)); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (rbutton), FALSE); - gtk_tooltips_set_tip(tt, rbutton, _("Vertical text"), NULL); - - gtk_box_pack_start (GTK_BOX (row), rbutton, FALSE, FALSE, 0); - g_object_set_data (G_OBJECT (tbl), "orientation-vertical", rbutton); - g_signal_connect (G_OBJECT (rbutton), "toggled", G_CALLBACK (sp_text_toolbox_orientation_toggled), gpointer (1)); - gtk_toolbar_append_widget( tbl, row, "", "" ); + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("Justify"), + 1, _("Justify - Only flowed text"), + 2, GTK_STOCK_JUSTIFY_FILL, + -1 ); + EgeSelectOneAction* act = ege_select_one_action_new( "TextAlignAction", // Name + _("Alignment"), // Label + _("Text Alignment"), // Tooltip + NULL, // StockID + GTK_TREE_MODEL(model) ); // Model + g_object_set( act, "short_label", _("Align"), NULL ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + g_object_set_data( holder, "TextAlignAction", act ); - //watch selection - Inkscape::ConnectionPool* pool = Inkscape::ConnectionPool::new_connection_pool ("ISTextToolbox"); + ege_select_one_action_set_appearance( act, "full" ); + ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE ); + g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL ); + ege_select_one_action_set_icon_column( act, 2 ); + ege_select_one_action_set_icon_size( act, secondarySize ); + ege_select_one_action_set_tooltip_column( act, 1 ); + + gint mode = prefs->getInt("/tools/text/align_mode", 0); + ege_select_one_action_set_active( act, mode ); + g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_text_align_mode_changed), holder ); + } + + /* Orientation (Left to Right, Top to Bottom */ + { + GtkListStore* model = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING ); + + GtkTreeIter iter; + + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("Horizontal"), + 1, _("Horizontal Text"), + 2, INKSCAPE_ICON_FORMAT_TEXT_DIRECTION_HORIZONTAL, + -1 ); + + gtk_list_store_append( model, &iter ); + gtk_list_store_set( model, &iter, + 0, _("Vertical"), + 1, _("Vertical Text"), + 2, INKSCAPE_ICON_FORMAT_TEXT_DIRECTION_VERTICAL, + -1 ); + + EgeSelectOneAction* act = ege_select_one_action_new( "TextOrientationAction", // Name + _("Orientation"), // Label + _("Text Orientation"), // Tooltip + NULL, // StockID + GTK_TREE_MODEL(model) ); // Model + + g_object_set( act, "short_label", _("O:"), NULL ); + gtk_action_group_add_action( mainActions, GTK_ACTION(act) ); + g_object_set_data( holder, "TextOrientationAction", act ); + + ege_select_one_action_set_appearance( act, "full" ); + ege_select_one_action_set_radio_action_type( act, INK_RADIO_ACTION_TYPE ); + g_object_set( G_OBJECT(act), "icon-property", "iconId", NULL ); + ege_select_one_action_set_icon_column( act, 2 ); + ege_select_one_action_set_icon_size( act, secondarySize ); + ege_select_one_action_set_tooltip_column( act, 1 ); + + gint mode = prefs->getInt("/tools/text/orientation", 0); + ege_select_one_action_set_active( act, mode ); + g_signal_connect_after( G_OBJECT(act), "changed", G_CALLBACK(sp_text_orientation_mode_changed), holder ); + } + + /* Line height */ + { + // Drop down menu + gchar const* labels[] = {_("Smaller spacing"), 0, 0, 0, 0, _("Normal"), 0, 0, 0, 0, 0, _("Larger spacing")}; + gdouble values[] = { 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1,2, 1.3, 1.4, 1.5, 2.0}; + + EgeAdjustmentAction *eact = create_adjustment_action( + "TextLineHeightAction", /* name */ + _("Line Height"), /* label */ + _("Line:"), /* short label */ + _("Spacing between lines."), /* tooltip */ + "/tools/text/lineheight", /* path? */ + 0.0, /* default */ + GTK_WIDGET(desktop->canvas), /* focusTarget */ + NULL, /* unit selector */ + holder, /* dataKludge */ + FALSE, /* altx? */ + NULL, /* altx_mark? */ + 0.0, 10.0, 0.1, 1.0, /* lower, upper, step (arrow up/down), page up/down */ + labels, values, G_N_ELEMENTS(labels), /* drop down menu */ + sp_text_lineheight_value_changed, /* callback */ + 0.1, /* step (used?) */ + 2, /* digits to show */ + 1.0 /* factor (multiplies default) */ + ); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + g_object_set_data( holder, "TextLineHeightAction", eact ); + } + + /* Word spacing */ + { + // Drop down menu + gchar const* labels[] = {_("Negative spacing"), 0, 0, 0, _("Normal"), 0, 0, 0, 0, 0, 0, 0, _("Positive spacing")}; + gdouble values[] = {-2.0, -1.5, -1.0, -0.5, 0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0}; + + EgeAdjustmentAction *eact = create_adjustment_action( + "TextWordSpacingAction", /* name */ + _("Word spacing"), /* label */ + _("Word:"), /* short label */ + _("Spacing between words."), /* tooltip */ + "/tools/text/wordspacing", /* path? */ + 0.0, /* default */ + GTK_WIDGET(desktop->canvas), /* focusTarget */ + NULL, /* unit selector */ + holder, /* dataKludge */ + FALSE, /* altx? */ + NULL, /* altx_mark? */ + -100.0, 100.0, 1.0, 10.0, /* lower, upper, step (arrow up/down), page up/down */ + labels, values, G_N_ELEMENTS(labels), /* drop down menu */ + sp_text_wordspacing_value_changed, /* callback */ + 0.1, /* step (used?) */ + 2, /* digits to show */ + 1.0 /* factor (multiplies default) */ + ); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + g_object_set_data( holder, "TextWordSpacingAction", eact ); + } + + /* Letter spacing */ + { + // Drop down menu + gchar const* labels[] = {_("Negative spacing"), 0, 0, 0, _("Normal"), 0, 0, 0, 0, 0, 0, 0, _("Positive spacing")}; + gdouble values[] = {-2.0, -1.5, -1.0, -0.5, 0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0}; + + EgeAdjustmentAction *eact = create_adjustment_action( + "TextLetterSpacingAction", /* name */ + _("Letter spacing"), /* label */ + _("Letter:"), /* short label */ + _("Spacing between letters."), /* tooltip */ + "/tools/text/letterspacing", /* path? */ + 0.0, /* default */ + GTK_WIDGET(desktop->canvas), /* focusTarget */ + NULL, /* unit selector */ + holder, /* dataKludge */ + FALSE, /* altx? */ + NULL, /* altx_mark? */ + -100.0, 100.0, 1.0, 10.0, /* lower, upper, step (arrow up/down), page up/down */ + labels, values, G_N_ELEMENTS(labels), /* drop down menu */ + sp_text_letterspacing_value_changed, /* callback */ + 0.1, /* step (used?) */ + 2, /* digits to show */ + 1.0 /* factor (multiplies default) */ + ); + gtk_action_group_add_action( mainActions, GTK_ACTION(eact) ); + gtk_action_set_sensitive( GTK_ACTION(eact), TRUE ); + g_object_set_data( holder, "TextLetterSpacingAction", eact ); + } + + // Is this necessary to call? Shouldn't hurt. + sp_text_toolbox_selection_changed(sp_desktop_selection(desktop), holder); + + // Watch selection + Inkscape::ConnectionPool* pool = Inkscape::ConnectionPool::new_connection_pool ("ISTextToolboxGTK"); sigc::connection *c_selection_changed = new sigc::connection (sp_desktop_selection (desktop)->connectChanged - (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_changed), (GObject*)tbl))); + (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_changed), (GObject*)holder))); pool->add_connection ("selection-changed", c_selection_changed); sigc::connection *c_selection_modified = new sigc::connection (sp_desktop_selection (desktop)->connectModified - (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_modified), (GObject*)tbl))); + (sigc::bind (sigc::ptr_fun (sp_text_toolbox_selection_modified), (GObject*)holder))); pool->add_connection ("selection-modified", c_selection_modified); sigc::connection *c_subselection_changed = new sigc::connection (desktop->connectToolSubselectionChanged - (sigc::bind (sigc::ptr_fun (sp_text_toolbox_subselection_changed), (GObject*)tbl))); + (sigc::bind (sigc::ptr_fun (sp_text_toolbox_subselection_changed), (GObject*)holder))); pool->add_connection ("tool-subselection-changed", c_subselection_changed); - Inkscape::ConnectionPool::connect_destroy (G_OBJECT (tbl), pool); - - - gtk_widget_show_all( GTK_WIDGET(tbl) ); + Inkscape::ConnectionPool::connect_destroy (G_OBJECT (holder), pool); - return GTK_WIDGET(tbl); -} // end of sp_text_toolbox_new() + g_signal_connect( holder, "destroy", G_CALLBACK(purge_repr_listener), holder ); -}// namespace +} //######################### -- cgit v1.2.3 From 6b27688f633f9be6e75b3c88ec37d9414055a674 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Fri, 23 Apr 2010 22:14:51 +0200 Subject: Minor tweaks to text toolbar. (bzr r9366) --- src/widgets/toolbox.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 66f77a18d..826fabb06 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -488,8 +488,8 @@ static gchar const * ui_descr = " " " " " " - " " " " + " " " " " " " " @@ -7351,7 +7351,7 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions holder, /* dataKludge */ FALSE, /* altx? */ NULL, /* altx_mark? */ - 0.0, 10.0, 0.1, 1.0, /* lower, upper, step (arrow up/down), page up/down */ + 0.0, 10.0, 0.01, 0.10, /* lower, upper, step (arrow up/down), page up/down */ labels, values, G_N_ELEMENTS(labels), /* drop down menu */ sp_text_lineheight_value_changed, /* callback */ 0.1, /* step (used?) */ @@ -7381,7 +7381,7 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions holder, /* dataKludge */ FALSE, /* altx? */ NULL, /* altx_mark? */ - -100.0, 100.0, 1.0, 10.0, /* lower, upper, step (arrow up/down), page up/down */ + -100.0, 100.0, 0.01, 0.10, /* lower, upper, step (arrow up/down), page up/down */ labels, values, G_N_ELEMENTS(labels), /* drop down menu */ sp_text_wordspacing_value_changed, /* callback */ 0.1, /* step (used?) */ @@ -7411,7 +7411,7 @@ static void sp_text_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActions holder, /* dataKludge */ FALSE, /* altx? */ NULL, /* altx_mark? */ - -100.0, 100.0, 1.0, 10.0, /* lower, upper, step (arrow up/down), page up/down */ + -100.0, 100.0, 0.01, 0.10, /* lower, upper, step (arrow up/down), page up/down */ labels, values, G_N_ELEMENTS(labels), /* drop down menu */ sp_text_letterspacing_value_changed, /* callback */ 0.1, /* step (used?) */ -- cgit v1.2.3