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-05 09:57:36 +0100
commitd49e5761f359020c349c268ee78a4256cc46541e (patch)
tree51452df20c020095d9e7397f1066661f53c2e835 /svx
parent8ddc963165bb52d7272ee1cca099f2ee8fed6759 (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 (cherry picked from commit 9638e6207c7fc48712b1b238177462c00f5011e8)
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 46ed346d149c..37952024173d 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -87,7 +87,7 @@ SdrObjList::SdrObjList(SdrModel* pNewModel, SdrPage* pNewPage, SdrObjList* pNewU
eListKind=SDROBJLIST_UNKNOWN;
}
-SdrObjList::SdrObjList(const SdrObjList& rSrcList):
+SdrObjList::SdrObjList():
maList(),
mpNavigationOrder(),
mbIsNavigationOrderDirty(false)
@@ -100,7 +100,6 @@ SdrObjList::SdrObjList(const SdrObjList& rSrcList):
bRectsDirty=false;
pOwnerObj=NULL;
eListKind=SDROBJLIST_UNKNOWN;
- *this=rSrcList;
}
SdrObjList::~SdrObjList()
@@ -114,9 +113,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);
}
@@ -1245,31 +1253,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()
@@ -1318,20 +1301,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
@@ -1360,21 +1333,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())
{
@@ -1384,9 +1343,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
@@ -1398,7 +1360,7 @@ SdrPage* SdrPage::Clone(SdrModel* pNewModel) const
{
if (pNewModel==NULL) pNewModel=pModel;
SdrPage* pPage2=new SdrPage(*pNewModel);
- *pPage2=*this;
+ pPage2->lateInit(*this);
return pPage2;
}