Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / document.h
index 4f5f045c5566fb5819fcb59a5898740637b844a3..82c874cb73678f284b2e62e67dad2d7efdd93e9e 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef __SP_DOCUMENT_H__
-#define __SP_DOCUMENT_H__
+#ifndef SEEN_SP_DOCUMENT_H
+#define SEEN_SP_DOCUMENT_H
 
 /** \file
  * SPDocument: Typed SVG document implementation
@@ -7,6 +7,8 @@
 /* Authors:
  *   Lauris Kaplinski <lauris@kaplinski.com>
  *   MenTaLguY <mental@rydia.net>
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2004-2005 MenTaLguY
  * Copyright (C) 1999-2002 Lauris Kaplinski
@@ -28,6 +30,7 @@
 #include "gc-anchored.h"
 #include <glibmm/ustring.h>
 #include "verbs.h"
+#include "document-undo.h"
 #include <vector>
 #include <set>
 
@@ -64,10 +67,11 @@ namespace Proj {
 class SPDocumentPrivate;
 
 /// Typed SVG document implementation.
-struct SPDocument : public Inkscape::GC::Managed<>,
+class SPDocument : public Inkscape::GC::Managed<>,
                     public Inkscape::GC::Finalized,
                     public Inkscape::GC::Anchored
 {
+public:
     typedef sigc::signal<void, SPObject *> IDChangedSignal;
     typedef sigc::signal<void> ResourcesChangedSignal;
     typedef sigc::signal<void, guint> ModifiedSignal;
@@ -89,10 +93,13 @@ struct SPDocument : public Inkscape::GC::Managed<>,
     SPObject *root;             ///< Our SPRoot
     CRCascade *style_cascade;
 
+protected:
     gchar *uri;   ///< A filename (not a URI yet), or NULL
     gchar *base;  ///< To be used for resolving relative hrefs.
     gchar *name;  ///< basename(uri) or other human-readable label for the document.
 
+public:
+
     SPDocumentPrivate *priv;
 
     /// Last action key
@@ -113,6 +120,27 @@ struct SPDocument : public Inkscape::GC::Managed<>,
 
     bool oldSignalsConnected;
 
+    /** Returns our SPRoot */
+    SPObject *getRoot() { return root; }
+
+    Inkscape::XML::Node *getReprRoot() { return rroot; }
+
+    /** Our Inkscape::XML::Document. */
+    Inkscape::XML::Document *getReprDoc() { return rdoc; }
+    Inkscape::XML::Document const *getReprDoc() const { return rdoc; }
+
+    /** A filename (not a URI yet), or NULL */
+    gchar const *getURI() const { return uri; }
+    void setUri(gchar const *uri);
+
+    /** To be used for resolving relative hrefs. */
+    gchar const *getBase() const { return base; };
+    void setBase( gchar const* base );
+
+    /** basename(uri) or other human-readable label for the document. */
+    gchar const* getName() const { return name; }
+
+
     void setCurrentPersp3D(Persp3D * const persp);
     inline void setCurrentPersp3DImpl(Persp3DImpl * const persp_impl) { current_persp3d_impl = persp_impl; }
     /*
@@ -121,28 +149,28 @@ struct SPDocument : public Inkscape::GC::Managed<>,
      */
     Persp3D * getCurrentPersp3D();
     Persp3DImpl * getCurrentPersp3DImpl();
-    void getPerspectivesInDefs(std::vector<Persp3D*> &list);
-    unsigned int numPerspectivesInDefs() {
+
+    void getPerspectivesInDefs(std::vector<Persp3D*> &list) const;
+
+    unsigned int numPerspectivesInDefs() const {
         std::vector<Persp3D*> list;
         getPerspectivesInDefs(list);
         return list.size();
     }
 
-    //void initialize_current_persp3d();
-
     sigc::connection connectModified(ModifiedSignal::slot_type slot);
     sigc::connection connectURISet(URISetSignal::slot_type slot);
     sigc::connection connectResized(ResizedSignal::slot_type slot);
-sigc::connection connectCommit(CommitSignal::slot_type slot);
+    sigc::connection connectCommit(CommitSignal::slot_type slot);
 
     void bindObjectToId(gchar const *id, SPObject *object);
-    SPObject *getObjectById(gchar const *id);
+    SPObject *getObjectById(gchar const *id) const;
     sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
 
     void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
-    SPObject *getObjectByRepr(Inkscape::XML::Node *repr);
+    SPObject *getObjectByRepr(Inkscape::XML::Node *repr) const;
 
-    Glib::ustring getLanguage();
+    Glib::ustring getLanguage() const;
 
     void queueForOrphanCollection(SPObject *object);
     void collectOrphans();
@@ -180,83 +208,49 @@ public:
     sigc::connection _selection_changed_connection;
     sigc::connection _desktop_activated_connection;
 
-    void fitToRect(Geom::Rect const &rect, bool with_margins = false);
-};
-
-SPDocument *sp_document_new(const gchar *uri, unsigned int keepalive, bool make_new = false);
-SPDocument *sp_document_new_from_mem(const gchar *buffer, gint length, unsigned int keepalive);
-
-SPDocument *sp_document_ref(SPDocument *doc);
-SPDocument *sp_document_unref(SPDocument *doc);
-
-
-SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
+    sigc::connection connectResourcesChanged(const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
 
-/*
- * Access methods
- */
+    void fitToRect(Geom::Rect const &rect, bool with_margins = false);
+    static SPDocument *createNewDoc(const gchar *uri, unsigned int keepalive, bool make_new = false);
+    static SPDocument *createNewDocFromMem(const gchar *buffer, gint length, unsigned int keepalive);
 
-#define sp_document_repr_doc(d) (d->rdoc)
-#define sp_document_repr_root(d) (d->rroot)
-#define sp_document_root(d) (d->root)
-#define SP_DOCUMENT_ROOT(d) (d->root)
+    /**
+     * Returns the bottommost item from the list which is at the point, or NULL if none.
+     */
+    static SPItem *getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, const GSList *list, Geom::Point const p, bool take_insensitive = false);
+
+    // ToDo - Merge createDoc with createNewDoc
+    static SPDocument *createDoc(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
+
+    SPDocument *doRef();
+    SPDocument *doUnref();
+    gdouble getWidth() const;
+    gdouble getHeight() const;
+    Geom::Point getDimensions() const;
+    void setWidth(gdouble width, const SPUnit *unit);
+    void setHeight(gdouble height, const SPUnit *unit);
+    void requestModified();
+    gint ensureUpToDate();
+    bool addResource(const gchar *key, SPObject *object);
+    bool removeResource(const gchar *key, SPObject *object);
+    const GSList *getResourceList(const gchar *key) const;
+    GSList *getItemsInBox(unsigned int dkey, Geom::Rect const &box) const;
+    GSList *getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const;
+    SPItem *getItemAtPoint(unsigned int key, Geom::Point const p, gboolean into_groups, SPItem *upto = NULL) const;
+    GSList *getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points) const;
+    SPItem *getGroupAtPoint(unsigned int key,  Geom::Point const p) const;
+
+    void changeUriAndHrefs(gchar const *uri);
+    void emitResizedSignal(gdouble width, gdouble height);
+       
+    unsigned int vacuumDocument();
 
