diff options
author | Caolán McNamara <caolanm@redhat.com> | 2022-12-16 12:11:38 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2022-12-16 21:17:15 +0000 |
commit | 1726c27e0d633ab04843834d2bf987bc7645807f (patch) | |
tree | 7810a18cd5bc3bf5aa345b816b372d93bd323974 /sd | |
parent | 1ae71d8f09771ba7180be6ebdf89d36a31eb8625 (diff) |
check SfxObjectShell::Current()
SfxObjectShell::Current() can return null, it's based on the equally
vile SfxViewFrame::Current()
Change-Id: Ia5c7783680e9d8e5d3075078f16a2c15cb6f7a47
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144339
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/source/ui/animations/CustomAnimationDialog.cxx | 3 | ||||
-rw-r--r-- | sd/source/ui/app/sdmod2.cxx | 5 | ||||
-rw-r--r-- | sd/source/ui/sidebar/SlideBackground.cxx | 54 | ||||
-rw-r--r-- | sd/source/ui/view/drviews2.cxx | 34 |
4 files changed, 57 insertions, 39 deletions
diff --git a/sd/source/ui/animations/CustomAnimationDialog.cxx b/sd/source/ui/animations/CustomAnimationDialog.cxx index 625a3049695e..41d7685798d4 100644 --- a/sd/source/ui/animations/CustomAnimationDialog.cxx +++ b/sd/source/ui/animations/CustomAnimationDialog.cxx @@ -265,11 +265,10 @@ SdFontPropertyBox::SdFontPropertyBox(weld::Label* pLabel, weld::Container* pPare mxControl->show(); pLabel->set_mnemonic_widget(mxControl.get()); - SfxObjectShell* pDocSh = SfxObjectShell::Current(); const FontList* pFontList = nullptr; bool bMustDelete = false; - if (pDocSh) + if (SfxObjectShell* pDocSh = SfxObjectShell::Current()) { auto pItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST ); if (pItem) diff --git a/sd/source/ui/app/sdmod2.cxx b/sd/source/ui/app/sdmod2.cxx index 58c822c47bc4..cccf425172bc 100644 --- a/sd/source/ui/app/sdmod2.cxx +++ b/sd/source/ui/app/sdmod2.cxx @@ -342,10 +342,11 @@ IMPL_LINK(SdModule, CalcFieldValueHdl, EditFieldInfo*, pInfo, void) { try { - if (SfxObjectShell::Current() && SfxObjectShell::Current()->IsLoadingFinished()) + SfxObjectShell* pObjSh = SfxObjectShell::Current(); + if (pObjSh && pObjSh->IsLoadingFinished()) { auto pNonConstCustomPropertyField = const_cast<editeng::CustomPropertyField*>(pCustomPropertyField); - OUString sCurrent = pNonConstCustomPropertyField->GetFormatted(SfxObjectShell::Current()->getDocProperties()); + OUString sCurrent = pNonConstCustomPropertyField->GetFormatted(pObjSh->getDocProperties()); pInfo->SetRepresentation(sCurrent); } else diff --git a/sd/source/ui/sidebar/SlideBackground.cxx b/sd/source/ui/sidebar/SlideBackground.cxx index 11f49dff67eb..5f8bcff886b7 100644 --- a/sd/source/ui/sidebar/SlideBackground.cxx +++ b/sd/source/ui/sidebar/SlideBackground.cxx @@ -754,11 +754,14 @@ XGradient const & SlideBackground::GetGradientSetOrDefault() { if( !mpGradientItem ) { - SfxObjectShell* pSh = SfxObjectShell::Current(); - const SvxGradientListItem * pGradListItem = pSh->GetItem(SID_GRADIENT_LIST); - const XGradient aGradient = pGradListItem->GetGradientList()->GetGradient(0)->GetGradient(); - const OUString aGradientName = pGradListItem->GetGradientList()->GetGradient(0)->GetName(); - + XGradient aGradient; + OUString aGradientName; + if (SfxObjectShell* pSh = SfxObjectShell::Current()) + { + const SvxGradientListItem * pGradListItem = pSh->GetItem(SID_GRADIENT_LIST); + aGradient = pGradListItem->GetGradientList()->GetGradient(0)->GetGradient(); + aGradientName = pGradListItem->GetGradientList()->GetGradient(0)->GetName(); + } mpGradientItem.reset( new XFillGradientItem( aGradientName, aGradient ) ); } @@ -769,11 +772,14 @@ OUString const & SlideBackground::GetHatchingSetOrDefault() { if( !mpHatchItem ) { - SfxObjectShell* pSh = SfxObjectShell::Current(); - const SvxHatchListItem * pHatchListItem = pSh->GetItem(SID_HATCH_LIST); - const XHatch aHatch = pHatchListItem->GetHatchList()->GetHatch(0)->GetHatch(); - const OUString aHatchName = pHatchListItem->GetHatchList()->GetHatch(0)->GetName(); - + XHatch aHatch; + OUString aHatchName; + if (SfxObjectShell* pSh = SfxObjectShell::Current()) + { + const SvxHatchListItem * pHatchListItem = pSh->GetItem(SID_HATCH_LIST); + aHatch = pHatchListItem->GetHatchList()->GetHatch(0)->GetHatch(); + aHatchName = pHatchListItem->GetHatchList()->GetHatch(0)->GetName(); + } mpHatchItem.reset( new XFillHatchItem( aHatchName, aHatch ) ); } @@ -784,11 +790,14 @@ OUString const & SlideBackground::GetBitmapSetOrDefault() { if( !mpBitmapItem || mpBitmapItem->isPattern()) { - SfxObjectShell* pSh = SfxObjectShell::Current(); - const SvxBitmapListItem * pBmpListItem = pSh->GetItem(SID_BITMAP_LIST); - const GraphicObject aGraphObj = pBmpListItem->GetBitmapList()->GetBitmap(0)->GetGraphicObject(); - const OUString aBmpName = pBmpListItem->GetBitmapList()->GetBitmap(0)->GetName(); - + GraphicObject aGraphObj; + OUString aBmpName; + if (SfxObjectShell* pSh = SfxObjectShell::Current()) + { + const SvxBitmapListItem * pBmpListItem = pSh->GetItem(SID_BITMAP_LIST); + aGraphObj = pBmpListItem->GetBitmapList()->GetBitmap(0)->GetGraphicObject(); + aBmpName = pBmpListItem->GetBitmapList()->GetBitmap(0)->GetName(); + } mpBitmapItem.reset( new XFillBitmapItem( aBmpName, aGraphObj ) ); } @@ -799,11 +808,14 @@ OUString const & SlideBackground::GetPatternSetOrDefault() { if( !mpBitmapItem || !(mpBitmapItem->isPattern())) { - SfxObjectShell* pSh = SfxObjectShell::Current(); - const SvxPatternListItem * pPtrnListItem = pSh->GetItem(SID_PATTERN_LIST); - const GraphicObject aGraphObj = pPtrnListItem->GetPatternList()->GetBitmap(0)->GetGraphicObject(); - const OUString aPtrnName = pPtrnListItem->GetPatternList()->GetBitmap(0)->GetName(); - + GraphicObject aGraphObj; + OUString aPtrnName; + if (SfxObjectShell* pSh = SfxObjectShell::Current()) + { + const SvxPatternListItem * pPtrnListItem = pSh->GetItem(SID_PATTERN_LIST); + aGraphObj = pPtrnListItem->GetPatternList()->GetBitmap(0)->GetGraphicObject(); + aPtrnName = pPtrnListItem->GetPatternList()->GetBitmap(0)->GetName(); + } mpBitmapItem.reset( new XFillBitmapItem( aPtrnName, aGraphObj ) ); } @@ -1134,6 +1146,8 @@ IMPL_LINK_NOARG(SlideBackground, FillBackgroundHdl, weld::ComboBox&, void) { const eFillStyle nFillPos = static_cast<eFillStyle>(mxFillStyle->get_active()); SfxObjectShell* pSh = SfxObjectShell::Current(); + if (!pSh) + return; switch(nFillPos) { diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx index ebd99d6a61b8..cd575c493423 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -244,9 +244,9 @@ protected: uno::Reference<beans::XPropertyContainer> m_xPropertyContainer; sfx::ClassificationKeyCreator m_aKeyCreator; public: - ClassificationCommon(sd::DrawViewShell & rDrawViewShell) + ClassificationCommon(sd::DrawViewShell& rDrawViewShell, const css::uno::Reference<css::document::XDocumentProperties>& rDocProps) : m_rDrawViewShell(rDrawViewShell) - , m_xDocumentProperties(SfxObjectShell::Current()->getDocProperties()) + , m_xDocumentProperties(rDocProps) , m_xPropertyContainer(m_xDocumentProperties->getUserDefinedProperties()) , m_aKeyCreator(SfxClassificationHelper::getPolicyType()) {} @@ -306,8 +306,8 @@ private: } public: - ClassificationCollector(sd::DrawViewShell & rDrawViewShell) - : ClassificationCommon(rDrawViewShell) + ClassificationCollector(sd::DrawViewShell & rDrawViewShell, const css::uno::Reference<css::document::XDocumentProperties>& rDocProps) + : ClassificationCommon(rDrawViewShell, rDocProps) {} std::vector<svx::ClassificationResult> const & getResults() const @@ -461,8 +461,8 @@ private: } public: - ClassificationInserter(sd::DrawViewShell & rDrawViewShell) - : ClassificationCommon(rDrawViewShell) + ClassificationInserter(sd::DrawViewShell & rDrawViewShell, const css::uno::Reference<css::document::XDocumentProperties>& rDocProps) + : ClassificationCommon(rDrawViewShell, rDocProps) { } @@ -1689,18 +1689,22 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq) case SID_CLASSIFICATION_DIALOG: { - auto xDialog = std::make_shared<svx::ClassificationDialog>(GetFrameWeld(), false, [](){} ); - ClassificationCollector aCollector(*this); - aCollector.collect(); + if (SfxObjectShell* pObjShell = SfxObjectShell::Current()) + { + css::uno::Reference<css::document::XDocumentProperties> xDocProps(pObjShell->getDocProperties()); + auto xDialog = std::make_shared<svx::ClassificationDialog>(GetFrameWeld(), xDocProps, false, [](){} ); + ClassificationCollector aCollector(*this, xDocProps); + aCollector.collect(); - xDialog->setupValues(std::vector(aCollector.getResults())); + xDialog->setupValues(std::vector(aCollector.getResults())); - if (RET_OK == xDialog->run()) - { - ClassificationInserter aInserter(*this); - aInserter.insert(xDialog->getResult()); + if (RET_OK == xDialog->run()) + { + ClassificationInserter aInserter(*this, xDocProps); + aInserter.insert(xDialog->getResult()); + } + xDialog.reset(); } - xDialog.reset(); Cancel(); rReq.Ignore(); |