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"
32 namespace Avoid {
33 class Router;
34 }
36 struct NRRect;
37 struct SPDesktop;
38 struct SPItem;
39 struct SPObject;
40 struct SPGroup;
42 namespace Inkscape {
43 struct Application;
44 class Selection;
45 class UndoStackObserver;
46 class EventLog;
47 namespace XML {
48 class Document;
49 class Node;
50 }
51 }
53 class SPDocumentPrivate;
55 /// Typed SVG document implementation.
56 struct SPDocument : public Inkscape::GC::Managed<>,
57 public Inkscape::GC::Finalized,
58 public Inkscape::GC::Anchored
59 {
60 typedef sigc::signal<void, SPObject *> IDChangedSignal;
61 typedef sigc::signal<void> ResourcesChangedSignal;
62 typedef sigc::signal<void, guint> ModifiedSignal;
63 typedef sigc::signal<void, gchar const *> URISetSignal;
64 typedef sigc::signal<void, double, double> ResizedSignal;
65 typedef sigc::signal<void> ReconstructionStart;
66 typedef sigc::signal<void> ReconstructionFinish;
67 typedef sigc::signal<void> CommitSignal;
69 SPDocument();
70 ~SPDocument();
72 unsigned int keepalive : 1;
73 unsigned int virgin : 1; ///< Has the document never been touched?
75 Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
76 Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document
77 SPObject *root; ///< Our SPRoot
78 CRCascade *style_cascade;
80 gchar *uri; ///< URI string or NULL
81 gchar *base;
82 gchar *name;
84 SPDocumentPrivate *priv;
86 /// Last action key
87 const gchar *actionkey;
88 /// Handler ID
89 guint modified_id;
91 // Instance of the connector router
92 Avoid::Router *router;
94 sigc::connection connectModified(ModifiedSignal::slot_type slot);
95 sigc::connection connectURISet(URISetSignal::slot_type slot);
96 sigc::connection connectResized(ResizedSignal::slot_type slot);
97 sigc::connection connectCommit(CommitSignal::slot_type slot);
99 void bindObjectToId(gchar const *id, SPObject *object);
100 SPObject *getObjectById(gchar const *id);
101 sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
103 void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
104 SPObject *getObjectByRepr(Inkscape::XML::Node *repr);
106 Glib::ustring getLanguage();
108 void queueForOrphanCollection(SPObject *object);
109 void collectOrphans();
111 void _emitModified();
113 GSList *_collection_queue;
115 void addUndoObserver(Inkscape::UndoStackObserver& observer);
116 void removeUndoObserver(Inkscape::UndoStackObserver& observer);
118 bool _updateDocument();
120 private:
121 SPDocument(SPDocument const &); // no copy
122 void operator=(SPDocument const &); // no assign
124 public:
125 sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
126 sigc::connection connectReconstructionFinish (ReconstructionFinish::slot_type slot);
127 void emitReconstructionStart (void);
128 void emitReconstructionFinish (void);
130 void reset_key (void *dummy);
131 sigc::connection _selection_changed_connection;
132 sigc::connection _desktop_activated_connection;
134 void fitToRect(NRRect const & rect);
135 };
137 SPDocument *sp_document_new (const gchar *uri, unsigned int keepalive, bool make_new = false);
138 SPDocument *sp_document_new_from_mem (const gchar *buffer, gint length, unsigned int keepalive);
139 SPDocument *sp_document_new_dummy();
141 SPDocument *sp_document_ref (SPDocument *doc);
142 SPDocument *sp_document_unref (SPDocument *doc);
145 SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
147 /*
148 * Access methods
149 */
151 #define sp_document_repr_doc(d) (d->rdoc)
152 #define sp_document_repr_root(d) (d->rroot)
153 #define sp_document_root(d) (d->root)
154 #define SP_DOCUMENT_ROOT(d) (d->root)
156 gdouble sp_document_width (SPDocument * document);
157 gdouble sp_document_height (SPDocument * document);
159 struct SPUnit;
161 void sp_document_set_width (SPDocument * document, gdouble width, const SPUnit *unit);
162 void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit *unit);
164 #define SP_DOCUMENT_URI(d) (d->uri)
165 #define SP_DOCUMENT_NAME(d) (d->name)
166 #define SP_DOCUMENT_BASE(d) (d->base)
168 /*
169 * Dictionary
170 */
172 /*
173 * Undo & redo
174 */
176 void sp_document_set_undo_sensitive (SPDocument * document, bool sensitive);
177 bool sp_document_get_undo_sensitive (SPDocument const * document);
179 void sp_document_clear_undo (SPDocument * document);
180 void sp_document_clear_redo (SPDocument * document);
182 void sp_document_child_added (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
183 void sp_document_child_removed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
184 void sp_document_attr_changed (SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
185 void sp_document_content_changed (SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
186 void sp_document_order_changed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
188 /* Object modification root handler */
189 void sp_document_request_modified (SPDocument *doc);
190 gint sp_document_ensure_up_to_date (SPDocument *doc);
192 /* Save all previous actions to stack, as one undo step */
193 void sp_document_done (SPDocument *document, unsigned int event_type, Glib::ustring event_description);
194 void sp_document_maybe_done (SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
195 void sp_document_reset_key (Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
197 /* Cancel (and revert) current unsaved actions */
198 void sp_document_cancel (SPDocument *document);
200 /* Undo and redo */
201 gboolean sp_document_undo (SPDocument * document);
202 gboolean sp_document_redo (SPDocument * document);
204 /* Resource management */
205 gboolean sp_document_add_resource (SPDocument *document, const gchar *key, SPObject *object);
206 gboolean sp_document_remove_resource (SPDocument *document, const gchar *key, SPObject *object);
207 const GSList *sp_document_get_resource_list (SPDocument *document, const gchar *key);
208 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
211 /*
212 * Ideas: How to overcome style invalidation nightmare
213 *
214 * 1. There is reference request dictionary, that contains
215 * objects (styles) needing certain id. Object::build checks
216 * final id against it, and invokes necesary methods
217 *
218 * 2. Removing referenced object is simply prohibited -
219 * needs analyse, how we can deal with situations, where
220 * we simply want to ungroup etc. - probably we need
221 * Repr::reparent method :( [Or was it ;)]
222 *
223 */
225 /*
226 * Misc
227 */
229 GSList * sp_document_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
230 GSList * sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
231 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);
232 SPItem * sp_document_item_at_point (SPDocument *document, unsigned int key, NR::Point const p, gboolean into_groups, SPItem *upto = NULL);
233 SPItem * sp_document_group_at_point (SPDocument *document, unsigned int key, NR::Point const p);
235 void sp_document_set_uri (SPDocument *document, const gchar *uri);
236 void sp_document_resized_signal_emit (SPDocument *doc, gdouble width, gdouble height);
238 unsigned int vacuum_document (SPDocument *document);
240 #endif