summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvo Hinkelmann <ihi@openoffice.org>2011-01-18 18:14:05 +0100
committerIvo Hinkelmann <ihi@openoffice.org>2011-01-18 18:14:05 +0100
commit92bcdd86ab68aa1d37061e8e72e1280fbb9a92f2 (patch)
treea6ca69a222b11280a48455e662faeafce3e3a795
parentCWS-TOOLING: integrate CWS chartextensibility (diff)
parentfwk162: #i115902# review usage of SfxObjectShellRef, SfxObjecShellLock (diff)
downloadcore-92bcdd86ab68aa1d37061e8e72e1280fbb9a92f2.tar.gz
core-92bcdd86ab68aa1d37061e8e72e1280fbb9a92f2.zip
CWS-TOOLING: integrate CWS fwk162
-rw-r--r--sw/inc/doc.hxx16
-rw-r--r--sw/inc/unomailmerge.hxx2
-rw-r--r--sw/source/core/doc/docglbl.cxx4
-rw-r--r--sw/source/core/doc/docnew.cxx21
-rw-r--r--sw/source/core/docnode/ndtbl.cxx7
-rw-r--r--sw/source/core/docnode/section.cxx10
-rw-r--r--sw/source/core/fields/expfld.cxx16
-rw-r--r--sw/source/core/ole/ndole.cxx18
-rw-r--r--sw/source/core/unocore/unocrsrhelper.cxx1
-rw-r--r--sw/source/core/view/vprint.cxx8
-rw-r--r--sw/source/filter/basflt/shellio.cxx6
-rw-r--r--sw/source/filter/ww8/ww8glsy.cxx2
-rw-r--r--sw/source/ui/app/appenv.cxx2
-rw-r--r--sw/source/ui/app/apphdl.cxx2
-rw-r--r--sw/source/ui/app/applab.cxx2
-rw-r--r--sw/source/ui/app/docsh.cxx23
-rw-r--r--sw/source/ui/app/docsh2.cxx2
-rw-r--r--sw/source/ui/dbui/dbmgr.cxx22
-rw-r--r--sw/source/ui/dbui/mmoutputpage.cxx6
-rw-r--r--sw/source/ui/dochdl/swdtflvr.cxx12
-rw-r--r--sw/source/ui/inc/swdtflvr.hxx2
-rw-r--r--sw/source/ui/inc/uivwimp.hxx7
-rw-r--r--sw/source/ui/inc/unotxvw.hxx2
-rw-r--r--sw/source/ui/inc/view.hxx6
-rw-r--r--sw/source/ui/uiview/view.cxx6
-rw-r--r--sw/source/ui/uiview/view2.cxx5
-rw-r--r--sw/source/ui/uno/unomailmerge.cxx1
-rw-r--r--sw/source/ui/uno/unotxdoc.cxx10
-rw-r--r--sw/source/ui/uno/unotxvw.cxx4
29 files changed, 112 insertions, 113 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 736fbb70a3b5..4aad1fb56cd1 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -74,6 +74,7 @@ class SwList;
#include <com/sun/star/linguistic2/XHyphenatedWord.hpp>
#include <vos/ref.hxx>
#include <svx/svdtypes.hxx>
+#include <sfx2/objsh.hxx>
#include <svl/style.hxx>
#include <editeng/numitem.hxx>
#include "comphelper/implementationreference.hxx"
@@ -94,8 +95,6 @@ class SwList;
#include <boost/scoped_ptr.hpp>
-class SfxObjectShell;
-class SfxObjectShellRef;
class SvxForbiddenCharactersTable;
class SwExtTextInput;
class DateTime;
@@ -358,9 +357,8 @@ class SW_DLLPUBLIC SwDoc :
SvxMacroTableDtor *pMacroTable; // Tabelle der dokumentglobalen Macros
SwDocShell *pDocShell; // Ptr auf die SfxDocShell vom Doc
- SfxObjectShellRef* pDocShRef; // fuers Kopieren von OLE-Nodes (wenn keine
- // DocShell gesetzt ist, muss dieser
- // Ref-Pointer gesetzt sein!!!!)
+ SfxObjectShellLock xTmpDocShell; // A temporary shell that is used to copy OLE-Nodes
+
sfx2::LinkManager *pLinkMgr; // Liste von Verknuepften (Grafiken/DDE/OLE)
SwAutoCorrExceptWord *pACEWord; // fuer die automatische Uebernahme von
@@ -1834,10 +1832,10 @@ public:
const SwDocShell* GetDocShell() const { return pDocShell; }
void SetDocShell( SwDocShell* pDSh );
- // falls beim Kopieren von OLE-Nodes eine DocShell angelegt werden muss,
- // dann MUSS der Ref-Pointer besetzt sein!!!!
- SfxObjectShellRef* GetRefForDocShell() { return pDocShRef; }
- void SetRefForDocShell( SfxObjectShellRef* p ) { pDocShRef = p; }
+ // in case during copying of embedded object a new shell is created,
+ // it should be set here and cleaned later
+ void SetTmpDocShell( SfxObjectShellLock rLock ) { xTmpDocShell = rLock; }
+ SfxObjectShellLock GetTmpDocShell() { return xTmpDocShell; }
// fuer die TextBausteine - diese habe nur ein SvPersist zur
// Verfuegung
diff --git a/sw/inc/unomailmerge.hxx b/sw/inc/unomailmerge.hxx
index 39a9664c4123..9e15051232a4 100644
--- a/sw/inc/unomailmerge.hxx
+++ b/sw/inc/unomailmerge.hxx
@@ -41,7 +41,7 @@
#include <com/sun/star/beans/PropertyChangeEvent.hpp>
#include <com/sun/star/text/XMailMergeBroadcaster.hpp>
#include <svl/itemprop.hxx>
-#include <sfx2/objsh.hxx> // SfxObjectShellRef
+#include <sfx2/objsh.hxx>
#include <functional>
diff --git a/sw/source/core/doc/docglbl.cxx b/sw/source/core/doc/docglbl.cxx
index 30a385442fc0..91c67cc96fb3 100644
--- a/sw/source/core/doc/docglbl.cxx
+++ b/sw/source/core/doc/docglbl.cxx
@@ -254,7 +254,7 @@ BOOL SwDoc::SplitDoc( USHORT eDocType, const String& rPath,
String sFileName;
if( pSttNd->GetIndex() + 1 < aEndIdx.GetIndex() )
{
- SfxObjectShellRef xDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
+ SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
if( xDocSh->DoInitNew( 0 ) )
{
SwDoc* pDoc = ((SwDocShell*)(&xDocSh))->GetDoc();
@@ -605,7 +605,7 @@ BOOL SwDoc::SplitDoc( USHORT eDocType, const String& rPath, int nOutlineLevel )
String sFileName;
if( pSttNd->GetIndex() + 1 < aEndIdx.GetIndex() )
{
- SfxObjectShellRef xDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
+ SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
if( xDocSh->DoInitNew( 0 ) )
{
SwDoc* pDoc = ((SwDocShell*)(&xDocSh))->GetDoc();
diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx
index 484b5119d9e5..e0d3437959c7 100644
--- a/sw/source/core/doc/docnew.cxx
+++ b/sw/source/core/doc/docnew.cxx
@@ -254,7 +254,6 @@ SwDoc::SwDoc() :
pFtnIdxs( new SwFtnIdxs ),
pDocStat( new SwDocStat ),
pDocShell( 0 ),
- pDocShRef( 0 ),
pLinkMgr( new sfx2::LinkManager( 0 ) ),
pACEWord( 0 ),
pURLStateChgd( 0 ),
@@ -1149,15 +1148,23 @@ SfxObjectShell* SwDoc::CreateCopy(bool bCallInitNew ) const
// COMPATIBILITY FLAGS END
//
pRet->ReplaceStyles( * const_cast< SwDoc*>( this ));
- SfxObjectShellRef aDocShellRef = const_cast< SwDocShell* >( GetDocShell() );
- pRet->SetRefForDocShell( boost::addressof(aDocShellRef) );
- SfxObjectShellRef xRetShell = new SwDocShell( pRet, SFX_CREATE_MODE_STANDARD );
+
+ // we have to use pointer here, since the callee has to decide whether SfxObjectShellLock or SfxObjectShellRef should be used
+ // sometimes the object will be returned with refcount set to 0 ( if no DoInitNew is done )
+ SfxObjectShell* pRetShell = new SwDocShell( pRet, SFX_CREATE_MODE_STANDARD );
if( bCallInitNew )
- xRetShell->DoInitNew();
+ {
+ // it could happen that DoInitNew creates model, that increases the refcount of the object
+ pRetShell->DoInitNew();
+ }
+
//copy content
pRet->Paste( *this );
- pRet->SetRefForDocShell( 0 );
- return xRetShell;
+
+ // remove the temporary shell if it is there as it was done before
+ pRet->SetTmpDocShell( (SfxObjectShell*)NULL );
+
+ return pRetShell;
}
/*-- 08.05.2009 10:52:40---------------------------------------------------
copy document content - code from SwFEShell::Paste( SwDoc* , BOOL )
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 588ef88f7740..5f21e32df796 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -4376,7 +4376,6 @@ BOOL SwDoc::InsCopyOfTbl( SwPosition& rInsPos, const SwSelBoxes& rBoxes,
}
SwDoc* pCpyDoc = (SwDoc*)pSrcTblNd->GetDoc();
- SfxObjectShellRef* pRefForDocSh = 0;
BOOL bDelCpyDoc = pCpyDoc == this;
if( bDelCpyDoc )
@@ -4384,13 +4383,10 @@ BOOL SwDoc::InsCopyOfTbl( SwPosition& rInsPos, const SwSelBoxes& rBoxes,
// kopiere die Tabelle erstmal in ein temp. Doc
pCpyDoc = new SwDoc;
pCpyDoc->acquire();
- pRefForDocSh = new SfxObjectShellRef();
- pCpyDoc->SetRefForDocShell( pRefForDocSh );
SwPosition aPos( SwNodeIndex( pCpyDoc->GetNodes().GetEndOfContent() ));
if( !pSrcTblNd->GetTable().MakeCopy( pCpyDoc, aPos, rBoxes, TRUE, TRUE ))
{
- delete pRefForDocSh;
if( pCpyDoc->release() == 0 )
delete pCpyDoc;
@@ -4403,8 +4399,6 @@ BOOL SwDoc::InsCopyOfTbl( SwPosition& rInsPos, const SwSelBoxes& rBoxes,
}
aPos.nNode -= 1; // auf den EndNode der Tabelle
pSrcTblNd = aPos.nNode.GetNode().FindTableNode();
-
- pCpyDoc->SetRefForDocShell( NULL );
}
const SwStartNode* pSttNd = rInsPos.nNode.GetNode().FindTableBoxStartNode();
@@ -4443,7 +4437,6 @@ BOOL SwDoc::InsCopyOfTbl( SwPosition& rInsPos, const SwSelBoxes& rBoxes,
if( bDelCpyDoc )
{
- delete pRefForDocSh;
if( pCpyDoc->release() == 0 )
delete pCpyDoc;
}
diff --git a/sw/source/core/docnode/section.cxx b/sw/source/core/docnode/section.cxx
index 2d54cb88f2e6..a0c16bd9d1e5 100644
--- a/sw/source/core/docnode/section.cxx
+++ b/sw/source/core/docnode/section.cxx
@@ -1319,9 +1319,10 @@ void lcl_UpdateLinksInSect( SwBaseLink& rUpdLnk, SwSectionNode& rSectNd )
// Der Return-Wert gibt an, was mit der Shell zu geschehen hat:
// 0 - Fehler, konnte DocShell nicht finden
// 1 - DocShell ist ein existieren Document
-// 2 - DocShell wurde neu angelegt, muss also wieder geschlossen werden
+// 2 - DocShell wurde neu angelegt, muss also wieder geschlossen werden ( will be assigned to xLockRef additionaly )
int lcl_FindDocShell( SfxObjectShellRef& xDocSh,
+ SfxObjectShellLock& xLockRef,
const String& rFileName,
const String& rPasswd,
String& rFilter,
@@ -1407,7 +1408,9 @@ int lcl_FindDocShell( SfxObjectShellRef& xDocSh,
// ohne Filter geht gar nichts
pMed->SetFilter( pSfxFlt );
- xDocSh = new SwDocShell( SFX_CREATE_MODE_INTERNAL );
+ // if the new shell is created, SfxObjectShellLock should be used to let it be closed later for sure
+ xLockRef = new SwDocShell( SFX_CREATE_MODE_INTERNAL );
+ xDocSh = (SfxObjectShell*)xLockRef;
if( xDocSh->DoLoad( pMed ) )
return 2;
}
@@ -1504,6 +1507,7 @@ void SwIntrnlSectRefLink::DataChanged( const String& rMimeType,
RedlineMode_t eOldRedlineMode = nsRedlineMode_t::REDLINE_NONE;
SfxObjectShellRef xDocSh;
+ SfxObjectShellLock xLockRef;
int nRet;
if( !sFileName.Len() )
{
@@ -1512,7 +1516,7 @@ void SwIntrnlSectRefLink::DataChanged( const String& rMimeType,
}
else
{
- nRet = lcl_FindDocShell( xDocSh, sFileName,
+ nRet = lcl_FindDocShell( xDocSh, xLockRef, sFileName,
rSection.GetLinkFilePassword(),
sFilter, 0, pDoc->GetDocShell() );
if( nRet )
diff --git a/sw/source/core/fields/expfld.cxx b/sw/source/core/fields/expfld.cxx
index e55c8598cf90..1be00582a586 100644
--- a/sw/source/core/fields/expfld.cxx
+++ b/sw/source/core/fields/expfld.cxx
@@ -76,10 +76,18 @@ sal_Int16 lcl_SubTypeToAPI(USHORT nSubType)
sal_Int16 nRet = 0;
switch(nSubType)
{
- case nsSwGetSetExpType::GSE_EXPR : nRet = SetVariableType::VAR /*0*/; break;
- case nsSwGetSetExpType::GSE_SEQ : nRet = SetVariableType::SEQUENCE /*1*/; break;
- case nsSwGetSetExpType::GSE_FORMULA : nRet = SetVariableType::FORMULA /*2*/; break;
- case nsSwGetSetExpType::GSE_STRING : nRet = SetVariableType::STRING /*3*/; break;
+ case nsSwGetSetExpType::GSE_EXPR:
+ nRet = SetVariableType::VAR; // 0
+ break;
+ case nsSwGetSetExpType::GSE_SEQ:
+ nRet = SetVariableType::SEQUENCE; // 1
+ break;
+ case nsSwGetSetExpType::GSE_FORMULA:
+ nRet = SetVariableType::FORMULA; // 2
+ break;
+ case nsSwGetSetExpType::GSE_STRING:
+ nRet = SetVariableType::STRING; // 3
+ break;
}
return nRet;
}
diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx
index 1cd0fdd02830..db341c9991ba 100644
--- a/sw/source/core/ole/ndole.cxx
+++ b/sw/source/core/ole/ndole.cxx
@@ -437,16 +437,14 @@ Size SwOLENode::GetTwipSize() const
SwCntntNode* SwOLENode::MakeCopy( SwDoc* pDoc, const SwNodeIndex& rIdx ) const
{
// Falls bereits eine SvPersist-Instanz existiert, nehmen wir diese
- SfxObjectShell* p = pDoc->GetPersist();
- if( !p )
+ SfxObjectShell* pPersistShell = pDoc->GetPersist();
+ if( !pPersistShell )
{
- // TODO/LATER: reicht hier nicht ein EmbeddedObjectContainer? Was passiert mit
- // diesem Dokument?
- ASSERT( pDoc->GetRefForDocShell(),
- "wo ist die Ref-Klasse fuer die DocShell?")
- p = new SwDocShell( pDoc, SFX_CREATE_MODE_INTERNAL );
- *pDoc->GetRefForDocShell() = p;
- p->DoInitNew( NULL );
+ // TODO/LATER: is EmbeddedObjectContainer not enough?
+ // the created document will be closed by pDoc ( should use SfxObjectShellLock )
+ pPersistShell = new SwDocShell( pDoc, SFX_CREATE_MODE_INTERNAL );
+ pDoc->SetTmpDocShell( pPersistShell );
+ pPersistShell->DoInitNew( NULL );
}
// Wir hauen das Ding auf SvPersist-Ebene rein
@@ -454,7 +452,7 @@ SwCntntNode* SwOLENode::MakeCopy( SwDoc* pDoc, const SwNodeIndex& rIdx ) const
::rtl::OUString aNewName/*( Sw3Io::UniqueName( p->GetStorage(), "Obj" ) )*/;
SfxObjectShell* pSrc = GetDoc()->GetPersist();
- p->GetEmbeddedObjectContainer().CopyAndGetEmbeddedObject(
+ pPersistShell->GetEmbeddedObjectContainer().CopyAndGetEmbeddedObject(
pSrc->GetEmbeddedObjectContainer(),
pSrc->GetEmbeddedObjectContainer().GetEmbeddedObject( aOLEObj.aName ),
aNewName );
diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx
index 92a33da130fe..9b60693c6755 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -935,6 +935,7 @@ void InsertFile(SwUnoCrsr* pUnoCrsr,
if( !pMed )
return;
+ // this sourcecode is not responsible for the lifetime of the shell, SfxObjectShellLock should not be used
SfxObjectShellRef aRef( pDocSh );
pDocSh->RegisterTransfer( *pMed );
diff --git a/sw/source/core/view/vprint.cxx b/sw/source/core/view/vprint.cxx
index 83e0289e6082..df6bcb377fb5 100644
--- a/sw/source/core/view/vprint.cxx
+++ b/sw/source/core/view/vprint.cxx
@@ -443,8 +443,8 @@ SwDoc * ViewShell::FillPrtDoc( SwDoc *pPrtDoc, const SfxPrinter* pPrt)
}
// es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!)
-// if( aDocShellRef.Is() )
-// SwDataExchange::InitOle( aDocShellRef, pPrtDoc );
+//REMOVE // if( aDocShellRef.Is() )
+//REMOVE // SwDataExchange::InitOle( aDocShellRef, pPrtDoc );
// und fuellen es mit dem selektierten Bereich
pFESh->Copy( pPrtDoc );
@@ -503,10 +503,6 @@ sal_Bool ViewShell::PrintOrPDFExport(
ViewShell *pShell;
SwDoc *pOutDevDoc;
- //!! muss warum auch immer hier in diesem scope existieren !!
- //!! (h?ngt mit OLE Objekten im Dokument zusammen.)
- SfxObjectShellRef aDocShellRef;
-
// Print/PDF export for (multi-)selection has already generated a
// temporary document with the selected text.
// (see XRenderable implementation in unotxdoc.cxx)
diff --git a/sw/source/filter/basflt/shellio.cxx b/sw/source/filter/basflt/shellio.cxx
index 963c5c847500..b0b69501979e 100644
--- a/sw/source/filter/basflt/shellio.cxx
+++ b/sw/source/filter/basflt/shellio.cxx
@@ -530,7 +530,7 @@ SwDoc* Reader::GetTemplateDoc()
{
SwDocShell *pDocSh =
new SwDocShell ( SFX_CREATE_MODE_INTERNAL );
- SfxObjectShellRef xDocSh = pDocSh;
+ SfxObjectShellLock xDocSh = pDocSh;
if( pDocSh->DoInitNew( 0 ) )
{
pTemplate = pDocSh->GetDoc();
@@ -805,15 +805,12 @@ ULONG SwWriter::Write( WriterRef& rxWriter, const String* pRealFileName )
SwPaM * pPam;
SwDoc *pDoc = 0;
- SfxObjectShellRef* pRefForDocSh = 0;
if ( pShell && !bWriteAll && pShell->IsTableMode() )
{
bWriteAll = TRUE;
pDoc = new SwDoc;
pDoc->acquire();
- pRefForDocSh = new SfxObjectShellRef();
- pDoc->SetRefForDocShell( pRefForDocSh );
// kopiere Teile aus einer Tabelle: lege eine Tabelle mit der Breite
// von der Originalen an und kopiere die selectierten Boxen.
@@ -971,7 +968,6 @@ ULONG SwWriter::Write( WriterRef& rxWriter, const String* pRealFileName )
if ( pDoc )
{
- delete pRefForDocSh;
if ( !pDoc->release() )
delete pDoc;
bWriteAll = FALSE;
diff --git a/sw/source/filter/ww8/ww8glsy.cxx b/sw/source/filter/ww8/ww8glsy.cxx
index 7d8bc56272b7..9ae2cf4ce442 100644
--- a/sw/source/filter/ww8/ww8glsy.cxx
+++ b/sw/source/filter/ww8/ww8glsy.cxx
@@ -219,7 +219,7 @@ bool WW8Glossary::Load( SwTextBlocks &rBlocks, bool bSaveRelFile )
if ( 0 != (nStrings = static_cast< USHORT >(aStrings.size())))
{
- SfxObjectShellRef xDocSh(new SwDocShell(SFX_CREATE_MODE_INTERNAL));
+ SfxObjectShellLock xDocSh(new SwDocShell(SFX_CREATE_MODE_INTERNAL));
if (xDocSh->DoInitNew(0))
{
SwDoc *pD = ((SwDocShell*)(&xDocSh))->GetDoc();
diff --git a/sw/source/ui/app/appenv.cxx b/sw/source/ui/app/appenv.cxx
index ce06c22cfc88..ee2e686a8400 100644
--- a/sw/source/ui/app/appenv.cxx
+++ b/sw/source/ui/app/appenv.cxx
@@ -189,7 +189,7 @@ static USHORT nTitleNo = 0;
pOldSh = pMyDocSh ? pMyDocSh->GetWrtShell() : 0;
// Neues Dokument erzeugen (kein Show!)
- SfxObjectShellRef xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
+ SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
xDocSh->DoInitNew( 0 );
pFrame = SfxViewFrame::LoadHiddenDocument( *xDocSh, 0 );
pNewView = (SwView*) pFrame->GetViewShell();
diff --git a/sw/source/ui/app/apphdl.cxx b/sw/source/ui/app/apphdl.cxx
index 653208aaf250..0002928c0eb6 100644
--- a/sw/source/ui/app/apphdl.cxx
+++ b/sw/source/ui/app/apphdl.cxx
@@ -968,7 +968,7 @@ void NewXForms( SfxRequest& rReq )
// copied & excerpted from SwModule::InsertLab(..)
// create new document
- SfxObjectShellRef xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD) );
+ SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD) );
xDocSh->DoInitNew( 0 );
// initialize XForms
diff --git a/sw/source/ui/app/applab.cxx b/sw/source/ui/app/applab.cxx
index 41f055f86050..1bbdfc71eeb4 100644
--- a/sw/source/ui/app/applab.cxx
+++ b/sw/source/ui/app/applab.cxx
@@ -209,7 +209,7 @@ static sal_uInt16 nBCTitleNo = 0;
aLabCfg.Commit();
// Neues Dokument erzeugen.
- SfxObjectShellRef xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD));
+ SfxObjectShellLock xDocSh( new SwDocShell( SFX_CREATE_MODE_STANDARD));
xDocSh->DoInitNew( 0 );
// Drucker
diff --git a/sw/source/ui/app/docsh.cxx b/sw/source/ui/app/docsh.cxx
index c839b5c03f52..7f48cdf40230 100644
--- a/sw/source/ui/app/docsh.cxx
+++ b/sw/source/ui/app/docsh.cxx
@@ -468,7 +468,9 @@ sal_Bool SwDocShell::SaveAs( SfxMedium& rMedium )
// will set the wrong class id.
SvGlobalName aClassName;
String aAppName, aLongUserName, aUserName;
- SfxObjectShellRef xDocSh =
+
+ // The document is closed explicitly, but using SfxObjectShellLock is still more correct here
+ SfxObjectShellLock xDocSh =
new SwGlobalDocShell( SFX_CREATE_MODE_INTERNAL );
// the global document can not be a template
xDocSh->SetupStorage( xStor, SotStorage::GetVersion( xStor ), sal_False );
@@ -701,25 +703,6 @@ BOOL SwDocShell::ConvertTo( SfxMedium& rMedium )
GetDoc()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, bIsGlblDocSaveLinksSave);
}
- if( bRet && nMyType != nSaveType )
- {
- SvGlobalName aClassName;
- String aAppName, aLongUserName, aUserName;
- SfxObjectShellRef xDocSh;
- switch( nSaveType )
- {
- case 0:
- xDocSh = new SwDocShell( SFX_CREATE_MODE_INTERNAL );
- break;
- case 1:
- xDocSh = new SwWebDocShell( SFX_CREATE_MODE_INTERNAL );
- break;
- case 2:
- xDocSh = new SwGlobalDocShell( SFX_CREATE_MODE_INTERNAL );
- break;
- }
- }
-
return bRet;
}
diff --git a/sw/source/ui/app/docsh2.cxx b/sw/source/ui/app/docsh2.cxx
index 5bbc29aab2ee..df49dc4b1e68 100644
--- a/sw/source/ui/app/docsh2.cxx
+++ b/sw/source/ui/app/docsh2.cxx
@@ -1013,7 +1013,7 @@ void SwDocShell::Execute(SfxRequest& rReq)
BYTE nLevel = pDlg->GetLevel();
BYTE nPara = pDlg->GetPara();
SwDoc* pSmryDoc = new SwDoc();
- SfxObjectShellRef xDocSh( new SwDocShell( pSmryDoc, SFX_CREATE_MODE_STANDARD));
+ SfxObjectShellLock xDocSh( new SwDocShell( pSmryDoc, SFX_CREATE_MODE_STANDARD));
xDocSh->DoInitNew( 0 );
BOOL bImpress = FN_ABSTRACT_STARIMPRESS == nWhich;
diff --git a/sw/source/ui/dbui/dbmgr.cxx b/sw/source/ui/dbui/dbmgr.cxx
index 90eeb6ee1982..94d7c8c2f057 100644
--- a/sw/source/ui/dbui/dbmgr.cxx
+++ b/sw/source/ui/dbui/dbmgr.cxx
@@ -938,7 +938,11 @@ BOOL SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
// in case of creating a single resulting file this has to be created here
SwWrtShell* pTargetShell = 0;
- SfxObjectShellRef xTargetDocShell;
+
+ // the shell will be explicitly closed at the end of the method, but it is
+ // still more safe to use SfxObjectShellLock here
+ SfxObjectShellLock xTargetDocShell;
+
SwView* pTargetView = 0;
std::auto_ptr< utl::TempFile > aTempFile;
String sModifiedStartingPageDesc;
@@ -1062,8 +1066,9 @@ BOOL SwNewDBMgr::MergeMailFiles(SwWrtShell* pSourceShell,
for (USHORT i = 0; i < 10; i++)
Application::Reschedule();
- // Neues Dokument erzeugen und speichern
- SfxObjectShellRef xWorkDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
+ // Create and save new document
+ // The SfxObjectShell will be closed explicitly later but it is more safe to use SfxObjectShellLock here
+ SfxObjectShellLock xWorkDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
SfxMedium* pWorkMed = new SfxMedium( sSourceDocumentURL, STREAM_STD_READ, TRUE );
pWorkMed->SetFilter( pSfxFlt );
@@ -1503,7 +1508,8 @@ ULONG SwNewDBMgr::GetColumnFmt( uno::Reference< XDataSource> xSource,
if(!xSource.is())
{
uno::Reference<XChild> xChild(xConnection, UNO_QUERY);
- xSource = uno::Reference<XDataSource>(xChild->getParent(), UNO_QUERY);
+ if ( xChild.is() )
+ xSource = uno::Reference<XDataSource>(xChild->getParent(), UNO_QUERY);
}
if(xSource.is() && xConnection.is() && xColumn.is() && pNFmtr)
{
@@ -2543,6 +2549,7 @@ void SwNewDBMgr::ExecuteFormLetter( SwWrtShell& rSh,
if(xResSet.is())
aDescriptor[daCursor] <<= xResSet;
+ // SfxObjectShellRef is ok, since there should be no control over the document lifetime here
SfxObjectShellRef xDocShell = rSh.GetView().GetViewFrame()->GetObjectShell();
SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE), xDocShell));
{
@@ -2573,7 +2580,9 @@ void SwNewDBMgr::ExecuteFormLetter( SwWrtShell& rSh,
}
else
{
- SfxObjectShellRef xWorkDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
+ // the shell will be explicitly closed, but it is more safe to use SfxObjectShellLock here
+ // especially for the case that the loading has failed
+ SfxObjectShellLock xWorkDocSh( new SwDocShell( SFX_CREATE_MODE_INTERNAL ));
SfxMedium* pWorkMed = new SfxMedium( sTempURL, STREAM_STD_READ, TRUE );
pWorkMed->SetFilter( pSfxFlt );
if( xWorkDocSh->DoLoad(pWorkMed) )
@@ -2916,7 +2925,8 @@ sal_Int32 SwNewDBMgr::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
}
// copy the source document
- SfxObjectShellRef xWorkDocSh;
+ // the copy will be closed later, but it is more safe to use SfxObjectShellLock here
+ SfxObjectShellLock xWorkDocSh;
if(nDocNo == 1 )
{
uno::Reference< util::XCloneable > xClone( rSourceView.GetDocShell()->GetModel(), uno::UNO_QUERY);
diff --git a/sw/source/ui/dbui/mmoutputpage.cxx b/sw/source/ui/dbui/mmoutputpage.cxx
index ee2803e73aad..943e21adee34 100644
--- a/sw/source/ui/dbui/mmoutputpage.cxx
+++ b/sw/source/ui/dbui/mmoutputpage.cxx
@@ -853,7 +853,8 @@ IMPL_LINK(SwMailMergeOutputPage, SaveOutputHdl_Impl, PushButton*, pButton)
aSaveMonitor.aPrintInfo.SetText(sStat);
//now extract a document from the target document
- SfxObjectShellRef xTempDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
+ // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
+ SfxObjectShellLock xTempDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
xTempDocShell->DoInitNew( 0 );
SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, 0 );
// pTempFrame->GetFrame().Appear();
@@ -1271,7 +1272,8 @@ IMPL_LINK(SwMailMergeOutputPage, SendDocumentsHdl_Impl, PushButton*, pButton)
SwDocMergeInfo& rInfo = rConfigItem.GetDocumentMergeInfo(nDoc);
//now extract a document from the target document
- SfxObjectShellRef xTempDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
+ // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
+ SfxObjectShellLock xTempDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
xTempDocShell->DoInitNew( 0 );
SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, 0 );
// pTempFrame->GetFrame().Appear();
diff --git a/sw/source/ui/dochdl/swdtflvr.cxx b/sw/source/ui/dochdl/swdtflvr.cxx
index 8220c7ee2c8d..2efe65c50079 100644
--- a/sw/source/ui/dochdl/swdtflvr.cxx
+++ b/sw/source/ui/dochdl/swdtflvr.cxx
@@ -454,14 +454,14 @@ sal_Bool SwTransferable::GetData( const DATA_FLAVOR& rFlavor )
pClpDocFac = new SwDocFac;
SwDoc *const pTmpDoc = lcl_GetDoc(*pClpDocFac);
- pTmpDoc->SetRefForDocShell( boost::addressof(aDocShellRef) );
pTmpDoc->LockExpFlds(); // nie die Felder updaten - Text so belassen
pWrtShell->Copy( pTmpDoc );
// es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!)
+ aDocShellRef = pTmpDoc->GetTmpDocShell();
if( aDocShellRef.Is() )
SwTransferable::InitOle( aDocShellRef, *pTmpDoc );
- pTmpDoc->SetRefForDocShell( 0 );
+ pTmpDoc->SetTmpDocShell( (SfxObjectShell*)NULL );
if( nSelectionType & nsSelectionType::SEL_TXT && !pWrtShell->HasMark() )
{
@@ -869,7 +869,6 @@ int SwTransferable::PrepareForCopy( BOOL bIsCut )
SwDoc *const pTmpDoc = lcl_GetDoc(*pClpDocFac);
- pTmpDoc->SetRefForDocShell( boost::addressof(aDocShellRef) );
pTmpDoc->LockExpFlds(); // nie die Felder updaten - Text so belassen
pWrtShell->Copy( pTmpDoc );
@@ -892,9 +891,10 @@ int SwTransferable::PrepareForCopy( BOOL bIsCut )
}
// es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!)
+ aDocShellRef = pTmpDoc->GetTmpDocShell();
if( aDocShellRef.Is() )
SwTransferable::InitOle( aDocShellRef, *pTmpDoc );
- pTmpDoc->SetRefForDocShell( 0 );
+ pTmpDoc->SetTmpDocShell( (SfxObjectShell*)NULL );
if( pWrtShell->IsObjSelected() )
eBufferType = TRNSFR_DRAWING;
@@ -1052,15 +1052,15 @@ int SwTransferable::CopyGlossary( SwTextBlocks& rGlossary,
SwCntntNode* pCNd = rNds.GoNext( &aNodeIdx ); // gehe zum 1. ContentNode
SwPaM aPam( *pCNd );
- pCDoc->SetRefForDocShell( boost::addressof(aDocShellRef) );
pCDoc->LockExpFlds(); // nie die Felder updaten - Text so belassen
pCDoc->InsertGlossary( rGlossary, rStr, aPam, 0 );
// es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!)
+ aDocShellRef = pCDoc->GetTmpDocShell();
if( aDocShellRef.Is() )
SwTransferable::InitOle( aDocShellRef, *pCDoc );
- pCDoc->SetRefForDocShell( 0 );
+ pCDoc->SetTmpDocShell( (SfxObjectShell*)NULL );
eBufferType = TRNSFR_DOCUMENT;
diff --git a/sw/source/ui/inc/swdtflvr.hxx b/sw/source/ui/inc/swdtflvr.hxx
index 041b55d9c6db..452637a3e7f8 100644
--- a/sw/source/ui/inc/swdtflvr.hxx
+++ b/sw/source/ui/inc/swdtflvr.hxx
@@ -65,7 +65,7 @@ namespace nsTransferBufferType
class SwTransferable : public TransferableHelper
{
friend class SwView_Impl;
- SfxObjectShellRef aDocShellRef;
+ SfxObjectShellLock aDocShellRef;
TransferableDataHelper aOleData;
TransferableObjectDescriptor aObjDesc;
::sfx2::SvBaseLinkRef refDdeLink;
diff --git a/sw/source/ui/inc/uivwimp.hxx b/sw/source/ui/inc/uivwimp.hxx
index 9c22b44ad868..509610500a3f 100644
--- a/sw/source/ui/inc/uivwimp.hxx
+++ b/sw/source/ui/inc/uivwimp.hxx
@@ -111,8 +111,7 @@ class SwView_Impl
// temporary document for printing text of selection / multi selection
// in PDF export.
- SfxObjectShellRef xTmpSelDocSh;
- SfxObjectShellRef aEmbeddedObjRef;
+ SfxObjectShellLock xTmpSelDocSh;
SwView* pView;
SwScannerEventListener* pScanEvtLstnr;
@@ -148,9 +147,7 @@ public:
void AddClipboardListener();
- SfxObjectShellRef & GetTmpSelectionDoc() { return xTmpSelDocSh; }
-
- SfxObjectShellRef& GetEmbeddedObjRef() { return *boost::addressof(aEmbeddedObjRef); }
+ SfxObjectShellLock& GetTmpSelectionDoc() { return xTmpSelDocSh; }
void AddTransferable(SwTransferable& rTransferable);
diff --git a/sw/source/ui/inc/unotxvw.hxx b/sw/source/ui/inc/unotxvw.hxx
index 4990df84f43b..1c8ad77e2054 100644
--- a/sw/source/ui/inc/unotxvw.hxx
+++ b/sw/source/ui/inc/unotxvw.hxx
@@ -156,7 +156,7 @@ public:
void Invalidate();
// temporary document used for PDF export of selections/multi-selections
- SfxObjectShellRef BuildTmpSelectionDoc();
+ SfxObjectShellLock BuildTmpSelectionDoc();
};
/* -----------------17.09.98 12:52-------------------
diff --git a/sw/source/ui/inc/view.hxx b/sw/source/ui/inc/view.hxx
index 0c92d7fdeb65..a462cd1deb6d 100644
--- a/sw/source/ui/inc/view.hxx
+++ b/sw/source/ui/inc/view.hxx
@@ -32,7 +32,7 @@
#include <svtools/htmlcfg.hxx>
#include <sfx2/viewfac.hxx>
#include <sfx2/viewsh.hxx>
-#include <sfx2/objsh.hxx> // SfxObjectShellRef <-> SV_DECL_REF(SfxObjectShell)
+#include <sfx2/objsh.hxx>
#include <editeng/svxenum.hxx>
#include <svx/zoomitem.hxx>
#include <editeng/editstat.hxx>
@@ -641,8 +641,8 @@ public:
void NotifyDBChanged();
- SfxObjectShellRef & GetTmpSelectionDoc();
- SfxObjectShellRef & GetOrCreateTmpSelectionDoc();
+ SfxObjectShellLock & GetTmpSelectionDoc();
+ SfxObjectShellLock & GetOrCreateTmpSelectionDoc();
void AddTransferable(SwTransferable& rTransferable);
diff --git a/sw/source/ui/uiview/view.cxx b/sw/source/ui/uiview/view.cxx
index 5c440d55883e..c1b93b56b96d 100644
--- a/sw/source/ui/uiview/view.cxx
+++ b/sw/source/ui/uiview/view.cxx
@@ -1897,16 +1897,16 @@ void SwView::NotifyDBChanged()
/* -----------------------------28.10.02 13:25--------------------------------
---------------------------------------------------------------------------*/
-SfxObjectShellRef & SwView::GetTmpSelectionDoc()
+SfxObjectShellLock & SwView::GetTmpSelectionDoc()
{
return GetViewImpl()->GetTmpSelectionDoc();
}
/* -----------------------------31.10.02 13:25--------------------------------
---------------------------------------------------------------------------*/
-SfxObjectShellRef & SwView::GetOrCreateTmpSelectionDoc()
+SfxObjectShellLock & SwView::GetOrCreateTmpSelectionDoc()
{
- SfxObjectShellRef &rxTmpDoc = GetViewImpl()->GetTmpSelectionDoc();
+ SfxObjectShellLock &rxTmpDoc = GetViewImpl()->GetTmpSelectionDoc();
if (!rxTmpDoc.Is())
{
SwXTextView *pImpl = GetViewImpl()->GetUNOObject_Impl();
diff --git a/sw/source/ui/uiview/view2.cxx b/sw/source/ui/uiview/view2.cxx
index eeab95b5bccd..7c4ee3924a4b 100644
--- a/sw/source/ui/uiview/view2.cxx
+++ b/sw/source/ui/uiview/view2.cxx
@@ -2142,14 +2142,15 @@ long SwView::InsertMedium( USHORT nSlotId, SfxMedium* pMedium, INT16 nVersion )
else
{
SfxObjectShellRef xDocSh;
+ SfxObjectShellLock xLockRef;
-extern int lcl_FindDocShell( SfxObjectShellRef& xDocSh,
+extern int lcl_FindDocShell( SfxObjectShellRef& xDocSh, SfxObjectShellLock& xLockRef,
const String& rFileName, const String& rPasswd,
String& rFilter, INT16 nVersion,
SwDocShell* pDestSh );
String sFltNm;
- int nRet = lcl_FindDocShell( xDocSh, pMedium->GetName(), aEmptyStr,
+ int nRet = lcl_FindDocShell( xDocSh, xLockRef, pMedium->GetName(), aEmptyStr,
sFltNm, nVersion, pDocSh );
if( nRet )
{
diff --git a/sw/source/ui/uno/unomailmerge.cxx b/sw/source/ui/uno/unomailmerge.cxx
index 06b9e62b4a94..256d5737f7f5 100644
--- a/sw/source/ui/uno/unomailmerge.cxx
+++ b/sw/source/ui/uno/unomailmerge.cxx
@@ -201,6 +201,7 @@ static BOOL LoadFromURL_impl(
}
else
{
+ // SfxObjectShellRef is ok here, since the document will be explicitly closed
SfxObjectShellRef xTmpDocSh = pTmpDocShell;
CloseModelAndDocSh( xTmpModel, xTmpDocSh );
}
diff --git a/sw/source/ui/uno/unotxdoc.cxx b/sw/source/ui/uno/unotxdoc.cxx
index b0b95657600c..2dea6feb88c9 100644
--- a/sw/source/ui/uno/unotxdoc.cxx
+++ b/sw/source/ui/uno/unotxdoc.cxx
@@ -2591,7 +2591,7 @@ SwDoc * SwXTextDocument::GetRenderDoc(
const TypeId aSwViewTypeId = TYPE(SwView);
if (rpView && rpView->IsA(aSwViewTypeId))
{
- SfxObjectShellRef xDocSh(((SwView*)rpView)->GetOrCreateTmpSelectionDoc());
+ SfxObjectShellLock xDocSh(((SwView*)rpView)->GetOrCreateTmpSelectionDoc());
if (xDocSh.Is())
{
pDoc = ((SwDocShell*)&xDocSh)->GetDoc();
@@ -3170,8 +3170,12 @@ uno::Reference< util::XCloneable > SwXTextDocument::createClone( ) throw (uno::
::vos::OGuard aGuard(Application::GetSolarMutex());
if(!IsValid())
throw RuntimeException();
- //create a new document - hidden - copy the storage and return it
- SfxObjectShell* pShell = pDocShell->GetDoc()->CreateCopy(false);
+
+ // create a new document - hidden - copy the storage and return it
+ // SfxObjectShellRef is used here, since the model should control object lifetime after creation
+ // and thus SfxObjectShellLock is not allowed here
+ // the model holds reference to the shell, so the shell will not destructed at the end of method
+ SfxObjectShellRef pShell = pDocShell->GetDoc()->CreateCopy(false);
uno::Reference< frame::XModel > xNewModel = pShell->GetModel();
uno::Reference< embed::XStorage > xNewStorage = ::comphelper::OStorageHelper::GetTemporaryStorage( );
uno::Sequence< beans::PropertyValue > aTempMediaDescriptor;
diff --git a/sw/source/ui/uno/unotxvw.cxx b/sw/source/ui/uno/unotxvw.cxx
index c03935464abf..5f533bde3f22 100644
--- a/sw/source/ui/uno/unotxvw.cxx
+++ b/sw/source/ui/uno/unotxvw.cxx
@@ -903,12 +903,12 @@ void SAL_CALL SwXTextView::setRubyList(
/*-- 29.12.02 15:45:29---------------------------------------------------
-----------------------------------------------------------------------*/
-SfxObjectShellRef SwXTextView::BuildTmpSelectionDoc()
+SfxObjectShellLock SwXTextView::BuildTmpSelectionDoc()
{
SwWrtShell& rOldSh = m_pView->GetWrtShell();
SfxPrinter *pPrt = rOldSh.getIDocumentDeviceAccess()->getPrinter( false );
SwDocShell* pDocSh;
- SfxObjectShellRef xDocSh( pDocSh = new SwDocShell( /*pPrtDoc, */SFX_CREATE_MODE_STANDARD ) );
+ SfxObjectShellLock xDocSh( pDocSh = new SwDocShell( /*pPrtDoc, */SFX_CREATE_MODE_STANDARD ) );
xDocSh->DoInitNew( 0 );
SwDoc *const pTempDoc( pDocSh->GetDoc() );
// #i103634#, #i112425#: do not expand numbering and fields on PDF export