Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / desktop.cpp
index e7ef2897e9e22fa57de4e9c1c0b233de749e3e46..0b17fb385aead21accff281c1d3cc646cdf92955 100644 (file)
@@ -1,5 +1,3 @@
-#define __SP_DESKTOP_C__
-
 /** \file
  * Editable view implementation
  *
@@ -10,6 +8,8 @@
  *   Ralf Stephan <ralf@ark.in-berlin.de>
  *   John Bintz <jcoswell@coswellproductions.org>
  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2007 Jon A. Cruz
  * Copyright (C) 2006-2008 Johan Engelen
@@ -186,12 +186,12 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas, Inkscape::UI::View::EditWid
 
     SPDocument *document = SP_OBJECT_DOCUMENT (namedview);
     /* Kill flicker */
-    document->ensure_up_to_date ();
+    document->ensureUpToDate();
 
     /* Setup Dialog Manager */
     _dlg_mgr = &Inkscape::UI::Dialog::DialogManager::getInstance();
 
-    dkey = SPItem::display_key_new (1);
+    dkey = SPItem::display_key_new(1);
 
     /* Connect document */
     setDocument (document);
@@ -273,12 +273,12 @@ SPDesktop::init (SPNamedView *nv, SPCanvas *aCanvas, Inkscape::UI::View::EditWid
 
 
     /* Connect event for page resize */
-    _doc2dt[5] = document->getHeight ();
+    _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));
 
-    NRArenaItem *ai = SP_ITEM (sp_document_root (document))->invoke_show (
+    NRArenaItem *ai = SP_ITEM(document->getRoot())->invoke_show(
             SP_CANVAS_ARENA (drawing)->arena,
             dkey,
             SP_ITEM_SHOW_DISPLAY);
@@ -395,7 +395,7 @@ void SPDesktop::destroy()
     }
 
     if (drawing) {
-        SP_ITEM (sp_document_root (doc()))->invoke_hide (dkey);
+        SP_ITEM(doc()->getRoot())->invoke_hide(dkey);
         drawing = NULL;
     }
 
@@ -451,7 +451,7 @@ void SPDesktop::_setDisplayMode(Inkscape::RenderMode mode) {
     canvas->rendermode = mode;
     _display_mode = mode;
     sp_canvas_item_affine_absolute (SP_CANVAS_ITEM (main), _d2w); // redraw
-    _widget->setTitle(SP_DOCUMENT_NAME(sp_desktop_document(this)));
+    _widget->setTitle( sp_desktop_document(this)->getName() );
 }
 
 void SPDesktop::displayModeToggle() {
@@ -463,9 +463,9 @@ void SPDesktop::displayModeToggle() {
         _setDisplayMode(Inkscape::RENDERMODE_OUTLINE);
         break;
     case Inkscape::RENDERMODE_OUTLINE:
-        _setDisplayMode(Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW);
+        _setDisplayMode(Inkscape::RENDERMODE_NORMAL);
         break;
-    case Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW:
+//    case Inkscape::RENDERMODE_PRINT_COLORS_PREVIEW:
     default:
         _setDisplayMode(Inkscape::RENDERMODE_NORMAL);
     }
@@ -495,7 +495,7 @@ SPObject *SPDesktop::currentLayer() const
 void SPDesktop::setCurrentLayer(SPObject *object) {
     g_return_if_fail(SP_IS_GROUP(object));
     g_return_if_fail( currentRoot() == object || (currentRoot() && currentRoot()->isAncestorOf(object)) );
-    // printf("Set Layer to ID: %s\n", SP_OBJECT_ID(object));
+    // printf("Set Layer to ID: %s\n", object->getId());
     _layer_hierarchy->setBottom(object);
 }
 
@@ -637,9 +637,15 @@ SPDesktop::set_event_context (GtkType type, const gchar *config)
         event_context = next;
     }
 
+    // The event_context will be null. This means that it will be impossible
+    // to process any event invoked by the lines below. See for example bug
+    // LP #622350. Cutting and undoing again in the node tool resets the event
+    // context to the node tool. In this bug the line bellow invokes GDK_LEAVE_NOTIFY
+    // events which cannot be handled and must be discarded.
     ec = sp_event_context_new (type, this, config, SP_EVENT_CONTEXT_STATIC);
     ec->next = event_context;
     event_context = ec;
+    // Now the event_context has been set again and we can process all events again
     sp_event_context_activate (ec);
     _event_context_changed_signal.emit (this, ec);
 }
@@ -679,33 +685,30 @@ SPDesktop::set_coordinate_status (Geom::Point p) {
 }
 
 /**
- * \see sp_document_item_from_list_at_point_bottom()
+ * \see SPDocument::getItemFromListAtPointBottom()
  */
