From: Abhishek Sharma public Date: Wed, 11 Aug 2010 14:49:55 +0000 (+0530) Subject: XML Privatisation Stuff after a long time X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b50f3defe2c02de337fc2747ab4b683829363d75;p=inkscape.git XML Privatisation Stuff after a long time --- diff --git a/src/desktop-events.cpp b/src/desktop-events.cpp index 2046b9510..9e97aa432 100644 --- a/src/desktop-events.cpp +++ b/src/desktop-events.cpp @@ -75,7 +75,7 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge int wx, wy; SPDesktop *desktop = dtw->desktop; - Inkscape::XML::Node *repr = SP_OBJECT_REPR(desktop->namedview); + //Inkscape::XML::Node *repr = SP_OBJECT_REPR(desktop->namedview); gdk_window_get_pointer(GTK_WIDGET(dtw->canvas)->window, &wx, &wy, NULL); Geom::Point const event_win(wx, wy); @@ -92,8 +92,10 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge Geom::Point const event_dt(desktop->w2d(event_w)); // explicitly show guidelines; if I draw a guide, I want them on - sp_repr_set_boolean(repr, "showguides", TRUE); - sp_repr_set_boolean(repr, "inkscape:guide-bbox", TRUE); + /*sp_repr_set_boolean(repr, "showguides", TRUE); + sp_repr_set_boolean(repr, "inkscape:guide-bbox", TRUE);*/ + + desktop->namedview->setGuides(true); // calculate the normal of the guidelines when dragged from the edges of rulers. Geom::Point normal_bl_to_tr(-1.,1.); //bottomleft to topright @@ -183,7 +185,8 @@ static gint sp_dt_ruler_event(GtkWidget *widget, GdkEvent *event, SPDesktopWidge Inkscape::XML::Node *repr = xml_doc->createElement("sodipodi:guide"); sp_repr_set_point(repr, "orientation", normal); sp_repr_set_point(repr, "position", from_2geom(event_dt)); - SP_OBJECT_REPR(desktop->namedview)->appendChild(repr); + //SP_OBJECT_REPR(desktop->namedview)->appendChild(repr); + desktop->namedview->appendChild(repr); Inkscape::GC::release(repr); SPDocumentUndo::done(sp_desktop_document(desktop), SP_VERB_NONE, _("Create guide")); diff --git a/src/desktop-style.cpp b/src/desktop-style.cpp index 9a8725fac..049b5fcf8 100644 --- a/src/desktop-style.cpp +++ b/src/desktop-style.cpp @@ -103,7 +103,7 @@ sp_desktop_apply_css_recursive(SPObject *o, SPCSSAttr *css, bool skip_lines) || SP_IS_FLOWDIV(o) || SP_IS_FLOWPARA(o) || SP_IS_TEXTPATH(o)) - && !SP_OBJECT_REPR(o)->attribute("style")) + && /*!SP_OBJECT_REPR(o)->attribute("style")*/ !o->getAttribute("style")) && !(SP_IS_FLOWREGION(o) || SP_IS_FLOWREGIONEXCLUDE(o) || @@ -129,7 +129,8 @@ sp_desktop_apply_css_recursive(SPObject *o, SPCSSAttr *css, bool skip_lines) } } - sp_repr_css_change(SP_OBJECT_REPR(o), css_set, "style"); + //sp_repr_css_change(SP_OBJECT_REPR(o), css_set, "style"); + o->changeCSS(css_set,"style"); sp_repr_css_attr_unref(css_set); } diff --git a/src/desktop.cpp b/src/desktop.cpp index 3f9fc7806..e7ef2897e 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -970,10 +970,12 @@ void SPDesktop::applyCurrentOrToolStyle(SPObject *obj, Glib::ustring const &tool Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool(tool_path + "/usecurrent") && css_current) { - sp_repr_css_set(obj->getRepr(), css_current, "style"); + //sp_repr_css_set(obj->getRepr(), css_current, "style"); + obj->setCSS(css_current,"style"); } else { SPCSSAttr *css = prefs->getInheritedStyle(tool_path + "/style"); - sp_repr_css_set(obj->getRepr(), css, "style"); + //sp_repr_css_set(obj->getRepr(), css, "style"); + obj->setCSS(css,"style"); sp_repr_css_attr_unref(css); } if (css_current) { @@ -1432,8 +1434,9 @@ void SPDesktop::toggleGrids() } } else { //there is no grid present at the moment. add a rectangular grid and make it visible - Inkscape::XML::Node *repr = SP_OBJECT_REPR(namedview); - Inkscape::CanvasGrid::writeNewGridToRepr(repr, sp_desktop_document(this), Inkscape::GRID_RECTANGULAR); + //Inkscape::XML::Node *repr = SP_OBJECT_REPR(namedview); + //Inkscape::CanvasGrid::writeNewGridToRepr(repr, sp_desktop_document(this), Inkscape::GRID_RECTANGULAR); + namedview->writeNewGrid(sp_desktop_document(this), Inkscape::GRID_RECTANGULAR); showGrids(true); } } @@ -1451,9 +1454,11 @@ void SPDesktop::showGrids(bool show, bool dirty_document) void SPDesktop::toggleSnapGlobal() { - bool v = namedview->snap_manager.snapprefs.getSnapEnabledGlobally(); - Inkscape::XML::Node *repr = SP_OBJECT_REPR(namedview); - sp_repr_set_boolean(repr, "inkscape:snap-global", !v); + //bool v = namedview->snap_manager.snapprefs.getSnapEnabledGlobally(); + //Inkscape::XML::Node *repr = SP_OBJECT_REPR(namedview); + //sp_repr_set_boolean(repr, "inkscape:snap-global", !v); + bool v=namedview->getSnapGlobal(); + namedview->setSnapGlobal(!v); } //---------------------------------------------------------------------- diff --git a/src/document.cpp b/src/document.cpp index 6b72f0bb8..702c58d5d 100644 --- a/src/document.cpp +++ b/src/document.cpp @@ -627,18 +627,21 @@ Geom::Point SPDocument::getDimensions() * otherwise. Used for percentage margins. * \return the margin size in px, else 0.0 if anything is invalid. */ -static double getMarginLength(Inkscape::XML::Node * const nv_repr, - gchar const * const key, +//static double getMarginLength(/*Inkscape::XML::Node * const nv_repr*/ +/* gchar const * const key, SPUnit const * const margin_units, SPUnit const * const return_units, double const width, double const height, - bool const use_width) -{ - double value; - if (!sp_repr_get_double (nv_repr, key, &value)) { + bool const use_width)*/ +//{ + // double value; + /*if (!sp_repr_get_double (nv_repr, key, &value)) { return 0.0; - } + }*/ +/* if(!this->storeAsDouble(key,&value)) { + return 0.0; + } if (margin_units == &sp_unit_get_by_id (SP_UNIT_PERCENT)) { return (use_width)? width * value : height * value; } @@ -646,7 +649,7 @@ static double getMarginLength(Inkscape::XML::Node * const nv_repr, return 0.0; } return value; -} +}*/ /** * Given a Geom::Rect that may, for example, correspond to the bbox of an object, @@ -674,9 +677,10 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) SPNamedView *nv = sp_document_namedview(this, 0); if (with_margins && nv) { - Inkscape::XML::Node *nv_repr = SP_OBJECT_REPR (nv); - if (nv_repr != NULL) { - gchar const * const units_abbr = nv_repr->attribute("units"); + //Inkscape::XML::Node *nv_repr = SP_OBJECT_REPR (nv); + if (nv != NULL) { + //gchar const * const units_abbr = nv_repr->attribute("units"); + gchar const * const units_abbr = nv->getAttribute("units"); SPUnit const *margin_units = NULL; if (units_abbr != NULL) { margin_units = sp_unit_get_by_abbreviation(units_abbr); @@ -684,6 +688,7 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) if (margin_units == NULL) { margin_units = &px; } + /* margin_top = getMarginLength(nv_repr, "fit-margin-top", margin_units, &px, w, h, false); margin_left = getMarginLength(nv_repr, "fit-margin-left", @@ -691,7 +696,13 @@ void SPDocument::fitToRect(Geom::Rect const &rect, bool with_margins) margin_right = getMarginLength(nv_repr, "fit-margin-right", margin_units, &px, w, h, true); margin_bottom = getMarginLength(nv_repr, "fit-margin-bottom", - margin_units, &px, w, h, false); + margin_units, &px, w, h, false);*/ + margin_top = nv->getMarginLength("fit-margin-top",margin_units, &px, w, h, false); + margin_top = nv->getMarginLength("fit-margin-left",margin_units, &px, w, h, true); + margin_top = nv->getMarginLength("fit-margin-right",margin_units, &px, w, h, true); + margin_top = nv->getMarginLength("fit-margin-bottom",margin_units, &px, w, h, false); + + } } diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 7c93c5f07..f7123da47 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1751,7 +1751,7 @@ struct Forward { static Iterator next(Iterator i) { return SP_OBJECT_NEXT(i); } }; -struct Reverse { +struct ReverseSelect { typedef GSList *Iterator; static Iterator children(SPObject *o) { @@ -1830,7 +1830,7 @@ sp_selection_item_prev(SPDesktop *desktop) root = desktop->currentRoot(); } - SPItem *item=next_item_from_list(desktop, selection->itemList(), root, SP_CYCLING == SP_CYCLE_VISIBLE, inlayer, onlyvisible, onlysensitive); + SPItem *item=next_item_from_list(desktop, selection->itemList(), root, SP_CYCLING == SP_CYCLE_VISIBLE, inlayer, onlyvisible, onlysensitive); if (item) { selection->set(item, PREFS_SELECTION_LAYER_RECURSIVE == inlayer); diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index c4ce6355b..61685b321 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -726,6 +726,12 @@ void SPNamedView::show(SPDesktop *desktop) #define MIN_ONSCREEN_DISTANCE 50 +void SPNamedView::writeNewGrid(SPDocument *document,int gridtype) +{ + g_assert(this->getRepr() != NULL); + Inkscape::CanvasGrid::writeNewGridToRepr(this->getRepr(),document,static_cast(gridtype)); +} + /* * Restores window geometry from the document settings or defaults in prefs */ @@ -774,6 +780,17 @@ void sp_namedview_window_from_document(SPDesktop *desktop) } } +bool SPNamedView::getSnapGlobal() const +{ + return this->snap_manager.snapprefs.getSnapEnabledGlobally(); +} + +void SPNamedView::setSnapGlobal(bool v) +{ + g_assert(this->getRepr() != NULL); + sp_repr_set_boolean(this->getRepr(), "inkscape:snap-global", v); +} + void sp_namedview_update_layers_from_document (SPDesktop *desktop) { SPObject *layer = NULL; @@ -984,6 +1001,48 @@ SPNamedView *sp_document_namedview(SPDocument *document, const gchar *id) return (SPNamedView *) nv; } +void SPNamedView::setGuides(bool v) +{ + g_assert(this->getRepr() != NULL); + sp_repr_set_boolean(this->getRepr(), "showguides", v); + sp_repr_set_boolean(this->getRepr(), "inkscape:guide-bbox", v); + +} + +/** + * Gets page fitting margin information from the namedview node in the XML. + * \param nv_repr reference to this document's namedview + * \param key the same key used by the RegisteredScalarUnit in + * ui/widget/page-sizer.cpp + * \param margin_units units for the margin + * \param return_units units to return the result in + * \param width width in px (for percentage margins) + * \param height height in px (for percentage margins) + * \param use_width true if the this key is left or right margins, false + * otherwise. Used for percentage margins. + * \return the margin size in px, else 0.0 if anything is invalid. + */ +double SPNamedView::getMarginLength(gchar const * const key, + SPUnit const * const margin_units, + SPUnit const * const return_units, + double const width, + double const height, + bool const use_width) +{ + double value; + if(!this->storeAsDouble(key,&value)) { + return 0.0; + } + if (margin_units == &sp_unit_get_by_id (SP_UNIT_PERCENT)) { + return (use_width)? width * value : height * value; + } + if (!sp_convert_distance (&value, margin_units, return_units)) { + return 0.0; + } + return value; +} + + /** * Returns namedview's default metric. */ diff --git a/src/sp-namedview.h b/src/sp-namedview.h index 048096d8c..337a67deb 100644 --- a/src/sp-namedview.h +++ b/src/sp-namedview.h @@ -23,6 +23,8 @@ #include "sp-object-group.h" #include "sp-metric.h" #include "snap.h" +#include "display/canvas-grid.h" +#include "document.h" namespace Inkscape { class CanvasGrid; @@ -80,6 +82,14 @@ struct SPNamedView : public SPObjectGroup { void translateGuides(Geom::Translate const &translation); void scrollAllDesktops(double dx, double dy, bool is_scrolling); + void writeNewGrid(SPDocument *document,int gridtype); + bool getSnapGlobal() const; + void setSnapGlobal(bool v); + void setGuides(bool v); + + private: + double getMarginLength(gchar const * const key,SPUnit const * const margin_units,SPUnit const * const return_units,double const width,double const height,bool const use_width); + friend class SPDocument; }; struct SPNamedViewClass { diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 80f39db4a..88d24bffd 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -503,6 +503,18 @@ SPObject::appendChildRepr(Inkscape::XML::Node *repr) { } } +void SPObject::setCSS(SPCSSAttr *css, gchar const *attr) +{ + g_assert(this->getRepr() != NULL); + sp_repr_css_set(this->getRepr(), css, attr); +} + +void SPObject::changeCSS(SPCSSAttr *css, gchar const *attr) +{ + g_assert(this->getRepr() != NULL); + sp_repr_css_change(this->getRepr(), css, attr); +} + /** * Retrieves the children as a GSList object, optionally ref'ing the children * in the process, if add_ref is specified. @@ -1524,6 +1536,12 @@ SPObject::removeAttribute(gchar const *key, SPException *ex) getRepr()->setAttribute(key, NULL, false); } +bool SPObject::storeAsDouble( gchar const *key, double *val ) const +{ + g_assert(this->getRepr()!= NULL); + return sp_repr_get_double(((Inkscape::XML::Node *)(this->getRepr())),key,val); +} + /* Helper */ gchar * diff --git a/src/sp-object.h b/src/sp-object.h index 4856bdd06..b7b3f9cc4 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -70,6 +70,7 @@ class SPObjectClass; #include "forward.h" #include "version.h" #include "util/forward-pointer-iterator.h" +#include "desktop-style.h" namespace Inkscape { namespace XML { @@ -540,6 +541,9 @@ public: void removeAttribute(gchar const *key, SPException *ex=0); gchar const *getStyleProperty(gchar const *key, gchar const *def) const; SPObject *prev(); + void setCSS(SPCSSAttr *css, gchar const *attr); + void changeCSS(SPCSSAttr *css, gchar const *attr); + bool storeAsDouble( gchar const *key, double *val ) const; private: // Private member functions used in the definitions of setTitle(),