Code

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