sw/inc/doc.hxx | 4 sw/source/core/access/AccessibilityIssue.cxx | 22 +-- sw/source/core/crsr/swcrsr.cxx | 3 sw/source/core/doc/DocumentLinksAdministrationManager.cxx | 17 +-- sw/source/core/doc/docedt.cxx | 79 +++++++------- sw/source/core/doc/docglos.cxx | 14 +- sw/source/core/doc/docnew.cxx | 4 sw/source/core/doc/rdfhelper.cxx | 20 ++- sw/source/core/doc/textboxhelper.cxx | 8 - sw/source/core/doc/visiturl.cxx | 8 - sw/source/core/docnode/section.cxx | 19 +-- sw/source/core/draw/dpage.cxx | 9 + sw/source/core/draw/drawdoc.cxx | 4 sw/source/core/edit/edfcol.cxx | 34 +++--- sw/source/core/edit/edlingu.cxx | 5 sw/source/core/edit/edundo.cxx | 5 sw/source/core/fields/authfld.cxx | 4 sw/source/core/fields/textapi.cxx | 24 ++-- sw/source/core/frmedt/feflyole.cxx | 27 ++-- sw/source/core/layout/atrfrm.cxx | 11 + sw/source/core/layout/layact.cxx | 6 - sw/source/core/layout/paintfrm.cxx | 4 sw/source/core/layout/wsfrm.cxx | 6 - sw/source/core/swg/SwXMLTextBlocks1.cxx | 26 ++-- sw/source/core/text/itrform2.cxx | 42 +++---- sw/source/core/text/porlay.cxx | 70 ++++++------ sw/source/core/tox/txmsrt.cxx | 48 ++++---- sw/source/core/txtnode/ndtxt.cxx | 12 +- sw/source/core/unocore/unocoll.cxx | 19 ++- sw/source/core/unocore/unocrsrhelper.cxx | 38 +++--- sw/source/core/unocore/unoframe.cxx | 50 +++++--- sw/source/core/unocore/unoidx.cxx | 11 + sw/source/core/unocore/unosect.cxx | 13 +- sw/source/core/unocore/unostyle.cxx | 20 ++- sw/source/filter/docx/swdocxreader.cxx | 5 sw/source/filter/html/htmlbas.cxx | 6 - sw/source/filter/html/htmlcss1.cxx | 3 sw/source/filter/html/swhtml.cxx | 47 ++++---- sw/source/filter/rtf/swparrtf.cxx | 5 sw/source/filter/ww8/docxattributeoutput.cxx | 3 sw/source/filter/ww8/docxexport.cxx | 15 ++ sw/source/filter/ww8/docxexportfilter.cxx | 31 +++-- sw/source/filter/ww8/docxtablestyleexport.cxx | 5 sw/source/filter/ww8/ww8par.cxx | 9 + sw/source/filter/xml/xmlexp.cxx | 10 + sw/source/filter/xml/xmlimp.cxx | 20 +-- sw/source/filter/xml/xmltexti.cxx | 3 sw/source/ui/index/swuiidxmrk.cxx | 9 + sw/source/uibase/misc/redlndlg.cxx | 6 - sw/source/uibase/shells/grfshex.cxx | 11 + sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx | 3 sw/source/uibase/uno/unotxdoc.cxx | 13 +- sw/source/uibase/utlui/uitool.cxx | 3 53 files changed, 541 insertions(+), 352 deletions(-)
New commits: commit 112e07f37f87d6e5ae22bf91f9cccc896698ff87 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Fri Oct 25 10:14:48 2024 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Tue Nov 12 14:19:37 2024 +0100 sw: use SAL_RET_MAYBENULL in GetDocShell() similar to commit c796878e6af0fc7c886e813a0010d9402312eb5c Author: Xisco Fauli <xiscofa...@libreoffice.org> Date: Mon Oct 21 15:56:25 2024 +0200 tdf#163543: check GetDocShell() Change-Id: I4b489c59b7596466aea6b5c7b78248d82f193a0b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175628 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> Tested-by: Jenkins diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index e90b2b0278f5..e0e77c2971f2 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -1383,8 +1383,8 @@ public: */ // Pointer to SfxDocShell from Doc. Can be 0!! - SwDocShell* GetDocShell() { return mpDocShell; } - const SwDocShell* GetDocShell() const { return mpDocShell; } + SAL_RET_MAYBENULL SwDocShell* GetDocShell() { return mpDocShell; } + SAL_RET_MAYBENULL const SwDocShell* GetDocShell() const { return mpDocShell; } void SetDocShell( SwDocShell* pDSh ); /** in case during copying of embedded object a new shell is created, diff --git a/sw/source/core/access/AccessibilityIssue.cxx b/sw/source/core/access/AccessibilityIssue.cxx index 5c34449f6e40..a6e02f9a8b67 100644 --- a/sw/source/core/access/AccessibilityIssue.cxx +++ b/sw/source/core/access/AccessibilityIssue.cxx @@ -252,6 +252,10 @@ void AccessibilityIssue::quickFixIssue() const if (!m_pDoc) return; + SwDocShell* pShell = m_pDoc->GetDocShell(); + if (!pShell) + return; + if (canGotoIssue()) gotoIssue(); @@ -270,7 +274,7 @@ void AccessibilityIssue::quickFixIssue() const OUString aTitle(pFlyFormat->GetObjTitle()); bool isDecorative(pFlyFormat->IsDecorative()); - SwWrtShell* pWrtShell = m_pDoc->GetDocShell()->GetWrtShell(); + SwWrtShell* pWrtShell = pShell->GetWrtShell(); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); VclPtr<AbstractSvxObjectTitleDescDialog> pDlg(pFact->CreateSvxObjectTitleDescDialog( pWrtShell->GetView().GetFrameWeld(), aTitle, aDescription, isDecorative)); @@ -296,7 +300,7 @@ void AccessibilityIssue::quickFixIssue() const case IssueObject::SHAPE: case IssueObject::FORM: { - SwWrtShell* pWrtShell = m_pDoc->GetDocShell()->GetWrtShell(); + SwWrtShell* pWrtShell = pShell->GetWrtShell(); auto pPage = pWrtShell->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0); SdrObject* pObj = pPage->GetObjByName(m_sObjectID); if (pObj) @@ -329,7 +333,7 @@ void AccessibilityIssue::quickFixIssue() const case IssueObject::HYPERLINKTEXT: { SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - SwWrtShell* pWrtShell = m_pDoc->GetDocShell()->GetWrtShell(); + SwWrtShell* pWrtShell = pShell->GetWrtShell(); ScopedVclPtr<AbstractSvxNameDialog> aNameDialog(pFact->CreateSvxNameDialog( pWrtShell->GetView().GetFrameWeld(), OUString(), SwResId(STR_HYPERLINK_NO_NAME_DLG), SwResId(STR_HYPERLINK_NO_NAME_DLG))); @@ -356,16 +360,12 @@ void AccessibilityIssue::quickFixIssue() const case IssueObject::DOCUMENT_TITLE: { SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - SwWrtShell* pWrtShell = m_pDoc->GetDocShell()->GetWrtShell(); + SwWrtShell* pWrtShell = pShell->GetWrtShell(); ScopedVclPtr<AbstractSvxNameDialog> aNameDialog(pFact->CreateSvxNameDialog( pWrtShell->GetView().GetFrameWeld(), OUString(), SwResId(STR_DOCUMENT_TITLE_DLG_DESC), SwResId(STR_DOCUMENT_TITLE_DLG_TITLE))); if (aNameDialog->Execute() == RET_OK) { - SwDocShell* pShell = m_pDoc->GetDocShell(); - if (!pShell) - return; - const uno::Reference<document::XDocumentPropertiesSupplier> xDPS( pShell->GetModel(), uno::UNO_QUERY_THROW); const uno::Reference<document::XDocumentProperties> xDocumentProperties( @@ -378,8 +378,7 @@ void AccessibilityIssue::quickFixIssue() const break; case IssueObject::DOCUMENT_BACKGROUND: { - uno::Reference<frame::XModel> xModel(m_pDoc->GetDocShell()->GetModel(), - uno::UNO_QUERY_THROW); + uno::Reference<frame::XModel> xModel(pShell->GetModel(), uno::UNO_QUERY_THROW); comphelper::dispatchCommand(u".uno:PageAreaDialog"_ustr, xModel->getCurrentController()->getFrame(), {}); @@ -387,8 +386,7 @@ void AccessibilityIssue::quickFixIssue() const break; case IssueObject::LANGUAGE_NOT_SET: { - uno::Reference<frame::XModel> xModel(m_pDoc->GetDocShell()->GetModel(), - uno::UNO_QUERY_THROW); + uno::Reference<frame::XModel> xModel(pShell->GetModel(), uno::UNO_QUERY_THROW); if (m_sObjectID.isEmpty()) { diff --git a/sw/source/core/crsr/swcrsr.cxx b/sw/source/core/crsr/swcrsr.cxx index bf68081de1fe..a195759f452c 100644 --- a/sw/source/core/crsr/swcrsr.cxx +++ b/sw/source/core/crsr/swcrsr.cxx @@ -733,7 +733,8 @@ bool SwCursor::IsAtValidPos( bool bPoint ) const } // #i45129# - in UI-ReadOnly everything is allowed - if( !rDoc.GetDocShell() || !rDoc.GetDocShell()->IsReadOnlyUI() ) + const SwDocShell* pShell = rDoc.GetDocShell(); + if( !pShell || !pShell->IsReadOnlyUI() ) return true; const bool bCursorInReadOnly = IsReadOnlyAvailable(); diff --git a/sw/source/core/doc/DocumentLinksAdministrationManager.cxx b/sw/source/core/doc/DocumentLinksAdministrationManager.cxx index 1c13b3c50729..be6eb0f17d1b 100644 --- a/sw/source/core/doc/DocumentLinksAdministrationManager.cxx +++ b/sw/source/core/doc/DocumentLinksAdministrationManager.cxx @@ -189,19 +189,20 @@ const sfx2::LinkManager& DocumentLinksAdministrationManager::GetLinkManager() co // to new SwDoc::UpdateLinks(): void DocumentLinksAdministrationManager::UpdateLinks() { - if (!m_rDoc.GetDocShell()) + SwDocShell* pShell = m_rDoc.GetDocShell(); + if (!pShell) return; - SfxObjectCreateMode eMode = m_rDoc.GetDocShell()->GetCreateMode(); + SfxObjectCreateMode eMode = pShell->GetCreateMode(); if (eMode == SfxObjectCreateMode::INTERNAL) return; if (eMode == SfxObjectCreateMode::ORGANIZER) return; - if (m_rDoc.GetDocShell()->IsPreview()) + if (pShell->IsPreview()) return; if (GetLinkManager().GetLinks().empty()) return; sal_uInt16 nLinkMode = m_rDoc.GetDocumentSettingManager().getLinkUpdateMode(true); - sal_uInt16 nUpdateDocMode = m_rDoc.GetDocShell()->GetUpdateDocMode(); + sal_uInt16 nUpdateDocMode = pShell->GetUpdateDocMode(); if (nLinkMode == NEVER && nUpdateDocMode != document::UpdateDocMode::FULL_UPDATE) return; @@ -215,20 +216,20 @@ void DocumentLinksAdministrationManager::UpdateLinks() } if (nLinkMode == AUTOMATIC && !bAskUpdate) { - SfxMedium * medium = m_rDoc.GetDocShell()->GetMedium(); + SfxMedium * medium = pShell->GetMedium(); if (!SvtSecurityOptions::isTrustedLocationUriForUpdatingLinks( medium == nullptr ? OUString() : medium->GetName())) { bAskUpdate = true; } } - comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = m_rDoc.GetDocShell()->getEmbeddedObjectContainer(); + comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = pShell->getEmbeddedObjectContainer(); if (bUpdate) { rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true); - weld::Window* pDlgParent = GetFrameWeld(m_rDoc.GetDocShell()); - SfxMedium * medium = m_rDoc.GetDocShell()->GetMedium(); + weld::Window* pDlgParent = GetFrameWeld(pShell); + SfxMedium * medium = pShell->GetMedium(); GetLinkManager().UpdateAllLinks( bAskUpdate, false, pDlgParent, medium == nullptr ? OUString() : medium->GetName()); } diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx index 1a0389e14416..c5dc09a64f3b 100644 --- a/sw/source/core/doc/docedt.cxx +++ b/sw/source/core/doc/docedt.cxx @@ -621,45 +621,48 @@ uno::Any SwDoc::Spell( SwPaM& rPaM, uno::Reference< linguistic2::XProofreadingIterator > xGCIterator( GetGCIterator() ); if (xGCIterator.is()) { - rtl::Reference< SwXTextDocument > xDoc = GetDocShell()->GetBaseModel(); - // Expand the string: - const ModelToViewHelper aConversionMap(*pNd->GetTextNode(), pLayout); - const OUString& aExpandText = aConversionMap.getViewText(); - - // get XFlatParagraph to use... - uno::Reference< text::XFlatParagraph > xFlatPara = new SwXFlatParagraph( *pNd->GetTextNode(), aExpandText, aConversionMap ); - - // get error position of cursor in XFlatParagraph - linguistic2::ProofreadingResult aResult; - bool bGrammarErrors; - do + if (const SwDocShell* pShell = GetDocShell()) { - aConversionMap.ConvertToViewPosition( nBeginGrammarCheck ); - aResult = xGCIterator->checkSentenceAtPosition( - cppu::getXWeak(xDoc.get()), xFlatPara, aExpandText, lang::Locale(), nBeginGrammarCheck, -1, -1 ); - - lcl_syncGrammarError( *pNd->GetTextNode(), aResult, aConversionMap ); - - // get suggestions to use for the specific error position - bGrammarErrors = aResult.aErrors.hasElements(); - // if grammar checking doesn't have any progress then quit - if( aResult.nStartOfNextSentencePosition <= nBeginGrammarCheck ) - break; - // prepare next iteration - nBeginGrammarCheck = aResult.nStartOfNextSentencePosition; - } - while( nSpellErrorPosition > aResult.nBehindEndOfSentencePosition && !bGrammarErrors && aResult.nBehindEndOfSentencePosition < nEndGrammarCheck ); - - if( bGrammarErrors && nSpellErrorPosition >= aResult.nBehindEndOfSentencePosition ) - { - aRet <<= aResult; - //put the cursor to the current error - const linguistic2::SingleProofreadingError &rError = aResult.aErrors[0]; - pSttPos->Assign(nCurrNd, pSttPos->GetContentIndex()); - pEndPos->Assign(nCurrNd, pEndPos->GetContentIndex()); - pSpellArgs->pStartPos->Assign(*pNd->GetTextNode(), aConversionMap.ConvertToModelPosition( rError.nErrorStart ).mnPos ); - pSpellArgs->pEndPos->Assign(*pNd->GetTextNode(), aConversionMap.ConvertToModelPosition( rError.nErrorStart + rError.nErrorLength ).mnPos ); - nCurrNd = nEndNd; + rtl::Reference< SwXTextDocument > xDoc = pShell->GetBaseModel(); + // Expand the string: + const ModelToViewHelper aConversionMap(*pNd->GetTextNode(), pLayout); + const OUString& aExpandText = aConversionMap.getViewText(); + + // get XFlatParagraph to use... + uno::Reference< text::XFlatParagraph > xFlatPara = new SwXFlatParagraph( *pNd->GetTextNode(), aExpandText, aConversionMap ); + + // get error position of cursor in XFlatParagraph + linguistic2::ProofreadingResult aResult; + bool bGrammarErrors; + do + { + aConversionMap.ConvertToViewPosition( nBeginGrammarCheck ); + aResult = xGCIterator->checkSentenceAtPosition( + cppu::getXWeak(xDoc.get()), xFlatPara, aExpandText, lang::Locale(), nBeginGrammarCheck, -1, -1 ); + + lcl_syncGrammarError( *pNd->GetTextNode(), aResult, aConversionMap ); + + // get suggestions to use for the specific error position + bGrammarErrors = aResult.aErrors.hasElements(); + // if grammar checking doesn't have any progress then quit + if( aResult.nStartOfNextSentencePosition <= nBeginGrammarCheck ) + break; + // prepare next iteration + nBeginGrammarCheck = aResult.nStartOfNextSentencePosition; + } + while( nSpellErrorPosition > aResult.nBehindEndOfSentencePosition && !bGrammarErrors && aResult.nBehindEndOfSentencePosition < nEndGrammarCheck ); + + if( bGrammarErrors && nSpellErrorPosition >= aResult.nBehindEndOfSentencePosition ) + { + aRet <<= aResult; + //put the cursor to the current error + const linguistic2::SingleProofreadingError &rError = aResult.aErrors[0]; + pSttPos->Assign(nCurrNd, pSttPos->GetContentIndex()); + pEndPos->Assign(nCurrNd, pEndPos->GetContentIndex()); + pSpellArgs->pStartPos->Assign(*pNd->GetTextNode(), aConversionMap.ConvertToModelPosition( rError.nErrorStart ).mnPos ); + pSpellArgs->pEndPos->Assign(*pNd->GetTextNode(), aConversionMap.ConvertToModelPosition( rError.nErrorStart + rError.nErrorLength ).mnPos ); + nCurrNd = nEndNd; + } } } } diff --git a/sw/source/core/doc/docglos.cxx b/sw/source/core/doc/docglos.cxx index dae24d1cdfd6..2deb1993ae98 100644 --- a/sw/source/core/doc/docglos.cxx +++ b/sw/source/core/doc/docglos.cxx @@ -42,8 +42,12 @@ void SwDoc::ReplaceUserDefinedDocumentProperties( { OSL_ENSURE(xSourceDocProps.is(), "null reference"); + SwDocShell* pShell = GetDocShell(); + if (!pShell) + return; + uno::Reference<document::XDocumentPropertiesSupplier> xDPS( - GetDocShell()->GetModel(), uno::UNO_QUERY_THROW); + pShell->GetModel(), uno::UNO_QUERY_THROW); uno::Reference<document::XDocumentProperties> xDocProps( xDPS->getDocumentProperties() ); OSL_ENSURE(xDocProps.is(), "null reference"); @@ -82,14 +86,18 @@ void SwDoc::ReplaceUserDefinedDocumentProperties( void SwDoc::ReplaceDocumentProperties(const SwDoc& rSource, bool mailMerge) { + SwDocShell* pShell = GetDocShell(); + const SwDocShell* pSourceShell = rSource.GetDocShell(); + if (!pShell || !pSourceShell) + return; uno::Reference<document::XDocumentPropertiesSupplier> xSourceDPS( - rSource.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW); + pSourceShell->GetModel(), uno::UNO_QUERY_THROW); uno::Reference<document::XDocumentProperties> xSourceDocProps( xSourceDPS->getDocumentProperties() ); OSL_ENSURE(xSourceDocProps.is(), "null reference"); uno::Reference<document::XDocumentPropertiesSupplier> xDPS( - GetDocShell()->GetModel(), uno::UNO_QUERY_THROW); + pShell->GetModel(), uno::UNO_QUERY_THROW); uno::Reference<document::XDocumentProperties> xDocProps( xDPS->getDocumentProperties() ); OSL_ENSURE(xDocProps.is(), "null reference"); diff --git a/sw/source/core/doc/docnew.cxx b/sw/source/core/doc/docnew.cxx index 95e3f351621b..f3b9e768557a 100644 --- a/sw/source/core/doc/docnew.cxx +++ b/sw/source/core/doc/docnew.cxx @@ -147,6 +147,8 @@ bool SwDoc::StartGrammarChecking( bool bSkipStart ) bool bVisible = false; bool bStarted = false; const SwDocShell *pDocShell = GetDocShell(); + if (!pDocShell) + return bStarted; SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pDocShell, false ); while (pFrame && !bVisible) { @@ -164,7 +166,7 @@ bool SwDoc::StartGrammarChecking( bool bSkipStart ) uno::Reference< linguistic2::XProofreadingIterator > xGCIterator( GetGCIterator() ); if ( xGCIterator.is() ) { - rtl::Reference< SwXTextDocument > xDoc = GetDocShell()->GetBaseModel(); + rtl::Reference< SwXTextDocument > xDoc = pDocShell->GetBaseModel(); uno::Reference< text::XFlatParagraphIteratorProvider > xFPIP( xDoc ); // start automatic background checking if not active already diff --git a/sw/source/core/doc/rdfhelper.cxx b/sw/source/core/doc/rdfhelper.cxx index 5d6c573821da..55bce35496a1 100644 --- a/sw/source/core/doc/rdfhelper.cxx +++ b/sw/source/core/doc/rdfhelper.cxx @@ -172,20 +172,29 @@ void SwRDFHelper::clearStatements(const rtl::Reference<SwXTextDocument>& xModel, std::map<OUString, OUString> SwRDFHelper::getTextNodeStatements(const OUString& rType, SwTextNode& rTextNode) { uno::Reference<rdf::XResource> xTextNode(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode, nullptr)); - return getStatements(rTextNode.GetDoc().GetDocShell()->GetBaseModel(), rType, xTextNode); + SwDocShell* pShell = rTextNode.GetDoc().GetDocShell(); + if (!pShell) + return std::map<OUString, OUString>(); + return getStatements(pShell->GetBaseModel(), rType, xTextNode); } void SwRDFHelper::addTextNodeStatement(const OUString& rType, const OUString& rPath, SwTextNode& rTextNode, const OUString& rKey, const OUString& rValue) { uno::Reference<rdf::XResource> xSubject(SwXParagraph::CreateXParagraph(rTextNode.GetDoc(), &rTextNode, nullptr)); - addStatement(rTextNode.GetDoc().GetDocShell()->GetBaseModel(), rType, rPath, xSubject, rKey, rValue); + SwDocShell* pShell = rTextNode.GetDoc().GetDocShell(); + if (!pShell) + return; + addStatement(pShell->GetBaseModel(), rType, rPath, xSubject, rKey, rValue); } void SwRDFHelper::removeTextNodeStatement(const OUString& rType, SwTextNode& rTextNode, const OUString& rKey, const OUString& rValue) { const uno::Reference<uno::XComponentContext>& xComponentContext(comphelper::getProcessComponentContext()); uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType); - rtl::Reference<SwXTextDocument> xModel(rTextNode.GetDoc().GetDocShell()->GetBaseModel()); + SwDocShell* pShell = rTextNode.GetDoc().GetDocShell(); + if (!pShell) + return; + rtl::Reference<SwXTextDocument> xModel(pShell->GetBaseModel()); uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel); const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = getGraphNames(xDocumentMetadataAccess, xType); if (!aGraphNames.hasElements()) @@ -203,7 +212,10 @@ void SwRDFHelper::updateTextNodeStatement(const OUString& rType, const OUString& { const uno::Reference<uno::XComponentContext>& xComponentContext(comphelper::getProcessComponentContext()); uno::Reference<rdf::XURI> xType = rdf::URI::create(xComponentContext, rType); - rtl::Reference<SwXTextDocument> xModel(rTextNode.GetDoc().GetDocShell()->GetBaseModel()); + SwDocShell* pShell = rTextNode.GetDoc().GetDocShell(); + if (!pShell) + return; + rtl::Reference<SwXTextDocument> xModel(pShell->GetBaseModel()); uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(xModel); const uno::Sequence< uno::Reference<rdf::XURI> > aGraphNames = getGraphNames(xDocumentMetadataAccess, xType); uno::Reference<rdf::XURI> xGraphName; diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index 92fc92dc62c5..222887b51e92 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -106,9 +106,11 @@ void SwTextBoxHelper::create(SwFrameFormat* pShape, SdrObject* pObject, bool bCo if (!xTextContentAppend) { - rtl::Reference<SwXTextDocument> xTextDocument( - pShape->GetDoc()->GetDocShell()->GetBaseModel()); - xTextContentAppend.set(xTextDocument->getText(), uno::UNO_QUERY_THROW); + if (SwDocShell* pShell = pShape->GetDoc()->GetDocShell()) + { + rtl::Reference<SwXTextDocument> xTextDocument(pShell->GetBaseModel()); + xTextContentAppend.set(xTextDocument->getText(), uno::UNO_QUERY_THROW); + } } if (xAnchor) diff --git a/sw/source/core/doc/visiturl.cxx b/sw/source/core/doc/visiturl.cxx index 47b75ea1347d..34d5e93f2d29 100644 --- a/sw/source/core/doc/visiturl.cxx +++ b/sw/source/core/doc/visiturl.cxx @@ -49,13 +49,13 @@ void SwURLStateChanged::Notify( SfxBroadcaster& , const SfxHint& rHint ) const INetURLObject* pIURL = static_cast<const INetURLHistoryHint&>(rHint).GetObject(); OUString sURL( pIURL->GetMainURL( INetURLObject::DecodeMechanism::NONE ) ), sBkmk; - SwEditShell* pESh = m_rDoc.GetEditShell(); - - if( m_rDoc.GetDocShell() && m_rDoc.GetDocShell()->GetMedium() && + SwDocShell* pShell = m_rDoc.GetDocShell(); + if( pShell && pShell->GetMedium() && // If this is our Doc, we can also have local jumps! - m_rDoc.GetDocShell()->GetMedium()->GetName() == sURL ) + pShell->GetMedium()->GetName() == sURL ) sBkmk = "#" + pIURL->GetMark(); + SwEditShell* pESh = m_rDoc.GetEditShell(); bool bAction = false, bUnLockView = false; m_rDoc.ForEachINetFormat( [&sURL, &sBkmk, &bAction, &pESh, &bUnLockView] (const SwFormatINetFormat& rFormatItem) -> bool diff --git a/sw/source/core/docnode/section.cxx b/sw/source/core/docnode/section.cxx index f9cb6efbee63..c539c7531dc8 100644 --- a/sw/source/core/docnode/section.cxx +++ b/sw/source/core/docnode/section.cxx @@ -1295,16 +1295,19 @@ static void lcl_UpdateLinksInSect( const SwBaseLink& rUpdLnk, SwSectionNode& rSe pPam = pCursor; } - SvMemoryStream aStrm( const_cast<sal_Int8 *>(aSeq.getConstArray()), aSeq.getLength(), - StreamMode::READ ); - aStrm.Seek( 0 ); + if (SwDocShell* pShell = pDoc->GetDocShell()) + { + SvMemoryStream aStrm( const_cast<sal_Int8 *>(aSeq.getConstArray()), aSeq.getLength(), + StreamMode::READ ); + aStrm.Seek( 0 ); - // TODO/MBA: it's impossible to set a BaseURL here! - SwReader aTmpReader( aStrm, OUString(), pDoc->GetDocShell()->GetMedium()->GetBaseURL(), *pPam ); + // TODO/MBA: it's impossible to set a BaseURL here! + SwReader aTmpReader( aStrm, OUString(), pShell->GetMedium()->GetBaseURL(), *pPam ); - if( ! aTmpReader.Read( *pRead ).IsError() ) - { - rSection.SetConnectFlag(); + if( ! aTmpReader.Read( *pRead ).IsError() ) + { + rSection.SetConnectFlag(); + } } if( pESh ) diff --git a/sw/source/core/draw/dpage.cxx b/sw/source/core/draw/dpage.cxx index 699c50604f0f..b082de341037 100644 --- a/sw/source/core/draw/dpage.cxx +++ b/sw/source/core/draw/dpage.cxx @@ -223,9 +223,12 @@ bool SwDPage::RequestHelp( vcl::Window* pWindow, SdrView const * pView, if (!sText.isEmpty()) { // #i80029# - bool bExecHyperlinks = m_pDoc->GetDocShell()->IsReadOnly(); - if (!bExecHyperlinks && !bTooltip) - sText = SfxHelp::GetURLHelpText(sText); + if (SwDocShell* pDocShell = m_pDoc->GetDocShell()) + { + bool bExecHyperlinks = pDocShell->IsReadOnly(); + if (!bExecHyperlinks && !bTooltip) + sText = SfxHelp::GetURLHelpText(sText); + } // then display the help: tools::Rectangle aScreenRect(pWindow->OutputToScreenPixel(aPixRect.TopLeft()), diff --git a/sw/source/core/draw/drawdoc.cxx b/sw/source/core/draw/drawdoc.cxx index 4c3006cb0b9a..9bfbea0d6a7b 100644 --- a/sw/source/core/draw/drawdoc.cxx +++ b/sw/source/core/draw/drawdoc.cxx @@ -133,9 +133,9 @@ uno::Reference< frame::XModel > SwDrawModel::createUnoModel() try { - if ( GetDoc().GetDocShell() ) + if ( SwDocShell* pShell = GetDoc().GetDocShell() ) { - xModel = GetDoc().GetDocShell()->GetModel(); + xModel = pShell->GetModel(); } } catch( uno::RuntimeException& ) diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 44125de5c46c..452b487970fd 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -1681,18 +1681,21 @@ SwUndoParagraphSigning::SwUndoParagraphSigning(SwDoc& rDoc, m_bRemove(bRemove) { // Save the metadata and field content to undo/redo. - rtl::Reference<SwXTextDocument> xModel = m_rDoc.GetDocShell()->GetBaseModel(); - const std::map<OUString, OUString> aStatements = lcl_getRDFStatements(xModel, m_xField); - const auto it = aStatements.find(ParagraphSignatureIdRDFName); - if (it != aStatements.end()) - m_signature = it->second; - - const auto it2 = aStatements.find(ParagraphSignatureUsageRDFName); - if (it2 != aStatements.end()) - m_usage = it2->second; - - uno::Reference<css::text::XTextRange> xText(m_xField, uno::UNO_QUERY); - m_display = xText->getString(); + if (SwDocShell* pShell = m_rDoc.GetDocShell()) + { + rtl::Reference<SwXTextDocument> xModel = pShell->GetBaseModel(); + const std::map<OUString, OUString> aStatements = lcl_getRDFStatements(xModel, m_xField); + const auto it = aStatements.find(ParagraphSignatureIdRDFName); + if (it != aStatements.end()) + m_signature = it->second; + + const auto it2 = aStatements.find(ParagraphSignatureUsageRDFName); + if (it2 != aStatements.end()) + m_usage = it2->second; + + uno::Reference<css::text::XTextRange> xText(m_xField, uno::UNO_QUERY); + m_display = xText->getString(); + } } void SwUndoParagraphSigning::UndoImpl(::sw::UndoRedoContext&) @@ -1731,8 +1734,11 @@ void SwUndoParagraphSigning::Insert() m_rDoc.GetIDocumentUndoRedo().DoUndo(isUndoEnabled); }); - m_xField = lcl_InsertParagraphSignature(m_rDoc.GetDocShell()->GetBaseModel(), m_xParent, m_signature, m_usage); - lcl_DoUpdateParagraphSignatureField(m_rDoc, m_xField, m_display); + if (SwDocShell* pShell = m_rDoc.GetDocShell()) + { + m_xField = lcl_InsertParagraphSignature(pShell->GetBaseModel(), m_xParent, m_signature, m_usage); + lcl_DoUpdateParagraphSignatureField(m_rDoc, m_xField, m_display); + } } void SwUndoParagraphSigning::Remove() diff --git a/sw/source/core/edit/edlingu.cxx b/sw/source/core/edit/edlingu.cxx index 4cd4227296bc..d2d3a3d4b842 100644 --- a/sw/source/core/edit/edlingu.cxx +++ b/sw/source/core/edit/edlingu.cxx @@ -979,7 +979,10 @@ bool SwEditShell::GetGrammarCorrection( uno::Reference< linguistic2::XProofreadingIterator > xGCIterator( mxDoc->GetGCIterator() ); if (xGCIterator.is()) { - rtl::Reference< SwXTextDocument > xDoc = mxDoc->GetDocShell()->GetBaseModel(); + SwDocShell* pShell = mxDoc->GetDocShell(); + if (!pShell) + return bRes; + rtl::Reference< SwXTextDocument > xDoc = pShell->GetBaseModel(); // Expand the string: const ModelToViewHelper aConversionMap(*pNode, GetLayout()); diff --git a/sw/source/core/edit/edundo.cxx b/sw/source/core/edit/edundo.cxx index 9fa5342f08d7..34e295427fd6 100644 --- a/sw/source/core/edit/edundo.cxx +++ b/sw/source/core/edit/edundo.cxx @@ -43,7 +43,10 @@ static void lcl_SelectSdrMarkList( SwEditShell* pShell, bool SwEditShell::CursorsLocked() const { - return GetDoc()->GetDocShell()->GetModel()->hasControllersLocked(); + SwDocShell* pShell = GetDoc()->GetDocShell(); + if (!pShell) + return false; + return pShell->GetModel()->hasControllersLocked(); } void SwEditShell::HandleUndoRedoContext(::sw::UndoRedoContext & rContext) diff --git a/sw/source/core/fields/authfld.cxx b/sw/source/core/fields/authfld.cxx index a8da2323f7d4..0a3de0e91bb5 100644 --- a/sw/source/core/fields/authfld.cxx +++ b/sw/source/core/fields/authfld.cxx @@ -651,6 +651,8 @@ OUString SwAuthorityField::GetAbsoluteURL() const ? AUTH_FIELD_URL : AUTH_FIELD_TARGET_URL); SwDoc* pDoc = static_cast<SwAuthorityFieldType*>(GetTyp())->GetDoc(); SwDocShell* pDocShell = pDoc->GetDocShell(); + if (!pDocShell) + return OUString(); OUString aBasePath = pDocShell->getDocumentBaseURL(); return INetURLObject::GetAbsURL(aBasePath, rURL, INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism::WithCharset); @@ -662,6 +664,8 @@ OUString SwAuthorityField::GetRelativeURI() const SwDoc* pDoc = static_cast<SwAuthorityFieldType*>(GetTyp())->GetDoc(); SwDocShell* pDocShell = pDoc->GetDocShell(); + if (!pDocShell) + return OUString(); const OUString aBaseURL = pDocShell->getDocumentBaseURL(); std::u16string_view aBaseURIScheme; sal_Int32 nSep = aBaseURL.indexOf(':'); diff --git a/sw/source/core/fields/textapi.cxx b/sw/source/core/fields/textapi.cxx index ccbf299b1e7d..187785a0b340 100644 --- a/sw/source/core/fields/textapi.cxx +++ b/sw/source/core/fields/textapi.cxx @@ -125,9 +125,12 @@ void SwTextAPIEditSource::UpdateData() SwTextAPIEditSource::SwTextAPIEditSource(SwDoc* pDoc) : m_pImpl(new SwTextAPIEditSource_Impl) { - m_pImpl->mpPool = &pDoc->GetDocShell()->GetPool(); - m_pImpl->mpDoc = pDoc; - m_pImpl->mnRef = 1; + if (SwDocShell* pShell = pDoc->GetDocShell()) + { + m_pImpl->mpPool = &pShell->GetPool(); + m_pImpl->mpDoc = pDoc; + m_pImpl->mnRef = 1; + } } SwTextAPIEditSource::~SwTextAPIEditSource() @@ -148,12 +151,15 @@ void SwTextAPIEditSource::EnsureOutliner() { if( !m_pImpl->mpOutliner ) { - //init draw model first - m_pImpl->mpDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel(); - m_pImpl->mpOutliner.reset(new Outliner(m_pImpl->mpPool, OutlinerMode::TextObject)); - m_pImpl->mpOutliner->SetStyleSheetPool( - static_cast<SwDocStyleSheetPool*>(m_pImpl->mpDoc->GetDocShell()->GetStyleSheetPool())->GetEEStyleSheetPool()); - m_pImpl->mpDoc->SetCalcFieldValueHdl(m_pImpl->mpOutliner.get()); + if (SwDocShell* pShell = m_pImpl->mpDoc->GetDocShell()) + { + //init draw model first + m_pImpl->mpDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel(); + m_pImpl->mpOutliner.reset(new Outliner(m_pImpl->mpPool, OutlinerMode::TextObject)); + m_pImpl->mpOutliner->SetStyleSheetPool( + static_cast<SwDocStyleSheetPool*>(pShell->GetStyleSheetPool())->GetEEStyleSheetPool()); + m_pImpl->mpDoc->SetCalcFieldValueHdl(m_pImpl->mpOutliner.get()); + } } } diff --git a/sw/source/core/frmedt/feflyole.cxx b/sw/source/core/frmedt/feflyole.cxx index 0178c48239f6..59d5595725d8 100644 --- a/sw/source/core/frmedt/feflyole.cxx +++ b/sw/source/core/frmedt/feflyole.cxx @@ -101,21 +101,24 @@ bool SwFEShell::FinishOLEObj() // Server is terminated IsCheckForOLEInCaption() ) SetCheckForOLEInCaption( !IsCheckForOLEInCaption() ); - // enable update of the link preview - comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = GetDoc()->GetDocShell()->getEmbeddedObjectContainer(); - const bool aUserAllowsLinkUpdate = rEmbeddedObjectContainer.getUserAllowsLinkUpdate(); - rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true); + if (const SwDocShell* pShell = GetDoc()->GetDocShell()) + { + // enable update of the link preview + comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = pShell->getEmbeddedObjectContainer(); + const bool aUserAllowsLinkUpdate = rEmbeddedObjectContainer.getUserAllowsLinkUpdate(); + rEmbeddedObjectContainer.setUserAllowsLinkUpdate(true); - // leave UIActive state - pIPClient->DeactivateObject(); + // leave UIActive state + pIPClient->DeactivateObject(); - // if we have more than one link let's update them too - sfx2::LinkManager& rLinkManager = GetDoc()->getIDocumentLinksAdministration().GetLinkManager(); - if (rLinkManager.GetLinks().size() > 1) - rLinkManager.UpdateAllLinks(false, false, nullptr, u""_ustr); + // if we have more than one link let's update them too + sfx2::LinkManager& rLinkManager = GetDoc()->getIDocumentLinksAdministration().GetLinkManager(); + if (rLinkManager.GetLinks().size() > 1) + rLinkManager.UpdateAllLinks(false, false, nullptr, u""_ustr); - // return back original value of the "update of the link preview" flag - rEmbeddedObjectContainer.setUserAllowsLinkUpdate(aUserAllowsLinkUpdate); + // return back original value of the "update of the link preview" flag + rEmbeddedObjectContainer.setUserAllowsLinkUpdate(aUserAllowsLinkUpdate); + } } return bRet; } diff --git a/sw/source/core/layout/atrfrm.cxx b/sw/source/core/layout/atrfrm.cxx index ec9f7633a141..7a68cda9d3b2 100644 --- a/sw/source/core/layout/atrfrm.cxx +++ b/sw/source/core/layout/atrfrm.cxx @@ -2933,8 +2933,15 @@ SdrObject* SwFrameFormat::FindRealSdrObject() if( pFly ) return pFly->GetVirtDrawObj(); - if( !GetDoc() || !GetDoc()->GetDocShell() || - GetDoc()->GetDocShell()->GetCreateMode() != SfxObjectCreateMode::EMBEDDED ) + SwDoc* pDoc = GetDoc(); + if (!pDoc) + return nullptr; + + SwDocShell* pShell = pDoc->GetDocShell(); + if (!pShell) + return nullptr; + + if (pShell->GetCreateMode() != SfxObjectCreateMode::EMBEDDED ) return nullptr; // tdf#126477 fix lost charts in embedded documents diff --git a/sw/source/core/layout/layact.cxx b/sw/source/core/layout/layact.cxx index 8c6c55478472..b03fd1fe2380 100644 --- a/sw/source/core/layout/layact.cxx +++ b/sw/source/core/layout/layact.cxx @@ -2215,7 +2215,11 @@ bool SwLayIdle::isJobEnabled(IdleJobType eJob, const SwViewShell* pViewShell) case IdleJobType::SMART_TAGS: { const SwDoc* pDoc = pViewShell->GetDoc(); - if (pDoc->GetDocShell()->IsHelpDocument() || pDoc->isXForms() || !SwSmartTagMgr::Get().IsSmartTagsEnabled()) + const SwDocShell* pShell = pDoc->GetDocShell(); + if (!pShell) + return false; + + if (pShell->IsHelpDocument() || pDoc->isXForms() || !SwSmartTagMgr::Get().IsSmartTagsEnabled()) return false; return true; } diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx index 9c3fcf77eec8..fb2f6d750b9f 100644 --- a/sw/source/core/layout/paintfrm.cxx +++ b/sw/source/core/layout/paintfrm.cxx @@ -3518,8 +3518,8 @@ void SwRootFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect const& pPage->PaintSwFrame( rRenderContext, aPaintRect, isPaintHellOverHF ? PAINT_NON_HEADER_FOOTER : PAINT_ALL); // no paint of page border and shadow, if writer is in place mode. - if( pSh->GetWin() && pSh->GetDoc()->GetDocShell() && - !pSh->GetDoc()->GetDocShell()->IsInPlaceActive() ) + SwDocShell* pShell = pSh->GetDoc()->GetDocShell(); + if( pSh->GetWin() && pShell && !pShell->IsInPlaceActive() ) { SwPageFrame::PaintBorderAndShadow( pPage->getFrameArea(), pSh, bPaintLeftShadow, bPaintRightShadow, bRightSidebar ); SwPageFrame::PaintNotesSidebar( pPage->getFrameArea(), pSh, pPage->GetPhyPageNum(), bRightSidebar); diff --git a/sw/source/core/layout/wsfrm.cxx b/sw/source/core/layout/wsfrm.cxx index 8d6607bf962d..0e2c5e9e38d3 100644 --- a/sw/source/core/layout/wsfrm.cxx +++ b/sw/source/core/layout/wsfrm.cxx @@ -2220,9 +2220,10 @@ SwTwips SwContentFrame::GrowFrame(SwTwips nDist, SwResizeLimitReason& reason, bo SwTabFrame *pTab = (nOld && IsInTab()) ? FindTabFrame() : nullptr; if (pTab) { + SwDocShell* pShell = pTab->GetFormat()->GetDoc()->GetDocShell(); if ( pTab->GetTable()->GetHTMLTableLayout() && !pTab->IsJoinLocked() && - !pTab->GetFormat()->GetDoc()->GetDocShell()->IsReadOnly() ) + pShell && !pShell->IsReadOnly() ) { pTab->InvalidatePos(); pTab->SetResizeHTMLTable(); @@ -2319,9 +2320,10 @@ SwTwips SwContentFrame::ShrinkFrame( SwTwips nDist, bool bTst, bool bInfo ) SwTabFrame *pTab = IsInTab() ? FindTabFrame() : nullptr; if (pTab) { + SwDocShell* pShell = pTab->GetFormat()->GetDoc()->GetDocShell(); if ( pTab->GetTable()->GetHTMLTableLayout() && !pTab->IsJoinLocked() && - !pTab->GetFormat()->GetDoc()->GetDocShell()->IsReadOnly() ) + pShell && !pShell->IsReadOnly() ) { pTab->InvalidatePos(); pTab->SetResizeHTMLTable(); diff --git a/sw/source/core/swg/SwXMLTextBlocks1.cxx b/sw/source/core/swg/SwXMLTextBlocks1.cxx index f5964fe0938d..9673e0cecc22 100644 --- a/sw/source/core/swg/SwXMLTextBlocks1.cxx +++ b/sw/source/core/swg/SwXMLTextBlocks1.cxx @@ -76,16 +76,19 @@ ErrCode SwXMLTextBlocks::GetDoc( sal_uInt16 nIdx ) OUString sObjReplacements( u"ObjectReplacements"_ustr ); if ( m_xRoot->hasByName( sObjReplacements ) ) { - uno::Reference< document::XStorageBasedDocument > xDocStor( m_xDoc->GetDocShell()->GetModel(), uno::UNO_QUERY ); - if (xDocStor) + if (SwDocShell* pShell = m_xDoc->GetDocShell()) { - uno::Reference< embed::XStorage > xStr( xDocStor->getDocumentStorage() ); - if ( xStr.is() ) + uno::Reference< document::XStorageBasedDocument > xDocStor( pShell->GetModel(), uno::UNO_QUERY ); + if (xDocStor) { - m_xRoot->copyElementTo( sObjReplacements, xStr, sObjReplacements ); - uno::Reference< embed::XTransactedObject > xTrans( xStr, uno::UNO_QUERY ); - if ( xTrans.is() ) - xTrans->commit(); + uno::Reference< embed::XStorage > xStr( xDocStor->getDocumentStorage() ); + if ( xStr.is() ) + { + m_xRoot->copyElementTo( sObjReplacements, xStr, sObjReplacements ); + uno::Reference< embed::XTransactedObject > xTrans( xStr, uno::UNO_QUERY ); + if ( xTrans.is() ) + xTrans->commit(); + } } } } @@ -495,9 +498,12 @@ ErrCode SwXMLTextBlocks::SetMacroTable( const uno::Reference< uno::XComponentContext >& xContext = comphelper::getProcessComponentContext(); + SwDocShell* pShell = m_xDoc->GetDocShell(); + if (!pShell) + return ERR_SWG_WRITE_ERROR; + // Get model - uno::Reference< lang::XComponent > xModelComp = - m_xDoc->GetDocShell()->GetModel(); + uno::Reference< lang::XComponent > xModelComp = pShell->GetModel(); OSL_ENSURE( xModelComp.is(), "XMLWriter::Write: got no model" ); if( !xModelComp.is() ) return ERR_SWG_WRITE_ERROR; diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx index 752aadb5ffb8..42fce3f0bb67 100644 --- a/sw/source/core/text/itrform2.cxx +++ b/sw/source/core/text/itrform2.cxx @@ -1267,29 +1267,31 @@ SwTextPortion *SwTextFormatter::WhichTextPor( SwTextFormatInfo &rInf ) const static uno::Reference< rdf::XURI > xODF_SHADING( rdf::URI::createKnown(xContext, rdf::URIs::LO_EXT_SHADING), uno::UNO_SET_THROW); - rtl::Reference<SwXTextDocument> xDocumentMetadataAccess( - rDoc.GetDocShell()->GetBaseModel()); + if (const SwDocShell* pShell = rDoc.GetDocShell()) + { + rtl::Reference<SwXTextDocument> xDocumentMetadataAccess(pShell->GetBaseModel()); - const css::uno::Reference<css::rdf::XResource> xSubject(xRet, uno::UNO_QUERY); - const uno::Reference<rdf::XRepository>& xRepository = - xDocumentMetadataAccess->getRDFRepository(); - const uno::Reference<container::XEnumeration> xEnum( - xRepository->getStatements(xSubject, xODF_SHADING, nullptr), uno::UNO_SET_THROW); + const css::uno::Reference<css::rdf::XResource> xSubject(xRet, uno::UNO_QUERY); + const uno::Reference<rdf::XRepository>& xRepository = + xDocumentMetadataAccess->getRDFRepository(); + const uno::Reference<container::XEnumeration> xEnum( + xRepository->getStatements(xSubject, xODF_SHADING, nullptr), uno::UNO_SET_THROW); - while (xEnum->hasMoreElements()) - { - rdf::Statement stmt; - if (!(xEnum->nextElement() >>= stmt)) { - throw uno::RuntimeException(); - } - const uno::Reference<rdf::XLiteral> xObject(stmt.Object, uno::UNO_QUERY); - if (!xObject.is()) continue; - if (xEnum->hasMoreElements()) { - SAL_INFO("sw.uno", "ignoring other odf:shading statements"); + while (xEnum->hasMoreElements()) + { + rdf::Statement stmt; + if (!(xEnum->nextElement() >>= stmt)) { + throw uno::RuntimeException(); + } + const uno::Reference<rdf::XLiteral> xObject(stmt.Object, uno::UNO_QUERY); + if (!xObject.is()) continue; + if (xEnum->hasMoreElements()) { + SAL_INFO("sw.uno", "ignoring other odf:shading statements"); + } + Color rColor = Color::STRtoRGB(xObject->getValue()); + pMetaPor->SetShadowColor(rColor); + break; } - Color rColor = Color::STRtoRGB(xObject->getValue()); - pMetaPor->SetShadowColor(rColor); - break; } } pPor = pMetaPor; diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx index e8096fe85b57..cc2dbd379d13 100644 --- a/sw/source/core/text/porlay.cxx +++ b/sw/source/core/text/porlay.cxx @@ -881,25 +881,28 @@ static Color getBookmarkColor(const SwTextNode& rNode, const sw::mark::Bookmark* const rtl::Reference< SwXBookmark > xRef = SwXBookmark::CreateXBookmark(rDoc, const_cast<sw::mark::MarkBase*>(static_cast<const sw::mark::MarkBase*>(pBookmark))); const css::uno::Reference<css::rdf::XResource> xSubject(xRef); - rtl::Reference<SwXTextDocument> xModel = rDoc.GetDocShell()->GetBaseModel(); + if (const SwDocShell* pShell = rDoc.GetDocShell()) + { + rtl::Reference<SwXTextDocument> xModel = pShell->GetBaseModel(); - static uno::Reference< uno::XComponentContext > xContext( - ::comphelper::getProcessComponentContext()); + static uno::Reference< uno::XComponentContext > xContext( + ::comphelper::getProcessComponentContext()); - static uno::Reference< rdf::XURI > xODF_SHADING( - rdf::URI::createKnown(xContext, rdf::URIs::LO_EXT_SHADING), uno::UNO_SET_THROW); + static uno::Reference< rdf::XURI > xODF_SHADING( + rdf::URI::createKnown(xContext, rdf::URIs::LO_EXT_SHADING), uno::UNO_SET_THROW); - const uno::Reference<rdf::XRepository>& xRepository = - xModel->getRDFRepository(); - const uno::Reference<container::XEnumeration> xEnum( - xRepository->getStatements(xSubject, xODF_SHADING, nullptr), uno::UNO_SET_THROW); + const uno::Reference<rdf::XRepository>& xRepository = + xModel->getRDFRepository(); + const uno::Reference<container::XEnumeration> xEnum( + xRepository->getStatements(xSubject, xODF_SHADING, nullptr), uno::UNO_SET_THROW); - rdf::Statement stmt; - if ( xEnum->hasMoreElements() && (xEnum->nextElement() >>= stmt) ) - { - const uno::Reference<rdf::XLiteral> xObject(stmt.Object, uno::UNO_QUERY); - if ( xObject.is() ) - c = Color::STRtoRGB(xObject->getValue()); + rdf::Statement stmt; + if ( xEnum->hasMoreElements() && (xEnum->nextElement() >>= stmt) ) + { + const uno::Reference<rdf::XLiteral> xObject(stmt.Object, uno::UNO_QUERY); + if ( xObject.is() ) + c = Color::STRtoRGB(xObject->getValue()); + } } } catch (const lang::IllegalArgumentException&) @@ -920,27 +923,30 @@ static OUString getBookmarkType(const SwTextNode& rNode, const sw::mark::Bookmar const rtl::Reference< SwXBookmark > xRef = SwXBookmark::CreateXBookmark(rDoc, const_cast<sw::mark::MarkBase*>(static_cast<const sw::mark::MarkBase*>(pBookmark))); const css::uno::Reference<css::rdf::XResource> xSubject(xRef); - rtl::Reference<SwXTextDocument> xModel = rDoc.GetDocShell()->GetBaseModel(); + if (const SwDocShell* pShell = rDoc.GetDocShell()) + { + rtl::Reference<SwXTextDocument> xModel = pShell->GetBaseModel(); - static uno::Reference< uno::XComponentContext > xContext( - ::comphelper::getProcessComponentContext()); + static uno::Reference< uno::XComponentContext > xContext( + ::comphelper::getProcessComponentContext()); - static uno::Reference< rdf::XURI > xODF_PREFIX( - rdf::URI::createKnown(xContext, rdf::URIs::RDF_TYPE), uno::UNO_SET_THROW); + static uno::Reference< rdf::XURI > xODF_PREFIX( + rdf::URI::createKnown(xContext, rdf::URIs::RDF_TYPE), uno::UNO_SET_THROW); - uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess( - rDoc.GetDocShell()->GetBaseModel()); - const uno::Reference<rdf::XRepository>& xRepository = - xDocumentMetadataAccess->getRDFRepository(); - const uno::Reference<container::XEnumeration> xEnum( - xRepository->getStatements(xSubject, xODF_PREFIX, nullptr), uno::UNO_SET_THROW); + uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess( + pShell->GetBaseModel()); + const uno::Reference<rdf::XRepository>& xRepository = + xDocumentMetadataAccess->getRDFRepository(); + const uno::Reference<container::XEnumeration> xEnum( + xRepository->getStatements(xSubject, xODF_PREFIX, nullptr), uno::UNO_SET_THROW); - rdf::Statement stmt; - if ( xEnum->hasMoreElements() && (xEnum->nextElement() >>= stmt) ) - { - const uno::Reference<rdf::XLiteral> xObject(stmt.Object, uno::UNO_QUERY); - if ( xObject.is() ) - sRet = xObject->getValue(); + rdf::Statement stmt; + if ( xEnum->hasMoreElements() && (xEnum->nextElement() >>= stmt) ) + { + const uno::Reference<rdf::XLiteral> xObject(stmt.Object, uno::UNO_QUERY); + if ( xObject.is() ) + sRet = xObject->getValue(); + } } } catch (const lang::IllegalArgumentException&) diff --git a/sw/source/core/tox/txmsrt.cxx b/sw/source/core/tox/txmsrt.cxx index c2bc4ab4cd05..5d4302dd8c11 100644 --- a/sw/source/core/tox/txmsrt.cxx +++ b/sw/source/core/tox/txmsrt.cxx @@ -883,32 +883,34 @@ void SwTOXAuthority::FillText(SwTextNode& rNd, const SwContentIndex& rInsPos, sa // Convert URL to a relative one if requested. SwDoc* pDoc = static_cast<SwAuthorityFieldType*>(m_rField.GetField()->GetTyp())->GetDoc(); - SwDocShell* pDocShell = pDoc->GetDocShell(); - const OUString aBaseURL = pDocShell->getDocumentBaseURL(); - std::u16string_view aBaseURIScheme; - sal_Int32 nSep = aBaseURL.indexOf(':'); - if (nSep != -1) + if (SwDocShell* pDocShell = pDoc->GetDocShell()) { - aBaseURIScheme = aBaseURL.subView(0, nSep); - } + std::u16string_view aBaseURIScheme; + const OUString aBaseURL = pDocShell->getDocumentBaseURL(); + sal_Int32 nSep = aBaseURL.indexOf(':'); + if (nSep != -1) + { + aBaseURIScheme = aBaseURL.subView(0, nSep); + } - uno::Reference<uri::XUriReferenceFactory> xUriReferenceFactory - = uri::UriReferenceFactory::create(comphelper::getProcessComponentContext()); - uno::Reference<uri::XUriReference> xUriRef; - try - { - xUriRef = xUriReferenceFactory->parse(aText); - } - catch (const uno::Exception& rException) - { - SAL_WARN("sw.core", - "SwTOXAuthority::FillText: failed to parse url: " << rException.Message); - } + uno::Reference<uri::XUriReferenceFactory> xUriReferenceFactory + = uri::UriReferenceFactory::create(comphelper::getProcessComponentContext()); + uno::Reference<uri::XUriReference> xUriRef; + try + { + xUriRef = xUriReferenceFactory->parse(aText); + } + catch (const uno::Exception& rException) + { + SAL_WARN("sw.core", + "SwTOXAuthority::FillText: failed to parse url: " << rException.Message); + } - bool bSaveRelFSys = officecfg::Office::Common::Save::URL::FileSystem::get(); - if (xUriRef.is() && bSaveRelFSys && xUriRef->getScheme() == aBaseURIScheme) - { - aText = INetURLObject::GetRelURL(aBaseURL, aText); + bool bSaveRelFSys = officecfg::Office::Common::Save::URL::FileSystem::get(); + if (xUriRef.is() && bSaveRelFSys && xUriRef->getScheme() == aBaseURIScheme) + { + aText = INetURLObject::GetRelURL(aBaseURL, aText); + } } } diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index a0a8c8c2ed98..a0ee0b29ae8b 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -2677,9 +2677,10 @@ void SwTextNode::CutImpl( SwTextNode * const pDest, const SwContentIndex & rDest || pHt->HasDummyChar() ) { // do not delete note and later add it -> sidebar flickering - if (GetDoc().GetDocShell()) + SwDocShell* pShell = GetDoc().GetDocShell(); + if (pShell) { - GetDoc().GetDocShell()->Broadcast( SfxHint(SfxHintId::SwSplitNodeOperation)); + pShell->Broadcast( SfxHint(SfxHintId::SwSplitNodeOperation)); } // move attribute m_pSwpHints->Delete( pHt ); @@ -2699,9 +2700,9 @@ void SwTextNode::CutImpl( SwTextNode * const pDest, const SwContentIndex & rDest pDest->InsertHint( pHt, SetAttrMode::NOTXTATRCHR | SetAttrMode::DONTREPLACE ); - if (GetDoc().GetDocShell()) + if (pShell) { - GetDoc().GetDocShell()->Broadcast( SfxHint(SfxHintId::SwSplitNodeOperation)); + pShell->Broadcast( SfxHint(SfxHintId::SwSplitNodeOperation)); } continue; // iterate while loop, no ++ ! } @@ -4456,7 +4457,8 @@ void SwTextNode::AddToList() // "default" list: visible items in Show Changes mode (tracked insertions and deletions) // "hidden" list: visible items in Hide Changes mode (tracked insertions, but not deletions) // "orig" list: visible items rejecting all changes (no tracked insertions and deletions) - bool bRecordChanges = GetDoc().GetDocShell() && GetDoc().GetDocShell()->IsChangeRecording(); + SwDocShell* pShell = GetDoc().GetDocShell(); + bool bRecordChanges = pShell && pShell->IsChangeRecording(); if (!bRecordChanges || GetDoc().IsInXMLImport() || GetDoc().IsInWriterfilterImport() ) { const SwRedlineTable& rRedTable = GetDoc().getIDocumentRedlineAccess().GetRedlineTable(); diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx index 9387752df234..54c8416771b6 100644 --- a/sw/source/core/unocore/unocoll.cxx +++ b/sw/source/core/unocore/unocoll.cxx @@ -593,12 +593,15 @@ SwXServiceProvider::MakeInstance(SwServiceType nObjectType, SwDoc & rDoc) #if HAVE_FEATURE_SCRIPTING { uno::Any aGlobs; - BasicManager *pBasicMan = rDoc.GetDocShell()->GetBasicManager(); - if (pBasicMan && !pBasicMan->GetGlobalUNOConstant(u"VBAGlobals"_ustr, aGlobs)) + if (SwDocShell* pShell = rDoc.GetDocShell()) { - uno::Sequence< uno::Any > aArgs{ uno::Any(rDoc.GetDocShell()->GetModel()) }; - aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( u"ooo.vba.word.Globals"_ustr, aArgs ); - pBasicMan->SetGlobalUNOConstant( u"VBAGlobals"_ustr, aGlobs ); + BasicManager *pBasicMan = pShell->GetBasicManager(); + if (pBasicMan && !pBasicMan->GetGlobalUNOConstant(u"VBAGlobals"_ustr, aGlobs)) + { + uno::Sequence< uno::Any > aArgs{ uno::Any(pShell->GetModel()) }; + aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( u"ooo.vba.word.Globals"_ustr, aArgs ); + pBasicMan->SetGlobalUNOConstant( u"VBAGlobals"_ustr, aGlobs ); + } } aGlobs >>= xRet; } @@ -812,16 +815,18 @@ SwXServiceProvider::MakeInstance(SwServiceType nObjectType, SwDoc & rDoc) xRet = SvUnoImageMapPolygonObject_createInstance( sw_GetSupportedMacroItems() ); break; case SwServiceType::Chart2DataProvider: + { // #i64497# If a chart is in a temporary document during clipboard // paste, there should be no data provider, so that own data is used // This should not happen during copy/paste, as this will unlink // charts using table data. - if (rDoc.GetDocShell()->GetCreateMode() != SfxObjectCreateMode::EMBEDDED) + SwDocShell* pShell = rDoc.GetDocShell(); + if (pShell && pShell->GetCreateMode() != SfxObjectCreateMode::EMBEDDED) xRet = getXWeak(rDoc.getIDocumentChartDataProviderAccess().GetChartDataProvider( true /* create - if not yet available */ )); else SAL_WARN("sw.uno", "not creating chart data provider for embedded object"); - + } break; case SwServiceType::TypeMeta: xRet = getXWeak(SwXMeta::CreateXMeta(rDoc, false).get()); diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx index 6564d9b5aaff..7a019bf98bd3 100644 --- a/sw/source/core/unocore/unocrsrhelper.cxx +++ b/sw/source/core/unocore/unocrsrhelper.cxx @@ -866,13 +866,16 @@ void setNumberingProperty(const Any& rValue, SwPaM& rPam) if(!pCharFormat) { - SfxStyleSheetBasePool* pPool = rDoc.GetDocShell()->GetStyleSheetPool(); - SfxStyleSheetBase* pBase; - pBase = pPool->Find(pNewCharStyles[i], SfxStyleFamily::Char); - // shall it really be created? - if(!pBase) - pBase = &pPool->Make(pNewCharStyles[i], SfxStyleFamily::Page); - pCharFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat(); + if (SwDocShell* pShell = rDoc.GetDocShell()) + { + SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool(); + SfxStyleSheetBase* pBase; + pBase = pPool->Find(pNewCharStyles[i], SfxStyleFamily::Char); + // shall it really be created? + if(!pBase) + pBase = &pPool->Make(pNewCharStyles[i], SfxStyleFamily::Page); + pCharFormat = static_cast<SwDocStyleSheet*>(pBase)->GetCharFormat(); + } } if(pCharFormat) aFormat.SetCharFormat(pCharFormat); @@ -885,14 +888,17 @@ void setNumberingProperty(const Any& rValue, SwPaM& rPam) (!aFormat.GetBulletFont() || aFormat.GetBulletFont()->GetFamilyName() != pBulletFontNames[i]) ) { - const SvxFontListItem* pFontListItem = - static_cast<const SvxFontListItem* >(rDoc.GetDocShell() - ->GetItem( SID_ATTR_CHAR_FONTLIST )); - const FontList* pList = pFontListItem->GetFontList(); - - vcl::Font aFont(pList->Get( - pBulletFontNames[i],WEIGHT_NORMAL, ITALIC_NONE)); - aFormat.SetBulletFont(&aFont); + if (SwDocShell* pShell = rDoc.GetDocShell()) + { + const SvxFontListItem* pFontListItem = + static_cast<const SvxFontListItem* >( + pShell->GetItem( SID_ATTR_CHAR_FONTLIST )); + const FontList* pList = pFontListItem->GetFontList(); + + vcl::Font aFont(pList->Get( + pBulletFontNames[i],WEIGHT_NORMAL, ITALIC_NONE)); + aFormat.SetBulletFont(&aFont); + } } aRule.Set( i, aFormat ); } @@ -1038,7 +1044,6 @@ void InsertFile(SwUnoCursor* pUnoCursor, const OUString& rURL, std::unique_ptr<SfxMedium> pMed; SwDoc& rDoc = pUnoCursor->GetDoc(); - SwDocShell* pDocSh = rDoc.GetDocShell(); utl::MediaDescriptor aMediaDescriptor( rOptions ); OUString sFileName = rURL; OUString sFilterName, sFilterOptions, sPassword, sBaseURL; @@ -1059,6 +1064,7 @@ void InsertFile(SwUnoCursor* pUnoCursor, const OUString& rURL, if ( !xInputStream.is() && xStream.is() ) xInputStream = xStream->getInputStream(); + SwDocShell* pDocSh = rDoc.GetDocShell(); if(!pDocSh || (sFileName.isEmpty() && !xInputStream.is())) return; diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index 9cac516808e5..0d17f192d40f 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -952,8 +952,11 @@ bool SwFrameProperties_Impl::AnyToItemSet(SwDoc *pDoc, SfxItemSet& rSet, SfxItem OUString sStyle; *pStyleName >>= sStyle; SwStyleNameMapper::FillUIName(sStyle, sStyle, SwGetPoolIdFromName::FrmFmt); - pStyle = static_cast<SwDocStyleSheet*>(pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, - SfxStyleFamily::Frame)); + if (SwDocShell* pShell = pDoc->GetDocShell()) + { + pStyle = static_cast<SwDocStyleSheet*>(pShell->GetStyleSheetPool()->Find(sStyle, + SfxStyleFamily::Frame)); + } } if ( pStyle ) @@ -1031,8 +1034,11 @@ bool SwGraphicProperties_Impl::AnyToItemSet( OUString sStyle; *pStyleName >>= sStyle; SwStyleNameMapper::FillUIName(sStyle, sStyle, SwGetPoolIdFromName::FrmFmt); - pStyle = static_cast<SwDocStyleSheet*>(pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, - SfxStyleFamily::Frame)); + if (SwDocShell* pShell = pDoc->GetDocShell()) + { + pStyle = static_cast<SwDocStyleSheet*>(pShell->GetStyleSheetPool()->Find(sStyle, + SfxStyleFamily::Frame)); + } } if ( pStyle ) @@ -1127,11 +1133,15 @@ SwXFrame::SwXFrame(FlyCntType eSet, const ::SfxItemPropertySet* pSet, SwDoc *pDo , m_nVisibleAreaWidth(0) , m_nVisibleAreaHeight(0) { + SwDocShell* pShell = pDoc->GetDocShell(); + if (!pShell) + return; + // Register ourselves as a listener to the document (via the page descriptor) StartListening(pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier()); // get the property set for the default style data // First get the model - rtl::Reference < SwXTextDocument > xModel = pDoc->GetDocShell()->GetBaseModel(); + rtl::Reference < SwXTextDocument > xModel = pShell->GetBaseModel(); // Get the style families uno::Reference < XNameAccess > xFamilies = xModel->getStyleFamilies(); // Get the Frame family (and keep it for later) @@ -2162,9 +2172,10 @@ uno::Any SwXFrame::getPropertyValue(const OUString& rPropertyName) if ( FN_EMBEDDED_OBJECT == pEntry->nWID ) { // when exposing the EmbeddedObject, ensure it has a client site - OSL_ENSURE( pDoc->GetDocShell(), "no doc shell => no client site" ); - if ( pDoc->GetDocShell() ) - pDoc->GetDocShell()->GetIPClient( svt::EmbeddedObjectRef( xIP, embed::Aspects::MSOLE_CONTENT ) ); + SwDocShell* pShell = pDoc->GetDocShell(); + OSL_ENSURE( pShell, "no doc shell => no client site" ); + if ( pShell ) + pShell->GetIPClient( svt::EmbeddedObjectRef( xIP, embed::Aspects::MSOLE_CONTENT ) ); aAny <<= xIP; } else if ( xModel.is() ) @@ -2902,8 +2913,9 @@ void SwXFrame::attachToRange(uno::Reference<text::XTextRange> const& xTextRange, // set parent to get correct VisArea(in case of object needing parent printer) uno::Reference < container::XChild > xChild( xIPObj, uno::UNO_QUERY ); - if ( xChild.is() ) - xChild->setParent( pDoc->GetDocShell()->GetModel() ); + SwDocShell* pShell = pDoc->GetDocShell(); + if ( xChild.is() && pShell ) + xChild->setParent( pShell->GetModel() ); //The Size should be suggested by the OLE server if not manually set MapUnit aRefMap = VCLUnoHelper::UnoEmbed2VCLMapUnit( xIPObj->getMapUnit( nAspect ) ); @@ -2938,9 +2950,12 @@ void SwXFrame::attachToRange(uno::Reference<text::XTextRange> const& xTextRange, aPam, xObjRef, &aFrameSet ); // store main document name to show in the title bar - uno::Reference< frame::XTitle > xModelTitle( pDoc->GetDocShell()->GetModel(), css::uno::UNO_QUERY ); - if( xModelTitle.is() ) - xIPObj->setContainerName( xModelTitle->getTitle() ); + if (SwDocShell* pShell = pDoc->GetDocShell()) + { + uno::Reference< frame::XTitle > xModelTitle( pShell->GetModel(), css::uno::UNO_QUERY ); + if( xModelTitle.is() ) + xIPObj->setContainerName( xModelTitle->getTitle() ); + } assert(pFormat2 && "Doc->Insert(notxt) failed."); @@ -2973,9 +2988,10 @@ void SwXFrame::attachToRange(uno::Reference<text::XTextRange> const& xTextRange, if( pNd ) { uno::Reference < embed::XEmbeddedObject > xObj = pNd->GetOLEObj().GetOleRef(); - if( xObj.is() ) + SwDocShell* pShell = pDoc->GetDocShell(); + if( xObj.is() && pShell ) { - uno::Reference< frame::XTitle > xModelTitle( pDoc->GetDocShell()->GetModel(), css::uno::UNO_QUERY ); + uno::Reference< frame::XTitle > xModelTitle( pShell->GetModel(), css::uno::UNO_QUERY ); if( xModelTitle.is() ) xObj->setContainerName( xModelTitle->getTitle() ); } @@ -3421,8 +3437,8 @@ uno::Reference< embed::XEmbeddedObject > SAL_CALL SwXTextEmbeddedObject::getExte if ( svt::EmbeddedObjectRef::TryRunningState( xResult ) ) { // TODO/LATER: the listener registered after client creation should be able to handle scaling, after that the client is not necessary here - if ( pDoc->GetDocShell() ) - pDoc->GetDocShell()->GetIPClient( svt::EmbeddedObjectRef( xResult, embed::Aspects::MSOLE_CONTENT ) ); + if (SwDocShell* pShell = pDoc->GetDocShell()) + pShell->GetIPClient( svt::EmbeddedObjectRef( xResult, embed::Aspects::MSOLE_CONTENT ) ); uno::Reference < lang::XComponent > xComp( xResult->getComponent(), uno::UNO_QUERY ); uno::Reference< util::XModifyBroadcaster > xBrdcst( xComp, uno::UNO_QUERY); diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx index 1b5b805da1f8..5237380ccfab 100644 --- a/sw/source/core/unocore/unoidx.cxx +++ b/sw/source/core/unocore/unoidx.cxx @@ -1974,10 +1974,13 @@ SwXDocumentIndexMark::getAnchor() { aPam.GetPoint()->AdjustContent(1); } - const rtl::Reference< SwXTextDocument > xModel = - m_pImpl->m_pDoc->GetDocShell()->GetBaseModel(); - const uno::Reference< text::XTextRange > xRet = - new SwXTextRange(aPam, xModel->getText()); + uno::Reference< text::XTextRange > xRet; + if(SwDocShell* pShell = m_pImpl->m_pDoc->GetDocShell()) + { + const rtl::Reference< SwXTextDocument > xModel = + pShell->GetBaseModel(); + xRet = new SwXTextRange(aPam, xModel->getText()); + } return xRet; } diff --git a/sw/source/core/unocore/unosect.cxx b/sw/source/core/unocore/unosect.cxx index 5e396c44a3ea..678efda2a7f6 100644 --- a/sw/source/core/unocore/unosect.cxx +++ b/sw/source/core/unocore/unosect.cxx @@ -680,11 +680,14 @@ void SwXTextSection::Impl::SetPropertyValues_Impl( { pSectionData->SetType(SectionType::FileLink); } - const OUString sTmp(!aLink.FileURL.isEmpty() - ? URIHelper::SmartRel2Abs( - pFormat->GetDoc()->GetDocShell()->GetMedium()->GetURLObject(), - aLink.FileURL, URIHelper::GetMaybeFileHdl()) - : OUString()); + OUString sTmp; + SwDocShell* pShell = pFormat->GetDoc()->GetDocShell(); + if (pShell && !aLink.FileURL.isEmpty()) + { + sTmp = URIHelper::SmartRel2Abs( + pShell->GetMedium()->GetURLObject(), + aLink.FileURL, URIHelper::GetMaybeFileHdl()); + } const OUString sFileName( sTmp + OUStringChar(sfx2::cTokenSeparator) + aLink.FilterName + OUStringChar(sfx2::cTokenSeparator) + diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 4b88dbfdf2e0..b99a8a2be759 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1297,7 +1297,10 @@ static uno::Reference<container::XNameAccess> lcl_InitStyleFamily(SwDoc* pDoc, c && rEntry.family() != SfxStyleFamily::Para && rEntry.family() != SfxStyleFamily::Page) return {}; - rtl::Reference<SwXTextDocument> xModel(pDoc->GetDocShell()->GetBaseModel()); + SwDocShell* pShell = pDoc->GetDocShell(); + if (!pShell) + return {}; + rtl::Reference<SwXTextDocument> xModel(pShell->GetBaseModel()); auto xFamilies = xModel->getStyleFamilies(); auto aResult(xFamilies->getByName(rEntry.name())); if(!aResult.has<return_t>()) @@ -1722,10 +1725,13 @@ void SwXStyle::SetPropertyValue<FN_UNO_NUM_RULES>(const SfxItemPropertyMapEntry& && !SwXNumberingRules::isInvalidStyle(rBulletName) && (!pFormat->GetBulletFont() || pFormat->GetBulletFont()->GetFamilyName() != rBulletName)) { - const auto pFontListItem(static_cast<const SvxFontListItem*>(m_pDoc->GetDocShell()->GetItem(SID_ATTR_CHAR_FONTLIST))); - const auto pList(pFontListItem->GetFontList()); - vcl::Font aFont(pList->Get(rBulletName, WEIGHT_NORMAL, ITALIC_NONE)); - aFormat.SetBulletFont(&aFont); + if (SwDocShell* pShell = m_pDoc->GetDocShell()) + { + const auto pFontListItem(static_cast<const SvxFontListItem*>(pShell->GetItem(SID_ATTR_CHAR_FONTLIST))); + const auto pList(pFontListItem->GetFontList()); + vcl::Font aFont(pList->Get(rBulletName, WEIGHT_NORMAL, ITALIC_NONE)); + aFormat.SetBulletFont(&aFont); + } } aSetRule.Set(i, &aFormat); } @@ -1935,7 +1941,9 @@ void SwXStyle::SetPropertyValue<sal_uInt16(RES_PARATR_DROP)>(const SfxItemProper const auto sValue(rValue.get<OUString>()); OUString sStyle; SwStyleNameMapper::FillUIName(sValue, sStyle, SwGetPoolIdFromName::ChrFmt); - auto pStyle(static_cast<SwDocStyleSheet*>(m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SfxStyleFamily::Char))); + SwDocStyleSheet* pStyle = nullptr; + if (SwDocShell* pShell = m_pDoc->GetDocShell()) + pStyle = static_cast<SwDocStyleSheet*>(pShell->GetStyleSheetPool()->Find(sStyle, SfxStyleFamily::Char)); //default character style must not be set as default format if(!pStyle || pStyle->GetCharFormat() == m_pDoc->GetDfltCharFormat() ) { diff --git a/sw/source/filter/docx/swdocxreader.cxx b/sw/source/filter/docx/swdocxreader.cxx index ca88027cba48..54f8599034bb 100644 --- a/sw/source/filter/docx/swdocxreader.cxx +++ b/sw/source/filter/docx/swdocxreader.cxx @@ -58,7 +58,11 @@ ErrCodeMsg SwDOCXReader::Read(SwDoc& rDoc, const OUString& /* rBaseURL */, SwPaM uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(comphelper::getProcessServiceFactory()); uno::Reference<uno::XInterface> xInterface(xMultiServiceFactory->createInstance(u"com.sun.star.comp.Writer.WriterFilter"_ustr), uno::UNO_SET_THROW); + ErrCode ret = ERRCODE_NONE; SwDocShell* pDocShell(rDoc.GetDocShell()); + if (!pDocShell) + return ret; + uno::Reference<lang::XComponent> xDstDoc(pDocShell->GetModel(), uno::UNO_QUERY_THROW); uno::Reference<document::XImporter> xImporter(xInterface, uno::UNO_QUERY_THROW); xImporter->setTargetDocument(xDstDoc); @@ -79,7 +83,6 @@ ErrCodeMsg SwDOCXReader::Read(SwDoc& rDoc, const OUString& /* rBaseURL */, SwPaM { "TextInsertModeRange", uno::Any(uno::Reference<text::XTextRange>(xInsertTextRange)) } })); - ErrCode ret = ERRCODE_NONE; uno::Reference<document::XFilter> xFilter(xInterface, uno::UNO_QUERY_THROW); try { diff --git a/sw/source/filter/html/htmlbas.cxx b/sw/source/filter/html/htmlbas.cxx index ba66315d7d65..1ed9c751080d 100644 --- a/sw/source/filter/html/htmlbas.cxx +++ b/sw/source/filter/html/htmlbas.cxx @@ -253,7 +253,11 @@ void SwHTMLWriter::OutBasic(const SwHTMLWriter & rHTMLWrt) if( !m_bCfgStarBasic ) return; - BasicManager *pBasicMan = m_pDoc->GetDocShell()->GetBasicManager(); + SwDocShell* pShell = m_pDoc->GetDocShell(); + if (!pShell) + return; + + BasicManager *pBasicMan = pShell->GetBasicManager(); OSL_ENSURE( pBasicMan, "Where is the Basic-Manager?" ); // Only write DocumentBasic if( !pBasicMan || pBasicMan == SfxApplication::GetBasicManager() ) diff --git a/sw/source/filter/html/htmlcss1.cxx b/sw/source/filter/html/htmlcss1.cxx index 15ada592cc0d..9a9e8ac032a9 100644 --- a/sw/source/filter/html/htmlcss1.cxx +++ b/sw/source/filter/html/htmlcss1.cxx @@ -1707,7 +1707,8 @@ bool SwHTMLParser::FileDownload( const OUString& rURL, } // was aborted? - if( ( m_xDoc->GetDocShell() && m_xDoc->GetDocShell()->IsAbortingImport() ) + SwDocShell* pShell = m_xDoc->GetDocShell(); + if( ( pShell && pShell->IsAbortingImport() ) || 1 == m_xDoc->getReferenceCount() ) { // was the import aborted from SFX? diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index cd9b0bcb0d9d..e35749be234e 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -487,21 +487,21 @@ SwHTMLParser::~SwHTMLParser() Application::RemoveUserEvent( m_nEventId ); // the DocumentDetected maybe can delete the DocShells, therefore fetch again - if( m_xDoc->GetDocShell() ) + if (SwDocShell* pShell = m_xDoc->GetDocShell()) { // update linked sections sal_uInt16 nLinkMode = m_xDoc->getIDocumentSettingAccess().getLinkUpdateMode( true ); if( nLinkMode != NEVER && bAsync && - SfxObjectCreateMode::INTERNAL!=m_xDoc->GetDocShell()->GetCreateMode() ) + SfxObjectCreateMode::INTERNAL != pShell->GetCreateMode() ) { - SfxMedium * medium = m_xDoc->GetDocShell()->GetMedium(); + SfxMedium * medium = pShell->GetMedium(); m_xDoc->getIDocumentLinksAdministration().GetLinkManager().UpdateAllLinks( nLinkMode == MANUAL, false, nullptr, medium == nullptr ? OUString() : medium->GetName() ); } - if ( m_xDoc->GetDocShell()->IsLoading() ) + if ( pShell->IsLoading() ) { // #i59688# - m_xDoc->GetDocShell()->LoadingFinished(); + pShell->LoadingFinished(); } } @@ -534,8 +534,9 @@ SwHTMLParser::~SwHTMLParser() m_pTempViewFrame->DoClose(); // the temporary view frame is hidden, so the hidden flag might need to be removed - if ( m_bRemoveHidden && m_xDoc.is() && m_xDoc->GetDocShell() && m_xDoc->GetDocShell()->GetMedium() ) - m_xDoc->GetDocShell()->GetMedium()->GetItemSet().ClearItem( SID_HIDDEN ); + SwDocShell* pShell = m_xDoc.is() ? m_xDoc->GetDocShell() : nullptr; + if ( m_bRemoveHidden && pShell && pShell->GetMedium() ) + pShell->GetMedium()->GetItemSet().ClearItem( SID_HIDDEN ); } } @@ -545,7 +546,8 @@ IMPL_LINK_NOARG( SwHTMLParser, AsyncCallback, void*, void ) // #i47907# - If the document has already been destructed, // the parser should be aware of this: - if( ( m_xDoc->GetDocShell() && m_xDoc->GetDocShell()->IsAbortingImport() ) + SwDocShell* pShell = m_xDoc->GetDocShell(); + if( ( pShell && pShell->IsAbortingImport() ) || 1 == m_xDoc->getReferenceCount() ) { // was the import aborted by SFX? @@ -635,7 +637,8 @@ void SwHTMLParser::Continue( HtmlTokenId nToken ) // we still continue, so that we clean up properly. OSL_ENSURE( SvParserState::Error!=eState, "SwHTMLParser::Continue: already set an error" ); - if( m_xDoc->GetDocShell() && m_xDoc->GetDocShell()->IsAbortingImport() ) + SwDocShell* pShell = m_xDoc->GetDocShell(); + if( pShell && pShell->IsAbortingImport() ) eState = SvParserState::Error; // Fetch SwViewShell from document, save it and set as current. @@ -659,12 +662,12 @@ void SwHTMLParser::Continue( HtmlTokenId nToken ) } m_bSetModEnabled = false; - if( m_xDoc->GetDocShell() ) + if( pShell ) { - m_bSetModEnabled = m_xDoc->GetDocShell()->IsEnableSetModified(); + m_bSetModEnabled = pShell->IsEnableSetModified(); if( m_bSetModEnabled ) { - m_xDoc->GetDocShell()->EnableSetModified( false ); + pShell->EnableSetModified( false ); } } @@ -952,9 +955,9 @@ void SwHTMLParser::Continue( HtmlTokenId nToken ) m_xDoc->SetOle2Link( aOLELink ); if( !bModified ) m_xDoc->getIDocumentState().ResetModified(); - if( m_bSetModEnabled && m_xDoc->GetDocShell() ) + if( m_bSetModEnabled && pShell ) { - m_xDoc->GetDocShell()->EnableSetModified(); + pShell->EnableSetModified(); m_bSetModEnabled = false; // this is unnecessary here } } @@ -999,7 +1002,8 @@ void SwHTMLParser::DocumentDetected() // is called for every token that is recognised in CallParser void SwHTMLParser::NextToken( HtmlTokenId nToken ) { - if( ( m_xDoc->GetDocShell() && m_xDoc->GetDocShell()->IsAbortingImport() ) + SwDocShell* pShell = m_xDoc->GetDocShell(); + if( ( pShell && pShell->IsAbortingImport() ) || 1 == m_xDoc->getReferenceCount() ) { // Was the import cancelled by SFX? If a pending stack @@ -1048,9 +1052,10 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) OUString sTitle = m_sTitle.makeStringAndClear(); if( IsNewDoc() && !sTitle.isEmpty() ) { - if( m_xDoc->GetDocShell() ) { + if (pShell) + { uno::Reference<document::XDocumentPropertiesSupplier> - xDPS(m_xDoc->GetDocShell()->GetModel(), + xDPS(pShell->GetModel(), uno::UNO_QUERY_THROW); uno::Reference<document::XDocumentProperties> xDocProps( xDPS->getDocumentProperties()); @@ -1059,7 +1064,7 @@ void SwHTMLParser::NextToken( HtmlTokenId nToken ) xDocProps->setTitle(sTitle); } - m_xDoc->GetDocShell()->SetTitle(sTitle); + pShell->SetTitle(sTitle); } } m_bInTitle = false; @@ -2591,7 +2596,8 @@ void SwHTMLParser::Show() Application::Reschedule(); - if( ( m_xDoc->GetDocShell() && m_xDoc->GetDocShell()->IsAbortingImport() ) + SwDocShell* pShell = m_xDoc->GetDocShell(); + if( ( pShell && pShell->IsAbortingImport() ) || 1 == m_xDoc->getReferenceCount() ) { // was the import aborted by SFX? @@ -2628,7 +2634,8 @@ void SwHTMLParser::ShowStatline() { Application::Reschedule(); - if( ( m_xDoc->GetDocShell() && m_xDoc->GetDocShell()->IsAbortingImport() ) + SwDocShell* pShell = m_xDoc->GetDocShell(); + if( ( pShell && pShell->IsAbortingImport() ) || 1 == m_xDoc->getReferenceCount() ) // was the import aborted by SFX? eState = SvParserState::Error; diff --git a/sw/source/filter/rtf/swparrtf.cxx b/sw/source/filter/rtf/swparrtf.cxx index 1e057ca319b1..ae7eac7c53e7 100644 --- a/sw/source/filter/rtf/swparrtf.cxx +++ b/sw/source/filter/rtf/swparrtf.cxx @@ -85,7 +85,11 @@ ErrCodeMsg SwRTFReader::Read(SwDoc& rDoc, const OUString& /*rBaseURL*/, SwPaM& r rDoc.SetTextFormatColl( rPam, rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool(RES_POOLCOLL_STANDARD, false)); + auto ret = ERRCODE_NONE; SwDocShell* pDocShell(rDoc.GetDocShell()); + if (!pDocShell) + return ret; + uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory( comphelper::getProcessServiceFactory()); uno::Reference<uno::XInterface> xInterface( @@ -106,7 +110,6 @@ ErrCodeMsg SwRTFReader::Read(SwDoc& rDoc, const OUString& /*rBaseURL*/, SwPaM& r { "InsertMode", uno::Any(true) }, { "TextInsertModeRange", uno::Any(uno::Reference<text::XTextRange>(xInsertTextRange)) } })); - auto ret = ERRCODE_NONE; try { xFilter->filter(aDescriptor); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 519cba272263..a60ae8542fe8 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -5859,7 +5859,8 @@ bool DocxAttributeOutput::ExportAsActiveXControl(const SdrObject* pObject) const if (!xControlModel.is()) return false; - uno::Reference< css::frame::XModel > xModel( m_rExport.m_rDoc.GetDocShell() ? m_rExport.m_rDoc.GetDocShell()->GetModel() : nullptr ); + SwDocShell* pShell = m_rExport.m_rDoc.GetDocShell(); + uno::Reference< css::frame::XModel > xModel( pShell ? pShell->GetModel() : nullptr ); if (!xModel.is()) return false; diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 63f53bf34dd5..fce0686af353 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -476,7 +476,8 @@ std::pair<OString, OString> DocxExport::WriteActiveXObject(const uno::Reference< { oox::ole::OleStorage aOleStorage(m_rFilter.getComponentContext(), xOutStorage, false); uno::Reference<io::XOutputStream> xOutputStream(aOleStorage.openOutputStream(u"contents"_ustr), uno::UNO_SET_THROW); - uno::Reference< css::frame::XModel > xModel( m_rDoc.GetDocShell() ? m_rDoc.GetDocShell()->GetModel() : nullptr ); + SwDocShell* pShell = m_rDoc.GetDocShell(); + uno::Reference< css::frame::XModel > xModel( pShell ? pShell->GetModel() : nullptr ); oox::ole::OleFormCtrlExportHelper exportHelper(comphelper::getProcessComponentContext(), xModel, rxControlModel); if ( !exportHelper.isValid() ) return std::make_pair<OString, OString>(OString(), OString()); @@ -1803,7 +1804,11 @@ void DocxExport::WriteCustomXml() void DocxExport::WriteVBA() { - rtl::Reference<SwXTextDocument> xStorageBasedDocument(m_rDoc.GetDocShell()->GetBaseModel()); + SwDocShell* pShell = m_rDoc.GetDocShell(); + if (!pShell) + return; + + rtl::Reference<SwXTextDocument> xStorageBasedDocument(pShell->GetBaseModel()); if (!xStorageBasedDocument.is()) return; @@ -1862,7 +1867,11 @@ void DocxExport::WriteVBA() void DocxExport::WriteEmbeddings() { - rtl::Reference< SwXTextDocument > xPropSet( m_rDoc.GetDocShell()->GetBaseModel() ); + SwDocShell* pShell = m_rDoc.GetDocShell(); + if (!pShell) + return; + + rtl::Reference< SwXTextDocument > xPropSet( pShell->GetBaseModel() ); uno::Reference< beans::XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo(); OUString aName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG; diff --git a/sw/source/filter/ww8/docxexportfilter.cxx b/sw/source/filter/ww8/docxexportfilter.cxx index ac910902935e..2a4630a0a40a 100644 --- a/sw/source/filter/ww8/docxexportfilter.cxx +++ b/sw/source/filter/ww8/docxexportfilter.cxx @@ -73,22 +73,25 @@ bool DocxExportFilter::exportDocument() // Check whether application is in headless mode if (!Application::IsHeadlessModeEnabled()) { - rtl::Reference<SwXTextDocument> xStorageBasedDocument( - pDoc->GetDocShell()->GetBaseModel()); - if (xStorageBasedDocument.is()) + if (SwDocShell* pShell = pDoc->GetDocShell()) { - uno::Reference<embed::XStorage> xDocumentStorage = - xStorageBasedDocument->getDocumentStorage(); - if (xDocumentStorage.is() && xDocumentStorage->hasByName(u"_MS_VBA_Macros"_ustr)) + rtl::Reference<SwXTextDocument> xStorageBasedDocument( + pShell->GetBaseModel()); + if (xStorageBasedDocument.is()) { - // Let user know that macros won't be saved in this format - std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( - nullptr, - VclMessageType::Warning, VclButtonsType::OkCancel, - SwResId(STR_CANT_SAVE_MACROS)) - ); - if (xBox->run() == RET_CANCEL) - return false; + uno::Reference<embed::XStorage> xDocumentStorage = + xStorageBasedDocument->getDocumentStorage(); + if (xDocumentStorage.is() && xDocumentStorage->hasByName(u"_MS_VBA_Macros"_ustr)) + { + // Let user know that macros won't be saved in this format + std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog( + nullptr, + VclMessageType::Warning, VclButtonsType::OkCancel, + SwResId(STR_CANT_SAVE_MACROS)) + ); + if (xBox->run() == RET_CANCEL) + return false; + } } } } diff --git a/sw/source/filter/ww8/docxtablestyleexport.cxx b/sw/source/filter/ww8/docxtablestyleexport.cxx index d843cdd515a2..eb9f9a2328e7 100644 --- a/sw/source/filter/ww8/docxtablestyleexport.cxx +++ b/sw/source/filter/ww8/docxtablestyleexport.cxx @@ -124,8 +124,11 @@ void DocxTableStyleExport::CnfStyle(const uno::Sequence<beans::PropertyValue>& r void DocxTableStyleExport::TableStyles(sal_Int32 nCountStylesToWrite) { + SwDocShell* pShell = m_pImpl->getDoc().GetDocShell(); + if (!pShell) + return; // Do we have table styles from InteropGrabBag available? - rtl::Reference<SwXTextDocument> xPropertySet(m_pImpl->getDoc().GetDocShell()->GetBaseModel()); + rtl::Reference<SwXTextDocument> xPropertySet(pShell->GetBaseModel()); uno::Sequence<beans::PropertyValue> aInteropGrabBag; xPropertySet->getPropertyValue(u"InteropGrabBag"_ustr) >>= aInteropGrabBag; uno::Sequence<beans::PropertyValue> aTableStyles; diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx index 871a116a4e2b..31f8f8f0f340 100644 --- a/sw/source/filter/ww8/ww8par.cxx +++ b/sw/source/filter/ww8/ww8par.cxx @@ -6754,9 +6754,12 @@ void SwWW8ImplReader::NotifyMacroEventRead() { if (m_bNotifyMacroEventRead) return; - uno::Reference<frame::XModel> const xModel(static_cast<SfxBaseModel*>(m_rDoc.GetDocShell()->GetBaseModel().get())); - comphelper::DocumentInfo::notifyMacroEventRead(xModel); - m_bNotifyMacroEventRead = true; + if (SwDocShell* pShell = m_rDoc.GetDocShell()) + { + uno::Reference<frame::XModel> const xModel(static_cast<SfxBaseModel*>(pShell->GetBaseModel().get())); + comphelper::DocumentInfo::notifyMacroEventRead(xModel); + m_bNotifyMacroEventRead = true; + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx index 676317ef869e..b0be42eab82f 100644 --- a/sw/source/filter/xml/xmlexp.cxx +++ b/sw/source/filter/xml/xmlexp.cxx @@ -358,6 +358,10 @@ void SwXMLExport::ExportFontDecls_() void SwXMLExport::GetViewSettings(Sequence<PropertyValue>& aProps) { + SwDoc *pDoc = getDoc(); + SwDocShell* pShell = pDoc->GetDocShell(); + if (!pShell) + return; aProps.realloc(7); // Currently exporting 9 properties PropertyValue *pValue = aProps.getArray(); @@ -366,10 +370,8 @@ void SwXMLExport::GetViewSettings(Sequence<PropertyValue>& aProps) pValue[0].Name = "Views"; pValue[0].Value <<= uno::Reference< container::XIndexContainer >(xBox); - SwDoc *pDoc = getDoc(); - const tools::Rectangle rRect = - pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT ); - bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MapUnit::MapTwip; + const tools::Rectangle rRect = pShell->GetVisArea( ASPECT_CONTENT ); + bool bTwip = pShell->GetMapUnit ( ) == MapUnit::MapTwip; OSL_ENSURE( bTwip, "Map unit for visible area is not in TWIPS!" ); diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx index e6eccbbcdf27..bb26fe13a9ae 100644 --- a/sw/source/filter/xml/xmlimp.cxx +++ b/sw/source/filter/xml/xmlimp.cxx @@ -1162,23 +1162,26 @@ void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps) if (IsInsertMode() || IsStylesOnlyMode() || IsBlockMode() || m_bOrganizerMode || !GetModel().is() ) return; + SwDoc *pDoc = getDoc(); + SwDocShell* pShell = pDoc->GetDocShell(); + if (!pShell) + return; + // this method will modify the document directly -> lock SolarMutex SolarMutexGuard aGuard; - SwDoc *pDoc = getDoc(); tools::Rectangle aRect; - if( pDoc->GetDocShell() ) - aRect = pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT ); - //TODO/LATER: why that cast?! - //aRect = ((SfxInPlaceObject *)pDoc->GetDocShell())->GetVisArea(); + aRect = pShell->GetVisArea( ASPECT_CONTENT ); + //TODO/LATER: why that cast?! + //aRect = ((SfxInPlaceObject *)pShell)->GetVisArea(); sal_Int64 nTmp = 0; bool bShowRedlineChanges = false, bBrowseMode = false; bool bChangeShowRedline = false, bChangeBrowseMode = false; //TODO/LATER: why that cast?! - bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MapUnit::MapTwip; - //sal_Bool bTwip = pDoc->GetDocShell()->SfxInPlaceObject::GetMapUnit ( ) == MapUnit::MapTwip; + bool bTwip = pShell->GetMapUnit ( ) == MapUnit::MapTwip; + //sal_Bool bTwip = pShell->SfxInPlaceObject::GetMapUnit ( ) == MapUnit::MapTwip; for (const PropertyValue& rValue : aViewProps) { @@ -1218,8 +1221,7 @@ void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps) bChangeBrowseMode = true; } } - if( pDoc->GetDocShell() ) - pDoc->GetDocShell()->SetVisArea ( aRect ); + pShell->SetVisArea ( aRect ); if (bChangeBrowseMode) pDoc->getIDocumentSettingAccess().set(DocumentSettingId::BROWSE_MODE, bBrowseMode ); diff --git a/sw/source/filter/xml/xmltexti.cxx b/sw/source/filter/xml/xmltexti.cxx index 1037e1fb548a..93d698cac9eb 100644 --- a/sw/source/filter/xml/xmltexti.cxx +++ b/sw/source/filter/xml/xmltexti.cxx @@ -541,7 +541,8 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertOOoLink( uno::Sequence< beans::PropertyValue > aMediaDescriptor{ comphelper::makePropertyValue( u"URL"_ustr, aURLObj.GetMainURL( INetURLObject::DecodeMechanism::NONE )) }; - if (SfxMedium* pMedium = pDoc->GetDocShell() ? pDoc->GetDocShell()->GetMedium() : nullptr) + SwDocShell* pShell = pDoc->GetDocShell(); + if (SfxMedium* pMedium = pShell ? pShell->GetMedium() : nullptr) { uno::Reference< task::XInteractionHandler > xInteraction = pMedium->GetInteractionHandler(); if ( xInteraction.is() ) diff --git a/sw/source/ui/index/swuiidxmrk.cxx b/sw/source/ui/index/swuiidxmrk.cxx index fffd03a46c5e..f8b1a2351aed 100644 --- a/sw/source/ui/index/swuiidxmrk.cxx +++ b/sw/source/ui/index/swuiidxmrk.cxx @@ -1884,10 +1884,13 @@ IMPL_LINK(SwCreateAuthEntryDlg_Impl, BrowseHdl, weld::Button&, rButton, void) } else { - OUString aBaseURL = m_rWrtSh.GetDoc()->GetDocShell()->getDocumentBaseURL(); - if (!aBaseURL.isEmpty()) + if (SwDocShell* pShell = m_rWrtSh.GetDoc()->GetDocShell()) { - aFileDlg.SetDisplayDirectory(aBaseURL); + OUString aBaseURL = pShell->getDocumentBaseURL(); + if (!aBaseURL.isEmpty()) + { + aFileDlg.SetDisplayDirectory(aBaseURL); + } } } diff --git a/sw/source/uibase/misc/redlndlg.cxx b/sw/source/uibase/misc/redlndlg.cxx index 6c1e9a854d18..ab6078a4e976 100644 --- a/sw/source/uibase/misc/redlndlg.cxx +++ b/sw/source/uibase/misc/redlndlg.cxx @@ -368,7 +368,8 @@ void SwRedlineAcceptDlg::InitAuthors() pFilterPage->SelectAuthor(aStrings[0]); weld::TreeView& rTreeView = m_pTable->GetWidget(); - bool const bEnable = pSh && !pSh->GetDoc()->GetDocShell()->IsReadOnly() + SwDocShell* pShell = pSh ? pSh->GetDoc()->GetDocShell() : nullptr; + bool const bEnable = pShell && !pShell->IsReadOnly() && rTreeView.n_children() != 0 && !pSh->getIDocumentRedlineAccess().GetRedlinePassword().hasElements(); bool bSel = rTreeView.get_selected(nullptr); @@ -1393,7 +1394,8 @@ IMPL_LINK_NOARG(SwRedlineAcceptDlg, GotoHdl, Timer *, void) } } - bool const bEnable = !pSh->GetDoc()->GetDocShell()->IsReadOnly() + SwDocShell* pShell = pSh ? pSh->GetDoc()->GetDocShell() : nullptr; + bool const bEnable = pShell && !pShell->IsReadOnly() && !pSh->getIDocumentRedlineAccess().GetRedlinePassword().hasElements(); m_pTPView->EnableAccept( bEnable && bSel /*&& !bReadonlySel*/ ); m_pTPView->EnableReject( bEnable && bSel /*&& !bReadonlySel*/ ); diff --git a/sw/source/uibase/shells/grfshex.cxx b/sw/source/uibase/shells/grfshex.cxx index de3f438f18db..ddd52affe24a 100644 --- a/sw/source/uibase/shells/grfshex.cxx +++ b/sw/source/uibase/shells/grfshex.cxx @@ -128,10 +128,13 @@ bool SwTextShell::InsertMediaDlg( SfxRequest const & rReq ) } else { - uno::Reference<frame::XModel> const xModel( - rSh.GetDoc()->GetDocShell()->GetModel()); - bRet = ::avmedia::EmbedMedia(xModel, aURL, realURL); - if (!bRet) { return bRet; } + if (SwDocShell* pShell = rSh.GetDoc()->GetDocShell()) + { + uno::Reference<frame::XModel> const xModel( + pShell->GetModel()); + bRet = ::avmedia::EmbedMedia(xModel, aURL, realURL); + if (!bRet) { return bRet; } + } } rtl::Reference<SdrMediaObj> pObj = new SdrMediaObj( diff --git a/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx b/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx index 4a69c2c1b21b..eb8424ae92d8 100644 --- a/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx +++ b/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx @@ -766,6 +766,9 @@ IMPL_LINK(WriterInspectorTextPanel, AttrChangedNotify, LinkParamNone*, pLink, vo } SwDocShell* pDocSh = m_pShell->GetDoc()->GetDocShell(); + if (!pDocSh) + return; + std::vector<svx::sidebar::TreeNode> aStore; if (m_pShell->GetCursor()->GetPointNode().GetTextNode()) diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index aeb358201205..2c5d72edaff2 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -1005,9 +1005,12 @@ static OUString lcl_CreateOutlineString(const size_t nIndex, const SwDoc* pDoc) nVal -= pOutlRule->Get(nLevel).GetStart(); sEntry.append( OUString::number(nVal) + "."); } - OUString sOutlineText = pDoc->getIDocumentOutlineNodes().getOutlineText( - nIndex, pDoc->GetDocShell()->GetWrtShell()->GetLayout(), false); - sEntry.append(sOutlineText); + if (const SwDocShell* pShell = pDoc->GetDocShell()) + { + OUString sOutlineText = pDoc->getIDocumentOutlineNodes().getOutlineText( + nIndex, pShell->GetWrtShell()->GetLayout(), false); + sEntry.append(sOutlineText); + } return sEntry.makeStringAndClear(); } @@ -3176,8 +3179,8 @@ void SAL_CALL SwXTextDocument::render( m_pHiddenViewFrame = nullptr; // prevent crash described in #i108805 - SwDocShell *pRenderDocShell = pDoc->GetDocShell(); - pRenderDocShell->GetMedium()->GetItemSet().Put( SfxBoolItem( SID_HIDDEN, false ) ); + if (SwDocShell *pRenderDocShell = pDoc->GetDocShell()) + pRenderDocShell->GetMedium()->GetItemSet().Put( SfxBoolItem( SID_HIDDEN, false ) ); } } diff --git a/sw/source/uibase/utlui/uitool.cxx b/sw/source/uibase/utlui/uitool.cxx index 9f8401f368ca..86c1c18264ef 100644 --- a/sw/source/uibase/utlui/uitool.cxx +++ b/sw/source/uibase/utlui/uitool.cxx @@ -439,6 +439,9 @@ namespace bool IsOwnFormat(const SwDoc& rDoc) { const SwDocShell* pDocShell = rDoc.GetDocShell(); + if (!pDocShell) + return false; + SfxMedium* pMedium = pDocShell->GetMedium(); if (!pMedium) {