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 void reset_key (void *dummy);
135 sigc::connection _selection_changed_connection;
136 sigc::connection _desktop_activated_connection;
138 void fitToRect(NRRect const & rect);
139 };
141 SPDocument *sp_document_new (const gchar *uri, unsigned int keepalive, bool make_new = false);
142 SPDocument *sp_document_new_from_mem (const gchar *buffer, gint length, unsigned int keepalive);
143 SPDocument *sp_document_new_dummy();
145 SPDocument *sp_document_ref (SPDocument *doc);
146 SPDocument *sp_document_unref (SPDocument *doc);
149 SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
151 /*
152 * Access methods
153 */
155 #define sp_document_repr_doc(d) (d->rdoc)
156 #define sp_document_repr_root(d) (d->rroot)
157 #define sp_document_root(d) (d->root)
158 #define SP_DOCUMENT_ROOT(d) (d->root)
160 gdouble sp_document_width (SPDocument * document);
161 gdouble sp_document_height (SPDocument * document);
163 struct SPUnit;
165 void sp_document_set_width (SPDocument * document, gdouble width, const SPUnit *unit);
166 void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit *unit);
168 #define SP_DOCUMENT_URI(d) (d->uri)
169 #define SP_DOCUMENT_NAME(d) (d->name)
170 #define SP_DOCUMENT_BASE(d) (d->base)
172 /*
173 * Dictionary
174 */
176 /*
177 * Undo & redo
178 */
180 void sp_document_set_undo_sensitive (SPDocument * document, bool sensitive);
181 bool sp_document_get_undo_sensitive (SPDocument const * document);
183 void sp_document_clear_undo (SPDocument * document);
184 void sp_document_clear_redo (SPDocument * document);
186 void sp_document_child_added (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
187 void sp_document_child_removed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
188 void sp_document_attr_changed (SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
189 void sp_document_content_changed (SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
190 void sp_document_order_changed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
192 /* Object modification root handler */
193 void sp_document_request_modified (SPDocument *doc);
194 gint sp_document_ensure_up_to_date (SPDocument *doc);
196 /* Save all previous actions to stack, as one undo step */
197 void sp_document_done (SPDocument *document, unsigned int event_type, Glib::ustring event_description);
198 void sp_document_maybe_done (SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
199 void sp_document_reset_key (Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
201 /* Cancel (and revert) current unsaved actions */
202 void sp_document_cancel (SPDocument *document);
204 /* Undo and redo */
205 gboolean sp_document_undo (SPDocument * document);
206 gboolean sp_document_redo (SPDocument * document);
208 /* Resource management */
209 gboolean sp_document_add_resource (SPDocument *document, const gchar *key, SPObject *object);
210 gboolean sp_document_remove_resource (SPDocument *document, const gchar *key, SPObject *object);
211 const GSList *sp_document_get_resource_list (SPDocument *document, const gchar *key);
212 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
215 /*
216 * Ideas: How to overcome style invalidation nightmare
217 *
218 * 1. There is reference request dictionary, that contains
219 * objects (styles) needing certain id. Object::build checks
220 * final id against it, and invokes necesary methods
221 *
222 * 2. Removing referenced object is simply prohibited -
223 * needs analyse, how we can deal with situations, where
224 * we simply want to ungroup etc. - probably we need
225 * Repr::reparent method :( [Or was it ;)]
226 *
227 */
229 /*
230 * Misc
231 */
233 GSList * sp_document_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
234 GSList * sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
235 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);
236 SPItem * sp_document_item_at_point (SPDocument *document, unsigned int key, NR::Point const p, gboolean into_groups, SPItem *upto = NULL);
237 GSList *sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<NR::Point> points);
238 SPItem *sp_document_group_at_point (SPDocument *document, unsigned int key, NR::Point const p);
240 void sp_document_set_uri (SPDocument *document, const gchar *uri);
241 void sp_document_resized_signal_emit (SPDocument *doc, gdouble width, gdouble height);
243 unsigned int vacuum_document (SPDocument *document);
245 #endif