Code

XML Privatisation Stuff after a long time
authorAbhishek Sharma public <spyzerdotabhishek0at-signgmaildotcom>
Wed, 11 Aug 2010 14:49:55 +0000 (20:19 +0530)
committerAbhishek Sharma public <spyzerdotabhishek0at-signgmaildotcom>
Wed, 11 Aug 2010 14:49:55 +0000 (20:19 +0530)
src/desktop-events.cpp
src/desktop-style.cpp
src/desktop.cpp
src/document.cpp
src/selection-chemistry.cpp
src/sp-namedview.cpp
src/sp-namedview.h
src/sp-object.cpp
src/sp-object.h

index 2046b95101aaca86b3c43e837fc9ec9673ded798..9e97aa432fd1ebe4830f841ba7267de837c33832 100644 (file)
@@ -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"));
index 9a8725fac7054ebc7bb5c8934ef95020e0a3540c..049b5fcf80604bab290882db2933b793a83bbd85 100644 (file)
@@ -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);
     }
index 3f9fc7806a0b98a9a97e65f057d3181e27695aa6..e7ef2897e9e22fa57de4e9c1c0b233de749e3e46 100644 (file)
@@ -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);
 }
 
 //----------------------------------------------------------------------
index 6b72f0bb802faed78125f390ae6558c7860f0571..702c58d5dc871025201e4792edcfe8eb3042252b 100644 (file)
@@ -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);
+
+
         }
     }
     
index 7c93c5f07beed800b671dc272465d09c7a5b71ce..f7123da47833d4dac45e44d105183b55d1851ad4 100644 (file)
@@ -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<Reverse>(desktop, selection->itemList(), root, SP_CYCLING == SP_CYCLE_VISIBLE, inlayer, onlyvisible, onlysensitive);
+    SPItem *item=next_item_from_list<ReverseSelect>(desktop, selection->itemList(), root, SP_CYCLING == SP_CYCLE_VISIBLE, inlayer, onlyvisible, onlysensitive);
 
     if (item) {
         selection->set(item, PREFS_SELECTION_LAYER_RECURSIVE == inlayer);
index c4ce6355b320c1ace8d770b0fd77b2305887fd25..61685b3217e2b73fc6b93779f35b12b511c52950 100644 (file)
@@ -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<Inkscape::GridType>(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.
  */
index 048096d8c0096e569761f332afb9f0d51be03425..337a67deb10fd557ff23fa9ff8c25b3071e9b2ce 100644 (file)
@@ -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 {
index 80f39db4ac9051f5fe223a71ad2ff8a8fa2ec06f..88d24bffd08753216cf44ca6d762131f084e19d2 100644 (file)
@@ -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 *
index 4856bdd06757fccb4e0937da7621f89778eb79ae..b7b3f9cc48df57dadd0ce5e20a1673baa35b375d 100644 (file)
@@ -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(),