Code

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