Code

A simple layout document as to what, why and how is cppification.
[inkscape.git] / src / desktop.cpp
index 204807e983ad0e39481c843f13be6961686af131..e7ef2897e9e22fa57de4e9c1c0b233de749e3e46 100644 (file)
@@ -90,6 +90,7 @@
 #include "display/canvas-grid.h"
 #include "widgets/desktop-widget.h"
 #include "box3d-context.h"
+#include "desktop-style.h"
 
 // TODO those includes are only for node tool quick zoom. Remove them after fixing it.
 #include "ui/tool/node-tool.h"
@@ -185,7 +186,7 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas, Inkscape::UI::View::EditWid
 
     SPDocument *document = SP_OBJECT_DOCUMENT (namedview);
     /* Kill flicker */
-    sp_document_ensure_up_to_date (document);
+    document->ensure_up_to_date ();
 
     /* Setup Dialog Manager */
     _dlg_mgr = &Inkscape::UI::Dialog::DialogManager::getInstance();
@@ -255,7 +256,7 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas, Inkscape::UI::View::EditWid
     // display rect and zoom are now handled in sp_desktop_widget_realize()
 
     Geom::Rect const d(Geom::Point(0.0, 0.0),
-                       Geom::Point(sp_document_width(document), sp_document_height(document)));
+                       Geom::Point(document->getWidth(), document->getHeight()));
 
     SP_CTRLRECT(page)->setRectangle(d);
     SP_CTRLRECT(page_border)->setRectangle(d);
@@ -272,7 +273,7 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas, Inkscape::UI::View::EditWid
 
 
     /* Connect event for page resize */
-    _doc2dt[5] = sp_document_height (document);
+    _doc2dt[5] = document->getHeight ();
     sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (drawing), _doc2dt);
 
     _modified_connection = namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&_namedview_modified), this));
@@ -684,7 +685,7 @@ SPItem *
 SPDesktop::item_from_list_at_point_bottom (const GSList *list, Geom::Point const p) const
 {
     g_return_val_if_fail (doc() != NULL, NULL);
-    return sp_document_item_from_list_at_point_bottom (dkey, SP_GROUP (doc()->root), list, p);
+    return SPDocument::item_from_list_at_point_bottom (dkey, SP_GROUP (doc()->root), list, p);
 }
 
 /**
@@ -694,7 +695,7 @@ SPItem *
 SPDesktop::item_at_point (Geom::Point const p, bool into_groups, SPItem *upto) const
 {
     g_return_val_if_fail (doc() != NULL, NULL);
-    return sp_document_item_at_point (doc(), dkey, p, into_groups, upto);
+    return doc()->item_at_point ( dkey, p, into_groups, upto);
 }
 
 /**
@@ -704,7 +705,7 @@ SPItem *
 SPDesktop::group_at_point (Geom::Point const p) const
 {
     g_return_val_if_fail (doc() != NULL, NULL);
-    return sp_document_group_at_point (doc(), dkey, p);
+    return doc()->group_at_point (dkey, p);
 }
 
 /**
@@ -960,6 +961,29 @@ SPDesktop::zoom_absolute_keep_point (double cx, double cy, double px, double py,
                      0.0);
 }
 
+/**
+  * Apply the desktop's current style or the tool style to the object.
+  */
+void SPDesktop::applyCurrentOrToolStyle(SPObject *obj, Glib::ustring const &tool_path, bool with_text)
+{
+       SPCSSAttr *css_current = sp_desktop_get_style(this, with_text);
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+
+    if (prefs->getBool(tool_path + "/usecurrent") && css_current) {
+        //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");
+               obj->setCSS(css,"style");
+        sp_repr_css_attr_unref(css);
+    }
+    if (css_current) {
+        sp_repr_css_attr_unref(css_current);
+    }
+
+}
+
 /**
  * Zoom to center with absolute zoom factor.
  */
@@ -1014,7 +1038,7 @@ void
 SPDesktop::zoom_page()
 {
     Geom::Rect d(Geom::Point(0, 0),
-                 Geom::Point(sp_document_width(doc()), sp_document_height(doc())));
+                 Geom::Point(doc()->getWidth(), doc()->getHeight()));
 
     if (d.minExtent() < 1.0) {
         return;
@@ -1031,12 +1055,12 @@ SPDesktop::zoom_page_width()
 {
     Geom::Rect const a = get_display_area();
 
-    if (sp_document_width(doc()) < 1.0) {
+    if (doc()->getWidth() < 1.0) {
         return;
     }
 
     Geom::Rect d(Geom::Point(0, a.midpoint()[Geom::Y]),
-                 Geom::Point(sp_document_width(doc()), a.midpoint()[Geom::Y]));
+                 Geom::Point(doc()->getWidth(), a.midpoint()[Geom::Y]));
 
     set_display_area(d, 10);
 }
@@ -1410,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);
     }
 }
@@ -1429,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);
 }
 
 //----------------------------------------------------------------------