-gdouble sp_document_width(SPDocument *document);
-gdouble sp_document_height(SPDocument *document);
-Geom::Point sp_document_dimensions(SPDocument *document);
+private:
+    void do_change_uri(gchar const *const filename, bool const rebase);
+};
 
 struct SPUnit;
 
-void sp_document_set_width(SPDocument *document, gdouble width, const SPUnit *unit);
-void sp_document_set_height(SPDocument *document, gdouble height, const SPUnit *unit);
-
-#define SP_DOCUMENT_URI(d)  (d->uri)
-#define SP_DOCUMENT_NAME(d) (d->name)
-#define SP_DOCUMENT_BASE(d) (d->base)
-
-/*
- * Dictionary
- */
-
-/*
- * Undo & redo
- */
-
-void sp_document_set_undo_sensitive(SPDocument *document, bool sensitive);
-bool sp_document_get_undo_sensitive(SPDocument const *document);
-
-void sp_document_clear_undo(SPDocument *document);
-void sp_document_clear_redo(SPDocument *document);
-
-void sp_document_child_added(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
-void sp_document_child_removed(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
-void sp_document_attr_changed(SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
-void sp_document_content_changed(SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
-void sp_document_order_changed(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
-
-/* Object modification root handler */
-void sp_document_request_modified(SPDocument *doc);
-gint sp_document_ensure_up_to_date(SPDocument *doc);
-
-/* Save all previous actions to stack, as one undo step */
-void sp_document_done(SPDocument *document, unsigned int event_type, Glib::ustring event_description);
-void sp_document_maybe_done(SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
-void sp_document_reset_key(Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
-
-/* Cancel (and revert) current unsaved actions */
-void sp_document_cancel(SPDocument *document);
-
-/* Undo and redo */
-gboolean sp_document_undo(SPDocument *document);
-gboolean sp_document_redo(SPDocument *document);
-
-/* Resource management */
-gboolean sp_document_add_resource(SPDocument *document, const gchar *key, SPObject *object);
-gboolean sp_document_remove_resource(SPDocument *document, const gchar *key, SPObject *object);
-const GSList *sp_document_get_resource_list(SPDocument *document, const gchar *key);
-sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
-
-
 /*
  * Ideas: How to overcome style invalidation nightmare
  *
@@ -271,26 +265,7 @@ sigc::connection sp_document_resources_changed_connect(SPDocument *document, con
  *
  */
 
-/*
- * Misc
- */
-
-GSList *sp_document_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
-GSList *sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
-SPItem *sp_document_item_from_list_at_point_bottom(unsigned int dkey, SPGroup *group, const GSList *list, Geom::Point const p, bool take_insensitive = false);
-SPItem *sp_document_item_at_point  (SPDocument *document, unsigned int key, Geom::Point const p, gboolean into_groups, SPItem *upto = NULL);
-GSList *sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<Geom::Point> points);
-SPItem *sp_document_group_at_point (SPDocument *document, unsigned int key,  Geom::Point const p);
-
-void sp_document_set_uri(SPDocument *document, gchar const *uri);
-void sp_document_change_uri_and_hrefs(SPDocument *document, gchar const *uri);
-
-void sp_document_resized_signal_emit(SPDocument *doc, gdouble width, gdouble height);
-
-unsigned int vacuum_document(SPDocument *document);
-
-
-#endif
+#endif // SEEN_SP_DOCUMENT_H
 
 /*
   Local Variables: