Code

SVG 1.1 Conditional Processing Module rendering support (<switch> element, requiredRe...
[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 "libnr/nr-forward.h"
26 #include "gc-managed.h"
27 #include "gc-finalized.h"
28 #include "gc-anchored.h"
29 #include <glibmm/ustring.h>
31 namespace Avoid {
32 class Router;
33 }
35 struct NRRect;
36 struct SPDesktop;
37 struct SPItem;
38 struct SPObject;
39 struct SPGroup;
41 namespace Inkscape {
42     struct Application;
43     class Selection; 
44     class UndoStackObserver;
45     namespace XML {
46         class Document;
47         class Node;
48     }
49 }
51 class SPDocumentPrivate;
53 /// Typed SVG document implementation.
54 struct SPDocument : public Inkscape::GC::Managed<>,
55                     public Inkscape::GC::Finalized,
56                     public Inkscape::GC::Anchored
57 {
58         typedef sigc::signal<void, SPObject *> IDChangedSignal;
59         typedef sigc::signal<void> ResourcesChangedSignal;
60         typedef sigc::signal<void, guint> ModifiedSignal;
61         typedef sigc::signal<void, gchar const *> URISetSignal;
62         typedef sigc::signal<void, double, double> ResizedSignal;
63         typedef sigc::signal<void> ReconstructionStart;
64         typedef sigc::signal<void> ReconstructionFinish;
66         SPDocument();
67         ~SPDocument();
69         unsigned int keepalive : 1;
70         unsigned int virgin    : 1; ///< Has the document never been touched?
72         Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
73         Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document
74         SPObject *root;             ///< Our SPRoot
75         CRCascade *style_cascade;
77         gchar *uri; ///< URI string or NULL
78         gchar *base;
79         gchar *name;
81         SPDocumentPrivate *priv;
83         /// Last action key
84         const gchar *actionkey;
85         /// Handler ID
86         guint modified_id;
88         // Instance of the connector router
89         Avoid::Router *router;
91         sigc::connection connectModified(ModifiedSignal::slot_type slot);
92         sigc::connection connectURISet(URISetSignal::slot_type slot);
93         sigc::connection connectResized(ResizedSignal::slot_type slot);
95         void bindObjectToId(gchar const *id, SPObject *object);
96         SPObject *getObjectById(gchar const *id);
97         sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
99         void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
100         SPObject *getObjectByRepr(Inkscape::XML::Node *repr);
102     Glib::ustring getLanguage();
104         void queueForOrphanCollection(SPObject *object);
105         void collectOrphans();
107         void _emitModified();
109         GSList *_collection_queue;
111         void addUndoObserver(Inkscape::UndoStackObserver& observer);
112         void removeUndoObserver(Inkscape::UndoStackObserver& observer);
114 private:
115         SPDocument(SPDocument const &); // no copy
116         void operator=(SPDocument const &); // no assign
118 public:
119         sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
120         sigc::connection connectReconstructionFinish (ReconstructionFinish::slot_type  slot);
121         void emitReconstructionStart (void);
122         void emitReconstructionFinish  (void);
124         void reset_key (void *dummy);
125         sigc::connection _selection_changed_connection;
126         sigc::connection _desktop_activated_connection;
128         void SPDocument::fitToRect(NRRect const & rect);
129 };
131 SPDocument *sp_document_new (const gchar *uri, unsigned int keepalive, bool make_new = false);
132 SPDocument *sp_document_new_from_mem (const gchar *buffer, gint length, unsigned int keepalive);
133 SPDocument *sp_document_new_dummy(); 
135 SPDocument *sp_document_ref (SPDocument *doc);
136 SPDocument *sp_document_unref (SPDocument *doc);
138 /*
139  * Access methods
140  */
142 #define sp_document_repr_doc(d) (d->rdoc)
143 #define sp_document_repr_root(d) (d->rroot)
144 #define sp_document_root(d) (d->root)
145 #define SP_DOCUMENT_ROOT(d)  (d->root)
147 gdouble sp_document_width (SPDocument * document);
148 gdouble sp_document_height (SPDocument * document);
150 struct SPUnit;
152 void sp_document_set_width (SPDocument * document, gdouble width, const SPUnit *unit);
153 void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit *unit);
155 #define SP_DOCUMENT_URI(d) (d->uri)
156 #define SP_DOCUMENT_NAME(d) (d->name)
157 #define SP_DOCUMENT_BASE(d) (d->base)
159 /*
160  * Dictionary
161  */
163 /*
164  * Undo & redo
165  */
167 void sp_document_set_undo_sensitive (SPDocument * document, gboolean sensitive);
168 gboolean sp_document_get_undo_sensitive (SPDocument const * document);
170 void sp_document_clear_undo (SPDocument * document);
171 void sp_document_clear_redo (SPDocument * document);
173 void sp_document_child_added (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
174 void sp_document_child_removed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
175 void sp_document_attr_changed (SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
176 void sp_document_content_changed (SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
177 void sp_document_order_changed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
179 /* Object modification root handler */
180 void sp_document_request_modified (SPDocument *doc);
181 gint sp_document_ensure_up_to_date (SPDocument *doc);
183 /* Save all previous actions to stack, as one undo step */
184 void sp_document_done (SPDocument *document);
185 void sp_document_maybe_done (SPDocument *document, const gchar *key);
186 void sp_document_reset_key (Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
188 /* Cancel (and revert) current unsaved actions */
189 void sp_document_cancel (SPDocument *document);
191 /* Undo and redo */
192 gboolean sp_document_undo (SPDocument * document);
193 gboolean sp_document_redo (SPDocument * document);
195 /* Resource management */
196 gboolean sp_document_add_resource (SPDocument *document, const gchar *key, SPObject *object);
197 gboolean sp_document_remove_resource (SPDocument *document, const gchar *key, SPObject *object);
198 const GSList *sp_document_get_resource_list (SPDocument *document, const gchar *key);
199 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
202 /*
203  * Ideas: How to overcome style invalidation nightmare
204  *
205  * 1. There is reference request dictionary, that contains
206  * objects (styles) needing certain id. Object::build checks
207  * final id against it, and invokes necesary methods
208  *
209  * 2. Removing referenced object is simply prohibited -
210  * needs analyse, how we can deal with situations, where
211  * we simply want to ungroup etc. - probably we need
212  * Repr::reparent method :( [Or was it ;)]
213  *
214  */
216 /*
217  * Misc
218  */
220 GSList * sp_document_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
221 GSList * sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
222 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);
223 SPItem * sp_document_item_at_point (SPDocument *document, unsigned int key, NR::Point const p, gboolean into_groups, SPItem *upto = NULL);
224 SPItem * sp_document_group_at_point (SPDocument *document, unsigned int key,  NR::Point const p);
226 void sp_document_set_uri (SPDocument *document, const gchar *uri);
227 void sp_document_resized_signal_emit (SPDocument *doc, gdouble width, gdouble height);
229 unsigned int vacuum_document (SPDocument *document);
231 #endif