Kaydet (Commit) 560b9a41 authored tarafından Caolán McNamara's avatar Caolán McNamara

use more references to fix life cycles

Change-Id: I0c903533542608c1d7a3c97e2be7f2b7624b265b
(cherry picked from commit a1426bc5)
üst c3568650
......@@ -327,7 +327,7 @@ XFCell* LwpCellLayout::ConvertCell(LwpObjectID aTableID, sal_uInt16 nRow, sal_uI
// we should adjust its style by current position
if (pTable->GetDefaultCellStyle() == GetObjectID())
{
aStyleName = GetCellStyleName(nRow, nCol, pTable->GetTableLayout());
aStyleName = GetCellStyleName(nRow, nCol, pTable->GetTableLayout().get());
}
// content of cell
......@@ -661,8 +661,8 @@ void LwpCellLayout::ApplyProtect(XFCell * pCell, LwpObjectID aTableID)
{
// judge whole table
LwpTable * pTable = dynamic_cast<LwpTable *>(aTableID.obj().get());
LwpTableLayout * pTableLayout = pTable ? dynamic_cast<LwpTableLayout *>(pTable->GetTableLayout()) : nullptr;
LwpSuperTableLayout * pSuper = pTableLayout ? pTableLayout->GetSuperTableLayout() : nullptr;
rtl::Reference<LwpTableLayout> xTableLayout(pTable ? pTable->GetTableLayout() : nullptr);
LwpSuperTableLayout * pSuper = xTableLayout.is() ? xTableLayout->GetSuperTableLayout() : nullptr;
if (pSuper && pSuper->GetIsProtected())
{
bProtected = true;
......
......@@ -121,17 +121,20 @@ void LwpContent::Read()
pStrm->SkipExtra();
}
LwpVirtualLayout* LwpContent::GetLayout(LwpVirtualLayout* pStartLayout)
rtl::Reference<LwpVirtualLayout> LwpContent::GetLayout(LwpVirtualLayout* pStartLayout)
{
return m_LayoutsWithMe.GetLayout(pStartLayout);
}
bool LwpContent::HasNonEmbeddedLayouts()
{
LwpVirtualLayout* pLayout = nullptr;
while( (pLayout = GetLayout(pLayout)) )
rtl::Reference<LwpVirtualLayout> xLayout;
while (1)
{
if(!pLayout->NoContentReference())
xLayout = GetLayout(xLayout.get());
if (!xLayout.is())
break;
if (!xLayout->NoContentReference())
return true;
}
return false;
......@@ -139,10 +142,13 @@ bool LwpContent::HasNonEmbeddedLayouts()
bool LwpContent::IsStyleContent()
{
LwpVirtualLayout* pLayout = nullptr;
while( (pLayout = GetLayout(pLayout)) )
rtl::Reference<LwpVirtualLayout> xLayout;
while (1)
{
if(pLayout->IsStyleLayout())
xLayout = GetLayout(xLayout.get());
if (!xLayout.is())
break;
if (xLayout->IsStyleLayout())
return true;
}
return false;
......
......@@ -106,7 +106,7 @@ protected:
void Read() override;
public:
inline LwpAssociatedLayouts& GetLayoutsWithMe();
LwpVirtualLayout* GetLayout(LwpVirtualLayout* pStartLayout);
rtl::Reference<LwpVirtualLayout> GetLayout(LwpVirtualLayout* pStartLayout);
inline bool IsActive();
virtual bool IsTable();
inline OUString GetClassName();
......
......@@ -363,7 +363,7 @@ LwpEnSuperTableLayout* LwpFootnote::FindFootnoteTableLayout()
while ((pContent = pFoundry->EnumContents(pContent)) != nullptr)
if (pContent->IsTable() && (strClassName.equals(pContent->GetClassName())) &&
pContent->IsActive() && pContent->GetLayout(nullptr))
pContent->IsActive() && pContent->GetLayout(nullptr).is())
{
// Found it!
return static_cast<LwpEnSuperTableLayout *>(
......@@ -381,7 +381,7 @@ LwpContent* LwpFootnote::FindFootnoteContent()
LwpContent* pContent = dynamic_cast<LwpContent*>(m_Content.obj().get());
//if the content has layout, the content has footnote contents;
//or looking for the celllayout and return the footnote contents.
if(pContent && pContent->GetLayout(nullptr))
if (pContent && pContent->GetLayout(nullptr).is())
return pContent;
LwpCellLayout* pCellLayout = GetCellLayout();
......
......@@ -273,8 +273,8 @@ void LwpGraphicObject::RegisterStyle()
if (m_sServerContextFormat[1]=='l'&&m_sServerContextFormat[2]=='c'&&m_sServerContextFormat[3]=='h')
{
LwpVirtualLayout* pMyLayout = GetLayout(nullptr);
if (pMyLayout && pMyLayout->IsFrame())
rtl::Reference<LwpVirtualLayout> xMyLayout(GetLayout(nullptr));
if (xMyLayout.is() && xMyLayout->IsFrame())
{
XFFrameStyle* pXFFrameStyle = new XFFrameStyle();
pXFFrameStyle->SetXPosType(enumXFFrameXPosFromLeft, enumXFFrameXRelFrame);
......
......@@ -419,42 +419,40 @@ void LwpAssociatedLayouts::Read(LwpObjectStream* pStrm)
* @descr: Looking for the layout which follows the pStartLayout
* @param: pStartLayout - the layout which is used for looking for its following layout
*/
LwpVirtualLayout* LwpAssociatedLayouts::GetLayout(LwpVirtualLayout *pStartLayout)
rtl::Reference<LwpVirtualLayout> LwpAssociatedLayouts::GetLayout(LwpVirtualLayout *pStartLayout)
{
if (!pStartLayout && !m_OnlyLayout.IsNull())
/* Looking for the first layout and there's only one layout in the list.*/
return dynamic_cast<LwpVirtualLayout*>(m_OnlyLayout.obj().get());
return rtl::Reference<LwpVirtualLayout>(dynamic_cast<LwpVirtualLayout*>(m_OnlyLayout.obj().get()));
LwpObjectHolder* pObjHolder = dynamic_cast<LwpObjectHolder*>(m_Layouts.GetHead().obj().get());
if(pObjHolder)
rtl::Reference<LwpObjectHolder> xObjHolder(dynamic_cast<LwpObjectHolder*>(m_Layouts.GetHead().obj().get()));
if (xObjHolder.is())
{
LwpVirtualLayout* pLayout = dynamic_cast<LwpVirtualLayout*>(pObjHolder->GetObject().obj().get());
if(!pStartLayout )
return pLayout;
rtl::Reference<LwpVirtualLayout> xLayout(dynamic_cast<LwpVirtualLayout*>(xObjHolder->GetObject().obj().get()));
if (!pStartLayout)
return xLayout;
while(pObjHolder && pStartLayout != pLayout)
while (xObjHolder.is() && pStartLayout != xLayout.get())
{
pObjHolder = dynamic_cast<LwpObjectHolder*>(pObjHolder->GetNext().obj().get());
if(pObjHolder)
xObjHolder.set(dynamic_cast<LwpObjectHolder*>(xObjHolder->GetNext().obj().get()));
if (xObjHolder.is())
{
pLayout = dynamic_cast<LwpVirtualLayout*>(pObjHolder->GetObject().obj().get());
xLayout.set(dynamic_cast<LwpVirtualLayout*>(xObjHolder->GetObject().obj().get()));
}
}
if(pObjHolder)
if (xObjHolder.is())
{
pObjHolder = dynamic_cast<LwpObjectHolder*>(pObjHolder->GetNext().obj().get());
if(pObjHolder)
xObjHolder.set(dynamic_cast<LwpObjectHolder*>(xObjHolder->GetNext().obj().get()));
if (xObjHolder.is())
{
pLayout = dynamic_cast<LwpVirtualLayout*>(pObjHolder->GetObject().obj().get());
return pLayout;
xLayout.set(dynamic_cast<LwpVirtualLayout*>(xObjHolder->GetObject().obj().get()));
return xLayout;
}
}
//return pLayout;
}
return nullptr;
return rtl::Reference<LwpVirtualLayout>();
}
LwpHeadLayout::LwpHeadLayout(LwpObjectHeader &objHdr, LwpSvStream* pStrm)
......@@ -473,27 +471,27 @@ void LwpHeadLayout::Read()
void LwpHeadLayout::RegisterStyle()
{
//Register all children styles
LwpVirtualLayout* pLayout = dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get());
while(pLayout)
rtl::Reference<LwpVirtualLayout> xLayout(dynamic_cast<LwpVirtualLayout*>(GetChildHead().obj().get()));
while (xLayout.is())
{
pLayout->SetFoundry(m_pFoundry);
xLayout->SetFoundry(m_pFoundry);
//if the layout is relative to para, the layout will be registered in para
if(!pLayout->IsRelativeAnchored())
if (!xLayout->IsRelativeAnchored())
{
if (pLayout == this)
if (xLayout.get() == this)
{
OSL_FAIL("Layout points to itself");
break;
}
pLayout->DoRegisterStyle();
xLayout->DoRegisterStyle();
}
LwpVirtualLayout *pNext = dynamic_cast<LwpVirtualLayout*>(pLayout->GetNext().obj().get());
if (pNext == pLayout)
rtl::Reference<LwpVirtualLayout> xNext(dynamic_cast<LwpVirtualLayout*>(xLayout->GetNext().obj().get()));
if (xNext.get() == xLayout.get())
{
OSL_FAIL("Layout points to itself");
break;
}
pLayout = pNext;
xLayout = xNext;
}
}
......
......@@ -254,7 +254,7 @@ public:
LwpAssociatedLayouts(){}
void Read(LwpObjectStream* pStrm);
LwpObjectID& GetOnlyLayout() { return m_OnlyLayout;}
LwpVirtualLayout* GetLayout(LwpVirtualLayout* pStartLayout);
rtl::Reference<LwpVirtualLayout> GetLayout(LwpVirtualLayout* pStartLayout);
protected:
LwpObjectID m_OnlyLayout; //LwpVirtualLayout
LwpDLVListHeadTail m_Layouts;
......
......@@ -107,10 +107,10 @@ void LwpGraphicOleObject::GetGrafScaledSize(double & fWidth, double & fHeight)
double fSclGrafWidth = fWidth;//LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleWidth());
double fSclGrafHeight = fHeight;//LwpTools::ConvertFromUnitsToMetric(pMyScale->GetScaleHeight());
LwpVirtualLayout* pLayout = GetLayout(nullptr);
if (pLayout && pLayout->IsFrame())
rtl::Reference<LwpVirtualLayout> xLayout(GetLayout(nullptr));
if (xLayout.is() && xLayout->IsFrame())
{
LwpFrameLayout* pMyFrameLayout = static_cast<LwpFrameLayout*>(pLayout);
LwpFrameLayout* pMyFrameLayout = static_cast<LwpFrameLayout*>(xLayout.get());
LwpLayoutScale* pMyScale = pMyFrameLayout->GetLayoutScale();
LwpLayoutGeometry* pFrameGeo = pMyFrameLayout->GetGeometry();
......
......@@ -618,8 +618,10 @@ bool LwpPara::ComparePagePosition(LwpVirtualLayout * pPreLayout, LwpVirtualLayou
bool LwpPara::IsInCell()
{
LwpStory *pStory = GetStory();
LwpVirtualLayout* pLayout = pStory ? pStory->GetLayout(nullptr) : nullptr;
if(pLayout && pLayout->IsCell())
if (!pStory)
return false;
rtl::Reference<LwpVirtualLayout> xLayout(pStory->GetLayout(nullptr));
if (xLayout.is() && xLayout->IsCell())
return true;
return false;
}
......
......@@ -129,11 +129,11 @@ void LwpSdwGroupLoaderV0102::BeginDrawObjects(std::vector< rtl::Reference<XFFram
m_pStream->SeekRel(2);
//for calculating transformation params.
LwpFrameLayout* pMyFrameLayout = static_cast<LwpFrameLayout*>(m_pGraphicObj->GetLayout(nullptr));
if (pMyFrameLayout)
rtl::Reference<LwpFrameLayout> xMyFrameLayout(dynamic_cast<LwpFrameLayout*>(m_pGraphicObj->GetLayout(nullptr).get()));
if (xMyFrameLayout.is())
{
LwpLayoutScale* pMyScale = pMyFrameLayout->GetLayoutScale();
LwpLayoutGeometry* pFrameGeo = pMyFrameLayout->GetGeometry();
LwpLayoutScale* pMyScale = xMyFrameLayout->GetLayoutScale();
LwpLayoutGeometry* pFrameGeo = xMyFrameLayout->GetGeometry();
if (pMyScale && pFrameGeo)
{
// original drawing size
......@@ -143,10 +143,8 @@ void LwpSdwGroupLoaderV0102::BeginDrawObjects(std::vector< rtl::Reference<XFFram
double fGrafOrgHeight = (double)nHeight/TWIPS_PER_CM;
// get margin values
double fLeftMargin = pMyFrameLayout->GetMarginsValue(MARGIN_LEFT);
// double fRightMargin = pMyFrameLayout->GetMarginsValue(MARGIN_RIGHT);
double fTopMargin = pMyFrameLayout->GetMarginsValue(MARGIN_TOP);
// double fBottomMargin = pMyFrameLayout->GetMarginsValue(MARGIN_BOTTOM);
double fLeftMargin = xMyFrameLayout->GetMarginsValue(MARGIN_LEFT);
double fTopMargin = xMyFrameLayout->GetMarginsValue(MARGIN_TOP);
// frame size
double fFrameWidth = LwpTools::ConvertFromUnitsToMetric(pFrameGeo->GetWidth());
......@@ -197,7 +195,7 @@ void LwpSdwGroupLoaderV0102::BeginDrawObjects(std::vector< rtl::Reference<XFFram
}
// placement: centered
if (pMyFrameLayout->GetScaleCenter())
if (xMyFrameLayout->GetScaleCenter())
{
Rectangle aBoundRect(static_cast<long>(left*m_aTransformData.fScaleX + fLeftMargin),
static_cast<long>(top * m_aTransformData.fScaleY + fTopMargin),
......
......@@ -215,20 +215,20 @@ void LwpStory::SortPageLayout()
{
//Get all the pagelayout and store in list
std::vector<LwpPageLayout*> aLayoutList;
LwpVirtualLayout* pLayout = GetLayout(nullptr);
while(pLayout)
rtl::Reference<LwpVirtualLayout> xLayout(GetLayout(nullptr));
while (xLayout.get())
{
if(pLayout->IsPage())
if (xLayout->IsPage())
{
LwpLayout::UseWhenType eSectionType = static_cast<LwpPageLayout*>(pLayout)->GetUseWhenType();
LwpLayout::UseWhenType eSectionType = static_cast<LwpPageLayout*>(xLayout.get())->GetUseWhenType();
//for mirror page, the child is pagelayout
LwpVirtualLayout* pParent = pLayout->GetParentLayout();
LwpVirtualLayout* pParent = xLayout->GetParentLayout();
if(eSectionType != LwpLayout::StartWithinColume && pParent && !pParent->IsPage())
{
aLayoutList.push_back(static_cast<LwpPageLayout*>(pLayout));
aLayoutList.push_back(static_cast<LwpPageLayout*>(xLayout.get()));
}
}
pLayout = GetLayout(pLayout);
xLayout = GetLayout(xLayout.get());
}
// sort the pagelayout according to their position
std::vector<LwpPageLayout*>::iterator aIt;
......@@ -315,10 +315,10 @@ bool LwpStory::IsNeedSection()
**************************************************************************/
void LwpStory::XFConvertFrameInCell(XFContentContainer* pCont)
{
LwpVirtualLayout* pLayout = GetLayout(nullptr);
while(pLayout)
rtl::Reference<LwpVirtualLayout> xLayout(GetLayout(nullptr));
while (xLayout.is())
{
LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead().obj().get());
LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(xLayout->GetChildHead().obj().get());
while(pFrameLayout)
{
......@@ -334,7 +334,7 @@ void LwpStory::XFConvertFrameInCell(XFContentContainer* pCont)
}
pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext().obj().get());
}
pLayout = GetLayout(pLayout);
xLayout = GetLayout(xLayout.get());
}
}
......@@ -343,10 +343,10 @@ void LwpStory::XFConvertFrameInCell(XFContentContainer* pCont)
**************************************************************************/
void LwpStory::XFConvertFrameInPage(XFContentContainer* pCont)
{
LwpVirtualLayout* pLayout = GetLayout(nullptr);
while(pLayout)
rtl::Reference<LwpVirtualLayout> xLayout(GetLayout(nullptr));
while (xLayout.is())
{
LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead().obj().get());
LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(xLayout->GetChildHead().obj().get());
while(pFrameLayout)
{
if((pFrameLayout->IsAnchorPage()
......@@ -358,7 +358,7 @@ void LwpStory::XFConvertFrameInPage(XFContentContainer* pCont)
}
pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext().obj().get());
}
pLayout = GetLayout(pLayout);
xLayout = GetLayout(xLayout.get());
}
}
/**************************************************************************
......@@ -366,10 +366,10 @@ void LwpStory::XFConvertFrameInPage(XFContentContainer* pCont)
**************************************************************************/
void LwpStory::XFConvertFrameInFrame(XFContentContainer* pCont)
{
LwpVirtualLayout* pLayout = GetLayout(nullptr);
while(pLayout)
rtl::Reference<LwpVirtualLayout> xLayout(GetLayout(nullptr));
while (xLayout.get())
{
LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead().obj().get());
LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(xLayout->GetChildHead().obj().get());
while(pFrameLayout)
{
if(pFrameLayout->IsAnchorFrame())
......@@ -378,7 +378,7 @@ void LwpStory::XFConvertFrameInFrame(XFContentContainer* pCont)
}
pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext().obj().get());
}
pLayout = GetLayout(pLayout);
xLayout = GetLayout(xLayout.get());
}
}
/**************************************************************************
......@@ -386,13 +386,13 @@ void LwpStory::XFConvertFrameInFrame(XFContentContainer* pCont)
**************************************************************************/
void LwpStory::XFConvertFrameInHeaderFooter(XFContentContainer* pCont)
{
LwpVirtualLayout* pLayout = GetLayout(nullptr);
while(pLayout)
rtl::Reference<LwpVirtualLayout> xLayout(GetLayout(nullptr));
while (xLayout.is())
{
LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pLayout->GetChildHead().obj().get());
LwpVirtualLayout* pFrameLayout = dynamic_cast<LwpVirtualLayout*>(xLayout->GetChildHead().obj().get());
while(pFrameLayout)
{
if(pFrameLayout->IsAnchorPage() && (pLayout->IsHeader() || pLayout->IsFooter()))
if(pFrameLayout->IsAnchorPage() && (xLayout->IsHeader() || xLayout->IsFooter()))
{
//The frame must be included by <text:p>
rtl::Reference<XFContent> first(
......@@ -403,7 +403,7 @@ void LwpStory::XFConvertFrameInHeaderFooter(XFContentContainer* pCont)
}
pFrameLayout = dynamic_cast<LwpVirtualLayout*>(pFrameLayout->GetNext().obj().get());
}
pLayout = GetLayout(pLayout);
xLayout = GetLayout(xLayout.get());
}
}
......@@ -423,10 +423,10 @@ XFContentContainer* LwpStory::GetXFContent()
LwpPara* LwpStory::GetLastParaOfPreviousStory()
{
LwpVirtualLayout* pVLayout = this->GetLayout(nullptr);
if (pVLayout)
rtl::Reference<LwpVirtualLayout> xVLayout(this->GetLayout(nullptr));
if (xVLayout.is())
{
return pVLayout->GetLastParaOfPreviousStory();
return xVLayout->GetLastParaOfPreviousStory();
}
return nullptr;
......
......@@ -147,7 +147,7 @@ LwpMiddleLayout* LwpStory::GetTabLayout()
{
if(m_pTabLayout)
return m_pTabLayout;
return static_cast<LwpMiddleLayout*>(GetLayout(nullptr));
return dynamic_cast<LwpMiddleLayout*>(GetLayout(nullptr).get());
}
void LwpStory::SetPMModified(bool bPMModified)
{
......
......@@ -119,7 +119,10 @@ public:
LwpObjectID& GetDefaultCellStyle() {return m_DefaultCellStyle;}
sal_uInt16 GetRow() {return m_nRow;}
sal_uInt16 GetColumn() {return m_nColumn;}
LwpTableLayout * GetTableLayout(){return dynamic_cast<LwpTableLayout *>(GetLayout(nullptr));}
rtl::Reference<LwpTableLayout> GetTableLayout()
{
return rtl::Reference<LwpTableLayout>(dynamic_cast<LwpTableLayout*>(GetLayout(nullptr).get()));
}
bool IsNumberDown();
virtual bool IsTable() override { return true;}
LwpSuperTableLayout* GetSuperTableLayout();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment