summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2014-12-03 22:01:57 +0100
committerDavid Tardon <dtardon@redhat.com>2014-12-04 23:10:24 +0100
commit9638e6207c7fc48712b1b238177462c00f5011e8 (patch)
tree5b4f30ee6fc163e52ab0cb5bf179d6f55ff261bd /svx
parent34e456a2b030eb2e80ae5ca87e81896cc8240bff (diff)
ooo#93212 avoid slicing during construction of SdrPage
Also hide copy ctor and assignment operator of all derived classes, to ensure that Clone() is the only method to make copies of them. Change-Id: Icb3b50c63b086abe8c9add32e3041fe19692d20b
Diffstat (limited to 'svx')
-rw-r--r--svx/source/engine3d/obj3d.cxx11
-rw-r--r--svx/source/form/fmpage.cxx11
-rw-r--r--svx/source/svdraw/svdpage.cxx84
3 files changed, 41 insertions, 65 deletions
diff --git a/svx/source/engine3d/obj3d.cxx b/svx/source/engine3d/obj3d.cxx
index eee59ad5bbec..ef50b3da671f 100644
--- a/svx/source/engine3d/obj3d.cxx
+++ b/svx/source/engine3d/obj3d.cxx
@@ -91,11 +91,18 @@ E3dObjList::E3dObjList(SdrModel* pNewModel, SdrPage* pNewPage, E3dObjList* pNewU
{
}
-E3dObjList::E3dObjList(const E3dObjList& rSrcList)
-: SdrObjList(rSrcList)
+E3dObjList::E3dObjList(const E3dObjList&)
+: SdrObjList()
{
}
+E3dObjList* E3dObjList::Clone() const
+{
+ E3dObjList* const pObjList = new E3dObjList(*this);
+ pObjList->lateInit(*this);
+ return pObjList;
+}
+
E3dObjList::~E3dObjList()
{
}
diff --git a/svx/source/form/fmpage.cxx b/svx/source/form/fmpage.cxx
index 365dfd38e325..96c3baaf7105 100644
--- a/svx/source/form/fmpage.cxx
+++ b/svx/source/form/fmpage.cxx
@@ -66,6 +66,12 @@ FmFormPage::FmFormPage(const FmFormPage& rPage)
:SdrPage(rPage)
,m_pImpl(new FmFormPageImpl( *this ) )
{
+}
+
+void FmFormPage::lateInit(const FmFormPage& rPage)
+{
+ SdrPage::lateInit( rPage );
+
m_pImpl->initFrom( rPage.GetImpl() );
m_sPageName = rPage.m_sPageName;
}
@@ -113,8 +119,9 @@ void FmFormPage::SetModel(SdrModel* pNewModel)
SdrPage* FmFormPage::Clone() const
{
- return new FmFormPage(*this);
- // hier fehlt noch ein kopieren der Objekte
+ FmFormPage* const pNewPage = new FmFormPage(*this);
+ pNewPage->lateInit(*this);
+ return pNewPage;
}
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index 94139448bcb3..da27d4a27f09 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -88,7 +88,7 @@ SdrObjList::SdrObjList(SdrModel* pNewModel, SdrPage* pNewPage, SdrObjList* pNewU
eListKind=SDROBJLIST_UNKNOWN;
}
-SdrObjList::SdrObjList(const SdrObjList& rSrcList):
+SdrObjList::SdrObjList():
maList(),
mpNavigationOrder(),
mbIsNavigationOrderDirty(false)
@@ -101,7 +101,6 @@ SdrObjList::SdrObjList(const SdrObjList& rSrcList):
bRectsDirty=false;
pOwnerObj=NULL;
eListKind=SDROBJLIST_UNKNOWN;
- *this=rSrcList;
}
SdrObjList::~SdrObjList()
@@ -115,9 +114,18 @@ SdrObjList::~SdrObjList()
Clear(); // delete contents of container
}
-void SdrObjList::operator=(const SdrObjList& rSrcList)
+SdrObjList* SdrObjList::Clone() const
{
- Clear();
+ SdrObjList* const pObjList = new SdrObjList();
+ pObjList->lateInit(*this);
+ return pObjList;
+}
+
+void SdrObjList::lateInit(const SdrObjList& rSrcList)
+{
+ // this function is only supposed to be called once, right after construction
+ assert(maList.empty());
+
eListKind=rSrcList.eListKind;
CopyObjects(rSrcList);
}
@@ -1246,31 +1254,6 @@ SdrPage::SdrPage(const SdrPage& rSrcPage)
mbPageBorderOnlyLeftRight(rSrcPage.mbPageBorderOnlyLeftRight)
{
aPrefVisiLayers.SetAll();
- eListKind = (mbMaster) ? SDROBJLIST_MASTERPAGE : SDROBJLIST_DRAWPAGE;
-
- // copy things from source
- // Warning: this leads to slicing (see issue 93186) and has to be
- // removed as soon as possible.
- *this = rSrcPage;
- OSL_ENSURE(mpSdrPageProperties,
- "SdrPage::SdrPage: operator= did not create needed SdrPageProperties (!)");
-
- // be careful and correct eListKind, a member of SdrObjList which
- // will be changed by the SdrOIbjList::operator= before...
- eListKind = (mbMaster) ? SDROBJLIST_MASTERPAGE : SDROBJLIST_DRAWPAGE;
-
- // The previous assignment to *this may have resulted in a call to
- // createUnoPage at a partially initialized (sliced) SdrPage object.
- // Due to the vtable being not yet fully set-up at this stage,
- // createUnoPage() may have been called at the wrong class.
- // To force a call to the right createUnoPage() at a later time when the
- // new object is full constructed mxUnoPage is disposed now.
- uno::Reference<lang::XComponent> xComponent (mxUnoPage, uno::UNO_QUERY);
- if (xComponent.is())
- {
- mxUnoPage = NULL;
- xComponent->dispose();
- }
}
SdrPage::~SdrPage()
@@ -1319,20 +1302,10 @@ SdrPage::~SdrPage()
}
-SdrPage& SdrPage::operator=(const SdrPage& rSrcPage)
+void SdrPage::lateInit(const SdrPage& rSrcPage)
{
- if( this == &rSrcPage )
- return *this;
- if(mpViewContact)
- {
- delete mpViewContact;
- mpViewContact = 0L;
- }
-
- // Joe also sets some parameters for the class this one
- // is derived from. SdrObjList does the same bad handling of
- // copy constructor and operator=, so i better let it stand here.
- pPage = this;
+ assert(!mpViewContact);
+ assert(!mpSdrPageProperties);
// copy all the local parameters to make this instance
// a valid copy of source page before copying and inserting
@@ -1361,21 +1334,7 @@ SdrPage& SdrPage::operator=(const SdrPage& rSrcPage)
mbObjectsNotPersistent = rSrcPage.mbObjectsNotPersistent;
{
- // #i111122# delete SdrPageProperties when model is different
- if(mpSdrPageProperties && GetModel() != rSrcPage.GetModel())
- {
- delete mpSdrPageProperties;
- mpSdrPageProperties = 0;
- }
-
- if(!mpSdrPageProperties)
- {
- mpSdrPageProperties = new SdrPageProperties(*this);
- }
- else
- {
- mpSdrPageProperties->ClearItem(0);
- }
+ mpSdrPageProperties = new SdrPageProperties(*this);
if(!IsMasterPage())
{
@@ -1385,9 +1344,12 @@ SdrPage& SdrPage::operator=(const SdrPage& rSrcPage)
mpSdrPageProperties->SetStyleSheet(rSrcPage.getSdrPageProperties().GetStyleSheet());
}
- // Now copy the contained objects (by cloning them)
- SdrObjList::operator=(rSrcPage);
- return *this;
+ // Now copy the contained objects
+ SdrObjList::lateInit(rSrcPage);
+
+ // be careful and correct eListKind, a member of SdrObjList which
+ // will be changed by the SdrObjList::lateInit before...
+ eListKind = (mbMaster) ? SDROBJLIST_MASTERPAGE : SDROBJLIST_DRAWPAGE;
}
SdrPage* SdrPage::Clone() const
@@ -1399,7 +1361,7 @@ SdrPage* SdrPage::Clone(SdrModel* pNewModel) const
{
if (pNewModel==NULL) pNewModel=pModel;
SdrPage* pPage2=new SdrPage(*pNewModel);
- *pPage2=*this;
+ pPage2->lateInit(*this);
return pPage2;
}