Code

restored pedro/work and added it to make.exclude
[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 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);
139 SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive);
141 /*
142  * Access methods
143  */
145 #define sp_document_repr_doc(d) (d->rdoc)
146 #define sp_document_repr_root(d) (d->rroot)
147 #define sp_document_root(d) (d->root)
148 #define SP_DOCUMENT_ROOT(d)  (d->root)
150 gdouble sp_document_width (SPDocument * document);
151 gdouble sp_document_height (SPDocument * document);
153 struct SPUnit;
155 void sp_document_set_width (SPDocument * document, gdouble width, const SPUnit *unit);
156 void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit *unit);
158 #define SP_DOCUMENT_URI(d) (d->uri)
159 #define SP_DOCUMENT_NAME(d) (d->name)
160 #define SP_DOCUMENT_BASE(d) (d->base)
162 /*
163  * Dictionary
164  */
166 /*
167  * Undo & redo
168  */
170 void sp_document_set_undo_sensitive (SPDocument * document, gboolean sensitive);
171 gboolean sp_document_get_undo_sensitive (SPDocument const * document);
173 void sp_document_clear_undo (SPDocument * document);
174 void sp_document_clear_redo (SPDocument * document);
176 void sp_document_child_added (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
177 void sp_document_child_removed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref);
178 void sp_document_attr_changed (SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval);
179 void sp_document_content_changed (SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent);
180 void sp_document_order_changed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref);
182 /* Object modification root handler */
183 void sp_document_request_modified (SPDocument *doc);
184 gint sp_document_ensure_up_to_date (SPDocument *doc);
186 /* Save all previous actions to stack, as one undo step */
187 void sp_document_done (SPDocument *document);
188 void sp_document_maybe_done (SPDocument *document, const gchar *key);
189 void sp_document_reset_key (Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base);
191 /* Cancel (and revert) current unsaved actions */
192 void sp_document_cancel (SPDocument *document);
194 /* Undo and redo */
195 gboolean sp_document_undo (SPDocument * document);
196 gboolean sp_document_redo (SPDocument * document);
198 /* Resource management */
199 gboolean sp_document_add_resource (SPDocument *document, const gchar *key, SPObject *object);
200 gboolean sp_document_remove_resource (SPDocument *document, const gchar *key, SPObject *object);
201 const GSList *sp_document_get_resource_list (SPDocument *document, const gchar *key);
202 sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot);
205 /*
206  * Ideas: How to overcome style invalidation nightmare
207  *
208  * 1. There is reference request dictionary, that contains
209  * objects (styles) needing certain id. Object::build checks
210  * final id against it, and invokes necesary methods
211  *
212  * 2. Removing referenced object is simply prohibited -
213  * needs analyse, how we can deal with situations, where
214  * we simply want to ungroup etc. - probably we need
215  * Repr::reparent method :( [Or was it ;)]
216  *
217  */
219 /*
220  * Misc
221  */
223 GSList * sp_document_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
224 GSList * sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box);
225 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);
226 SPItem * sp_document_item_at_point (SPDocument *document, unsigned int key, NR::Point const p, gboolean into_groups, SPItem *upto = NULL);
227 SPItem * sp_document_group_at_point (SPDocument *document, unsigned int key,  NR::Point const p);
229 void sp_document_set_uri (SPDocument *document, const gchar *uri);
230 void sp_document_resized_signal_emit (SPDocument *doc, gdouble width, gdouble height);
232 unsigned int vacuum_document (SPDocument *document);
234 #endif