summaryrefslogtreecommitdiff
path: root/include/svx/svdobj.hxx
diff options
context:
space:
mode:
authorArmin Le Grand <Armin.Le.Grand@cib.de>2018-05-07 11:44:26 +0200
committerArmin Le Grand <Armin.Le.Grand@cib.de>2018-05-08 01:53:46 +0200
commit91b0d2122bdee361bf5412a42d48ff051159cbf2 (patch)
tree003ef60b93668847803a812486534ebc805e6546 /include/svx/svdobj.hxx
parentbdccb7e9991d83029eb2f2f11327b54534a00db8 (diff)
tdf#116977 secured ::Clone methods
Renamed SdrPage::Clone -> SdrPage::CloneSdrPage Renamed SdrObject::Clone -> SdrObject::CloneSdrObject Giving SdrModel is no longer an option, but a must (as reference). This makes future changes more safe by force usage to think about it. Also equals the constructors which already require a target SdrModel. Done the same for ::CloneSdrPage. Change-Id: I06f0129e15140bd8693db27a445037d7e2f7f652 Reviewed-on: https://gerrit.libreoffice.org/53933 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Armin Le Grand <Armin.Le.Grand@cib.de>
Diffstat (limited to 'include/svx/svdobj.hxx')
-rw-r--r--include/svx/svdobj.hxx24
1 files changed, 17 insertions, 7 deletions
diff --git a/include/svx/svdobj.hxx b/include/svx/svdobj.hxx
index c901dfa1416d..0972849dd74a 100644
--- a/include/svx/svdobj.hxx
+++ b/include/svx/svdobj.hxx
@@ -306,7 +306,7 @@ public:
// SwFlyDrawObj
/// Abstract DrawObject
-class SVX_DLLPUBLIC SdrObject: public SfxListener, public virtual tools::WeakBase
+class SVX_DLLPUBLIC SdrObject : public SfxListener, public virtual tools::WeakBase
{
private:
friend class SdrObjListIter;
@@ -479,11 +479,11 @@ public:
virtual bool HasLimitedRotation() const;
// Returns a copy of the object. Every inherited class must reimplement this (in class Foo
- // it should be sufficient to do "virtual Foo* Clone() const { return CloneHelper< Foo >(); }".
+ // it should be sufficient to do "virtual Foo* CloneSdrObject(...) const { return CloneHelper< Foo >(); }".
// Note that this function uses operator= internally.
- virtual SdrObject* Clone(SdrModel* pTargetModel = nullptr) const;
+ virtual SdrObject* CloneSdrObject(SdrModel& rTargetModel) const;
- // implemented mainly for the purposes of Clone()
+ // implemented mainly for the purposes of CloneSdrObject()
SdrObject& operator=(const SdrObject& rObj);
// TakeObjName...() is for the display in the UI, e.g. "3 frames selected"
@@ -982,7 +982,7 @@ protected:
virtual void impl_setUnoShape( const css::uno::Reference< css::uno::XInterface >& _rxUnoShape );
// helper function for reimplementing Clone().
- template< typename T > T* CloneHelper(SdrModel* pTargetModel) const;
+ template< typename T > T* CloneHelper(SdrModel& rTargetModel) const;
private:
struct Impl;
@@ -1025,6 +1025,16 @@ private:
SdrObject( const SdrObject& ) = delete;
};
+// helper for constructing std::unique_ptr for SdrObjects where a
+// deleter is needed - here, SdrObject::Free needs to be used.
+struct SVX_DLLPUBLIC SdrObjectFreeOp
+{
+ void operator()(SdrObject* obj)
+ {
+ SdrObject::Free(obj);
+ }
+};
+
/** Suppress BroadcastObjectChange() until destruction of the (last) instance.
Prevents multiple broadcasts for a sequence of calls that would trigger a
broadcast each. Instances may be nested in levels, the outer instance will
@@ -1076,12 +1086,12 @@ private:
SdrObjFactory() = delete;
};
-template< typename T > T* SdrObject::CloneHelper(SdrModel* pTargetModel) const
+template< typename T > T* SdrObject::CloneHelper(SdrModel& rTargetModel) const
{
OSL_ASSERT( typeid( T ) == typeid( *this ));
T* pObj = dynamic_cast< T* >(
SdrObjFactory::MakeNewObject(
- nullptr == pTargetModel ? getSdrModelFromSdrObject() : *pTargetModel,
+ rTargetModel,
GetObjInventor(),
GetObjIdentifier()));