use rtl::Reference in SwDocFac

instead of manual acquire/release

Change-Id: I40b4f6d2893fe0d4113032f638bce1793fc47cd7
This commit is contained in:
Noel Grandin
2017-01-19 11:29:32 +02:00
parent 071c74dfe2
commit a754294ac7
3 changed files with 69 additions and 73 deletions

View File

@@ -20,13 +20,14 @@
#define INCLUDED_SW_INC_DOCFAC_HXX #define INCLUDED_SW_INC_DOCFAC_HXX
#include <tools/solar.h> #include <tools/solar.h>
#include <rtl/ref.hxx>
class SwDoc; class SwDoc;
class SW_DLLPUBLIC SwDocFac class SW_DLLPUBLIC SwDocFac
{ {
protected: protected:
SwDoc* pDoc; rtl::Reference<SwDoc> mxDoc;
public: public:
SwDocFac( SwDoc *pDoc = nullptr ); SwDocFac( SwDoc *pDoc = nullptr );

View File

@@ -25,28 +25,23 @@
SwDocFac::SwDocFac( SwDoc *pDc ) SwDocFac::SwDocFac( SwDoc *pDc )
: pDoc( pDc ) : mxDoc( pDc )
{ {
if( pDoc )
pDoc->acquire();
} }
SwDocFac::~SwDocFac() SwDocFac::~SwDocFac()
{ {
if( pDoc && !pDoc->release() )
delete pDoc;
} }
SwDoc *SwDocFac::GetDoc() SwDoc *SwDocFac::GetDoc()
{ {
if( !pDoc ) if( !mxDoc.is() )
{ {
pDoc = new SwDoc; mxDoc = new SwDoc;
pDoc->acquire();
} }
return pDoc; return mxDoc.get();
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -88,11 +88,11 @@ sal_uLong SwReader::Read( const Reader& rOptions )
GetDoc(); GetDoc();
// while reading, do not call OLE-Modified // while reading, do not call OLE-Modified
Link<bool,void> aOLELink( pDoc->GetOle2Link() ); Link<bool,void> aOLELink( mxDoc->GetOle2Link() );
pDoc->SetOle2Link( Link<bool,void>() ); mxDoc->SetOle2Link( Link<bool,void>() );
pDoc->SetInReading( true ); mxDoc->SetInReading( true );
pDoc->SetInXMLImport( dynamic_cast< XMLReader* >(po) != nullptr ); mxDoc->SetInXMLImport( dynamic_cast< XMLReader* >(po) != nullptr );
SwPaM *pPam; SwPaM *pPam;
if( pCursor ) if( pCursor )
@@ -100,13 +100,13 @@ sal_uLong SwReader::Read( const Reader& rOptions )
else else
{ {
// if the Reader was not called by a Shell, create a PaM ourselves // if the Reader was not called by a Shell, create a PaM ourselves
SwNodeIndex nNode( pDoc->GetNodes().GetEndOfContent(), -1 ); SwNodeIndex nNode( mxDoc->GetNodes().GetEndOfContent(), -1 );
pPam = new SwPaM( nNode ); pPam = new SwPaM( nNode );
// For Web documents the default template was set already by InitNew, // For Web documents the default template was set already by InitNew,
// unless the filter is not HTML, // unless the filter is not HTML,
// or a SetTemplateName was called in ConvertFrom. // or a SetTemplateName was called in ConvertFrom.
if( !pDoc->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE) || ReadHTML != po || !po->mxTemplate.is() ) if( !mxDoc->getIDocumentSettingAccess().get(DocumentSettingId::HTML_MODE) || ReadHTML != po || !po->mxTemplate.is() )
po->SetTemplate( *pDoc ); po->SetTemplate( *mxDoc );
} }
// Pams are connected like rings; stop when we return to the 1st element // Pams are connected like rings; stop when we return to the 1st element
@@ -114,7 +114,7 @@ sal_uLong SwReader::Read( const Reader& rOptions )
SwUndoInsDoc* pUndo = nullptr; SwUndoInsDoc* pUndo = nullptr;
bool bReadPageDescs = false; bool bReadPageDescs = false;
bool const bDocUndo = pDoc->GetIDocumentUndoRedo().DoesUndo(); bool const bDocUndo = mxDoc->GetIDocumentUndoRedo().DoesUndo();
bool bSaveUndo = bDocUndo && pCursor; bool bSaveUndo = bDocUndo && pCursor;
if( bSaveUndo ) if( bSaveUndo )
{ {
@@ -123,19 +123,19 @@ sal_uLong SwReader::Read( const Reader& rOptions )
if( bReadPageDescs ) if( bReadPageDescs )
{ {
bSaveUndo = false; bSaveUndo = false;
pDoc->GetIDocumentUndoRedo().DelAllUndoObj(); mxDoc->GetIDocumentUndoRedo().DelAllUndoObj();
} }
else else
{ {
pDoc->GetIDocumentUndoRedo().ClearRedo(); mxDoc->GetIDocumentUndoRedo().ClearRedo();
pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_INSDOKUMENT, nullptr ); mxDoc->GetIDocumentUndoRedo().StartUndo( UNDO_INSDOKUMENT, nullptr );
} }
} }
pDoc->GetIDocumentUndoRedo().DoUndo(false); mxDoc->GetIDocumentUndoRedo().DoUndo(false);
SwNodeIndex aSplitIdx( pDoc->GetNodes() ); SwNodeIndex aSplitIdx( mxDoc->GetNodes() );
RedlineFlags eOld = pDoc->getIDocumentRedlineAccess().GetRedlineFlags(); RedlineFlags eOld = mxDoc->getIDocumentRedlineAccess().GetRedlineFlags();
RedlineFlags ePostReadRedlineFlags( RedlineFlags::Ignore ); RedlineFlags ePostReadRedlineFlags( RedlineFlags::Ignore );
// Array of FlyFormats // Array of FlyFormats
@@ -148,7 +148,7 @@ sal_uLong SwReader::Read( const Reader& rOptions )
if( bSaveUndo ) if( bSaveUndo )
pUndo = new SwUndoInsDoc( *pPam ); pUndo = new SwUndoInsDoc( *pPam );
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::Ignore ); mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::Ignore );
SwPaM* pUndoPam = nullptr; SwPaM* pUndoPam = nullptr;
if( bDocUndo || pCursor ) if( bDocUndo || pCursor )
@@ -161,8 +161,8 @@ sal_uLong SwReader::Read( const Reader& rOptions )
// store for now all Fly's // store for now all Fly's
if( pCursor ) if( pCursor )
{ {
std::copy(pDoc->GetSpzFrameFormats()->begin(), std::copy(mxDoc->GetSpzFrameFormats()->begin(),
pDoc->GetSpzFrameFormats()->end(), std::back_inserter(aFlyFrameArr)); mxDoc->GetSpzFrameFormats()->end(), std::back_inserter(aFlyFrameArr));
} }
const sal_Int32 nSttContent = pPam->GetPoint()->nContent.GetIndex(); const sal_Int32 nSttContent = pPam->GetPoint()->nContent.GetIndex();
@@ -172,21 +172,21 @@ sal_uLong SwReader::Read( const Reader& rOptions )
sal_Int32 nEndContent = pCNd ? pCNd->Len() - nSttContent : 0; sal_Int32 nEndContent = pCNd ? pCNd->Len() - nSttContent : 0;
SwNodeIndex aEndPos( pPam->GetPoint()->nNode, 1 ); SwNodeIndex aEndPos( pPam->GetPoint()->nNode, 1 );
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
nError = po->Read( *pDoc, sBaseURL, *pPam, aFileName ); nError = po->Read( *mxDoc, sBaseURL, *pPam, aFileName );
// an ODF document may contain redline mode in settings.xml; save it! // an ODF document may contain redline mode in settings.xml; save it!
ePostReadRedlineFlags = pDoc->getIDocumentRedlineAccess().GetRedlineFlags(); ePostReadRedlineFlags = mxDoc->getIDocumentRedlineAccess().GetRedlineFlags();
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::Ignore ); mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::Ignore );
if( !IsError( nError )) // set the End position already if( !IsError( nError )) // set the End position already
{ {
--aEndPos; --aEndPos;
pCNd = aEndPos.GetNode().GetContentNode(); pCNd = aEndPos.GetNode().GetContentNode();
if( !pCNd && nullptr == ( pCNd = SwNodes::GoPrevious( &aEndPos ) )) if( !pCNd && nullptr == ( pCNd = SwNodes::GoPrevious( &aEndPos ) ))
pCNd = pDoc->GetNodes().GoNext( &aEndPos ); pCNd = mxDoc->GetNodes().GoNext( &aEndPos );
pPam->GetPoint()->nNode = aEndPos; pPam->GetPoint()->nNode = aEndPos;
const sal_Int32 nLen = pCNd->Len(); const sal_Int32 nLen = pCNd->Len();
@@ -202,7 +202,7 @@ sal_uLong SwReader::Read( const Reader& rOptions )
SwTableBox* pBox = pTableBoxStart->GetTableBox(); SwTableBox* pBox = pTableBoxStart->GetTableBox();
if ( pBox ) if ( pBox )
{ {
pDoc->ChkBoxNumFormat( *pBox, true ); mxDoc->ChkBoxNumFormat( *pBox, true );
} }
} }
} }
@@ -222,9 +222,9 @@ sal_uLong SwReader::Read( const Reader& rOptions )
rNd.FindFooterStartNode(); rNd.FindFooterStartNode();
// search all new Fly's, and store them as individual Undo Objects // search all new Fly's, and store them as individual Undo Objects
for( SwFrameFormats::size_type n = 0; n < pDoc->GetSpzFrameFormats()->size(); ++n ) for( SwFrameFormats::size_type n = 0; n < mxDoc->GetSpzFrameFormats()->size(); ++n )
{ {
SwFrameFormat* pFrameFormat = (*pDoc->GetSpzFrameFormats())[ n ]; SwFrameFormat* pFrameFormat = (*mxDoc->GetSpzFrameFormats())[ n ];
const SwFormatAnchor& rAnchor = pFrameFormat->GetAnchor(); const SwFormatAnchor& rAnchor = pFrameFormat->GetAnchor();
if( !aFlyFrameArr.Contains( pFrameFormat) ) if( !aFlyFrameArr.Contains( pFrameFormat) )
{ {
@@ -245,7 +245,7 @@ sal_uLong SwReader::Read( const Reader& rOptions )
*pFrameAnchor, *pFrameAnchor,
*pUndoPam->GetPoint(), *pUndoPam->GetPoint(),
*pUndoPam->GetMark(), *pUndoPam->GetMark(),
pDoc) mxDoc.get())
) )
) )
) )
@@ -257,20 +257,20 @@ sal_uLong SwReader::Read( const Reader& rOptions )
{ {
// DrawObjects are not allowed in Headers/Footers! // DrawObjects are not allowed in Headers/Footers!
pFrameFormat->DelFrames(); pFrameFormat->DelFrames();
pDoc->DelFrameFormat( pFrameFormat ); mxDoc->DelFrameFormat( pFrameFormat );
--n; --n;
} }
else else
{ {
if( bSaveUndo ) if( bSaveUndo )
{ {
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
// UGLY: temp. enable undo // UGLY: temp. enable undo
pDoc->GetIDocumentUndoRedo().DoUndo(true); mxDoc->GetIDocumentUndoRedo().DoUndo(true);
pDoc->GetIDocumentUndoRedo().AppendUndo( mxDoc->GetIDocumentUndoRedo().AppendUndo(
new SwUndoInsLayFormat( pFrameFormat,0,0 ) ); new SwUndoInsLayFormat( pFrameFormat,0,0 ) );
pDoc->GetIDocumentUndoRedo().DoUndo(false); mxDoc->GetIDocumentUndoRedo().DoUndo(false);
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::Ignore ); mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::Ignore );
} }
if( pFrameFormat->HasWriterListeners() ) if( pFrameFormat->HasWriterListeners() )
{ {
@@ -286,7 +286,7 @@ sal_uLong SwReader::Read( const Reader& rOptions )
} }
else if( pCursor ) else if( pCursor )
{ {
pDoc->SetContainsAtPageObjWithContentAnchor( true ); mxDoc->SetContainsAtPageObjWithContentAnchor( true );
} }
} }
else else
@@ -298,22 +298,22 @@ sal_uLong SwReader::Read( const Reader& rOptions )
if( !aFlyFrameArr.empty() ) if( !aFlyFrameArr.empty() )
aFlyFrameArr.clear(); aFlyFrameArr.clear();
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
if( pDoc->getIDocumentRedlineAccess().IsRedlineOn() ) if( mxDoc->getIDocumentRedlineAccess().IsRedlineOn() )
pDoc->getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( nsRedlineType_t::REDLINE_INSERT, *pUndoPam ), true); mxDoc->getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( nsRedlineType_t::REDLINE_INSERT, *pUndoPam ), true);
else else
pDoc->getIDocumentRedlineAccess().SplitRedline( *pUndoPam ); mxDoc->getIDocumentRedlineAccess().SplitRedline( *pUndoPam );
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::Ignore ); mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::Ignore );
} }
if( bSaveUndo ) if( bSaveUndo )
{ {
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
pUndo->SetInsertRange( *pUndoPam, false ); pUndo->SetInsertRange( *pUndoPam, false );
// UGLY: temp. enable undo // UGLY: temp. enable undo
pDoc->GetIDocumentUndoRedo().DoUndo(true); mxDoc->GetIDocumentUndoRedo().DoUndo(true);
pDoc->GetIDocumentUndoRedo().AppendUndo( pUndo ); mxDoc->GetIDocumentUndoRedo().AppendUndo( pUndo );
pDoc->GetIDocumentUndoRedo().DoUndo(false); mxDoc->GetIDocumentUndoRedo().DoUndo(false);
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::Ignore ); mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::Ignore );
} }
delete pUndoPam; delete pUndoPam;
@@ -338,25 +338,25 @@ sal_uLong SwReader::Read( const Reader& rOptions )
} }
} }
pDoc->SetInReading( false ); mxDoc->SetInReading( false );
pDoc->SetInXMLImport( false ); mxDoc->SetInXMLImport( false );
pDoc->InvalidateNumRules(); mxDoc->InvalidateNumRules();
pDoc->UpdateNumRule(); mxDoc->UpdateNumRule();
pDoc->ChkCondColls(); mxDoc->ChkCondColls();
pDoc->SetAllUniqueFlyNames(); mxDoc->SetAllUniqueFlyNames();
pDoc->getIDocumentState().SetLoaded(); mxDoc->getIDocumentState().SetLoaded();
// Clear unassigned cell styles, because they aren't needed anymore. // Clear unassigned cell styles, because they aren't needed anymore.
pDoc->GetCellStyles().clear(); mxDoc->GetCellStyles().clear();
pDoc->GetIDocumentUndoRedo().DoUndo(bDocUndo); mxDoc->GetIDocumentUndoRedo().DoUndo(bDocUndo);
if (!bReadPageDescs) if (!bReadPageDescs)
{ {
if( bSaveUndo ) if( bSaveUndo )
{ {
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_INSDOKUMENT, nullptr ); mxDoc->GetIDocumentUndoRedo().EndUndo( UNDO_INSDOKUMENT, nullptr );
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::Ignore ); mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( RedlineFlags::Ignore );
} }
} }
@@ -368,26 +368,26 @@ sal_uLong SwReader::Read( const Reader& rOptions )
// #i42634# Moved common code of SwReader::Read() and // #i42634# Moved common code of SwReader::Read() and
// SwDocShell::UpdateLinks() to new SwDoc::UpdateLinks(): // SwDocShell::UpdateLinks() to new SwDoc::UpdateLinks():
// ATM still with Update // ATM still with Update
pDoc->getIDocumentLinksAdministration().UpdateLinks(); mxDoc->getIDocumentLinksAdministration().UpdateLinks();
// not insert: set the redline mode read from settings.xml // not insert: set the redline mode read from settings.xml
eOld = ePostReadRedlineFlags & ~RedlineFlags::Ignore; eOld = ePostReadRedlineFlags & ~RedlineFlags::Ignore;
pDoc->getIDocumentFieldsAccess().SetFieldsDirty(false, nullptr, 0); mxDoc->getIDocumentFieldsAccess().SetFieldsDirty(false, nullptr, 0);
} }
pDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld ); mxDoc->getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld );
pDoc->SetOle2Link( aOLELink ); mxDoc->SetOle2Link( aOLELink );
if( pCursor ) // das Doc ist jetzt modifiziert if( pCursor ) // das Doc ist jetzt modifiziert
pDoc->getIDocumentState().SetModified(); mxDoc->getIDocumentState().SetModified();
// #i38810# - If links have been updated, the document // #i38810# - If links have been updated, the document
// have to be modified. During update of links the OLE link at the document // have to be modified. During update of links the OLE link at the document
// isn't set. Thus, the document's modified state has to be set again after // isn't set. Thus, the document's modified state has to be set again after
// the OLE link is restored - see above <pDoc->SetOle2Link( aOLELink )>. // the OLE link is restored - see above <mxDoc->SetOle2Link( aOLELink )>.
if ( pDoc->getIDocumentLinksAdministration().LinksUpdated() ) if ( mxDoc->getIDocumentLinksAdministration().LinksUpdated() )
{ {
pDoc->getIDocumentState().SetModified(); mxDoc->getIDocumentState().SetModified();
} }
po->SetReadUTF8( false ); po->SetReadUTF8( false );