-SPItem *
-SPDesktop::item_from_list_at_point_bottom (const GSList *list, Geom::Point const p) const
+SPItem *SPDesktop::getItemFromListAtPointBottom(const GSList *list, Geom::Point const p) const
 {
     g_return_val_if_fail (doc() != NULL, NULL);
-    return SPDocument::item_from_list_at_point_bottom (dkey, SP_GROUP (doc()->root), list, p);
+    return SPDocument::getItemFromListAtPointBottom(dkey, SP_GROUP (doc()->root), list, p);
 }
 
 /**
- * \see sp_document_item_at_point()
+ * \see SPDocument::getItemAtPoint()
  */
-SPItem *
-SPDesktop::item_at_point (Geom::Point const p, bool into_groups, SPItem *upto) const
+SPItem *SPDesktop::getItemAtPoint(Geom::Point const p, bool into_groups, SPItem *upto) const
 {
     g_return_val_if_fail (doc() != NULL, NULL);
-    return doc()->item_at_point ( dkey, p, into_groups, upto);
+    return doc()->getItemAtPoint( dkey, p, into_groups, upto);
 }
 
 /**
- * \see sp_document_group_at_point()
+ * \see SPDocument::getGroupAtPoint()
  */
-SPItem *
-SPDesktop::group_at_point (Geom::Point const p) const
+SPItem *SPDesktop::getGroupAtPoint(Geom::Point const p) const
 {
     g_return_val_if_fail (doc() != NULL, NULL);
-    return doc()->group_at_point (dkey, p);
+    return doc()->getGroupAtPoint(dkey, p);
 }
 
 /**
@@ -966,22 +969,19 @@ SPDesktop::zoom_absolute_keep_point (double cx, double cy, double px, double py,
   */
 void SPDesktop::applyCurrentOrToolStyle(SPObject *obj, Glib::ustring const &tool_path, bool with_text)
 {
-       SPCSSAttr *css_current = sp_desktop_get_style(this, 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");
+        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");
+        obj->setCSS(css,"style");
         sp_repr_css_attr_unref(css);
     }
     if (css_current) {
         sp_repr_css_attr_unref(css_current);
     }
-
 }
 
 /**
@@ -1096,7 +1096,7 @@ void
 SPDesktop::zoom_drawing()
 {
     g_return_if_fail (doc() != NULL);
-    SPItem *docitem = SP_ITEM (sp_document_root (doc()));
+    SPItem *docitem = SP_ITEM(doc()->getRoot());
     g_return_if_fail (docitem != NULL);
 
     Geom::OptRect d = docitem->getBboxDesktop();
@@ -1391,7 +1391,7 @@ SPDesktop::emitToolSubselectionChanged(gpointer data)
 void
 SPDesktop::updateNow()
 {
-  sp_canvas_update_now(canvas);
+    sp_canvas_update_now(canvas);
 }
 
 void
@@ -1434,9 +1434,7 @@ 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);
-               namedview->writeNewGrid(sp_desktop_document(this), Inkscape::GRID_RECTANGULAR);
+        namedview->writeNewGrid(sp_desktop_document(this), Inkscape::GRID_RECTANGULAR);
         showGrids(true);
     }
 }
@@ -1454,11 +1452,8 @@ 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->getSnapGlobal();
-       namedview->setSnapGlobal(!v);
+    bool v = namedview->getSnapGlobal();
+    namedview->setSnapGlobal(!v);
 }
 
 //----------------------------------------------------------------------
@@ -1501,7 +1496,7 @@ SPDesktop::setDocument (SPDocument *doc)
 {
     if (this->doc() && doc) {
         namedview->hide(this);
-        SP_ITEM (sp_document_root (this->doc()))->invoke_hide (dkey);
+        SP_ITEM(this->doc()->getRoot())->invoke_hide(dkey);
     }
 
     if (_layer_hierarchy) {
@@ -1512,7 +1507,7 @@ SPDesktop::setDocument (SPDocument *doc)
     _layer_hierarchy->connectAdded(sigc::bind(sigc::ptr_fun(_layer_activated), this));
     _layer_hierarchy->connectRemoved(sigc::bind(sigc::ptr_fun(_layer_deactivated), this));
     _layer_hierarchy->connectChanged(sigc::bind(sigc::ptr_fun(_layer_hierarchy_changed), this));
-    _layer_hierarchy->setTop(SP_DOCUMENT_ROOT(doc));
+    _layer_hierarchy->setTop(doc->getRoot());
 
     /* setup EventLog */
     event_log = new Inkscape::EventLog(doc);
@@ -1532,7 +1527,7 @@ SPDesktop::setDocument (SPDocument *doc)
         _modified_connection = namedview->connectModified(sigc::bind<2>(sigc::ptr_fun(&_namedview_modified), this));
         number = namedview->getViewCount();
 
-        ai = SP_ITEM (sp_document_root (doc))->invoke_show (
+        ai = SP_ITEM(doc->getRoot())->invoke_show(
                 SP_CANVAS_ARENA (drawing)->arena,
                 dkey,
                 SP_ITEM_SHOW_DISPLAY);
@@ -1837,4 +1832,4 @@ Geom::Point SPDesktop::dt2doc(Geom::Point const &p) const
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :