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 "document-undo.h"
32 #include <vector>
33 #include <set>
35 namespace Avoid {
36 class Router;
37 }
39 struct NRRect;
40 struct SPDesktop;
41 struct SPItem;
42 struct SPObject;
43 struct SPGroup;
45 namespace Inkscape {
46 struct Application;
47 class Selection;
48 class UndoStackObserver;
49 class EventLog;
50 class ProfileManager;
51 namespace XML {
52 class Document;
53 class Node;
54 }
55 }
57 class SP3DBox;
58 class Persp3D;
59 class Persp3DImpl;
61 namespace Proj {
62 class TransfMat3x4;
63 }
65 class SPDocumentPrivate;
67 /// Typed SVG document implementation.
68 class SPDocument : public Inkscape::GC::Managed<>,
69 public Inkscape::GC::Finalized,
70 public Inkscape::GC::Anchored
71 {
72 public:
73 typedef sigc::signal<void, SPObject *> IDChangedSignal;
74 typedef sigc::signal<void> ResourcesChangedSignal;
75 typedef sigc::signal<void, guint> ModifiedSignal;
76 typedef sigc::signal<void, gchar const *> URISetSignal;
77 typedef sigc::signal<void, double, double> ResizedSignal;
78 typedef sigc::signal<void> ReconstructionStart;
79 typedef sigc::signal<void> ReconstructionFinish;
80 typedef sigc::signal<void> CommitSignal;
82 SPDocument();
83 virtual ~SPDocument();
85 unsigned int keepalive : 1;
86 unsigned int virgin : 1; ///< Has the document never been touched?
87 unsigned int modified_since_save : 1;
89 Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
90 Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document
91 SPObject *root; ///< Our SPRoot
92 CRCascade *style_cascade;
94 gchar *uri; ///< A filename (not a URI yet), or NULL
95 gchar *base; ///< To be used for resolving relative hrefs.
96 gchar *name; ///< basename(uri) or other human-readable label for the document.
98 SPDocumentPrivate *priv;
100 /// Last action key
101 const gchar *actionkey;
102 /// Handler ID
103 guint modified_id;
105 /// Connector rerouting handler ID
106 guint rerouting_handler_id;
108 Inkscape::ProfileManager* profileManager;
110 // Instance of the connector router
111 Avoid::Router *router;
113 GSList *_collection_queue;
115 bool oldSignalsConnected;
117 void setCurrentPersp3D(Persp3D * const persp);
118 inline void setCurrentPersp3DImpl(Persp3DImpl * const persp_impl) { current_persp3d_impl = persp_impl; }
119 /*
120 * getCurrentPersp3D returns current_persp3d (if non-NULL) or the first
121 * perspective in the defs. If no perspective exists, returns NULL.
122 */
123 Persp3D * getCurrentPersp3D();
124 Persp3DImpl * getCurrentPersp3DImpl();
125 void getPerspectivesInDefs(std::vector<Persp3D*> &list);
126 unsigned int numPerspectivesInDefs() {
127 std::vector<Persp3D*> list;
128 getPerspectivesInDefs(list);
129 return list.size();
130 }
132 //void initialize_current_persp3d();
134 sigc::connection connectModified(ModifiedSignal::slot_type slot);
135 sigc::connection connectURISet(URISetSignal::slot_type slot);
136 sigc::connection connectResized(ResizedSignal::slot_type slot);
137 sigc::connection connectCommit(CommitSignal::slot_type slot);
139 void bindObjectToId(gchar const *id, SPObject *object);
140 SPObject *getObjectById(gchar const *id);
141 sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
143 void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
144 SPObject *getObjectByRepr(Inkscape::XML::Node *repr);
146 Glib::ustring getLanguage();
148 void queueForOrphanCollection(SPObject *object);
149 void collectOrphans();
151 void _emitModified();
153 void addUndoObserver(Inkscape::UndoStackObserver& observer);
154 void removeUndoObserver(Inkscape::UndoStackObserver& observer);
156 bool _updateDocument();
158 /// Are we currently in a transition between two "known good" states of the document?
159 bool isSeeking() const;
161 bool isModifiedSinceSave() const { return modified_since_save; }
162 void setModifiedSinceSave(bool modified = true) {
163 modified_since_save = modified;
164 }
165 //Inkscape::XML::Document * getRdoc(){ return rdoc; }
167 private:
168 //Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
169 SPDocument(SPDocument const &); // no copy
170 void operator=(SPDocument const &); // no assign
172 Persp3D *current_persp3d; /**< Currently 'active' perspective (to which, e.g., newly created boxes are attached) */
173 Persp3DImpl *current_persp3d_impl;
175 public:
176 sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
177 sigc::connection connectReconstructionFinish(ReconstructionFinish::slot_type slot);
178 void emitReconstructionStart(void);
179 void emitReconstructionFinish(void);
181 unsigned long serial() const;
182 void reset_key(void *dummy);
183 sigc::connection _selection_changed_connection;
184 sigc::connection _desktop_activated_connection;
186 void fitToRect(Geom::Rect const &rect, bool with_margins = false);
187 static SPDocument *createNewDoc(const gchar *uri, unsigned int keepalive, bool make_new = false);
188 static SPDocument *createNewDocFromMem(const gchar *buffer, gint length, unsigned int keepalive);
190 /* ToDo - Merge createDoc with createNewDoc */
191 static SPDocument *createDoc(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
193 SPDocument *doRef();
194 SPDocument *doUnref();
195 gdouble getWidth();
196 gdouble getHeight();
197 Geom::Point getDimensions();
198 void setWidth(gdouble width, const SPUnit *unit);
199 void setHeight(gdouble height, const SPUnit *unit);
200 //void setUndoSensitive(bool sensitive);
201 void request_modified();
202 gint ensure_up_to_date();
203 gboolean add_resource(const gchar *key, SPObject *object);
204 gboolean remove_resource(const gchar *key, SPObject *object);
205 const GSList *get_resource_list(const gchar *key);
206 sigc::connection resources_changed_connect(const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
207 GSList * items_in_box(unsigned int dkey, Geom::Rect const &box);
208 GSList *partial_items_in_box(unsigned int dkey, Geom::Rect const &box);
209 static SPItem *item_from_list_at_point_bottom(unsigned int dkey, SPGroup *group, const GSList *list, Geom::Point const p, bool take_insensitive = false);
210 SPItem *item_at_point (unsigned int key, Geom::Point const p, gboolean into_groups, SPItem *upto = NULL);
211 GSList *items_at_points(unsigned const key, std::vector<Geom::Point> points);
212 SPItem *group_at_point (unsigned int key, Geom::Point const p);
214 void setUri(gchar const *uri);
215 void change_uri_and_hrefs(gchar const *uri);
216 void resized_signal_emit(gdouble width, gdouble height);
218 unsigned int vacuum_document();
220 private:
221 void do_change_uri(gchar const *const filename, bool const rebase);
222 };
224 //SPDocument *sp_document_new(const gchar *uri, unsigned int keepalive, bool make_new = false);
225 //SPDocument *sp_document_new_from_mem(const gchar *buffer, gint length, unsigned int keepalive);
227 //SPDocument *sp_document_ref(SPDocument *doc);
228 //SPDocument *sp_document_unref(SPDocument *doc);
231 //SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
233 /*
234 * Access methods
235 */
237 #define sp_document_repr_doc(d) (d->rdoc)
238 #define sp_document_repr_root(d) (d->rroot)
239 #define sp_document_root(d) (d->root)
240 #define SP_DOCUMENT_ROOT(d) (d->root)
242 //gdouble sp_document_width(SPDocument *document);
243 //gdouble sp_document_height(SPDocument *document);
244 //Geom::Point sp_document_dimensions(SPDocument *document);
246 struct SPUnit;
248 //void sp_document_set_width(SPDocument *document, gdouble width, const SPUnit *unit);
249 //void sp_document_set_height(SPDocument *document, gdouble height, const SPUnit *unit);
251 #define SP_DOCUMENT_URI(d) (d->uri)
252 #define SP_DOCUMENT_NAME(d) (d->name)
253 #define SP_DOCUMENT_BASE(d) (d->base)
255 /*
256 * Dictionary
257 */
259 /*
260 * Undo & redo
261 */
263 //void sp_document_set_undo_sensitive(SPDocument *document, bool sensitive);
264 //bool sp_document_get_undo_sensitive(SPDocument const *document);
266 //void sp_document_clear_undo(SPDocument *document);
267 //void sp_document_clear_redo(SPDocument *document);
269 //void sp_document_child_added(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
270 //void sp_document_child_removed(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
271 //void sp_document_attr_changed(SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
272 //void sp_document_content_changed(SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
273 //void sp_document_order_changed(SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
275 /* Object modification root handler */
276 //void sp_document_request_modified(SPDocument *doc);
277 //gint sp_document_ensure_up_to_date(SPDocument *doc);
279 /* Save all previous actions to stack, as one undo step */
280 //void sp_document_done(SPDocument *document, unsigned int event_type, Glib::ustring event_description);
281 //void sp_document_maybe_done(SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
282 //void sp_document_reset_key(Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
284 /* Cancel (and revert) current unsaved actions */
285 //void sp_document_cancel(SPDocument *document);
287 /* Undo and redo */
288 //gboolean sp_document_undo(SPDocument *document);
289 //gboolean sp_document_redo(SPDocument *document);
291 /* Resource management */
292 //gboolean sp_document_add_resource(SPDocument *document, const gchar *key, SPObject *object);
293 //gboolean sp_document_remove_resource(SPDocument *document, const gchar *key, SPObject *object);
294 //const GSList *sp_document_get_resource_list(SPDocument *document, const gchar *key);
295 //sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
298 /*
299 * Ideas: How to overcome style invalidation nightmare
300 *
301 * 1. There is reference request dictionary, that contains
302 * objects (styles) needing certain id. Object::build checks
303 * final id against it, and invokes necesary methods
304 *
305 * 2. Removing referenced object is simply prohibited -
306 * needs analyse, how we can deal with situations, where
307 * we simply want to ungroup etc. - probably we need
308 * Repr::reparent method :( [Or was it ;)]
309 *
310 */
312 /*
313 * Misc
314 */
316 //GSList *sp_document_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
317 //GSList *sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
318 //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);
319 //SPItem *sp_document_item_at_point (SPDocument *document, unsigned int key, Geom::Point const p, gboolean into_groups, SPItem *upto = NULL);
320 //GSList *sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<Geom::Point> points);
321 //SPItem *sp_document_group_at_point (SPDocument *document, unsigned int key, Geom::Point const p);
323 //void sp_document_set_uri(SPDocument *document, gchar const *uri);
324 //void sp_document_change_uri_and_hrefs(SPDocument *document, gchar const *uri);
326 //void sp_document_resized_signal_emit(SPDocument *doc, gdouble width, gdouble height);
328 //unsigned int vacuum_document(SPDocument *document);
331 #endif
333 /*
334 Local Variables:
335 mode:c++
336 c-file-style:"stroustrup"
337 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
338 indent-tabs-mode:nil
339 fill-column:99
340 End:
341 */
342 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :