diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2013-09-19 22:33:11 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2013-09-19 22:33:11 +0000 |
| commit | 4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7 (patch) | |
| tree | caeb924426bcc861badc6fa81318b67460b26d47 /src/sp-anchor.cpp | |
| parent | Update to trunk (diff) | |
| parent | updates for cmake (diff) | |
| download | inkscape-4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7.tar.gz inkscape-4bda89e32e33c7bdff5d3ea3c1ceee1f806de9f7.zip | |
Update to trunk
(bzr r11950.1.141)
Diffstat (limited to 'src/sp-anchor.cpp')
| -rw-r--r-- | src/sp-anchor.cpp | 139 |
1 files changed, 54 insertions, 85 deletions
diff --git a/src/sp-anchor.cpp b/src/sp-anchor.cpp index 8b52cf400..d9a8c4142 100644 --- a/src/sp-anchor.cpp +++ b/src/sp-anchor.cpp @@ -25,75 +25,53 @@ #include "ui/view/view.h" #include "document.h" -static void sp_anchor_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); -static void sp_anchor_release(SPObject *object); -static void sp_anchor_set(SPObject *object, unsigned int key, const gchar *value); -static Inkscape::XML::Node *sp_anchor_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags); +#include "sp-factory.h" -static gchar *sp_anchor_description(SPItem *item); -static gint sp_anchor_event(SPItem *item, SPEvent *event); +namespace { + SPObject* createAnchor() { + return new SPAnchor(); + } -G_DEFINE_TYPE(SPAnchor, sp_anchor, SP_TYPE_GROUP); - -static void sp_anchor_class_init(SPAnchorClass *ac) -{ - SPObjectClass *sp_object_class = (SPObjectClass *) ac; - SPItemClass *item_class = (SPItemClass *) ac; - - sp_object_class->build = sp_anchor_build; - sp_object_class->release = sp_anchor_release; - sp_object_class->set = sp_anchor_set; - sp_object_class->write = sp_anchor_write; - - item_class->description = sp_anchor_description; - item_class->event = sp_anchor_event; + bool anchorRegistered = SPFactory::instance().registerObject("svg:a", createAnchor); } -static void sp_anchor_init(SPAnchor *anchor) -{ - anchor->href = NULL; +SPAnchor::SPAnchor() : SPGroup() { + this->href = NULL; } -static void sp_anchor_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ - if (((SPObjectClass *) (sp_anchor_parent_class))->build) { - ((SPObjectClass *) (sp_anchor_parent_class))->build(object, document, repr); - } - - object->readAttr( "xlink:type" ); - object->readAttr( "xlink:role" ); - object->readAttr( "xlink:arcrole" ); - object->readAttr( "xlink:title" ); - object->readAttr( "xlink:show" ); - object->readAttr( "xlink:actuate" ); - object->readAttr( "xlink:href" ); - object->readAttr( "target" ); +SPAnchor::~SPAnchor() { } -static void sp_anchor_release(SPObject *object) -{ - SPAnchor *anchor = SP_ANCHOR(object); +void SPAnchor::build(SPDocument *document, Inkscape::XML::Node *repr) { + SPGroup::build(document, repr); + + this->readAttr( "xlink:type" ); + this->readAttr( "xlink:role" ); + this->readAttr( "xlink:arcrole" ); + this->readAttr( "xlink:title" ); + this->readAttr( "xlink:show" ); + this->readAttr( "xlink:actuate" ); + this->readAttr( "xlink:href" ); + this->readAttr( "target" ); +} - if (anchor->href) { - g_free(anchor->href); - anchor->href = NULL; +void SPAnchor::release() { + if (this->href) { + g_free(this->href); + this->href = NULL; } - if (((SPObjectClass *) sp_anchor_parent_class)->release) { - ((SPObjectClass *) sp_anchor_parent_class)->release(object); - } + SPGroup::release(); } -static void sp_anchor_set(SPObject *object, unsigned int key, const gchar *value) -{ - SPAnchor *anchor = SP_ANCHOR(object); - +void SPAnchor::set(unsigned int key, const gchar* value) { switch (key) { case SP_ATTR_XLINK_HREF: - g_free(anchor->href); - anchor->href = g_strdup(value); - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + g_free(this->href); + this->href = g_strdup(value); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; + case SP_ATTR_XLINK_TYPE: case SP_ATTR_XLINK_ROLE: case SP_ATTR_XLINK_ARCROLE: @@ -101,12 +79,11 @@ static void sp_anchor_set(SPObject *object, unsigned int key, const gchar *value case SP_ATTR_XLINK_SHOW: case SP_ATTR_XLINK_ACTUATE: case SP_ATTR_TARGET: - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + this->requestModified(SP_OBJECT_MODIFIED_FLAG); break; + default: - if (((SPObjectClass *) (sp_anchor_parent_class))->set) { - ((SPObjectClass *) (sp_anchor_parent_class))->set(object, key, value); - } + SPGroup::set(key, value); break; } } @@ -114,40 +91,33 @@ static void sp_anchor_set(SPObject *object, unsigned int key, const gchar *value #define COPY_ATTR(rd,rs,key) (rd)->setAttribute((key), rs->attribute(key)); -static Inkscape::XML::Node *sp_anchor_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) -{ - SPAnchor *anchor = SP_ANCHOR(object); - +Inkscape::XML::Node* SPAnchor::write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:a"); } - repr->setAttribute("xlink:href", anchor->href); + repr->setAttribute("xlink:href", this->href); - if (repr != object->getRepr()) { + if (repr != this->getRepr()) { // XML Tree being directly used while it shouldn't be in the // below COPY_ATTR lines - COPY_ATTR(repr, object->getRepr(), "xlink:type"); - COPY_ATTR(repr, object->getRepr(), "xlink:role"); - COPY_ATTR(repr, object->getRepr(), "xlink:arcrole"); - COPY_ATTR(repr, object->getRepr(), "xlink:title"); - COPY_ATTR(repr, object->getRepr(), "xlink:show"); - COPY_ATTR(repr, object->getRepr(), "xlink:actuate"); - COPY_ATTR(repr, object->getRepr(), "target"); + COPY_ATTR(repr, this->getRepr(), "xlink:type"); + COPY_ATTR(repr, this->getRepr(), "xlink:role"); + COPY_ATTR(repr, this->getRepr(), "xlink:arcrole"); + COPY_ATTR(repr, this->getRepr(), "xlink:title"); + COPY_ATTR(repr, this->getRepr(), "xlink:show"); + COPY_ATTR(repr, this->getRepr(), "xlink:actuate"); + COPY_ATTR(repr, this->getRepr(), "target"); } - if (((SPObjectClass *) (sp_anchor_parent_class))->write) { - ((SPObjectClass *) (sp_anchor_parent_class))->write(object, xml_doc, repr, flags); - } + SPGroup::write(xml_doc, repr, flags); return repr; } -static gchar *sp_anchor_description(SPItem *item) -{ - SPAnchor *anchor = SP_ANCHOR(item); - if (anchor->href) { - char *quoted_href = xml_quote_strdup(anchor->href); +gchar* SPAnchor::description() { + if (this->href) { + char *quoted_href = xml_quote_strdup(this->href); char *ret = g_strdup_printf(_("<b>Link</b> to %s"), quoted_href); g_free(quoted_href); return ret; @@ -157,24 +127,23 @@ static gchar *sp_anchor_description(SPItem *item) } /* fixme: We should forward event to appropriate container/view */ - -static gint sp_anchor_event(SPItem *item, SPEvent *event) -{ - SPAnchor *anchor = SP_ANCHOR(item); - +gint SPAnchor::event(SPEvent* event) { switch (event->type) { case SP_EVENT_ACTIVATE: - if (anchor->href) { - g_print("Activated xlink:href=\"%s\"\n", anchor->href); + if (this->href) { + g_print("Activated xlink:href=\"%s\"\n", this->href); return TRUE; } break; + case SP_EVENT_MOUSEOVER: (static_cast<Inkscape::UI::View::View*>(event->data))->mouseover(); break; + case SP_EVENT_MOUSEOUT: (static_cast<Inkscape::UI::View::View*>(event->data))->mouseout(); break; + default: break; } |
