2#ifndef SP_OBJECT_H_SEEN
3#define SP_OBJECT_H_SEEN
19#include <glibmm/ustring.h>
27#define SP_OBJECT_MODIFIED_FLAG (1 << 0)
28#define SP_OBJECT_CHILD_MODIFIED_FLAG (1 << 1)
29#define SP_OBJECT_PARENT_MODIFIED_FLAG (1 << 2)
30#define SP_OBJECT_STYLE_MODIFIED_FLAG (1 << 3)
31#define SP_OBJECT_VIEWPORT_MODIFIED_FLAG (1 << 4)
32#define SP_OBJECT_USER_MODIFIED_FLAG_A (1 << 5)
33#define SP_OBJECT_USER_MODIFIED_FLAG_B (1 << 6)
34#define SP_OBJECT_STYLESHEET_MODIFIED_FLAG (1 << 7)
37#define SP_OBJECT_FLAGS_ALL 0xff
42#define SP_OBJECT_USER_MODIFIED_TAG_1 (1 << 8)
43#define SP_OBJECT_USER_MODIFIED_TAG_2 (1 << 9)
44#define SP_OBJECT_USER_MODIFIED_TAG_3 (1 << 10)
45#define SP_OBJECT_USER_MODIFIED_TAG_4 (1 << 11)
46#define SP_OBJECT_USER_MODIFIED_TAG_5 (1 << 12)
47#define SP_OBJECT_USER_MODIFIED_TAG_6 (1 << 13)
48#define SP_OBJECT_USER_MODIFIED_TAG_7 (1 << 14)
49#define SP_OBJECT_USER_MODIFIED_TAG_8 (1 << 15)
51#define SP_OBJECT_USER_TAGS_ALL 0xff00
55#define SP_OBJECT_MODIFIED_STATE (SP_OBJECT_FLAGS_ALL & ~(SP_OBJECT_PARENT_MODIFIED_FLAG))
59#define SP_OBJECT_MODIFIED_CASCADE ((SP_OBJECT_FLAGS_ALL | SP_OBJECT_USER_TAGS_ALL) & ~(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))
63 static_assert(SP_OBJECT_PARENT_MODIFIED_FLAG == SP_OBJECT_MODIFIED_FLAG << 2);
64 return (flags & SP_OBJECT_MODIFIED_CASCADE) | (flags & SP_OBJECT_MODIFIED_FLAG) << 2;
68#define SP_OBJECT_WRITE_BUILD (1 << 0)
69#define SP_OBJECT_WRITE_EXT (1 << 1)
70#define SP_OBJECT_WRITE_ALL (1 << 2)
71#define SP_OBJECT_WRITE_NO_CHILDREN (1 << 3)
76#include <boost/intrusive/list.hpp>
78#include <sigc++/connection.h>
79#include <sigc++/functors/slot.h>
80#include <sigc++/signal.h>
178 virtual int tag()
const {
return tag_of<
decltype(*this)>; }
202 char const*
getId()
const;
204 void getIds(std::set<std::string> &ret)
const;
209 std::string
getUrl()
const;
266 if (
object ==
nullptr)
return false;
285 std::vector<SPObject *> ret;
349 char const *
label()
const;
391 bool setDesc(
char const *
desc,
bool verbatim=
false);
501 void deleteObject(
bool propagate,
bool propagate_descendants);
523 void getObjectsExcept(std::vector<SPObject *> &objects,
const std::vector<SPObject *> &except);
706 sigc::slot<
void (
SPObject *,
unsigned int)> slot
788 (value.
data() ==
nullptr || value.
data()[0]==
'\0') ?
nullptr : value.
data());
828 bool setTitleOrDesc(
char const *value,
char const *svg_tagname,
bool verbatim);
891 virtual void update(
SPCtx *ctx,
unsigned int flags);
892 virtual void modified(
unsigned int flags);
896 typedef boost::intrusive::list_member_hook<>
ListHook;
902 boost::intrusive::member_hook<
911 void objectTrace(std::string
const &,
bool in =
true,
unsigned flags = 0);
923std::ostream &operator<<(std::ostream &out,
const SPObject &o);
Cartesian point / 2D vector and related operations.
constexpr int tag_of
Convenience function to retrieve the tag (class id) of a given type.
Two-dimensional point that doubles as a vector.
Non-owning reference to 'const char*' Main-purpose: avoid overloads of type f(char*,...
const char * data() const noexcept
Interface for XML node observers.
Interface for refcounted XML nodes.
Typed SVG document implementation.
Internal class consisting of two bits.
SPObject is an abstract base class of all of the document nodes at the SVG document level.
SPObject & operator=(SPObject const &)=delete
CollectionPolicy collectionPolicy() const
Set the policy under which this object will be orphan-collected.
Inkscape::Util::ForwardPointerIterator< SPObject const, ParentIteratorStrategy > ConstParentIterator
char const * label() const
Gets the author-visible label property for the object or a default if no label is defined.
int getIntAttribute(char const *key, int def)
Inkscape::XML::Node * repr
char * desc() const
Returns the description of this object, or NULL if there is none.
friend class SPObjectImpl
boost::intrusive::list< SPObject, boost::intrusive::member_hook< SPObject, ListHook, &SPObject::_child_hook > > ChildrenList
void requestOrphanCollection()
Requests a later automatic call to collectOrphan().
Inkscape::Util::ForwardPointerIterator< SPObject, ParentIteratorStrategy > ParentIterator
void setAttributeOrRemoveIfEmpty(Inkscape::Util::const_char_ptr key, Inkscape::Util::const_char_ptr value)
void setAttributeDouble(Inkscape::Util::const_char_ptr key, double value)
void appendChild(Inkscape::XML::Node *child)
void _updateTotalHRefCount(int increment)
Adds increment to _total_hrefcount of object and its parents.
bool storeAsDouble(char const *key, double *val) const
void setAttribute(Inkscape::Util::const_char_ptr key, Inkscape::Util::const_char_ptr value)
std::vector< SPObject * > getLinked(LinkedObjectNature direction=LinkedObjectNature::ANY) const
Get objects which are linked, like above.
SPObject()
Constructor, sets all attributes to default values.
SPObject * clone_original
void detach(SPObject *object)
Remove object from parent's children, release and unref it.
void requestModified(unsigned int flags)
Requests that a modification notification signal be emitted later (e.g.
void removeAttribute(char const *key)
Glib::ustring getExportFilename() const
Get and set the exportable filename on this object.
Geom::Point getExportDpi() const
Get and set the exported DPI for this objet, if available.
void notifyChildOrderChanged(Inkscape::XML::Node &node, Inkscape::XML::Node &child, Inkscape::XML::Node *old_prev, Inkscape::XML::Node *new_prev) final
Child order change callback.
void setKeyValue(SPAttr key, char const *value)
Call virtual set() function of object.
bool setDesc(char const *desc, bool verbatim=false)
Sets the description of this object.
void setExportDpi(Geom::Point dpi)
void deleteObject(bool propagate=true)
Deletes on object.
void setExportFilename(Glib::ustring filename)
sigc::connection connectDelete(sigc::slot< void(SPObject *)> slot)
Connects a slot to be called when an object is deleted.
std::vector< SPObject * > childList(bool add_ref, Action action=ActionGeneral)
Retrieves the children as a std vector object, optionally ref'ing the children in the process,...
void setTmpSuccessor(SPObject *tmpsuccessor)
Indicates that another object supercedes temporaty this one.
sigc::connection connectPositionChanged(sigc::slot< void(SPObject *)> slot)
char * getTitleOrDesc(char const *svg_tagname) const
Returns the title or description of this object, or NULL if there is none.
void getObjectsExcept(std::vector< SPObject * > &objects, const std::vector< SPObject * > &except)
Get all child objects except for any in the list.
SPObject * get_child_by_repr(Inkscape::XML::Node *repr)
Return object's child whose node pointer equals repr.
virtual void read_content()
void invoke_build(SPDocument *document, Inkscape::XML::Node *repr, unsigned int cloned)
void notifyAttributeChanged(Inkscape::XML::Node &node, GQuark key, Inkscape::Util::ptr_shared oldval, Inkscape::Util::ptr_shared newval) final
Attribute change callback.
void attach(SPObject *object, SPObject *prev)
Put object into object tree, under parent, and behind prev; also update object's XML space.
void updateDisplay(SPCtx *ctx, unsigned int flags)
Updates the object's display immediately.
bool isReferenced()
Check if object is referenced by any other object.
virtual void remove_child(Inkscape::XML::Node *child)
void emitModified(unsigned int flags)
Emits the MODIFIED signal with the object's flags.
void getLinkedRecursive(std::vector< SPObject * > &objects, LinkedObjectNature direction=LinkedObjectNature::ANY) const
Grows the input list with all linked items recursively in both child nodes and links of links.
char const * getId() const
Returns the objects current ID string.
bool setTitleOrDesc(char const *value, char const *svg_tagname, bool verbatim)
Sets or deletes the title or description of this object.
void changeCSS(SPCSSAttr *css, char const *attr)
void notifyChildRemoved(Inkscape::XML::Node &node, Inkscape::XML::Node &child, Inkscape::XML::Node *prev) final
Child removal callback.
void recursivePrintTree(unsigned level=0)
sigc::signal< void(SPObject *)> _position_changed_signal
SPStyle * style
Represents the style properties, whether from presentation attributes, the style attribute,...
sigc::connection connectRelease(sigc::slot< void(SPObject *)> slot)
Connects to the release request signal.
bool setTitle(char const *title, bool verbatim=false)
Sets the title of this object.
std::vector< SPObject * > ancestorList(bool root_to_tip)
Retrieves a list of ancestors of the object, as an easy to use vector.
virtual Inkscape::XML::Node * write(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, unsigned int flags)
void notifyChildAdded(Inkscape::XML::Node &node, Inkscape::XML::Node &child, Inkscape::XML::Node *prev) final
Child addition callback.
SPObject const * lastChild() const
CollectionPolicy _collection_policy
Glib::ustring textualContent() const
Return the full textual content of an element (typically all the content except the tags).
sigc::signal< void(SPObject *, unsigned int)> _modified_signal
void setSuccessor(SPObject *successor)
Indicates that another object supercedes this one.
boost::intrusive::list_member_hook ListHook
~SPObject() override
Destructor, frees the used memory and unreferences a potential successor of the object.
SPObject * getPrev()
Returns previous object in sibling list or NULL.
char const * defaultLabel() const
Returns a default label property for this object.
void setLabel(char const *label)
Sets the author-visible label for this object.
virtual void update(SPCtx *ctx, unsigned int flags)
SPStyle * context_style
Represents the style that should be used to resolve 'context-fill' and 'context-stroke'.
SPObject * findFirstChild(char const *tagname) const
Find the first child of this object with a given tag name, and return it.
void unhrefObject(SPObject *owner=nullptr)
Decrease weak refcount.
Inkscape::XML::Node * updateRepr(unsigned int flags=SP_OBJECT_WRITE_EXT)
Updates the object's repr based on the object's state.
void _requireSVGVersion(unsigned major, unsigned minor)
SPObject * successor()
Returns the object which supercedes this one (if any).
virtual void modified(unsigned int flags)
void readAttr(char const *key)
Read value of key attribute from XML node into object.
SPObject(SPObject const &)=delete
void _sendDeleteSignalRecursive()
Sends the delete signal to all children of this object recursively.
void reorder(SPObject *obj, SPObject *prev)
In list of object's children, move object behind prev.
sigc::signal< void(SPObject *)> _delete_signal
std::string generate_unique_id(char const *default_id=nullptr) const
Generate a document-wide unique id for this object.
void hrefObject(SPObject *owner=nullptr)
Increase weak refcount.
void deleteObject(bool propagate, bool propagate_descendants)
Deletes an object, unparenting it from its parent.
Inkscape::XML::Node * getRepr()
Returns the XML representation of tree.
virtual void child_added(Inkscape::XML::Node *child, Inkscape::XML::Node *ref)
char const * getAttribute(char const *name) const
bool isSiblingOf(SPObject const *object) const
void fixTmpSuccessors()
Fix temporary successors in duple stamp.
char * title() const
Returns the title of this object, or NULL if there is none.
void cropToObjects(std::vector< SPObject * > except_objects)
Removes objects which are not related to given list of objects.
virtual void getLinked(std::vector< SPObject * > &objects, LinkedObjectNature direction=LinkedObjectNature::ANY) const
Get objects which are linked to this object as either a source or a target.
SPObject * appendChildRepr(Inkscape::XML::Node *repr)
Append repr as child of this object.
void setCollectionPolicy(CollectionPolicy policy)
Sets the orphan-collection policy in effect for this object.
bool isAncestorOf(SPObject const *object) const
True if object is non-NULL and this is some in/direct parent of object.
std::string getUrl() const
Get the id in a URL format.
void objectTrace(std::string const &, bool in=true, unsigned flags=0)
SPObject * nthChild(unsigned index)
void cropToObject(SPObject *except)
Removes all children except for the given object, it's children and it's ancesstors.
void collectOrphan()
Unconditionally delete the object if it is not referenced.
void addChild(Inkscape::XML::Node *child, Inkscape::XML::Node *prev=nullptr)
std::list< SPObject * > hrefList
virtual void build(SPDocument *doc, Inkscape::XML::Node *repr)
SPObject const * nearestCommonAncestor(SPObject const *object) const
Returns youngest object being parent to this and object.
void getIds(std::set< std::string > &ret) const
Accumulate this id and all it's descendants ids.
void unsetTmpSuccessor()
Unset object supercedes.
sigc::connection connectModified(sigc::slot< void(SPObject *, unsigned int)> slot)
Connects to the modification notification signal.
virtual void order_changed(Inkscape::XML::Node *child, Inkscape::XML::Node *old_repr, Inkscape::XML::Node *new_repr)
char const * getTagName() const
SPObject const * getTopAncestorNonLayer() const
Returns ancestor non layer.
void setCSS(SPCSSAttr *css, char const *attr)
sigc::signal< void(SPObject *)> _release_signal
void notifyContentChanged(Inkscape::XML::Node &node, Inkscape::Util::ptr_shared oldcontent, Inkscape::Util::ptr_shared newcontent) final
Content change callback.
void notifyElementNameChanged(Inkscape::XML::Node &node, GQuark old_name, GQuark new_name) final
Element name change callback.
void requestDisplayUpdate(unsigned int flags)
Queues an deferred update of this object's display.
SPObject const * nthChild(unsigned index) const
virtual void tag_name_changed(gchar const *oldname, gchar const *newname)
void releaseReferences()
Cleans up an SPObject, releasing its references and requesting that references to it be released.
unsigned int _total_hrefcount
SPObject const * firstChild() const
std::shared_ptr< Css const > css
Inkscape::XML::Node * node
Interface for XML node observers.
static cairo_user_data_key_t key
bool sp_object_compare_position_bool(SPObject const *first, SPObject const *second)
SPObject * sp_object_unref(SPObject *object, SPObject *owner=nullptr)
Decrease reference count of object, with possible debugging and finalization.
unsigned cascade_flags(unsigned flags)
int sp_object_compare_position(SPObject const *first, SPObject const *second)
Compares height of objects in tree.
SPObject * sp_object_ref(SPObject *object, SPObject *owner=nullptr)
Increase reference count of object, with possible debugging.
Interface for XML documents.
Switch containing next() method.
static SPObject const * next(SPObject const *object)