2f9da781764328158f6e983ca71a602b120f9697
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 <2geom/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>
32 #include <set>
34 namespace Avoid {
35 class Router;
36 }
38 struct NRRect;
39 struct SPDesktop;
40 struct SPItem;
41 struct SPObject;
42 struct SPGroup;
44 namespace Inkscape {
45 struct Application;
46 class Selection;
47 class UndoStackObserver;
48 class EventLog;
49 class ProfileManager;
50 namespace XML {
51 class Document;
52 class Node;
53 }
54 }
56 class SP3DBox;
57 class Persp3D;
58 class Persp3DImpl;
60 namespace Proj {
61 class TransfMat3x4;
62 }
64 class SPDocumentPrivate;
66 /// Typed SVG document implementation.
67 class SPDocument : public Inkscape::GC::Managed<>,
68 public Inkscape::GC::Finalized,
69 public Inkscape::GC::Anchored
70 {
71 public:
72 typedef sigc::signal<void, SPObject *> IDChangedSignal;
73 typedef sigc::signal<void> ResourcesChangedSignal;
74 typedef sigc::signal<void, guint> ModifiedSignal;
75 typedef sigc::signal<void, gchar const *> URISetSignal;
76 typedef sigc::signal<void, double, double> ResizedSignal;
77 typedef sigc::signal<void> ReconstructionStart;
78 typedef sigc::signal<void> ReconstructionFinish;
79 typedef sigc::signal<void> CommitSignal;
81 SPDocument();
82 virtual ~SPDocument();
84 unsigned int keepalive : 1;
85 unsigned int virgin : 1; ///< Has the document never been touched?
86 unsigned int modified_since_save : 1;
88 Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
89 Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document
90 SPObject *root; ///< Our SPRoot
91 CRCascade *style_cascade;
93 gchar *uri; ///< A filename (not a URI yet), or NULL
94 gchar *base; ///< To be used for resolving relative hrefs.
95 gchar *name; ///< basename(uri) or other human-readable label for the document.
97 SPDocumentPrivate *priv;
99 /// Last action key
100 const gchar *actionkey;
101 /// Handler ID
102 guint modified_id;
104 /// Connector rerouting handler ID
105 guint rerouting_handler_id;
107 Inkscape::ProfileManager* profileManager;
109 // Instance of the connector router
110 Avoid::Router *router;
112 GSList *_collection_queue;
114 bool oldSignalsConnected;
116 void setCurrentPersp3D(Persp3D * const persp);
117 inline void setCurrentPersp3DImpl(Persp3DImpl * const persp_impl) { current_persp3d_impl = persp_impl; }
118 /*
119 * getCurrentPersp3D returns current_persp3d (if non-NULL) or the first
120 * perspective in the defs. If no perspective exists, returns NULL.
121 */
122 Persp3D * getCurrentPersp3D();
123 Persp3DImpl * getCurrentPersp3DImpl();
124 void getPerspectivesInDefs(std::vector<Persp3D*> &list);
125 unsigned int numPerspectivesInDefs() {
126 std::vector<Persp3D*> list;
127 getPerspectivesInDefs(list);
128 return list.size();
129 }
131 //void initialize_current_persp3d();
133 sigc::connection connectModified(ModifiedSignal::slot_type slot);
134 sigc::connection connectURISet(URISetSignal::slot_type slot);
135 sigc::connection connectResized(ResizedSignal::slot_type slot);
136 sigc::connection connectCommit(CommitSignal::slot_type slot);
138 void bindObjectToId(gchar const *id, SPObject *object);
139 SPObject *getObjectById(gchar const *id);
140 sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
142 void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
143 SPObject *getObjectByRepr(Inkscape::XML::Node *repr);
145 Glib::ustring getLanguage();
147 void queueForOrphanCollection(SPObject *object);
148 void collectOrphans();
150 void _emitModified();
152 void addUndoObserver(Inkscape::UndoStackObserver& observer);
153 void removeUndoObserver(Inkscape::UndoStackObserver& observer);
155 bool _updateDocument();
157 /// Are we currently in a transition between two "known good" states of the document?
158 bool isSeeking() const;
160 bool isModifiedSinceSave() const { return modified_since_save; }
161 void setModifiedSinceSave(bool modified = true) {
162 modified_since_save = modified;
163 }
165 private:
166 SPDocument(SPDocument const &); // no copy
167 void operator=(SPDocument const &); // no assign
169 Persp3D *current_persp3d; /**< Currently 'active' perspective (to which, e.g., newly created boxes are attached) */
170 Persp3DImpl *current_persp3d_impl;
172 public:
173 sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
174 sigc::connection connectReconstructionFinish(ReconstructionFinish::slot_type slot);
175 void emitReconstructionStart(void);
176 void emitReconstructionFinish(void);
178 unsigned long serial() const;
179 void reset_key(void *dummy);
180 sigc::connection _selection_changed_connection;
181 sigc::connection _desktop_activated_connection;
183 void fitToRect(Geom::Rect const &rect, bool with_margins = false);
184 static SPDocument *createDoc(const gchar *uri, unsigned int keepalive, bool make_new = false);
185 static SPDocument *createDocFromMem(const gchar *buffer, gint length, unsigned int keepalive);
186 SPDocument *doRef();
187 SPDocument *doUnref();
188 };
190 //SPDocument *sp_document_new(const gchar *uri, unsigned int keepalive, bool make_new = false);
191 //SPDocument *sp_document_new_from_mem(const gchar *buffer, gint length, unsigned int keepalive);
193 //SPDocument *sp_document_ref(SPDocument *doc);
194 //SPDocument *sp_document_unref(SPDocument *doc);
197 SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
199 /*
200 * Access methods
201 */
203 #define sp_document_repr_doc(d) (d->rdoc)
204 #define sp_document_repr_root(d) (d->rroot)
205 #define sp_document_root(d) (d->root)
206 #define SP_DOCUMENT_ROOT(d) (d->root)
208 gdouble sp_document_width(SPDocument *document);
209 gdouble sp_document_height(SPDocument *document);
210 Geom::Point sp_document_dimensions(SPDocument *document);
212 struct SPUnit;
214 void sp_document_set_width(SPDocument *document, gdouble width, const SPUnit *unit);
215 void sp_document_set_height(SPDocument *document, gdouble height, const SPUnit *unit);
217 #define SP_DOCUMENT_URI(d) (d->uri)
218 #define SP_DOCUMENT_NAME(d) (d->name)
219 #define SP_DOCUMENT_BASE(d) (d->base)
221 /*
222 * Dictionary
223 */
225 /*
226 * Undo & redo
227 */
229 void sp_document_set_undo_sensitive(SPDocument *document, bool sensitive);
230 bool sp_document_get_undo_sensitive(SPDocument const *document);
232 void sp_document_clear_undo(SPDocument *document);
233 void sp_document_clear_redo(SPDocument *document);
235 void sp_document_child_added(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
236 void sp_document_child_removed(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
237 void sp_document_attr_changed(SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
238 void sp_document_content_changed(SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
239 void sp_document_order_changed(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
241 /* Object modification root handler */
242 void sp_document_request_modified(SPDocument *doc);
243 gint sp_document_ensure_up_to_date(SPDocument *doc);
245 /* Save all previous actions to stack, as one undo step */
246 void sp_document_done(SPDocument *document, unsigned int event_type, Glib::ustring event_description);
247 void sp_document_maybe_done(SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
248 void sp_document_reset_key(Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
250 /* Cancel (and revert) current unsaved actions */
251 void sp_document_cancel(SPDocument *document);
253 /* Undo and redo */
254 gboolean sp_document_undo(SPDocument *document);
255 gboolean sp_document_redo(SPDocument *document);
257 /* Resource management */
258 gboolean sp_document_add_resource(SPDocument *document, const gchar *key, SPObject *object);
259 gboolean sp_document_remove_resource(SPDocument *document, const gchar *key, SPObject *object);
260 const GSList *sp_document_get_resource_list(SPDocument *document, const gchar *key);
261 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
264 /*
265 * Ideas: How to overcome style invalidation nightmare
266 *
267 * 1. There is reference request dictionary, that contains
268 * objects (styles) needing certain id. Object::build checks
269 * final id against it, and invokes necesary methods
270 *
271 * 2. Removing referenced object is simply prohibited -
272 * needs analyse, how we can deal with situations, where
273 * we simply want to ungroup etc. - probably we need
274 * Repr::reparent method :( [Or was it ;)]
275 *
276 */
278 /*
279 * Misc
280 */
282 GSList *sp_document_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
283 GSList *sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
284 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);
285 SPItem *sp_document_item_at_point (SPDocument *document, unsigned int key, Geom::Point const p, gboolean into_groups, SPItem *upto = NULL);
286 GSList *sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<Geom::Point> points);
287 SPItem *sp_document_group_at_point (SPDocument *document, unsigned int key, Geom::Point const p);
289 void sp_document_set_uri(SPDocument *document, gchar const *uri);
290 void sp_document_change_uri_and_hrefs(SPDocument *document, gchar const *uri);
292 void sp_document_resized_signal_emit(SPDocument *doc, gdouble width, gdouble height);
294 unsigned int vacuum_document(SPDocument *document);
297 #endif
299 /*
300 Local Variables:
301 mode:c++
302 c-file-style:"stroustrup"
303 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
304 indent-tabs-mode:nil
305 fill-column:99
306 End:
307 */
308 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :