Code

Hold perspectives on document level rather than globally; this corrects the changes...
[inkscape.git] / src / document.h
1 #ifndef __SP_DOCUMENT_H__
2 #define __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  *
11  * Copyright (C) 2004-2005 MenTaLguY
12  * Copyright (C) 1999-2002 Lauris Kaplinski
13  * Copyright (C) 2000-2001 Ximian, Inc.
14  *
15  * Released under GNU GPL, read the file 'COPYING' for more information
16  */
18 #include <glib-object.h>
19 #include <gtk/gtksignal.h>
20 #include <sigc++/sigc++.h>
21 #include <sigc++/class_slot.h>
23 #include "libcroco/cr-cascade.h"
24 #include "libnr/nr-forward.h"
26 #include "gc-managed.h"
27 #include "gc-finalized.h"
28 #include "gc-anchored.h"
29 #include <glibmm/ustring.h>
30 #include "verbs.h"
31 #include <vector>
33 namespace Avoid {
34 class Router;
35 }
37 struct NRRect;
38 struct SPDesktop;
39 struct SPItem;
40 struct SPObject;
41 struct SPGroup;
43 namespace Inkscape {
44     struct Application;
45     class Selection; 
46     class UndoStackObserver;
47     class EventLog;
48     namespace XML {
49         class Document;
50         class Node;
51     }
52 }
54 class SP3DBox;
56 namespace Box3D {
57   class Perspective3D;
58   class VanishingPoint;
59 }
61 class SPDocumentPrivate;
63 /// Typed SVG document implementation.
64 struct SPDocument : public Inkscape::GC::Managed<>,
65                     public Inkscape::GC::Finalized,
66                     public Inkscape::GC::Anchored
67 {
68         typedef sigc::signal<void, SPObject *> IDChangedSignal;
69         typedef sigc::signal<void> ResourcesChangedSignal;
70         typedef sigc::signal<void, guint> ModifiedSignal;
71         typedef sigc::signal<void, gchar const *> URISetSignal;
72         typedef sigc::signal<void, double, double> ResizedSignal;
73         typedef sigc::signal<void> ReconstructionStart;
74         typedef sigc::signal<void> ReconstructionFinish;
75   typedef sigc::signal<void> CommitSignal;
77         SPDocument();
78         ~SPDocument();
80         unsigned int keepalive : 1;
81         unsigned int virgin    : 1; ///< Has the document never been touched?
83         Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
84         Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document
85         SPObject *root;             ///< Our SPRoot
86         CRCascade *style_cascade;
88         gchar *uri; ///< URI string or NULL
89         gchar *base;
90         gchar *name;
92         SPDocumentPrivate *priv;
94         /// Last action key
95         const gchar *actionkey;
96         /// Handler ID
97         guint modified_id;
99         // Instance of the connector router
100         Avoid::Router *router;
102         GSList *perspectives;
103         Box3D::Perspective3D *current_perspective;
105         // FIXME: Perspectives should be linked to the list of existing ones automatically in the constructor
106         //        and removed in the destructor!
107         void add_perspective (Box3D::Perspective3D * const persp);
108         void remove_perspective (Box3D::Perspective3D * const persp);
109         /* find an existing perspective whose VPs are equal to those of persp */
110         Box3D::Perspective3D * find_perspective (const Box3D::Perspective3D * persp);
112         Box3D::Perspective3D * get_persp_of_box (const SP3DBox *box);
113         Box3D::Perspective3D * get_persp_of_VP (const Box3D::VanishingPoint *vp);
115         sigc::connection connectModified(ModifiedSignal::slot_type slot);
116         sigc::connection connectURISet(URISetSignal::slot_type slot);
117         sigc::connection connectResized(ResizedSignal::slot_type slot);
118   sigc::connection connectCommit(CommitSignal::slot_type slot);
120         void bindObjectToId(gchar const *id, SPObject *object);
121         SPObject *getObjectById(gchar const *id);
122         sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
124         void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
125         SPObject *getObjectByRepr(Inkscape::XML::Node *repr);
127     Glib::ustring getLanguage();
129         void queueForOrphanCollection(SPObject *object);
130         void collectOrphans();
132         void _emitModified();
134         GSList *_collection_queue;
136         void addUndoObserver(Inkscape::UndoStackObserver& observer);
137         void removeUndoObserver(Inkscape::UndoStackObserver& observer);
139         bool _updateDocument();
141         /// Are we currently in a transition between two "known good" states of the document?
142         bool isSeeking() const;
144 private:
145         SPDocument(SPDocument const &); // no copy
146         void operator=(SPDocument const &); // no assign
148 public:
149         sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
150         sigc::connection connectReconstructionFinish (ReconstructionFinish::slot_type  slot);
151         void emitReconstructionStart (void);
152         void emitReconstructionFinish  (void);
154         unsigned long serial() const;
155         void reset_key (void *dummy);
156         sigc::connection _selection_changed_connection;
157         sigc::connection _desktop_activated_connection;
159         void fitToRect(NR::Rect const &rect);
160 };
162 SPDocument *sp_document_new (const gchar *uri, unsigned int keepalive, bool make_new = false);
163 SPDocument *sp_document_new_from_mem (const gchar *buffer, gint length, unsigned int keepalive);
165 SPDocument *sp_document_ref (SPDocument *doc);
166 SPDocument *sp_document_unref (SPDocument *doc);
169 SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
171 /*
172  * Access methods
173  */
175 #define sp_document_repr_doc(d) (d->rdoc)
176 #define sp_document_repr_root(d) (d->rroot)
177 #define sp_document_root(d) (d->root)
178 #define SP_DOCUMENT_ROOT(d)  (d->root)
180 gdouble sp_document_width (SPDocument * document);
181 gdouble sp_document_height (SPDocument * document);
183 struct SPUnit;
185 void sp_document_set_width (SPDocument * document, gdouble width, const SPUnit *unit);
186 void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit *unit);
188 #define SP_DOCUMENT_URI(d) (d->uri)
189 #define SP_DOCUMENT_NAME(d) (d->name)
190 #define SP_DOCUMENT_BASE(d) (d->base)
192 /*
193  * Dictionary
194  */
196 /*
197  * Undo & redo
198  */
200 void sp_document_set_undo_sensitive (SPDocument * document, bool sensitive);
201 bool sp_document_get_undo_sensitive (SPDocument const * document);
203 void sp_document_clear_undo (SPDocument * document);
204 void sp_document_clear_redo (SPDocument * document);
206 void sp_document_child_added (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
207 void sp_document_child_removed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
208 void sp_document_attr_changed (SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
209 void sp_document_content_changed (SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
210 void sp_document_order_changed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
212 /* Object modification root handler */
213 void sp_document_request_modified (SPDocument *doc);
214 gint sp_document_ensure_up_to_date (SPDocument *doc);
216 /* Save all previous actions to stack, as one undo step */
217 void sp_document_done (SPDocument *document, unsigned int event_type, Glib::ustring event_description);
218 void sp_document_maybe_done (SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
219 void sp_document_reset_key (Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
221 /* Cancel (and revert) current unsaved actions */
222 void sp_document_cancel (SPDocument *document);
224 /* Undo and redo */
225 gboolean sp_document_undo (SPDocument * document);
226 gboolean sp_document_redo (SPDocument * document);
228 /* Resource management */
229 gboolean sp_document_add_resource (SPDocument *document, const gchar *key, SPObject *object);
230 gboolean sp_document_remove_resource (SPDocument *document, const gchar *key, SPObject *object);
231 const GSList *sp_document_get_resource_list (SPDocument *document, const gchar *key);
232 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
235 /*
236  * Ideas: How to overcome style invalidation nightmare
237  *
238  * 1. There is reference request dictionary, that contains
239  * objects (styles) needing certain id. Object::build checks
240  * final id against it, and invokes necesary methods
241  *
242  * 2. Removing referenced object is simply prohibited -
243  * needs analyse, how we can deal with situations, where
244  * we simply want to ungroup etc. - probably we need
245  * Repr::reparent method :( [Or was it ;)]
246  *
247  */
249 /*
250  * Misc
251  */
253 GSList * sp_document_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
254 GSList * sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
255 SPItem* sp_document_item_from_list_at_point_bottom (unsigned int dkey, SPGroup *group, const GSList *list, NR::Point const p, bool take_insensitive = false);
256 SPItem * sp_document_item_at_point (SPDocument *document, unsigned int key, NR::Point const p, gboolean into_groups, SPItem *upto = NULL);
257 GSList *sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<NR::Point> points);
258 SPItem *sp_document_group_at_point (SPDocument *document, unsigned int key,  NR::Point const p);
260 void sp_document_set_uri (SPDocument *document, const gchar *uri);
261 void sp_document_resized_signal_emit (SPDocument *doc, gdouble width, gdouble height);
263 unsigned int vacuum_document (SPDocument *document);
265 #endif