From fa56037ac97f54aededa4f24b609d6ad734b58c1 Mon Sep 17 00:00:00 2001 From: Adonis Papaderos Date: Mon, 6 Aug 2012 13:05:43 +0300 Subject: hack for 898797 (bzr r11595.1.1) --- src/sp-item-group.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index b54ec65e2..f9d74d089 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -853,7 +853,9 @@ sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write) } // only run LPEs when the shape has a curve defined if (c) { + c->transform(i2anc_affine(subitem, topgroup)); sp_lpe_item_perform_path_effect(SP_LPE_ITEM(topgroup), c); + c->transform(i2anc_affine(subitem, topgroup).inverse()); SP_SHAPE(subitem)->setCurve(c, TRUE); if (write) { -- cgit v1.2.3 From 16b19e18b4f9b416f0cc16f6b5b749bd38455b24 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 01:27:53 +0200 Subject: Added "virtual pad" to SPObject. (bzr r11608.1.1) --- src/sp-object.cpp | 102 +++++++++++++++++++++++++++++++++++++++++++++++------- src/sp-object.h | 31 +++++++++++++++++ 2 files changed, 121 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/sp-object.cpp b/src/sp-object.cpp index 892c89a15..5c42e009c 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -145,10 +145,27 @@ void SPObjectClass::sp_object_class_init(SPObjectClass *klass) klass->write = SPObject::sp_object_private_write; } + +// CPPIFY: make pure virtual +void CObject::onReadContent() { + throw; +} + +void CObject::onUpdate(SPCtx* ctx, unsigned int flags) { + throw; +} + +void CObject::onModified(unsigned int flags) { + throw; +} + + void SPObject::sp_object_init(SPObject *object) { debug("id=%x, typename=%s",object, g_type_name_from_instance((GTypeInstance*)object)); + object->cobject = new CObject(object); + object->hrefcount = 0; object->_total_hrefcount = 0; object->document = NULL; @@ -182,6 +199,8 @@ void SPObject::sp_object_finalize(GObject *object) { SPObject *spobject = (SPObject *)object; + delete spobject->cobject; + g_free(spobject->_label); g_free(spobject->_default_label); spobject->_label = NULL; @@ -202,6 +221,16 @@ void SPObject::sp_object_finalize(GObject *object) } } + +// CPPIFY: remove +CObject::CObject(SPObject* object) { + this->spobject = object; +} + +CObject::~CObject() { +} + + namespace { namespace Debug = Inkscape::Debug; @@ -616,8 +645,9 @@ SPObject *SPObject::get_child_by_repr(Inkscape::XML::Node *repr) return result; } -void SPObject::sp_object_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) -{ +void CObject::onChildAdded(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { + SPObject* object = this->spobject; + GType type = sp_repr_type_lookup(child); if (!type) { return; @@ -630,16 +660,30 @@ void SPObject::sp_object_child_added(SPObject *object, Inkscape::XML::Node *chil ochild->invoke_build(object->document, child, object->cloned); } -void SPObject::sp_object_release(SPObject *object) +// CPPIFY: remove +void SPObject::sp_object_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { + object->cobject->onChildAdded(child, ref); +} + +void CObject::onRelease() { + SPObject* object = this->spobject; + debug("id=%x, typename=%s", object, g_type_name_from_instance((GTypeInstance*)object)); while (object->children) { object->detach(object->children); } } -void SPObject::sp_object_remove_child(SPObject *object, Inkscape::XML::Node *child) +// CPPIFY: remove +void SPObject::sp_object_release(SPObject *object) { + object->cobject->onRelease(); +} + +void CObject::onRemoveChild(Inkscape::XML::Node* child) { + SPObject* object = this->spobject; + debug("id=%x, typename=%s", object, g_type_name_from_instance((GTypeInstance*)object)); SPObject *ochild = object->get_child_by_repr(child); g_return_if_fail (ochild != NULL || !strcmp("comment", child->name())); // comments have no objects @@ -648,9 +692,15 @@ void SPObject::sp_object_remove_child(SPObject *object, Inkscape::XML::Node *chi } } -void SPObject::sp_object_order_changed(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node */*old_ref*/, - Inkscape::XML::Node *new_ref) +// CPPIFY: remove +void SPObject::sp_object_remove_child(SPObject *object, Inkscape::XML::Node *child) { + object->cobject->onRemoveChild(child); +} + +void CObject::onOrderChanged(Inkscape::XML::Node *child, Inkscape::XML::Node * old_ref, Inkscape::XML::Node *new_ref) { + SPObject* object = this->spobject; + SPObject *ochild = object->get_child_by_repr(child); g_return_if_fail(ochild != NULL); SPObject *prev = new_ref ? object->get_child_by_repr(new_ref) : NULL; @@ -658,8 +708,16 @@ void SPObject::sp_object_order_changed(SPObject *object, Inkscape::XML::Node *ch ochild->_position_changed_signal.emit(ochild); } -void SPObject::sp_object_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) +// CPPIFY: remove +void SPObject::sp_object_order_changed(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, + Inkscape::XML::Node *new_ref) { + object->cobject->onOrderChanged(child, old_ref, new_ref); +} + +void CObject::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPObject* object = this->spobject; + /* Nothing specific here */ debug("id=%x, typename=%s", object, g_type_name_from_instance((GTypeInstance*)object)); @@ -679,6 +737,12 @@ void SPObject::sp_object_build(SPObject *object, SPDocument *document, Inkscape: } } +// CPPIFY: remove +void SPObject::sp_object_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) +{ + object->cobject->onBuild(document, repr); +} + void SPObject::invoke_build(SPDocument *document, Inkscape::XML::Node *repr, unsigned int cloned) { debug("id=%x, typename=%s", this, g_type_name_from_instance((GTypeInstance*)this)); @@ -847,10 +911,11 @@ void SPObject::sp_object_repr_order_changed(Inkscape::XML::Node */*repr*/, Inksc } } -void SPObject::sp_object_private_set(SPObject *object, unsigned int key, gchar const *value) -{ +void CObject::onSet(unsigned int key, gchar const* value) { g_assert(key != SP_ATTR_INVALID); + SPObject* object = this->spobject; + switch (key) { case SP_ATTR_ID: @@ -869,7 +934,7 @@ void SPObject::sp_object_private_set(SPObject *object, unsigned int key, gchar c if (!document->isSeeking()) { sp_object_ref(conflict, NULL); // give the conflicting object a new ID - gchar *new_conflict_id = sp_object_get_unique_id(conflict, NULL); + gchar *new_conflict_id = SPObject::sp_object_get_unique_id(conflict, NULL); conflict->getRepr()->setAttribute("id", new_conflict_id); g_free(new_conflict_id); sp_object_unref(conflict, NULL); @@ -932,6 +997,12 @@ void SPObject::sp_object_private_set(SPObject *object, unsigned int key, gchar c } } +// CPPIFY: remove +void SPObject::sp_object_private_set(SPObject *object, unsigned int key, gchar const *value) +{ + object->cobject->onSet(key, value); +} + void SPObject::setKeyValue(unsigned int key, gchar const *value) { //g_assert(object != NULL); @@ -997,8 +1068,9 @@ static gchar const *sp_xml_get_space_string(unsigned int space) } } -Inkscape::XML::Node * SPObject::sp_object_private_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) -{ +Inkscape::XML::Node* CObject::onWrite(Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) { + SPObject* object = this->spobject; + if (!repr && (flags & SP_OBJECT_WRITE_BUILD)) { repr = object->getRepr()->duplicate(doc); if (!( flags & SP_OBJECT_WRITE_EXT )) { @@ -1080,6 +1152,12 @@ Inkscape::XML::Node * SPObject::sp_object_private_write(SPObject *object, Inksca return repr; } +// CPPIFY: remove +Inkscape::XML::Node * SPObject::sp_object_private_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) +{ + return object->cobject->onWrite(doc, repr, flags); +} + Inkscape::XML::Node * SPObject::updateRepr(unsigned int flags) { if ( !cloned ) { diff --git a/src/sp-object.h b/src/sp-object.h index b08706b0b..9ff772870 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -176,6 +176,7 @@ SPObject *sp_object_href(SPObject *object, gpointer owner); */ SPObject *sp_object_hunref(SPObject *object, gpointer owner); +class CObject; /** * SPObject is an abstract base class of all of the document nodes at the @@ -203,6 +204,8 @@ public: ALWAYS_COLLECT }; + CObject* cobject; + unsigned int cloned : 1; unsigned int uflags : 8; unsigned int mflags : 8; @@ -909,6 +912,7 @@ public: friend class SPObjectClass; friend class SPObjectImpl; + friend class CObject; }; /// The SPObject vtable. @@ -948,6 +952,33 @@ private: }; +class CObject { +public: + CObject(SPObject* object); + virtual ~CObject(); + + virtual void onBuild(SPDocument* doc, Inkscape::XML::Node* repr); + virtual void onRelease(); + + virtual void onChildAdded(Inkscape::XML::Node* child, Inkscape::XML::Node* ref); + virtual void onRemoveChild(Inkscape::XML::Node* child); + + virtual void onOrderChanged(Inkscape::XML::Node* child, Inkscape::XML::Node* old_repr, Inkscape::XML::Node* new_repr); + + virtual void onSet(unsigned int key, const gchar* value); + + virtual void onReadContent(); + + virtual void onUpdate(SPCtx* ctx, unsigned int flags); + virtual void onModified(unsigned int flags); + + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags); + +protected: + SPObject* spobject; +}; + + /** * Compares height of objects in tree. * -- cgit v1.2.3 From 07eac1237fe242e6680bd0d76552771ff852fef7 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 01:36:49 +0200 Subject: Added "virtual pad" to SPItem. (bzr r11608.1.2) --- src/sp-item.cpp | 161 +++++++++++++++++++++++++++++++++++++++++++------------- src/sp-item.h | 32 +++++++++++ 2 files changed, 155 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/sp-item.cpp b/src/sp-item.cpp index b1eb5a24a..20b6b3ef3 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -120,11 +120,22 @@ SPItemClass::sp_item_class_init(SPItemClass *klass) klass->snappoints = SPItem::sp_item_private_snappoints; } +// CPPIFY: remove +CItem::CItem(SPItem* item) : CObject(item) { + this->spitem = item; +} + +CItem::~CItem() { +} + /** * Callback for SPItem object initialization. */ void SPItem::sp_item_init(SPItem *item) { + item->citem = new CItem(item); + item->cobject = item->citem; + item->init(); } @@ -413,9 +424,9 @@ void SPItem::moveTo(SPItem *target, gboolean intoafter) { } } +void CItem::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPItem* object = this->spitem; -void SPItem::sp_item_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ object->readAttr( "style" ); object->readAttr( "transform" ); object->readAttr( "clip-path" ); @@ -427,14 +438,17 @@ void SPItem::sp_item_build(SPObject *object, SPDocument *document, Inkscape::XML object->readAttr( "inkscape:connector-avoid" ); object->readAttr( "inkscape:connection-points" ); - if (((SPObjectClass *) (SPItemClass::static_parent_class))->build) { - (* ((SPObjectClass *) (SPItemClass::static_parent_class))->build)(object, document, repr); - } + CObject::onBuild(document, repr); } -void SPItem::sp_item_release(SPObject *object) +// CPPIFY: remove +void SPItem::sp_item_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - SPItem *item = (SPItem *) object; + ((SPItem*)object)->citem->onBuild(document, repr); +} + +void CItem::onRelease() { + SPItem* item = this->spitem; // Note: do this here before the clip_ref is deleted, since calling // ensureUpToDate() for triggered routing may reference @@ -447,20 +461,25 @@ void SPItem::sp_item_release(SPObject *object) delete item->clip_ref; delete item->mask_ref; - if (((SPObjectClass *) (SPItemClass::static_parent_class))->release) { - ((SPObjectClass *) SPItemClass::static_parent_class)->release(object); - } + CObject::onRelease(); while (item->display) { - item->display = sp_item_view_list_remove(item->display, item->display); + item->display = SPItem::sp_item_view_list_remove(item->display, item->display); } item->_transformed_signal.~signal(); + } -void SPItem::sp_item_set(SPObject *object, unsigned key, gchar const *value) +// CPPIFY: remove +void SPItem::sp_item_release(SPObject *object) { - SPItem *item = (SPItem *) object; + ((SPItem*)object)->citem->onRelease(); +} + +void CItem::onSet(unsigned int key, gchar const* value) { + SPItem *item = this->spitem; + SPItem* object = item; switch (key) { case SP_ATTR_TRANSFORM: { @@ -544,14 +563,18 @@ void SPItem::sp_item_set(SPObject *object, unsigned key, gchar const *value) sp_style_read_from_object(object->style, object); object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); } else { - if (((SPObjectClass *) (SPItemClass::static_parent_class))->set) { - (* ((SPObjectClass *) (SPItemClass::static_parent_class))->set)(object, key, value); - } + CObject::onSet(key, value); } break; } } +// CPPIFY: remove +void SPItem::sp_item_set(SPObject *object, unsigned key, gchar const *value) +{ + ((SPItem*)object)->citem->onSet(key, value); +} + void SPItem::clip_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item) { if (old_clip) { @@ -601,13 +624,16 @@ void SPItem::mask_ref_changed(SPObject *old_mask, SPObject *mask, SPItem *item) } } -void SPItem::sp_item_update(SPObject *object, SPCtx *ctx, guint flags) -{ - SPItem *item = SP_ITEM(object); +void CItem::onUpdate(SPCtx *ctx, guint flags) { + SPItem *item = this->spitem; + SPItem* object = item; - if (((SPObjectClass *) (SPItemClass::static_parent_class))->update) { - (* ((SPObjectClass *) (SPItemClass::static_parent_class))->update)(object, ctx, flags); - } + // CPPIFY: As CItem is derived directly from CObject, this doesn't make no sense. + // CObject::onUpdate is pure. What was the idea behind these lines? +// if (((SPObjectClass *) (SPItemClass::static_parent_class))->update) { +// (* ((SPObjectClass *) (SPItemClass::static_parent_class))->update)(object, ctx, flags); +// } +// CObject::onUpdate(ctx, flags); // any of the modifications defined in sp-object.h might change bbox, // so we invalidate it unconditionally @@ -661,9 +687,15 @@ void SPItem::sp_item_update(SPObject *object, SPCtx *ctx, guint flags) item->avoidRef->handleSettingChange(); } -Inkscape::XML::Node *SPItem::sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +// CPPIFY: remove +void SPItem::sp_item_update(SPObject *object, SPCtx *ctx, guint flags) { - SPItem *item = SP_ITEM(object); + ((SPItem*)object)->citem->onUpdate(ctx, flags); +} + +Inkscape::XML::Node* CItem::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPItem *item = this->spitem; + SPItem* object = item; // in the case of SP_OBJECT_WRITE_BUILD, the item should always be newly created, // so we need to add any children from the underlying object to the new repr @@ -721,13 +753,22 @@ Inkscape::XML::Node *SPItem::sp_item_write(SPObject *const object, Inkscape::XML } } - if (((SPObjectClass *) (SPItemClass::static_parent_class))->write) { - ((SPObjectClass *) (SPItemClass::static_parent_class))->write(object, xml_doc, repr, flags); - } + CObject::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +Inkscape::XML::Node *SPItem::sp_item_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPItem*)object)->citem->onWrite(xml_doc, repr, flags); +} + +// CPPIFY: make pure virtual +Geom::OptRect CItem::onBbox(Geom::Affine const &transform, SPItem::BBoxType type) { + throw; +} + /** * Get item's geometric bounding box in this item's coordinate system. * @@ -813,6 +854,7 @@ Geom::OptRect SPItem::visualBounds(Geom::Affine const &transform) const return bbox; } + Geom::OptRect SPItem::bounds(BBoxType type, Geom::Affine const &transform) const { if (type == GEOMETRIC_BBOX) { @@ -902,6 +944,12 @@ unsigned SPItem::pos_in_parent() return 0; } +// CPPIFY: make pure virtual, see below! +void CItem::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + throw; +} + +// CPPIFY: remove void SPItem::sp_item_private_snappoints(SPItem const * /*item*/, std::vector &/*p*/, Inkscape::SnapPreferences const * /*snapprefs*/) { /* This will only be called if the derived class doesn't override this. @@ -911,7 +959,6 @@ void SPItem::sp_item_private_snappoints(SPItem const * /*item*/, std::vector &p, Inkscape::SnapPreferences const *snapprefs) const { // Get the snappoints of the item @@ -953,6 +1000,11 @@ void SPItem::getSnappoints(std::vector &p, Inkscap } } +// CPPIFY: make pure virtual +void CItem::onPrint(SPPrintContext* ctx) { + throw; +} + void SPItem::invoke_print(SPPrintContext *ctx) { if ( !isHidden() ) { @@ -970,9 +1022,15 @@ void SPItem::invoke_print(SPPrintContext *ctx) } } -gchar *SPItem::sp_item_private_description(SPItem */*item*/) +// CPPIFY: is it possible to combine this method with "SPItem::description()"? +gchar* CItem::onDescription() { + return g_strdup(_("Object")); +} + +// CPPIFY: remove +gchar *SPItem::sp_item_private_description(SPItem *item) { - return g_strdup(_("Object")); + return item->citem->onDescription(); } /** @@ -1040,6 +1098,11 @@ unsigned SPItem::display_key_new(unsigned numkeys) return dkey - numkeys; } +// CPPIFY: make pure virtual +Inkscape::DrawingItem* CItem::onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + throw; +} + Inkscape::DrawingItem *SPItem::invoke_show(Inkscape::Drawing &drawing, unsigned key, unsigned flags) { Inkscape::DrawingItem *ai = NULL; @@ -1094,6 +1157,11 @@ Inkscape::DrawingItem *SPItem::invoke_show(Inkscape::Drawing &drawing, unsigned return ai; } +// CPPIFY: make pure virtual +void CItem::onHide(unsigned int key) { + throw; +} + void SPItem::invoke_hide(unsigned key) { if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->hide) { @@ -1323,6 +1391,11 @@ void SPItem::adjust_livepatheffect (Geom::Affine const &postmul, bool set) } } +// CPPIFY:: make pure virtual +Geom::Affine CItem::onSetTransform(Geom::Affine const &transform) { + throw; +} + /** * Set a new transform on an object. * @@ -1425,6 +1498,11 @@ void SPItem::doWriteTransform(Inkscape::XML::Node *repr, Geom::Affine const &tra _transformed_signal.emit(&advertized_transform, this); } +// CPPIFY: see below, do not make pure? +gint CItem::onEvent(SPEvent* event) { + return FALSE; +} + gint SPItem::emitEvent(SPEvent &event) { if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->event) { @@ -1449,15 +1527,22 @@ void SPItem::set_item_transform(Geom::Affine const &transform_matrix) } } -void SPItem::convert_item_to_guides() { - // Use derived method if present ... - if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->convert_to_guides) { - (*((SPItemClass *) G_OBJECT_GET_CLASS(this))->convert_to_guides)(this); - } else { - // .. otherwise simply place the guides around the item's bounding box +void CItem::onConvertToGuides() { + // CPPIFY: If not overridden, call SPItem::convert_to_guides(), see below! + this->spitem->convert_to_guides(); +} - convert_to_guides(); - } +// CPPIFY: remove +void SPItem::convert_item_to_guides() { +// // Use derived method if present ... +// if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->convert_to_guides) { +// (*((SPItemClass *) G_OBJECT_GET_CLASS(this))->convert_to_guides)(this); +// } else { +// // .. otherwise simply place the guides around the item's bounding box +// +// convert_to_guides(); +// } + this->citem->onConvertToGuides(); } diff --git a/src/sp-item.h b/src/sp-item.h index 2c7bd5a5d..69300e093 100644 --- a/src/sp-item.h +++ b/src/sp-item.h @@ -100,6 +100,7 @@ public: class SPItem; class SPItemClass; +class CItem; #define SP_TYPE_ITEM (SPItem::getType ()) #define SP_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_ITEM, SPItem)) @@ -120,6 +121,8 @@ public: VISUAL_BBOX }; + CItem* citem; + unsigned int sensitive : 1; unsigned int stop_paint: 1; mutable unsigned bbox_valid : 1; @@ -244,6 +247,7 @@ private: static void mask_ref_changed(SPObject *old_clip, SPObject *clip, SPItem *item); friend class SPItemClass; + friend class CItem; }; /// The SPItem vtable. @@ -283,8 +287,36 @@ public: static void sp_item_class_init(SPItemClass *klass); friend class SPItem; + friend class CItem; +}; + + +class CItem : public CObject { +public: + CItem(SPItem* item); + virtual ~CItem(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onRelease(); + virtual void onSet(unsigned int key, gchar const* value); + virtual void onUpdate(SPCtx *ctx, guint flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + + virtual Geom::OptRect onBbox(Geom::Affine const &transform, SPItem::BBoxType type); + virtual void onPrint(SPPrintContext *ctx); + virtual gchar* onDescription(); + virtual Inkscape::DrawingItem* onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); + virtual void onHide(unsigned int key); + virtual void onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs); + virtual Geom::Affine onSetTransform(Geom::Affine const &transform); + virtual void onConvertToGuides(); + virtual gint onEvent(SPEvent *event); + +protected: + SPItem* spitem; }; + // Utility Geom::Affine i2anc_affine(SPObject const *item, SPObject const *ancestor); -- cgit v1.2.3 From 39c965d12930e24942a9ae036c5cb2166eee81b4 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 02:09:06 +0200 Subject: Added "virtual pad" to SPLPEItem. (bzr r11608.1.3) --- src/sp-lpe-item.cpp | 151 ++++++++++++++++++++++++++++++++++++---------------- src/sp-lpe-item.h | 29 ++++++++++ 2 files changed, 134 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index f17422d02..f43e5cc07 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -111,9 +111,21 @@ sp_lpe_item_class_init(SPLPEItemClass *klass) klass->update_patheffect = NULL; } +// CPPIFY: remove +CLPEItem::CLPEItem(SPLPEItem* lpeitem) : CItem(lpeitem) { + this->splpeitem = lpeitem; +} + +CLPEItem::~CLPEItem() { +} + static void sp_lpe_item_init(SPLPEItem *lpeitem) { + lpeitem->clpeitem = new CLPEItem(lpeitem); + lpeitem->citem = lpeitem->clpeitem; + lpeitem->cobject = lpeitem->clpeitem; + lpeitem->path_effects_enabled = 1; lpeitem->path_effect_list = new PathEffectList(); @@ -130,6 +142,15 @@ sp_lpe_item_finalize(GObject *object) } } +void CLPEItem::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPLPEItem* object = this->splpeitem; + + object->readAttr( "inkscape:path-effect" ); + + CItem::onBuild(document, repr); +} + +// CPPIFY: remove /** * Reads the Inkscape::XML::Node, and initializes SPLPEItem variables. For this to get called, * our name must be associated with a repr via "sp_object_type_register". Best done through @@ -138,20 +159,11 @@ sp_lpe_item_finalize(GObject *object) static void sp_lpe_item_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - object->readAttr( "inkscape:path-effect" ); - - if (((SPObjectClass *) parent_class)->build) { - ((SPObjectClass *) parent_class)->build(object, document, repr); - } + ((SPLPEItem*)object)->clpeitem->onBuild(document, repr); } -/** - * Drops any allocated memory. - */ -static void -sp_lpe_item_release(SPObject *object) -{ - SPLPEItem *lpeitem = (SPLPEItem *) object; +void CLPEItem::onRelease() { + SPLPEItem *lpeitem = this->splpeitem; // disconnect all modified listeners: for (std::list::iterator mod_it = lpeitem->lpe_modified_connection_list->begin(); @@ -173,17 +185,22 @@ sp_lpe_item_release(SPObject *object) delete lpeitem->path_effect_list; lpeitem->path_effect_list = NULL; - if (((SPObjectClass *) parent_class)->release) - ((SPObjectClass *) parent_class)->release(object); + CItem::onRelease(); } +// CPPIFY: remove /** - * Sets a specific value in the SPLPEItem. + * Drops any allocated memory. */ static void -sp_lpe_item_set(SPObject *object, unsigned int key, gchar const *value) +sp_lpe_item_release(SPObject *object) { - SPLPEItem *lpeitem = (SPLPEItem *) object; + ((SPLPEItem*)object)->clpeitem->onRelease(); +} + +void CLPEItem::onSet(unsigned int key, gchar const* value) { + SPLPEItem *lpeitem = this->splpeitem; + SPLPEItem* object = lpeitem; switch (key) { case SP_ATTR_INKSCAPE_PATH_EFFECT: @@ -243,49 +260,66 @@ sp_lpe_item_set(SPObject *object, unsigned int key, gchar const *value) } break; default: - if (((SPObjectClass *) parent_class)->set) { - ((SPObjectClass *) parent_class)->set(object, key, value); - } + CItem::onSet(key, value); break; } } +// CPPIFY: remove /** - * Receives update notifications. + * Sets a specific value in the SPLPEItem. */ static void -sp_lpe_item_update(SPObject *object, SPCtx *ctx, guint flags) +sp_lpe_item_set(SPObject *object, unsigned int key, gchar const *value) { - if (((SPObjectClass *) parent_class)->update) { - ((SPObjectClass *) parent_class)->update(object, ctx, flags); - } + ((SPLPEItem*)object)->clpeitem->onSet(key, value); +} + +void CLPEItem::onUpdate(SPCtx* ctx, unsigned int flags) { + CItem::onUpdate(ctx, flags); - // update the helperpaths of all LPEs applied to the item + // update the helperpaths of all LPEs applied to the item // TODO: re-add for the new node tool } +// CPPIFY: remove /** - * Sets modified flag for all sub-item views. + * Receives update notifications. */ static void -sp_lpe_item_modified (SPObject *object, unsigned int flags) +sp_lpe_item_update(SPObject *object, SPCtx *ctx, guint flags) { + ((SPLPEItem*)object)->clpeitem->onUpdate(ctx, flags); +} + +void CLPEItem::onModified(unsigned int flags) { + SPLPEItem *lpeitem = this->splpeitem; + SPLPEItem* object = lpeitem; + if (SP_IS_GROUP(object) && (flags & SP_OBJECT_MODIFIED_FLAG) && (flags & SP_OBJECT_USER_MODIFIED_FLAG_B)) { sp_lpe_item_update_patheffect(SP_LPE_ITEM(object), true, true); } - if (((SPObjectClass *) (parent_class))->modified) { - (* ((SPObjectClass *) (parent_class))->modified) (object, flags); - } + // CPPIFY: This doesn't make no sense. + // CObject::onModified is pure and CItem doesn't override this method. What was the idea behind these lines? +// if (((SPObjectClass *) (parent_class))->modified) { +// (* ((SPObjectClass *) (parent_class))->modified) (object, flags); +// } +// CItem::onModified(flags); } +// CPPIFY: remove /** - * Writes its settings to an incoming repr object, if any. + * Sets modified flag for all sub-item views. */ -static Inkscape::XML::Node * -sp_lpe_item_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void +sp_lpe_item_modified (SPObject *object, unsigned int flags) { - SPLPEItem *lpeitem = (SPLPEItem *) object; + ((SPLPEItem*)object)->clpeitem->onModified(flags); +} + +Inkscape::XML::Node* CLPEItem::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPLPEItem *lpeitem = this->splpeitem; if (flags & SP_OBJECT_WRITE_EXT) { if ( sp_lpe_item_has_path_effect(lpeitem) ) { @@ -296,13 +330,21 @@ sp_lpe_item_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape:: } } - if (((SPObjectClass *)(parent_class))->write) { - ((SPObjectClass *)(parent_class))->write(object, xml_doc, repr, flags); - } + CItem::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +/** + * Writes its settings to an incoming repr object, if any. + */ +static Inkscape::XML::Node * +sp_lpe_item_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPLPEItem*)object)->clpeitem->onWrite(xml_doc, repr, flags); +} + /** * returns true when LPE was successful. */ @@ -360,6 +402,11 @@ bool sp_lpe_item_perform_path_effect(SPLPEItem *lpeitem, SPCurve *curve) { return true; } +// CPPIFY: make pure virtual +void CLPEItem::onUpdatePatheffect(bool write) { + throw; +} + /** * Calls any registered handlers for the update_patheffect action */ @@ -675,11 +722,10 @@ void sp_lpe_item_edit_next_param_oncanvas(SPLPEItem *lpeitem, SPDesktop *dt) } } -static void -sp_lpe_item_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) -{ - if (((SPObjectClass *) (parent_class))->child_added) - (* ((SPObjectClass *) (parent_class))->child_added) (object, child, ref); +void CLPEItem::onChildAdded(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { + SPLPEItem* object = this->splpeitem; + + CItem::onChildAdded(child, ref); if (SP_IS_LPE_ITEM(object) && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(object))) { SPObject *ochild = object->get_child_by_repr(child); @@ -689,9 +735,16 @@ sp_lpe_item_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape: } } +// CPPIFY: remove static void -sp_lpe_item_remove_child (SPObject * object, Inkscape::XML::Node * child) +sp_lpe_item_child_added (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { + ((SPLPEItem*)object)->clpeitem->onChildAdded(child, ref); +} + +void CLPEItem::onRemoveChild(Inkscape::XML::Node * child) { + SPLPEItem* object = this->splpeitem; + if (SP_IS_LPE_ITEM(object) && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(object))) { SPObject *ochild = object->get_child_by_repr(child); if ( ochild && SP_IS_LPE_ITEM(ochild) ) { @@ -699,8 +752,14 @@ sp_lpe_item_remove_child (SPObject * object, Inkscape::XML::Node * child) } } - if (((SPObjectClass *) (parent_class))->remove_child) - (* ((SPObjectClass *) (parent_class))->remove_child) (object, child); + CItem::onRemoveChild(child); +} + +// CPPIFY: remove +static void +sp_lpe_item_remove_child (SPObject * object, Inkscape::XML::Node * child) +{ + ((SPLPEItem*)object)->clpeitem->onRemoveChild(child); } static std::string patheffectlist_write_svg(PathEffectList const & list) diff --git a/src/sp-lpe-item.h b/src/sp-lpe-item.h index 8f99ae1b0..b45e9950a 100644 --- a/src/sp-lpe-item.h +++ b/src/sp-lpe-item.h @@ -26,6 +26,7 @@ struct LivePathEffectObject; struct SPCurve; +class CLPEItem; namespace Inkscape{ namespace Display { @@ -41,6 +42,8 @@ typedef std::list PathEffectList class SPLPEItem : public SPItem { public: + CLPEItem* clpeitem; + int path_effects_enabled; PathEffectList* path_effect_list; @@ -59,6 +62,32 @@ struct SPLPEItemClass { void (* update_patheffect) (SPLPEItem *lpeitem, bool write); }; + +class CLPEItem : public CItem { +public: + CLPEItem(SPLPEItem* lpeitem); + virtual ~CLPEItem(); + + virtual void onBuild(SPDocument* doc, Inkscape::XML::Node* repr); + virtual void onRelease(); + + virtual void onSet(unsigned int key, gchar const* value); + + virtual void onUpdate(SPCtx* ctx, unsigned int flags); + virtual void onModified(unsigned int flags); + + virtual void onChildAdded(Inkscape::XML::Node* child, Inkscape::XML::Node* ref); + virtual void onRemoveChild(Inkscape::XML::Node* child); + + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + + virtual void onUpdatePatheffect(bool write); + +protected: + SPLPEItem* splpeitem; +}; + + GType sp_lpe_item_get_type(); void sp_lpe_item_update_patheffect (SPLPEItem *lpeitem, bool wholetree, bool write); -- cgit v1.2.3 From c849e4b8aaffdb80a32b29bfda1df21d00b468eb Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 02:53:06 +0200 Subject: Added "virtual pad" to SPShape. (bzr r11608.1.4) --- src/sp-shape.cpp | 251 ++++++++++++++++++++++++++++++++++--------------------- src/sp-shape.h | 33 ++++++++ 2 files changed, 191 insertions(+), 93 deletions(-) (limited to 'src') diff --git a/src/sp-shape.cpp b/src/sp-shape.cpp index f27b3c9db..e0f13c62d 100644 --- a/src/sp-shape.cpp +++ b/src/sp-shape.cpp @@ -111,11 +111,23 @@ void SPShapeClass::sp_shape_class_init(SPShapeClass *klass) klass->set_shape = NULL; } +CShape::CShape(SPShape* shape) : CLPEItem(shape) { + this->spshape = shape; +} + +CShape::~CShape() { +} + /** * Initializes an SPShape object. */ void SPShape::sp_shape_init(SPShape *shape) { + shape->cshape = new CShape(shape); + shape->clpeitem = shape->cshape; + shape->citem = shape->cshape; + shape->cobject = shape->cshape; + for ( int i = 0 ; i < SP_MARKER_LOC_QTY ; i++ ) { new (&shape->_release_connect[i]) sigc::connection(); new (&shape->_modified_connect[i]) sigc::connection(); @@ -141,6 +153,17 @@ void SPShape::sp_shape_finalize(GObject *object) } } +void CShape::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPShape* object = this->spshape; + + CLPEItem::onBuild(document, repr); + + for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) { + sp_shape_set_marker (object, i, object->style->marker[i].value); + } +} + +// CPPIFY: remove /** * Virtual build callback for SPMarker. * @@ -150,31 +173,15 @@ void SPShape::sp_shape_finalize(GObject *object) */ void SPShape::sp_shape_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) (SPShapeClass::parent_class))->build) { - (*((SPObjectClass *) (SPShapeClass::parent_class))->build) (object, document, repr); - } - - for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) { - sp_shape_set_marker (object, i, object->style->marker[i].value); - } + ((SPShape*)object)->cshape->onBuild(document, repr); } -/** - * Removes, releases and unrefs all children of object - * - * This is the inverse of sp_shape_build(). It must be invoked as soon - * as the shape is removed from the tree, even if it is still referenced - * by other objects. This routine also disconnects/unrefs markers and - * curves attached to it. - * - * \see sp_object_release() - */ -void SPShape::sp_shape_release(SPObject *object) -{ +void CShape::onRelease() { SPItem *item; SPShape *shape; SPItemView *v; int i; + SPShape* object = this->spshape; item = (SPItem *) object; shape = (SPShape *) object; @@ -196,40 +203,51 @@ void SPShape::sp_shape_release(SPObject *object) shape->_curve_before_lpe = shape->_curve_before_lpe->unref(); } - if (((SPObjectClass *) SPShapeClass::parent_class)->release) { - ((SPObjectClass *) SPShapeClass::parent_class)->release (object); - } + CLPEItem::onRelease(); } +// CPPIFY: remove +/** + * Removes, releases and unrefs all children of object + * + * This is the inverse of sp_shape_build(). It must be invoked as soon + * as the shape is removed from the tree, even if it is still referenced + * by other objects. This routine also disconnects/unrefs markers and + * curves attached to it. + * + * \see sp_object_release() + */ +void SPShape::sp_shape_release(SPObject *object) +{ + ((SPShape*)object)->cshape->onRelease(); +} +void CShape::onSet(unsigned int key, const gchar* value) { + CLPEItem::onSet(key, value); +} +// CPPIFY: remove void SPShape::sp_shape_set(SPObject *object, unsigned int key, gchar const *value) { - if (((SPObjectClass *) SPShapeClass::parent_class)->set) { - ((SPObjectClass *) SPShapeClass::parent_class)->set(object, key, value); - } + ((SPShape*)object)->cshape->onSet(key, value); +} + +Inkscape::XML::Node* CShape::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + CLPEItem::onWrite(xml_doc, repr, flags); + return repr; } +// CPPIFY: remove Inkscape::XML::Node * SPShape::sp_shape_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) { - if (((SPObjectClass *)(SPShapeClass::parent_class))->write) { - ((SPObjectClass *)(SPShapeClass::parent_class))->write(object, doc, repr, flags); - } - - return repr; + return ((SPShape*)object)->cshape->onWrite(doc, repr, flags); } -/** - * Updates the shape when its attributes have changed. Also establishes - * marker objects to match the style settings. - */ -void SPShape::sp_shape_update(SPObject *object, SPCtx *ctx, unsigned int flags) -{ - SPShape *shape = (SPShape *) object; +void CShape::onUpdate(SPCtx* ctx, guint flags) { + SPShape* shape = this->spshape; + SPShape* object = shape; - if (((SPObjectClass *) (SPShapeClass::parent_class))->update) { - (* ((SPObjectClass *) (SPShapeClass::parent_class))->update) (object, ctx, flags); - } + CLPEItem::onUpdate(ctx, flags); /* This stanza checks that an object's marker style agrees with * the marker objects it has allocated. sp_shape_set_marker ensures @@ -281,11 +299,21 @@ void SPShape::sp_shape_update(SPObject *object, SPCtx *ctx, unsigned int flags) /* Update marker views */ for (SPItemView *v = shape->display; v != NULL; v = v->next) { - sp_shape_update_marker_view (shape, v->arenaitem); + SPShape::sp_shape_update_marker_view (shape, v->arenaitem); } } } +// CPPIFY: remove +/** + * Updates the shape when its attributes have changed. Also establishes + * marker objects to match the style settings. + */ +void SPShape::sp_shape_update(SPObject *object, SPCtx *ctx, unsigned int flags) +{ + ((SPShape*)object)->cshape->onUpdate(ctx, flags); +} + /** * Calculate the transform required to get a marker's path object in the * right place for particular path segment on a shape. @@ -479,32 +507,32 @@ void SPShape::sp_shape_update_marker_view(SPShape *shape, Inkscape::DrawingItem } } -/** - * Sets modified flag for all sub-item views. - */ -void SPShape::sp_shape_modified(SPObject *object, unsigned int flags) -{ - SPShape *shape = SP_SHAPE (object); +void CShape::onModified(unsigned int flags) { + SPShape* shape = this->spshape; + SPShape* object = shape; - if (((SPObjectClass *) (SPShapeClass::parent_class))->modified) { - (* ((SPObjectClass *) (SPShapeClass::parent_class))->modified) (object, flags); - } + CLPEItem::onModified(flags); if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { for (SPItemView *v = shape->display; v != NULL; v = v->next) { Inkscape::DrawingShape *sh = dynamic_cast(v->arenaitem); - sh->setStyle(object->style); + sh->setStyle(shape->style); } } } +// CPPIFY: remove /** - * Calculates the bounding box for item, storing it into bbox. - * This also includes the bounding boxes of any markers included in the shape. + * Sets modified flag for all sub-item views. */ -Geom::OptRect SPShape::sp_shape_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType bboxtype) +void SPShape::sp_shape_modified(SPObject *object, unsigned int flags) { - SPShape const *shape = SP_SHAPE (item); + ((SPShape*)object)->cshape->onModified(flags); +} + +Geom::OptRect CShape::onBbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype) { + SPShape const* shape = this->spshape; + SPShape const* item = shape; Geom::OptRect bbox; if (!shape->_curve) return bbox; @@ -656,6 +684,16 @@ Geom::OptRect SPShape::sp_shape_bbox(SPItem const *item, Geom::Affine const &tra return bbox; } +// CPPIFY: remove +/** + * Calculates the bounding box for item, storing it into bbox. + * This also includes the bounding boxes of any markers included in the shape. + */ +Geom::OptRect SPShape::sp_shape_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType bboxtype) +{ + return ((SPShape*)item)->cshape->onBbox(transform, bboxtype); +} + static void sp_shape_print_invoke_marker_printing(SPObject *obj, Geom::Affine tr, SPStyle const *style, SPPrintContext *ctx) { @@ -674,19 +712,12 @@ sp_shape_print_invoke_marker_printing(SPObject *obj, Geom::Affine tr, SPStyle co marker_item->transform = old_tr; } } -/** - * Prepares shape for printing. Handles printing of comments for printing - * debugging, sizes the item to fit into the document width/height, - * applies print fill/stroke, sets transforms for markers, and adds - * comment labels. - */ -void -sp_shape_print (SPItem *item, SPPrintContext *ctx) -{ - Geom::OptRect pbox, dbox, bbox; - SPShape *shape = SP_SHAPE(item); +void CShape::onPrint(SPPrintContext* ctx) { + SPShape *shape = this->spshape; + SPShape* item = shape; + Geom::OptRect pbox, dbox, bbox; if (!shape->_curve) return; Geom::PathVector const & pathv = shape->_curve->get_pathvector(); @@ -781,21 +812,30 @@ sp_shape_print (SPItem *item, SPPrintContext *ctx) } } - if (add_comments) { - gchar * comment = g_strdup_printf("end '%s'", - item->defaultLabel()); - sp_print_comment(ctx, comment); - g_free(comment); - } + if (add_comments) { + gchar * comment = g_strdup_printf("end '%s'", + item->defaultLabel()); + sp_print_comment(ctx, comment); + g_free(comment); + } } +// CPPIFY: remove /** - * Sets style, path, and paintbox. Updates marker views, including dimensions. + * Prepares shape for printing. Handles printing of comments for printing + * debugging, sizes the item to fit into the document width/height, + * applies print fill/stroke, sets transforms for markers, and adds + * comment labels. */ -Inkscape::DrawingItem * SPShape::sp_shape_show(SPItem *item, Inkscape::Drawing &drawing, unsigned int /*key*/, unsigned int /*flags*/) +void +sp_shape_print (SPItem *item, SPPrintContext *ctx) { - SPObject *object = item; - SPShape *shape = SP_SHAPE(item); + ((SPShape*)item)->cshape->onPrint(ctx); +} + +Inkscape::DrawingItem* CShape::onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + SPObject *object = this->spshape; + SPShape *shape = this->spshape; Inkscape::DrawingShape *s = new Inkscape::DrawingShape(drawing); s->setStyle(object->style); @@ -826,23 +866,27 @@ Inkscape::DrawingItem * SPShape::sp_shape_show(SPItem *item, Inkscape::Drawing & } /* Update marker views */ - sp_shape_update_marker_view (shape, s); + SPShape::sp_shape_update_marker_view (shape, s); } return s; } /** - * Hides/removes marker views from the shape. + * Sets style, path, and paintbox. Updates marker views, including dimensions. */ -void SPShape::sp_shape_hide(SPItem *item, unsigned int key) +Inkscape::DrawingItem * SPShape::sp_shape_show(SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { - SPShape *shape; + return ((SPShape*)item)->cshape->onShow(drawing, key, flags); +} + +void CShape::onHide(unsigned int key) { + SPShape *shape = this->spshape; + SPShape* item = shape; + SPItemView *v; int i; - shape = (SPShape *) item; - for (i=0; i_marker[i]) { for (v = item->display; v != NULL; v = v->next) { @@ -854,9 +898,21 @@ void SPShape::sp_shape_hide(SPItem *item, unsigned int key) } } - if (((SPItemClass *) SPShapeClass::parent_class)->hide) { - ((SPItemClass *) SPShapeClass::parent_class)->hide (item, key); - } + // CPPIFY: This doesn't make no sense. + // CItem::onHide is pure and CLPEItem doesn't override it. What was the idea behind these lines? +// if (((SPItemClass *) SPShapeClass::parent_class)->hide) { +// ((SPItemClass *) SPShapeClass::parent_class)->hide (item, key); +// } +// CLPEItem::onHide(key); +} + +// CPPIFY: remove +/** + * Hides/removes marker views from the shape. + */ +void SPShape::sp_shape_hide(SPItem *item, unsigned int key) +{ + ((SPShape*)item)->cshape->onHide(key); } /** @@ -1013,7 +1069,10 @@ sp_shape_set_marker (SPObject *object, unsigned int key, const gchar *value) } } - +// CPPIFY: make pure virtual +void CShape::onSetShape() { + throw; +} /* Shape section */ @@ -1107,15 +1166,13 @@ void SPShape::setCurveInsync(SPCurve *new_curve, unsigned int owner) } } -/** - * Return all nodes in a path that are to be considered for snapping - */ -void SPShape::sp_shape_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) -{ - g_assert(item != NULL); +void CShape::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + SPShape const *shape = this->spshape; + SPShape const *item = shape; + + g_assert(item != NULL); g_assert(SP_IS_SHAPE(item)); - SPShape const *shape = SP_SHAPE(item); if (shape->_curve == NULL) { return; } @@ -1210,7 +1267,15 @@ void SPShape::sp_shape_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) +{ + ((SPShape*)item)->cshape->onSnappoints(p, snapprefs); } /* diff --git a/src/sp-shape.h b/src/sp-shape.h index 453750946..7459b2f90 100644 --- a/src/sp-shape.h +++ b/src/sp-shape.h @@ -32,12 +32,15 @@ class SPDesktop; namespace Inkscape { class DrawingItem; } +class CShape; /** * Base class for shapes, including element */ class SPShape : public SPLPEItem { public: + CShape* cshape; + static GType getType (void); void setShape (); SPCurve * getCurve () const; @@ -79,6 +82,7 @@ private: friend class SPShapeClass; + friend class CShape; }; class SPShapeClass { @@ -95,6 +99,35 @@ private: friend class SPShape; }; + +class CShape : public CLPEItem { +public: + CShape(SPShape* shape); + virtual ~CShape(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onRelease(); + virtual void onUpdate(SPCtx* ctx, guint flags); + virtual void onModified(unsigned int flags); + + virtual void onSet(unsigned int key, gchar const* value); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + + virtual Geom::OptRect onBbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype); + virtual void onPrint(SPPrintContext* ctx); + + virtual Inkscape::DrawingItem* onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); + virtual void onHide(unsigned int key); + + virtual void onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs); + + virtual void onSetShape(); + +protected: + SPShape* spshape; +}; + + void sp_shape_set_marker (SPObject *object, unsigned int key, const gchar *value); Geom::Affine sp_shape_marker_get_transform(Geom::Curve const & c1, Geom::Curve const & c2); -- cgit v1.2.3 From b86f217e4c4fb55989128b028faaa95650b9d639 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 16:32:37 +0200 Subject: Added "virtual pad" to - SPGenericEllipse - SPEllipse - SPCircle - SPArc (bzr r11608.1.5) --- src/sp-ellipse.cpp | 303 ++++++++++++++++++++++++++++++++++++++--------------- src/sp-ellipse.h | 92 +++++++++++++++- 2 files changed, 309 insertions(+), 86 deletions(-) (limited to 'src') diff --git a/src/sp-ellipse.cpp b/src/sp-ellipse.cpp index d74eaa6fb..d5d25504b 100644 --- a/src/sp-ellipse.cpp +++ b/src/sp-ellipse.cpp @@ -121,9 +121,22 @@ static void sp_genericellipse_class_init(SPGenericEllipseClass *klass) lpe_item_class->update_patheffect = sp_genericellipse_update_patheffect; } +CGenericEllipse::CGenericEllipse(SPGenericEllipse* genericEllipse) : CShape(genericEllipse) { + this->spgenericEllipse = genericEllipse; +} + +CGenericEllipse::~CGenericEllipse() { +} + static void sp_genericellipse_init(SPGenericEllipse *ellipse) { + ellipse->cgenericEllipse = new CGenericEllipse(ellipse); + ellipse->cshape = ellipse->cgenericEllipse; + ellipse->clpeitem = ellipse->cgenericEllipse; + ellipse->citem = ellipse->cgenericEllipse; + ellipse->cobject = ellipse->cgenericEllipse; + ellipse->cx.unset(); ellipse->cy.unset(); ellipse->rx.unset(); @@ -134,9 +147,9 @@ sp_genericellipse_init(SPGenericEllipse *ellipse) ellipse->closed = TRUE; } -static void -sp_genericellipse_update(SPObject *object, SPCtx *ctx, guint flags) -{ +void CGenericEllipse::onUpdate(SPCtx *ctx, guint flags) { + SPGenericEllipse* object = this->spgenericEllipse; + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { SPGenericEllipse *ellipse = (SPGenericEllipse *) object; SPStyle const *style = object->style; @@ -154,14 +167,18 @@ sp_genericellipse_update(SPObject *object, SPCtx *ctx, guint flags) static_cast(object)->setShape(); } - if (((SPObjectClass *) ge_parent_class)->update) - ((SPObjectClass *) ge_parent_class)->update(object, ctx, flags); + CShape::onUpdate(ctx, flags); } +// CPPIFY: remove static void -sp_genericellipse_update_patheffect(SPLPEItem *lpeitem, bool write) +sp_genericellipse_update(SPObject *object, SPCtx *ctx, guint flags) { - SPShape *shape = (SPShape *) lpeitem; + ((SPGenericEllipse*)object)->cgenericEllipse->onUpdate(ctx, flags); +} + +void CGenericEllipse::onUpdatePatheffect(bool write) { + SPShape *shape = this->spgenericEllipse; sp_genericellipse_set_shape(shape); if (write) { @@ -178,10 +195,19 @@ sp_genericellipse_update_patheffect(SPLPEItem *lpeitem, bool write) ((SPObject *)shape)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } +// CPPIFY: remove +static void +sp_genericellipse_update_patheffect(SPLPEItem *lpeitem, bool write) +{ + ((SPGenericEllipse*)lpeitem)->cgenericEllipse->onUpdatePatheffect(write); + +} + /* fixme: Think (Lauris) */ /* Can't we use arcto in this method? */ -static void sp_genericellipse_set_shape(SPShape *shape) -{ +void CGenericEllipse::onSetShape() { + SPGenericEllipse* shape = this->spgenericEllipse; + if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(shape))) { g_warning ("The ellipse shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as ellipse will remove the bad LPE"); if (shape->getRepr()->attribute("d")) { @@ -269,8 +295,15 @@ static void sp_genericellipse_set_shape(SPShape *shape) curve->unref(); } -static void sp_genericellipse_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) +// CPPIFY: remove +static void sp_genericellipse_set_shape(SPShape *shape) { + ((SPGenericEllipse*)shape)->cgenericEllipse->onSetShape(); +} + +void CGenericEllipse::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + SPGenericEllipse* item = this->spgenericEllipse; + g_assert(item != NULL); g_assert(SP_IS_GENERICELLIPSE(item)); @@ -336,6 +369,12 @@ static void sp_genericellipse_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) +{ + ((SPGenericEllipse*)item)->cgenericEllipse->onSnappoints(p, snapprefs); +} + void sp_genericellipse_normalize(SPGenericEllipse *ellipse) { @@ -351,9 +390,9 @@ sp_genericellipse_normalize(SPGenericEllipse *ellipse) /* Now we keep: 0 <= start < end <= 2*PI */ } -static Inkscape::XML::Node *sp_genericellipse_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) -{ - SPGenericEllipse *ellipse = SP_GENERICELLIPSE(object); +Inkscape::XML::Node* CGenericEllipse::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPGenericEllipse *ellipse = this->spgenericEllipse; + SPGenericEllipse* object = ellipse; if (flags & SP_OBJECT_WRITE_EXT) { if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { @@ -370,13 +409,17 @@ static Inkscape::XML::Node *sp_genericellipse_write(SPObject *object, Inkscape:: } } - if (((SPObjectClass *) ge_parent_class)->write) { - ((SPObjectClass *) ge_parent_class)->write(object, xml_doc, repr, flags); - } + CShape::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +static Inkscape::XML::Node *sp_genericellipse_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPGenericEllipse*)object)->cgenericEllipse->onWrite(xml_doc, repr, flags); +} + /* SVG element */ static void sp_ellipse_class_init(SPEllipseClass *klass); @@ -425,30 +468,43 @@ static void sp_ellipse_class_init(SPEllipseClass *klass) item_class->description = sp_ellipse_description; } -static void -sp_ellipse_init(SPEllipse */*ellipse*/) -{ - /* Nothing special */ +CEllipse::CEllipse(SPEllipse* ellipse) : CGenericEllipse(ellipse) { + this->spellipse = ellipse; +} + +CEllipse::~CEllipse() { } static void -sp_ellipse_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) +sp_ellipse_init(SPEllipse *ellipse) { - if (((SPObjectClass *) ellipse_parent_class)->build) - (* ((SPObjectClass *) ellipse_parent_class)->build) (object, document, repr); + ellipse->cellipse = new CEllipse(ellipse); + ellipse->cgenericEllipse = ellipse->cellipse; + ellipse->cshape = ellipse->cellipse; + ellipse->clpeitem = ellipse->cellipse; + ellipse->citem = ellipse->cellipse; + ellipse->cobject = ellipse->cellipse; +} +void CEllipse::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + CGenericEllipse::onBuild(document, repr); + + SPEllipse* object = this->spellipse; object->readAttr( "cx" ); object->readAttr( "cy" ); object->readAttr( "rx" ); object->readAttr( "ry" ); } -static Inkscape::XML::Node * -sp_ellipse_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +// CPPIFY: remove +static void +sp_ellipse_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - SPGenericEllipse *ellipse; + ((SPEllipse*)object)->cellipse->onBuild(document, repr); +} - ellipse = SP_GENERICELLIPSE(object); +Inkscape::XML::Node* CEllipse::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPGenericEllipse *ellipse = this->spellipse; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:ellipse"); @@ -459,18 +515,21 @@ sp_ellipse_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::X sp_repr_set_svg_double(repr, "rx", ellipse->rx.computed); sp_repr_set_svg_double(repr, "ry", ellipse->ry.computed); - if (((SPObjectClass *) ellipse_parent_class)->write) - (* ((SPObjectClass *) ellipse_parent_class)->write) (object, xml_doc, repr, flags); + CGenericEllipse::onWrite(xml_doc, repr, flags); return repr; } -static void -sp_ellipse_set(SPObject *object, unsigned int key, gchar const *value) +// CPPIFY: remove +static Inkscape::XML::Node * +sp_ellipse_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPGenericEllipse *ellipse; + return ((SPEllipse*)object)->cellipse->onWrite(xml_doc, repr, flags); +} - ellipse = SP_GENERICELLIPSE(object); +void CEllipse::onSet(unsigned int key, gchar const* value) { + SPEllipse *ellipse = this->spellipse; + SPEllipse* object = (SPEllipse*)ellipse; switch (key) { case SP_ATTR_CX: @@ -494,15 +553,26 @@ sp_ellipse_set(SPObject *object, unsigned int key, gchar const *value) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) ellipse_parent_class)->set) - ((SPObjectClass *) ellipse_parent_class)->set(object, key, value); + CGenericEllipse::onSet(key, value); break; } } -static gchar *sp_ellipse_description(SPItem */*item*/) +// CPPIFY: remove +static void +sp_ellipse_set(SPObject *object, unsigned int key, gchar const *value) { - return g_strdup(_("Ellipse")); + ((SPEllipse*)object)->cellipse->onSet(key, value); +} + +gchar* CEllipse::onDescription() { + return g_strdup(_("Ellipse")); +} + +// CPPIFY: remove +static gchar *sp_ellipse_description(SPItem *item) +{ + return ((SPEllipse*)item)->cellipse->onDescription(); } @@ -573,29 +643,43 @@ sp_circle_class_init(SPCircleClass *klass) item_class->description = sp_circle_description; } -static void -sp_circle_init(SPCircle */*circle*/) -{ - /* Nothing special */ +CCircle::CCircle(SPCircle* circle) : CGenericEllipse(circle) { + this->spcircle = circle; +} + +CCircle::~CCircle() { } static void -sp_circle_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) +sp_circle_init(SPCircle *circle) { - if (((SPObjectClass *) circle_parent_class)->build) - (* ((SPObjectClass *) circle_parent_class)->build)(object, document, repr); + circle->ccircle = new CCircle(circle); + circle->cgenericEllipse = circle->ccircle; + circle->cshape = circle->ccircle; + circle->clpeitem = circle->ccircle; + circle->citem = circle->ccircle; + circle->cobject = circle->ccircle; +} + +void CCircle::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPCircle* object = this->spcircle; + + CGenericEllipse::onBuild(document, repr); object->readAttr( "cx" ); object->readAttr( "cy" ); object->readAttr( "r" ); } -static Inkscape::XML::Node * -sp_circle_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +// CPPIFY: remove +static void +sp_circle_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - SPGenericEllipse *ellipse; + ((SPCircle*)object)->ccircle->onBuild(document, repr); +} - ellipse = SP_GENERICELLIPSE(object); +Inkscape::XML::Node* CCircle::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPGenericEllipse *ellipse = this->spcircle; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:circle"); @@ -605,18 +689,21 @@ sp_circle_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XM sp_repr_set_svg_double(repr, "cy", ellipse->cy.computed); sp_repr_set_svg_double(repr, "r", ellipse->rx.computed); - if (((SPObjectClass *) circle_parent_class)->write) - ((SPObjectClass *) circle_parent_class)->write(object, xml_doc, repr, flags); + CGenericEllipse::onWrite(xml_doc, repr, flags); return repr; } -static void -sp_circle_set(SPObject *object, unsigned int key, gchar const *value) +// CPPIFY: remove +static Inkscape::XML::Node * +sp_circle_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPGenericEllipse *ge; + return ((SPCircle*)object)->ccircle->onWrite(xml_doc, repr, flags); +} - ge = SP_GENERICELLIPSE(object); +void CCircle::onSet(unsigned int key, gchar const* value) { + SPGenericEllipse *ge = this->spcircle; + SPCircle* object = (SPCircle*)ge; switch (key) { case SP_ATTR_CX: @@ -635,15 +722,26 @@ sp_circle_set(SPObject *object, unsigned int key, gchar const *value) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) circle_parent_class)->set) - ((SPObjectClass *) circle_parent_class)->set(object, key, value); + CGenericEllipse::onSet(key, value); break; } } -static gchar *sp_circle_description(SPItem */*item*/) +// CPPIFY: remove +static void +sp_circle_set(SPObject *object, unsigned int key, gchar const *value) { - return g_strdup(_("Circle")); + ((SPCircle*)object)->ccircle->onSet(key, value); +} + +gchar* CCircle::onDescription() { + return g_strdup(_("Circle")); +} + +// CPPIFY: remove +gchar *sp_circle_description(SPItem *item) +{ + return ((SPCircle*)item)->ccircle->onDescription(); } /* element */ @@ -698,17 +796,29 @@ sp_arc_class_init(SPArcClass *klass) item_class->description = sp_arc_description; } -static void -sp_arc_init(SPArc */*arc*/) -{ - /* Nothing special */ +CArc::CArc(SPArc* arc) : CGenericEllipse(arc) { + this->sparc = arc; +} + +CArc::~CArc() { + } static void -sp_arc_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) +sp_arc_init(SPArc *arc) { - if (((SPObjectClass *) arc_parent_class)->build) - (* ((SPObjectClass *) arc_parent_class)->build) (object, document, repr); + arc->carc = new CArc(arc); + arc->cgenericEllipse = arc->carc; + arc->cshape = arc->carc; + arc->clpeitem = arc->carc; + arc->citem = arc->carc; + arc->cobject = arc->carc; +} + +void CArc::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPArc* object = this->sparc; + + CGenericEllipse::onBuild(document, repr); object->readAttr( "sodipodi:cx" ); object->readAttr( "sodipodi:cy" ); @@ -720,6 +830,13 @@ sp_arc_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) object->readAttr( "sodipodi:open" ); } +// CPPIFY: remove +static void +sp_arc_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) +{ + ((SPArc*)object)->carc->onBuild(document, repr); +} + /* * sp_arc_set_elliptical_path_attribute: * @@ -762,11 +879,10 @@ sp_arc_set_elliptical_path_attribute(SPArc *arc, Inkscape::XML::Node *repr) return true; } -static Inkscape::XML::Node * -sp_arc_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) -{ - SPGenericEllipse *ge = SP_GENERICELLIPSE(object); - SPArc *arc = SP_ARC(object); +Inkscape::XML::Node* CArc::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPArc* object = this->sparc; + SPGenericEllipse *ge = object; + SPArc *arc = object; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:path"); @@ -796,16 +912,21 @@ sp_arc_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML:: // write d= sp_arc_set_elliptical_path_attribute(arc, repr); - if (((SPObjectClass *) arc_parent_class)->write) - ((SPObjectClass *) arc_parent_class)->write(object, xml_doc, repr, flags); + CGenericEllipse::onWrite(xml_doc, repr, flags); return repr; } -static void -sp_arc_set(SPObject *object, unsigned int key, gchar const *value) +// CPPIFY: remove +static Inkscape::XML::Node * +sp_arc_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPGenericEllipse *ge = SP_GENERICELLIPSE(object); + return ((SPArc*)object)->carc->onWrite(xml_doc, repr, flags); +} + +void CArc::onSet(unsigned int key, gchar const* value) { + SPArc* object = this->sparc; + SPGenericEllipse *ge = object; switch (key) { case SP_ATTR_SODIPODI_CX: @@ -849,26 +970,38 @@ sp_arc_set(SPObject *object, unsigned int key, gchar const *value) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) arc_parent_class)->set) - ((SPObjectClass *) arc_parent_class)->set(object, key, value); + CGenericEllipse::onSet(key, value); break; } } +// CPPIFY: remove static void -sp_arc_modified(SPObject *object, guint flags) +sp_arc_set(SPObject *object, unsigned int key, gchar const *value) { + ((SPArc*)object)->carc->onSet(key, value); +} + +void CArc::onModified(guint flags) { + SPArc* object = this->sparc; + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { ((SPShape *) object)->setShape(); } - if (((SPObjectClass *) arc_parent_class)->modified) - ((SPObjectClass *) arc_parent_class)->modified(object, flags); + CGenericEllipse::onModified(flags); } -static gchar *sp_arc_description(SPItem *item) +// CPPIFY: remove +static void +sp_arc_modified(SPObject *object, guint flags) { - SPGenericEllipse *ge = SP_GENERICELLIPSE(item); + ((SPArc*)object)->carc->onModified(flags); +} + +gchar* CArc::onDescription() { + SPArc* item = this->sparc; + SPGenericEllipse *ge = item; gdouble len = fmod(ge->end - ge->start, SP_2PI); if (len < 0.0) len += SP_2PI; @@ -883,6 +1016,12 @@ static gchar *sp_arc_description(SPItem *item) } } +// CPPIFY: remove +static gchar *sp_arc_description(SPItem *item) +{ + return ((SPArc*)item)->carc->onDescription(); +} + void sp_arc_position_set(SPArc *arc, gdouble x, gdouble y, gdouble rx, gdouble ry) { diff --git a/src/sp-ellipse.h b/src/sp-ellipse.h index 91354ab60..4e7893c9e 100644 --- a/src/sp-ellipse.h +++ b/src/sp-ellipse.h @@ -27,8 +27,12 @@ class SPGenericEllipse; class SPGenericEllipseClass; +class CGenericEllipse; + +class SPGenericEllipse : public SPShape { +public: + CGenericEllipse* cgenericEllipse; -struct SPGenericEllipse : public SPShape { SVGLength cx; SVGLength cy; SVGLength rx; @@ -42,6 +46,25 @@ struct SPGenericEllipseClass { SPShapeClass parent_class; }; + +class CGenericEllipse : public CShape { +public: + CGenericEllipse(SPGenericEllipse* genericEllipse); + virtual ~CGenericEllipse(); + + virtual void onUpdate(SPCtx* ctx, unsigned int flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + + virtual void onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs); + virtual void onSetShape(); + + virtual void onUpdatePatheffect(bool write); + +protected: + SPGenericEllipse* spgenericEllipse; +}; + + GType sp_genericellipse_get_type (void); /* This is technically priate by we need this in object edit (Lauris) */ @@ -55,13 +78,33 @@ void sp_genericellipse_normalize (SPGenericEllipse *ellipse); #define SP_IS_ELLIPSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_ELLIPSE)) #define SP_IS_ELLIPSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_ELLIPSE)) -struct SPEllipse : public SPGenericEllipse { +class CEllipse; + +class SPEllipse : public SPGenericEllipse { +public: + CEllipse* cellipse; }; struct SPEllipseClass { SPGenericEllipseClass parent_class; }; + +class CEllipse : public CGenericEllipse { +public: + CEllipse(SPEllipse* ellipse); + virtual ~CEllipse(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual void onSet(unsigned int key, gchar const* value); + virtual gchar* onDescription(); + +protected: + SPEllipse* spellipse; +}; + + GType sp_ellipse_get_type (void); void sp_ellipse_position_set (SPEllipse * ellipse, gdouble x, gdouble y, gdouble rx, gdouble ry); @@ -74,13 +117,33 @@ void sp_ellipse_position_set (SPEllipse * ellipse, gdouble x, gdouble y, gdouble #define SP_IS_CIRCLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_CIRCLE)) #define SP_IS_CIRCLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_CIRCLE)) -struct SPCircle : public SPGenericEllipse { +class CCircle; + +class SPCircle : public SPGenericEllipse { +public: + CCircle* ccircle; }; struct SPCircleClass { SPGenericEllipseClass parent_class; }; + +class CCircle : public CGenericEllipse { +public: + CCircle(SPCircle* circle); + virtual ~CCircle(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual void onSet(unsigned int key, gchar const* value); + virtual gchar* onDescription(); + +protected: + SPCircle* spcircle; +}; + + GType sp_circle_get_type (void); /* element */ @@ -91,13 +154,34 @@ GType sp_circle_get_type (void); #define SP_IS_ARC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_ARC)) #define SP_IS_ARC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_ARC)) -struct SPArc : public SPGenericEllipse { +class CArc; + +class SPArc : public SPGenericEllipse { +public: + CArc* carc; }; struct SPArcClass { SPGenericEllipseClass parent_class; }; + +class CArc : public CGenericEllipse { +public: + CArc(SPArc* arc); + virtual ~CArc(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual void onSet(unsigned int key, gchar const* value); + virtual gchar* onDescription(); + virtual void onModified(unsigned int flags); + +protected: + SPArc* sparc; +}; + + GType sp_arc_get_type (void); void sp_arc_position_set (SPArc * arc, gdouble x, gdouble y, gdouble rx, gdouble ry); Geom::Point sp_arc_get_xy (SPArc *ge, gdouble arg); -- cgit v1.2.3 From 9dff787f0c9ff71746207bb2145c1c3a4d902a72 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 18:14:21 +0200 Subject: Added "virtual pad" to SPLine. (bzr r11608.1.6) --- src/sp-line.cpp | 116 +++++++++++++++++++++++++++++++++++++++++--------------- src/sp-line.h | 24 ++++++++++++ 2 files changed, 109 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/sp-line.cpp b/src/sp-line.cpp index 06604a1d6..a431a0948 100644 --- a/src/sp-line.cpp +++ b/src/sp-line.cpp @@ -68,20 +68,31 @@ void SPLineClass::sp_line_class_init(SPLineClass *klass) shape_class->set_shape = SPLine::setShape; } +CLine::CLine(SPLine* line) : CShape(line) { + this->spline = line; +} + +CLine::~CLine() { +} + void SPLine::init(SPLine * line) { + line->cline = new CLine(line); + line->cshape = line->cline; + line->clpeitem = line->cline; + line->citem = line->cline; + line->cobject = line->cline; + line->x1.unset(); line->y1.unset(); line->x2.unset(); line->y2.unset(); } +void CLine::onBuild(SPDocument * document, Inkscape::XML::Node * repr) { + SPLine* object = this->spline; -void SPLine::build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) -{ - if (((SPObjectClass *) SPLineClass::static_parent_class)->build) { - ((SPObjectClass *) SPLineClass::static_parent_class)->build(object, document, repr); - } + CShape::onBuild(document, repr); object->readAttr( "x1" ); object->readAttr( "y1" ); @@ -89,9 +100,15 @@ void SPLine::build(SPObject * object, SPDocument * document, Inkscape::XML::Node object->readAttr( "y2" ); } -void SPLine::set(SPObject *object, unsigned int key, const gchar *value) +// CPPIFY: remove +void SPLine::build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) { - SPLine * line = SP_LINE(object); + ((SPLine*)object)->cline->onBuild(document, repr); +} + +void CLine::onSet(unsigned int key, const gchar* value) { + SPLine* object = this->spline; + SPLine * line = object; /* fixme: we should really collect updates */ @@ -113,15 +130,20 @@ void SPLine::set(SPObject *object, unsigned int key, const gchar *value) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) SPLineClass::static_parent_class)->set) { - ((SPObjectClass *) SPLineClass::static_parent_class)->set(object, key, value); - } + CShape::onSet(key, value); break; } } -void SPLine::update(SPObject *object, SPCtx *ctx, guint flags) +// CPPIFY: remove +void SPLine::set(SPObject *object, unsigned int key, const gchar *value) { + ((SPLine*)object)->cline->onSet(key, value); +} + +void CLine::onUpdate(SPCtx *ctx, guint flags) { + SPLine* object = this->spline; + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { SPLine *line = SP_LINE(object); @@ -139,15 +161,18 @@ void SPLine::update(SPObject *object, SPCtx *ctx, guint flags) ((SPShape *) object)->setShape(); } - if (((SPObjectClass *) SPLineClass::static_parent_class)->update) { - ((SPObjectClass *) SPLineClass::static_parent_class)->update(object, ctx, flags); - } + CShape::onUpdate(ctx, flags); } - -Inkscape::XML::Node * SPLine::write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +// CPPIFY: remove +void SPLine::update(SPObject *object, SPCtx *ctx, guint flags) { - SPLine *line = SP_LINE(object); + ((SPLine*)object)->cline->onUpdate(ctx, flags); +} + +Inkscape::XML::Node* CLine::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPLine* object = this->spline; + SPLine *line = object; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:line"); @@ -162,21 +187,31 @@ Inkscape::XML::Node * SPLine::write(SPObject *object, Inkscape::XML::Document *x sp_repr_set_svg_double(repr, "x2", line->x2.computed); sp_repr_set_svg_double(repr, "y2", line->y2.computed); - if (((SPObjectClass *) (SPLineClass::static_parent_class))->write) { - ((SPObjectClass *) (SPLineClass::static_parent_class))->write(object, xml_doc, repr, flags); - } + CShape::onWrite(xml_doc, repr, flags); return repr; } -gchar * SPLine::getDescription(SPItem */*item*/) +// CPPIFY: remove +Inkscape::XML::Node * SPLine::write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - return g_strdup(_("Line")); + return ((SPLine*)object)->cline->onWrite(xml_doc, repr, flags); } -void SPLine::convertToGuides(SPItem *item) +gchar* CLine::onDescription() { + return g_strdup(_("Line")); +} + +// CPPIFY: remove +gchar * SPLine::getDescription(SPItem *item) { - SPLine *line = SP_LINE(item); + return ((SPLine*)item)->cline->onDescription(); +} + +void CLine::onConvertToGuides() { + SPLine* item = this->spline; + SPLine *line = item; + Geom::Point points[2]; Geom::Affine const i2dt(item->i2dt_affine()); @@ -187,32 +222,45 @@ void SPLine::convertToGuides(SPItem *item) SPGuide::createSPGuide(item->document, points[0], points[1]); } -Geom::Affine SPLine::setTransform(SPItem *item, Geom::Affine const &xform) +// CPPIFY: remove +void SPLine::convertToGuides(SPItem *item) { - SPLine *line = SP_LINE(item); + ((SPLine*)item)->cline->onConvertToGuides(); +} + +Geom::Affine CLine::onSetTransform(Geom::Affine const &transform) { + SPLine* item = this->spline; + SPLine *line = item; + Geom::Point points[2]; points[0] = Geom::Point(line->x1.computed, line->y1.computed); points[1] = Geom::Point(line->x2.computed, line->y2.computed); - points[0] *= xform; - points[1] *= xform; + points[0] *= transform; + points[1] *= transform; line->x1.computed = points[0][Geom::X]; line->y1.computed = points[0][Geom::Y]; line->x2.computed = points[1][Geom::X]; line->y2.computed = points[1][Geom::Y]; - item->adjust_stroke(xform.descrim()); + item->adjust_stroke(transform.descrim()); SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); return Geom::identity(); } -void SPLine::setShape(SPShape *shape) +// CPPIFY: remove +Geom::Affine SPLine::setTransform(SPItem *item, Geom::Affine const &xform) { - SPLine *line = SP_LINE(shape); + return ((SPLine*)item)->cline->onSetTransform(xform); +} + +void CLine::onSetShape() { + SPLine* shape = this->spline; + SPLine *line = shape; SPCurve *c = new SPCurve(); @@ -227,6 +275,12 @@ void SPLine::setShape(SPShape *shape) c->unref(); } +// CPPIFY: remove +void SPLine::setShape(SPShape *shape) +{ + ((SPLine*)shape)->cline->onSetShape(); +} + /* Local Variables: mode:c++ diff --git a/src/sp-line.h b/src/sp-line.h index 182f85a5c..2cfdaf82f 100644 --- a/src/sp-line.h +++ b/src/sp-line.h @@ -27,9 +27,12 @@ class SPLine; class SPLineClass; +class CLine; class SPLine : public SPShape { public: + CLine* cline; + SVGLength x1; SVGLength y1; SVGLength x2; @@ -65,6 +68,27 @@ private: }; +class CLine : public CShape { +public: + CLine(SPLine* line); + virtual ~CLine(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual void onSet(unsigned int key, gchar const* value); + + virtual gchar* onDescription(); + virtual Geom::Affine onSetTransform(Geom::Affine const &transform); + virtual void onConvertToGuides(); + virtual void onUpdate(SPCtx* ctx, guint flags); + + virtual void onSetShape(); + +protected: + SPLine* spline; +}; + + #endif // SEEN_SP_LINE_H /* Local Variables: -- cgit v1.2.3 From 1cca85d01800742484b2901ea0f2d6bcf6cae1a5 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 18:36:31 +0200 Subject: Added "virtual pad" to SPOffset. (bzr r11608.1.7) --- src/sp-offset.cpp | 140 +++++++++++++++++++++++++++++++++++++----------------- src/sp-offset.h | 27 ++++++++++- 2 files changed, 122 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/sp-offset.cpp b/src/sp-offset.cpp index 817db92e8..f2f707882 100644 --- a/src/sp-offset.cpp +++ b/src/sp-offset.cpp @@ -162,12 +162,25 @@ sp_offset_class_init(SPOffsetClass *klass) shape_class->set_shape = sp_offset_set_shape; } +COffset::COffset(SPOffset* offset) : CShape(offset) { + this->spoffset = offset; +} + +COffset::~COffset() { +} + /** * Callback for SPOffset object initialization. */ static void sp_offset_init(SPOffset *offset) { + offset->coffset = new COffset(offset); + offset->cshape = offset->coffset; + offset->clpeitem = offset->coffset; + offset->citem = offset->coffset; + offset->cobject = offset->coffset; + offset->rad = 1.0; offset->original = NULL; offset->originalPath = NULL; @@ -207,14 +220,10 @@ sp_offset_finalize(GObject *obj) offset->_transformed_connection.~connection(); } -/** - * Virtual build: set offset attributes from corresponding repr. - */ -static void -sp_offset_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ - if (((SPObjectClass *) parent_class)->build) - ((SPObjectClass *) parent_class)->build (object, document, repr); +void COffset::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPOffset* object = this->spoffset; + + CShape::onBuild(document, repr); //XML Tree being used directly here while it shouldn't be. if (object->getRepr()->attribute("inkscape:radius")) { @@ -255,13 +264,19 @@ sp_offset_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *rep } } +// CPPIFY: remove /** - * Virtual write: write offset attributes to corresponding repr. + * Virtual build: set offset attributes from corresponding repr. */ -static Inkscape::XML::Node * -sp_offset_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void +sp_offset_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - SPOffset *offset = SP_OFFSET (object); + ((SPOffset*)object)->coffset->onBuild(document, repr); +} + +Inkscape::XML::Node* COffset::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPOffset* object = this->spoffset; + SPOffset *offset = object; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:path"); @@ -290,19 +305,23 @@ sp_offset_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XM repr->setAttribute("d", d); g_free (d); - if (((SPObjectClass *) (parent_class))->write) - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, - flags | SP_SHAPE_WRITE_PATH); + CShape::onWrite(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); return repr; } +// CPPIFY: remove /** - * Virtual release callback. + * Virtual write: write offset attributes to corresponding repr. */ -static void -sp_offset_release(SPObject *object) +static Inkscape::XML::Node * +sp_offset_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + return ((SPOffset*)object)->coffset->onWrite(xml_doc, repr, flags); +} + +void COffset::onRelease() { + SPOffset* object = this->spoffset; SPOffset *offset = (SPOffset *) object; if (offset->original) free (offset->original); @@ -317,20 +336,22 @@ sp_offset_release(SPObject *object) offset->sourceHref = NULL; offset->sourceRef->detach(); - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release (object); - } - + CShape::onRelease(); } +// CPPIFY: remove /** - * Set callback: the function that is called whenever a change is made to - * the description of the object. + * Virtual release callback. */ static void -sp_offset_set(SPObject *object, unsigned key, gchar const *value) +sp_offset_release(SPObject *object) { - SPOffset *offset = SP_OFFSET (object); + ((SPOffset*)object)->coffset->onRelease(); +} + +void COffset::onSet(unsigned int key, const gchar* value) { + SPOffset* object = this->spoffset; + SPOffset *offset = object; if ( offset->sourceDirty ) refresh_offset_source(offset); @@ -389,19 +410,26 @@ sp_offset_set(SPObject *object, unsigned key, gchar const *value) } break; default: - if (((SPObjectClass *) parent_class)->set) - ((SPObjectClass *) parent_class)->set (object, key, value); + CShape::onSet(key, value); break; } } +// CPPIFY: remove /** - * Update callback: the object has changed, recompute its shape. + * Set callback: the function that is called whenever a change is made to + * the description of the object. */ static void -sp_offset_update(SPObject *object, SPCtx *ctx, guint flags) +sp_offset_set(SPObject *object, unsigned key, gchar const *value) { - SPOffset* offset = SP_OFFSET(object); + ((SPOffset*)object)->coffset->onSet(key, value); +} + +void COffset::onUpdate(SPCtx *ctx, guint flags) { + SPOffset* object = this->spoffset; + SPOffset* offset = object; + offset->isUpdating=true; // prevent sp_offset_set from requesting updates if ( offset->sourceDirty ) refresh_offset_source(offset); if (flags & @@ -411,17 +439,22 @@ sp_offset_update(SPObject *object, SPCtx *ctx, guint flags) } offset->isUpdating=false; - if (((SPObjectClass *) parent_class)->update) - ((SPObjectClass *) parent_class)->update (object, ctx, flags); + CShape::onUpdate(ctx, flags); } +// CPPIFY: remove /** - * Returns a textual description of object. + * Update callback: the object has changed, recompute its shape. */ -static gchar * -sp_offset_description(SPItem *item) +static void +sp_offset_update(SPObject *object, SPCtx *ctx, guint flags) { - SPOffset *offset = SP_OFFSET (item); + ((SPOffset*)object)->coffset->onUpdate(ctx, flags); +} + +gchar* COffset::onDescription() { + SPOffset* item = this->spoffset; + SPOffset *offset = item; if ( offset->sourceHref ) { // TRANSLATORS COMMENT: %s is either "outset" or "inset" depending on sign @@ -434,13 +467,19 @@ sp_offset_description(SPItem *item) } } +// CPPIFY: remove /** - * Compute and set shape's offset. + * Returns a textual description of object. */ -static void -sp_offset_set_shape(SPShape *shape) +static gchar * +sp_offset_description(SPItem *item) { - SPOffset *offset = SP_OFFSET (shape); + return ((SPOffset*)item)->coffset->onDescription(); +} + +void COffset::onSetShape() { + SPOffset* shape = this->spoffset; + SPOffset *offset = shape; if ( offset->originalPath == NULL ) { // oops : no path?! (the offset object should do harakiri) @@ -720,14 +759,27 @@ sp_offset_set_shape(SPShape *shape) } } +// CPPIFY: remove +/** + * Compute and set shape's offset. + */ +static void +sp_offset_set_shape(SPShape *shape) +{ + ((SPOffset*)shape)->coffset->onSetShape(); +} + +void COffset::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + CShape::onSnappoints(p, snapprefs); +} + +// CPPIFY: remove /** * Virtual snappoints function. */ static void sp_offset_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) { - if (((SPItemClass *) parent_class)->snappoints) { - ((SPItemClass *) parent_class)->snappoints (item, p, snapprefs); - } + ((SPOffset*)item)->coffset->onSnappoints(p, snapprefs); } diff --git a/src/sp-offset.h b/src/sp-offset.h index ec8c2cf29..0dc42bd00 100644 --- a/src/sp-offset.h +++ b/src/sp-offset.h @@ -24,6 +24,7 @@ class SPOffset; class SPOffsetClass; +class COffset; class SPUseReference; /** @@ -54,7 +55,10 @@ class SPUseReference; * points, or more precisely one control point, that's enough to define the * radius (look in object-edit). */ -struct SPOffset : public SPShape { +class SPOffset : public SPShape { +public: + COffset* coffset; + void *originalPath; ///< will be a livarot Path, just don't declare it here to please the gcc linker char *original; ///< SVG description of the source path float rad; ///< offset radius @@ -84,6 +88,27 @@ struct SPOffsetClass }; +class COffset : public CShape { +public: + COffset(SPOffset* offset); + ~COffset(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onSet(unsigned int key, gchar const* value); + virtual void onUpdate(SPCtx *ctx, guint flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual void onRelease(); + + virtual void onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs); + virtual gchar* onDescription(); + + virtual void onSetShape(); + +protected: + SPOffset* spoffset; +}; + + /* Standard Gtk function */ GType sp_offset_get_type (void); -- cgit v1.2.3 From c81b4a521a9b470412f06bb6db168847f2ecc507 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 19:02:28 +0200 Subject: Added "virtual pad" to SPPath. (bzr r11608.1.8) --- src/sp-path.cpp | 186 +++++++++++++++++++++++++++++++++++++------------------- src/sp-path.h | 27 ++++++++ 2 files changed, 150 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 107ceac16..d58242a38 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -129,9 +129,9 @@ gint SPPath::nodesInPath() const return _curve ? _curve->nodes_in_path() : 0; } -static gchar * -sp_path_description(SPItem * item) -{ +gchar* CPath::onDescription() { + SPPath* item = this->sppath; + int count = SP_PATH(item)->nodesInPath(); if (SP_IS_LPE_ITEM(item) && sp_lpe_item_has_path_effect(SP_LPE_ITEM(item))) { @@ -157,10 +157,16 @@ sp_path_description(SPItem * item) } } -static void -sp_path_convert_to_guides(SPItem *item) +// CPPIFY: remove +static gchar * +sp_path_description(SPItem * item) { - SPPath *path = SP_PATH(item); + return ((SPPath*)item)->cpath->onDescription(); +} + +void CPath::onConvertToGuides() { + SPPath* item = this->sppath; + SPPath *path = item; if (!path->_curve) { return; @@ -184,12 +190,32 @@ sp_path_convert_to_guides(SPItem *item) sp_guide_pt_pairs_to_guides(item->document, pts); } +// CPPIFY: remove +static void +sp_path_convert_to_guides(SPItem *item) +{ + ((SPPath*)item)->cpath->onConvertToGuides(); +} + +CPath::CPath(SPPath* path) : CShape(path) { + this->sppath = path; +} + +CPath::~CPath() { +} + /** * Initializes an SPPath. */ static void sp_path_init(SPPath *path) { + path->cpath = new CPath(path); + path->cshape = path->cpath; + path->clpeitem = path->cpath; + path->citem = path->cpath; + path->cobject = path->cpath; + new (&path->connEndPair) SPConnEndPair(path); } @@ -201,13 +227,9 @@ sp_path_finalize(GObject *obj) path->connEndPair.~SPConnEndPair(); } -/** - * Given a repr, this sets the data items in the path object such as - * fill & style attributes, markers, and CSS properties. - */ -static void -sp_path_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ +void CPath::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPPath* object = this->sppath; + /* Are these calls actually necessary? */ object->readAttr( "marker" ); object->readAttr( "marker-start" ); @@ -216,9 +238,7 @@ sp_path_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) sp_conn_end_pair_build(object); - if (((SPObjectClass *) parent_class)->build) { - ((SPObjectClass *) parent_class)->build(object, document, repr); - } + CShape::onBuild(document, repr); object->readAttr( "inkscape:original-d" ); object->readAttr( "d" ); @@ -230,25 +250,35 @@ sp_path_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) } } +// CPPIFY: remove +/** + * Given a repr, this sets the data items in the path object such as + * fill & style attributes, markers, and CSS properties. + */ static void -sp_path_release(SPObject *object) +sp_path_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - SPPath *path = SP_PATH(object); + ((SPPath*)object)->cpath->onBuild(document, repr); +} + +void CPath::onRelease() { + SPPath* object = this->sppath; + SPPath *path = object; path->connEndPair.release(); - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release(object); - } + CShape::onRelease(); } -/** - * Sets a value in the path object given by 'key', to 'value'. This is used - * for setting attributes and markers on a path object. - */ +// CPPIFY: remove static void -sp_path_set(SPObject *object, unsigned int key, gchar const *value) +sp_path_release(SPObject *object) { + ((SPPath*)object)->cpath->onRelease(); +} + +void CPath::onSet(unsigned int key, const gchar* value) { + SPPath* object = this->sppath; SPPath *path = (SPPath *) object; switch (key) { @@ -294,21 +324,25 @@ sp_path_set(SPObject *object, unsigned int key, gchar const *value) path->connEndPair.setAttr(key, value); break; default: - if (((SPObjectClass *) parent_class)->set) { - ((SPObjectClass *) parent_class)->set(object, key, value); - } + CShape::onSet(key, value); break; } } +// CPPIFY: remove /** - * - * Writes the path object into a Inkscape::XML::Node + * Sets a value in the path object given by 'key', to 'value'. This is used + * for setting attributes and markers on a path object. */ -static Inkscape::XML::Node * -sp_path_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void +sp_path_set(SPObject *object, unsigned int key, gchar const *value) { - SPShape *shape = (SPShape *) object; + ((SPPath*)object)->cpath->onSet(key, value); +} + +Inkscape::XML::Node* CPath::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPPath* object = this->sppath; + SPShape *shape = (SPShape *) object; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:path"); @@ -337,35 +371,45 @@ g_message("sp_path_write writes 'd' attribute"); SP_PATH(shape)->connEndPair.writeRepr(repr); - if (((SPObjectClass *)(parent_class))->write) { - ((SPObjectClass *)(parent_class))->write(object, xml_doc, repr, flags); - } + CShape::onWrite(xml_doc, repr, flags); return repr; } -static void -sp_path_update(SPObject *object, SPCtx *ctx, guint flags) +// CPPIFY: remove +/** + * + * Writes the path object into a Inkscape::XML::Node + */ +static Inkscape::XML::Node * +sp_path_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore - } + return ((SPPath*)object)->cpath->onWrite(xml_doc, repr, flags); +} - if (((SPObjectClass *) parent_class)->update) { - ((SPObjectClass *) parent_class)->update(object, ctx, flags); - } +void CPath::onUpdate(SPCtx *ctx, guint flags) { + SPPath* object = this->sppath; - SPPath *path = SP_PATH(object); - path->connEndPair.update(); -} + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore + } + CShape::onUpdate(ctx, flags); -/** - * Writes the given transform into the repr for the given item. - */ -static Geom::Affine -sp_path_set_transform(SPItem *item, Geom::Affine const &xform) + SPPath *path = SP_PATH(object); + path->connEndPair.update(); +} + +// CPPIFY: remove +static void +sp_path_update(SPObject *object, SPCtx *ctx, guint flags) { + ((SPPath*)object)->cpath->onUpdate(ctx, flags); +} + +Geom::Affine CPath::onSetTransform(Geom::Affine const &transform) { + SPPath* item = this->sppath; + if (!SP_IS_PATH(item)) { return Geom::identity(); } @@ -379,25 +423,25 @@ sp_path_set_transform(SPItem *item, Geom::Affine const &xform) if (path->_curve_before_lpe && sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(item))) { if (sp_lpe_item_has_path_effect_of_type(SP_LPE_ITEM(item), Inkscape::LivePathEffect::CLONE_ORIGINAL)) { // if path has the CLONE_ORIGINAL LPE applied, don't write the transform to the pathdata, but write it 'unoptimized' - return xform; + return transform; } else { - path->_curve_before_lpe->transform(xform); + path->_curve_before_lpe->transform(transform); } } else { - path->_curve->transform(xform); + path->_curve->transform(transform); } // Adjust stroke - item->adjust_stroke(xform.descrim()); + item->adjust_stroke(transform.descrim()); // Adjust pattern fill - item->adjust_pattern(xform); + item->adjust_pattern(transform); // Adjust gradient fill - item->adjust_gradient(xform); + item->adjust_gradient(transform); // Adjust LPE - item->adjust_livepatheffect(xform); + item->adjust_livepatheffect(transform); item->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); @@ -405,11 +449,20 @@ sp_path_set_transform(SPItem *item, Geom::Affine const &xform) return Geom::identity(); } - -static void -sp_path_update_patheffect(SPLPEItem *lpeitem, bool write) +// CPPIFY: remove +/** + * Writes the given transform into the repr for the given item. + */ +static Geom::Affine +sp_path_set_transform(SPItem *item, Geom::Affine const &xform) { + return ((SPPath*)item)->cpath->onSetTransform(xform); +} + +void CPath::onUpdatePatheffect(bool write) { + SPPath* lpeitem = this->sppath; SPShape * const shape = (SPShape *) lpeitem; + Inkscape::XML::Node *repr = shape->getRepr(); #ifdef PATH_VERBOSE @@ -451,6 +504,13 @@ g_message("sp_path_update_patheffect writes 'd' attribute"); } } +// CPPIFY: remove +static void +sp_path_update_patheffect(SPLPEItem *lpeitem, bool write) +{ + ((SPPath*)lpeitem)->cpath->onUpdatePatheffect(write); +} + /** * Adds a original_curve to the path. If owner is specified, a reference diff --git a/src/sp-path.h b/src/sp-path.h index 5dd79212c..92757d39d 100644 --- a/src/sp-path.h +++ b/src/sp-path.h @@ -20,6 +20,7 @@ #include "sp-conn-end-pair.h" class SPCurve; +class CPath; #define SP_TYPE_PATH (sp_path_get_type ()) #define SP_PATH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_PATH, SPPath)) @@ -30,6 +31,8 @@ class SPCurve; */ class SPPath : public SPShape { public: + CPath* cpath; + gint nodesInPath() const; // still in lowercase because the names should be clearer on whether curve, curve->copy or curve-ref is returned. @@ -50,6 +53,30 @@ struct SPPathClass { SPShapeClass shape_class; }; + +class CPath : public CShape { +public: + CPath(SPPath* path); + ~CPath(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onRelease(); + virtual void onUpdate(SPCtx* ctx, guint flags); + + virtual void onSet(unsigned int key, gchar const* value); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + + virtual gchar* onDescription(); + virtual Geom::Affine onSetTransform(Geom::Affine const &transform); + virtual void onConvertToGuides(); + + virtual void onUpdatePatheffect(bool write); + +protected: + SPPath* sppath; +}; + + GType sp_path_get_type (void); #endif // SEEN_SP_PATH_H -- cgit v1.2.3 From ce5e1752a9a1ce5e3caab79fcb2040a1ee401c33 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 21:17:33 +0200 Subject: Added "virtual pad" to SPPolygon. (bzr r11608.1.9) --- src/sp-polygon.cpp | 71 +++++++++++++++++++++++++++++++++++++----------------- src/sp-polygon.h | 22 ++++++++++++++++- 2 files changed, 70 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/sp-polygon.cpp b/src/sp-polygon.cpp index eee8d50bc..8aa66f15f 100644 --- a/src/sp-polygon.cpp +++ b/src/sp-polygon.cpp @@ -72,20 +72,36 @@ static void sp_polygon_class_init(SPPolygonClass *pc) item_class->description = sp_polygon_description; } -static void sp_polygon_init(SPPolygon */*polygon*/) -{ - /* Nothing here */ +CPolygon::CPolygon(SPPolygon* polygon) : CShape(polygon) { + this->sppolygon = polygon; } -static void sp_polygon_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) +CPolygon::~CPolygon() { +} + +static void sp_polygon_init(SPPolygon *polygon) { - if (((SPObjectClass *) parent_class)->build) { - ((SPObjectClass *) parent_class)->build(object, document, repr); - } + polygon->cpolygon = new CPolygon(polygon); + polygon->cshape = polygon->cpolygon; + polygon->clpeitem = polygon->cpolygon; + polygon->citem = polygon->cpolygon; + polygon->cobject = polygon->cpolygon; +} + +void CPolygon::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPPolygon* object = this->sppolygon; + + CShape::onBuild(document, repr); object->readAttr( "points" ); } +// CPPIFY: remove +static void sp_polygon_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) +{ + ((SPPolygon*)object)->cpolygon->onBuild(document, repr); +} + /* * sp_svg_write_polygon: Write points attribute for polygon tag. @@ -110,9 +126,9 @@ static gchar *sp_svg_write_polygon(Geom::PathVector const & pathv) return g_strdup(os.str().c_str()); } -static Inkscape::XML::Node *sp_polygon_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) -{ - SPShape *shape = SP_SHAPE(object); +Inkscape::XML::Node* CPolygon::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPShape *shape = this->sppolygon; + // Tolerable workaround: we need to update the object's curve before we set points= // because it's out of sync when e.g. some extension attrs of the polygon or star are changed in XML editor shape->setShape(); @@ -126,13 +142,17 @@ static Inkscape::XML::Node *sp_polygon_write(SPObject *object, Inkscape::XML::Do repr->setAttribute("points", str); g_free(str); - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); - } + CShape::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +static Inkscape::XML::Node *sp_polygon_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPPolygon*)object)->cpolygon->onWrite(xml_doc, repr, flags); +} + static gboolean polygon_get_value(gchar const **p, gdouble *v) { @@ -154,10 +174,8 @@ static gboolean polygon_get_value(gchar const **p, gdouble *v) return true; } - -void sp_polygon_set(SPObject *object, unsigned int key, const gchar *value) -{ - SPPolygon *polygon = SP_POLYGON(object); +void CPolygon::onSet(unsigned int key, const gchar* value) { + SPPolygon *polygon = this->sppolygon; switch (key) { case SP_ATTR_POINTS: { @@ -213,16 +231,25 @@ void sp_polygon_set(SPObject *object, unsigned int key, const gchar *value) break; } default: - if (((SPObjectClass *) parent_class)->set) { - ((SPObjectClass *) parent_class)->set(object, key, value); - } + CShape::onSet(key, value); break; } } -static gchar *sp_polygon_description(SPItem */*item*/) +// CPPIFY: remove +void sp_polygon_set(SPObject *object, unsigned int key, const gchar *value) +{ + ((SPPolygon*)object)->cpolygon->onSet(key, value); +} + +gchar* CPolygon::onDescription() { + return g_strdup(_("Polygon")); +} + +// CPPIFY: remove +static gchar *sp_polygon_description(SPItem *item) { - return g_strdup(_("Polygon")); + return ((SPPolygon*)item)->cpolygon->onDescription(); } /* diff --git a/src/sp-polygon.h b/src/sp-polygon.h index 3ea91be76..d11fd6da2 100644 --- a/src/sp-polygon.h +++ b/src/sp-polygon.h @@ -21,13 +21,33 @@ #define SP_IS_POLYGON(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_POLYGON)) #define SP_IS_POLYGON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_POLYGON)) -struct SPPolygon : public SPShape { +class CPolygon; + +class SPPolygon : public SPShape { +public: + CPolygon* cpolygon; }; struct SPPolygonClass { SPShapeClass parent_class; }; + +class CPolygon : public CShape { +public: + CPolygon(SPPolygon* polygon); + virtual ~CPolygon(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual void onSet(unsigned int key, gchar const* value); + virtual gchar* onDescription(); + +protected: + SPPolygon* sppolygon; +}; + + GType sp_polygon_get_type (void); // made 'public' so that SPCurve can set it as friend: -- cgit v1.2.3 From 49354077a17c09dcfb4ff3b9f77a4d74d0563399 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 21:30:20 +0200 Subject: Added "virtual pad" to Box3DSide. (bzr r11608.1.10) --- src/box3d-side.cpp | 86 ++++++++++++++++++++++++++++++++++++++++-------------- src/box3d-side.h | 24 ++++++++++++++- 2 files changed, 87 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/box3d-side.cpp b/src/box3d-side.cpp index 031b16a7c..3b30e31ab 100644 --- a/src/box3d-side.cpp +++ b/src/box3d-side.cpp @@ -76,27 +76,45 @@ static void box3d_side_class_init(Box3DSideClass *klass) shape_class->set_shape = box3d_side_set_shape; } +CBox3DSide::CBox3DSide(Box3DSide* box3dside) : CPolygon(box3dside) { + this->spbox3dside = box3dside; +} + +CBox3DSide::~CBox3DSide() { +} + static void box3d_side_init (Box3DSide * side) { + side->cbox3dside = new CBox3DSide(side); + side->cpolygon = side->cbox3dside; + side->cshape = side->cbox3dside; + side->clpeitem = side->cbox3dside; + side->citem = side->cbox3dside; + side->cobject = side->cbox3dside; + side->dir1 = Box3D::NONE; side->dir2 = Box3D::NONE; side->front_or_rear = Box3D::FRONT; } -static void box3d_side_build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) -{ - if (((SPObjectClass *) parent_class)->build) { - ((SPObjectClass *) parent_class)->build(object, document, repr); - } +void CBox3DSide::onBuild(SPDocument * document, Inkscape::XML::Node * repr) { + Box3DSide* object = this->spbox3dside; + + CPolygon::onBuild(document, repr); object->readAttr( "inkscape:box3dsidetype" ); } -static Inkscape::XML::Node * -box3d_side_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +// CPPIFY: remove +static void box3d_side_build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) { - Box3DSide *side = SP_BOX3D_SIDE (object); + ((Box3DSide*)object)->cbox3dside->onBuild(document, repr); +} + +Inkscape::XML::Node* CBox3DSide::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + Box3DSide* object = this->spbox3dside; + Box3DSide *side = object; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { // this is where we end up when saving as plain SVG (also in other circumstances?) @@ -120,16 +138,21 @@ box3d_side_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape:: repr->setAttribute("d", d); g_free (d); - if (((SPObjectClass *) (parent_class))->write) - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags); + CPolygon::onWrite(xml_doc, repr, flags); return repr; } -static void -box3d_side_set (SPObject *object, unsigned int key, const gchar *value) +// CPPIFY: remove +static Inkscape::XML::Node * +box3d_side_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - Box3DSide *side = SP_BOX3D_SIDE (object); + return ((Box3DSide*)object)->cbox3dside->onWrite(xml_doc, repr, flags); +} + +void CBox3DSide::onSet(unsigned int key, const gchar* value) { + Box3DSide* object = this->spbox3dside; + Box3DSide *side = object; // TODO: In case the box was recreated (by undo, e.g.) we need to recreate the path // (along with other info?) from the parent box. @@ -154,15 +177,21 @@ box3d_side_set (SPObject *object, unsigned int key, const gchar *value) } break; default: - if (((SPObjectClass *) parent_class)->set) - ((SPObjectClass *) parent_class)->set (object, key, value); + CPolygon::onSet(key, value); break; } } +// CPPIFY: remove static void -box3d_side_update (SPObject *object, SPCtx *ctx, guint flags) +box3d_side_set (SPObject *object, unsigned int key, const gchar *value) { + ((Box3DSide*)object)->cbox3dside->onSet(key, value); +} + +void CBox3DSide::onUpdate(SPCtx* ctx, guint flags) { + Box3DSide* object = this->spbox3dside; + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore } @@ -173,8 +202,14 @@ box3d_side_update (SPObject *object, SPCtx *ctx, guint flags) static_cast(object)->setShape (); } - if (((SPObjectClass *) parent_class)->update) - ((SPObjectClass *) parent_class)->update (object, ctx, flags); + CPolygon::onUpdate(ctx, flags); +} + +// CPPIFY: remove +static void +box3d_side_update (SPObject *object, SPCtx *ctx, guint flags) +{ + ((Box3DSide*)object)->cbox3dside->onUpdate(ctx, flags); } /* Create a new Box3DSide and append it to the parent box */ @@ -205,10 +240,10 @@ box3d_side_position_set (Box3DSide *side) { side->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -void -box3d_side_set_shape (SPShape *shape) -{ - Box3DSide *side = SP_BOX3D_SIDE (shape); +void CBox3DSide::onSetShape() { + Box3DSide* shape = this->spbox3dside; + Box3DSide *side = shape; + if (!side->document->getRoot()) { // avoid a warning caused by sp_document_height() (which is called from sp_item_i2d_affine() below) // when reading a file containing 3D boxes @@ -266,6 +301,13 @@ box3d_side_set_shape (SPShape *shape) c->unref(); } +// CPPIFY: remove +void +box3d_side_set_shape (SPShape *shape) +{ + ((Box3DSide*)shape)->cbox3dside->onSetShape(); +} + gchar *box3d_side_axes_string(Box3DSide *side) { GString *pstring = g_string_new(""); diff --git a/src/box3d-side.h b/src/box3d-side.h index ed4972e29..49273305b 100644 --- a/src/box3d-side.h +++ b/src/box3d-side.h @@ -25,10 +25,14 @@ class SPBox3D; class Box3DSide; class Box3DSideClass; +class CBox3DSide; class Persp3D; // FIXME: Would it be better to inherit from SPPath instead? -struct Box3DSide : public SPPolygon { +class Box3DSide : public SPPolygon { +public: + CBox3DSide* cbox3dside; + Box3D::Axis dir1; Box3D::Axis dir2; Box3D::FrontOrRear front_or_rear; @@ -40,6 +44,24 @@ struct Box3DSideClass { SPPolygonClass parent_class; }; + +class CBox3DSide : public CPolygon { +public: + CBox3DSide(Box3DSide* box3dside); + virtual ~CBox3DSide(); + + virtual void onBuild(SPDocument* doc, Inkscape::XML::Node* repr); + virtual void onSet(unsigned int key, gchar const* value); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual void onUpdate(SPCtx *ctx, guint flags); + + virtual void onSetShape(); + +protected: + Box3DSide* spbox3dside; +}; + + GType box3d_side_get_type (void); void box3d_side_position_set (Box3DSide *side); // FIXME: Replace this by box3d_side_set_shape?? -- cgit v1.2.3 From 2d3f862c97fdd6fdb17368933377370886375a2d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 23:51:06 +0200 Subject: Added "virtual pad" to SPStar. (bzr r11608.1.11) --- src/sp-star.cpp | 129 +++++++++++++++++++++++++++++++++++++++++--------------- src/sp-star.h | 31 +++++++++++++- 2 files changed, 126 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/sp-star.cpp b/src/sp-star.cpp index e0f05d0f4..aead51b8b 100644 --- a/src/sp-star.cpp +++ b/src/sp-star.cpp @@ -91,9 +91,23 @@ static void sp_star_class_init(SPStarClass *klass) shape_class->set_shape = sp_star_set_shape; } +CStar::CStar(SPStar* star) : CPolygon(star) { + this->spstar = star; +} + +CStar::~CStar() { +} + static void sp_star_init (SPStar * star) { + star->cstar = new CStar(star); + star->cpolygon = star->cstar; + star->cshape = star->cstar; + star->clpeitem = star->cstar; + star->citem = star->cstar; + star->cobject = star->cstar; + star->sides = 5; star->center = Geom::Point(0, 0); star->r[0] = 1.0; @@ -104,11 +118,11 @@ sp_star_init (SPStar * star) star->randomized = 0.0; } -static void -sp_star_build (SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) -{ - if (((SPObjectClass *) parent_class)->build) - ((SPObjectClass *) parent_class)->build (object, document, repr); +void CStar::onBuild(SPDocument * document, Inkscape::XML::Node * repr) { + SPStar* object = this->spstar; + + // CPPIFY: see header file + CShape::onBuild(document, repr); object->readAttr( "sodipodi:cx" ); object->readAttr( "sodipodi:cy" ); @@ -122,10 +136,16 @@ sp_star_build (SPObject * object, SPDocument * document, Inkscape::XML::Node * r object->readAttr( "inkscape:randomized" ); } -static Inkscape::XML::Node * -sp_star_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +// CPPIFY: remove +static void +sp_star_build (SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) { - SPStar *star = SP_STAR (object); + ((SPStar*)object)->cstar->onBuild(document, repr); +} + +Inkscape::XML::Node* CStar::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPStar* object = this->spstar; + SPStar *star = object; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:path"); @@ -150,18 +170,24 @@ sp_star_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML repr->setAttribute("d", d); g_free (d); - if (((SPObjectClass *) (parent_class))->write) - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags); + // CPPIFY: see header file + CShape::onWrite(xml_doc, repr, flags); return repr; } -static void -sp_star_set (SPObject *object, unsigned int key, const gchar *value) +// CPPIFY: remove +static Inkscape::XML::Node * +sp_star_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SVGLength::Unit unit; + return ((SPStar*)object)->cstar->onWrite(xml_doc, repr, flags); +} + +void CStar::onSet(unsigned int key, const gchar* value) { + SPStar* object = this->spstar; + SPStar *star = object; - SPStar *star = SP_STAR (object); + SVGLength::Unit unit; /* fixme: we should really collect updates */ switch (key) { @@ -250,29 +276,43 @@ sp_star_set (SPObject *object, unsigned int key, const gchar *value) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) parent_class)->set) - ((SPObjectClass *) parent_class)->set (object, key, value); + // CPPIFY: see header file + CShape::onSet(key, value); break; } } +// CPPIFY: remove static void -sp_star_update (SPObject *object, SPCtx *ctx, guint flags) +sp_star_set (SPObject *object, unsigned int key, const gchar *value) { + ((SPStar*)object)->cstar->onSet(key, value); +} + +void CStar::onUpdate(SPCtx *ctx, guint flags) { + SPStar* object = this->spstar; + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { ((SPShape *) object)->setShape (); } - if (((SPObjectClass *) parent_class)->update) - ((SPObjectClass *) parent_class)->update (object, ctx, flags); + // CPPIFY: see header file + CShape::onUpdate(ctx, flags); } +// CPPIFY: remove static void -sp_star_update_patheffect(SPLPEItem *lpeitem, bool write) +sp_star_update (SPObject *object, SPCtx *ctx, guint flags) { + ((SPStar*)object)->cstar->onUpdate(ctx, flags); +} + +void CStar::onUpdatePatheffect(bool write) { + SPStar* lpeitem = this->spstar; SPShape *shape = (SPShape *) lpeitem; + sp_star_set_shape(shape); if (write) { @@ -289,10 +329,15 @@ sp_star_update_patheffect(SPLPEItem *lpeitem, bool write) ((SPObject *)shape)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -static gchar * -sp_star_description (SPItem *item) +// CPPIFY: remove +static void +sp_star_update_patheffect(SPLPEItem *lpeitem, bool write) { - SPStar *star = SP_STAR (item); + ((SPStar*)lpeitem)->cstar->onUpdatePatheffect(write); +} + +gchar* CStar::onDescription() { + SPStar *star = this->spstar; // while there will never be less than 3 vertices, we still need to // make calls to ngettext because the pluralization may be different @@ -307,6 +352,13 @@ sp_star_description (SPItem *item) star->sides), star->sides); } +// CPPIFY: remove +static gchar * +sp_star_description (SPItem *item) +{ + return ((SPStar*)item)->cstar->onDescription(); +} + /** Returns a unit-length vector at 90 degrees to the direction from o to n */ @@ -413,14 +465,12 @@ sp_star_get_curvepoint (SPStar *star, SPStarPoint point, gint index, bool previ) } } - #define NEXT false #define PREV true -static void -sp_star_set_shape (SPShape *shape) -{ - SPStar *star = SP_STAR (shape); +void CStar::onSetShape() { + SPStar* shape = this->spstar; + SPStar *star = shape; // perhaps we should convert all our shapes into LPEs without source path // and with knotholders for parameters, then this situation will be handled automatically @@ -515,6 +565,13 @@ sp_star_set_shape (SPShape *shape) c->unref(); } +// CPPIFY: remove +static void +sp_star_set_shape (SPShape *shape) +{ + ((SPStar*)shape)->cstar->onSetShape(); +} + void sp_star_position_set (SPStar *star, gint sides, Geom::Point center, gdouble r1, gdouble r2, gdouble arg1, gdouble arg2, bool isflat, double rounded, double randomized) { @@ -537,16 +594,16 @@ sp_star_position_set (SPStar *star, gint sides, Geom::Point center, gdouble r1, star->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -static void sp_star_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) -{ +void CStar::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + SPStar* item = this->spstar; + // We will determine the star's midpoint ourselves, instead of trusting on the base class // Therefore snapping to object midpoints is temporarily disabled Inkscape::SnapPreferences local_snapprefs = *snapprefs; local_snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT, false); - if (((SPItemClass *) parent_class)->snappoints) { - ((SPItemClass *) parent_class)->snappoints (item, p, &local_snapprefs); - } + // CPPIFY: see header file + CShape::onSnappoints(p, &local_snapprefs); if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) { Geom::Affine const i2dt (item->i2dt_affine ()); @@ -554,6 +611,12 @@ static void sp_star_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) +{ + ((SPStar const*)item)->cstar->onSnappoints(p, snapprefs); +} + /** * sp_star_get_xy: Get X-Y value as item coordinate system * @star: star item diff --git a/src/sp-star.h b/src/sp-star.h index 82197d13d..de19cc5ec 100644 --- a/src/sp-star.h +++ b/src/sp-star.h @@ -26,13 +26,17 @@ class SPStar; class SPStarClass; +class CStar; typedef enum { SP_STAR_POINT_KNOT1, SP_STAR_POINT_KNOT2 } SPStarPoint; -struct SPStar : public SPPolygon { +class SPStar : public SPPolygon { +public: + CStar* cstar; + gint sides; Geom::Point center; @@ -48,6 +52,31 @@ struct SPStarClass { SPPolygonClass parent_class; }; +// CPPIFY: This derivation is a bit weird. +// parent_class = reinterpret_cast(g_type_class_ref(SP_TYPE_SHAPE)); +// So shouldn't star be derived from shape instead of polygon? +// What does polygon have that shape doesn't? +class CStar : public CPolygon { +public: + CStar(SPStar* star); + virtual ~CStar(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual void onSet(unsigned int key, gchar const* value); + virtual void onUpdate(SPCtx* ctx, guint flags); + + virtual gchar* onDescription(); + virtual void onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs); + + virtual void onUpdatePatheffect(bool write); + virtual void onSetShape(); + +protected: + SPStar* spstar; +}; + + GType sp_star_get_type (void); void sp_star_position_set (SPStar *star, gint sides, Geom::Point center, gdouble r1, gdouble r2, gdouble arg1, gdouble arg2, bool isflat, double rounded, double randomized); -- cgit v1.2.3 From 375a1ceb6ff9b4868f9e57b5cd865e7c2ce518fe Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 23:51:30 +0200 Subject: Added "virtual pad" to SPPolyLine. (bzr r11608.1.12) --- src/sp-polyline.cpp | 68 ++++++++++++++++++++++++++++++++++++++--------------- src/sp-polyline.h | 20 ++++++++++++++++ 2 files changed, 69 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/sp-polyline.cpp b/src/sp-polyline.cpp index 8dbed2a22..16980bcb6 100644 --- a/src/sp-polyline.cpp +++ b/src/sp-polyline.cpp @@ -59,24 +59,39 @@ void SPPolyLineClass::sp_polyline_class_init(SPPolyLineClass *klass) item_class->description = SPPolyLine::getDescription; } -void SPPolyLine::init(SPPolyLine * /*polyline*/) -{ - /* Nothing here */ +CPolyLine::CPolyLine(SPPolyLine* polyline) : CShape(polyline) { + this->sppolyline = polyline; } -void SPPolyLine::build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) +CPolyLine::~CPolyLine() { +} + +void SPPolyLine::init(SPPolyLine * polyline) { + polyline->cpolyline = new CPolyLine(polyline); + polyline->cshape = polyline->cpolyline; + polyline->clpeitem = polyline->cpolyline; + polyline->citem = polyline->cpolyline; + polyline->cobject = polyline->cpolyline; +} - if (((SPObjectClass *) SPPolyLineClass::static_parent_class)->build) { - ((SPObjectClass *) SPPolyLineClass::static_parent_class)->build (object, document, repr); - } +void CPolyLine::onBuild(SPDocument * document, Inkscape::XML::Node * repr) { + SPPolyLine* object = this->sppolyline; + + CShape::onBuild(document, repr); object->readAttr( "points" ); } -void SPPolyLine::set(SPObject *object, unsigned int key, const gchar *value) +// CPPIFY: remove +void SPPolyLine::build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) { - SPPolyLine *polyline = SP_POLYLINE(object); + ((SPPolyLine*)object)->cpolyline->onBuild(document, repr); +} + +void CPolyLine::onSet(unsigned int key, const gchar* value) { + SPPolyLine* object = this->sppolyline; + SPPolyLine *polyline = object; switch (key) { case SP_ATTR_POINTS: { @@ -125,16 +140,22 @@ void SPPolyLine::set(SPObject *object, unsigned int key, const gchar *value) break; } default: - if (((SPObjectClass *) SPPolyLineClass::static_parent_class)->set) { - ((SPObjectClass *) SPPolyLineClass::static_parent_class)->set (object, key, value); - } + CShape::onSet(key, value); break; } } -Inkscape::XML::Node *SPPolyLine::write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +// CPPIFY: remove +void SPPolyLine::set(SPObject *object, unsigned int key, const gchar *value) { - SP_POLYLINE(object); + ((SPPolyLine*)object)->cpolyline->onSet(key, value); +} + +Inkscape::XML::Node* CPolyLine::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPPolyLine* object = this->sppolyline; + + // CPPIFY: This is a simple type check? + //SP_POLYLINE(object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:polyline"); @@ -144,16 +165,25 @@ Inkscape::XML::Node *SPPolyLine::write(SPObject *object, Inkscape::XML::Document repr->mergeFrom(object->getRepr(), "id"); } - if (((SPObjectClass *) (SPPolyLineClass::static_parent_class))->write) { - ((SPObjectClass *) (SPPolyLineClass::static_parent_class))->write (object, xml_doc, repr, flags); - } + CShape::onWrite(xml_doc, repr, flags); return repr; } -gchar *SPPolyLine::getDescription(SPItem * /*item*/) +// CPPIFY: remove +Inkscape::XML::Node *SPPolyLine::write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPPolyLine*)object)->cpolyline->onWrite(xml_doc, repr, flags); +} + +gchar* CPolyLine::onDescription() { + return g_strdup(_("Polyline")); +} + +// CPPIFY: remove +gchar *SPPolyLine::getDescription(SPItem * item) { - return g_strdup(_("Polyline")); + return ((SPPolyLine*)item)->cpolyline->onDescription(); } diff --git a/src/sp-polyline.h b/src/sp-polyline.h index 277529b49..09c602c38 100644 --- a/src/sp-polyline.h +++ b/src/sp-polyline.h @@ -13,9 +13,12 @@ class SPPolyLine; class SPPolyLineClass; +class CPolyLine; class SPPolyLine : public SPShape { public: + CPolyLine* cpolyline; + static GType sp_polyline_get_type (void); private: @@ -41,6 +44,23 @@ private: friend class SPPolyLine; }; + +class CPolyLine : public CShape { +public: + CPolyLine(SPPolyLine* polyline); + virtual ~CPolyLine(); + + virtual void onBuild(SPDocument* doc, Inkscape::XML::Node* repr); + virtual void onSet(unsigned int key, gchar const* value); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + + virtual gchar* onDescription(); + +protected: + SPPolyLine* sppolyline; +}; + + #endif // SEEN_SP_POLYLINE_H /* -- cgit v1.2.3 From 1ab271aaa35acc07f07c88945f461d42dc7352fc Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 23:51:50 +0200 Subject: Added "virtual pad" to SPRect. (bzr r11608.1.13) --- src/sp-rect.cpp | 154 +++++++++++++++++++++++++++++++++++++++----------------- src/sp-rect.h | 30 ++++++++++- 2 files changed, 136 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp index 22a403345..47374605b 100644 --- a/src/sp-rect.cpp +++ b/src/sp-rect.cpp @@ -93,9 +93,22 @@ sp_rect_class_init(SPRectClass *klass) shape_class->set_shape = sp_rect_set_shape; } +CRect::CRect(SPRect* rect) : CShape(rect) { + this->sprect = rect; +} + +CRect::~CRect() { +} + static void -sp_rect_init(SPRect */*rect*/) +sp_rect_init(SPRect *rect) { + rect->crect = new CRect(rect); + rect->cshape = rect->crect; + rect->clpeitem = rect->crect; + rect->citem = rect->crect; + rect->cobject = rect->crect; + /* Initializing to zero is automatic */ /* sp_svg_length_unset(&rect->x, SP_SVG_UNIT_NONE, 0.0, 0.0); */ /* sp_svg_length_unset(&rect->y, SP_SVG_UNIT_NONE, 0.0, 0.0); */ @@ -105,11 +118,10 @@ sp_rect_init(SPRect */*rect*/) /* sp_svg_length_unset(&rect->ry, SP_SVG_UNIT_NONE, 0.0, 0.0); */ } -static void -sp_rect_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ - if (((SPObjectClass *) parent_class)->build) - ((SPObjectClass *) parent_class)->build(object, document, repr); +void CRect::onBuild(SPDocument* doc, Inkscape::XML::Node* repr) { + SPRect* object = this->sprect; + + CShape::onBuild(doc, repr); object->readAttr( "x" ); object->readAttr( "y" ); @@ -119,10 +131,16 @@ sp_rect_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) object->readAttr( "ry" ); } +// CPPIFY: remove static void -sp_rect_set(SPObject *object, unsigned key, gchar const *value) +sp_rect_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - SPRect *rect = SP_RECT(object); + ((SPRect*)object)->crect->onBuild(document, repr); +} + +void CRect::onSet(unsigned key, gchar const *value) { + SPRect* rect = this->sprect; + SPRect* object = rect; /* fixme: We need real error processing some time */ @@ -160,15 +178,21 @@ sp_rect_set(SPObject *object, unsigned key, gchar const *value) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) parent_class)->set) - ((SPObjectClass *) parent_class)->set(object, key, value); + CShape::onSet(key, value); break; } } +// CPPIFY: remove static void -sp_rect_update(SPObject *object, SPCtx *ctx, guint flags) +sp_rect_set(SPObject *object, unsigned key, gchar const *value) { + ((SPRect*)object)->crect->onSet(key, value); +} + +void CRect::onUpdate(SPCtx* ctx, unsigned int flags) { + SPRect* object = this->sprect; + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { SPRect *rect = (SPRect *) object; SPStyle *style = object->style; @@ -187,14 +211,18 @@ sp_rect_update(SPObject *object, SPCtx *ctx, guint flags) flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore } - if (((SPObjectClass *) parent_class)->update) - ((SPObjectClass *) parent_class)->update(object, ctx, flags); + CShape::onUpdate(ctx, flags); } -static Inkscape::XML::Node * -sp_rect_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +// CPPIFY: remove +static void +sp_rect_update(SPObject *object, SPCtx *ctx, guint flags) { - SPRect *rect = SP_RECT(object); + ((SPRect*)object)->crect->onUpdate(ctx, flags); +} + +Inkscape::XML::Node * CRect::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPRect* rect = this->sprect; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:rect"); @@ -207,26 +235,34 @@ sp_rect_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML: sp_repr_set_svg_double(repr, "x", rect->x.computed); sp_repr_set_svg_double(repr, "y", rect->y.computed); - if (((SPObjectClass *) parent_class)->write) - ((SPObjectClass *) parent_class)->write(object, xml_doc, repr, flags); + CShape::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +static Inkscape::XML::Node * +sp_rect_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPRect*)object)->crect->onWrite(xml_doc, repr, flags); +} + +gchar* CRect::onDescription() { + g_return_val_if_fail(SP_IS_RECT(this->sprect), NULL); + return g_strdup(_("Rectangle")); +} + +// CPPIFY: remove static gchar * sp_rect_description(SPItem *item) { - g_return_val_if_fail(SP_IS_RECT(item), NULL); - - return g_strdup(_("Rectangle")); + return ((SPRect*)item)->crect->onDescription(); } #define C1 0.554 -static void -sp_rect_set_shape(SPShape *shape) -{ - SPRect *rect = (SPRect *) shape; +void CRect::onSetShape() { + SPRect *rect = this->sprect; if ((rect->height.computed < 1e-18) || (rect->width.computed < 1e-18)) { SP_SHAPE(rect)->setCurveInsync( NULL, TRUE); @@ -288,6 +324,13 @@ sp_rect_set_shape(SPShape *shape) c->unref(); } +// CPPIFY: remove +static void +sp_rect_set_shape(SPShape *shape) +{ + ((SPRect*)shape)->crect->onSetShape(); +} + /* fixme: Think (Lauris) */ void @@ -328,18 +371,9 @@ sp_rect_set_ry(SPRect *rect, gboolean set, gdouble value) SP_OBJECT(rect)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -/* - * Initially we'll do: - * Transform x, y, set x, y, clear translation - */ - -/* fixme: Use preferred units somehow (Lauris) */ -/* fixme: Alternately preserve whatever units there are (lauris) */ - -static Geom::Affine -sp_rect_set_transform(SPItem *item, Geom::Affine const &xform) -{ - SPRect *rect = SP_RECT(item); +Geom::Affine CRect::onSetTransform(Geom::Affine const& xform) { + SPRect *rect = this->sprect; + SPRect* item = rect; /* Calculate rect start in parent coords. */ Geom::Point pos( Geom::Point(rect->x.computed, rect->y.computed) * xform ); @@ -395,6 +429,21 @@ sp_rect_set_transform(SPItem *item, Geom::Affine const &xform) return ret; } +/* + * Initially we'll do: + * Transform x, y, set x, y, clear translation + */ + +/* fixme: Use preferred units somehow (Lauris) */ +/* fixme: Alternately preserve whatever units there are (lauris) */ + +// CPPIFY: remove +static Geom::Affine +sp_rect_set_transform(SPItem *item, Geom::Affine const &xform) +{ + return ((SPRect*)item)->crect->onSetTransform(xform); +} + /** Returns the ratio in which the vector from p0 to p1 is stretched by transform @@ -551,11 +600,10 @@ sp_rect_get_visible_height(SPRect *rect) rect->transform); } -/** - * Sets the snappoint p to the unrounded corners of the rectangle - */ -static void sp_rect_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) -{ +void CRect::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + SPRect *rect = this->sprect; + SPRect* item = rect; + /* This method overrides sp_shape_snappoints, which is the default for any shape. The default method returns all eight points along the path of a rounded rectangle, but not the real corners. Snapping the startpoint and endpoint of each rounded corner is not very useful and really confusing. Instead @@ -566,8 +614,6 @@ static void sp_rect_snappoints(SPItem const *item, std::vectori2dt_affine ()); Geom::Point p0 = Geom::Point(rect->x.computed, rect->y.computed) * i2dt; @@ -592,12 +638,20 @@ static void sp_rect_snappoints(SPItem const *item, std::vectorisTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) { p.push_back(Inkscape::SnapCandidatePoint((p0 + p2)/2, Inkscape::SNAPSOURCE_OBJECT_MIDPOINT, Inkscape::SNAPTARGET_OBJECT_MIDPOINT)); } +} +// CPPIFY: remove +/** + * Sets the snappoint p to the unrounded corners of the rectangle + */ +static void sp_rect_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) +{ + ((SPRect*)item)->crect->onSnappoints(p, snapprefs); } -void -sp_rect_convert_to_guides(SPItem *item) { - SPRect *rect = SP_RECT(item); +void CRect::onConvertToGuides() { + SPRect* rect = this->sprect; + SPRect* item = rect; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (!prefs->getBool("/tools/shapes/rect/convertguides", true)) { @@ -622,6 +676,12 @@ sp_rect_convert_to_guides(SPItem *item) { sp_guide_pt_pairs_to_guides(item->document, pts); } +// CPPIFY: remove +void +sp_rect_convert_to_guides(SPItem *item) { + ((SPRect*)item)->crect->onConvertToGuides(); +} + /* Local Variables: mode:c++ diff --git a/src/sp-rect.h b/src/sp-rect.h index 7bc85dd8a..f33323a4d 100644 --- a/src/sp-rect.h +++ b/src/sp-rect.h @@ -28,8 +28,12 @@ class SPRect; class SPRectClass; +class CRect; + +class SPRect : public SPShape { +public: + CRect* crect; -struct SPRect : public SPShape { SVGLength x; SVGLength y; SVGLength width; @@ -43,6 +47,30 @@ struct SPRectClass { }; +class CRect : public CShape { +public: + CRect(SPRect* sprect); + virtual ~CRect(); + + virtual void onBuild(SPDocument* doc, Inkscape::XML::Node* repr); + + void onSet(unsigned key, gchar const *value); + void onUpdate(SPCtx* ctx, unsigned int flags); + + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual gchar* onDescription(); + + void onSetShape(); + virtual Geom::Affine onSetTransform(Geom::Affine const& xform); + + void onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs); + void onConvertToGuides(); + +protected: + SPRect* sprect; +}; + + /* Standard GType function */ GType sp_rect_get_type (void); -- cgit v1.2.3 From f7070430c2a43ad20438359f62c4313a49518152 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sat, 18 Aug 2012 23:52:09 +0200 Subject: Added "virtual pad" to SPSpiral. (bzr r11608.1.14) --- src/sp-spiral.cpp | 140 +++++++++++++++++++++++++++++++++++++----------------- src/sp-spiral.h | 27 ++++++++++- 2 files changed, 123 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/sp-spiral.cpp b/src/sp-spiral.cpp index fd2672388..f5e7cdb0b 100644 --- a/src/sp-spiral.cpp +++ b/src/sp-spiral.cpp @@ -97,12 +97,25 @@ static void sp_spiral_class_init(SPSpiralClass *klass) shape_class->set_shape = sp_spiral_set_shape; } +CSpiral::CSpiral(SPSpiral* spiral) : CShape(spiral) { + this->spspiral = spiral; +} + +CSpiral::~CSpiral() { +} + /** * Callback for SPSpiral object initialization. */ static void sp_spiral_init (SPSpiral * spiral) { + spiral->cspiral = new CSpiral(spiral); + spiral->cshape = spiral->cspiral; + spiral->clpeitem = spiral->cspiral; + spiral->citem = spiral->cspiral; + spiral->cobject = spiral->cspiral; + spiral->cx = 0.0; spiral->cy = 0.0; spiral->exp = 1.0; @@ -112,14 +125,10 @@ sp_spiral_init (SPSpiral * spiral) spiral->t0 = 0.0; } -/** - * Virtual build: set spiral properties from corresponding repr. - */ -static void sp_spiral_build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) -{ - if (reinterpret_cast(parent_class)->build) { - reinterpret_cast(parent_class)->build(object, document, repr); - } +void CSpiral::onBuild(SPDocument * document, Inkscape::XML::Node * repr) { + SPSpiral* object = this->spspiral; + + CShape::onBuild(document, repr); object->readAttr( "sodipodi:cx" ); object->readAttr( "sodipodi:cy" ); @@ -130,13 +139,17 @@ static void sp_spiral_build(SPObject * object, SPDocument * document, Inkscape:: object->readAttr( "sodipodi:t0" ); } +// CPPIFY: remove /** - * Virtual write: write spiral attributes to corresponding repr. + * Virtual build: set spiral properties from corresponding repr. */ -static Inkscape::XML::Node * -sp_spiral_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void sp_spiral_build(SPObject * object, SPDocument * document, Inkscape::XML::Node * repr) { - SPSpiral *spiral = SP_SPIRAL (object); + ((SPSpiral*)object)->cspiral->onBuild(document, repr); +} + +Inkscape::XML::Node* CSpiral::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPSpiral *spiral = this->spspiral; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:path"); @@ -168,19 +181,24 @@ sp_spiral_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::X repr->setAttribute("d", d); g_free (d); - if (reinterpret_cast(parent_class)->write) { - reinterpret_cast(parent_class)->write(object, xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); - } + CShape::onWrite(xml_doc, repr, flags | SP_SHAPE_WRITE_PATH); return repr; } +// CPPIFY: remove /** - * Virtual set: change spiral object attribute. + * Virtual write: write spiral attributes to corresponding repr. */ -static void sp_spiral_set(SPObject *object, unsigned int key, const gchar *value) +static Inkscape::XML::Node * +sp_spiral_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPSpiral *spiral = SP_SPIRAL(object); + return ((SPSpiral*)object)->cspiral->onWrite(xml_doc, repr, flags); +} + +void CSpiral::onSet(unsigned int key, gchar const* value) { + SPSpiral *spiral = this->spspiral; + SPSpiral* object = spiral; /// \todo fixme: we should really collect updates switch (key) { @@ -260,30 +278,42 @@ static void sp_spiral_set(SPObject *object, unsigned int key, const gchar *value object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; default: - if (reinterpret_cast(parent_class)->set) { - reinterpret_cast(parent_class)->set(object, key, value); - } + CShape::onSet(key, value); break; } } +// CPPIFY: remove /** - * Virtual update callback. + * Virtual set: change spiral object attribute. */ -static void sp_spiral_update(SPObject *object, SPCtx *ctx, guint flags) +static void sp_spiral_set(SPObject *object, unsigned int key, const gchar *value) { + ((SPSpiral*)object)->cspiral->onSet(key, value); +} + +void CSpiral::onUpdate(SPCtx *ctx, guint flags) { + SPSpiral* object = this->spspiral; + if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { reinterpret_cast(object)->setShape(); } - if (reinterpret_cast(parent_class)->update) { - reinterpret_cast(parent_class)->update(object, ctx, flags); - } + CShape::onUpdate(ctx, flags); } -static void sp_spiral_update_patheffect(SPLPEItem *lpeitem, bool write) +// CPPIFY: remove +/** + * Virtual update callback. + */ +static void sp_spiral_update(SPObject *object, SPCtx *ctx, guint flags) { - SPShape *shape = static_cast(lpeitem); + ((SPSpiral*)object)->cspiral->onUpdate(ctx, flags); +} + +void CSpiral::onUpdatePatheffect(bool write) { + SPSpiral* shape = this->spspiral; + sp_spiral_set_shape(shape); if (write) { @@ -300,14 +330,27 @@ static void sp_spiral_update_patheffect(SPLPEItem *lpeitem, bool write) shape->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } +// CPPIFY: remove +static void sp_spiral_update_patheffect(SPLPEItem *lpeitem, bool write) +{ + ((SPSpiral*)lpeitem)->cspiral->onUpdatePatheffect(write); +} + +gchar* CSpiral::onDescription() { + SPSpiral* item = this->spspiral; + + // TRANSLATORS: since turn count isn't an integer, please adjust the + // string as needed to deal with an localized plural forms. + return g_strdup_printf (_("Spiral with %3f turns"), SP_SPIRAL(item)->revo); +} + +// CPPIFY: remove /** * Return textual description of spiral. */ static gchar *sp_spiral_description(SPItem * item) { - // TRANSLATORS: since turn count isn't an integer, please adjust the - // string as needed to deal with an localized plural forms. - return g_strdup_printf (_("Spiral with %3f turns"), SP_SPIRAL(item)->revo); + return ((SPSpiral*)item)->cspiral->onDescription(); } @@ -401,10 +444,9 @@ sp_spiral_fit_and_draw (SPSpiral const *spiral, g_assert (is_unit_vector (hat2)); } -static void -sp_spiral_set_shape (SPShape *shape) -{ - SPSpiral *spiral = SP_SPIRAL(shape); +void CSpiral::onSetShape() { + SPSpiral *spiral = this->spspiral; + SPSpiral* shape = spiral; if (sp_lpe_item_has_broken_path_effect(SP_LPE_ITEM(shape))) { g_warning ("The spiral shape has unknown LPE on it! Convert to path to make it editable preserving the appearance; editing it as spiral will remove the bad LPE"); @@ -469,6 +511,13 @@ sp_spiral_set_shape (SPShape *shape) c->unref(); } +// CPPIFY: remove +static void +sp_spiral_set_shape (SPShape *shape) +{ + ((SPSpiral*)shape)->cspiral->onSetShape(); +} + /** * Set spiral properties and update display. */ @@ -500,19 +549,15 @@ sp_spiral_position_set (SPSpiral *spiral, (static_cast(spiral))->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); } -/** - * Virtual snappoints callback. - */ -static void sp_spiral_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) -{ +void CSpiral::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + SPSpiral* item = this->spspiral; + // We will determine the spiral's midpoint ourselves, instead of trusting on the base class // Therefore snapping to object midpoints is temporarily disabled Inkscape::SnapPreferences local_snapprefs = *snapprefs; local_snapprefs.setTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT, false); - if ((reinterpret_cast(parent_class))->snappoints) { - (reinterpret_cast(parent_class))->snappoints (item, p, &local_snapprefs); - } + CShape::onSnappoints(p, &local_snapprefs); if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_OBJECT_MIDPOINT)) { Geom::Affine const i2dt (item->i2dt_affine ()); @@ -523,6 +568,15 @@ static void sp_spiral_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) +{ + ((SPSpiral*)item)->cspiral->onSnappoints(p, snapprefs); +} + /** * Return one of the points on the spiral. * diff --git a/src/sp-spiral.h b/src/sp-spiral.h index 6da7c38a4..570f8e691 100644 --- a/src/sp-spiral.h +++ b/src/sp-spiral.h @@ -31,6 +31,7 @@ class SPSpiral; class SPSpiralClass; +class CSpiral; /** * A spiral Shape. @@ -44,7 +45,10 @@ class SPSpiralClass; * * \todo Should I remove these attributes? */ -struct SPSpiral : public SPShape { +class SPSpiral : public SPShape { +public: + CSpiral* cspiral; + float cx, cy; float exp; ///< Spiral expansion factor float revo; ///< Spiral revolution factor @@ -59,6 +63,27 @@ struct SPSpiralClass { }; +class CSpiral : public CShape { +public: + CSpiral(SPSpiral* spiral); + virtual ~CSpiral(); + + virtual void onBuild(SPDocument* doc, Inkscape::XML::Node* repr); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual void onUpdate(SPCtx *ctx, guint flags); + virtual void onSet(unsigned int key, gchar const* value); + + virtual void onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs); + virtual gchar* onDescription(); + + virtual void onSetShape(); + virtual void onUpdatePatheffect(bool write); + +protected: + SPSpiral* spspiral; +}; + + /* Standard Gtk function */ GType sp_spiral_get_type (void); -- cgit v1.2.3 From c2590463bfdefdbf69f5e1503533c7b4852ac7cd Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 00:11:19 +0200 Subject: As all subclasses of SPShape now have "virtual pads" with correct inheritance, the virtual function call to "onSetShape" was converted to C++ style. (bzr r11608.1.15) --- src/sp-shape.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src') diff --git a/src/sp-shape.cpp b/src/sp-shape.cpp index e0f13c62d..87b1e7607 100644 --- a/src/sp-shape.cpp +++ b/src/sp-shape.cpp @@ -509,7 +509,6 @@ void SPShape::sp_shape_update_marker_view(SPShape *shape, Inkscape::DrawingItem void CShape::onModified(unsigned int flags) { SPShape* shape = this->spshape; - SPShape* object = shape; CLPEItem::onModified(flags); @@ -1081,9 +1080,7 @@ void CShape::onSetShape() { */ void SPShape::setShape() { - if (SP_SHAPE_CLASS (G_OBJECT_GET_CLASS (this))->set_shape) { - SP_SHAPE_CLASS (G_OBJECT_GET_CLASS (this))->set_shape (this); - } + this->cshape->onSetShape(); } /** -- cgit v1.2.3 From 72f9ed8e6a94b65a3fbc9582179e6e72330ff144 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 01:40:03 +0200 Subject: Added "virtual pad" to SPGroup and SPSwitch. There was some weird try by someone else. SPGroup should work as expected, SPSwitch may still be buggy. (bzr r11608.1.16) --- src/sp-conn-end-pair.cpp | 2 +- src/sp-item-group.cpp | 539 +++++++++++++++++++++++++---------------------- src/sp-item-group.h | 44 ++-- src/sp-switch.cpp | 67 +++--- src/sp-switch.h | 54 +++-- 5 files changed, 386 insertions(+), 320 deletions(-) (limited to 'src') diff --git a/src/sp-conn-end-pair.cpp b/src/sp-conn-end-pair.cpp index 17e9e7397..05495477b 100644 --- a/src/sp-conn-end-pair.cpp +++ b/src/sp-conn-end-pair.cpp @@ -203,7 +203,7 @@ SPConnEndPair::getAttachedItems(SPItem *h2attItem[2]) const { // selected through the XML editor, it makes sense just to detach // connectors from them. if (SP_IS_GROUP(h2attItem[h])) { - if (SP_GROUP(h2attItem[h])->group->getItemCount() == 0) { + if (SP_GROUP(h2attItem[h])->getItemCount() == 0) { // This group is empty, so detach. sp_conn_end_detach(_path, h); h2attItem[h] = NULL; diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index b54ec65e2..406db4d8f 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -138,90 +138,232 @@ sp_group_class_init (SPGroupClass *klass) lpe_item_class->update_patheffect = sp_group_update_patheffect; } +CGroup::CGroup(SPGroup *group) : CLPEItem(group) { + this->spgroup = group; +} + +CGroup::~CGroup() { +} + static void sp_group_init (SPGroup *group) { + group->cgroup = new CGroup(group); + group->clpeitem = group->cgroup; + group->citem = group->cgroup; + group->cobject = group->cgroup; + group->_layer_mode = SPGroup::GROUP; - group->group = new CGroup(group); - new (&group->_display_modes) std::map(); + new (&group->_display_modes) std::map(); } -static void sp_group_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ +void CGroup::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPGroup* object = this->spgroup; + object->readAttr( "inkscape:groupmode" ); - if (((SPObjectClass *)parent_class)->build) { - ((SPObjectClass *)parent_class)->build(object, document, repr); - } + CLPEItem::onBuild(document, repr); } -static void sp_group_release(SPObject *object) { +// CPPIFY: remove +static void sp_group_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) +{ + ((SPGroup*)object)->cgroup->onBuild(document, repr); +} + +void CGroup::onRelease() { + SPGroup* object = this->spgroup; + if ( SP_GROUP(object)->_layer_mode == SPGroup::LAYER ) { object->document->removeResource("layer", object); } - if (((SPObjectClass *)parent_class)->release) { - ((SPObjectClass *)parent_class)->release(object); - } + + CLPEItem::onRelease(); +} + +// CPPIFY: remove +static void sp_group_release(SPObject *object) { + ((SPGroup*)object)->cgroup->onRelease(); } static void sp_group_dispose(GObject *object) { SP_GROUP(object)->_display_modes.~map(); - delete SP_GROUP(object)->group; } -static void sp_group_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) -{ - SPGroup *group = SP_GROUP(object); +void CGroup::onChildAdded(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) { + CLPEItem::onChildAdded(child, ref); + + SPObject *last_child = spgroup->lastChild(); + + if (last_child && last_child->getRepr() == child) { + // optimization for the common special case where the child is being added at the end + SPObject *ochild = last_child; + if ( SP_IS_ITEM(ochild) ) { + /* TODO: this should be moved into SPItem somehow */ + SPItemView *v; + Inkscape::DrawingItem *ac; + + for (v = spgroup->display; v != NULL; v = v->next) { + ac = SP_ITEM (ochild)->invoke_show (v->arenaitem->drawing(), v->key, v->flags); + + if (ac) { + v->arenaitem->appendChild(ac); + } + } + } + } else { // general case + SPObject *ochild = spgroup->get_child_by_repr(child); + if ( ochild && SP_IS_ITEM(ochild) ) { + /* TODO: this should be moved into SPItem somehow */ + SPItemView *v; + Inkscape::DrawingItem *ac; + + unsigned position = SP_ITEM(ochild)->pos_in_parent(); + + for (v = spgroup->display; v != NULL; v = v->next) { + ac = SP_ITEM (ochild)->invoke_show (v->arenaitem->drawing(), v->key, v->flags); - if (((SPObjectClass *) (parent_class))->child_added) { - (* ((SPObjectClass *) (parent_class))->child_added) (object, child, ref); + if (ac) { + v->arenaitem->prependChild(ac); + ac->setZOrder(position); + } + } + } } - group->group->onChildAdded(child); + spgroup->requestModified(SP_OBJECT_MODIFIED_FLAG); +} + +// CPPIFY: remove +static void sp_group_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) +{ + ((SPGroup*)object)->cgroup->onChildAdded(child, ref); } /* fixme: hide (Lauris) */ +void CGroup::onRemoveChild(Inkscape::XML::Node *child) { + CLPEItem::onRemoveChild(child); + + spgroup->requestModified(SP_OBJECT_MODIFIED_FLAG); +} + +// CPPIFY: remove static void sp_group_remove_child (SPObject * object, Inkscape::XML::Node * child) { - if (((SPObjectClass *) (parent_class))->remove_child) - (* ((SPObjectClass *) (parent_class))->remove_child) (object, child); + ((SPGroup*)object)->cgroup->onRemoveChild(child); +} + +void CGroup::onOrderChanged (Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref) +{ + CLPEItem::onOrderChanged(child, old_ref, new_ref); - SP_GROUP(object)->group->onChildRemoved(child); + SPObject *ochild = spgroup->get_child_by_repr(child); + if ( ochild && SP_IS_ITEM(ochild) ) { + /* TODO: this should be moved into SPItem somehow */ + SPItemView *v; + unsigned position = SP_ITEM(ochild)->pos_in_parent(); + for ( v = SP_ITEM (ochild)->display ; v != NULL ; v = v->next ) { + v->arenaitem->setZOrder(position); + } + } + + spgroup->requestModified(SP_OBJECT_MODIFIED_FLAG); } +// CPPIFY: remove static void sp_group_order_changed (SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref) { - if (((SPObjectClass *) (parent_class))->order_changed) - (* ((SPObjectClass *) (parent_class))->order_changed) (object, child, old_ref, new_ref); + ((SPGroup*)object)->cgroup->onOrderChanged(child, old_ref, new_ref); +} + +void CGroup::onUpdate(SPCtx *ctx, unsigned int flags) { + CLPEItem::onUpdate(ctx, flags); + + SPItemCtx *ictx, cctx; + + ictx = (SPItemCtx *) ctx; + cctx = *ictx; - SP_GROUP(object)->group->onOrderChanged(child, old_ref, new_ref); + if (flags & SP_OBJECT_MODIFIED_FLAG) { + flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; + } + + flags &= SP_OBJECT_MODIFIED_CASCADE; + + if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { + SPObject *object = spgroup; + for (SPItemView *v = spgroup->display; v != NULL; v = v->next) { + Inkscape::DrawingGroup *group = dynamic_cast(v->arenaitem); + group->setStyle(object->style); + } + } + + GSList *l = g_slist_reverse(spgroup->childList(true, SPObject::ActionUpdate)); + while (l) { + SPObject *child = SP_OBJECT (l->data); + l = g_slist_remove (l, child); + if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { + if (SP_IS_ITEM (child)) { + SPItem const &chi = *SP_ITEM(child); + cctx.i2doc = chi.transform * ictx->i2doc; + cctx.i2vp = chi.transform * ictx->i2vp; + child->updateDisplay((SPCtx *)&cctx, flags); + } else { + child->updateDisplay(ctx, flags); + } + } + g_object_unref (G_OBJECT (child)); + } } +// CPPIFY: remove static void sp_group_update (SPObject *object, SPCtx *ctx, unsigned int flags) { - if (((SPObjectClass *) (parent_class))->update) - ((SPObjectClass *) (parent_class))->update (object, ctx, flags); + ((SPGroup*)object)->cgroup->onUpdate(ctx, flags); +} + +void CGroup::onModified(guint flags) { + CLPEItem::onModified(flags); + + SPObject *child; + + if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; + flags &= SP_OBJECT_MODIFIED_CASCADE; - SP_GROUP(object)->group->onUpdate(ctx, flags); + if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { + SPObject *object = spgroup; + for (SPItemView *v = spgroup->display; v != NULL; v = v->next) { + Inkscape::DrawingGroup *group = dynamic_cast(v->arenaitem); + group->setStyle(object->style); + } + } + + GSList *l = g_slist_reverse(spgroup->childList(true)); + while (l) { + child = SP_OBJECT (l->data); + l = g_slist_remove (l, child); + if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { + child->emitModified(flags); + } + g_object_unref (G_OBJECT (child)); + } } +// CPPIFY: remove static void sp_group_modified (SPObject *object, guint flags) { - if (((SPObjectClass *) (parent_class))->modified) - ((SPObjectClass *) (parent_class))->modified (object, flags); - - SP_GROUP(object)->group->onModified(flags); + ((SPGroup*)object)->cgroup->onModified(flags); } -static Inkscape::XML::Node * sp_group_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) -{ +Inkscape::XML::Node* CGroup::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPGroup* object = this->spgroup; SPGroup *group = SP_GROUP(object); if (flags & SP_OBJECT_WRITE_BUILD) { @@ -269,32 +411,75 @@ static Inkscape::XML::Node * sp_group_write(SPObject *object, Inkscape::XML::Doc repr->setAttribute("inkscape:groupmode", value); } - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags); - } + CLPEItem::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +static Inkscape::XML::Node * sp_group_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPGroup*)object)->cgroup->onWrite(xml_doc, repr, flags); +} + +Geom::OptRect CGroup::onBbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype) +{ + Geom::OptRect bbox; + + GSList *l = spgroup->childList(false, SPObject::ActionBBox); + while (l) { + SPObject *o = SP_OBJECT (l->data); + if (SP_IS_ITEM(o) && !SP_ITEM(o)->isHidden()) { + SPItem *child = SP_ITEM(o); + Geom::Affine const ct(child->transform * transform); + bbox |= child->bounds(bboxtype, ct); + } + l = g_slist_remove (l, o); + } + return bbox; +} + +// CPPIFY: remove static Geom::OptRect sp_group_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) { - return SP_GROUP(item)->group->bounds(type, transform); + return ((SPGroup*)item)->cgroup->onBbox(transform, type); +} + +void CGroup::onPrint(SPPrintContext *ctx) { + GSList *l = g_slist_reverse(spgroup->childList(false)); + while (l) { + SPObject *o = SP_OBJECT (l->data); + if (SP_IS_ITEM(o)) { + SP_ITEM(o)->invoke_print (ctx); + } + l = g_slist_remove (l, o); + } } +// CPPIFY: remove static void sp_group_print (SPItem * item, SPPrintContext *ctx) { - SP_GROUP(item)->group->onPrint(ctx); + ((SPGroup*)item)->cgroup->onPrint(ctx); } +gchar *CGroup::onDescription() { + gint len = this->spgroup->getItemCount(); + return g_strdup_printf( + ngettext("Group of %d object", + "Group of %d objects", + len), len); +} + +// CPPIFY: remove static gchar * sp_group_description (SPItem * item) { - return SP_GROUP(item)->group->getDescription(); + return ((SPGroup*)item)->cgroup->onDescription(); } -static void sp_group_set(SPObject *object, unsigned key, char const *value) { - SPGroup *group = SP_GROUP(object); +void CGroup::onSet(unsigned int key, gchar const* value) { + SPGroup *group = this->spgroup; switch (key) { case SP_ATTR_INKSCAPE_GROUPMODE: @@ -307,27 +492,65 @@ static void sp_group_set(SPObject *object, unsigned key, char const *value) { } break; default: { - if (((SPObjectClass *) (parent_class))->set) { - (* ((SPObjectClass *) (parent_class))->set)(object, key, value); - } + CLPEItem::onSet(key, value); } } } +// CPPIFY: remove +static void sp_group_set(SPObject *object, unsigned key, char const *value) { + ((SPGroup*)object)->cgroup->onSet(key, value); +} + +Inkscape::DrawingItem *CGroup::onShow (Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + Inkscape::DrawingGroup *ai; + SPObject *object = spgroup; + + ai = new Inkscape::DrawingGroup(drawing); + ai->setPickChildren(spgroup->effectiveLayerMode(key) == SPGroup::LAYER); + ai->setStyle(object->style); + + this->spgroup->_showChildren(drawing, ai, key, flags); + return ai; +} + +// CPPIFY: remove static Inkscape::DrawingItem * sp_group_show (SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { - return SP_GROUP(item)->group->show(drawing, key, flags); + return ((SPGroup*)item)->cgroup->onShow(drawing, key, flags); } +void CGroup::onHide (unsigned int key) { + SPItem * child; + + GSList *l = g_slist_reverse(spgroup->childList(false, SPObject::ActionShow)); + while (l) { + SPObject *o = SP_OBJECT (l->data); + if (SP_IS_ITEM (o)) { + child = SP_ITEM (o); + child->invoke_hide (key); + } + l = g_slist_remove (l, o); + } + + // CPPIFY: This doesn't make no sense. + // CItem::onHide is pure and CLPEItem doesn't override it. What was the idea behind these lines? +// if (((SPItemClass *) parent_class)->hide) +// ((SPItemClass *) parent_class)->hide (spgroup, key); +// CLPEItem::onHide(key); +} + +// CPPIFY: remove static void sp_group_hide (SPItem *item, unsigned int key) { - SP_GROUP(item)->group->hide(key); + ((SPGroup*)item)->cgroup->onHide(key); } -static void sp_group_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) -{ +void CGroup::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + SPGroup* item = this->spgroup; + for ( SPObject const *o = item->firstChild(); o; o = o->getNext() ) { if (SP_IS_ITEM(o)) { @@ -336,6 +559,12 @@ static void sp_group_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) +{ + ((SPGroup*)item)->cgroup->onSnappoints(p, snapprefs); +} + void sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done) @@ -583,152 +812,9 @@ void SPGroup::translateChildItems(Geom::Translate const &tr) } } -CGroup::CGroup(SPGroup *group) { - _group = group; -} - -CGroup::~CGroup() { -} - -void CGroup::onChildAdded(Inkscape::XML::Node *child) { - SPObject *last_child = _group->lastChild(); - if (last_child && last_child->getRepr() == child) { - // optimization for the common special case where the child is being added at the end - SPObject *ochild = last_child; - if ( SP_IS_ITEM(ochild) ) { - /* TODO: this should be moved into SPItem somehow */ - SPItemView *v; - Inkscape::DrawingItem *ac; - - for (v = _group->display; v != NULL; v = v->next) { - ac = SP_ITEM (ochild)->invoke_show (v->arenaitem->drawing(), v->key, v->flags); - - if (ac) { - v->arenaitem->appendChild(ac); - } - } - } - } else { // general case - SPObject *ochild = _group->get_child_by_repr(child); - if ( ochild && SP_IS_ITEM(ochild) ) { - /* TODO: this should be moved into SPItem somehow */ - SPItemView *v; - Inkscape::DrawingItem *ac; - - unsigned position = SP_ITEM(ochild)->pos_in_parent(); - - for (v = _group->display; v != NULL; v = v->next) { - ac = SP_ITEM (ochild)->invoke_show (v->arenaitem->drawing(), v->key, v->flags); - - if (ac) { - v->arenaitem->prependChild(ac); - ac->setZOrder(position); - } - } - } - } - - _group->requestModified(SP_OBJECT_MODIFIED_FLAG); -} - -void CGroup::onChildRemoved(Inkscape::XML::Node */*child*/) { - _group->requestModified(SP_OBJECT_MODIFIED_FLAG); -} - -void CGroup::onUpdate(SPCtx *ctx, unsigned int flags) { - SPItemCtx *ictx, cctx; - - ictx = (SPItemCtx *) ctx; - cctx = *ictx; - - if (flags & SP_OBJECT_MODIFIED_FLAG) { - flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; - } - - flags &= SP_OBJECT_MODIFIED_CASCADE; - - if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { - SPObject *object = _group; - for (SPItemView *v = _group->display; v != NULL; v = v->next) { - Inkscape::DrawingGroup *group = dynamic_cast(v->arenaitem); - group->setStyle(object->style); - } - } - - GSList *l = g_slist_reverse(_group->childList(true, SPObject::ActionUpdate)); - while (l) { - SPObject *child = SP_OBJECT (l->data); - l = g_slist_remove (l, child); - if (flags || (child->uflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { - if (SP_IS_ITEM (child)) { - SPItem const &chi = *SP_ITEM(child); - cctx.i2doc = chi.transform * ictx->i2doc; - cctx.i2vp = chi.transform * ictx->i2vp; - child->updateDisplay((SPCtx *)&cctx, flags); - } else { - child->updateDisplay(ctx, flags); - } - } - g_object_unref (G_OBJECT (child)); - } -} - -void CGroup::onModified(guint flags) { - SPObject *child; - - if (flags & SP_OBJECT_MODIFIED_FLAG) flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; - flags &= SP_OBJECT_MODIFIED_CASCADE; - - if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { - SPObject *object = _group; - for (SPItemView *v = _group->display; v != NULL; v = v->next) { - Inkscape::DrawingGroup *group = dynamic_cast(v->arenaitem); - group->setStyle(object->style); - } - } - - GSList *l = g_slist_reverse(_group->childList(true)); - while (l) { - child = SP_OBJECT (l->data); - l = g_slist_remove (l, child); - if (flags || (child->mflags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_CHILD_MODIFIED_FLAG))) { - child->emitModified(flags); - } - g_object_unref (G_OBJECT (child)); - } -} - -Geom::OptRect CGroup::bounds(SPItem::BBoxType type, Geom::Affine const &transform) -{ - Geom::OptRect bbox; - - GSList *l = _group->childList(false, SPObject::ActionBBox); - while (l) { - SPObject *o = SP_OBJECT (l->data); - if (SP_IS_ITEM(o) && !SP_ITEM(o)->isHidden()) { - SPItem *child = SP_ITEM(o); - Geom::Affine const ct(child->transform * transform); - bbox |= child->bounds(type, ct); - } - l = g_slist_remove (l, o); - } - return bbox; -} - -void CGroup::onPrint(SPPrintContext *ctx) { - GSList *l = g_slist_reverse(_group->childList(false)); - while (l) { - SPObject *o = SP_OBJECT (l->data); - if (SP_IS_ITEM(o)) { - SP_ITEM(o)->invoke_print (ctx); - } - l = g_slist_remove (l, o); - } -} - -gint CGroup::getItemCount() { +gint SPGroup::getItemCount() { gint len = 0; - for (SPObject *o = _group->firstChild() ; o ; o = o->getNext() ) { + for (SPObject *o = this->firstChild() ; o ; o = o->getNext() ) { if (SP_IS_ITEM(o)) { len++; } @@ -737,30 +823,10 @@ gint CGroup::getItemCount() { return len; } -gchar *CGroup::getDescription() { - gint len = getItemCount(); - return g_strdup_printf( - ngettext("Group of %d object", - "Group of %d objects", - len), len); -} - -Inkscape::DrawingItem *CGroup::show (Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { - Inkscape::DrawingGroup *ai; - SPObject *object = _group; - - ai = new Inkscape::DrawingGroup(drawing); - ai->setPickChildren(_group->effectiveLayerMode(key) == SPGroup::LAYER); - ai->setStyle(object->style); - - _showChildren(drawing, ai, key, flags); - return ai; -} - -void CGroup::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags) { +void SPGroup::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags) { Inkscape::DrawingItem *ac = NULL; SPItem * child = NULL; - GSList *l = g_slist_reverse(_group->childList(false, SPObject::ActionShow)); + GSList *l = g_slist_reverse(this->childList(false, SPObject::ActionShow)); while (l) { SPObject *o = SP_OBJECT (l->data); if (SP_IS_ITEM (o)) { @@ -772,41 +838,9 @@ void CGroup::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *a } } -void CGroup::hide (unsigned int key) { - SPItem * child; - - GSList *l = g_slist_reverse(_group->childList(false, SPObject::ActionShow)); - while (l) { - SPObject *o = SP_OBJECT (l->data); - if (SP_IS_ITEM (o)) { - child = SP_ITEM (o); - child->invoke_hide (key); - } - l = g_slist_remove (l, o); - } - - if (((SPItemClass *) parent_class)->hide) - ((SPItemClass *) parent_class)->hide (_group, key); -} - -void CGroup::onOrderChanged (Inkscape::XML::Node *child, Inkscape::XML::Node *, Inkscape::XML::Node *) -{ - SPObject *ochild = _group->get_child_by_repr(child); - if ( ochild && SP_IS_ITEM(ochild) ) { - /* TODO: this should be moved into SPItem somehow */ - SPItemView *v; - unsigned position = SP_ITEM(ochild)->pos_in_parent(); - for ( v = SP_ITEM (ochild)->display ; v != NULL ; v = v->next ) { - v->arenaitem->setZOrder(position); - } - } - - _group->requestModified(SP_OBJECT_MODIFIED_FLAG); -} +void CGroup::onUpdatePatheffect(bool write) { + SPGroup* lpeitem = this->spgroup; -static void -sp_group_update_patheffect (SPLPEItem *lpeitem, bool write) -{ #ifdef GROUP_VERBOSE g_message("sp_group_update_patheffect: %p\n", lpeitem); #endif @@ -836,6 +870,13 @@ sp_group_update_patheffect (SPLPEItem *lpeitem, bool write) } } +// CPPIFY: remove +static void +sp_group_update_patheffect (SPLPEItem *lpeitem, bool write) +{ + ((SPGroup*)lpeitem)->cgroup->onUpdatePatheffect(write); +} + static void sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write) { diff --git a/src/sp-item-group.h b/src/sp-item-group.h index c13fa2b75..d5e8cc771 100644 --- a/src/sp-item-group.h +++ b/src/sp-item-group.h @@ -33,7 +33,10 @@ class DrawingItem; } // namespace Inkscape -struct SPGroup : public SPLPEItem { +class SPGroup : public SPLPEItem { +public: + CGroup *cgroup; + enum LayerMode { GROUP, LAYER, MASK_HELPER }; LayerMode _layer_mode; @@ -54,8 +57,9 @@ struct SPGroup : public SPLPEItem { void setLayerDisplayMode(unsigned int display_key, LayerMode mode); void translateChildItems(Geom::Translate const &tr); - CGroup *group; - + gint getItemCount(); + void _showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags); + private: void _updateLayerMode(unsigned int display_key=0); }; @@ -64,33 +68,43 @@ struct SPGroupClass { SPLPEItemClass parent_class; }; + /* * Virtual methods of SPGroup */ -class CGroup { +class CGroup : public CLPEItem { public: CGroup(SPGroup *group); virtual ~CGroup(); - virtual void onChildAdded(Inkscape::XML::Node *child); - virtual void onChildRemoved(Inkscape::XML::Node *child); + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onRelease(); + + virtual void onChildAdded(Inkscape::XML::Node* child, Inkscape::XML::Node* ref); + virtual void onRemoveChild(Inkscape::XML::Node *child); + virtual void onOrderChanged(Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref); + virtual void onUpdate(SPCtx *ctx, unsigned int flags); virtual void onModified(guint flags); - virtual Geom::OptRect bounds(SPItem::BBoxType type, Geom::Affine const &transform); + virtual void onSet(unsigned int key, gchar const* value); + + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + + virtual Geom::OptRect onBbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype); virtual void onPrint(SPPrintContext *ctx); - virtual void onOrderChanged(Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref); - virtual gchar *getDescription(); - virtual Inkscape::DrawingItem *show (Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); - virtual void hide (unsigned int key); + virtual gchar *onDescription(); + virtual Inkscape::DrawingItem *onShow (Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); + virtual void onHide (unsigned int key); - gint getItemCount(); + virtual void onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs); -protected: - virtual void _showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags); + virtual void onUpdatePatheffect(bool write); - SPGroup *_group; +protected: + SPGroup *spgroup; }; + GType sp_group_get_type (void); void sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done = true); diff --git a/src/sp-switch.cpp b/src/sp-switch.cpp index 500e43c9c..2c98c54fc 100644 --- a/src/sp-switch.cpp +++ b/src/sp-switch.cpp @@ -30,7 +30,7 @@ static void sp_switch_init (SPSwitch *group); static SPGroupClass * parent_class; -GType CSwitch::getType (void) +GType SPSwitch::getType (void) { static GType switch_type = 0; if (!switch_type) { @@ -56,24 +56,27 @@ sp_switch_class_init (SPSwitchClass *) { parent_class = (SPGroupClass *)g_type_class_ref (SP_TYPE_GROUP); } -static void sp_switch_init (SPSwitch *group) -{ - if (group->group) - delete group->group; - - group->group = new CSwitch(group); +CSwitch::CSwitch(SPSwitch* sw) : CGroup(sw) { + this->spswitch = sw; } -CSwitch::CSwitch(SPGroup *group) : CGroup(group), _cached_item(NULL) { +CSwitch::~CSwitch() { } -CSwitch::~CSwitch() { - _releaseLastItem(_cached_item); +static void sp_switch_init (SPSwitch *sw) +{ + sw->cswitch = new CSwitch(sw); + sw->cgroup = sw->cswitch; + sw->clpeitem = sw->cswitch; + sw->citem = sw->cswitch; + sw->cobject = sw->cswitch; + + sw->_cached_item = 0; } -SPObject *CSwitch::_evaluateFirst() { +SPObject *SPSwitch::_evaluateFirst() { SPObject *first = 0; - for (SPObject *child = _group->firstChild() ; child && !first ; child = child->getNext() ) { + for (SPObject *child = this->firstChild() ; child && !first ; child = child->getNext() ) { if (SP_IS_ITEM(child) && sp_item_evaluate(SP_ITEM(child))) { first = child; } @@ -81,9 +84,9 @@ SPObject *CSwitch::_evaluateFirst() { return first; } -GSList *CSwitch::_childList(bool add_ref, SPObject::Action action) { +GSList *SPSwitch::_childList(bool add_ref, SPObject::Action action) { if ( action != SPObject::ActionGeneral ) { - return _group->childList(add_ref, action); + return this->childList(add_ref, action); } SPObject *child = _evaluateFirst(); @@ -96,28 +99,28 @@ GSList *CSwitch::_childList(bool add_ref, SPObject::Action action) { return g_slist_prepend (NULL, child); } -gchar *CSwitch::getDescription() { - gint len = getItemCount(); +gchar *CSwitch::onDescription() { + gint len = this->spgroup->getItemCount(); return g_strdup_printf( ngettext("Conditional group of %d object", "Conditional group of %d objects", len), len); } -void CSwitch::onChildAdded(Inkscape::XML::Node *) { - _reevaluate(true); +void CSwitch::onChildAdded(Inkscape::XML::Node* child, Inkscape::XML::Node* ref) { + this->spswitch->_reevaluate(true); } -void CSwitch::onChildRemoved(Inkscape::XML::Node *) { - _reevaluate(); +void CSwitch::onRemoveChild(Inkscape::XML::Node *) { + this->spswitch->_reevaluate(); } void CSwitch::onOrderChanged (Inkscape::XML::Node *, Inkscape::XML::Node *, Inkscape::XML::Node *) { - _reevaluate(); + this->spswitch->_reevaluate(); } -void CSwitch::_reevaluate(bool /*add_to_drawing*/) { +void SPSwitch::_reevaluate(bool /*add_to_drawing*/) { SPObject *evaluated_child = _evaluateFirst(); if (!evaluated_child || _cached_item == evaluated_child) { return; @@ -138,29 +141,29 @@ void CSwitch::_reevaluate(bool /*add_to_drawing*/) { } _cached_item = evaluated_child; - _release_connection = evaluated_child->connectRelease(sigc::bind(sigc::ptr_fun(&CSwitch::_releaseItem), this)); + _release_connection = evaluated_child->connectRelease(sigc::bind(sigc::ptr_fun(&SPSwitch::_releaseItem), this)); - _group->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); + this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); } -void CSwitch::_releaseItem(SPObject *obj, CSwitch *selection) +void SPSwitch::_releaseItem(SPObject *obj, SPSwitch *selection) { selection->_releaseLastItem(obj); } -void CSwitch::_releaseLastItem(SPObject *obj) +void SPSwitch::_releaseLastItem(SPObject *obj) { - if (NULL == _cached_item || _cached_item != obj) + if (NULL == this->_cached_item || this->_cached_item != obj) return; - _release_connection.disconnect(); - _cached_item = NULL; + this->_release_connection.disconnect(); + this->_cached_item = NULL; } -void CSwitch::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags) { - SPObject *evaluated_child = _evaluateFirst(); +void SPSwitch::_showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags) { + SPObject *evaluated_child = this->_evaluateFirst(); - GSList *l = _childList(false, SPObject::ActionShow); + GSList *l = this->_childList(false, SPObject::ActionShow); while (l) { SPObject *o = SP_OBJECT (l->data); if (SP_IS_ITEM (o)) { diff --git a/src/sp-switch.h b/src/sp-switch.h index c2c98e3b3..6e8250c5e 100644 --- a/src/sp-switch.h +++ b/src/sp-switch.h @@ -17,48 +17,56 @@ #include #include -#define SP_TYPE_SWITCH (CSwitch::getType()) +#define SP_TYPE_SWITCH (SPSwitch::getType()) #define SP_SWITCH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_SWITCH, SPSwitch)) #define SP_SWITCH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_SWITCH, SPSwitchClass)) #define SP_IS_SWITCH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_SWITCH)) #define SP_IS_SWITCH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_SWITCH)) -/* - * Virtual methods of SPSwitch - */ -class CSwitch : public CGroup { +class CSwitch; + +class SPSwitch : public SPGroup { public: - CSwitch(SPGroup *group); - virtual ~CSwitch(); + CSwitch* cswitch; - friend class SPSwitch; + static GType getType(); - static GType getType(); - - virtual void onChildAdded(Inkscape::XML::Node *child); - virtual void onChildRemoved(Inkscape::XML::Node *child); - virtual void onOrderChanged(Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref); - virtual gchar *getDescription(); + void resetChildEvaluated() { _reevaluate(); } + + GSList *_childList(bool add_ref, SPObject::Action action); + void _showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags); -protected: - virtual GSList *_childList(bool add_ref, SPObject::Action action); - virtual void _showChildren (Inkscape::Drawing &drawing, Inkscape::DrawingItem *ai, unsigned int key, unsigned int flags); - SPObject *_evaluateFirst(); void _reevaluate(bool add_to_arena = false); - static void _releaseItem(SPObject *obj, CSwitch *selection); + static void _releaseItem(SPObject *obj, SPSwitch *selection); void _releaseLastItem(SPObject *obj); -private: SPObject *_cached_item; sigc::connection _release_connection; }; -struct SPSwitch : public SPGroup { - void resetChildEvaluated() { (static_cast(group))->_reevaluate(); } +struct SPSwitchClass : public SPGroupClass { }; -struct SPSwitchClass : public SPGroupClass { + +/* + * Virtual methods of SPSwitch + */ +class CSwitch : public CGroup { +public: + CSwitch(SPSwitch *sw); + virtual ~CSwitch(); + + friend class SPSwitch; + + virtual void onChildAdded(Inkscape::XML::Node* child, Inkscape::XML::Node* ref); + virtual void onRemoveChild(Inkscape::XML::Node *child); + virtual void onOrderChanged(Inkscape::XML::Node *child, Inkscape::XML::Node *old_ref, Inkscape::XML::Node *new_ref); + virtual gchar *onDescription(); + +protected: + SPSwitch* spswitch; }; + #endif -- cgit v1.2.3 From 1e6fcfc8481cc23d3bddf3d3a7e6dd96ed2724c1 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 01:57:40 +0200 Subject: Added "virtual pad" to SPAnchor. (bzr r11608.1.17) --- src/sp-anchor.cpp | 93 +++++++++++++++++++++++++++++++++++++++---------------- src/sp-anchor.h | 26 +++++++++++++++- 2 files changed, 91 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/sp-anchor.cpp b/src/sp-anchor.cpp index 517512eb2..b6cfd6f52 100644 --- a/src/sp-anchor.cpp +++ b/src/sp-anchor.cpp @@ -77,16 +77,28 @@ static void sp_anchor_class_init(SPAnchorClass *ac) item_class->event = sp_anchor_event; } +CAnchor::CAnchor(SPAnchor* anchor) : CGroup(anchor) { + this->spanchor = anchor; +} + +CAnchor::~CAnchor() { +} + static void sp_anchor_init(SPAnchor *anchor) { + anchor->canchor = new CAnchor(anchor); + anchor->cgroup = anchor->canchor; + anchor->clpeitem = anchor->canchor; + anchor->citem = anchor->canchor; + anchor->cobject = anchor->canchor; + anchor->href = NULL; } -static void sp_anchor_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ - if (((SPObjectClass *) (parent_class))->build) { - ((SPObjectClass *) (parent_class))->build(object, document, repr); - } +void CAnchor::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPAnchor* object = this->spanchor; + + CGroup::onBuild(document, repr); object->readAttr( "xlink:type" ); object->readAttr( "xlink:role" ); @@ -98,23 +110,32 @@ static void sp_anchor_build(SPObject *object, SPDocument *document, Inkscape::XM object->readAttr( "target" ); } -static void sp_anchor_release(SPObject *object) +// CPPIFY: remove +static void sp_anchor_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - SPAnchor *anchor = SP_ANCHOR(object); + ((SPAnchor*)object)->canchor->onBuild(document, repr); +} + +void CAnchor::onRelease() { + SPAnchor *anchor = this->spanchor; if (anchor->href) { g_free(anchor->href); anchor->href = NULL; } - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release(object); - } + CGroup::onRelease(); } -static void sp_anchor_set(SPObject *object, unsigned int key, const gchar *value) +// CPPIFY: remove +static void sp_anchor_release(SPObject *object) { - SPAnchor *anchor = SP_ANCHOR(object); + ((SPAnchor*)object)->canchor->onRelease(); +} + +void CAnchor::onSet(unsigned int key, const gchar* value) { + SPAnchor *anchor = this->spanchor; + SPAnchor* object = anchor; switch (key) { case SP_ATTR_XLINK_HREF: @@ -132,19 +153,22 @@ static void sp_anchor_set(SPObject *object, unsigned int key, const gchar *value object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) (parent_class))->set) { - ((SPObjectClass *) (parent_class))->set(object, key, value); - } + CGroup::onSet(key, value); break; } } +// CPPIFY: remove +static void sp_anchor_set(SPObject *object, unsigned int key, const gchar *value) +{ + ((SPAnchor*)object)->canchor->onSet(key, 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* CAnchor::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPAnchor *anchor = this->spanchor; + SPAnchor* object = anchor; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:a"); @@ -164,16 +188,20 @@ static Inkscape::XML::Node *sp_anchor_write(SPObject *object, Inkscape::XML::Doc COPY_ATTR(repr, object->getRepr(), "target"); } - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); - } + CGroup::onWrite(xml_doc, repr, flags); return repr; } -static gchar *sp_anchor_description(SPItem *item) +// CPPIFY: remove +static Inkscape::XML::Node *sp_anchor_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPAnchor *anchor = SP_ANCHOR(item); + return ((SPAnchor*)object)->canchor->onWrite(xml_doc, repr, flags); +} + +gchar* CAnchor::onDescription() { + SPAnchor *anchor = this->spanchor; + if (anchor->href) { char *quoted_href = xml_quote_strdup(anchor->href); char *ret = g_strdup_printf(_("Link to %s"), quoted_href); @@ -184,11 +212,14 @@ 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) +// CPPIFY: remove +static gchar *sp_anchor_description(SPItem *item) { - SPAnchor *anchor = SP_ANCHOR(item); + return ((SPAnchor*)item)->canchor->onDescription(); +} + +gint CAnchor::onEvent(SPEvent* event) { + SPAnchor *anchor = this->spanchor; switch (event->type) { case SP_EVENT_ACTIVATE: @@ -210,6 +241,14 @@ static gint sp_anchor_event(SPItem *item, SPEvent *event) return FALSE; } +/* fixme: We should forward event to appropriate container/view */ + +// CPPIFY: remove +static gint sp_anchor_event(SPItem *item, SPEvent *event) +{ + return ((SPAnchor*)item)->canchor->onEvent(event); +} + /* Local Variables: mode:c++ diff --git a/src/sp-anchor.h b/src/sp-anchor.h index 3c6481d94..48851b720 100644 --- a/src/sp-anchor.h +++ b/src/sp-anchor.h @@ -21,7 +21,12 @@ #define SP_IS_ANCHOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_ANCHOR)) #define SP_IS_ANCHOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_ANCHOR)) -struct SPAnchor : public SPGroup { +class CAnchor; + +class SPAnchor : public SPGroup { +public: + CAnchor* canchor; + gchar *href; }; @@ -29,6 +34,25 @@ struct SPAnchorClass { SPGroupClass parent_class; }; + +class CAnchor : public CGroup { +public: + CAnchor(SPAnchor* anchor); + virtual ~CAnchor(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onRelease(); + virtual void onSet(unsigned int key, gchar const* value); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + + virtual gchar* onDescription(); + virtual gint onEvent(SPEvent *event); + +protected: + SPAnchor* spanchor; +}; + + GType sp_anchor_get_type (void); #endif -- cgit v1.2.3 From bd1508b710ed55f5fa212a54291dd6ce1ff4f13e Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 02:13:08 +0200 Subject: Added "virtual pad" to SPBox3D. (bzr r11608.1.18) --- src/box3d.cpp | 131 +++++++++++++++++++++++++++++++++++++++++----------------- src/box3d.h | 24 +++++++++++ 2 files changed, 116 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/box3d.cpp b/src/box3d.cpp index 23f934b64..de1acdc7e 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -101,18 +101,30 @@ box3d_class_init(SPBox3DClass *klass) item_class->convert_to_guides = box3d_convert_to_guides; } +CBox3D::CBox3D(SPBox3D* box) : CGroup(box) { + this->spbox3d = box; +} + +CBox3D::~CBox3D() { +} + static void box3d_init(SPBox3D *box) { + box->cbox3d = new CBox3D(box); + box->cgroup = box->cbox3d; + box->clpeitem = box->cbox3d; + box->citem = box->cbox3d; + box->cobject = box->cbox3d; + box->persp_href = NULL; box->persp_ref = new Persp3DReference(box); } -static void box3d_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ - if (((SPObjectClass *) (parent_class))->build) { - ((SPObjectClass *) (parent_class))->build(object, document, repr); - } +void CBox3D::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPBox3D* object = this->spbox3d; + + CGroup::onBuild(document, repr); SPBox3D *box = SP_BOX3D (object); box->my_counter = counter++; @@ -134,13 +146,15 @@ static void box3d_build(SPObject *object, SPDocument *document, Inkscape::XML::N } } -/** - * Virtual release of SPBox3D members before destruction. - */ -static void -box3d_release(SPObject *object) +// CPPIFY: remove +static void box3d_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - SPBox3D *box = (SPBox3D *) object; + ((SPBox3D*)object)->cbox3d->onBuild(document, repr); +} + +void CBox3D::onRelease() { + SPBox3D* object = this->spbox3d; + SPBox3D *box = object; if (box->persp_href) { g_free(box->persp_href); @@ -173,14 +187,22 @@ box3d_release(SPObject *object) */ } - if (((SPObjectClass *) parent_class)->release) - ((SPObjectClass *) parent_class)->release(object); + CGroup::onRelease(); } +// CPPIFY: remove +/** + * Virtual release of SPBox3D members before destruction. + */ static void -box3d_set(SPObject *object, unsigned int key, const gchar *value) +box3d_release(SPObject *object) { - SPBox3D *box = SP_BOX3D(object); + ((SPBox3D*)object)->cbox3d->onRelease(); +} + +void CBox3D::onSet(unsigned int key, const gchar* value) { + SPBox3D* object = this->spbox3d; + SPBox3D *box = object; switch (key) { case SP_ATTR_INKSCAPE_BOX3D_PERSPECTIVE_ID: @@ -225,13 +247,18 @@ box3d_set(SPObject *object, unsigned int key, const gchar *value) } break; default: - if (((SPObjectClass *) (parent_class))->set) { - ((SPObjectClass *) (parent_class))->set(object, key, value); - } + CGroup::onSet(key, value); break; } } +// CPPIFY: remove +static void +box3d_set(SPObject *object, unsigned int key, const gchar *value) +{ + ((SPBox3D*)object)->cbox3d->onSet(key, value); +} + /** * Gets called when (re)attached to another perspective. */ @@ -248,9 +275,7 @@ box3d_ref_changed(SPObject *old_ref, SPObject *ref, SPBox3D *box) } } -static void -box3d_update(SPObject *object, SPCtx *ctx, guint flags) -{ +void CBox3D::onUpdate(SPCtx *ctx, guint flags) { if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { /* FIXME?: Perhaps the display updates of box sides should be instantiated from here, but this @@ -260,14 +285,19 @@ box3d_update(SPObject *object, SPCtx *ctx, guint flags) } // Invoke parent method - if (((SPObjectClass *) (parent_class))->update) - ((SPObjectClass *) (parent_class))->update(object, ctx, flags); + CGroup::onUpdate(ctx, flags); } - -static Inkscape::XML::Node * box3d_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +// CPPIFY: remove +static void +box3d_update(SPObject *object, SPCtx *ctx, guint flags) { - SPBox3D *box = SP_BOX3D(object); + ((SPBox3D*)object)->cbox3d->onUpdate(ctx, flags); +} + +Inkscape::XML::Node* CBox3D::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPBox3D* object = this->spbox3d; + SPBox3D *box = object; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { // this is where we end up when saving as plain SVG (also in other circumstances?) @@ -307,19 +337,29 @@ static Inkscape::XML::Node * box3d_write(SPObject *object, Inkscape::XML::Docume box->save_corner7 = box->orig_corner7; } - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); - } + CGroup::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +static Inkscape::XML::Node * box3d_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPBox3D*)object)->cbox3d->onWrite(xml_doc, repr, flags); +} + +gchar* CBox3D::onDescription() { + SPBox3D* item = this->spbox3d; + + g_return_val_if_fail(SP_IS_BOX3D(item), NULL); + return g_strdup(_("3D Box")); +} + +// CPPIFY: remove static gchar * box3d_description(SPItem *item) { - g_return_val_if_fail(SP_IS_BOX3D(item), NULL); - - return g_strdup(_("3D Box")); + return ((SPBox3D*)item)->cbox3d->onDescription(); } void box3d_position_set(SPBox3D *box) @@ -333,10 +373,9 @@ void box3d_position_set(SPBox3D *box) } } -static Geom::Affine -box3d_set_transform(SPItem *item, Geom::Affine const &xform) -{ - SPBox3D *box = SP_BOX3D(item); +Geom::Affine CBox3D::onSetTransform(Geom::Affine const &xform) { + SPBox3D* item = this->spbox3d; + SPBox3D *box = item; // We don't apply the transform to the box directly but instead to its perspective (which is // done in sp_selection_apply_affine). Here we only adjust strokes, patterns, etc. @@ -366,6 +405,13 @@ box3d_set_transform(SPItem *item, Geom::Affine const &xform) return Geom::identity(); } +// CPPIFY: remove +static Geom::Affine +box3d_set_transform(SPItem *item, Geom::Affine const &xform) +{ + return ((SPBox3D*)item)->cbox3d->onSetTransform(xform); +} + Proj::Pt3 box3d_get_proj_corner (guint id, Proj::Pt3 const &c0, Proj::Pt3 const &c7) { return Proj::Pt3 ((id & Box3D::X) ? c7[Proj::X] : c0[Proj::X], @@ -1392,9 +1438,10 @@ box3d_push_back_corner_pair(SPBox3D *box, std::listspbox3d; + SPBox3D *box = item; + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (!prefs->getBool("/tools/shapes/3dbox/convertguides", true)) { @@ -1425,6 +1472,12 @@ box3d_convert_to_guides(SPItem *item) { sp_guide_pt_pairs_to_guides(item->document, pts); } +// CPPIFY: remove +void +box3d_convert_to_guides(SPItem *item) { + ((SPBox3D*)item)->cbox3d->onConvertToGuides(); +} + /* Local Variables: mode:c++ diff --git a/src/box3d.h b/src/box3d.h index 5dbf0cf5e..939dd7bc9 100644 --- a/src/box3d.h +++ b/src/box3d.h @@ -29,9 +29,12 @@ class Box3DSide; class Persp3D; class Persp3DReference; +class CBox3D; class SPBox3D : public SPGroup { public: + CBox3D* cbox3d; + gint z_orders[6]; // z_orders[i] holds the ID of the face at position #i in the group (from top to bottom) gchar *persp_href; @@ -58,6 +61,27 @@ public: SPGroupClass parent_class; }; + +class CBox3D : public CGroup { +public: + CBox3D(SPBox3D* box3d); + virtual ~CBox3D(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onRelease(); + virtual void onSet(unsigned int key, gchar const* value); + virtual void onUpdate(SPCtx *ctx, guint flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + + virtual gchar *onDescription(); + virtual Geom::Affine onSetTransform(Geom::Affine const &transform); + virtual void onConvertToGuides(); + +protected: + SPBox3D* spbox3d; +}; + + GType box3d_get_type (void); void box3d_position_set (SPBox3D *box); -- cgit v1.2.3 From 0251afb68398f00dbd4236a695d519e6c0d2e7a6 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 02:28:40 +0200 Subject: Added "virtual pad" to SPMarker. (bzr r11608.1.19) --- src/marker.cpp | 160 +++++++++++++++++++++++++++++++++++++++------------------ src/marker.h | 30 ++++++++++- 2 files changed, 139 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/marker.cpp b/src/marker.cpp index a5681e180..58cd8ea7c 100644 --- a/src/marker.cpp +++ b/src/marker.cpp @@ -98,6 +98,13 @@ static void sp_marker_class_init(SPMarkerClass *klass) sp_item_class->print = sp_marker_print; } +CMarker::CMarker(SPMarker* marker) : CGroup(marker) { + this->spmarker = marker; +} + +CMarker::~CMarker() { +} + /** * Initializes an SPMarker object. This notes the marker's viewBox is * not set and initializes the marker's c2p identity matrix. @@ -105,11 +112,33 @@ static void sp_marker_class_init(SPMarkerClass *klass) static void sp_marker_init (SPMarker *marker) { + marker->cmarker = new CMarker(marker); + marker->cgroup = marker->cmarker; + marker->clpeitem = marker->cmarker; + marker->citem = marker->cmarker; + marker->cobject = marker->cmarker; + marker->viewBox = Geom::OptRect(); marker->c2p.setIdentity(); marker->views = NULL; } +void CMarker::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPMarker* object = this->spmarker; + + object->readAttr( "markerUnits" ); + object->readAttr( "refX" ); + object->readAttr( "refY" ); + object->readAttr( "markerWidth" ); + object->readAttr( "markerHeight" ); + object->readAttr( "orient" ); + object->readAttr( "viewBox" ); + object->readAttr( "preserveAspectRatio" ); + + CGroup::onBuild(document, repr); +} + +// CPPIFY: remove /** * Virtual build callback for SPMarker. * @@ -122,20 +151,25 @@ sp_marker_init (SPMarker *marker) */ static void sp_marker_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - object->readAttr( "markerUnits" ); - object->readAttr( "refX" ); - object->readAttr( "refY" ); - object->readAttr( "markerWidth" ); - object->readAttr( "markerHeight" ); - object->readAttr( "orient" ); - object->readAttr( "viewBox" ); - object->readAttr( "preserveAspectRatio" ); + ((SPMarker*)object)->cmarker->onBuild(document, repr); +} + +void CMarker::onRelease() { + SPMarker* object = this->spmarker; - if (reinterpret_cast(parent_class)->build) { - reinterpret_cast(parent_class)->build(object, document, repr); + SPMarker *marker = reinterpret_cast(object); + + while (marker->views) { + // Destroy all DrawingItems etc. + // Parent class ::hide method + reinterpret_cast(parent_class)->hide(marker, marker->views->key); + sp_marker_view_remove (marker, marker->views, TRUE); } + + CGroup::onRelease(); } +// CPPIFY: remove /** * Removes, releases and unrefs all children of object * @@ -150,35 +184,12 @@ static void sp_marker_build(SPObject *object, SPDocument *document, Inkscape::XM */ static void sp_marker_release(SPObject *object) { - SPMarker *marker = reinterpret_cast(object); - - while (marker->views) { - // Destroy all DrawingItems etc. - // Parent class ::hide method - reinterpret_cast(parent_class)->hide(marker, marker->views->key); - sp_marker_view_remove (marker, marker->views, TRUE); - } - - if (reinterpret_cast(parent_class)->release) { - reinterpret_cast(parent_class)->release(object); - } + ((SPMarker*)object)->cmarker->onRelease(); } -/** - * Sets an attribute, 'key', of a marker object to 'value'. Supported - * attributes that can be set with this routine include: - * - * SP_ATTR_MARKERUNITS - * SP_ATTR_REFX - * SP_ATTR_REFY - * SP_ATTR_MARKERWIDTH - * SP_ATTR_MARKERHEIGHT - * SP_ATTR_ORIENT - * SP_ATTR_VIEWBOX - * SP_ATTR_PRESERVEASPECTRATIO - */ -static void sp_marker_set(SPObject *object, unsigned int key, const gchar *value) -{ +void CMarker::onSet(unsigned int key, const gchar* value) { + SPMarker* object = this->spmarker; + SPMarker *marker = SP_MARKER(object); switch (key) { @@ -310,18 +321,33 @@ static void sp_marker_set(SPObject *object, unsigned int key, const gchar *value } break; default: - if (((SPObjectClass *) parent_class)->set) - ((SPObjectClass *) parent_class)->set (object, key, value); + CGroup::onSet(key, value); break; } } +// CPPIFY: remove /** - * Updates when its attributes have changed. Takes care of setting up - * transformations and viewBoxes. + * Sets an attribute, 'key', of a marker object to 'value'. Supported + * attributes that can be set with this routine include: + * + * SP_ATTR_MARKERUNITS + * SP_ATTR_REFX + * SP_ATTR_REFY + * SP_ATTR_MARKERWIDTH + * SP_ATTR_MARKERHEIGHT + * SP_ATTR_ORIENT + * SP_ATTR_VIEWBOX + * SP_ATTR_PRESERVEASPECTRATIO */ -static void sp_marker_update(SPObject *object, SPCtx *ctx, guint flags) +static void sp_marker_set(SPObject *object, unsigned int key, const gchar *value) { + ((SPMarker*)object)->cmarker->onSet(key, value); +} + +void CMarker::onUpdate(SPCtx *ctx, guint flags) { + SPMarker* object = this->spmarker; + SPMarker *marker = SP_MARKER(object); SPItemCtx rctx; @@ -429,9 +455,7 @@ static void sp_marker_update(SPObject *object, SPCtx *ctx, guint flags) } // And invoke parent method - if (((SPObjectClass *) (parent_class))->update) { - ((SPObjectClass *) (parent_class))->update (object, (SPCtx *) &rctx, flags); - } + CGroup::onUpdate((SPCtx *) &rctx, flags); // As last step set additional transform of drawing group for (SPMarkerView *v = marker->views; v != NULL; v = v->next) { @@ -444,12 +468,19 @@ static void sp_marker_update(SPObject *object, SPCtx *ctx, guint flags) } } +// CPPIFY: remove /** - * Writes the object's properties into its repr object. + * Updates when its attributes have changed. Takes care of setting up + * transformations and viewBoxes. */ -static Inkscape::XML::Node * -sp_marker_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void sp_marker_update(SPObject *object, SPCtx *ctx, guint flags) { + ((SPMarker*)object)->cmarker->onUpdate(ctx, flags); +} + +Inkscape::XML::Node* CMarker::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPMarker* object = this->spmarker; + SPMarker *marker; marker = SP_MARKER (object); @@ -502,12 +533,26 @@ sp_marker_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::X //XML Tree being used directly here while it shouldn't be.... repr->setAttribute("preserveAspectRatio", object->getRepr()->attribute("preserveAspectRatio")); - if (((SPObjectClass *) (parent_class))->write) - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags); + CGroup::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +/** + * Writes the object's properties into its repr object. + */ +static Inkscape::XML::Node * +sp_marker_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPMarker*)object)->cmarker->onWrite(xml_doc, repr, flags); +} + +Inkscape::DrawingItem* CMarker::onShow(Inkscape::Drawing &/*drawing*/, unsigned int /*key*/, unsigned int /*flags*/) { + return 0; +} + +// CPPIFY: remove /** * This routine is disabled to break propagation. */ @@ -518,6 +563,11 @@ sp_marker_private_show (SPItem */*item*/, Inkscape::Drawing &/*drawing*/, unsign return NULL; } +void CMarker::onHide(unsigned int key) { + +} + +// CPPIFY: remove /** * This routine is disabled to break propagation. */ @@ -527,6 +577,11 @@ sp_marker_private_hide (SPItem */*item*/, unsigned int /*key*/) /* Break propagation */ } +Geom::OptRect CMarker::onBbox(Geom::Affine const &transform, SPItem::BBoxType type) { + return Geom::OptRect(); +} + +// CPPIFY: remove /** * This routine is disabled to break propagation. */ @@ -537,6 +592,11 @@ sp_marker_bbox(SPItem const *, Geom::Affine const &, SPItem::BBoxType) return Geom::OptRect(); } +void CMarker::onPrint(SPPrintContext* ctx) { + +} + +// CPPIFY: remove /** * This routine is disabled to break propagation. */ diff --git a/src/marker.h b/src/marker.h index 6fdb82aa3..5c409b4d3 100644 --- a/src/marker.h +++ b/src/marker.h @@ -25,6 +25,7 @@ class SPMarker; class SPMarkerClass; class SPMarkerView; +class CMarker; #include <2geom/rect.h> #include <2geom/affine.h> @@ -34,7 +35,10 @@ class SPMarkerView; #include "sp-marker-loc.h" #include "uri-references.h" -struct SPMarker : public SPGroup { +class SPMarker : public SPGroup { +public: + CMarker* cmarker; + /* units */ unsigned int markerUnits_set : 1; unsigned int markerUnits : 1; @@ -71,6 +75,30 @@ struct SPMarkerClass { SPGroupClass parent_class; }; + +class CMarker : public CGroup { +public: + CMarker(SPMarker* marker); + virtual ~CMarker(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onRelease(); + virtual void onSet(unsigned int key, gchar const* value); + virtual void onUpdate(SPCtx *ctx, guint flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + + virtual Inkscape::DrawingItem* onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); + virtual void onHide(unsigned int key); + + virtual Geom::OptRect onBbox(Geom::Affine const &transform, SPItem::BBoxType type); + virtual void onPrint(SPPrintContext *ctx); + +protected: + SPMarker* spmarker; +}; + + + GType sp_marker_get_type (void); class SPMarkerReference : public Inkscape::URIReference { -- cgit v1.2.3 From 578d85febc1afde9024c335ae9d88358b82e40a1 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 02:54:53 +0200 Subject: Added "virtual pad" to SPRoot. (bzr r11608.1.20) --- src/sp-root.cpp | 188 ++++++++++++++++++++++++++++++++++++++------------------ src/sp-root.h | 30 ++++++++- 2 files changed, 157 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/sp-root.cpp b/src/sp-root.cpp index 393c70895..2b1ab3884 100644 --- a/src/sp-root.cpp +++ b/src/sp-root.cpp @@ -96,11 +96,24 @@ static void sp_root_class_init(SPRootClass *klass) sp_item_class->print = sp_root_print; } +CRoot::CRoot(SPRoot* root) : CGroup(root) { + this->sproot = root; +} + +CRoot::~CRoot() { +} + /** * Initializes an SPRoot object by setting its default parameter values. */ static void sp_root_init(SPRoot *root) { + root->croot = new CRoot(root); + root->cgroup = root->croot; + root->clpeitem = root->croot; + root->citem = root->croot; + root->cobject = root->croot; + static Inkscape::Version const zero_version(0, 0); sp_version_from_string(SVG_VERSION, &root->original.svg); @@ -121,13 +134,9 @@ static void sp_root_init(SPRoot *root) root->defs = NULL; } -/** - * Fills in the data for an SPObject from its Inkscape::XML::Node object. - * It fills in data such as version, x, y, width, height, etc. - * It then calls the object's parent class object's build function. - */ -static void sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ +void CRoot::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPRoot* object = this->sproot; + SPGroup *group = (SPGroup *) object; SPRoot *root = (SPRoot *) object; @@ -147,8 +156,7 @@ static void sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML: object->readAttr( "preserveAspectRatio" ); object->readAttr( "onload" ); - if (((SPObjectClass *) parent_class)->build) - (* ((SPObjectClass *) parent_class)->build) (object, document, repr); + CGroup::onBuild(document, repr); // Search for first node for (SPObject *o = group->firstChild() ; o ; o = o->getNext() ) { @@ -162,25 +170,39 @@ static void sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML: SP_ITEM(object)->transform = Geom::identity(); } +// CPPIFY: remove /** - * This is a destructor routine for SPRoot objects. It de-references any \ items and calls - * the parent class destructor. + * Fills in the data for an SPObject from its Inkscape::XML::Node object. + * It fills in data such as version, x, y, width, height, etc. + * It then calls the object's parent class object's build function. */ -static void sp_root_release(SPObject *object) +static void sp_root_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { + ((SPRoot*)object)->croot->onBuild(document, repr); +} + +void CRoot::onRelease() { + SPRoot* object = this->sproot; + SPRoot *root = (SPRoot *) object; root->defs = NULL; - if (((SPObjectClass *) parent_class)->release) - ((SPObjectClass *) parent_class)->release(object); + CGroup::onRelease(); } +// CPPIFY: remove /** - * Sets the attribute given by key for SPRoot objects to the value specified by value. + * This is a destructor routine for SPRoot objects. It de-references any \ items and calls + * the parent class destructor. */ -static void sp_root_set(SPObject *object, unsigned int key, gchar const *value) +static void sp_root_release(SPObject *object) { - SPRoot *root = SP_ROOT(object); + ((SPRoot*)object)->croot->onRelease(); +} + +void CRoot::onSet(unsigned int key, const gchar* value) { + SPRoot* object = this->sproot; + SPRoot *root = object; switch (key) { case SP_ATTR_VERSION: @@ -315,25 +337,27 @@ static void sp_root_set(SPObject *object, unsigned int key, gchar const *value) break; default: /* Pass the set event to the parent */ - if (((SPObjectClass *) parent_class)->set) { - ((SPObjectClass *) parent_class)->set(object, key, value); - } + CGroup::onSet(key, value); break; } } +// CPPIFY: remove /** - * This routine is for adding a child SVG object to an SPRoot object. - * The SPRoot object is taken to be an SPGroup. + * Sets the attribute given by key for SPRoot objects to the value specified by value. */ -static void sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) +static void sp_root_set(SPObject *object, unsigned int key, gchar const *value) { + ((SPRoot*)object)->croot->onSet(key, value); +} + +void CRoot::onChildAdded(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { + SPRoot* object = this->sproot; + SPRoot *root = (SPRoot *) object; SPGroup *group = (SPGroup *) object; - if (((SPObjectClass *) (parent_class))->child_added) { - (* ((SPObjectClass *) (parent_class))->child_added)(object, child, ref); - } + CGroup::onChildAdded(child, ref); SPObject *co = object->document->getObjectByRepr(child); g_assert (co != NULL || !strcmp("comment", child->name())); // comment repr node has no object @@ -349,11 +373,19 @@ static void sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, In } } +// CPPIFY: remove /** - * Removes the given child from this SPRoot object. + * This routine is for adding a child SVG object to an SPRoot object. + * The SPRoot object is taken to be an SPGroup. */ -static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child) +static void sp_root_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { + ((SPRoot*)object)->croot->onChildAdded(child, ref); +} + +void CRoot::onRemoveChild(Inkscape::XML::Node* child) { + SPRoot* object = this->sproot; + SPRoot *root = (SPRoot *) object; if ( root->defs && (root->defs->getRepr() == child) ) { @@ -371,16 +403,21 @@ static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child) } } - if (((SPObjectClass *) (parent_class))->remove_child) { - (* ((SPObjectClass *) (parent_class))->remove_child)(object, child); - } + CGroup::onRemoveChild(child); } +// CPPIFY: remove /** - * This callback routine updates the SPRoot object when its attributes have been changed. + * Removes the given child from this SPRoot object. */ -static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags) +static void sp_root_remove_child(SPObject *object, Inkscape::XML::Node *child) { + ((SPRoot*)object)->croot->onRemoveChild(child); +} + +void CRoot::onUpdate(SPCtx *ctx, guint flags) { + SPRoot* object = this->sproot; + SPRoot *root = SP_ROOT(object); SPItemCtx *ictx = (SPItemCtx *) ctx; @@ -508,8 +545,7 @@ static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags) rctx.i2vp = Geom::identity(); /* And invoke parent method */ - if (((SPObjectClass *) (parent_class))->update) - ((SPObjectClass *) (parent_class))->update(object, (SPCtx *) &rctx, flags); + CGroup::onUpdate((SPCtx *) &rctx, flags); /* As last step set additional transform of drawing group */ for (SPItemView *v = root->display; v != NULL; v = v->next) { @@ -518,17 +554,21 @@ static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags) } } +// CPPIFY: remove /** - * Calls the modified routine of the SPRoot object's parent class. - * Also, if the viewport has been modified, it sets the document size to the new - * height and width. + * This callback routine updates the SPRoot object when its attributes have been changed. */ -static void sp_root_modified(SPObject *object, guint flags) +static void sp_root_update(SPObject *object, SPCtx *ctx, guint flags) { + ((SPRoot*)object)->croot->onUpdate(ctx, flags); +} + +void CRoot::onModified(unsigned int flags) { + SPRoot* object = this->sproot; + SPRoot *root = SP_ROOT(object); - if (((SPObjectClass *) (parent_class))->modified) - (* ((SPObjectClass *) (parent_class))->modified)(object, flags); + CGroup::onModified(flags); /* fixme: (Lauris) */ if (!object->parent && (flags & SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { @@ -536,12 +576,20 @@ static void sp_root_modified(SPObject *object, guint flags) } } +// CPPIFY: remove /** - * Writes the object into the repr object, then calls the parent's write routine. + * Calls the modified routine of the SPRoot object's parent class. + * Also, if the viewport has been modified, it sets the document size to the new + * height and width. */ -static Inkscape::XML::Node * -sp_root_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void sp_root_modified(SPObject *object, guint flags) { + ((SPRoot*)object)->croot->onModified(flags); +} + +Inkscape::XML::Node* CRoot::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPRoot* object = this->sproot; + SPRoot *root = SP_ROOT(object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { @@ -576,39 +624,51 @@ sp_root_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML: repr->setAttribute("viewBox", os.str().c_str()); } - if (((SPObjectClass *) (parent_class))->write) - ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); + CGroup::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove /** - * Displays the SPRoot item on the drawing. + * Writes the object into the repr object, then calls the parent's write routine. */ -static Inkscape::DrawingItem * -sp_root_show(SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) +static Inkscape::XML::Node * +sp_root_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + return ((SPRoot*)object)->croot->onWrite(xml_doc, repr, flags); +} + +Inkscape::DrawingItem* CRoot::onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + SPRoot* item = this->sproot; + SPRoot *root = SP_ROOT(item); - Inkscape::DrawingItem *ai; - if (((SPItemClass *) (parent_class))->show) { - ai = ((SPItemClass *) (parent_class))->show(item, drawing, key, flags); - if (ai) { - Inkscape::DrawingGroup *g = dynamic_cast(ai); - g->setChildTransform(root->c2p); - } - } else { - ai = NULL; + Inkscape::DrawingItem *ai = 0; + + ai = CGroup::onShow(drawing, key, flags); + + if (ai) { + Inkscape::DrawingGroup *g = dynamic_cast(ai); + g->setChildTransform(root->c2p); } return ai; } +// CPPIFY: remove /** - * Virtual print callback. + * Displays the SPRoot item on the drawing. */ -static void sp_root_print(SPItem *item, SPPrintContext *ctx) +static Inkscape::DrawingItem * +sp_root_show(SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + return ((SPRoot*)item)->croot->onShow(drawing, key, flags); +} + +void CRoot::onPrint(SPPrintContext* ctx) { + SPRoot* item = this->sproot; + SPRoot *root = SP_ROOT(item); sp_print_bind(ctx, root->c2p, 1.0); @@ -620,6 +680,14 @@ static void sp_root_print(SPItem *item, SPPrintContext *ctx) sp_print_release(ctx); } +// CPPIFY: remove +/** + * Virtual print callback. + */ +static void sp_root_print(SPItem *item, SPPrintContext *ctx) +{ + ((SPRoot*)item)->croot->onPrint(ctx); +} /* Local Variables: diff --git a/src/sp-root.h b/src/sp-root.h index e2bad917b..f489cc83e 100644 --- a/src/sp-root.h +++ b/src/sp-root.h @@ -26,9 +26,13 @@ #define SP_IS_ROOT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), SP_TYPE_ROOT)) class SPDefs; +class CRoot; /** \ element */ -struct SPRoot : public SPGroup { +class SPRoot : public SPGroup { +public: + CRoot* croot; + struct { Inkscape::Version svg; Inkscape::Version inkscape; @@ -66,6 +70,30 @@ struct SPRootClass { SPGroupClass parent_class; }; + +class CRoot : public CGroup { +public: + CRoot(SPRoot* root); + virtual ~CRoot(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onRelease(); + virtual void onSet(unsigned int key, gchar const* value); + virtual void onUpdate(SPCtx *ctx, guint flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + + virtual void onModified(unsigned int flags); + virtual void onChildAdded(Inkscape::XML::Node* child, Inkscape::XML::Node* ref); + virtual void onRemoveChild(Inkscape::XML::Node* child); + + virtual Inkscape::DrawingItem* onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); + virtual void onPrint(SPPrintContext *ctx); + +protected: + SPRoot* sproot; +}; + + GType sp_root_get_type(); -- cgit v1.2.3 From 25d3298c964cd227bcf31d09539899ac0e6b9060 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 03:11:45 +0200 Subject: Added "virtual pad" to SPSymbol. (bzr r11608.1.21) --- src/sp-symbol.cpp | 168 ++++++++++++++++++++++++++++++++++++------------------ src/sp-symbol.h | 31 +++++++++- 2 files changed, 142 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/sp-symbol.cpp b/src/sp-symbol.cpp index 87cd210e4..bd8a0ea53 100644 --- a/src/sp-symbol.cpp +++ b/src/sp-symbol.cpp @@ -85,32 +85,53 @@ static void sp_symbol_class_init(SPSymbolClass *klass) sp_item_class->print = sp_symbol_print; } +CSymbol::CSymbol(SPSymbol* symbol) : CGroup(symbol) { + this->spsymbol = symbol; +} + +CSymbol::~CSymbol() { +} + static void sp_symbol_init(SPSymbol *symbol) { - symbol->viewBox_set = FALSE; + symbol->csymbol = new CSymbol(symbol); + symbol->cgroup = symbol->csymbol; + symbol->clpeitem = symbol->csymbol; + symbol->citem = symbol->csymbol; + symbol->cobject = symbol->csymbol; + symbol->viewBox_set = FALSE; symbol->c2p = Geom::identity(); } -static void sp_symbol_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ +void CSymbol::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPSymbol* object = this->spsymbol; + object->readAttr( "viewBox" ); object->readAttr( "preserveAspectRatio" ); - if (((SPObjectClass *) parent_class)->build) { - ((SPObjectClass *) parent_class)->build (object, document, repr); - } + CGroup::onBuild(document, repr); } -static void sp_symbol_release(SPObject *object) +// CPPIFY: remove +static void sp_symbol_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release (object); - } + ((SPSymbol*)object)->csymbol->onBuild(document, repr); } -static void sp_symbol_set(SPObject *object, unsigned int key, const gchar *value) +void CSymbol::onRelease() { + CGroup::onRelease(); +} + +// CPPIFY: remove +static void sp_symbol_release(SPObject *object) { + ((SPSymbol*)object)->csymbol->onRelease(); +} + +void CSymbol::onSet(unsigned int key, const gchar* value) { + SPSymbol* object = this->spsymbol; + SPSymbol *symbol = SP_SYMBOL(object); switch (key) { @@ -202,22 +223,31 @@ static void sp_symbol_set(SPObject *object, unsigned int key, const gchar *value } break; default: - if (((SPObjectClass *) parent_class)->set) - ((SPObjectClass *) parent_class)->set (object, key, value); + CGroup::onSet(key, value); break; } } -static void sp_symbol_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) +// CPPIFY: remove +static void sp_symbol_set(SPObject *object, unsigned int key, const gchar *value) { - if (((SPObjectClass *) (parent_class))->child_added) { - ((SPObjectClass *) (parent_class))->child_added (object, child, ref); - } + ((SPSymbol*)object)->csymbol->onSet(key, value); } -static void sp_symbol_update(SPObject *object, SPCtx *ctx, guint flags) +void CSymbol::onChildAdded(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { + CGroup::onChildAdded(child, ref); +} + +// CPPIFY: remove +static void sp_symbol_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { - SPSymbol *symbol = SP_SYMBOL(object); + ((SPSymbol*)object)->csymbol->onChildAdded(child, ref); +} + +void CSymbol::onUpdate(SPCtx *ctx, guint flags) { + SPSymbol* object = this->spsymbol; + SPSymbol *symbol = object; + SPItemCtx *ictx = (SPItemCtx *) ctx; SPItemCtx rctx; @@ -315,9 +345,7 @@ static void sp_symbol_update(SPObject *object, SPCtx *ctx, guint flags) } // And invoke parent method - if (((SPObjectClass *) (parent_class))->update) { - ((SPObjectClass *) (parent_class))->update (object, (SPCtx *) &rctx, flags); - } + CGroup::onUpdate((SPCtx *) &rctx, flags); // As last step set additional transform of drawing group for (SPItemView *v = symbol->display; v != NULL; v = v->next) { @@ -326,24 +354,28 @@ static void sp_symbol_update(SPObject *object, SPCtx *ctx, guint flags) } } else { // No-op - if (((SPObjectClass *) (parent_class))->update) { - ((SPObjectClass *) (parent_class))->update (object, ctx, flags); - } + CGroup::onUpdate(ctx, flags); } } -static void sp_symbol_modified(SPObject *object, guint flags) +// CPPIFY: remove +static void sp_symbol_update(SPObject *object, SPCtx *ctx, guint flags) { - SP_SYMBOL(object); + ((SPSymbol*)object)->csymbol->onUpdate(ctx, flags); +} - if (((SPObjectClass *) (parent_class))->modified) { - (* ((SPObjectClass *) (parent_class))->modified) (object, flags); - } +void CSymbol::onModified(unsigned int flags) { + CGroup::onModified(flags); } -static Inkscape::XML::Node *sp_symbol_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +// CPPIFY: remove +static void sp_symbol_modified(SPObject *object, guint flags) { - SP_SYMBOL(object); + ((SPSymbol*)object)->csymbol->onModified(flags); +} + +Inkscape::XML::Node* CSymbol::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPSymbol* object = this->spsymbol; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:symbol"); @@ -355,72 +387,96 @@ static Inkscape::XML::Node *sp_symbol_write(SPObject *object, Inkscape::XML::Doc //XML Tree being used directly here while it shouldn't be. repr->setAttribute("preserveAspectRatio", object->getRepr()->attribute("preserveAspectRatio")); - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags); - } + CGroup::onWrite(xml_doc, repr, flags); return repr; } -static Inkscape::DrawingItem *sp_symbol_show(SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) +// CPPIFY: remove +static Inkscape::XML::Node *sp_symbol_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + return ((SPSymbol*)object)->csymbol->onWrite(xml_doc, repr, flags); +} + +Inkscape::DrawingItem* CSymbol::onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + SPSymbol* item = this->spsymbol; + SPSymbol *symbol = SP_SYMBOL(item); Inkscape::DrawingItem *ai = 0; if (symbol->cloned) { // Cloned is actually renderable - if (((SPItemClass *) (parent_class))->show) { - ai = ((SPItemClass *) (parent_class))->show (item, drawing, key, flags); - Inkscape::DrawingGroup *g = dynamic_cast(ai); - if (g) { - g->setChildTransform(symbol->c2p); - } - } + ai = CGroup::onShow(drawing, key, flags); + Inkscape::DrawingGroup *g = dynamic_cast(ai); + if (g) { + g->setChildTransform(symbol->c2p); + } } return ai; } -static void sp_symbol_hide(SPItem *item, unsigned int key) +// CPPIFY: remove +static Inkscape::DrawingItem *sp_symbol_show(SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + return ((SPSymbol*)item)->csymbol->onShow(drawing, key, flags); +} + +void CSymbol::onHide(unsigned int key) { + SPSymbol* item = this->spsymbol; + SPSymbol *symbol = SP_SYMBOL(item); if (symbol->cloned) { /* Cloned is actually renderable */ - if (((SPItemClass *) (parent_class))->hide) { - ((SPItemClass *) (parent_class))->hide (item, key); - } + CGroup::onHide(key); } } -static Geom::OptRect sp_symbol_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) +// CPPIFY: remove +static void sp_symbol_hide(SPItem *item, unsigned int key) { + ((SPSymbol*)item)->csymbol->onHide(key); +} + +Geom::OptRect CSymbol::onBbox(Geom::Affine const &transform, SPItem::BBoxType type) { + SPSymbol* item = this->spsymbol; + SPSymbol const *symbol = SP_SYMBOL(item); Geom::OptRect bbox; if (symbol->cloned) { // Cloned is actually renderable + Geom::Affine const a( symbol->c2p * transform ); + bbox = CGroup::onBbox(a, type); - if (((SPItemClass *) (parent_class))->bbox) { - Geom::Affine const a( symbol->c2p * transform ); - bbox = ((SPItemClass *) (parent_class))->bbox(item, a, type); - } } return bbox; } -static void sp_symbol_print(SPItem *item, SPPrintContext *ctx) +// CPPIFY: remove +static Geom::OptRect sp_symbol_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) { + return ((SPSymbol*)item)->csymbol->onBbox(transform, type); +} + +void CSymbol::onPrint(SPPrintContext* ctx) { + SPSymbol* item = this->spsymbol; + SPSymbol *symbol = SP_SYMBOL(item); if (symbol->cloned) { // Cloned is actually renderable sp_print_bind(ctx, symbol->c2p, 1.0); - if (((SPItemClass *) (parent_class))->print) { - ((SPItemClass *) (parent_class))->print (item, ctx); - } + CGroup::onPrint(ctx); sp_print_release (ctx); } } + +// CPPIFY: remove +static void sp_symbol_print(SPItem *item, SPPrintContext *ctx) +{ + ((SPSymbol*)item)->csymbol->onPrint(ctx); +} diff --git a/src/sp-symbol.h b/src/sp-symbol.h index 59f343285..82dd3ca9f 100644 --- a/src/sp-symbol.h +++ b/src/sp-symbol.h @@ -23,13 +23,17 @@ class SPSymbol; class SPSymbolClass; +class CSymbol; #include <2geom/affine.h> #include "svg/svg-length.h" #include "enums.h" #include "sp-item-group.h" -struct SPSymbol : public SPGroup { +class SPSymbol : public SPGroup { +public: + CSymbol* csymbol; + /* viewBox; */ unsigned int viewBox_set : 1; Geom::Rect viewBox; @@ -47,6 +51,31 @@ struct SPSymbolClass { SPGroupClass parent_class; }; + +class CSymbol : public CGroup { +public: + CSymbol(SPSymbol* symbol); + virtual ~CSymbol(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onRelease(); + virtual void onSet(unsigned int key, gchar const* value); + virtual void onUpdate(SPCtx *ctx, guint flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + + virtual void onModified(unsigned int flags); + virtual void onChildAdded(Inkscape::XML::Node* child, Inkscape::XML::Node* ref); + + virtual Inkscape::DrawingItem* onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); + virtual void onPrint(SPPrintContext *ctx); + virtual Geom::OptRect onBbox(Geom::Affine const &transform, SPItem::BBoxType type); + virtual void onHide (unsigned int key); + +protected: + SPSymbol* spsymbol; +}; + + GType sp_symbol_get_type (void); #endif -- cgit v1.2.3 From 37e4ac1b79668657362806503a1a0079b534c365 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 03:18:49 +0200 Subject: As all subclasses of SPLPEItem now have "virtual pads" with correct inheritance, the virtual function call to "onUpdatePatheffect" was converted to C++ style. (bzr r11608.1.22) --- src/sp-lpe-item.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index f43e5cc07..15243c651 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -453,9 +453,7 @@ sp_lpe_item_update_patheffect (SPLPEItem *lpeitem, bool wholetree, bool write) top = lpeitem; } - if (SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (top))->update_patheffect) { - SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (top))->update_patheffect (top, write); - } + top->clpeitem->onUpdatePatheffect(write); } /** -- cgit v1.2.3 From b403c428afe0c33b95d8d0d36eac42fd01ba31fd Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 21:31:33 +0200 Subject: Added "virtual pad" to - SPFlowdiv - SPFlowtspan - SPFlowpara - SPFlowline - SPFlowregionbreak (bzr r11608.1.23) --- src/sp-flowdiv.cpp | 350 +++++++++++++++++++++++++++++++++++++---------------- src/sp-flowdiv.h | 108 ++++++++++++++++- 2 files changed, 350 insertions(+), 108 deletions(-) (limited to 'src') diff --git a/src/sp-flowdiv.cpp b/src/sp-flowdiv.cpp index 7a0c5e0b8..976746770 100644 --- a/src/sp-flowdiv.cpp +++ b/src/sp-flowdiv.cpp @@ -94,25 +94,36 @@ static void sp_flowdiv_class_init(SPFlowdivClass *klass) sp_object_class->modified = sp_flowdiv_modified; } -static void sp_flowdiv_init(SPFlowdiv */*group*/) +CFlowdiv::CFlowdiv(SPFlowdiv* flowdiv) : CItem(flowdiv) { + this->spflowdiv = flowdiv; +} + +CFlowdiv::~CFlowdiv() { +} + +static void sp_flowdiv_init(SPFlowdiv *group) { + group->cflowdiv = new CFlowdiv(group); + group->citem = group->cflowdiv; + group->cobject = group->cflowdiv; +} + +void CFlowdiv::onRelease() { + CItem::onRelease(); } +// CPPIFY: remove static void sp_flowdiv_release(SPObject *object) { - if (reinterpret_cast(flowdiv_parent_class)->release) { - reinterpret_cast(flowdiv_parent_class)->release(object); - } + ((SPFlowdiv*)object)->cflowdiv->onRelease(); } -static void sp_flowdiv_update(SPObject *object, SPCtx *ctx, unsigned int flags) -{ +void CFlowdiv::onUpdate(SPCtx *ctx, unsigned int flags) { + SPFlowdiv* object = this->spflowdiv; SPItemCtx *ictx = reinterpret_cast(ctx); SPItemCtx cctx = *ictx; - if (reinterpret_cast(flowdiv_parent_class)->update) { - reinterpret_cast(flowdiv_parent_class)->update(object, ctx, flags); - } + CItem::onUpdate(ctx, flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -142,11 +153,16 @@ static void sp_flowdiv_update(SPObject *object, SPCtx *ctx, unsigned int flags) } } -static void sp_flowdiv_modified(SPObject *object, guint flags) +// CPPIFY: remove +static void sp_flowdiv_update(SPObject *object, SPCtx *ctx, unsigned int flags) { - if (reinterpret_cast(flowdiv_parent_class)->modified) { - reinterpret_cast(flowdiv_parent_class)->modified(object, flags); - } + ((SPFlowdiv*)object)->cflowdiv->onUpdate(ctx, flags); +} + +void CFlowdiv::onModified(unsigned int flags) { + SPFlowdiv* object = this->spflowdiv; + + CItem::onModified(flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -169,24 +185,39 @@ static void sp_flowdiv_modified(SPObject *object, guint flags) } } +// CPPIFY: remove +static void sp_flowdiv_modified(SPObject *object, guint flags) +{ + ((SPFlowdiv*)object)->cflowdiv->onModified(flags); +} + +void CFlowdiv::onBuild(SPDocument *doc, Inkscape::XML::Node *repr) { + SPFlowdiv* object = this->spflowdiv; + + object->_requireSVGVersion(Inkscape::Version(1, 2)); + + CItem::onBuild(doc, repr); +} + +// CPPIFY: remove static void sp_flowdiv_build(SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr) { - object->_requireSVGVersion(Inkscape::Version(1, 2)); + ((SPFlowdiv*)object)->cflowdiv->onBuild(doc, repr); +} - if (reinterpret_cast(flowdiv_parent_class)->build) { - reinterpret_cast(flowdiv_parent_class)->build(object, doc, repr); - } +void CFlowdiv::onSet(unsigned int key, const gchar* value) { + CItem::onSet(key, value); } +// CPPIFY: remove static void sp_flowdiv_set(SPObject *object, unsigned int key, const gchar *value) { - if (reinterpret_cast(flowdiv_parent_class)->set) { - reinterpret_cast(flowdiv_parent_class)->set(object, key, value); - } + ((SPFlowdiv*)object)->cflowdiv->onSet(key, value); } -static Inkscape::XML::Node *sp_flowdiv_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) -{ +Inkscape::XML::Node* CFlowdiv::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPFlowdiv* object = this->spflowdiv; + if ( flags & SP_OBJECT_WRITE_BUILD ) { if ( repr == NULL ) { repr = xml_doc->createElement("svg:flowDiv"); @@ -222,13 +253,17 @@ static Inkscape::XML::Node *sp_flowdiv_write(SPObject *object, Inkscape::XML::Do } } - if (((SPObjectClass *) (flowdiv_parent_class))->write) { - ((SPObjectClass *) (flowdiv_parent_class))->write(object, xml_doc, repr, flags); - } + CItem::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +static Inkscape::XML::Node *sp_flowdiv_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPFlowdiv*)object)->cflowdiv->onWrite(xml_doc, repr, flags); +} + /* * @@ -270,25 +305,37 @@ static void sp_flowtspan_class_init(SPFlowtspanClass *klass) sp_object_class->modified = sp_flowtspan_modified; } -static void sp_flowtspan_init(SPFlowtspan */*group*/) +CFlowtspan::CFlowtspan(SPFlowtspan* flowtspan) : CItem(flowtspan) { + this->spflowtspan = flowtspan; +} + +CFlowtspan::~CFlowtspan() { +} + +static void sp_flowtspan_init(SPFlowtspan *group) { + group->cflowtspan = new CFlowtspan(group); + group->citem = group->cflowtspan; + group->cobject = group->cflowtspan; +} + +void CFlowtspan::onRelease() { + CItem::onRelease(); } +// CPPIFY: remove static void sp_flowtspan_release(SPObject *object) { - if (reinterpret_cast(flowtspan_parent_class)->release) { - reinterpret_cast(flowtspan_parent_class)->release(object); - } + ((SPFlowtspan*)object)->cflowtspan->onRelease(); } -static void sp_flowtspan_update(SPObject *object, SPCtx *ctx, unsigned int flags) -{ +void CFlowtspan::onUpdate(SPCtx *ctx, unsigned int flags) { + SPFlowtspan* object = this->spflowtspan; + SPItemCtx *ictx = reinterpret_cast(ctx); SPItemCtx cctx = *ictx; - if (reinterpret_cast(flowtspan_parent_class)->update) { - reinterpret_cast(flowtspan_parent_class)->update(object, ctx, flags); - } + CItem::onUpdate(ctx, flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -318,11 +365,16 @@ static void sp_flowtspan_update(SPObject *object, SPCtx *ctx, unsigned int flags } } -static void sp_flowtspan_modified(SPObject *object, guint flags) +// CPPIFY: remove +static void sp_flowtspan_update(SPObject *object, SPCtx *ctx, unsigned int flags) { - if (reinterpret_cast(flowtspan_parent_class)->modified) { - reinterpret_cast(flowtspan_parent_class)->modified(object, flags); - } + ((SPFlowtspan*)object)->cflowtspan->onUpdate(ctx, flags); +} + +void CFlowtspan::onModified(unsigned int flags) { + SPFlowtspan* object = this->spflowtspan; + + CItem::onModified(flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -345,22 +397,37 @@ static void sp_flowtspan_modified(SPObject *object, guint flags) } } +// CPPIFY: remove +static void sp_flowtspan_modified(SPObject *object, guint flags) +{ + ((SPFlowtspan*)object)->cflowtspan->onModified(flags); +} + +void CFlowtspan::onBuild(SPDocument *doc, Inkscape::XML::Node *repr) +{ + CItem::onBuild(doc, repr); +} + +// CPPIFY: remove static void sp_flowtspan_build(SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr) { - if (reinterpret_cast(flowtspan_parent_class)->build) { - reinterpret_cast(flowtspan_parent_class)->build(object, doc, repr); - } + ((SPFlowtspan*)object)->cflowtspan->onBuild(doc, repr); +} + +void CFlowtspan::onSet(unsigned int key, const gchar* value) { + CItem::onSet(key, value); } +// CPPIFY: remove static void sp_flowtspan_set(SPObject *object, unsigned int key, const gchar *value) { - if (reinterpret_cast(flowtspan_parent_class)->set) { - reinterpret_cast(flowtspan_parent_class)->set(object, key, value); - } + ((SPFlowtspan*)object)->cflowtspan->onSet(key, value); } -static Inkscape::XML::Node *sp_flowtspan_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +Inkscape::XML::Node *CFlowtspan::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPFlowtspan* object = this->spflowtspan; + if ( flags&SP_OBJECT_WRITE_BUILD ) { if ( repr == NULL ) { repr = xml_doc->createElement("svg:flowSpan"); @@ -396,13 +463,17 @@ static Inkscape::XML::Node *sp_flowtspan_write(SPObject *object, Inkscape::XML:: } } - if (((SPObjectClass *) (flowtspan_parent_class))->write) { - ((SPObjectClass *) (flowtspan_parent_class))->write(object, xml_doc, repr, flags); - } + CItem::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +static Inkscape::XML::Node *sp_flowtspan_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPFlowtspan*)object)->cflowtspan->onWrite(xml_doc, repr, flags); +} + /* @@ -445,25 +516,38 @@ static void sp_flowpara_class_init(SPFlowparaClass *klass) sp_object_class->modified = sp_flowpara_modified; } -static void sp_flowpara_init (SPFlowpara */*group*/) +CFlowpara::CFlowpara(SPFlowpara* flowpara) : CItem(flowpara) { + this->spflowpara = flowpara; +} + +CFlowpara::~CFlowpara() { +} + +static void sp_flowpara_init (SPFlowpara *group) { + group->cflowpara = new CFlowpara(group); + group->citem = group->cflowpara; + group->cobject = group->cflowpara; +} + +void CFlowpara::onRelease() { + CItem::onRelease(); } +// CPPIFY: remove static void sp_flowpara_release(SPObject *object) { - if (reinterpret_cast(flowpara_parent_class)->release) { - reinterpret_cast(flowpara_parent_class)->release(object); - } + ((SPFlowpara*)object)->cflowpara->onRelease(); } -static void sp_flowpara_update(SPObject *object, SPCtx *ctx, unsigned int flags) +void CFlowpara::onUpdate(SPCtx *ctx, unsigned int flags) { + SPFlowpara* object = this->spflowpara; + SPItemCtx *ictx = reinterpret_cast(ctx); SPItemCtx cctx = *ictx; - if (reinterpret_cast(flowpara_parent_class)->update) { - reinterpret_cast(flowpara_parent_class)->update(object, ctx, flags); - } + CItem::onUpdate(ctx, flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -493,11 +577,16 @@ static void sp_flowpara_update(SPObject *object, SPCtx *ctx, unsigned int flags) } } -static void sp_flowpara_modified(SPObject *object, guint flags) +// CPPIFY: remove +static void sp_flowpara_update(SPObject *object, SPCtx *ctx, unsigned int flags) { - if (reinterpret_cast(flowpara_parent_class)->modified) { - reinterpret_cast(flowpara_parent_class)->modified(object, flags); - } + ((SPFlowpara*)object)->cflowpara->onUpdate(ctx, flags); +} + +void CFlowpara::onModified(unsigned int flags) { + SPFlowpara* object = this->spflowpara; + + CItem::onModified(flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -520,22 +609,37 @@ static void sp_flowpara_modified(SPObject *object, guint flags) } } +// CPPIFY: remove +static void sp_flowpara_modified(SPObject *object, guint flags) +{ + ((SPFlowpara*)object)->cflowpara->onModified(flags); +} + +void CFlowpara::onBuild(SPDocument *doc, Inkscape::XML::Node *repr) +{ + CItem::onBuild(doc, repr); +} + +// CPPIFY: remove static void sp_flowpara_build(SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr) { - if (reinterpret_cast(flowpara_parent_class)->build) { - reinterpret_cast(flowpara_parent_class)->build(object, doc, repr); - } + ((SPFlowpara*)object)->cflowpara->onBuild(doc, repr); } +void CFlowpara::onSet(unsigned int key, const gchar* value) { + CItem::onSet(key, value); +} + +// CPPIFY: remove static void sp_flowpara_set(SPObject *object, unsigned int key, const gchar *value) { - if (reinterpret_cast(flowpara_parent_class)->set) { - reinterpret_cast(flowpara_parent_class)->set(object, key, value); - } + ((SPFlowpara*)object)->cflowpara->onSet(key, value); } -static Inkscape::XML::Node *sp_flowpara_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +Inkscape::XML::Node *CFlowpara::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPFlowpara* object = this->spflowpara; + if ( flags&SP_OBJECT_WRITE_BUILD ) { if ( repr == NULL ) repr = xml_doc->createElement("svg:flowPara"); GSList *l = NULL; @@ -569,13 +673,17 @@ static Inkscape::XML::Node *sp_flowpara_write(SPObject *object, Inkscape::XML::D } } - if (((SPObjectClass *) (flowpara_parent_class))->write) { - ((SPObjectClass *) (flowpara_parent_class))->write(object, xml_doc, repr, flags); - } + CItem::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +static Inkscape::XML::Node *sp_flowpara_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPFlowpara*)object)->cflowpara->onWrite(xml_doc, repr, flags); +} + /* * */ @@ -612,30 +720,45 @@ static void sp_flowline_class_init(SPFlowlineClass *klass) sp_object_class->modified = sp_flowline_modified; } -static void sp_flowline_init(SPFlowline */*group*/) +CFlowline::CFlowline(SPFlowline* flowline) : CObject(flowline) { + this->spflowline = flowline; +} + +CFlowline::~CFlowline() { +} + +static void sp_flowline_init(SPFlowline *group) { + group->cflowline = new CFlowline(group); + group->cobject = group->cflowline; } +void CFlowline::onRelease() { + CObject::onRelease(); +} + +// CPPIFY: remove static void sp_flowline_release(SPObject *object) { - if (reinterpret_cast(flowline_parent_class)->release) { - reinterpret_cast(flowline_parent_class)->release(object); - } + ((SPFlowline*)object)->cflowline->onRelease(); } +void CFlowline::onModified(unsigned int flags) { + CObject::onModified(flags); + + if (flags & SP_OBJECT_MODIFIED_FLAG) { + flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; + } + flags &= SP_OBJECT_MODIFIED_CASCADE; +} + +// CPPIFY: remove static void sp_flowline_modified(SPObject *object, guint flags) { - if (reinterpret_cast(flowline_parent_class)->modified) { - reinterpret_cast(flowline_parent_class)->modified(object, flags); - } - - if (flags & SP_OBJECT_MODIFIED_FLAG) { - flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; - } - flags &= SP_OBJECT_MODIFIED_CASCADE; + ((SPFlowline*)object)->cflowline->onModified(flags); } -static Inkscape::XML::Node *sp_flowline_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +Inkscape::XML::Node *CFlowline::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ( flags & SP_OBJECT_WRITE_BUILD ) { if ( repr == NULL ) { @@ -644,13 +767,17 @@ static Inkscape::XML::Node *sp_flowline_write(SPObject *object, Inkscape::XML::D } else { } - if (reinterpret_cast(flowline_parent_class)->write) { - reinterpret_cast(flowline_parent_class)->write(object, xml_doc, repr, flags); - } + CObject::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +static Inkscape::XML::Node *sp_flowline_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPFlowline*)object)->cflowline->onWrite(xml_doc, repr, flags); +} + /* * */ @@ -687,30 +814,45 @@ static void sp_flowregionbreak_class_init(SPFlowregionbreakClass *klass) sp_object_class->modified = sp_flowregionbreak_modified; } -static void sp_flowregionbreak_init(SPFlowregionbreak */*group*/) +CFlowregionbreak::CFlowregionbreak(SPFlowregionbreak* flowregionbreak) : CObject(flowregionbreak) { + this->spflowregionbreak = flowregionbreak; +} + +CFlowregionbreak::~CFlowregionbreak() { +} + +static void sp_flowregionbreak_init(SPFlowregionbreak *group) { + group->cflowregionbreak = new CFlowregionbreak(group); + group->cobject = group->cflowregionbreak; } +void CFlowregionbreak::onRelease() { + CObject::onRelease(); +} + +// CPPIFY: remove static void sp_flowregionbreak_release(SPObject *object) { - if (reinterpret_cast(flowregionbreak_parent_class)->release) { - reinterpret_cast(flowregionbreak_parent_class)->release(object); - } + ((SPFlowregionbreak*)object)->cflowregionbreak->onRelease(); } +void CFlowregionbreak::onModified(unsigned int flags) { + CObject::onModified(flags); + + if (flags & SP_OBJECT_MODIFIED_FLAG) { + flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; + } + flags &= SP_OBJECT_MODIFIED_CASCADE; +} + +// CPPIFY: remove static void sp_flowregionbreak_modified(SPObject *object, guint flags) { - if (reinterpret_cast(flowregionbreak_parent_class)->modified) { - reinterpret_cast(flowregionbreak_parent_class)->modified(object, flags); - } - - if (flags & SP_OBJECT_MODIFIED_FLAG) { - flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; - } - flags &= SP_OBJECT_MODIFIED_CASCADE; + ((SPFlowregionbreak*)object)->cflowregionbreak->onModified(flags); } -static Inkscape::XML::Node *sp_flowregionbreak_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +Inkscape::XML::Node *CFlowregionbreak::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { if ( flags & SP_OBJECT_WRITE_BUILD ) { if ( repr == NULL ) { @@ -719,13 +861,17 @@ static Inkscape::XML::Node *sp_flowregionbreak_write(SPObject *object, Inkscape: } else { } - if (reinterpret_cast(flowregionbreak_parent_class)->write) { - reinterpret_cast(flowregionbreak_parent_class)->write(object, xml_doc, repr, flags); - } + CObject::onWrite(xml_doc, repr, flags); return repr; } +// CPPIFY: remove +static Inkscape::XML::Node *sp_flowregionbreak_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPFlowregionbreak*)object)->cflowregionbreak->onWrite(xml_doc, repr, flags); +} + /* Local Variables: mode:c++ diff --git a/src/sp-flowdiv.h b/src/sp-flowdiv.h index c01ada3b0..4414be338 100644 --- a/src/sp-flowdiv.h +++ b/src/sp-flowdiv.h @@ -37,24 +37,39 @@ #define SP_IS_FLOWREGIONBREAK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SP_TYPE_FLOWREGIONBREAK)) #define SP_IS_FLOWREGIONBREAK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SP_TYPE_FLOWREGIONBREAK)) +class CFlowdiv; +class CFlowtspan; +class CFlowpara; +class CFlowline; +class CFlowregionbreak; + // these 3 are derivatives of SPItem to get the automatic style handling -struct SPFlowdiv : public SPItem { +class SPFlowdiv : public SPItem { +public: + CFlowdiv* cflowdiv; }; -struct SPFlowtspan : public SPItem { +class SPFlowtspan : public SPItem { +public: + CFlowtspan* cflowtspan; }; -struct SPFlowpara : public SPItem { +class SPFlowpara : public SPItem { +public: + CFlowpara* cflowpara; }; // these do not need any style -struct SPFlowline : public SPObject { +class SPFlowline : public SPObject { +public: + CFlowline* cflowline; }; -struct SPFlowregionbreak : public SPObject { +class SPFlowregionbreak : public SPObject { +public: + CFlowregionbreak* cflowregionbreak; }; - struct SPFlowdivClass { SPItemClass parent_class; }; @@ -75,6 +90,87 @@ struct SPFlowregionbreakClass { SPObjectClass parent_class; }; + +class CFlowdiv : public CItem { +public: + CFlowdiv(SPFlowdiv* flowdiv); + virtual ~CFlowdiv(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onRelease(); + virtual void onUpdate(SPCtx* ctx, guint flags); + virtual void onModified(unsigned int flags); + + virtual void onSet(unsigned int key, gchar const* value); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + +protected: + SPFlowdiv* spflowdiv; +}; + +class CFlowtspan : public CItem { +public: + CFlowtspan(SPFlowtspan* flowtspan); + virtual ~CFlowtspan(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onRelease(); + virtual void onUpdate(SPCtx* ctx, guint flags); + virtual void onModified(unsigned int flags); + + virtual void onSet(unsigned int key, gchar const* value); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + +protected: + SPFlowtspan* spflowtspan; +}; + +class CFlowpara : public CItem { +public: + CFlowpara(SPFlowpara* flowpara); + virtual ~CFlowpara(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onRelease(); + virtual void onUpdate(SPCtx* ctx, guint flags); + virtual void onModified(unsigned int flags); + + virtual void onSet(unsigned int key, gchar const* value); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + +protected: + SPFlowpara* spflowpara; +}; + +class CFlowline : public CObject { +public: + CFlowline(SPFlowline* flowline); + virtual ~CFlowline(); + + virtual void onRelease(); + virtual void onModified(unsigned int flags); + + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + +protected: + SPFlowline* spflowline; +}; + +class CFlowregionbreak : public CObject { +public: + CFlowregionbreak(SPFlowregionbreak* flowregionbreak); + virtual ~CFlowregionbreak(); + + virtual void onRelease(); + virtual void onModified(unsigned int flags); + + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + +protected: + SPFlowregionbreak* spflowregionbreak; +}; + + GType sp_flowdiv_get_type (void); GType sp_flowtspan_get_type (void); GType sp_flowpara_get_type (void); -- cgit v1.2.3 From 1e25ba03dddd007b9849ce31bcc365fa39102a2d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 22:12:31 +0200 Subject: Added "virtual pad" to - SPFlowregion - SPFlowregionExclude (bzr r11608.1.24) --- src/sp-flowregion.cpp | 160 +++++++++++++++++++++++++++++++++++--------------- src/sp-flowregion.h | 44 +++++++++++++- 2 files changed, 154 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/sp-flowregion.cpp b/src/sp-flowregion.cpp index 649193c33..8dc8ebf8a 100644 --- a/src/sp-flowregion.cpp +++ b/src/sp-flowregion.cpp @@ -101,9 +101,20 @@ sp_flowregion_class_init (SPFlowregionClass *klass) item_class->description = sp_flowregion_description; } +CFlowregion::CFlowregion(SPFlowregion* flowregion) : CItem(flowregion) { + this->spflowregion = flowregion; +} + +CFlowregion::~CFlowregion() { +} + static void sp_flowregion_init (SPFlowregion *group) { + group->cflowregion = new CFlowregion(group); + group->citem = group->cflowregion; + group->cobject = group->cflowregion; + new (&group->computed) std::vector; } @@ -116,39 +127,44 @@ sp_flowregion_dispose(GObject *object) group->computed.~vector(); } -static void sp_flowregion_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) -{ - SP_ITEM(object); +void CFlowregion::onChildAdded(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { + SPFlowregion* object = this->spflowregion; - if (((SPObjectClass *) (flowregion_parent_class))->child_added) { - (* ((SPObjectClass *) (flowregion_parent_class))->child_added) (object, child, ref); - } + CItem::onChildAdded(child, ref); object->requestModified(SP_OBJECT_MODIFIED_FLAG); } +static void sp_flowregion_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) +{ + ((SPFlowregion*)object)->cflowregion->onChildAdded(child, ref); +} + /* fixme: hide (Lauris) */ +void CFlowregion::onRemoveChild(Inkscape::XML::Node * child) { + SPFlowregion* object = this->spflowregion; + + CItem::onRemoveChild(child); + + object->requestModified(SP_OBJECT_MODIFIED_FLAG); +} + static void sp_flowregion_remove_child (SPObject * object, Inkscape::XML::Node * child) { - if (((SPObjectClass *) (flowregion_parent_class))->remove_child) - (* ((SPObjectClass *) (flowregion_parent_class))->remove_child) (object, child); - - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + ((SPFlowregion*)object)->cflowregion->onRemoveChild(child); } +void CFlowregion::onUpdate(SPCtx *ctx, unsigned int flags) { + SPFlowregion* object = this->spflowregion; -static void sp_flowregion_update(SPObject *object, SPCtx *ctx, unsigned int flags) -{ SPFlowregion *group = SP_FLOWREGION(object); SPItemCtx *ictx = reinterpret_cast(ctx); SPItemCtx cctx = *ictx; - if (((SPObjectClass *) (flowregion_parent_class))->update) { - ((SPObjectClass *) (flowregion_parent_class))->update (object, ctx, flags); - } + CItem::onUpdate(ctx, flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -180,6 +196,11 @@ static void sp_flowregion_update(SPObject *object, SPCtx *ctx, unsigned int flag group->UpdateComputed(); } +static void sp_flowregion_update(SPObject *object, SPCtx *ctx, unsigned int flags) +{ + ((SPFlowregion*)object)->cflowregion->onUpdate(ctx, flags); +} + void SPFlowregion::UpdateComputed(void) { for (std::vector::iterator it = computed.begin() ; it != computed.end() ; ++it) { @@ -194,9 +215,8 @@ void SPFlowregion::UpdateComputed(void) } } -static void sp_flowregion_modified(SPObject *object, guint flags) -{ - SP_FLOWREGION(object); // ensure it is the proper type. +void CFlowregion::onModified(guint flags) { + SPFlowregion* object = this->spflowregion; if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -219,8 +239,14 @@ static void sp_flowregion_modified(SPObject *object, guint flags) } } -static Inkscape::XML::Node *sp_flowregion_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void sp_flowregion_modified(SPObject *object, guint flags) { + ((SPFlowregion*)object)->cflowregion->onModified(flags); +} + +Inkscape::XML::Node *CFlowregion::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPFlowregion* object = this->spflowregion; + if (flags & SP_OBJECT_WRITE_BUILD) { if ( repr == NULL ) { repr = xml_doc->createElement("svg:flowRegion"); @@ -250,20 +276,26 @@ static Inkscape::XML::Node *sp_flowregion_write(SPObject *object, Inkscape::XML: } } - if (((SPObjectClass *) (flowregion_parent_class))->write) { - ((SPObjectClass *) (flowregion_parent_class))->write (object, xml_doc, repr, flags); - } + CItem::onWrite(xml_doc, repr, flags); return repr; } - -static gchar *sp_flowregion_description(SPItem */*item*/) +static Inkscape::XML::Node *sp_flowregion_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + return ((SPFlowregion*)object)->cflowregion->onWrite(xml_doc, repr, flags); +} + +gchar* CFlowregion::onDescription() { // TRANSLATORS: "Flow region" is an area where text is allowed to flow return g_strdup_printf(_("Flow region")); } +static gchar *sp_flowregion_description(SPItem *item) +{ + return ((SPFlowregion*)item)->cflowregion->onDescription(); +} + /* * */ @@ -314,9 +346,20 @@ sp_flowregionexclude_class_init (SPFlowregionExcludeClass *klass) item_class->description = sp_flowregionexclude_description; } +CFlowregionExclude::CFlowregionExclude(SPFlowregionExclude* flowregionexclude) : CItem(flowregionexclude) { + this->spflowregionexclude = flowregionexclude; +} + +CFlowregionExclude::~CFlowregionExclude() { +} + static void sp_flowregionexclude_init (SPFlowregionExclude *group) { + group->cflowregionexclude = new CFlowregionExclude(group); + group->citem = group->cflowregionexclude; + group->cobject = group->cflowregionexclude; + group->computed = NULL; } @@ -330,39 +373,44 @@ sp_flowregionexclude_dispose(GObject *object) } } -static void sp_flowregionexclude_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) -{ - SP_ITEM(object); +void CFlowregionExclude::onChildAdded(Inkscape::XML::Node *child, Inkscape::XML::Node *ref) { + SPFlowregionExclude* object = this->spflowregionexclude; - if (((SPObjectClass *) (flowregionexclude_parent_class))->child_added) { - (* ((SPObjectClass *) (flowregionexclude_parent_class))->child_added) (object, child, ref); - } + CItem::onChildAdded(child, ref); object->requestModified(SP_OBJECT_MODIFIED_FLAG); } +static void sp_flowregionexclude_child_added(SPObject *object, Inkscape::XML::Node *child, Inkscape::XML::Node *ref) +{ + ((SPFlowregionExclude*)object)->cflowregionexclude->onChildAdded(child, ref); +} + /* fixme: hide (Lauris) */ +void CFlowregionExclude::onRemoveChild(Inkscape::XML::Node * child) { + SPFlowregionExclude* object = this->spflowregionexclude; + + CItem::onRemoveChild(child); + + object->requestModified(SP_OBJECT_MODIFIED_FLAG); +} + static void sp_flowregionexclude_remove_child (SPObject * object, Inkscape::XML::Node * child) { - if (((SPObjectClass *) (flowregionexclude_parent_class))->remove_child) - (* ((SPObjectClass *) (flowregionexclude_parent_class))->remove_child) (object, child); - - object->requestModified(SP_OBJECT_MODIFIED_FLAG); + ((SPFlowregionExclude*)object)->cflowregionexclude->onRemoveChild(child); } +void CFlowregionExclude::onUpdate(SPCtx *ctx, unsigned int flags) { + SPFlowregionExclude* object = this->spflowregionexclude; -static void sp_flowregionexclude_update(SPObject *object, SPCtx *ctx, unsigned int flags) -{ SPFlowregionExclude *group = SP_FLOWREGIONEXCLUDE (object); SPItemCtx *ictx = reinterpret_cast(ctx); SPItemCtx cctx = *ictx; - if (((SPObjectClass *) (flowregionexclude_parent_class))->update) { - ((SPObjectClass *) (flowregionexclude_parent_class))->update (object, ctx, flags); - } + CItem::onUpdate(ctx, flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -394,6 +442,11 @@ static void sp_flowregionexclude_update(SPObject *object, SPCtx *ctx, unsigned i group->UpdateComputed(); } +static void sp_flowregionexclude_update(SPObject *object, SPCtx *ctx, unsigned int flags) +{ + ((SPFlowregionExclude*)object)->cflowregionexclude->onUpdate(ctx, flags); +} + void SPFlowregionExclude::UpdateComputed(void) { if (computed) { @@ -406,9 +459,8 @@ void SPFlowregionExclude::UpdateComputed(void) } } -static void sp_flowregionexclude_modified(SPObject *object, guint flags) -{ - SP_FLOWREGIONEXCLUDE(object); // Ensure it is the proper type +void CFlowregionExclude::onModified(guint flags) { + SPFlowregionExclude* object = this->spflowregionexclude; if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -431,8 +483,14 @@ static void sp_flowregionexclude_modified(SPObject *object, guint flags) } } -static Inkscape::XML::Node *sp_flowregionexclude_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void sp_flowregionexclude_modified(SPObject *object, guint flags) { + ((SPFlowregionExclude*)object)->cflowregionexclude->onModified(flags); +} + +Inkscape::XML::Node *CFlowregionExclude::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPFlowregionExclude* object = this->spflowregionexclude; + if (flags & SP_OBJECT_WRITE_BUILD) { if ( repr == NULL ) { repr = xml_doc->createElement("svg:flowRegionExclude"); @@ -458,16 +516,17 @@ static Inkscape::XML::Node *sp_flowregionexclude_write(SPObject *object, Inkscap } } - if (((SPObjectClass *) (flowregionexclude_parent_class))->write) { - ((SPObjectClass *) (flowregionexclude_parent_class))->write (object, xml_doc, repr, flags); - } + CItem::onWrite(xml_doc, repr, flags); return repr; } - -static gchar *sp_flowregionexclude_description(SPItem */*item*/) +static Inkscape::XML::Node *sp_flowregionexclude_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + return ((SPFlowregionExclude*)object)->cflowregionexclude->onWrite(xml_doc, repr, flags); +} + +gchar* CFlowregionExclude::onDescription() { /* TRANSLATORS: A region "cut out of" a flow region; text is not allowed to flow inside the * flow excluded region. flowRegionExclude in SVG 1.2: see * http://www.w3.org/TR/2004/WD-SVG12-20041027/flow.html#flowRegion-elem and @@ -475,6 +534,11 @@ static gchar *sp_flowregionexclude_description(SPItem */*item*/) return g_strdup_printf(_("Flow excluded region")); } +static gchar *sp_flowregionexclude_description(SPItem *item) +{ + return ((SPFlowregionExclude*)item)->cflowregionexclude->onDescription(); +} + /* * */ diff --git a/src/sp-flowregion.h b/src/sp-flowregion.h index 46b584cf2..2386149ab 100644 --- a/src/sp-flowregion.h +++ b/src/sp-flowregion.h @@ -22,8 +22,13 @@ class Path; class Shape; class flow_dest; class FloatLigne; +class CFlowregion; +class CFlowregionExclude; + +class SPFlowregion : public SPItem { +public: + CFlowregion* cflowregion; -struct SPFlowregion : public SPItem { std::vector computed; void UpdateComputed(void); @@ -33,9 +38,28 @@ struct SPFlowregionClass { SPItemClass parent_class; }; +class CFlowregion : public CItem { +public: + CFlowregion(SPFlowregion* flowregion); + virtual ~CFlowregion(); + + virtual void onChildAdded(Inkscape::XML::Node* child, Inkscape::XML::Node* ref); + virtual void onRemoveChild(Inkscape::XML::Node *child); + virtual void onUpdate(SPCtx *ctx, unsigned int flags); + virtual void onModified(guint flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual gchar *onDescription(); + +protected: + SPFlowregion* spflowregion; +}; + GType sp_flowregion_get_type (void); -struct SPFlowregionExclude : public SPItem { +class SPFlowregionExclude : public SPItem { +public: + CFlowregionExclude* cflowregionexclude; + Shape *computed; void UpdateComputed(void); @@ -45,6 +69,22 @@ struct SPFlowregionExcludeClass { SPItemClass parent_class; }; +class CFlowregionExclude : public CItem { +public: + CFlowregionExclude(SPFlowregionExclude* flowregionexclude); + virtual ~CFlowregionExclude(); + + virtual void onChildAdded(Inkscape::XML::Node* child, Inkscape::XML::Node* ref); + virtual void onRemoveChild(Inkscape::XML::Node *child); + virtual void onUpdate(SPCtx *ctx, unsigned int flags); + virtual void onModified(guint flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual gchar *onDescription(); + +protected: + SPFlowregionExclude* spflowregionexclude; +}; + GType sp_flowregionexclude_get_type (void); #endif -- cgit v1.2.3 From 37eb84dcfa0f0bb84f5e62303ef7288ee922b64d Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 22:59:52 +0200 Subject: Added "virtual pad" to SPImage. (bzr r11608.1.25) --- src/sp-image.cpp | 156 +++++++++++++++++++++++++++++++++++++++++-------------- src/sp-image.h | 31 ++++++++++- 2 files changed, 147 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/sp-image.cpp b/src/sp-image.cpp index 07885ff4d..15f565bc4 100644 --- a/src/sp-image.cpp +++ b/src/sp-image.cpp @@ -602,8 +602,19 @@ static void sp_image_class_init( SPImageClass * klass ) item_class->set_transform = sp_image_set_transform; } +CImage::CImage(SPImage* image) : CItem(image) { + this->spimage = image; +} + +CImage::~CImage() { +} + static void sp_image_init( SPImage *image ) { + image->cimage = new CImage(image); + image->citem = image->cimage; + image->cobject = image->cimage; + image->x.unset(); image->y.unset(); image->width.unset(); @@ -624,11 +635,10 @@ static void sp_image_init( SPImage *image ) image->lastMod = 0; } -static void sp_image_build( SPObject *object, SPDocument *document, Inkscape::XML::Node *repr ) -{ - if (((SPObjectClass *) parent_class)->build) { - ((SPObjectClass *) parent_class)->build (object, document, repr); - } +void CImage::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPImage* object = this->spimage; + + CItem::onBuild(document, repr); object->readAttr( "xlink:href" ); object->readAttr( "x" ); @@ -642,8 +652,14 @@ static void sp_image_build( SPObject *object, SPDocument *document, Inkscape::XM document->addResource("image", object); } -static void sp_image_release( SPObject *object ) +static void sp_image_build( SPObject *object, SPDocument *document, Inkscape::XML::Node *repr ) { + ((SPImage*)object)->cimage->onBuild(document, repr); +} + +void CImage::onRelease() { + SPImage* object = this->spimage; + SPImage *image = SP_IMAGE(object); if (object->document) { @@ -677,13 +693,18 @@ static void sp_image_release( SPObject *object ) image->curve = image->curve->unref(); } - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release (object); - } + CItem::onRelease(); } -static void sp_image_set( SPObject *object, unsigned int key, const gchar *value ) +static void sp_image_release( SPObject *object ) { + ((SPImage*)object)->cimage->onRelease(); + +} + +void CImage::onSet(unsigned int key, const gchar* value) { + SPImage* object = this->spimage; + SPImage *image = SP_IMAGE (object); switch (key) { @@ -796,22 +817,25 @@ static void sp_image_set( SPObject *object, unsigned int key, const gchar *value break; #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) default: - if (((SPObjectClass *) (parent_class))->set) - ((SPObjectClass *) (parent_class))->set (object, key, value); + CItem::onSet(key, value); break; } sp_image_set_curve(image); //creates a curve at the image's boundary for snapping } -static void sp_image_update( SPObject *object, SPCtx *ctx, unsigned int flags ) +static void sp_image_set( SPObject *object, unsigned int key, const gchar *value ) { + ((SPImage*)object)->cimage->onSet(key, value); +} + +void CImage::onUpdate(SPCtx *ctx, unsigned int flags) { + SPImage* object = this->spimage; + SPImage *image = SP_IMAGE(object); SPDocument *doc = object->document; - if (((SPObjectClass *) (parent_class))->update) { - ((SPObjectClass *) (parent_class))->update (object, ctx, flags); - } + CItem::onUpdate(ctx, flags); if (flags & SP_IMAGE_HREF_MODIFIED_FLAG) { if (image->pixbuf) { @@ -1009,13 +1033,22 @@ static void sp_image_update( SPObject *object, SPCtx *ctx, unsigned int flags ) sp_image_update_canvas_image ((SPImage *) object); } -static void sp_image_modified( SPObject *object, unsigned int flags ) +static void sp_image_update( SPObject *object, SPCtx *ctx, unsigned int flags ) { + ((SPImage*)object)->cimage->onUpdate(ctx, flags); +} + +void CImage::onModified(unsigned int flags) { + SPImage* object = this->spimage; + SPImage *image = SP_IMAGE (object); - if (((SPObjectClass *) (parent_class))->modified) { - (* ((SPObjectClass *) (parent_class))->modified) (object, flags); - } + // CPPIFY: This doesn't make no sense. + // CObject::onModified is pure and CItem doesn't override this method. What was the idea behind these lines? +// if (((SPObjectClass *) (parent_class))->modified) { +// (* ((SPObjectClass *) (parent_class))->modified) (object, flags); +// } +// CItem::onModified(flags); if (flags & SP_OBJECT_STYLE_MODIFIED_FLAG) { for (SPItemView *v = image->display; v != NULL; v = v->next) { @@ -1025,8 +1058,14 @@ static void sp_image_modified( SPObject *object, unsigned int flags ) } } -static Inkscape::XML::Node *sp_image_write( SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags ) +static void sp_image_modified( SPObject *object, unsigned int flags ) { + ((SPImage*)object)->cimage->onModified(flags); +} + +Inkscape::XML::Node *CImage::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags ) { + SPImage* object = this->spimage; + SPImage *image = SP_IMAGE (object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { @@ -1056,27 +1095,37 @@ static Inkscape::XML::Node *sp_image_write( SPObject *object, Inkscape::XML::Doc } #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags); - } + CItem::onWrite(xml_doc, repr, flags); return repr; } -static Geom::OptRect sp_image_bbox( SPItem const *item,Geom::Affine const &transform, SPItem::BBoxType /*type*/ ) +static Inkscape::XML::Node *sp_image_write( SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags ) { - SPImage const &image = *SP_IMAGE(item); - Geom::OptRect bbox; + return ((SPImage*)object)->cimage->onWrite(xml_doc, repr, flags); +} - if ((image.width.computed > 0.0) && (image.height.computed > 0.0)) { - bbox = Geom::Rect::from_xywh(image.x.computed, image.y.computed, image.width.computed, image.height.computed); - *bbox *= transform; - } - return bbox; +Geom::OptRect CImage::onBbox(Geom::Affine const &transform, SPItem::BBoxType type) { + SPImage* item = this->spimage; + + SPImage const &image = *SP_IMAGE(item); + Geom::OptRect bbox; + + if ((image.width.computed > 0.0) && (image.height.computed > 0.0)) { + bbox = Geom::Rect::from_xywh(image.x.computed, image.y.computed, image.width.computed, image.height.computed); + *bbox *= transform; + } + return bbox; } -static void sp_image_print( SPItem *item, SPPrintContext *ctx ) +static Geom::OptRect sp_image_bbox( SPItem const *item,Geom::Affine const &transform, SPItem::BBoxType type) { + return ((SPImage*)item)->cimage->onBbox(transform, type); +} + +void CImage::onPrint(SPPrintContext *ctx) { + SPImage* item = this->spimage; + SPImage *image = SP_IMAGE(item); if (image->pixbuf && (image->width.computed > 0.0) && (image->height.computed > 0.0) ) { @@ -1122,8 +1171,14 @@ static void sp_image_print( SPItem *item, SPPrintContext *ctx ) } } -static gchar *sp_image_description( SPItem *item ) +static void sp_image_print( SPItem *item, SPPrintContext *ctx ) { + ((SPImage*)item)->cimage->onPrint(ctx); +} + +gchar* CImage::onDescription() { + SPImage* item = this->spimage; + SPImage *image = SP_IMAGE(item); char *href_desc; if (image->href) { @@ -1145,8 +1200,14 @@ static gchar *sp_image_description( SPItem *item ) return ret; } -static Inkscape::DrawingItem *sp_image_show( SPItem *item, Inkscape::Drawing &drawing, unsigned int /*key*/, unsigned int /*flags*/ ) +static gchar *sp_image_description( SPItem *item ) { + return ((SPImage*)item)->cimage->onDescription(); +} + +Inkscape::DrawingItem* CImage::onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + SPImage* item = this->spimage; + SPImage * image = SP_IMAGE(item); Inkscape::DrawingImage *ai = new Inkscape::DrawingImage(drawing); @@ -1155,6 +1216,11 @@ static Inkscape::DrawingItem *sp_image_show( SPItem *item, Inkscape::Drawing &dr return ai; } +static Inkscape::DrawingItem *sp_image_show( SPItem *item, Inkscape::Drawing &drawing, unsigned int key, unsigned int flags ) +{ + return ((SPImage*)item)->cimage->onShow(drawing, key, flags); +} + /* * utility function to try loading image from href * @@ -1279,8 +1345,9 @@ static void sp_image_update_canvas_image(SPImage *image) } } -static void sp_image_snappoints( SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs ) -{ +void CImage::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + SPImage* item = this->spimage; + /* An image doesn't have any nodes to snap, but still we want to be able snap one image to another. Therefore we will create some snappoints at the corner, similar to a rect. If the image is rotated, then the snappoints will rotate with it. Again, just like a rect. @@ -1310,13 +1377,19 @@ static void sp_image_snappoints( SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs ) +{ + ((SPImage*)item)->cimage->onSnappoints(p, snapprefs); +} + /* * Initially we'll do: * Transform x, y, set x, y, clear translation */ -static Geom::Affine sp_image_set_transform( SPItem *item, Geom::Affine const &xform ) -{ +Geom::Affine CImage::onSetTransform(Geom::Affine const &xform) { + SPImage* item = this->spimage; + SPImage *image = SP_IMAGE(item); /* Calculate position in parent coords. */ @@ -1355,6 +1428,11 @@ static Geom::Affine sp_image_set_transform( SPItem *item, Geom::Affine const &xf return ret; } +static Geom::Affine sp_image_set_transform( SPItem *item, Geom::Affine const &xform ) +{ + return ((SPImage*)item)->cimage->onSetTransform(xform); +} + static GdkPixbuf *sp_image_repr_read_dataURI( const gchar * uri_data ) { GdkPixbuf * pixbuf = NULL; diff --git a/src/sp-image.h b/src/sp-image.h index c657d0a2f..c6d36e7de 100644 --- a/src/sp-image.h +++ b/src/sp-image.h @@ -22,6 +22,7 @@ class SPImage; class SPImageClass; +class CImage; /* SPImage */ @@ -32,7 +33,10 @@ class SPImageClass; #define SP_IMAGE_HREF_MODIFIED_FLAG SP_OBJECT_USER_MODIFIED_FLAG_A -struct SPImage : public SPItem { +class SPImage : public SPItem { +public: + CImage* cimage; + SVGLength x; SVGLength y; SVGLength width; @@ -65,6 +69,31 @@ struct SPImageClass { SPItemClass parent_class; }; + +class CImage : public CItem { +public: + CImage(SPImage* image); + virtual ~CImage(); + + virtual void onBuild(SPDocument *document, Inkscape::XML::Node *repr); + virtual void onRelease(); + virtual void onSet(unsigned int key, gchar const* value); + virtual void onUpdate(SPCtx *ctx, guint flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual void onModified(unsigned int flags); + + virtual Geom::OptRect onBbox(Geom::Affine const &transform, SPItem::BBoxType type); + virtual void onPrint(SPPrintContext *ctx); + virtual gchar* onDescription(); + virtual Inkscape::DrawingItem* onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); + virtual void onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs); + virtual Geom::Affine onSetTransform(Geom::Affine const &transform); + +protected: + SPImage* spimage; +}; + + GType sp_image_get_type (void); /* Return duplicate of curve or NULL */ -- cgit v1.2.3 From c3603a6d13023cce77d405f4a660a7088a935179 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Sun, 19 Aug 2012 23:43:28 +0200 Subject: Added "virtual pad" to SPText. (bzr r11608.1.26) --- src/sp-text.cpp | 180 +++++++++++++++++++++++++++++++++++++++++++------------- src/sp-text.h | 34 ++++++++++- 2 files changed, 171 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/sp-text.cpp b/src/sp-text.cpp index 0b60c1960..d9c4df702 100644 --- a/src/sp-text.cpp +++ b/src/sp-text.cpp @@ -132,42 +132,63 @@ sp_text_class_init (SPTextClass *classname) item_class->print = sp_text_print; } +CText::CText(SPText* text) : CItem(text) { + this->sptext = text; +} + +CText::~CText() { +} + static void sp_text_init (SPText *text) { + text->ctext = new CText(text); + text->citem = text->ctext; + text->cobject = text->ctext; + new (&text->layout) Inkscape::Text::Layout; new (&text->attributes) TextTagAttributes; } -static void -sp_text_release (SPObject *object) -{ +void CText::onRelease() { + SPText* object = this->sptext; + SPText *text = SP_TEXT(object); text->attributes.~TextTagAttributes(); text->layout.~Layout(); - if (((SPObjectClass *) text_parent_class)->release) - ((SPObjectClass *) text_parent_class)->release(object); + CItem::onRelease(); } static void -sp_text_build (SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr) +sp_text_release (SPObject *object) { + ((SPText*)object)->ctext->onRelease(); +} + +void CText::onBuild(SPDocument *doc, Inkscape::XML::Node *repr) { + SPText* object = this->sptext; + object->readAttr( "x" ); object->readAttr( "y" ); object->readAttr( "dx" ); object->readAttr( "dy" ); object->readAttr( "rotate" ); - if (((SPObjectClass *) text_parent_class)->build) - ((SPObjectClass *) text_parent_class)->build(object, doc, repr); + CItem::onBuild(doc, repr); object->readAttr( "sodipodi:linespacing" ); // has to happen after the styles are read } static void -sp_text_set(SPObject *object, unsigned key, gchar const *value) +sp_text_build (SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr) { + ((SPText*)object)->ctext->onBuild(doc, repr); +} + +void CText::onSet(unsigned int key, const gchar* value) { + SPText* object = this->sptext; + SPText *text = SP_TEXT (object); if (text->attributes.readSingleAttribute(key, value)) { @@ -186,41 +207,56 @@ sp_text_set(SPObject *object, unsigned key, gchar const *value) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) text_parent_class)->set) - ((SPObjectClass *) text_parent_class)->set (object, key, value); + CItem::onSet(key, value); break; } } } static void -sp_text_child_added (SPObject *object, Inkscape::XML::Node *rch, Inkscape::XML::Node *ref) +sp_text_set(SPObject *object, unsigned key, gchar const *value) { + ((SPText*)object)->ctext->onSet(key, value); +} + +void CText::onChildAdded(Inkscape::XML::Node *rch, Inkscape::XML::Node *ref) { + SPText* object = this->sptext; + SPText *text = SP_TEXT (object); - if (((SPObjectClass *) text_parent_class)->child_added) - ((SPObjectClass *) text_parent_class)->child_added (object, rch, ref); + CItem::onChildAdded(rch, ref); text->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_CONTENT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG); } static void -sp_text_remove_child (SPObject *object, Inkscape::XML::Node *rch) +sp_text_child_added (SPObject *object, Inkscape::XML::Node *rch, Inkscape::XML::Node *ref) { + ((SPText*)object)->ctext->onChildAdded(rch, ref); +} + +void CText::onRemoveChild(Inkscape::XML::Node *rch) { + SPText* object = this->sptext; + SPText *text = SP_TEXT (object); - if (((SPObjectClass *) text_parent_class)->remove_child) - ((SPObjectClass *) text_parent_class)->remove_child (object, rch); + CItem::onRemoveChild(rch); text->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_TEXT_CONTENT_MODIFIED_FLAG | SP_TEXT_LAYOUT_MODIFIED_FLAG); } -static void sp_text_update(SPObject *object, SPCtx *ctx, guint flags) +static void +sp_text_remove_child (SPObject *object, Inkscape::XML::Node *rch) { + ((SPText*)object)->ctext->onRemoveChild(rch); +} + +void CText::onUpdate(SPCtx *ctx, guint flags) { + SPText* object = this->sptext; + SPText *text = SP_TEXT (object); - if (((SPObjectClass *) text_parent_class)->update) - ((SPObjectClass *) text_parent_class)->update (object, ctx, flags); + CItem::onUpdate(ctx, flags); guint cflags = (flags & SP_OBJECT_MODIFIED_CASCADE); if (flags & SP_OBJECT_MODIFIED_FLAG) cflags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -262,11 +298,20 @@ static void sp_text_update(SPObject *object, SPCtx *ctx, guint flags) } } -static void sp_text_modified(SPObject *object, guint flags) +static void sp_text_update(SPObject *object, SPCtx *ctx, guint flags) { - if (((SPObjectClass *) text_parent_class)->modified) { - ((SPObjectClass *) text_parent_class)->modified (object, flags); - } + ((SPText*)object)->ctext->onUpdate(ctx, flags); +} + +void CText::onModified(guint flags) { + SPText* object = this->sptext; + + // CPPIFY: This doesn't make no sense. + // CObject::onModified is pure and CItem doesn't override this method. What was the idea behind these lines? +// if (((SPObjectClass *) text_parent_class)->modified) { +// ((SPObjectClass *) text_parent_class)->modified (object, flags); +// } +// CItem::onModified(flags); guint cflags = (flags & SP_OBJECT_MODIFIED_CASCADE); if (flags & SP_OBJECT_MODIFIED_FLAG) { @@ -305,8 +350,14 @@ static void sp_text_modified(SPObject *object, guint flags) } } -static Inkscape::XML::Node *sp_text_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void sp_text_modified(SPObject *object, guint flags) { + ((SPText*)object)->ctext->onModified(flags); +} + +Inkscape::XML::Node *CText::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPText* object = this->sptext; + SPText *text = SP_TEXT (object); if (flags & SP_OBJECT_WRITE_BUILD) { @@ -357,16 +408,19 @@ static Inkscape::XML::Node *sp_text_write(SPObject *object, Inkscape::XML::Docum text->getRepr()->setAttribute("sodipodi:linespacing", NULL); } - if (((SPObjectClass *) (text_parent_class))->write) { - ((SPObjectClass *) (text_parent_class))->write (object, xml_doc, repr, flags); - } + CItem::onWrite(xml_doc, repr, flags); return repr; } -static Geom::OptRect -sp_text_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) +static Inkscape::XML::Node *sp_text_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + return ((SPText*)object)->ctext->onWrite(xml_doc, repr, flags); +} + +Geom::OptRect CText::onBbox(Geom::Affine const &transform, SPItem::BBoxType type) { + SPText* item = this->sptext; + Geom::OptRect bbox = SP_TEXT(item)->layout.bounds(transform); // FIXME this code is incorrect @@ -377,10 +431,15 @@ sp_text_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType return bbox; } - -static Inkscape::DrawingItem * -sp_text_show(SPItem *item, Inkscape::Drawing &drawing, unsigned /* key*/, unsigned /*flags*/) +static Geom::OptRect +sp_text_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) { + return ((SPText*)item)->ctext->onBbox(transform, type); +} + +Inkscape::DrawingItem* CText::onShow(Inkscape::Drawing &drawing, unsigned key, unsigned flags) { + SPText* item = this->sptext; + SPText *group = (SPText *) item; Inkscape::DrawingGroup *flowed = new Inkscape::DrawingGroup(drawing); @@ -393,15 +452,29 @@ sp_text_show(SPItem *item, Inkscape::Drawing &drawing, unsigned /* key*/, unsign return flowed; } +static Inkscape::DrawingItem * +sp_text_show(SPItem *item, Inkscape::Drawing &drawing, unsigned key, unsigned flags) +{ + return ((SPText*)item)->ctext->onShow(drawing, key, flags); +} + +void CText::onHide(unsigned int key) { + // CPPIFY: This doesn't make no sense. + // CItem::onHide is pure and CLPEItem doesn't override it. What was the idea behind these lines? +// if (((SPItemClass *) text_parent_class)->hide) +// ((SPItemClass *) text_parent_class)->hide (item, key); +// CItem::onHide(key); +} + static void sp_text_hide(SPItem *item, unsigned key) { - if (((SPItemClass *) text_parent_class)->hide) - ((SPItemClass *) text_parent_class)->hide (item, key); + ((SPText*)item)->ctext->onHide(key); } -static char * sp_text_description(SPItem *item) -{ +gchar* CText::onDescription() { + SPText* item = this->sptext; + SPText *text = reinterpret_cast(item); SPStyle *style = text->style; @@ -433,8 +506,14 @@ static char * sp_text_description(SPItem *item) return ret; } -static void sp_text_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) +static char * sp_text_description(SPItem *item) { + return ((SPText*)item)->ctext->onDescription(); +} + +void CText::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + SPText* item = this->sptext; + if (snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_TEXT_BASELINE)) { // Choose a point on the baseline for snapping from or to, with the horizontal position // of this point depending on the text alignment (left vs. right) @@ -448,9 +527,14 @@ static void sp_text_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + ((SPText*)item)->ctext->onSnappoints(p, snapprefs); +} + +Geom::Affine CText::onSetTransform(Geom::Affine const &xform) { + SPText* item = this->sptext; + SPText *text = SP_TEXT(item); // we cannot optimize textpath because changing its fontsize will break its match to the path @@ -497,9 +581,15 @@ sp_text_set_transform (SPItem *item, Geom::Affine const &xform) return ret; } -static void -sp_text_print (SPItem *item, SPPrintContext *ctx) +static Geom::Affine +sp_text_set_transform (SPItem *item, Geom::Affine const &xform) { + return ((SPText*)item)->ctext->onSetTransform(xform); +} + +void CText::onPrint(SPPrintContext *ctx) { + SPText* item = this->sptext; + SPText *group = SP_TEXT (item); Geom::OptRect pbox, bbox, dbox; @@ -511,6 +601,12 @@ sp_text_print (SPItem *item, SPPrintContext *ctx) group->layout.print(ctx,pbox,dbox,bbox,ctm); } +static void +sp_text_print (SPItem *item, SPPrintContext *ctx) +{ + ((SPText*)item)->ctext->onPrint(ctx); +} + /* * Member functions */ diff --git a/src/sp-text.h b/src/sp-text.h index 457f11f06..fb0ffdeac 100644 --- a/src/sp-text.h +++ b/src/sp-text.h @@ -32,10 +32,14 @@ #define SP_TEXT_CONTENT_MODIFIED_FLAG SP_OBJECT_USER_MODIFIED_FLAG_A #define SP_TEXT_LAYOUT_MODIFIED_FLAG SP_OBJECT_USER_MODIFIED_FLAG_A +class CText; /* SPText */ -struct SPText : public SPItem { +class SPText : public SPItem { +public: + CText* ctext; + /** Converts the text object to its component curves */ SPCurve *getNormalizedBpath() const {return layout.convertToCurves();} @@ -72,6 +76,34 @@ struct SPTextClass { SPItemClass parent_class; }; + +class CText : public CItem { +public: + CText(SPText* text); + virtual ~CText(); + + virtual void onBuild(SPDocument* doc, Inkscape::XML::Node* repr); + virtual void onRelease(); + virtual void onChildAdded(Inkscape::XML::Node* child, Inkscape::XML::Node* ref); + virtual void onRemoveChild(Inkscape::XML::Node* child); + virtual void onSet(unsigned int key, const gchar* value); + virtual void onUpdate(SPCtx* ctx, unsigned int flags); + virtual void onModified(unsigned int flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags); + + virtual Geom::OptRect onBbox(Geom::Affine const &transform, SPItem::BBoxType type); + virtual void onPrint(SPPrintContext *ctx); + virtual gchar* onDescription(); + virtual Inkscape::DrawingItem* onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); + virtual void onHide(unsigned int key); + virtual void onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs); + virtual Geom::Affine onSetTransform(Geom::Affine const &transform); + +protected: + SPText* sptext; +}; + + GType sp_text_get_type(); #endif -- cgit v1.2.3 From 217bc5844bedf86a84c099f051e51d6dc8a1966f Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Mon, 20 Aug 2012 00:21:00 +0200 Subject: Added "virtual pad" to SPTextPath and SPTSpan. (bzr r11608.1.27) --- src/sp-textpath.h | 24 ++++++- src/sp-tspan.cpp | 211 +++++++++++++++++++++++++++++++++++++++--------------- src/sp-tspan.h | 28 +++++++- 3 files changed, 204 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/sp-textpath.h b/src/sp-textpath.h index d79f4d346..c609e5eb7 100644 --- a/src/sp-textpath.h +++ b/src/sp-textpath.h @@ -15,8 +15,12 @@ class Path; #define SP_IS_TEXTPATH(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), SP_TYPE_TEXTPATH)) #define SP_IS_TEXTPATH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_TEXTPATH)) +class CTextPath; + +class SPTextPath : public SPItem { +public: + CTextPath* ctextpath; -struct SPTextPath : public SPItem { TextTagAttributes attributes; SVGLength startOffset; @@ -29,6 +33,24 @@ struct SPTextPathClass { SPItemClass parent_class; }; + +class CTextPath : public CItem { +public: + CTextPath(SPTextPath* textpath); + virtual ~CTextPath(); + + virtual void onBuild(SPDocument* doc, Inkscape::XML::Node* repr); + virtual void onRelease(); + virtual void onSet(unsigned int key, const gchar* value); + virtual void onUpdate(SPCtx* ctx, unsigned int flags); + virtual void onModified(unsigned int flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags); + +protected: + SPTextPath* sptextpath; +}; + + GType sp_textpath_get_type(); #define SP_IS_TEXT_TEXTPATH(obj) (SP_IS_TEXT(obj) && obj->firstChild() && SP_IS_TEXTPATH(obj->firstChild())) diff --git a/src/sp-tspan.cpp b/src/sp-tspan.cpp index 1b1ae3d52..3a83cb70d 100644 --- a/src/sp-tspan.cpp +++ b/src/sp-tspan.cpp @@ -109,28 +109,42 @@ sp_tspan_class_init(SPTSpanClass *classname) item_class->description = sp_tspan_description; } +CTSpan::CTSpan(SPTSpan* span) : CItem(span) { + this->sptspan = span; +} + +CTSpan::~CTSpan() { +} + static void sp_tspan_init(SPTSpan *tspan) { + tspan->ctspan = new CTSpan(tspan); + tspan->citem = tspan->ctspan; + tspan->cobject = tspan->ctspan; + tspan->role = SP_TSPAN_ROLE_UNSPECIFIED; new (&tspan->attributes) TextTagAttributes; } -static void -sp_tspan_release(SPObject *object) -{ +void CTSpan::onRelease() { + SPTSpan* object = this->sptspan; + SPTSpan *tspan = SP_TSPAN(object); tspan->attributes.~TextTagAttributes(); - if (((SPObjectClass *) tspan_parent_class)->release) - ((SPObjectClass *) tspan_parent_class)->release(object); + CItem::onRelease(); } static void -sp_tspan_build(SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr) +sp_tspan_release(SPObject *object) { - //SPTSpan *tspan = SP_TSPAN(object); + ((SPTSpan*)object)->ctspan->onRelease(); +} + +void CTSpan::onBuild(SPDocument *doc, Inkscape::XML::Node *repr) { + SPTSpan* object = this->sptspan; object->readAttr( "x" ); object->readAttr( "y" ); @@ -139,13 +153,18 @@ sp_tspan_build(SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr) object->readAttr( "rotate" ); object->readAttr( "sodipodi:role" ); - if (((SPObjectClass *) tspan_parent_class)->build) - ((SPObjectClass *) tspan_parent_class)->build(object, doc, repr); + CItem::onBuild(doc, repr); } static void -sp_tspan_set(SPObject *object, unsigned key, gchar const *value) +sp_tspan_build(SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr) { + ((SPTSpan*)object)->ctspan->onBuild(doc, repr); +} + +void CTSpan::onSet(unsigned int key, const gchar* value) { + SPTSpan* object = this->sptspan; + SPTSpan *tspan = SP_TSPAN(object); if (tspan->attributes.readSingleAttribute(key, value)) { @@ -160,18 +179,22 @@ sp_tspan_set(SPObject *object, unsigned key, gchar const *value) } break; default: - if (((SPObjectClass *) tspan_parent_class)->set) - (((SPObjectClass *) tspan_parent_class)->set)(object, key, value); + CItem::onSet(key, value); break; } } } -static void sp_tspan_update(SPObject *object, SPCtx *ctx, guint flags) +static void +sp_tspan_set(SPObject *object, unsigned key, gchar const *value) { - if (((SPObjectClass *) tspan_parent_class)->update) { - ((SPObjectClass *) tspan_parent_class)->update(object, ctx, flags); - } + ((SPTSpan*)object)->ctspan->onSet(key, value); +} + +void CTSpan::onUpdate(SPCtx *ctx, guint flags) { + SPTSpan* object = this->sptspan; + + CItem::onUpdate(ctx, flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -185,11 +208,20 @@ static void sp_tspan_update(SPObject *object, SPCtx *ctx, guint flags) } } -static void sp_tspan_modified(SPObject *object, unsigned flags) +static void sp_tspan_update(SPObject *object, SPCtx *ctx, guint flags) { - if (((SPObjectClass *) tspan_parent_class)->modified) { - ((SPObjectClass *) tspan_parent_class)->modified(object, flags); - } + ((SPTSpan*)object)->ctspan->onUpdate(ctx, flags); +} + +void CTSpan::onModified(unsigned int flags) { + SPTSpan* object = this->sptspan; + + // CPPIFY: This doesn't make no sense. + // CObject::onModified is pure and CItem doesn't override this method. What was the idea behind these lines? +// if (((SPObjectClass *) tspan_parent_class)->modified) { +// ((SPObjectClass *) tspan_parent_class)->modified(object, flags); +// } +// CItem::onModified(flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -203,9 +235,14 @@ static void sp_tspan_modified(SPObject *object, unsigned flags) } } -static Geom::OptRect -sp_tspan_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) +static void sp_tspan_modified(SPObject *object, unsigned flags) { + ((SPTSpan*)object)->ctspan->onModified(flags); +} + +Geom::OptRect CTSpan::onBbox(Geom::Affine const &transform, SPItem::BBoxType type) { + SPTSpan* item = this->sptspan; + Geom::OptRect bbox; // find out the ancestor text which holds our layout SPObject const *parent_text = item; @@ -229,9 +266,15 @@ sp_tspan_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxTyp return bbox; } -static Inkscape::XML::Node * -sp_tspan_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static Geom::OptRect +sp_tspan_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) { + return ((SPTSpan*)item)->ctspan->onBbox(transform, type); +} + +Inkscape::XML::Node* CTSpan::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPTSpan* object = this->sptspan; + SPTSpan *tspan = SP_TSPAN(object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { @@ -272,21 +315,31 @@ sp_tspan_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML } } - if (((SPObjectClass *) tspan_parent_class)->write) { - ((SPObjectClass *) tspan_parent_class)->write(object, xml_doc, repr, flags); - } + CItem::onWrite(xml_doc, repr, flags); return repr; } -static char * -sp_tspan_description(SPItem *item) +static Inkscape::XML::Node * +sp_tspan_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - g_return_val_if_fail(SP_IS_TSPAN(item), NULL); + return ((SPTSpan*)object)->ctspan->onWrite(xml_doc, repr, flags); +} + +gchar* CTSpan::onDescription() { + SPTSpan* item = this->sptspan; + + g_return_val_if_fail(SP_IS_TSPAN(item), NULL); return g_strdup(_("Text span")); } +static char * +sp_tspan_description(SPItem *item) +{ + return ((SPTSpan*)item)->ctspan->onDescription(); +} + /*##################################################### # SPTEXTPATH @@ -350,9 +403,21 @@ static void sp_textpath_class_init(SPTextPathClass *classname) sp_object_class->write = sp_textpath_write; } + +CTextPath::CTextPath(SPTextPath* textpath) : CItem(textpath) { + this->sptextpath = textpath; +} + +CTextPath::~CTextPath() { +} + static void sp_textpath_init(SPTextPath *textpath) { + textpath->ctextpath = new CTextPath(textpath); + textpath->citem = textpath->ctextpath; + textpath->cobject = textpath->ctextpath; + new (&textpath->attributes) TextTagAttributes; textpath->startOffset._set = false; @@ -371,9 +436,9 @@ sp_textpath_finalize(GObject *obj) delete textpath->sourcePath; } -static void -sp_textpath_release(SPObject *object) -{ +void CTextPath::onRelease() { + SPTextPath* object = this->sptextpath; + SPTextPath *textpath = SP_TEXTPATH(object); textpath->attributes.~TextTagAttributes(); @@ -381,12 +446,18 @@ sp_textpath_release(SPObject *object) if (textpath->originalPath) delete textpath->originalPath; textpath->originalPath = NULL; - if (((SPObjectClass *) textpath_parent_class)->release) - ((SPObjectClass *) textpath_parent_class)->release(object); + CItem::onRelease(); } -static void sp_textpath_build(SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr) +static void +sp_textpath_release(SPObject *object) { + ((SPTextPath*)object)->ctextpath->onRelease(); +} + +void CTextPath::onBuild(SPDocument *doc, Inkscape::XML::Node *repr) { + SPTextPath* object = this->sptextpath; + object->readAttr( "x" ); object->readAttr( "y" ); object->readAttr( "dx" ); @@ -410,14 +481,17 @@ static void sp_textpath_build(SPObject *object, SPDocument *doc, Inkscape::XML:: repr->addChild(rch, NULL); } - if (((SPObjectClass *) textpath_parent_class)->build) { - ((SPObjectClass *) textpath_parent_class)->build(object, doc, repr); - } + CItem::onBuild(doc, repr); } -static void -sp_textpath_set(SPObject *object, unsigned key, gchar const *value) +static void sp_textpath_build(SPObject *object, SPDocument *doc, Inkscape::XML::Node *repr) { + ((SPTextPath*)object)->ctextpath->onBuild(doc, repr); +} + +void CTextPath::onSet(unsigned int key, const gchar* value) { + SPTextPath* object = this->sptextpath; + SPTextPath *textpath = SP_TEXTPATH(object); if (textpath->attributes.readSingleAttribute(key, value)) { @@ -432,15 +506,21 @@ sp_textpath_set(SPObject *object, unsigned key, gchar const *value) object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); break; default: - if (((SPObjectClass *) textpath_parent_class)->set) - (((SPObjectClass *) textpath_parent_class)->set)(object, key, value); + CItem::onSet(key, value); break; } } } -static void sp_textpath_update(SPObject *object, SPCtx *ctx, guint flags) +static void +sp_textpath_set(SPObject *object, unsigned key, gchar const *value) { + ((SPTextPath*)object)->ctextpath->onSet(key, value); +} + +void CTextPath::onUpdate(SPCtx *ctx, guint flags) { + SPTextPath* object = this->sptextpath; + SPTextPath *textpath = SP_TEXTPATH(object); textpath->isUpdating = true; @@ -449,9 +529,7 @@ static void sp_textpath_update(SPObject *object, SPCtx *ctx, guint flags) } textpath->isUpdating = false; - if (((SPObjectClass *) textpath_parent_class)->update) { - ((SPObjectClass *) textpath_parent_class)->update(object, ctx, flags); - } + CItem::onUpdate(ctx, flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -465,6 +543,11 @@ static void sp_textpath_update(SPObject *object, SPCtx *ctx, guint flags) } } +static void sp_textpath_update(SPObject *object, SPCtx *ctx, guint flags) +{ + ((SPTextPath*)object)->ctextpath->onUpdate(ctx, flags); +} + void refresh_textpath_source(SPTextPath* tp) { @@ -486,11 +569,15 @@ void refresh_textpath_source(SPTextPath* tp) } } -static void sp_textpath_modified(SPObject *object, unsigned flags) -{ - if (((SPObjectClass *) textpath_parent_class)->modified) { - ((SPObjectClass *) textpath_parent_class)->modified(object, flags); - } +void CTextPath::onModified(unsigned int flags) { + SPTextPath* object = this->sptextpath; + + // CPPIFY: This doesn't make no sense. + // CObject::onModified is pure and CItem doesn't override this method. What was the idea behind these lines? +// if (((SPObjectClass *) textpath_parent_class)->modified) { +// ((SPObjectClass *) textpath_parent_class)->modified(object, flags); +// } +// CItem::onModified(flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -503,9 +590,15 @@ static void sp_textpath_modified(SPObject *object, unsigned flags) } } } -static Inkscape::XML::Node * -sp_textpath_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) + +static void sp_textpath_modified(SPObject *object, unsigned flags) { + ((SPTextPath*)object)->ctextpath->onModified(flags); +} + +Inkscape::XML::Node* CTextPath::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPTextPath* object = this->sptextpath; + SPTextPath *textpath = SP_TEXTPATH(object); if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { @@ -559,13 +652,17 @@ sp_textpath_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape:: } } - if (((SPObjectClass *) textpath_parent_class)->write) { - ((SPObjectClass *) textpath_parent_class)->write(object, xml_doc, repr, flags); - } + CItem::onWrite(xml_doc, repr, flags); return repr; } +static Inkscape::XML::Node * +sp_textpath_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPTextPath*)object)->ctextpath->onWrite(xml_doc, repr, flags); +} + SPItem * sp_textpath_get_path_item(SPTextPath *tp) diff --git a/src/sp-tspan.h b/src/sp-tspan.h index 3672fd3b5..79df014bd 100644 --- a/src/sp-tspan.h +++ b/src/sp-tspan.h @@ -23,7 +23,12 @@ enum { SP_TSPAN_ROLE_LINE }; -struct SPTSpan : public SPItem { +class CTSpan; + +class SPTSpan : public SPItem { +public: + CTSpan* ctspan; + guint role : 2; TextTagAttributes attributes; }; @@ -32,6 +37,27 @@ struct SPTSpanClass { SPItemClass parent_class; }; + +class CTSpan : public CItem { +public: + CTSpan(SPTSpan* span); + virtual ~CTSpan(); + + virtual void onBuild(SPDocument* doc, Inkscape::XML::Node* repr); + virtual void onRelease(); + virtual void onSet(unsigned int key, const gchar* value); + virtual void onUpdate(SPCtx* ctx, unsigned int flags); + virtual void onModified(unsigned int flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags); + + virtual Geom::OptRect onBbox(Geom::Affine const &transform, SPItem::BBoxType type); + virtual gchar* onDescription(); + +protected: + SPTSpan* sptspan; +}; + + GType sp_tspan_get_type(); -- cgit v1.2.3 From 1283ff19f8baabbea8fae03faddce5e27acbb110 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Mon, 20 Aug 2012 00:38:14 +0200 Subject: Added "virtual pad" to SPTRef. (bzr r11608.1.28) --- src/sp-tref.cpp | 131 +++++++++++++++++++++++++++++++++++++------------------- src/sp-tref.h | 28 +++++++++++- 2 files changed, 113 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/sp-tref.cpp b/src/sp-tref.cpp index 938b7c7cc..0c7e52d60 100644 --- a/src/sp-tref.cpp +++ b/src/sp-tref.cpp @@ -115,9 +115,20 @@ sp_tref_class_init(SPTRefClass *tref_class) item_class->description = sp_tref_description; } +CTRef::CTRef(SPTRef* tref) : CItem(tref) { + this->sptref = tref; +} + +CTRef::~CTRef() { +} + static void sp_tref_init(SPTRef *tref) { + tref->ctref = new CTRef(tref); + tref->citem = tref->ctref; + tref->cobject = tref->ctref; + new (&tref->attributes) TextTagAttributes; tref->href = NULL; @@ -129,7 +140,6 @@ sp_tref_init(SPTRef *tref) tref->uriOriginalRef->changedSignal().connect(sigc::bind(sigc::ptr_fun(sp_tref_href_changed), tref)); } - static void sp_tref_finalize(GObject *obj) { @@ -141,16 +151,10 @@ sp_tref_finalize(GObject *obj) tref->_changed_connection.~connection(); } +void CTRef::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPTRef* object = this->sptref; -/** - * Reads the Inkscape::XML::Node, and initializes SPTRef variables. - */ -static void -sp_tref_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ - if (((SPObjectClass *) tref_parent_class)->build) { - ((SPObjectClass *) tref_parent_class)->build(object, document, repr); - } + CItem::onBuild(document, repr); object->readAttr( "xlink:href" ); object->readAttr( "x" ); @@ -161,11 +165,17 @@ sp_tref_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) } /** - * Drops any allocated memory. + * Reads the Inkscape::XML::Node, and initializes SPTRef variables. */ static void -sp_tref_release(SPObject *object) +sp_tref_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { + ((SPTRef*)object)->ctref->onBuild(document, repr); +} + +void CTRef::onRelease() { + SPTRef* object = this->sptref; + SPTRef *tref = SP_TREF(object); tref->attributes.~TextTagAttributes(); @@ -178,16 +188,21 @@ sp_tref_release(SPObject *object) tref->uriOriginalRef->detach(); - if (((SPObjectClass *) tref_parent_class)->release) - ((SPObjectClass *) tref_parent_class)->release(object); + CItem::onRelease(); } /** - * Sets a specific value in the SPTRef. + * Drops any allocated memory. */ static void -sp_tref_set(SPObject *object, unsigned int key, gchar const *value) +sp_tref_release(SPObject *object) { + ((SPTRef*)object)->ctref->onRelease(); +} + +void CTRef::onSet(unsigned int key, const gchar* value) { + SPTRef* object = this->sptref; + debug("0x%p %s(%u): '%s'",object, sp_attribute_name(key),key,value ? value : ""); @@ -225,27 +240,27 @@ sp_tref_set(SPObject *object, unsigned int key, gchar const *value) } } else { // default - if (((SPObjectClass *) tref_parent_class)->set) { - ((SPObjectClass *) tref_parent_class)->set(object, key, value); - } + CItem::onSet(key, value); } - - } /** - * Receives update notifications. Code based on sp_use_update and sp_tspan_update. + * Sets a specific value in the SPTRef. */ static void -sp_tref_update(SPObject *object, SPCtx *ctx, guint flags) +sp_tref_set(SPObject *object, unsigned int key, gchar const *value) { + ((SPTRef*)object)->ctref->onSet(key, value); +} + +void CTRef::onUpdate(SPCtx *ctx, guint flags) { + SPTRef* object = this->sptref; + debug("0x%p",object); SPTRef *tref = SP_TREF(object); - if (((SPObjectClass *) tref_parent_class)->update) { - ((SPObjectClass *) tref_parent_class)->update(object, ctx, flags); - } + CItem::onUpdate(ctx, flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -259,13 +274,20 @@ sp_tref_update(SPObject *object, SPCtx *ctx, guint flags) child->updateDisplay(ctx, flags); } } - - } +/** + * Receives update notifications. Code based on sp_use_update and sp_tspan_update. + */ static void -sp_tref_modified(SPObject *object, guint flags) +sp_tref_update(SPObject *object, SPCtx *ctx, guint flags) { + ((SPTRef*)object)->ctref->onUpdate(ctx, flags); +} + +void CTRef::onModified(unsigned int flags) { + SPTRef* object = this->sptref; + SPTRef *tref_obj = SP_TREF(object); if (flags & SP_OBJECT_MODIFIED_FLAG) { @@ -284,12 +306,15 @@ sp_tref_modified(SPObject *object, guint flags) } } -/** - * Writes its settings to an incoming repr object, if any. - */ -static Inkscape::XML::Node * -sp_tref_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void +sp_tref_modified(SPObject *object, guint flags) { + ((SPTRef*)object)->ctref->onModified(flags); +} + +Inkscape::XML::Node* CTRef::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPTRef* object = this->sptref; + debug("0x%p",object); SPTRef *tref = SP_TREF(object); @@ -307,19 +332,23 @@ sp_tref_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML: g_free(uri_string); } - if (((SPObjectClass *) tref_parent_class)->write) { - ((SPObjectClass *) tref_parent_class)->write(object, xml_doc, repr, flags); - } + CItem::onWrite(xml_doc, repr, flags); return repr; } -/* - * The code for this function is swiped from the tspan bbox code, since tref should work pretty much the same way +/** + * Writes its settings to an incoming repr object, if any. */ -static Geom::OptRect -sp_tref_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) +static Inkscape::XML::Node * +sp_tref_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + return ((SPTRef*)object)->ctref->onWrite(xml_doc, repr, flags); +} + +Geom::OptRect CTRef::onBbox(Geom::Affine const &transform, SPItem::BBoxType type) { + SPTRef* item = this->sptref; + Geom::OptRect bbox; // find out the ancestor text which holds our layout SPObject const *parent_text = item; @@ -343,10 +372,18 @@ sp_tref_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType return bbox; } - -static gchar * -sp_tref_description(SPItem *item) +/* + * The code for this function is swiped from the tspan bbox code, since tref should work pretty much the same way + */ +static Geom::OptRect +sp_tref_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) { + return ((SPTRef*)item)->ctref->onBbox(transform, type); +} + +gchar* CTRef::onDescription() { + SPTRef* item = this->sptref; + SPTRef *tref = SP_TREF(item); if (tref) @@ -373,6 +410,12 @@ sp_tref_description(SPItem *item) return g_strdup(_("Orphaned cloned character data")); } +static gchar * +sp_tref_description(SPItem *item) +{ + return ((SPTRef*)item)->ctref->onDescription(); +} + /* For the sigc::connection changes (i.e. when the object being refered to changes) */ static void diff --git a/src/sp-tref.h b/src/sp-tref.h index cc80e48a8..448cb5e6e 100644 --- a/src/sp-tref.h +++ b/src/sp-tref.h @@ -29,9 +29,12 @@ #define SP_IS_TREF_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SP_TYPE_TREF)) class SPTRef; -class SPTRef; +class CTRef; + +class SPTRef : public SPItem { +public: + CTRef* ctref; -struct SPTRef : public SPItem { // Attributes that are used in the same way they would be in a tspan TextTagAttributes attributes; @@ -57,6 +60,27 @@ struct SPTRefClass { SPItemClass parent_class; }; + +class CTRef : public CItem { +public: + CTRef(SPTRef* tref); + virtual ~CTRef(); + + virtual void onBuild(SPDocument* doc, Inkscape::XML::Node* repr); + virtual void onRelease(); + virtual void onSet(unsigned int key, const gchar* value); + virtual void onUpdate(SPCtx* ctx, unsigned int flags); + virtual void onModified(unsigned int flags); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document* doc, Inkscape::XML::Node* repr, guint flags); + + virtual Geom::OptRect onBbox(Geom::Affine const &transform, SPItem::BBoxType type); + virtual gchar* onDescription(); + +protected: + SPTRef* sptref; +}; + + GType sp_tref_get_type(); void sp_tref_update_text(SPTRef *tref); -- cgit v1.2.3 From dc816bdcc37174e67992520342babb5ade6a9081 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Mon, 20 Aug 2012 00:54:02 +0200 Subject: Added "virtual pad" to SPUse. (bzr r11608.1.29) --- src/sp-use.cpp | 170 +++++++++++++++++++++++++++++++++++++++------------------ src/sp-use.h | 31 ++++++++++- 2 files changed, 146 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/sp-use.cpp b/src/sp-use.cpp index e39f560c3..eb089612b 100644 --- a/src/sp-use.cpp +++ b/src/sp-use.cpp @@ -113,9 +113,20 @@ sp_use_class_init(SPUseClass *classname) item_class->snappoints = sp_use_snappoints; } +CUse::CUse(SPUse* use) : CItem(use) { + this->spuse = use; +} + +CUse::~CUse() { +} + static void sp_use_init(SPUse *use) { + use->cuse = new CUse(use); + use->citem = use->cuse; + use->cobject = use->cuse; + use->x.unset(); use->y.unset(); use->width.unset(SVGLength::PERCENT, 1.0, 1.0); @@ -152,12 +163,10 @@ sp_use_finalize(GObject *obj) use->_transformed_connection.~connection(); } -static void -sp_use_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ - if (((SPObjectClass *) parent_class)->build) { - (* ((SPObjectClass *) parent_class)->build)(object, document, repr); - } +void CUse::onBuild(SPDocument *document, Inkscape::XML::Node *repr) { + SPUse* object = this->spuse; + + CItem::onBuild(document, repr); object->readAttr( "x" ); object->readAttr( "y" ); @@ -171,9 +180,14 @@ sp_use_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) } static void -sp_use_release(SPObject *object) +sp_use_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) { - SPUse *use = SP_USE(object); + ((SPUse*)object)->cuse->onBuild(document, repr); +} + +void CUse::onRelease() { + SPUse *use = this->spuse; + SPUse* object = use; if (use->child) { object->detach(use->child); @@ -189,15 +203,18 @@ sp_use_release(SPObject *object) use->ref->detach(); - if (((SPObjectClass *) parent_class)->release) { - ((SPObjectClass *) parent_class)->release(object); - } + CItem::onRelease(); } static void -sp_use_set(SPObject *object, unsigned key, gchar const *value) +sp_use_release(SPObject *object) { - SPUse *use = SP_USE(object); + ((SPUse*)object)->cuse->onRelease(); +} + +void CUse::onSet(unsigned int key, const gchar* value) { + SPUse *use = this->spuse; + SPUse* object = use; switch (key) { case SP_ATTR_X: @@ -242,25 +259,25 @@ sp_use_set(SPObject *object, unsigned key, gchar const *value) } default: - if (((SPObjectClass *) parent_class)->set) { - ((SPObjectClass *) parent_class)->set(object, key, value); - } + CItem::onSet(key, value); break; } } -static Inkscape::XML::Node * -sp_use_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) +static void +sp_use_set(SPObject *object, unsigned key, gchar const *value) { - SPUse *use = SP_USE(object); + ((SPUse*)object)->cuse->onSet(key, value); +} + +Inkscape::XML::Node* CUse::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPUse *use = this->spuse; if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:use"); } - if (((SPObjectClass *) (parent_class))->write) { - ((SPObjectClass *) (parent_class))->write(object, xml_doc, repr, flags); - } + CItem::onWrite(xml_doc, repr, flags); sp_repr_set_svg_double(repr, "x", use->x.computed); sp_repr_set_svg_double(repr, "y", use->y.computed); @@ -276,10 +293,15 @@ sp_use_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML:: return repr; } -static Geom::OptRect -sp_use_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) +static Inkscape::XML::Node * +sp_use_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { - SPUse const *use = SP_USE(item); + return ((SPUse*)object)->cuse->onWrite(xml_doc, repr, flags); +} + +Geom::OptRect CUse::onBbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype) { + SPUse const *use = this->spuse; + Geom::OptRect bbox; if (use->child && SP_IS_ITEM(use->child)) { @@ -288,16 +310,21 @@ sp_use_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType * Geom::Translate(use->x.computed, use->y.computed) * transform ); - bbox = child->bounds(type, ct); + bbox = child->bounds(bboxtype, ct); } return bbox; } -static void -sp_use_print(SPItem *item, SPPrintContext *ctx) +static Geom::OptRect +sp_use_bbox(SPItem const *item, Geom::Affine const &transform, SPItem::BBoxType type) { + return ((SPUse*)item)->cuse->onBbox(transform, type); +} + +void CUse::onPrint(SPPrintContext* ctx) { + SPUse *use = this->spuse; + bool translated = false; - SPUse *use = SP_USE(item); if ((use->x._set && use->x.computed != 0) || (use->y._set && use->y.computed != 0)) { Geom::Affine tp(Geom::Translate(use->x.computed, use->y.computed)); @@ -314,10 +341,14 @@ sp_use_print(SPItem *item, SPPrintContext *ctx) } } -static gchar * -sp_use_description(SPItem *item) +static void +sp_use_print(SPItem *item, SPPrintContext *ctx) { - SPUse *use = SP_USE(item); + ((SPUse*)item)->cuse->onPrint(ctx); +} + +gchar* CUse::onDescription() { + SPUse *use = this->spuse; char *ret; if (use->child) { @@ -341,10 +372,15 @@ sp_use_description(SPItem *item) } } -static Inkscape::DrawingItem * -sp_use_show(SPItem *item, Inkscape::Drawing &drawing, unsigned key, unsigned flags) +static gchar * +sp_use_description(SPItem *item) { - SPUse *use = SP_USE(item); + return ((SPUse*)item)->cuse->onDescription(); +} + +Inkscape::DrawingItem* CUse::onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags) { + SPUse *use = this->spuse; + SPUse* item = use; Inkscape::DrawingGroup *ai = new Inkscape::DrawingGroup(drawing); ai->setPickChildren(false); @@ -363,18 +399,26 @@ sp_use_show(SPItem *item, Inkscape::Drawing &drawing, unsigned key, unsigned fla return ai; } -static void -sp_use_hide(SPItem *item, unsigned key) +static Inkscape::DrawingItem * +sp_use_show(SPItem *item, Inkscape::Drawing &drawing, unsigned key, unsigned flags) { - SPUse *use = SP_USE(item); + return ((SPUse*)item)->cuse->onShow(drawing, key, flags); +} + +void CUse::onHide(unsigned int key) { + SPUse *use = this->spuse; if (use->child) { SP_ITEM(use->child)->invoke_hide(key); } - if (((SPItemClass *) parent_class)->hide) { - ((SPItemClass *) parent_class)->hide(item, key); - } + CItem::onHide(key); +} + +static void +sp_use_hide(SPItem *item, unsigned key) +{ + ((SPUse*)item)->cuse->onHide(key); } /** @@ -569,16 +613,15 @@ sp_use_delete_self(SPObject */*deleted*/, SPUse *self) } } -static void -sp_use_update(SPObject *object, SPCtx *ctx, unsigned flags) -{ +void CUse::onUpdate(SPCtx *ctx, unsigned flags) { + SPUse* object = this->spuse; + SPItem *item = SP_ITEM(object); SPUse *use = SP_USE(object); SPItemCtx *ictx = (SPItemCtx *) ctx; SPItemCtx cctx = *ictx; - if (((SPObjectClass *) (parent_class))->update) - ((SPObjectClass *) (parent_class))->update(object, ctx, flags); + CItem::onUpdate(ctx, flags); if (flags & SP_OBJECT_MODIFIED_FLAG) { flags |= SP_OBJECT_PARENT_MODIFIED_FLAG; @@ -633,8 +676,14 @@ sp_use_update(SPObject *object, SPCtx *ctx, unsigned flags) } static void -sp_use_modified(SPObject *object, guint flags) +sp_use_update(SPObject *object, SPCtx *ctx, unsigned flags) { + ((SPUse*)object)->cuse->onUpdate(ctx, flags); +} + +void CUse::onModified(unsigned int flags) { + SPUse* object = this->spuse; + SPUse *use_obj = SP_USE(object); if (flags & SP_OBJECT_MODIFIED_FLAG) { @@ -659,6 +708,12 @@ sp_use_modified(SPObject *object, guint flags) } } +static void +sp_use_modified(SPObject *object, guint flags) +{ + return ((SPUse*)object)->cuse->onModified(flags); +} + SPItem *sp_use_unlink(SPUse *use) { if (!use) { @@ -752,9 +807,9 @@ SPItem *sp_use_get_original(SPUse *use) return ref; } -static void -sp_use_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) -{ +void CUse::onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs) { + SPUse* item = this->spuse; + g_assert (item != NULL); g_assert (SP_IS_ITEM(item)); g_assert (SP_IS_USE(item)); @@ -764,10 +819,17 @@ sp_use_snappoints(SPItem const *item, std::vector if (!root) return; - SPItemClass const &item_class = *(SPItemClass const *) G_OBJECT_GET_CLASS(root); - if (item_class.snappoints) { - item_class.snappoints(root, p, snapprefs); - } +// SPItemClass const &item_class = *(SPItemClass const *) G_OBJECT_GET_CLASS(root); +// if (item_class.snappoints) { +// item_class.snappoints(root, p, snapprefs); +// } + root->citem->onSnappoints(p, snapprefs); +} + +static void +sp_use_snappoints(SPItem const *item, std::vector &p, Inkscape::SnapPreferences const *snapprefs) +{ + ((SPUse*)item)->cuse->onSnappoints(p, snapprefs); } diff --git a/src/sp-use.h b/src/sp-use.h index 399f30a4c..013c03228 100644 --- a/src/sp-use.h +++ b/src/sp-use.h @@ -28,8 +28,12 @@ class SPUse; class SPUseClass; class SPUseReference; +class CUse; + +class SPUse : public SPItem { +public: + CUse* cuse; -struct SPUse : public SPItem { // item built from the original's repr (the visible clone) // relative to the SPUse itself, it is treated as a child, similar to a grouped item relative to its group SPObject *child; @@ -56,6 +60,31 @@ struct SPUseClass { SPItemClass parent_class; }; + +class CUse : public CItem { +public: + CUse(SPUse* use); + virtual ~CUse(); + + virtual void onBuild(SPDocument* doc, Inkscape::XML::Node* repr); + virtual void onRelease(); + virtual void onSet(unsigned key, gchar const *value); + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + virtual void onUpdate(SPCtx* ctx, unsigned int flags); + virtual void onModified(unsigned int flags); + + virtual Geom::OptRect onBbox(Geom::Affine const &transform, SPItem::BBoxType bboxtype); + virtual gchar* onDescription(); + virtual void onPrint(SPPrintContext *ctx); + virtual Inkscape::DrawingItem* onShow(Inkscape::Drawing &drawing, unsigned int key, unsigned int flags); + virtual void onHide(unsigned int key); + virtual void onSnappoints(std::vector &p, Inkscape::SnapPreferences const *snapprefs); + +protected: + SPUse* spuse; +}; + + GType sp_use_get_type (void); SPItem *sp_use_unlink (SPUse *use); -- cgit v1.2.3 From 3e79e62687153095acc0c2e7dc6865905d33a827 Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Mon, 20 Aug 2012 08:29:15 +0200 Subject: As all subclasses of SPItem now have "virtual pads" with correct inheritance, all virtual function calls in SPItem were converted to C++ style. (bzr r11608.1.30) --- src/sp-item.cpp | 120 +++++++++++++++++++++++--------------------------------- 1 file changed, 50 insertions(+), 70 deletions(-) (limited to 'src') diff --git a/src/sp-item.cpp b/src/sp-item.cpp index 20b6b3ef3..e6cc563f6 100644 --- a/src/sp-item.cpp +++ b/src/sp-item.cpp @@ -777,10 +777,10 @@ Geom::OptRect CItem::onBbox(Geom::Affine const &transform, SPItem::BBoxType type Geom::OptRect SPItem::geometricBounds(Geom::Affine const &transform) const { Geom::OptRect bbox; + // call the subclass method - if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->bbox) { - bbox = ((SPItemClass *) G_OBJECT_GET_CLASS(this))->bbox(this, transform, SPItem::GEOMETRIC_BBOX); - } + bbox = this->citem->onBbox(transform, SPItem::GEOMETRIC_BBOX); + return bbox; } @@ -797,10 +797,8 @@ Geom::OptRect SPItem::visualBounds(Geom::Affine const &transform) const Geom::OptRect bbox; if ( style && style->filter.href && style->getFilter() && SP_IS_FILTER(style->getFilter())) { - // call the subclass method - if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->bbox) { - bbox = ((SPItemClass *) G_OBJECT_GET_CLASS(this))->bbox(this, Geom::identity(), SPItem::VISUAL_BBOX); - } + // call the subclass method + bbox = this->citem->onBbox(Geom::identity(), SPItem::VISUAL_BBOX); SPFilter *filter = SP_FILTER(style->getFilter()); // default filer area per the SVG spec: @@ -843,10 +841,8 @@ Geom::OptRect SPItem::visualBounds(Geom::Affine const &transform) const bbox = Geom::OptRect(minp, maxp); *bbox *= transform; } else { - // call the subclass method - if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->bbox) { - bbox = ((SPItemClass *) G_OBJECT_GET_CLASS(this))->bbox(this, transform, SPItem::VISUAL_BBOX); - } + // call the subclass method + bbox = this->citem->onBbox(transform, SPItem::VISUAL_BBOX); } if (clip_ref->getObject()) { bbox.intersectWith(SP_CLIPPATH(clip_ref->getObject())->geometricBounds(transform)); @@ -962,10 +958,7 @@ void SPItem::sp_item_private_snappoints(SPItem const * /*item*/, std::vector &p, Inkscape::SnapPreferences const *snapprefs) const { // Get the snappoints of the item - SPItemClass const &item_class = *(SPItemClass const *) G_OBJECT_GET_CLASS(this); - if (item_class.snappoints) { - item_class.snappoints(this, p, snapprefs); - } + this->citem->onSnappoints(p, snapprefs); // Get the snappoints at the item's center if (snapprefs != NULL && snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER)) { @@ -1008,17 +1001,13 @@ void CItem::onPrint(SPPrintContext* ctx) { void SPItem::invoke_print(SPPrintContext *ctx) { if ( !isHidden() ) { - if ( reinterpret_cast(G_OBJECT_GET_CLASS(this))->print ) { - if (!transform.isIdentity() - || style->opacity.value != SP_SCALE24_MAX) - { - sp_print_bind(ctx, transform, SP_SCALE24_TO_FLOAT(style->opacity.value)); - reinterpret_cast(G_OBJECT_GET_CLASS(this))->print(this, ctx); - sp_print_release(ctx); - } else { - reinterpret_cast(G_OBJECT_GET_CLASS(this))->print(this, ctx); - } - } + if (!transform.isIdentity() || style->opacity.value != SP_SCALE24_MAX) { + sp_print_bind(ctx, transform, SP_SCALE24_TO_FLOAT(style->opacity.value)); + this->citem->onPrint(ctx); + sp_print_release(ctx); + } else { + this->citem->onPrint(ctx); + } } } @@ -1040,34 +1029,29 @@ gchar *SPItem::sp_item_private_description(SPItem *item) */ gchar *SPItem::description() { - if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->description) { - gchar *s = ((SPItemClass *) G_OBJECT_GET_CLASS(this))->description(this); - if (s && clip_ref->getObject()) { - gchar *snew = g_strdup_printf (_("%s; clipped"), s); - g_free (s); - s = snew; - } - if (s && mask_ref->getObject()) { - gchar *snew = g_strdup_printf (_("%s; masked"), s); - g_free (s); - s = snew; - } - if ( style && style->filter.href && style->filter.href->getObject() ) { - const gchar *label = style->filter.href->getObject()->label(); - gchar *snew = 0; - if (label) { - snew = g_strdup_printf (_("%s; filtered (%s)"), s, _(label)); - } else { - snew = g_strdup_printf (_("%s; filtered"), s); - } - g_free (s); - s = snew; - } - return s; - } - - g_assert_not_reached(); - return NULL; + gchar* s = this->citem->onDescription(); + if (s && clip_ref->getObject()) { + gchar *snew = g_strdup_printf (_("%s; clipped"), s); + g_free (s); + s = snew; + } + if (s && mask_ref->getObject()) { + gchar *snew = g_strdup_printf (_("%s; masked"), s); + g_free (s); + s = snew; + } + if ( style && style->filter.href && style->filter.href->getObject() ) { + const gchar *label = style->filter.href->getObject()->label(); + gchar *snew = 0; + if (label) { + snew = g_strdup_printf (_("%s; filtered (%s)"), s, _(label)); + } else { + snew = g_strdup_printf (_("%s; filtered"), s); + } + g_free (s); + s = snew; + } + return s; } /** @@ -1077,9 +1061,11 @@ gchar *SPItem::description() int SPItem::ifilt() { int retval=0; - if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->description) { - if ( style && style->filter.href && style->filter.href->getObject() ) { retval=1; } - } + + if ( style && style->filter.href && style->filter.href->getObject() ) { + retval=1; + } + return retval; } @@ -1106,9 +1092,8 @@ Inkscape::DrawingItem* CItem::onShow(Inkscape::Drawing &drawing, unsigned int ke Inkscape::DrawingItem *SPItem::invoke_show(Inkscape::Drawing &drawing, unsigned key, unsigned flags) { Inkscape::DrawingItem *ai = NULL; - if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->show) { - ai = ((SPItemClass *) G_OBJECT_GET_CLASS(this))->show(this, drawing, key, flags); - } + + ai = this->citem->onShow(drawing, key, flags); if (ai != NULL) { Geom::OptRect item_bbox = geometricBounds(); @@ -1164,9 +1149,7 @@ void CItem::onHide(unsigned int key) { void SPItem::invoke_hide(unsigned key) { - if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->hide) { - ((SPItemClass *) G_OBJECT_GET_CLASS(this))->hide(this, key); - } + this->citem->onHide(key); SPItemView *ref = NULL; SPItemView *v = display; @@ -1461,13 +1444,14 @@ void SPItem::doWriteTransform(Inkscape::XML::Node *repr, Geom::Affine const &tra gint preserve = prefs->getBool("/options/preservetransform/value", 0); Geom::Affine transform_attr (transform); if ( // run the object's set_transform (i.e. embed transform) only if: - ((SPItemClass *) G_OBJECT_GET_CLASS(this))->set_transform && // it does have a set_transform method !preserve && // user did not chose to preserve all transforms !clip_ref->getObject() && // the object does not have a clippath !mask_ref->getObject() && // the object does not have a mask !(!transform.isTranslation() && style && style->getFilter()) // the object does not have a filter, or the transform is translation (which is supposed to not affect filters) ) { - transform_attr = ((SPItemClass *) G_OBJECT_GET_CLASS(this))->set_transform(this, transform); + + transform_attr = this->citem->onSetTransform(transform); + if (freeze_stroke_width) { freeze_stroke_width_recursive(false); } @@ -1505,11 +1489,7 @@ gint CItem::onEvent(SPEvent* event) { gint SPItem::emitEvent(SPEvent &event) { - if (((SPItemClass *) G_OBJECT_GET_CLASS(this))->event) { - return ((SPItemClass *) G_OBJECT_GET_CLASS(this))->event(this, &event); - } - - return FALSE; + return this->citem->onEvent(&event); } /** -- cgit v1.2.3 From fa1b664180baa1ec99b8d5b9ec7c8b21c7203c9f Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Mon, 20 Aug 2012 23:48:42 +0200 Subject: Added "virtual pad" to SPTitle. (bzr r11608.1.31) --- src/sp-title.cpp | 33 +++++++++++++++++++++++---------- src/sp-title.h | 18 +++++++++++++++++- 2 files changed, 40 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/sp-title.cpp b/src/sp-title.cpp index ddeccede2..c7739823c 100644 --- a/src/sp-title.cpp +++ b/src/sp-title.cpp @@ -52,23 +52,36 @@ sp_title_class_init(SPTitleClass *klass) sp_object_class->write = sp_title_write; } +CTitle::CTitle(SPTitle* title) : CObject(title) { + this->sptitle = title; +} + +CTitle::~CTitle() { +} + static void -sp_title_init(SPTitle */*desc*/) +sp_title_init(SPTitle *desc) { + desc->ctitle = new CTitle(desc); + desc->cobject = desc->ctitle; } -/** - * Writes it's settings to an incoming repr object, if any. - */ -static Inkscape::XML::Node *sp_title_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) -{ +Inkscape::XML::Node* CTitle::onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags) { + SPTitle* object = this->sptitle; + if (!repr) { - repr = object->getRepr()->duplicate(doc); + repr = object->getRepr()->duplicate(xml_doc); } - if (((SPObjectClass *) title_parent_class)->write) { - ((SPObjectClass *) title_parent_class)->write(object, doc, repr, flags); - } + CObject::onWrite(xml_doc, repr, flags); return repr; } + +/** + * Writes it's settings to an incoming repr object, if any. + */ +static Inkscape::XML::Node *sp_title_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags) +{ + return ((SPTitle*)object)->ctitle->onWrite(doc, repr, flags); +} diff --git a/src/sp-title.h b/src/sp-title.h index a5f0a2fea..a048b6a55 100644 --- a/src/sp-title.h +++ b/src/sp-title.h @@ -19,14 +19,30 @@ class SPTitle; class SPTitleClass; +class CTitle; -struct SPTitle : public SPObject { +class SPTitle : public SPObject { +public: + CTitle* ctitle; }; struct SPTitleClass { SPObjectClass parent_class; }; + +class CTitle : public CObject { +public: + CTitle(SPTitle* title); + virtual ~CTitle(); + + virtual Inkscape::XML::Node* onWrite(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags); + +protected: + SPTitle* sptitle; +}; + + GType sp_title_get_type (void); #endif -- cgit v1.2.3 From 791de080f5a2377d4801b276b1f3bba797a24caa Mon Sep 17 00:00:00 2001 From: Markus Engel Date: Mon, 20 Aug 2012 23:58:18 +0200 Subject: Added "virtual pad" to SPStyleElem. (bzr r11608.1.32) --- src/sp-style-elem.cpp | 69 ++++++++++++++++++++++++++++++++++++--------------- src/sp-style-elem.h | 20 +++++++++++++++ 2 files changed, 69 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/sp-style-elem.cpp b/src/sp-style-elem.cpp index 2e14ae5ff..71eb87b8c 100644 --- a/src/sp-style-elem.cpp +++ b/src/sp-style-elem.cpp @@ -51,16 +51,26 @@ sp_style_elem_class_init(SPStyleElemClass *klass) klass->write = sp_style_elem_write; } +CStyleElem::CStyleElem(SPStyleElem* se) : CObject(se) { + this->spstyleelem = se; +} + +CStyleElem::~CStyleElem() { +} + static void sp_style_elem_init(SPStyleElem *style_elem) { + style_elem->cstyleelem = new CStyleElem(style_elem); + style_elem->cobject = style_elem->cstyleelem; + media_set_all(style_elem->media); style_elem->is_css = false; } -static void -sp_style_elem_set(SPObject *object, unsigned const key, gchar const *const value) -{ +void CStyleElem::onSet(unsigned int key, const gchar* value) { + SPStyleElem* object = this->spstyleelem; + g_return_if_fail(object); SPStyleElem &style_elem = *SP_STYLE_ELEM(object); @@ -89,14 +99,18 @@ sp_style_elem_set(SPObject *object, unsigned const key, gchar const *const value /* title is ignored. */ default: { - if (parent_class->set) { - parent_class->set(object, key, value); - } + CObject::onSet(key, value); break; } } } +static void +sp_style_elem_set(SPObject *object, unsigned const key, gchar const *const value) +{ + ((SPStyleElem*)object)->cstyleelem->onSet(key, value); +} + static void child_add_rm_cb(Inkscape::XML::Node *, Inkscape::XML::Node *, Inkscape::XML::Node *, void *const data) @@ -119,9 +133,9 @@ child_order_changed_cb(Inkscape::XML::Node *, Inkscape::XML::Node *, sp_style_elem_read_content(static_cast(data)); } -static Inkscape::XML::Node * -sp_style_elem_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint const flags) -{ +Inkscape::XML::Node* CStyleElem::onWrite(Inkscape::XML::Document* xml_doc, Inkscape::XML::Node* repr, guint flags) { + SPStyleElem* object = this->spstyleelem; + if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { repr = xml_doc->createElement("svg:style"); } @@ -138,12 +152,17 @@ sp_style_elem_write(SPObject *const object, Inkscape::XML::Document *xml_doc, In } /* todo: media */ - if (((SPObjectClass *) parent_class)->write) - ((SPObjectClass *) parent_class)->write(object, xml_doc, repr, flags); + CObject::onWrite(xml_doc, repr, flags); return repr; } +static Inkscape::XML::Node * +sp_style_elem_write(SPObject *const object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint const flags) +{ + return ((SPStyleElem*)object)->cstyleelem->onWrite(xml_doc, repr, flags); +} + /** Returns the concatenation of the content of the text children of the specified object. */ static GString * @@ -297,9 +316,9 @@ property_cb(CRDocHandler *const a_handler, g_return_if_fail(append_status == CR_OK); } -static void -sp_style_elem_read_content(SPObject *const object) -{ +void CStyleElem::onReadContent() { + SPStyleElem* object = this->spstyleelem; + SPStyleElem &style_elem = *SP_STYLE_ELEM(object); /* fixme: If there's more than one