Code

fff3289ddbfc5489924fdafbad1d73001e756e66
[inkscape.git] / src / document.h
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/rect.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 Geom {
45     class Point;
46 }
48 namespace Inkscape {
49     struct Application;
50     class Selection; 
51     class UndoStackObserver;
52     class EventLog;
53     class ProfileManager;
54     namespace XML {
55         class Document;
56         class Node;
57     }
58 }
60 class SP3DBox;
61 class Persp3D;
63 namespace Proj {
64   class TransfMat3x4;
65 }
67 class SPDocumentPrivate;
69 /// Typed SVG document implementation.
70 struct SPDocument : public Inkscape::GC::Managed<>,
71                     public Inkscape::GC::Finalized,
72                     public Inkscape::GC::Anchored
73 {
74     typedef sigc::signal<void, SPObject *> IDChangedSignal;
75     typedef sigc::signal<void> ResourcesChangedSignal;
76     typedef sigc::signal<void, guint> ModifiedSignal;
77     typedef sigc::signal<void, gchar const *> URISetSignal;
78     typedef sigc::signal<void, double, double> ResizedSignal;
79     typedef sigc::signal<void> ReconstructionStart;
80     typedef sigc::signal<void> ReconstructionFinish;
81     typedef sigc::signal<void> CommitSignal;
83     SPDocument();
84     virtual ~SPDocument();
86     unsigned int keepalive : 1;
87     unsigned int virgin    : 1; ///< Has the document never been touched?
88     unsigned int modified_since_save : 1;
90     Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
91     Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document
92     SPObject *root;             ///< Our SPRoot
93     CRCascade *style_cascade;
95     gchar *uri; ///< URI string or NULL
96     gchar *base;
97     gchar *name;
99     SPDocumentPrivate *priv;
101     /// Last action key
102     const gchar *actionkey;
103     /// Handler ID
104     guint modified_id;
106     Inkscape::ProfileManager* profileManager;
108     // Instance of the connector router
109     Avoid::Router *router;
111     GSList *perspectives;
113     Persp3D *current_persp3d; // "currently active" perspective (e.g., newly created boxes are attached to this one)
115     GSList *_collection_queue;
117     void add_persp3d (Persp3D * const persp);
118     void remove_persp3d (Persp3D * const persp);
120     sigc::connection connectModified(ModifiedSignal::slot_type slot);
121     sigc::connection connectURISet(URISetSignal::slot_type slot);
122     sigc::connection connectResized(ResizedSignal::slot_type slot);
123 sigc::connection connectCommit(CommitSignal::slot_type slot);
125     void bindObjectToId(gchar const *id, SPObject *object);
126     SPObject *getObjectById(gchar const *id);
127     sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
129     void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
130     SPObject *getObjectByRepr(Inkscape::XML::Node *repr);
132     Glib::ustring getLanguage();
134     void queueForOrphanCollection(SPObject *object);
135     void collectOrphans();
137     void _emitModified();
139     void addUndoObserver(Inkscape::UndoStackObserver& observer);
140     void removeUndoObserver(Inkscape::UndoStackObserver& observer);
142     bool _updateDocument();
144     /// Are we currently in a transition between two "known good" states of the document?
145     bool isSeeking() const;
147     bool isModifiedSinceSave() const { return modified_since_save; }
148     void setModifiedSinceSave(bool modified = true) {
149         modified_since_save = modified;
150     }
152 private:
153     SPDocument(SPDocument const &); // no copy
154     void operator=(SPDocument const &); // no assign
156 public:
157     sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
158     sigc::connection connectReconstructionFinish (ReconstructionFinish::slot_type  slot);
159     void emitReconstructionStart (void);
160     void emitReconstructionFinish  (void);
162     unsigned long serial() const;
163     void reset_key (void *dummy);
164     sigc::connection _selection_changed_connection;
165     sigc::connection _desktop_activated_connection;
167     void fitToRect(Geom::Rect const &rect);
168 };
170 SPDocument *sp_document_new (const gchar *uri, unsigned int keepalive, bool make_new = false);
171 SPDocument *sp_document_new_from_mem (const gchar *buffer, gint length, unsigned int keepalive);
173 SPDocument *sp_document_ref (SPDocument *doc);
174 SPDocument *sp_document_unref (SPDocument *doc);
177 SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
179 /*
180  * Access methods
181  */
183 #define sp_document_repr_doc(d) (d->rdoc)
184 #define sp_document_repr_root(d) (d->rroot)
185 #define sp_document_root(d) (d->root)
186 #define SP_DOCUMENT_ROOT(d)  (d->root)
188 gdouble sp_document_width (SPDocument * document);
189 gdouble sp_document_height (SPDocument * document);
191 struct SPUnit;
193 void sp_document_set_width (SPDocument * document, gdouble width, const SPUnit *unit);
194 void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit *unit);
196 #define SP_DOCUMENT_URI(d) (d->uri)
197 #define SP_DOCUMENT_NAME(d) (d->name)
198 #define SP_DOCUMENT_BASE(d) (d->base)
200 /*
201  * Dictionary
202  */
204 /*
205  * Undo & redo
206  */
208 void sp_document_set_undo_sensitive (SPDocument * document, bool sensitive);
209 bool sp_document_get_undo_sensitive (SPDocument const * document);
211 void sp_document_clear_undo (SPDocument * document);
212 void sp_document_clear_redo (SPDocument * document);
214 void sp_document_child_added (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
215 void sp_document_child_removed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
216 void sp_document_attr_changed (SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
217 void sp_document_content_changed (SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
218 void sp_document_order_changed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
220 /* Object modification root handler */
221 void sp_document_request_modified (SPDocument *doc);
222 gint sp_document_ensure_up_to_date (SPDocument *doc);
224 /* Save all previous actions to stack, as one undo step */
225 void sp_document_done (SPDocument *document, unsigned int event_type, Glib::ustring event_description);
226 void sp_document_maybe_done (SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
227 void sp_document_reset_key (Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
229 /* Cancel (and revert) current unsaved actions */
230 void sp_document_cancel (SPDocument *document);
232 /* Undo and redo */
233 gboolean sp_document_undo (SPDocument * document);
234 gboolean sp_document_redo (SPDocument * document);
236 /* Resource management */
237 gboolean sp_document_add_resource (SPDocument *document, const gchar *key, SPObject *object);
238 gboolean sp_document_remove_resource (SPDocument *document, const gchar *key, SPObject *object);
239 const GSList *sp_document_get_resource_list (SPDocument *document, const gchar *key);
240 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
243 /*
244  * Ideas: How to overcome style invalidation nightmare
245  *
246  * 1. There is reference request dictionary, that contains
247  * objects (styles) needing certain id. Object::build checks
248  * final id against it, and invokes necesary methods
249  *
250  * 2. Removing referenced object is simply prohibited -
251  * needs analyse, how we can deal with situations, where
252  * we simply want to ungroup etc. - probably we need
253  * Repr::reparent method :( [Or was it ;)]
254  *
255  */
257 /*
258  * Misc
259  */
261 GSList * sp_document_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
262 GSList * sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, Geom::Rect const &box);
263 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);
264 SPItem * sp_document_item_at_point (SPDocument *document, unsigned int key, Geom::Point const p, gboolean into_groups, SPItem *upto = NULL);
265 GSList *sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<Geom::Point> points);
266 SPItem *sp_document_group_at_point (SPDocument *document, unsigned int key,  Geom::Point const p);
268 void sp_document_set_uri (SPDocument *document, const gchar *uri);
269 void sp_document_resized_signal_emit (SPDocument *doc, gdouble width, gdouble height);
271 unsigned int vacuum_document (SPDocument *document);
273 #endif
275 /*
276   Local Variables:
277   mode:c++
278   c-file-style:"stroustrup"
279   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
280   indent-tabs-mode:nil
281   fill-column:99
282   End:
283 */
284 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :