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;
59 namespace Proj {
60 class TransfMat3x4;
61 }
63 class SPDocumentPrivate;
65 /// Typed SVG document implementation.
66 struct SPDocument : public Inkscape::GC::Managed<>,
67 public Inkscape::GC::Finalized,
68 public Inkscape::GC::Anchored
69 {
70 typedef sigc::signal<void, SPObject *> IDChangedSignal;
71 typedef sigc::signal<void> ResourcesChangedSignal;
72 typedef sigc::signal<void, guint> ModifiedSignal;
73 typedef sigc::signal<void, gchar const *> URISetSignal;
74 typedef sigc::signal<void, double, double> ResizedSignal;
75 typedef sigc::signal<void> ReconstructionStart;
76 typedef sigc::signal<void> ReconstructionFinish;
77 typedef sigc::signal<void> CommitSignal;
79 SPDocument();
80 virtual ~SPDocument();
82 unsigned int keepalive : 1;
83 unsigned int virgin : 1; ///< Has the document never been touched?
84 unsigned int modified_since_save : 1;
86 Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
87 Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document
88 SPObject *root; ///< Our SPRoot
89 CRCascade *style_cascade;
91 gchar *uri; ///< A filename (not a URI yet), or NULL
92 gchar *base; ///< To be used for resolving relative hrefs.
93 gchar *name; ///< basename(uri) or other human-readable label for the document.
95 SPDocumentPrivate *priv;
97 /// Last action key
98 const gchar *actionkey;
99 /// Handler ID
100 guint modified_id;
102 /// Connector rerouting handler ID
103 guint rerouting_handler_id;
105 Inkscape::ProfileManager* profileManager;
107 // Instance of the connector router
108 Avoid::Router *router;
110 GSList *perspectives;
112 Persp3D *current_persp3d; // "currently active" perspective (e.g., newly created boxes are attached to this one)
114 GSList *_collection_queue;
116 bool oldSignalsConnected;
118 void add_persp3d(Persp3D * const persp);
119 void remove_persp3d(Persp3D * const persp);
120 void initialize_current_persp3d();
122 sigc::connection connectModified(ModifiedSignal::slot_type slot);
123 sigc::connection connectURISet(URISetSignal::slot_type slot);
124 sigc::connection connectResized(ResizedSignal::slot_type slot);
125 sigc::connection connectCommit(CommitSignal::slot_type slot);
127 void bindObjectToId(gchar const *id, SPObject *object);
128 SPObject *getObjectById(gchar const *id);
129 sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
131 void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
132 SPObject *getObjectByRepr(Inkscape::XML::Node *repr);
134 Glib::ustring getLanguage();
136 void queueForOrphanCollection(SPObject *object);
137 void collectOrphans();
139 void _emitModified();
141 void addUndoObserver(Inkscape::UndoStackObserver& observer);
142 void removeUndoObserver(Inkscape::UndoStackObserver& observer);
144 bool _updateDocument();
146 /// Are we currently in a transition between two "known good" states of the document?
147 bool isSeeking() const;
149 bool isModifiedSinceSave() const { return modified_since_save; }
150 void setModifiedSinceSave(bool modified = true) {
151 modified_since_save = modified;
152 }
154 private:
155 SPDocument(SPDocument const &); // no copy
156 void operator=(SPDocument const &); // no assign
158 public:
159 sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
160 sigc::connection connectReconstructionFinish(ReconstructionFinish::slot_type slot);
161 void emitReconstructionStart(void);
162 void emitReconstructionFinish(void);
164 unsigned long serial() const;
165 void reset_key(void *dummy);
166 sigc::connection _selection_changed_connection;
167 sigc::connection _desktop_activated_connection;
169 void fitToRect(Geom::Rect const &rect);
170 };
172 SPDocument *sp_document_new(const gchar *uri, unsigned int keepalive, bool make_new = false);
173 SPDocument *sp_document_new_from_mem(const gchar *buffer, gint length, unsigned int keepalive);
175 SPDocument *sp_document_ref(SPDocument *doc);
176 SPDocument *sp_document_unref(SPDocument *doc);
179 SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
181 /*
182 * Access methods
183 */
185 #define sp_document_repr_doc(d) (d->rdoc)
186 #define sp_document_repr_root(d) (d->rroot)
187 #define sp_document_root(d) (d->root)
188 #define SP_DOCUMENT_ROOT(d) (d->root)
190 gdouble sp_document_width(SPDocument *document);
191 gdouble sp_document_height(SPDocument *document);
192 Geom::Point sp_document_dimensions(SPDocument *document);
194 struct SPUnit;
196 void sp_document_set_width(SPDocument *document, gdouble width, const SPUnit *unit);
197 void sp_document_set_height(SPDocument *document, gdouble height, const SPUnit *unit);
199 #define SP_DOCUMENT_URI(d) (d->uri)
200 #define SP_DOCUMENT_NAME(d) (d->name)
201 #define SP_DOCUMENT_BASE(d) (d->base)
203 /*
204 * Dictionary
205 */
207 /*
208 * Undo & redo
209 */
211 void sp_document_set_undo_sensitive(SPDocument *document, bool sensitive);
212 bool sp_document_get_undo_sensitive(SPDocument const *document);
214 void sp_document_clear_undo(SPDocument *document);
215 void sp_document_clear_redo(SPDocument *document);
217 void sp_document_child_added(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
218 void sp_document_child_removed(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
219 void sp_document_attr_changed(SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
220 void sp_document_content_changed(SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
221 void sp_document_order_changed(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
223 /* Object modification root handler */
224 void sp_document_request_modified(SPDocument *doc);
225 gint sp_document_ensure_up_to_date(SPDocument *doc);
227 /* Save all previous actions to stack, as one undo step */
228 void sp_document_done(SPDocument *document, unsigned int event_type, Glib::ustring event_description);
229 void sp_document_maybe_done(SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
230 void sp_document_reset_key(Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
232 /* Cancel (and revert) current unsaved actions */
233 void sp_document_cancel(SPDocument *document);
235 /* Undo and redo */
236 gboolean sp_document_undo(SPDocument *document);
237 gboolean sp_document_redo(SPDocument *document);
239 /* Resource management */
240 gboolean sp_document_add_resource(SPDocument *document, const gchar *key, SPObject *object);
241 gboolean sp_document_remove_resource(SPDocument *document, const gchar *key, SPObject *object);
242 const GSList *sp_document_get_resource_list(SPDocument *document, const gchar *key);
243 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
246 /*
247 * Ideas: How to overcome style invalidation nightmare
248 *
249 * 1. There is reference request dictionary, that contains
250 * objects (styles) needing certain id. Object::build checks
251 * final id against it, and invokes necesary methods
252 *
253 * 2. Removing referenced object is simply prohibited -
254 * needs analyse, how we can deal with situations, where
255 * we simply want to ungroup etc. - probably we need
256 * Repr::reparent method :( [Or was it ;)]
257 *
258 */
260 /*
261 * Misc
262 */
264 GSList *sp_document_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
265 GSList *sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
266 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);
267 SPItem *sp_document_item_at_point (SPDocument *document, unsigned int key, Geom::Point const p, gboolean into_groups, SPItem *upto = NULL);
268 GSList *sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<Geom::Point> points);
269 SPItem *sp_document_group_at_point (SPDocument *document, unsigned int key, Geom::Point const p);
271 void sp_document_set_uri(SPDocument *document, gchar const *uri);
272 void sp_document_change_uri_and_hrefs(SPDocument *document, gchar const *uri);
274 void sp_document_resized_signal_emit(SPDocument *doc, gdouble width, gdouble height);
276 unsigned int vacuum_document(SPDocument *document);
279 #endif
281 /*
282 Local Variables:
283 mode:c++
284 c-file-style:"stroustrup"
285 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
286 indent-tabs-mode:nil
287 fill-column:99
288 End:
289 */
290 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :