Code

Adding profile manager and user-visible drop-down in CMS picker
[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>
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     class ProfileManager;
49     namespace XML {
50         class Document;
51         class Node;
52     }
53 }
55 class SP3DBox;
57 namespace Box3D {
58   class Perspective3D;
59   class VanishingPoint;
60 }
62 class SPDocumentPrivate;
64 /// Typed SVG document implementation.
65 struct SPDocument : public Inkscape::GC::Managed<>,
66                     public Inkscape::GC::Finalized,
67                     public Inkscape::GC::Anchored
68 {
69         typedef sigc::signal<void, SPObject *> IDChangedSignal;
70         typedef sigc::signal<void> ResourcesChangedSignal;
71         typedef sigc::signal<void, guint> ModifiedSignal;
72         typedef sigc::signal<void, gchar const *> URISetSignal;
73         typedef sigc::signal<void, double, double> ResizedSignal;
74         typedef sigc::signal<void> ReconstructionStart;
75         typedef sigc::signal<void> ReconstructionFinish;
76   typedef sigc::signal<void> CommitSignal;
78         SPDocument();
79         ~SPDocument();
81         unsigned int keepalive : 1;
82         unsigned int virgin    : 1; ///< Has the document never been touched?
84         Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
85         Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document
86         SPObject *root;             ///< Our SPRoot
87         CRCascade *style_cascade;
89         gchar *uri; ///< URI string or NULL
90         gchar *base;
91         gchar *name;
93         SPDocumentPrivate *priv;
95         /// Last action key
96         const gchar *actionkey;
97         /// Handler ID
98         guint modified_id;
100     Inkscape::ProfileManager* profileManager;
102         // Instance of the connector router
103         Avoid::Router *router;
105         GSList *perspectives;
106         Box3D::Perspective3D *current_perspective;
108         // FIXME: Perspectives should be linked to the list of existing ones automatically in the constructor
109         //        and removed in the destructor!
110         void add_perspective (Box3D::Perspective3D * const persp);
111         void remove_perspective (Box3D::Perspective3D * const persp);
112         /* find an existing perspective whose VPs are equal to those of persp */
113         Box3D::Perspective3D * find_perspective (const Box3D::Perspective3D * persp);
115         Box3D::Perspective3D * get_persp_of_box (const SP3DBox *box);
116         Box3D::Perspective3D * get_persp_of_VP (const Box3D::VanishingPoint *vp);
118         sigc::connection connectModified(ModifiedSignal::slot_type slot);
119         sigc::connection connectURISet(URISetSignal::slot_type slot);
120         sigc::connection connectResized(ResizedSignal::slot_type slot);
121   sigc::connection connectCommit(CommitSignal::slot_type slot);
123         void bindObjectToId(gchar const *id, SPObject *object);
124         SPObject *getObjectById(gchar const *id);
125         sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
127         void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
128         SPObject *getObjectByRepr(Inkscape::XML::Node *repr);
130     Glib::ustring getLanguage();
132         void queueForOrphanCollection(SPObject *object);
133         void collectOrphans();
135         void _emitModified();
137         GSList *_collection_queue;
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 private:
148         SPDocument(SPDocument const &); // no copy
149         void operator=(SPDocument const &); // no assign
151 public:
152         sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
153         sigc::connection connectReconstructionFinish (ReconstructionFinish::slot_type  slot);
154         void emitReconstructionStart (void);
155         void emitReconstructionFinish  (void);
157         unsigned long serial() const;
158         void reset_key (void *dummy);
159         sigc::connection _selection_changed_connection;
160         sigc::connection _desktop_activated_connection;
162         void fitToRect(NR::Rect const &rect);
163 };
165 SPDocument *sp_document_new (const gchar *uri, unsigned int keepalive, bool make_new = false);
166 SPDocument *sp_document_new_from_mem (const gchar *buffer, gint length, unsigned int keepalive);
168 SPDocument *sp_document_ref (SPDocument *doc);
169 SPDocument *sp_document_unref (SPDocument *doc);
172 SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
174 /*
175  * Access methods
176  */
178 #define sp_document_repr_doc(d) (d->rdoc)
179 #define sp_document_repr_root(d) (d->rroot)
180 #define sp_document_root(d) (d->root)
181 #define SP_DOCUMENT_ROOT(d)  (d->root)
183 gdouble sp_document_width (SPDocument * document);
184 gdouble sp_document_height (SPDocument * document);
186 struct SPUnit;
188 void sp_document_set_width (SPDocument * document, gdouble width, const SPUnit *unit);
189 void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit *unit);
191 #define SP_DOCUMENT_URI(d) (d->uri)
192 #define SP_DOCUMENT_NAME(d) (d->name)
193 #define SP_DOCUMENT_BASE(d) (d->base)
195 /*
196  * Dictionary
197  */
199 /*
200  * Undo & redo
201  */
203 void sp_document_set_undo_sensitive (SPDocument * document, bool sensitive);
204 bool sp_document_get_undo_sensitive (SPDocument const * document);
206 void sp_document_clear_undo (SPDocument * document);
207 void sp_document_clear_redo (SPDocument * document);
209 void sp_document_child_added (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
210 void sp_document_child_removed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
211 void sp_document_attr_changed (SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
212 void sp_document_content_changed (SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
213 void sp_document_order_changed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
215 /* Object modification root handler */
216 void sp_document_request_modified (SPDocument *doc);
217 gint sp_document_ensure_up_to_date (SPDocument *doc);
219 /* Save all previous actions to stack, as one undo step */
220 void sp_document_done (SPDocument *document, unsigned int event_type, Glib::ustring event_description);
221 void sp_document_maybe_done (SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
222 void sp_document_reset_key (Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
224 /* Cancel (and revert) current unsaved actions */
225 void sp_document_cancel (SPDocument *document);
227 /* Undo and redo */
228 gboolean sp_document_undo (SPDocument * document);
229 gboolean sp_document_redo (SPDocument * document);
231 /* Resource management */
232 gboolean sp_document_add_resource (SPDocument *document, const gchar *key, SPObject *object);
233 gboolean sp_document_remove_resource (SPDocument *document, const gchar *key, SPObject *object);
234 const GSList *sp_document_get_resource_list (SPDocument *document, const gchar *key);
235 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
238 /*
239  * Ideas: How to overcome style invalidation nightmare
240  *
241  * 1. There is reference request dictionary, that contains
242  * objects (styles) needing certain id. Object::build checks
243  * final id against it, and invokes necesary methods
244  *
245  * 2. Removing referenced object is simply prohibited -
246  * needs analyse, how we can deal with situations, where
247  * we simply want to ungroup etc. - probably we need
248  * Repr::reparent method :( [Or was it ;)]
249  *
250  */
252 /*
253  * Misc
254  */
256 GSList * sp_document_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
257 GSList * sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
258 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);
259 SPItem * sp_document_item_at_point (SPDocument *document, unsigned int key, NR::Point const p, gboolean into_groups, SPItem *upto = NULL);
260 GSList *sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector<NR::Point> points);
261 SPItem *sp_document_group_at_point (SPDocument *document, unsigned int key,  NR::Point const p);
263 void sp_document_set_uri (SPDocument *document, const gchar *uri);
264 void sp_document_resized_signal_emit (SPDocument *doc, gdouble width, gdouble height);
266 unsigned int vacuum_document (SPDocument *document);
268 #endif