Code

Fix change in revision 9947 to be consistent with rest of the codebase.
[inkscape.git] / src / document.h
1 #ifndef SEEN_SP_DOCUMENT_H
2 #define SEEN_SP_DOCUMENT_H
4 /** \file
5  * SPDocument: Typed SVG document implementation
6  */
7 /* Authors:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *   MenTaLguY <mental@rydia.net>
10  *   Jon A. Cruz <jon@joncruz.org>
11  *   Abhishek Sharma
12  *
13  * Copyright (C) 2004-2005 MenTaLguY
14  * Copyright (C) 1999-2002 Lauris Kaplinski
15  * Copyright (C) 2000-2001 Ximian, Inc.
16  *
17  * Released under GNU GPL, read the file 'COPYING' for more information
18  */
20 #include <glib-object.h>
21 #include <gtk/gtksignal.h>
22 #include <sigc++/sigc++.h>
23 #include <sigc++/class_slot.h>
25 #include "libcroco/cr-cascade.h"
26 #include <2geom/forward.h>
28 #include "gc-managed.h"
29 #include "gc-finalized.h"
30 #include "gc-anchored.h"
31 #include <glibmm/ustring.h>
32 #include "verbs.h"
33 #include "document-undo.h"
34 #include <vector>
35 #include <set>
37 namespace Avoid {
38 class Router;
39 }
41 struct NRRect;
42 struct SPDesktop;
43 struct SPItem;
44 struct SPObject;
45 struct SPGroup;
47 namespace Inkscape {
48     struct Application;
49     class Selection; 
50     class UndoStackObserver;
51     class EventLog;
52     class ProfileManager;
53     namespace XML {
54         class Document;
55         class Node;
56     }
57 }
59 class SP3DBox;
60 class Persp3D;
61 class Persp3DImpl;
63 namespace Proj {
64     class TransfMat3x4;
65 }
67 class SPDocumentPrivate;
69 /// Typed SVG document implementation.
70 class SPDocument : public Inkscape::GC::Managed<>,
71                     public Inkscape::GC::Finalized,
72                     public Inkscape::GC::Anchored
73 {
74 public:
75     typedef sigc::signal<void, SPObject *> IDChangedSignal;
76     typedef sigc::signal<void> ResourcesChangedSignal;
77     typedef sigc::signal<void, guint> ModifiedSignal;
78     typedef sigc::signal<void, gchar const *> URISetSignal;
79     typedef sigc::signal<void, double, double> ResizedSignal;
80     typedef sigc::signal<void> ReconstructionStart;
81     typedef sigc::signal<void> ReconstructionFinish;
82     typedef sigc::signal<void> CommitSignal;
84     SPDocument();
85     virtual ~SPDocument();
87     unsigned int keepalive : 1;
88     unsigned int virgin    : 1; ///< Has the document never been touched?
89     unsigned int modified_since_save : 1;
91     Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
92     Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document
93     SPObject *root;             ///< Our SPRoot
94     CRCascade *style_cascade;
96 protected:
97     gchar *uri;   ///< A filename (not a URI yet), or NULL
98     gchar *base;  ///< To be used for resolving relative hrefs.
99     gchar *name;  ///< basename(uri) or other human-readable label for the document.
101 public:
103     SPDocumentPrivate *priv;
105     /// Last action key
106     Glib::ustring actionkey;
108     /// Handler ID
109     guint modified_id;
110     
111     /// Connector rerouting handler ID
112     guint rerouting_handler_id;
114     Inkscape::ProfileManager* profileManager;
116     // Instance of the connector router
117     Avoid::Router *router;
119     GSList *_collection_queue;
121     bool oldSignalsConnected;
123     /** Returns our SPRoot */
124     SPObject *getRoot() { return root; }
126     Inkscape::XML::Node *getReprRoot() { return rroot; }
128     /** Our Inkscape::XML::Document. */
129     Inkscape::XML::Document *getReprDoc() { return rdoc; }
130     Inkscape::XML::Document const *getReprDoc() const { return rdoc; }
132     /** A filename (not a URI yet), or NULL */
133     gchar const *getURI() const { return uri; }
134     void setUri(gchar const *uri);
136     /** To be used for resolving relative hrefs. */
137     gchar const *getBase() const { return base; };
138     void setBase( gchar const* base );
140     /** basename(uri) or other human-readable label for the document. */
141     gchar const* getName() const { return name; }
144     void setCurrentPersp3D(Persp3D * const persp);
145     inline void setCurrentPersp3DImpl(Persp3DImpl * const persp_impl) { current_persp3d_impl = persp_impl; }
146     /*
147      * getCurrentPersp3D returns current_persp3d (if non-NULL) or the first
148      * perspective in the defs. If no perspective exists, returns NULL.
149      */
150     Persp3D * getCurrentPersp3D();
151     Persp3DImpl * getCurrentPersp3DImpl();
153     void getPerspectivesInDefs(std::vector<Persp3D*> &list) const;
155     unsigned int numPerspectivesInDefs() const {
156         std::vector<Persp3D*> list;
157         getPerspectivesInDefs(list);
158         return list.size();
159     }
161     sigc::connection connectModified(ModifiedSignal::slot_type slot);
162     sigc::connection connectURISet(URISetSignal::slot_type slot);
163     sigc::connection connectResized(ResizedSignal::slot_type slot);
164     sigc::connection connectCommit(CommitSignal::slot_type slot);
166     void bindObjectToId(gchar const *id, SPObject *object);
167     SPObject *getObjectById(gchar const *id) const;
168     sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
170     void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
171     SPObject *getObjectByRepr(Inkscape::XML::Node *repr) const;
173     Glib::ustring getLanguage() const;
175     void queueForOrphanCollection(SPObject *object);
176     void collectOrphans();
178     void _emitModified();
180     void addUndoObserver(Inkscape::UndoStackObserver& observer);
181     void removeUndoObserver(Inkscape::UndoStackObserver& observer);
183     bool _updateDocument();
185     /// Are we currently in a transition between two "known good" states of the document?
186     bool isSeeking() const;
188     bool isModifiedSinceSave() const { return modified_since_save; }
189     void setModifiedSinceSave(bool modified = true) {
190         modified_since_save = modified;
191     }
193 private:
194     SPDocument(SPDocument const &); // no copy
195     void operator=(SPDocument const &); // no assign
197     Persp3D *current_persp3d; /**< Currently 'active' perspective (to which, e.g., newly created boxes are attached) */
198     Persp3DImpl *current_persp3d_impl;
200 public:
201     sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
202     sigc::connection connectReconstructionFinish(ReconstructionFinish::slot_type slot);
203     void emitReconstructionStart(void);
204     void emitReconstructionFinish(void);
206     unsigned long serial() const;
207     void reset_key(void *dummy);
208     sigc::connection _selection_changed_connection;
209     sigc::connection _desktop_activated_connection;
211     sigc::connection connectResourcesChanged(const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
213     void fitToRect(Geom::Rect const &rect, bool with_margins = false);
214     static SPDocument *createNewDoc(const gchar *uri, unsigned int keepalive, bool make_new = false);
215     static SPDocument *createNewDocFromMem(const gchar *buffer, gint length, unsigned int keepalive);
217     /**
218      * Returns the bottommost item from the list which is at the point, or NULL if none.
219      */
220     static SPItem *getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, const GSList *list, Geom::Point const p, bool take_insensitive = false);
222     // ToDo - Merge createDoc with createNewDoc
223     static SPDocument *createDoc(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
225     SPDocument *doRef();
226     SPDocument *doUnref();
227     gdouble getWidth() const;
228     gdouble getHeight() const;
229     Geom::Point getDimensions() const;
230     void setWidth(gdouble width, const SPUnit *unit);
231     void setHeight(gdouble height, const SPUnit *unit);
232     void requestModified();
233     gint ensureUpToDate();
234     bool addResource(const gchar *key, SPObject *object);
235     bool removeResource(const gchar *key, SPObject *object);
236     const GSList *getResourceList(const gchar *key) const;
237     GSList *getItemsInBox(unsigned int dkey, Geom::Rect const &box) const;
238     GSList *getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const;
239     SPItem *getItemAtPoint(unsigned int key, Geom::Point const p, gboolean into_groups, SPItem *upto = NULL) const;
240     GSList *getItemsAtPoints(unsigned const key, std::vector<Geom::Point> points) const;
241     SPItem *getGroupAtPoint(unsigned int key,  Geom::Point const p) const;
243     void changeUriAndHrefs(gchar const *uri);
244     void emitResizedSignal(gdouble width, gdouble height);
245         
246     unsigned int vacuumDocument();
248 private:
249     void do_change_uri(gchar const *const filename, bool const rebase);
250 };
252 struct SPUnit;
254 /*
255  * Ideas: How to overcome style invalidation nightmare
256  *
257  * 1. There is reference request dictionary, that contains
258  * objects (styles) needing certain id. Object::build checks
259  * final id against it, and invokes necesary methods
260  *
261  * 2. Removing referenced object is simply prohibited -
262  * needs analyse, how we can deal with situations, where
263  * we simply want to ungroup etc. - probably we need
264  * Repr::reparent method :( [Or was it ;)]
265  *
266  */
268 #endif // SEEN_SP_DOCUMENT_H
270 /*
271   Local Variables:
272   mode:c++
273   c-file-style:"stroustrup"
274   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
275   indent-tabs-mode:nil
276   fill-column:99
277   End:
278 */
279 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :