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 "libnr/nr-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>
33 namespace Avoid {
34 class Router;
35 }
37 struct NRRect;
38 struct SPDesktop;
39 struct SPItem;
40 struct SPObject;
41 struct SPGroup;
43 namespace Inkscape {
44 struct Application;
45 class Selection;
46 class UndoStackObserver;
47 class EventLog;
48 namespace XML {
49 class Document;
50 class Node;
51 }
52 }
54 class SPDocumentPrivate;
56 /// Typed SVG document implementation.
57 struct SPDocument : public Inkscape::GC::Managed<>,
58 public Inkscape::GC::Finalized,
59 public Inkscape::GC::Anchored
60 {
61 typedef sigc::signal<void, SPObject *> IDChangedSignal;
62 typedef sigc::signal<void> ResourcesChangedSignal;
63 typedef sigc::signal<void, guint> ModifiedSignal;
64 typedef sigc::signal<void, gchar const *> URISetSignal;
65 typedef sigc::signal<void, double, double> ResizedSignal;
66 typedef sigc::signal<void> ReconstructionStart;
67 typedef sigc::signal<void> ReconstructionFinish;
68 typedef sigc::signal<void> CommitSignal;
70 SPDocument();
71 ~SPDocument();
73 unsigned int keepalive : 1;
74 unsigned int virgin : 1; ///< Has the document never been touched?
76 Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
77 Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document
78 SPObject *root; ///< Our SPRoot
79 CRCascade *style_cascade;
81 gchar *uri; ///< URI string or NULL
82 gchar *base;
83 gchar *name;
85 SPDocumentPrivate *priv;
87 /// Last action key
88 const gchar *actionkey;
89 /// Handler ID
90 guint modified_id;
92 // Instance of the connector router
93 Avoid::Router *router;
95 sigc::connection connectModified(ModifiedSignal::slot_type slot);
96 sigc::connection connectURISet(URISetSignal::slot_type slot);
97 sigc::connection connectResized(ResizedSignal::slot_type slot);
98 sigc::connection connectCommit(CommitSignal::slot_type slot);
100 void bindObjectToId(gchar const *id, SPObject *object);
101 SPObject *getObjectById(gchar const *id);
102 sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
104 void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
105 SPObject *getObjectByRepr(Inkscape::XML::Node *repr);
107 Glib::ustring getLanguage();
109 void queueForOrphanCollection(SPObject *object);
110 void collectOrphans();
112 void _emitModified();
114 GSList *_collection_queue;
116 void addUndoObserver(Inkscape::UndoStackObserver& observer);
117 void removeUndoObserver(Inkscape::UndoStackObserver& observer);
119 bool _updateDocument();
121 /// Are we currently in a transition between two "known good" states of the document?
122 bool isSeeking() const;
124 private:
125 SPDocument(SPDocument const &); // no copy
126 void operator=(SPDocument const &); // no assign
128 public:
129 sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
130 sigc::connection connectReconstructionFinish (ReconstructionFinish::slot_type slot);
131 void emitReconstructionStart (void);
132 void emitReconstructionFinish (void);
134 unsigned long serial() const;
135 void reset_key (void *dummy);
136 sigc::connection _selection_changed_connection;
137 sigc::connection _desktop_activated_connection;
139 void fitToRect(NRRect const & rect);
140 };
142 SPDocument *sp_document_new (const gchar *uri, unsigned int keepalive, bool make_new = false);
143 SPDocument *sp_document_new_from_mem (const gchar *buffer, gint length, unsigned int keepalive);
144 SPDocument *sp_document_new_dummy();
146 SPDocument *sp_document_ref (SPDocument *doc);
147 SPDocument *sp_document_unref (SPDocument *doc);
150 SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
152 /*
153 * Access methods
154 */
156 #define sp_document_repr_doc(d) (d->rdoc)
157 #define sp_document_repr_root(d) (d->rroot)
158 #define sp_document_root(d) (d->root)
159 #define SP_DOCUMENT_ROOT(d) (d->root)
161 gdouble sp_document_width (SPDocument * document);
162 gdouble sp_document_height (SPDocument * document);
164 struct SPUnit;
166 void sp_document_set_width (SPDocument * document, gdouble width, const SPUnit *unit);
167 void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit *unit);
169 #define SP_DOCUMENT_URI(d) (d->uri)
170 #define SP_DOCUMENT_NAME(d) (d->name)
171 #define SP_DOCUMENT_BASE(d) (d->base)
173 /*
174 * Dictionary
175 */
177 /*
178 * Undo & redo
179 */
181 void sp_document_set_undo_sensitive (SPDocument * document, bool sensitive);
182 bool sp_document_get_undo_sensitive (SPDocument const * document);
184 void sp_document_clear_undo (SPDocument * document);
185 void sp_document_clear_redo (SPDocument * document);
187 void sp_document_child_added (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
188 void sp_document_child_removed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
189 void sp_document_attr_changed (SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
190 void sp_document_content_changed (SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
191 void sp_document_order_changed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
193 /* Object modification root handler */
194 void sp_document_request_modified (SPDocument *doc);
195 gint sp_document_ensure_up_to_date (SPDocument *doc);
197 /* Save all previous actions to stack, as one undo step */
198 void sp_document_done (SPDocument *document, unsigned int event_type, Glib::ustring event_description);
199 void sp_document_maybe_done (SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
200 void sp_document_reset_key (Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
202 /* Cancel (and revert) current unsaved actions */
203 void sp_document_cancel (SPDocument *document);
205 /* Undo and redo */
206 gboolean sp_document_undo (SPDocument * document);
207 gboolean sp_document_redo (SPDocument * document);
209 /* Resource management */
210 gboolean sp_document_add_resource (SPDocument *document, const gchar *key, SPObject *object);
211 gboolean sp_document_remove_resource (SPDocument *document, const gchar *key, SPObject *object);
212 const GSList *sp_document_get_resource_list (SPDocument *document, const gchar *key);
213 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
216 /*
217 * Ideas: How to overcome style invalidation nightmare
218 *
219 * 1. There is reference request dictionary, that contains
220 * objects (styles) needing certain id. Object::build checks
221 * final id against it, and invokes necesary methods
222 *
223 * 2. Removing referenced object is simply prohibited -
224 * needs analyse, how we can deal with situations, where
225 * we simply want to ungroup etc. - probably we need
226 * Repr::reparent method :( [Or was it ;)]
227 *
228 */
230 /*
231 * Misc
232 */
234 GSList * sp_document_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
235 GSList * sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
236 SPItem* sp_document_item_from_list_at_point_bottom (unsigned int dkey, SPGroup *group, const GSList *list, NR::Point const p, bool take_insensitive = false);
237 SPItem * sp_document_item_at_point (SPDocument *document, unsigned int key, NR::Point const p, gboolean into_groups, SPItem *upto = NULL);
238 GSList *sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<NR::Point> points);
239 SPItem *sp_document_group_at_point (SPDocument *document, unsigned int key, NR::Point const p);
241 void sp_document_set_uri (SPDocument *document, const gchar *uri);
242 void sp_document_resized_signal_emit (SPDocument *doc, gdouble width, gdouble height);
244 unsigned int vacuum_document (SPDocument *document);
246 #endif