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"
30 struct SPDesktop;
31 struct SPItem;
32 struct SPObject;
33 struct SPGroup;
35 namespace Inkscape {
36 struct Application;
37 class Selection;
38 class UndoStackObserver;
39 namespace XML {
40 class Document;
41 class Node;
42 }
43 }
45 class SPDocumentPrivate;
47 /// Typed SVG document implementation.
48 struct SPDocument : public Inkscape::GC::Managed<>,
49 public Inkscape::GC::Finalized,
50 public Inkscape::GC::Anchored
51 {
52 typedef sigc::signal<void, SPObject *> IDChangedSignal;
53 typedef sigc::signal<void> ResourcesChangedSignal;
54 typedef sigc::signal<void, guint> ModifiedSignal;
55 typedef sigc::signal<void, gchar const *> URISetSignal;
56 typedef sigc::signal<void, double, double> ResizedSignal;
57 typedef sigc::signal<void> ReconstructionStart;
58 typedef sigc::signal<void> ReconstructionFinish;
60 SPDocument();
61 ~SPDocument();
63 unsigned int keepalive : 1;
64 unsigned int virgin : 1; ///< Has the document never been touched?
66 Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document
67 Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document
68 SPObject *root; ///< Our SPRoot
69 CRCascade *style_cascade;
71 gchar *uri; ///< URI string or NULL
72 gchar *base;
73 gchar *name;
75 SPDocumentPrivate *priv;
77 /// Last action key
78 const gchar *actionkey;
79 /// Handler ID
80 guint modified_id;
82 sigc::connection connectModified(ModifiedSignal::slot_type slot);
83 sigc::connection connectURISet(URISetSignal::slot_type slot);
84 sigc::connection connectResized(ResizedSignal::slot_type slot);
86 void bindObjectToId(gchar const *id, SPObject *object);
87 SPObject *getObjectById(gchar const *id);
88 sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot);
90 void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object);
91 SPObject *getObjectByRepr(Inkscape::XML::Node *repr);
93 void queueForOrphanCollection(SPObject *object);
94 void collectOrphans();
96 void _emitModified();
98 GSList *_collection_queue;
100 void addUndoObserver(Inkscape::UndoStackObserver& observer);
101 void removeUndoObserver(Inkscape::UndoStackObserver& observer);
103 private:
104 SPDocument(SPDocument const &); // no copy
105 void operator=(SPDocument const &); // no assign
107 public:
108 sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot);
109 sigc::connection connectReconstructionFinish (ReconstructionFinish::slot_type slot);
110 void emitReconstructionStart (void);
111 void emitReconstructionFinish (void);
113 void reset_key (void *dummy);
114 sigc::connection _selection_changed_connection;
115 sigc::connection _desktop_activated_connection;
116 };
118 SPDocument *sp_document_new (const gchar *uri, unsigned int keepalive, bool make_new = false);
119 SPDocument *sp_document_new_from_mem (const gchar *buffer, gint length, unsigned int keepalive);
120 SPDocument *sp_document_new_dummy();
122 SPDocument *sp_document_ref (SPDocument *doc);
123 SPDocument *sp_document_unref (SPDocument *doc);
125 /*
126 * Access methods
127 */
129 #define sp_document_repr_doc(d) (d->rdoc)
130 #define sp_document_repr_root(d) (d->rroot)
131 #define sp_document_root(d) (d->root)
132 #define SP_DOCUMENT_ROOT(d) (d->root)
134 gdouble sp_document_width (SPDocument * document);
135 gdouble sp_document_height (SPDocument * document);
137 struct SPUnit;
139 void sp_document_set_width (SPDocument * document, gdouble width, const SPUnit *unit);
140 void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit *unit);
142 #define SP_DOCUMENT_URI(d) (d->uri)
143 #define SP_DOCUMENT_NAME(d) (d->name)
144 #define SP_DOCUMENT_BASE(d) (d->base)
146 /*
147 * Dictionary
148 */
150 /*
151 * Undo & redo
152 */
154 void sp_document_set_undo_sensitive (SPDocument * document, gboolean sensitive);
155 gboolean sp_document_get_undo_sensitive (SPDocument const * document);
157 void sp_document_clear_undo (SPDocument * document);
158 void sp_document_clear_redo (SPDocument * document);
160 void sp_document_child_added (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
161 void sp_document_child_removed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
162 void sp_document_attr_changed (SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
163 void sp_document_content_changed (SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
164 void sp_document_order_changed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
166 /* Object modification root handler */
167 void sp_document_request_modified (SPDocument *doc);
168 gint sp_document_ensure_up_to_date (SPDocument *doc);
170 /* Save all previous actions to stack, as one undo step */
171 void sp_document_done (SPDocument *document);
172 void sp_document_maybe_done (SPDocument *document, const gchar *key);
173 void sp_document_reset_key (Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
175 /* Cancel (and revert) current unsaved actions */
176 void sp_document_cancel (SPDocument *document);
178 /* Undo and redo */
179 gboolean sp_document_undo (SPDocument * document);
180 gboolean sp_document_redo (SPDocument * document);
182 /* Resource management */
183 gboolean sp_document_add_resource (SPDocument *document, const gchar *key, SPObject *object);
184 gboolean sp_document_remove_resource (SPDocument *document, const gchar *key, SPObject *object);
185 const GSList *sp_document_get_resource_list (SPDocument *document, const gchar *key);
186 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
189 /*
190 * Ideas: How to overcome style invalidation nightmare
191 *
192 * 1. There is reference request dictionary, that contains
193 * objects (styles) needing certain id. Object::build checks
194 * final id against it, and invokes necesary methods
195 *
196 * 2. Removing referenced object is simply prohibited -
197 * needs analyse, how we can deal with situations, where
198 * we simply want to ungroup etc. - probably we need
199 * Repr::reparent method :( [Or was it ;)]
200 *
201 */
203 /*
204 * Misc
205 */
207 GSList * sp_document_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
208 GSList * sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
209 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);
210 SPItem * sp_document_item_at_point (SPDocument *document, unsigned int key, NR::Point const p, gboolean into_groups, SPItem *upto = NULL);
211 SPItem * sp_document_group_at_point (SPDocument *document, unsigned int key, NR::Point const p);
213 void sp_document_set_uri (SPDocument *document, const gchar *uri);
214 void sp_document_resized_signal_emit (SPDocument *doc, gdouble width, gdouble height);
216 unsigned int vacuum_document (SPDocument *document);
218 #endif