Code

Forced redraw of canvas upon document commit to work around event starvation issue...
[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;
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         Inkscape::EventLog& getEventLog() const;
120         bool _updateDocument();
122 private:
123         SPDocument(SPDocument const &); // no copy
124         void operator=(SPDocument const &); // no assign
126 public:
127         sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
128         sigc::connection connectReconstructionFinish (ReconstructionFinish::slot_type  slot);
129         void emitReconstructionStart (void);
130         void emitReconstructionFinish  (void);
132         void reset_key (void *dummy);
133         sigc::connection _selection_changed_connection;
134         sigc::connection _desktop_activated_connection;
136         void fitToRect(NRRect const & rect);
137 };
139 SPDocument *sp_document_new (const gchar *uri, unsigned int keepalive, bool make_new = false);
140 SPDocument *sp_document_new_from_mem (const gchar *buffer, gint length, unsigned int keepalive);
141 SPDocument *sp_document_new_dummy(); 
143 SPDocument *sp_document_ref (SPDocument *doc);
144 SPDocument *sp_document_unref (SPDocument *doc);
147 SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
149 /*
150  * Access methods
151  */
153 #define sp_document_repr_doc(d) (d->rdoc)
154 #define sp_document_repr_root(d) (d->rroot)
155 #define sp_document_root(d) (d->root)
156 #define SP_DOCUMENT_ROOT(d)  (d->root)
158 gdouble sp_document_width (SPDocument * document);
159 gdouble sp_document_height (SPDocument * document);
161 struct SPUnit;
163 void sp_document_set_width (SPDocument * document, gdouble width, const SPUnit *unit);
164 void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit *unit);
166 #define SP_DOCUMENT_URI(d) (d->uri)
167 #define SP_DOCUMENT_NAME(d) (d->name)
168 #define SP_DOCUMENT_BASE(d) (d->base)
170 /*
171  * Dictionary
172  */
174 /*
175  * Undo & redo
176  */
178 void sp_document_set_undo_sensitive (SPDocument * document, gboolean sensitive);
179 gboolean sp_document_get_undo_sensitive (SPDocument const * document);
181 void sp_document_clear_undo (SPDocument * document);
182 void sp_document_clear_redo (SPDocument * document);
184 void sp_document_child_added (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
185 void sp_document_child_removed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
186 void sp_document_attr_changed (SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
187 void sp_document_content_changed (SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
188 void sp_document_order_changed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
190 /* Object modification root handler */
191 void sp_document_request_modified (SPDocument *doc);
192 gint sp_document_ensure_up_to_date (SPDocument *doc);
194 /* Save all previous actions to stack, as one undo step */
195 void sp_document_done (SPDocument *document, unsigned int event_type, Glib::ustring event_description);
196 void sp_document_maybe_done (SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description);
197 void sp_document_reset_key (Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
199 /* Cancel (and revert) current unsaved actions */
200 void sp_document_cancel (SPDocument *document);
202 /* Undo and redo */
203 gboolean sp_document_undo (SPDocument * document);
204 gboolean sp_document_redo (SPDocument * document);
206 /* Resource management */
207 gboolean sp_document_add_resource (SPDocument *document, const gchar *key, SPObject *object);
208 gboolean sp_document_remove_resource (SPDocument *document, const gchar *key, SPObject *object);
209 const GSList *sp_document_get_resource_list (SPDocument *document, const gchar *key);
210 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
213 /*
214  * Ideas: How to overcome style invalidation nightmare
215  *
216  * 1. There is reference request dictionary, that contains
217  * objects (styles) needing certain id. Object::build checks
218  * final id against it, and invokes necesary methods
219  *
220  * 2. Removing referenced object is simply prohibited -
221  * needs analyse, how we can deal with situations, where
222  * we simply want to ungroup etc. - probably we need
223  * Repr::reparent method :( [Or was it ;)]
224  *
225  */
227 /*
228  * Misc
229  */
231 GSList * sp_document_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
232 GSList * sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
233 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);
234 SPItem * sp_document_item_at_point (SPDocument *document, unsigned int key, NR::Point const p, gboolean into_groups, SPItem *upto = NULL);
235 SPItem * sp_document_group_at_point (SPDocument *document, unsigned int key,  NR::Point const p);
237 void sp_document_set_uri (SPDocument *document, const gchar *uri);
238 void sp_document_resized_signal_emit (SPDocument *doc, gdouble width, gdouble height);
240 unsigned int vacuum_document (SPDocument *document);
242 #endif