summaryrefslogtreecommitdiff
path: root/basctl
diff options
context:
space:
mode:
authorNoel <noel.grandin@collabora.co.uk>2021-02-09 13:42:22 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-02-10 07:35:41 +0100
commit09cb778b6eb7d3a5b9029965a1320b49c90e7295 (patch)
tree63d75bc66ddbe4af5f6a52f4a0d65e9b199dbae7 /basctl
parentccdee8eebaa56619248e35001017226eecfe4e83 (diff)
clean up SdrObject cloning
using operator= implies that overwriting an SdrObject is a useful operation, but that is not at all true - they are typically linked into and referred to by many other things. So rather use a copy-constructor. Also clean up a couple of weird "do some stuff after the clone" code into the main copy constructor. Change-Id: Iefc1481b527602748b5f3abed06e7cca66c0581c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110633 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'basctl')
-rw-r--r--basctl/source/dlged/dlgedobj.cxx88
-rw-r--r--basctl/source/inc/dlgedobj.hxx8
2 files changed, 42 insertions, 54 deletions
diff --git a/basctl/source/dlged/dlgedobj.cxx b/basctl/source/dlged/dlgedobj.cxx
index 056006c4305e..e4047abace14 100644
--- a/basctl/source/dlged/dlgedobj.cxx
+++ b/basctl/source/dlged/dlgedobj.cxx
@@ -74,6 +74,44 @@ DlgEdObj::DlgEdObj(SdrModel& rSdrModel)
{
}
+DlgEdObj::DlgEdObj(SdrModel& rSdrModel, DlgEdObj const & rSource)
+: SdrUnoObj(rSdrModel, rSource)
+ ,bIsListening(false)
+{
+ // set parent form
+ pDlgEdForm = rSource.pDlgEdForm;
+
+ // add child to parent form
+ pDlgEdForm->AddChild( this );
+
+ Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
+ if ( xPSet.is() )
+ {
+ // set new name
+ OUString aOUniqueName( GetUniqueName() );
+ Any aUniqueName;
+ aUniqueName <<= aOUniqueName;
+ xPSet->setPropertyValue( DLGED_PROP_NAME, aUniqueName );
+
+ Reference< container::XNameContainer > xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY );
+ if ( xCont.is() )
+ {
+ // set tabindex
+ Sequence< OUString > aNames = xCont->getElementNames();
+ xPSet->setPropertyValue( DLGED_PROP_TABINDEX, Any(static_cast<sal_Int16>(aNames.getLength())) );
+
+ // insert control model in dialog model
+ Reference< awt::XControlModel > xCtrl( xPSet , UNO_QUERY );
+ xCont->insertByName( aOUniqueName, Any(xCtrl) );
+
+ pDlgEdForm->UpdateTabOrderAndGroups();
+ }
+ }
+
+ // start listening
+ StartListening();
+}
+
DlgEdObj::DlgEdObj(
SdrModel& rSdrModel,
const OUString& rModelName,
@@ -868,62 +906,16 @@ SdrObjKind DlgEdObj::GetObjIdentifier() const
}
}
-void DlgEdObj::clonedFrom(const DlgEdObj* _pSource)
-{
- // set parent form
- pDlgEdForm = _pSource->pDlgEdForm;
-
- // add child to parent form
- pDlgEdForm->AddChild( this );
-
- Reference< beans::XPropertySet > xPSet( GetUnoControlModel(), UNO_QUERY );
- if ( xPSet.is() )
- {
- // set new name
- OUString aOUniqueName( GetUniqueName() );
- Any aUniqueName;
- aUniqueName <<= aOUniqueName;
- xPSet->setPropertyValue( DLGED_PROP_NAME, aUniqueName );
-
- Reference< container::XNameContainer > xCont( GetDlgEdForm()->GetUnoControlModel() , UNO_QUERY );
- if ( xCont.is() )
- {
- // set tabindex
- Sequence< OUString > aNames = xCont->getElementNames();
- xPSet->setPropertyValue( DLGED_PROP_TABINDEX, Any(static_cast<sal_Int16>(aNames.getLength())) );
-
- // insert control model in dialog model
- Reference< awt::XControlModel > xCtrl( xPSet , UNO_QUERY );
- xCont->insertByName( aOUniqueName, Any(xCtrl) );
-
- pDlgEdForm->UpdateTabOrderAndGroups();
- }
- }
-
- // start listening
- StartListening();
-}
-
DlgEdObj* DlgEdObj::CloneSdrObject(SdrModel& rTargetModel) const
{
- DlgEdObj* pDlgEdObj = CloneHelper< DlgEdObj >(rTargetModel);
- DBG_ASSERT( pDlgEdObj != nullptr, "DlgEdObj::Clone: invalid clone!" );
- if ( pDlgEdObj )
- pDlgEdObj->clonedFrom( this );
-
- return pDlgEdObj;
+ return new DlgEdObj(rTargetModel, *this);
}
SdrObjectUniquePtr DlgEdObj::getFullDragClone() const
{
// no need to really add the clone for dragging, it's a temporary
// object
- SdrObjectUniquePtr pObj( new SdrUnoObj(
- getSdrModelFromSdrObject(),
- OUString()) );
- *pObj = *static_cast<const SdrUnoObj*>(this);
-
- return pObj;
+ return SdrObjectUniquePtr(new SdrUnoObj(getSdrModelFromSdrObject(), *this));
}
void DlgEdObj::NbcMove( const Size& rSize )
diff --git a/basctl/source/inc/dlgedobj.hxx b/basctl/source/inc/dlgedobj.hxx
index 8ae88ef5c80a..d5e29cf48caf 100644
--- a/basctl/source/inc/dlgedobj.hxx
+++ b/basctl/source/inc/dlgedobj.hxx
@@ -59,6 +59,8 @@ private:
protected:
DlgEdObj(SdrModel& rSdrModel);
+ // copy constructor
+ DlgEdObj(SdrModel& rSdrModel, DlgEdObj const & rSource);
DlgEdObj(
SdrModel& rSdrModel,
const OUString& rModelName,
@@ -91,11 +93,6 @@ protected:
sal_Int32& nXOut, sal_Int32& nYOut, sal_Int32& nWidthOut, sal_Int32& nHeightOut );
public:
- DlgEdObj(DlgEdObj const &) = delete; // due to SdrUnoObj
- DlgEdObj(DlgEdObj &&) = delete; // due to SdrUnoObj
- DlgEdObj & operator =(DlgEdObj const &) = default;
- DlgEdObj & operator =(DlgEdObj &&) = default;
-
void SetDlgEdForm( DlgEdForm* pForm ) { pDlgEdForm = pForm; }
DlgEdForm* GetDlgEdForm() const { return pDlgEdForm; }
@@ -103,7 +100,6 @@ public:
virtual SdrObjKind GetObjIdentifier() const override;
virtual DlgEdObj* CloneSdrObject(SdrModel& rTargetModel) const override; // not working yet
- void clonedFrom(const DlgEdObj* _pSource); // not working yet
// FullDrag support
virtual SdrObjectUniquePtr getFullDragClone() const override;