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 struct SPDocument : public Inkscape::GC::Managed<>,
68 public Inkscape::GC::Finalized,
69 public Inkscape::GC::Anchored
70 {
71 typedef sigc::signal<void, SPObject *> IDChangedSignal;
72 typedef sigc::signal<void> ResourcesChangedSignal;
73 typedef sigc::signal<void, guint> ModifiedSignal;
74 typedef sigc::signal<void, gchar const *> URISetSignal;
75 typedef sigc::signal<void, double, double> ResizedSignal;
76 typedef sigc::signal<void> ReconstructionStart;
77 typedef sigc::signal<void> ReconstructionFinish;
78 typedef sigc::signal<void> CommitSignal;
80 SPDocument();
81 virtual ~SPDocument();
83 unsigned int keepalive : 1;
84 unsigned int virgin : 1; ///< Has the document never been touched?
85 unsigned int modified_since_save : 1;
87 Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
88 Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document
89 SPObject *root; ///< Our SPRoot
90 CRCascade *style_cascade;
92 gchar *uri; ///< A filename (not a URI yet), or NULL
93 gchar *base; ///< To be used for resolving relative hrefs.
94 gchar *name; ///< basename(uri) or other human-readable label for the document.
96 SPDocumentPrivate *priv;
98 /// Last action key
99 Glib::ustring 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 };
186 SPDocument *sp_document_new(const gchar *uri, unsigned int keepalive, bool make_new = false);
187 SPDocument *sp_document_new_from_mem(const gchar *buffer, gint length, unsigned int keepalive);
189 SPDocument *sp_document_ref(SPDocument *doc);
190 SPDocument *sp_document_unref(SPDocument *doc);
193 SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
195 /*
196 * Access methods
197 */
199 #define sp_document_repr_doc(d) (d->rdoc)
200 #define sp_document_repr_root(d) (d->rroot)
201 #define sp_document_root(d) (d->root)
202 #define SP_DOCUMENT_ROOT(d) (d->root)
204 gdouble sp_document_width(SPDocument *document);
205 gdouble sp_document_height(SPDocument *document);
206 Geom::Point sp_document_dimensions(SPDocument *document);
208 struct SPUnit;
210 void sp_document_set_width(SPDocument *document, gdouble width, const SPUnit *unit);
211 void sp_document_set_height(SPDocument *document, gdouble height, const SPUnit *unit);
213 #define SP_DOCUMENT_URI(d) (d->uri)
214 #define SP_DOCUMENT_NAME(d) (d->name)
215 #define SP_DOCUMENT_BASE(d) (d->base)
217 /*
218 * Dictionary
219 */
221 /*
222 * Undo & redo
223 */
225 void sp_document_set_undo_sensitive(SPDocument *document, bool sensitive);
226 bool sp_document_get_undo_sensitive(SPDocument const *document);
228 void sp_document_clear_undo(SPDocument *document);
229 void sp_document_clear_redo(SPDocument *document);
231 void sp_document_child_added(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
232 void sp_document_child_removed(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
233 void sp_document_attr_changed(SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
234 void sp_document_content_changed(SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
235 void sp_document_order_changed(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
237 /* Object modification root handler */
238 void sp_document_request_modified(SPDocument *doc);
239 gint sp_document_ensure_up_to_date(SPDocument *doc);
241 /* Save all previous actions to stack, as one undo step */
242 void sp_document_done(SPDocument *document, unsigned int event_type, Glib::ustring event_description);
243 void sp_document_maybe_done(SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
244 void sp_document_reset_key(Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
246 /* Cancel (and revert) current unsaved actions */
247 void sp_document_cancel(SPDocument *document);
249 /* Undo and redo */
250 gboolean sp_document_undo(SPDocument *document);
251 gboolean sp_document_redo(SPDocument *document);
253 /* Resource management */
254 gboolean sp_document_add_resource(SPDocument *document, const gchar *key, SPObject *object);
255 gboolean sp_document_remove_resource(SPDocument *document, const gchar *key, SPObject *object);
256 const GSList *sp_document_get_resource_list(SPDocument *document, const gchar *key);
257 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
260 /*
261 * Ideas: How to overcome style invalidation nightmare
262 *
263 * 1. There is reference request dictionary, that contains
264 * objects (styles) needing certain id. Object::build checks
265 * final id against it, and invokes necesary methods
266 *
267 * 2. Removing referenced object is simply prohibited -
268 * needs analyse, how we can deal with situations, where
269 * we simply want to ungroup etc. - probably we need
270 * Repr::reparent method :( [Or was it ;)]
271 *
272 */
274 /*
275 * Misc
276 */
278 GSList *sp_document_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
279 GSList *sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
280 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);
281 SPItem *sp_document_item_at_point (SPDocument *document, unsigned int key, Geom::Point const p, gboolean into_groups, SPItem *upto = NULL);
282 GSList *sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<Geom::Point> points);
283 SPItem *sp_document_group_at_point (SPDocument *document, unsigned int key, Geom::Point const p);
285 void sp_document_set_uri(SPDocument *document, gchar const *uri);
286 void sp_document_change_uri_and_hrefs(SPDocument *document, gchar const *uri);
288 void sp_document_resized_signal_emit(SPDocument *doc, gdouble width, gdouble height);
290 unsigned int vacuum_document(SPDocument *document);
293 #endif
295 /*
296 Local Variables:
297 mode:c++
298 c-file-style:"stroustrup"
299 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
300 indent-tabs-mode:nil
301 fill-column:99
302 End:
303 */
304 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :