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 const gchar *actionkey;
100 /// Handler ID
101 guint modified_id;
103 /// Connector rerouting handler ID
104 guint rerouting_handler_id;
106 Inkscape::ProfileManager* profileManager;
108 // Instance of the connector router
109 Avoid::Router *router;
111 GSList *_collection_queue;
113 bool oldSignalsConnected;
115 void setCurrentPersp3D(Persp3D * const persp);
116 inline void setCurrentPersp3DImpl(Persp3DImpl * const persp_impl) { current_persp3d_impl = persp_impl; }
117 /*
118 * getCurrentPersp3D returns current_persp3d (if non-NULL) or the first
119 * perspective in the defs. If no perspective exists, returns NULL.
120 */
121 Persp3D * getCurrentPersp3D();
122 Persp3DImpl * getCurrentPersp3DImpl();
123 void getPerspectivesInDefs(std::vector<Persp3D*> &list);
124 unsigned int numPerspectivesInDefs() {
125 std::vector<Persp3D*> list;
126 getPerspectivesInDefs(list);
127 return list.size();
128 }
130 //void initialize_current_persp3d();
132 sigc::connection connectModified(ModifiedSignal::slot_type slot);
133 sigc::connection connectURISet(URISetSignal::slot_type slot);
134 sigc::connection connectResized(ResizedSignal::slot_type slot);
135 sigc::connection connectCommit(CommitSignal::slot_type slot);
137 void bindObjectToId(gchar const *id, SPObject *object);
138 SPObject *getObjectById(gchar const *id);
139 sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
141 void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
142 SPObject *getObjectByRepr(Inkscape::XML::Node *repr);
144 Glib::ustring getLanguage();
146 void queueForOrphanCollection(SPObject *object);
147 void collectOrphans();
149 void _emitModified();
151 void addUndoObserver(Inkscape::UndoStackObserver& observer);
152 void removeUndoObserver(Inkscape::UndoStackObserver& observer);
154 bool _updateDocument();
156 /// Are we currently in a transition between two "known good" states of the document?
157 bool isSeeking() const;
159 bool isModifiedSinceSave() const { return modified_since_save; }
160 void setModifiedSinceSave(bool modified = true) {
161 modified_since_save = modified;
162 }
164 private:
165 SPDocument(SPDocument const &); // no copy
166 void operator=(SPDocument const &); // no assign
168 Persp3D *current_persp3d; /**< Currently 'active' perspective (to which, e.g., newly created boxes are attached) */
169 Persp3DImpl *current_persp3d_impl;
171 public:
172 sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
173 sigc::connection connectReconstructionFinish(ReconstructionFinish::slot_type slot);
174 void emitReconstructionStart(void);
175 void emitReconstructionFinish(void);
177 unsigned long serial() const;
178 void reset_key(void *dummy);
179 sigc::connection _selection_changed_connection;
180 sigc::connection _desktop_activated_connection;
182 void fitToRect(Geom::Rect const &rect, bool with_margins = false);
183 };
185 SPDocument *sp_document_new(const gchar *uri, unsigned int keepalive, bool make_new = false);
186 SPDocument *sp_document_new_from_mem(const gchar *buffer, gint length, unsigned int keepalive);
188 SPDocument *sp_document_ref(SPDocument *doc);
189 SPDocument *sp_document_unref(SPDocument *doc);
192 SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
194 /*
195 * Access methods
196 */
198 #define sp_document_repr_doc(d) (d->rdoc)
199 #define sp_document_repr_root(d) (d->rroot)
200 #define sp_document_root(d) (d->root)
201 #define SP_DOCUMENT_ROOT(d) (d->root)
203 gdouble sp_document_width(SPDocument *document);
204 gdouble sp_document_height(SPDocument *document);
205 Geom::Point sp_document_dimensions(SPDocument *document);
207 struct SPUnit;
209 void sp_document_set_width(SPDocument *document, gdouble width, const SPUnit *unit);
210 void sp_document_set_height(SPDocument *document, gdouble height, const SPUnit *unit);
212 #define SP_DOCUMENT_URI(d) (d->uri)
213 #define SP_DOCUMENT_NAME(d) (d->name)
214 #define SP_DOCUMENT_BASE(d) (d->base)
216 /*
217 * Dictionary
218 */
220 /*
221 * Undo & redo
222 */
224 void sp_document_set_undo_sensitive(SPDocument *document, bool sensitive);
225 bool sp_document_get_undo_sensitive(SPDocument const *document);
227 void sp_document_clear_undo(SPDocument *document);
228 void sp_document_clear_redo(SPDocument *document);
230 void sp_document_child_added(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
231 void sp_document_child_removed(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
232 void sp_document_attr_changed(SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
233 void sp_document_content_changed(SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
234 void sp_document_order_changed(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
236 /* Object modification root handler */
237 void sp_document_request_modified(SPDocument *doc);
238 gint sp_document_ensure_up_to_date(SPDocument *doc);
240 /* Save all previous actions to stack, as one undo step */
241 void sp_document_done(SPDocument *document, unsigned int event_type, Glib::ustring event_description);
242 void sp_document_maybe_done(SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
243 void sp_document_reset_key(Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
245 /* Cancel (and revert) current unsaved actions */
246 void sp_document_cancel(SPDocument *document);
248 /* Undo and redo */
249 gboolean sp_document_undo(SPDocument *document);
250 gboolean sp_document_redo(SPDocument *document);
252 /* Resource management */
253 gboolean sp_document_add_resource(SPDocument *document, const gchar *key, SPObject *object);
254 gboolean sp_document_remove_resource(SPDocument *document, const gchar *key, SPObject *object);
255 const GSList *sp_document_get_resource_list(SPDocument *document, const gchar *key);
256 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
259 /*
260 * Ideas: How to overcome style invalidation nightmare
261 *
262 * 1. There is reference request dictionary, that contains
263 * objects (styles) needing certain id. Object::build checks
264 * final id against it, and invokes necesary methods
265 *
266 * 2. Removing referenced object is simply prohibited -
267 * needs analyse, how we can deal with situations, where
268 * we simply want to ungroup etc. - probably we need
269 * Repr::reparent method :( [Or was it ;)]
270 *
271 */
273 /*
274 * Misc
275 */
277 GSList *sp_document_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
278 GSList *sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
279 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);
280 SPItem *sp_document_item_at_point (SPDocument *document, unsigned int key, Geom::Point const p, gboolean into_groups, SPItem *upto = NULL);
281 GSList *sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<Geom::Point> points);
282 SPItem *sp_document_group_at_point (SPDocument *document, unsigned int key, Geom::Point const p);
284 void sp_document_set_uri(SPDocument *document, gchar const *uri);
285 void sp_document_change_uri_and_hrefs(SPDocument *document, gchar const *uri);
287 void sp_document_resized_signal_emit(SPDocument *doc, gdouble width, gdouble height);
289 unsigned int vacuum_document(SPDocument *document);
292 #endif
294 /*
295 Local Variables:
296 mode:c++
297 c-file-style:"stroustrup"
298 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
299 indent-tabs-mode:nil
300 fill-column:99
301 End:
302 */
303 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :