Code

patch from Gustav Broberg: undo annotations and history dialog
[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"
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;
68         SPDocument();
69         ~SPDocument();
71         unsigned int keepalive : 1;
72         unsigned int virgin    : 1; ///< Has the document never been touched?
74         Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
75         Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document
76         SPObject *root;             ///< Our SPRoot
77         CRCascade *style_cascade;
79         gchar *uri; ///< URI string or NULL
80         gchar *base;
81         gchar *name;
83         SPDocumentPrivate *priv;
85         /// Last action key
86         const gchar *actionkey;
87         /// Handler ID
88         guint modified_id;
90         // Instance of the connector router
91         Avoid::Router *router;
93         sigc::connection connectModified(ModifiedSignal::slot_type slot);
94         sigc::connection connectURISet(URISetSignal::slot_type slot);
95         sigc::connection connectResized(ResizedSignal::slot_type slot);
97         void bindObjectToId(gchar const *id, SPObject *object);
98         SPObject *getObjectById(gchar const *id);
99         sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
101         void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
102         SPObject *getObjectByRepr(Inkscape::XML::Node *repr);
104     Glib::ustring getLanguage();
106         void queueForOrphanCollection(SPObject *object);
107         void collectOrphans();
109         void _emitModified();
111         GSList *_collection_queue;
113         void addUndoObserver(Inkscape::UndoStackObserver& observer);
114         void removeUndoObserver(Inkscape::UndoStackObserver& observer);
116         Inkscape::EventLog& getEventLog() const;
118 private:
119         SPDocument(SPDocument const &); // no copy
120         void operator=(SPDocument const &); // no assign
122 public:
123         sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
124         sigc::connection connectReconstructionFinish (ReconstructionFinish::slot_type  slot);
125         void emitReconstructionStart (void);
126         void emitReconstructionFinish  (void);
128         void reset_key (void *dummy);
129         sigc::connection _selection_changed_connection;
130         sigc::connection _desktop_activated_connection;
132         void fitToRect(NRRect const & rect);
133 };
135 SPDocument *sp_document_new (const gchar *uri, unsigned int keepalive, bool make_new = false);
136 SPDocument *sp_document_new_from_mem (const gchar *buffer, gint length, unsigned int keepalive);
137 SPDocument *sp_document_new_dummy(); 
139 SPDocument *sp_document_ref (SPDocument *doc);
140 SPDocument *sp_document_unref (SPDocument *doc);
143 SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
145 /*
146  * Access methods
147  */
149 #define sp_document_repr_doc(d) (d->rdoc)
150 #define sp_document_repr_root(d) (d->rroot)
151 #define sp_document_root(d) (d->root)
152 #define SP_DOCUMENT_ROOT(d)  (d->root)
154 gdouble sp_document_width (SPDocument * document);
155 gdouble sp_document_height (SPDocument * document);
157 struct SPUnit;
159 void sp_document_set_width (SPDocument * document, gdouble width, const SPUnit *unit);
160 void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit *unit);
162 #define SP_DOCUMENT_URI(d) (d->uri)
163 #define SP_DOCUMENT_NAME(d) (d->name)
164 #define SP_DOCUMENT_BASE(d) (d->base)
166 /*
167  * Dictionary
168  */
170 /*
171  * Undo & redo
172  */
174 void sp_document_set_undo_sensitive (SPDocument * document, gboolean sensitive);
175 gboolean sp_document_get_undo_sensitive (SPDocument const * document);
177 void sp_document_clear_undo (SPDocument * document);
178 void sp_document_clear_redo (SPDocument * document);
180 void sp_document_child_added (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
181 void sp_document_child_removed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
182 void sp_document_attr_changed (SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
183 void sp_document_content_changed (SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
184 void sp_document_order_changed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
186 /* Object modification root handler */
187 void sp_document_request_modified (SPDocument *doc);
188 gint sp_document_ensure_up_to_date (SPDocument *doc);
190 /* Save all previous actions to stack, as one undo step */
191 void sp_document_done (SPDocument *document, unsigned int event_type, Glib::ustring event_description);
192 void sp_document_maybe_done (SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
193 void sp_document_reset_key (Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
195 /* Cancel (and revert) current unsaved actions */
196 void sp_document_cancel (SPDocument *document);
198 /* Undo and redo */
199 gboolean sp_document_undo (SPDocument * document);
200 gboolean sp_document_redo (SPDocument * document);
202 /* Resource management */
203 gboolean sp_document_add_resource (SPDocument *document, const gchar *key, SPObject *object);
204 gboolean sp_document_remove_resource (SPDocument *document, const gchar *key, SPObject *object);
205 const GSList *sp_document_get_resource_list (SPDocument *document, const gchar *key);
206 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
209 /*
210  * Ideas: How to overcome style invalidation nightmare
211  *
212  * 1. There is reference request dictionary, that contains
213  * objects (styles) needing certain id. Object::build checks
214  * final id against it, and invokes necesary methods
215  *
216  * 2. Removing referenced object is simply prohibited -
217  * needs analyse, how we can deal with situations, where
218  * we simply want to ungroup etc. - probably we need
219  * Repr::reparent method :( [Or was it ;)]
220  *
221  */
223 /*
224  * Misc
225  */
227 GSList * sp_document_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
228 GSList * sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
229 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);
230 SPItem * sp_document_item_at_point (SPDocument *document, unsigned int key, NR::Point const p, gboolean into_groups, SPItem *upto = NULL);
231 SPItem * sp_document_group_at_point (SPDocument *document, unsigned int key,  NR::Point const p);
233 void sp_document_set_uri (SPDocument *document, const gchar *uri);
234 void sp_document_resized_signal_emit (SPDocument *doc, gdouble width, gdouble height);
236 unsigned int vacuum_document (SPDocument *document);
238 #endif