X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fdocument.h;h=82c874cb73678f284b2e62e67dad2d7efdd93e9e;hb=8680124aec2da49c3e34695c68840387511f78bf;hp=16300d170e1fa2a749c4385bd79ab8fa9d208bd8;hpb=cb1523c9f62c56c95670d52e638ccd451e7fd8a3;p=inkscape.git diff --git a/src/document.h b/src/document.h index 16300d170..82c874cb7 100644 --- a/src/document.h +++ b/src/document.h @@ -1,12 +1,14 @@ -#ifndef __SP_DOCUMENT_H__ -#define __SP_DOCUMENT_H__ +#ifndef SEEN_SP_DOCUMENT_H +#define SEEN_SP_DOCUMENT_H /** \file * SPDocument: Typed SVG document implementation - * - * Authors: + */ +/* Authors: * Lauris Kaplinski * MenTaLguY + * Jon A. Cruz + * Abhishek Sharma * * Copyright (C) 2004-2005 MenTaLguY * Copyright (C) 1999-2002 Lauris Kaplinski @@ -21,14 +23,16 @@ #include #include "libcroco/cr-cascade.h" -#include "libnr/nr-forward.h" +#include <2geom/forward.h> #include "gc-managed.h" #include "gc-finalized.h" #include "gc-anchored.h" #include #include "verbs.h" +#include "document-undo.h" #include +#include namespace Avoid { class Router; @@ -45,172 +49,207 @@ namespace Inkscape { class Selection; class UndoStackObserver; class EventLog; + class ProfileManager; namespace XML { class Document; class Node; } } +class SP3DBox; +class Persp3D; +class Persp3DImpl; + +namespace Proj { + class TransfMat3x4; +} + class SPDocumentPrivate; /// Typed SVG document implementation. -struct SPDocument : public Inkscape::GC::Managed<>, +class SPDocument : public Inkscape::GC::Managed<>, public Inkscape::GC::Finalized, - public Inkscape::GC::Anchored + public Inkscape::GC::Anchored { - typedef sigc::signal IDChangedSignal; - typedef sigc::signal ResourcesChangedSignal; - typedef sigc::signal ModifiedSignal; - typedef sigc::signal URISetSignal; - typedef sigc::signal ResizedSignal; - typedef sigc::signal ReconstructionStart; - typedef sigc::signal ReconstructionFinish; - typedef sigc::signal CommitSignal; - - SPDocument(); - ~SPDocument(); - - unsigned int keepalive : 1; - unsigned int virgin : 1; ///< Has the document never been touched? - - Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document - Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document - SPObject *root; ///< Our SPRoot - CRCascade *style_cascade; - - gchar *uri; ///< URI string or NULL - gchar *base; - gchar *name; - - SPDocumentPrivate *priv; - - /// Last action key - const gchar *actionkey; - /// Handler ID - guint modified_id; - - // Instance of the connector router - Avoid::Router *router; - - sigc::connection connectModified(ModifiedSignal::slot_type slot); - sigc::connection connectURISet(URISetSignal::slot_type slot); - sigc::connection connectResized(ResizedSignal::slot_type slot); - sigc::connection connectCommit(CommitSignal::slot_type slot); +public: + typedef sigc::signal IDChangedSignal; + typedef sigc::signal ResourcesChangedSignal; + typedef sigc::signal ModifiedSignal; + typedef sigc::signal URISetSignal; + typedef sigc::signal ResizedSignal; + typedef sigc::signal ReconstructionStart; + typedef sigc::signal ReconstructionFinish; + typedef sigc::signal CommitSignal; + + SPDocument(); + virtual ~SPDocument(); + + unsigned int keepalive : 1; + unsigned int virgin : 1; ///< Has the document never been touched? + unsigned int modified_since_save : 1; + + Inkscape::XML::Document *rdoc; ///< Our Inkscape::XML::Document + Inkscape::XML::Node *rroot; ///< Root element of Inkscape::XML::Document + SPObject *root; ///< Our SPRoot + CRCascade *style_cascade; + +protected: + gchar *uri; ///< A filename (not a URI yet), or NULL + gchar *base; ///< To be used for resolving relative hrefs. + gchar *name; ///< basename(uri) or other human-readable label for the document. - void bindObjectToId(gchar const *id, SPObject *object); - SPObject *getObjectById(gchar const *id); - sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot); +public: - void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object); - SPObject *getObjectByRepr(Inkscape::XML::Node *repr); + SPDocumentPrivate *priv; - Glib::ustring getLanguage(); + /// Last action key + Glib::ustring actionkey; - void queueForOrphanCollection(SPObject *object); - void collectOrphans(); + /// Handler ID + guint modified_id; + + /// Connector rerouting handler ID + guint rerouting_handler_id; - void _emitModified(); + Inkscape::ProfileManager* profileManager; - GSList *_collection_queue; + // Instance of the connector router + Avoid::Router *router; - void addUndoObserver(Inkscape::UndoStackObserver& observer); - void removeUndoObserver(Inkscape::UndoStackObserver& observer); + GSList *_collection_queue; - bool _updateDocument(); + bool oldSignalsConnected; - /// Are we currently in a transition between two "known good" states of the document? - bool isSeeking() const; + /** Returns our SPRoot */ + SPObject *getRoot() { return root; } -private: - SPDocument(SPDocument const &); // no copy - void operator=(SPDocument const &); // no assign + Inkscape::XML::Node *getReprRoot() { return rroot; } -public: - sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot); - sigc::connection connectReconstructionFinish (ReconstructionFinish::slot_type slot); - void emitReconstructionStart (void); - void emitReconstructionFinish (void); + /** Our Inkscape::XML::Document. */ + Inkscape::XML::Document *getReprDoc() { return rdoc; } + Inkscape::XML::Document const *getReprDoc() const { return rdoc; } - unsigned long serial() const; - void reset_key (void *dummy); - sigc::connection _selection_changed_connection; - sigc::connection _desktop_activated_connection; + /** A filename (not a URI yet), or NULL */ + gchar const *getURI() const { return uri; } + void setUri(gchar const *uri); - void fitToRect(NR::Rect const &rect); -}; + /** To be used for resolving relative hrefs. */ + gchar const *getBase() const { return base; }; + void setBase( gchar const* base ); -SPDocument *sp_document_new (const gchar *uri, unsigned int keepalive, bool make_new = false); -SPDocument *sp_document_new_from_mem (const gchar *buffer, gint length, unsigned int keepalive); + /** basename(uri) or other human-readable label for the document. */ + gchar const* getName() const { return name; } -SPDocument *sp_document_ref (SPDocument *doc); -SPDocument *sp_document_unref (SPDocument *doc); + void setCurrentPersp3D(Persp3D * const persp); + inline void setCurrentPersp3DImpl(Persp3DImpl * const persp_impl) { current_persp3d_impl = persp_impl; } + /* + * getCurrentPersp3D returns current_persp3d (if non-NULL) or the first + * perspective in the defs. If no perspective exists, returns NULL. + */ + Persp3D * getCurrentPersp3D(); + Persp3DImpl * getCurrentPersp3DImpl(); -SPDocument *sp_document_create(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive); + void getPerspectivesInDefs(std::vector &list) const; -/* - * Access methods - */ - -#define sp_document_repr_doc(d) (d->rdoc) -#define sp_document_repr_root(d) (d->rroot) -#define sp_document_root(d) (d->root) -#define SP_DOCUMENT_ROOT(d) (d->root) + unsigned int numPerspectivesInDefs() const { + std::vector list; + getPerspectivesInDefs(list); + return list.size(); + } -gdouble sp_document_width (SPDocument * document); -gdouble sp_document_height (SPDocument * document); + sigc::connection connectModified(ModifiedSignal::slot_type slot); + sigc::connection connectURISet(URISetSignal::slot_type slot); + sigc::connection connectResized(ResizedSignal::slot_type slot); + sigc::connection connectCommit(CommitSignal::slot_type slot); -struct SPUnit; + void bindObjectToId(gchar const *id, SPObject *object); + SPObject *getObjectById(gchar const *id) const; + sigc::connection connectIdChanged(const gchar *id, IDChangedSignal::slot_type slot); -void sp_document_set_width (SPDocument * document, gdouble width, const SPUnit *unit); -void sp_document_set_height (SPDocument * document, gdouble height, const SPUnit *unit); + void bindObjectToRepr(Inkscape::XML::Node *repr, SPObject *object); + SPObject *getObjectByRepr(Inkscape::XML::Node *repr) const; -#define SP_DOCUMENT_URI(d) (d->uri) -#define SP_DOCUMENT_NAME(d) (d->name) -#define SP_DOCUMENT_BASE(d) (d->base) + Glib::ustring getLanguage() const; -/* - * Dictionary - */ + void queueForOrphanCollection(SPObject *object); + void collectOrphans(); -/* - * Undo & redo - */ + void _emitModified(); -void sp_document_set_undo_sensitive (SPDocument * document, bool sensitive); -bool sp_document_get_undo_sensitive (SPDocument const * document); + void addUndoObserver(Inkscape::UndoStackObserver& observer); + void removeUndoObserver(Inkscape::UndoStackObserver& observer); -void sp_document_clear_undo (SPDocument * document); -void sp_document_clear_redo (SPDocument * document); + bool _updateDocument(); -void sp_document_child_added (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref); -void sp_document_child_removed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref); -void sp_document_attr_changed (SPDocument *doc, SPObject *object, const gchar *key, const gchar *oldval, const gchar *newval); -void sp_document_content_changed (SPDocument *doc, SPObject *object, const gchar *oldcontent, const gchar *newcontent); -void sp_document_order_changed (SPDocument *doc, SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *oldref, Inkscape::XML::Node *newref); + /// Are we currently in a transition between two "known good" states of the document? + bool isSeeking() const; -/* Object modification root handler */ -void sp_document_request_modified (SPDocument *doc); -gint sp_document_ensure_up_to_date (SPDocument *doc); + bool isModifiedSinceSave() const { return modified_since_save; } + void setModifiedSinceSave(bool modified = true) { + modified_since_save = modified; + } -/* Save all previous actions to stack, as one undo step */ -void sp_document_done (SPDocument *document, unsigned int event_type, Glib::ustring event_description); -void sp_document_maybe_done (SPDocument *document, const gchar *keyconst, unsigned int event_type, Glib::ustring event_description); -void sp_document_reset_key (Inkscape::Application *inkscape, SPDesktop *desktop, GtkObject *base); +private: + SPDocument(SPDocument const &); // no copy + void operator=(SPDocument const &); // no assign -/* Cancel (and revert) current unsaved actions */ -void sp_document_cancel (SPDocument *document); + Persp3D *current_persp3d; /**< Currently 'active' perspective (to which, e.g., newly created boxes are attached) */ + Persp3DImpl *current_persp3d_impl; -/* Undo and redo */ -gboolean sp_document_undo (SPDocument * document); -gboolean sp_document_redo (SPDocument * document); +public: + sigc::connection connectReconstructionStart(ReconstructionStart::slot_type slot); + sigc::connection connectReconstructionFinish(ReconstructionFinish::slot_type slot); + void emitReconstructionStart(void); + void emitReconstructionFinish(void); + + unsigned long serial() const; + void reset_key(void *dummy); + sigc::connection _selection_changed_connection; + sigc::connection _desktop_activated_connection; + + sigc::connection connectResourcesChanged(const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot); + + void fitToRect(Geom::Rect const &rect, bool with_margins = false); + static SPDocument *createNewDoc(const gchar *uri, unsigned int keepalive, bool make_new = false); + static SPDocument *createNewDocFromMem(const gchar *buffer, gint length, unsigned int keepalive); + + /** + * Returns the bottommost item from the list which is at the point, or NULL if none. + */ + static SPItem *getItemFromListAtPointBottom(unsigned int dkey, SPGroup *group, const GSList *list, Geom::Point const p, bool take_insensitive = false); + + // ToDo - Merge createDoc with createNewDoc + static SPDocument *createDoc(Inkscape::XML::Document *rdoc, gchar const *uri, gchar const *base, gchar const *name, unsigned int keepalive); + + SPDocument *doRef(); + SPDocument *doUnref(); + gdouble getWidth() const; + gdouble getHeight() const; + Geom::Point getDimensions() const; + void setWidth(gdouble width, const SPUnit *unit); + void setHeight(gdouble height, const SPUnit *unit); + void requestModified(); + gint ensureUpToDate(); + bool addResource(const gchar *key, SPObject *object); + bool removeResource(const gchar *key, SPObject *object); + const GSList *getResourceList(const gchar *key) const; + GSList *getItemsInBox(unsigned int dkey, Geom::Rect const &box) const; + GSList *getItemsPartiallyInBox(unsigned int dkey, Geom::Rect const &box) const; + SPItem *getItemAtPoint(unsigned int key, Geom::Point const p, gboolean into_groups, SPItem *upto = NULL) const; + GSList *getItemsAtPoints(unsigned const key, std::vector points) const; + SPItem *getGroupAtPoint(unsigned int key, Geom::Point const p) const; + + void changeUriAndHrefs(gchar const *uri); + void emitResizedSignal(gdouble width, gdouble height); + + unsigned int vacuumDocument(); -/* Resource management */ -gboolean sp_document_add_resource (SPDocument *document, const gchar *key, SPObject *object); -gboolean sp_document_remove_resource (SPDocument *document, const gchar *key, SPObject *object); -const GSList *sp_document_get_resource_list (SPDocument *document, const gchar *key); -sigc::connection sp_document_resources_changed_connect(SPDocument *document, const gchar *key, SPDocument::ResourcesChangedSignal::slot_type slot); +private: + void do_change_uri(gchar const *const filename, bool const rebase); +}; +struct SPUnit; /* * Ideas: How to overcome style invalidation nightmare @@ -226,20 +265,15 @@ sigc::connection sp_document_resources_changed_connect(SPDocument *document, con * */ -/* - * Misc - */ +#endif // SEEN_SP_DOCUMENT_H -GSList * sp_document_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box); -GSList * sp_document_partial_items_in_box(SPDocument *document, unsigned int dkey, NR::Rect const &box); -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); -SPItem * sp_document_item_at_point (SPDocument *document, unsigned int key, NR::Point const p, gboolean into_groups, SPItem *upto = NULL); -GSList *sp_document_items_at_points(SPDocument *document, unsigned const key, std::vector points); -SPItem *sp_document_group_at_point (SPDocument *document, unsigned int key, NR::Point const p); - -void sp_document_set_uri (SPDocument *document, const gchar *uri); -void sp_document_resized_signal_emit (SPDocument *doc, gdouble width, gdouble height); - -unsigned int vacuum_document (SPDocument *document); - -#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :