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>
This commit is contained in:
Caolán McNamara 2022-12-16 12:11:38 +00:00
parent 1ae71d8f09
commit 1726c27e0d
39 changed files with 355 additions and 292 deletions

View File

@ -156,7 +156,7 @@ IMPL_LINK_NOARG(SignSignatureLineDialog, chooseCertificate, weld::Button&, void)
{
// Document needs to be saved before selecting a certificate
SfxObjectShell* pShell = SfxObjectShell::Current();
if (!pShell->PrepareForSigning(m_xDialog.get()))
if (!pShell || !pShell->PrepareForSigning(m_xDialog.get()))
return;
Reference<XCertificate> xSignCertificate
@ -193,6 +193,12 @@ void SignSignatureLineDialog::Apply()
}
SfxObjectShell* pShell = SfxObjectShell::Current();
if (!pShell)
{
SAL_WARN("cui.dialogs", "No SfxObjectShell!");
return;
}
Reference<XGraphic> xValidGraphic = getSignedGraphic(true);
Reference<XGraphic> xInvalidGraphic = getSignedGraphic(false);
pShell->SignSignatureLine(m_xDialog.get(), m_aSignatureLineId, m_xSelectedCertifate,

View File

@ -64,9 +64,7 @@ void SvxSearchFormatDialog::PageCreated(const OString& rId, SfxTabPage& rPage)
if (rId == "font")
{
const FontList* pApm_pFontList = nullptr;
SfxObjectShell* pSh = SfxObjectShell::Current();
if ( pSh )
if (SfxObjectShell* pSh = SfxObjectShell::Current())
{
const SvxFontListItem* pFLItem = static_cast<const SvxFontListItem*>(
pSh->GetItem( SID_ATTR_CHAR_FONTLIST ));
@ -119,42 +117,44 @@ SvxSearchAttributeDialog::SvxSearchAttributeDialog(weld::Window* pParent,
SfxObjectShell* pSh = SfxObjectShell::Current();
DBG_ASSERT( pSh, "No DocShell" );
SfxItemPool& rPool = pSh->GetPool();
SfxItemSet aSet( rPool, pWhRanges );
SfxWhichIter aIter( aSet );
sal_uInt16 nWhich = aIter.FirstWhich();
while ( nWhich )
if (pSh)
{
sal_uInt16 nSlot = rPool.GetSlotId( nWhich );
if ( nSlot >= SID_SVX_START )
{
bool bChecked = false, bFound = false;
for ( sal_uInt16 i = 0; !bFound && i < rList.Count(); ++i )
{
if ( nSlot == rList[i].nSlot )
{
bFound = true;
if ( IsInvalidItem( rList[i].pItem ) )
bChecked = true;
}
}
SfxItemPool& rPool = pSh->GetPool();
SfxItemSet aSet( rPool, pWhRanges );
SfxWhichIter aIter( aSet );
sal_uInt16 nWhich = aIter.FirstWhich();
// item resources are in svx
sal_uInt32 nId = SvxAttrNameTable::FindIndex(nSlot);
if (RESARRAY_INDEX_NOTFOUND != nId)
while ( nWhich )
{
sal_uInt16 nSlot = rPool.GetSlotId( nWhich );
if ( nSlot >= SID_SVX_START )
{
m_xAttrLB->append();
const int nRow = m_xAttrLB->n_children() - 1;
m_xAttrLB->set_toggle(nRow, bChecked ? TRISTATE_TRUE : TRISTATE_FALSE);
m_xAttrLB->set_text(nRow, SvxAttrNameTable::GetString(nId), 0);
m_xAttrLB->set_id(nRow, OUString::number(nSlot));
bool bChecked = false, bFound = false;
for ( sal_uInt16 i = 0; !bFound && i < rList.Count(); ++i )
{
if ( nSlot == rList[i].nSlot )
{
bFound = true;
if ( IsInvalidItem( rList[i].pItem ) )
bChecked = true;
}
}
// item resources are in svx
sal_uInt32 nId = SvxAttrNameTable::FindIndex(nSlot);
if (RESARRAY_INDEX_NOTFOUND != nId)
{
m_xAttrLB->append();
const int nRow = m_xAttrLB->n_children() - 1;
m_xAttrLB->set_toggle(nRow, bChecked ? TRISTATE_TRUE : TRISTATE_FALSE);
m_xAttrLB->set_text(nRow, SvxAttrNameTable::GetString(nId), 0);
m_xAttrLB->set_id(nRow, OUString::number(nSlot));
}
else
SAL_WARN( "cui.dialogs", "no resource for slot id " << static_cast<sal_Int32>(nSlot) );
}
else
SAL_WARN( "cui.dialogs", "no resource for slot id " << static_cast<sal_Int32>(nSlot) );
nWhich = aIter.NextWhich();
}
nWhich = aIter.NextWhich();
}
m_xAttrLB->make_sorted();

View File

@ -168,9 +168,7 @@ SvxZoomDialog::SvxZoomDialog(weld::Window* pParent, const SfxItemSet& rCoreSet)
// maybe get the old value first
const SfxUInt16Item* pOldUserItem = nullptr;
SfxObjectShell* pShell = SfxObjectShell::Current();
if (pShell)
if (SfxObjectShell* pShell = SfxObjectShell::Current())
pOldUserItem = pShell->GetItem(SID_ATTR_ZOOM_USER);
if (pOldUserItem)
@ -384,9 +382,7 @@ IMPL_LINK_NOARG(SvxZoomDialog, OKHdl, weld::Button&, void)
m_pOutSet->Put(aViewLayoutItem);
// memorize value from the UserEdit beyond the dialog
SfxObjectShell* pShell = SfxObjectShell::Current();
if (pShell)
if (SfxObjectShell* pShell = SfxObjectShell::Current())
{
sal_uInt16 nZoomValue
= static_cast<sal_uInt16>(m_xUserEdit->get_value(FieldUnit::PERCENT));

View File

@ -769,7 +769,8 @@ bool OfaAutocorrReplacePage::FillItemSet( SfxItemSet* )
bool bKeepSourceFormatting = newEntry.pUserData == &bHasSelectionText;
if (bKeepSourceFormatting)
{
pAutoCorrect->PutText(newEntry.sShort, *SfxObjectShell::Current(), eCurrentLang);
if (SfxObjectShell* pSh = SfxObjectShell::Current())
pAutoCorrect->PutText(newEntry.sShort, *pSh, eCurrentLang);
continue;
}

View File

@ -574,8 +574,7 @@ SvxBorderTabPage::SvxBorderTabPage(weld::Container* pPage, weld::DialogControlle
// checkbox "Merge adjacent line styles" only visible for Writer dialog format.table
m_xMergeAdjacentBordersCB->hide();
SfxObjectShell* pDocSh = SfxObjectShell::Current();
if (pDocSh)
if (SfxObjectShell* pDocSh = SfxObjectShell::Current())
{
Reference< XServiceInfo > xSI( pDocSh->GetModel(), UNO_QUERY );
if ( xSI.is() )

View File

@ -344,10 +344,8 @@ const FontList* SvxCharNamePage::GetFontList() const
{
if ( !m_pImpl->m_pFontList )
{
SfxObjectShell* pDocSh = SfxObjectShell::Current();
/* #110771# SvxFontListItem::GetFontList can return NULL */
if ( pDocSh )
if (SfxObjectShell* pDocSh = SfxObjectShell::Current())
{
const SfxPoolItem* pItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST );
if ( pItem != nullptr )
@ -1366,8 +1364,7 @@ void SvxCharEffectsPage::Initialize()
const SfxUInt16Item* pHtmlModeItem = GetItemSet().GetItemIfSet( SID_HTML_MODE, false );
if ( !pHtmlModeItem)
{
SfxObjectShell* pShell = SfxObjectShell::Current();
if (pShell)
if (SfxObjectShell* pShell = SfxObjectShell::Current())
pHtmlModeItem = pShell->GetItem( SID_HTML_MODE );
}
if (pHtmlModeItem)

View File

@ -475,8 +475,7 @@ void SvxNumberFormatTabPage::Reset( const SfxItemSet* rSet )
bool bUseStarFormat = false;
SfxObjectShell* pDocSh = SfxObjectShell::Current();
if ( pDocSh )
if (SfxObjectShell* pDocSh = SfxObjectShell::Current())
{
// is this a calc document
Reference< XServiceInfo > xSI( pDocSh->GetModel(), UNO_QUERY );
@ -714,11 +713,8 @@ bool SvxNumberFormatTabPage::FillItemSet( SfxItemSet* rCoreAttrs )
else
{
SfxObjectShell* pDocSh = SfxObjectShell::Current();
DBG_ASSERT( pDocSh, "DocShell not found!" );
if ( pDocSh )
if (pDocSh)
pDocSh->PutItem( *pNumItem );
}
}

View File

@ -645,11 +645,13 @@ IMPL_LINK_NOARG(SvxNumPickTabPage, NumSelectHdl_Impl, ValueSet*, void)
//search for the font
if(!pList)
{
SfxObjectShell* pCurDocShell = SfxObjectShell::Current();
const SvxFontListItem* pFontListItem =
static_cast<const SvxFontListItem*>( pCurDocShell
->GetItem( SID_ATTR_CHAR_FONTLIST ));
pList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
if (SfxObjectShell* pCurDocShell = SfxObjectShell::Current())
{
const SvxFontListItem* pFontListItem =
static_cast<const SvxFontListItem*>( pCurDocShell
->GetItem( SID_ATTR_CHAR_FONTLIST ));
pList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
}
}
if(pList && pList->IsAvailable( pLevelSettings->sBulletFont ) )
{
@ -1243,8 +1245,7 @@ void SvxNumOptionsTabPage::Reset( const SfxItemSet* rSet )
rSet->GetItemIfSet( SID_HTML_MODE, false );
if (!pHtmlModeItem)
{
SfxObjectShell* pShell = SfxObjectShell::Current();
if (pShell)
if (SfxObjectShell* pShell = SfxObjectShell::Current())
pHtmlModeItem = pShell->GetItem( SID_HTML_MODE );
}
if ( pHtmlModeItem )

View File

@ -199,8 +199,7 @@ SvxPageDescPage::SvxPageDescPage(weld::Container* pPage, weld::DialogController*
const SfxUInt16Item* pHtmlModeItem = rAttr.GetItemIfSet(SID_HTML_MODE, false);
if (!pHtmlModeItem)
{
SfxObjectShell* pShell = SfxObjectShell::Current();
if (pShell)
if (SfxObjectShell* pShell = SfxObjectShell::Current())
pHtmlModeItem = pShell->GetItem(SID_HTML_MODE);
}
if (pHtmlModeItem)

View File

@ -148,8 +148,7 @@ static sal_uInt16 GetHtmlMode_Impl(const SfxItemSet& rSet)
const SfxUInt16Item* pItem = rSet.GetItemIfSet(SID_HTML_MODE, false);
if (!pItem)
{
SfxObjectShell* pShell = SfxObjectShell::Current();
if (pShell)
if (SfxObjectShell* pShell = SfxObjectShell::Current())
pItem = pShell->GetItem(SID_HTML_MODE);
}
if(pItem)
@ -1999,8 +1998,7 @@ SvxExtParagraphTabPage::SvxExtParagraphTabPage(weld::Container* pPage, weld::Dia
m_xPageNumBox->connect_toggled(LINK(this, SvxExtParagraphTabPage, PageNumBoxClickHdl_Impl));
m_xKeepParaBox->connect_toggled(LINK(this, SvxExtParagraphTabPage, KeepParaBoxClickHdl_Impl));
SfxObjectShell* pSh = SfxObjectShell::Current();
if ( pSh )
if (SfxObjectShell* pSh = SfxObjectShell::Current())
{
SfxStyleSheetBasePool* pPool = pSh->GetStyleSheetPool();
SfxStyleSheetBase* pStyle = pPool->First(SfxStyleFamily::Page);

View File

@ -1232,6 +1232,8 @@ rtl::Reference<LOKClipboard> forceSetClipboardForCurrentView(LibreOfficeKitDocum
const vcl::Font* FindFont(std::u16string_view rFontName)
{
SfxObjectShell* pDocSh = SfxObjectShell::Current();
if (!pDocSh)
return nullptr;
const SvxFontListItem* pFonts
= static_cast<const SvxFontListItem*>(pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST));
const FontList* pList = pFonts ? pFonts->GetFontList() : nullptr;
@ -4580,7 +4582,7 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
{
// Check if saving a PDF file
OUString aMimeType = lcl_getCurrentDocumentMimeType(pDocument);
if (pDocSh->IsModified() && aMimeType == "application/pdf")
if (pDocSh && pDocSh->IsModified() && aMimeType == "application/pdf")
{
// If we have a PDF file (for saving annotations for example), we need
// to run save-as to the same file as the opened document. Plain save
@ -4621,7 +4623,7 @@ static void doc_postUnoCommand(LibreOfficeKitDocument* pThis, const char* pComma
}), aPropertyValuesVector.end());
// skip saving and tell the result via UNO_COMMAND_RESULT
if (bDontSaveIfUnmodified && !pDocSh->IsModified())
if (bDontSaveIfUnmodified && (!pDocSh || !pDocSh->IsModified()))
{
tools::JsonWriter aJson;
aJson.put("commandName", pCommand);
@ -5393,6 +5395,8 @@ static char* getLanguages(const char* pCommand)
static char* getFonts (const char* pCommand)
{
SfxObjectShell* pDocSh = SfxObjectShell::Current();
if (!pDocSh)
return nullptr;
const SvxFontListItem* pFonts = static_cast<const SvxFontListItem*>(
pDocSh->GetItem(SID_ATTR_CHAR_FONTLIST));
const FontList* pList = pFonts ? pFonts->GetFontList() : nullptr;

View File

@ -362,9 +362,8 @@ IMPL_LINK_NOARG(BibGeneralPage, BrowseHdl, weld::Button&, void)
}
else
{
SfxObjectShell* pShell = SfxObjectShell::Current();
OUString aBaseURL;
if (pShell)
if (SfxObjectShell* pShell = SfxObjectShell::Current())
{
aBaseURL = pShell->getDocumentBaseURL();
}

View File

@ -82,8 +82,9 @@ private:
void toggleWidgetsDependingOnCategory();
public:
ClassificationDialog(weld::Window* pParent, bool bPerParagraph,
std::function<void()> aParagraphSignHandler = []() {});
ClassificationDialog(weld::Window* pParent,
const css::uno::Reference<css::document::XDocumentProperties>& rDocProps,
bool bPerParagraph, std::function<void()> aParagraphSignHandler = []() {});
~ClassificationDialog() override;
std::vector<ClassificationResult> getResult();

View File

@ -72,7 +72,7 @@ void ScAttrDlg::PageCreated(const OString& rPageId, SfxTabPage& rTabPage)
{
rTabPage.PageCreated(aSet);
}
else if (rPageId == "font")
else if (rPageId == "font" && pDocSh)
{
const SfxPoolItem* pInfoItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST );
assert(pInfoItem && "FontListItem not found :-(");

View File

@ -820,11 +820,14 @@ void ScDrawTextObjectBar::ExecuteAttr( SfxRequest &rReq )
pView->GetTextEditOutlinerView() : nullptr;
if ( pOutView )
{
const SvxFontListItem* pFontListItem = static_cast< const SvxFontListItem* >
( SfxObjectShell::Current()->GetItem( SID_ATTR_CHAR_FONTLIST ) );
const FontList* pFontList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
pOutView->GetEditView().ChangeFontSize( nSlot == SID_GROW_FONT_SIZE, pFontList );
mrViewData.GetBindings().Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
if (SfxObjectShell* pObjSh = SfxObjectShell::Current())
{
const SvxFontListItem* pFontListItem = static_cast< const SvxFontListItem* >
( pObjSh->GetItem( SID_ATTR_CHAR_FONTLIST ) );
const FontList* pFontList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
pOutView->GetEditView().ChangeFontSize( nSlot == SID_GROW_FONT_SIZE, pFontList );
mrViewData.GetBindings().Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
}
bDone = false;
}
}

View File

@ -99,9 +99,8 @@ void ScStyleDlg::PageCreated(const OString& rPageId, SfxTabPage& rTabPage)
rTabPage.PageCreated(aSet);
}
}
else
else if (SfxObjectShell* pDocSh = SfxObjectShell::Current())
{
SfxObjectShell* pDocSh = SfxObjectShell::Current();
SfxAllItemSet aSet(*(GetInputSetImpl()->GetPool()));
if (rPageId == "numbers")
{

View File

@ -1140,8 +1140,9 @@ void ScEditShell::ExecuteAttr(SfxRequest& rReq)
case SID_GROW_FONT_SIZE:
case SID_SHRINK_FONT_SIZE:
{
const SvxFontListItem* pFontListItem = static_cast< const SvxFontListItem* >
( SfxObjectShell::Current()->GetItem( SID_ATTR_CHAR_FONTLIST ) );
SfxObjectShell* pObjSh = SfxObjectShell::Current();
const SvxFontListItem* pFontListItem = static_cast<const SvxFontListItem*>
(pObjSh ? pObjSh->GetItem(SID_ATTR_CHAR_FONTLIST) : nullptr);
const FontList* pFontList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
pEditView->ChangeFontSize( nSlot == SID_GROW_FONT_SIZE, pFontList );
rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );

View File

@ -327,8 +327,7 @@ ScriptProtocolHandler::getScriptInvocation()
if ( pFrame->GetFrameInterface() == m_xFrame )
break;
}
SfxObjectShell* pDocShell = pFrame ? pFrame->GetCurrentDocument() : SfxObjectShell::Current();
if ( pDocShell )
if (SfxObjectShell* pDocShell = pFrame ? pFrame->GetCurrentDocument() : SfxObjectShell::Current())
{
Reference< XModel > xModel( pDocShell->GetModel() );
m_xScriptInvocation.set( xModel, UNO_QUERY );

View File

@ -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)

View File

@ -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

View File

@ -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)
{

View File

@ -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();
xDialog->setupValues(std::vector(aCollector.getResults()));
if (RET_OK == xDialog->run())
if (SfxObjectShell* pObjShell = SfxObjectShell::Current())
{
ClassificationInserter aInserter(*this);
aInserter.insert(xDialog->getResult());
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()));
if (RET_OK == xDialog->run())
{
ClassificationInserter aInserter(*this, xDocProps);
aInserter.insert(xDialog->getResult());
}
xDialog.reset();
}
xDialog.reset();
Cancel();
rReq.Ignore();

View File

@ -108,9 +108,11 @@ static bool lcl_GetPassword(
static bool lcl_IsPasswordCorrect(weld::Window *pParent, std::u16string_view rPassword)
{
bool bRes = false;
SfxObjectShell* pCurDocShell = SfxObjectShell::Current();
if (!pCurDocShell)
return false;
bool bRes = false;
uno::Sequence< sal_Int8 > aPasswordHash;
pCurDocShell->GetProtectionHash( aPasswordHash );
@ -199,7 +201,7 @@ bool SfxSecurityPage_Impl::FillItemSet_Impl()
bool bModified = false;
SfxObjectShell* pCurDocShell = SfxObjectShell::Current();
if (pCurDocShell&& !pCurDocShell->IsReadOnly())
if (pCurDocShell && !pCurDocShell->IsReadOnly())
{
if (m_eRedlingMode != RL_NONE )
{

View File

@ -155,10 +155,11 @@ void writeResultToXml(tools::XmlWriter & rXmlWriter,
} // end anonymous namespace
ClassificationDialog::ClassificationDialog(weld::Window* pParent, const bool bPerParagraph, std::function<void()> aParagraphSignHandler)
ClassificationDialog::ClassificationDialog(weld::Window* pParent, const css::uno::Reference<css::document::XDocumentProperties>& rDocProps,
const bool bPerParagraph, std::function<void()> aParagraphSignHandler)
: GenericDialogController(pParent, "svx/ui/classificationdialog.ui", "AdvancedDocumentClassificationDialog")
, maHelper(SfxObjectShell::Current()->getDocProperties())
, maInternationalHelper(SfxObjectShell::Current()->getDocProperties(), /*bUseLocalizedPolicy*/ false)
, maHelper(rDocProps)
, maInternationalHelper(rDocProps, /*bUseLocalizedPolicy*/ false)
, m_bPerParagraph(bPerParagraph)
, m_aParagraphSignHandler(std::move(aParagraphSignHandler))
, m_nCurrentSelectedCategory(-1)

View File

@ -1926,7 +1926,7 @@ namespace svxform
{
SfxObjectShell* pCurrentDoc = SfxObjectShell::Current();
DBG_ASSERT( pCurrentDoc, "DataNavigatorWindow::SetDocModified(): no objectshell" );
if ( !pCurrentDoc->IsModified() && pCurrentDoc->IsEnableSetModified() )
if (pCurrentDoc && !pCurrentDoc->IsModified() && pCurrentDoc->IsEnableSetModified())
pCurrentDoc->SetModified();
}

View File

@ -203,31 +203,39 @@ IMPL_LINK_NOARG(AreaPropertyPanelBase, ClickImportBitmapHdl, weld::Button&, void
if( nError != ERRCODE_NONE )
return;
XBitmapListRef pList = SfxObjectShell::Current()->GetItem(SID_BITMAP_LIST)->GetBitmapList();
INetURLObject aURL( aDlg.GetPath() );
OUString aFileName = aURL.GetLastName().getToken(0, '.');
OUString aName = aFileName;
tools::Long j = 1;
bool bValidBitmapName = false;
while( !bValidBitmapName )
mxLbFillAttr->clear();
if (SfxObjectShell* pSh = SfxObjectShell::Current())
{
bValidBitmapName = true;
for( tools::Long i = 0; i < pList->Count() && bValidBitmapName; i++ )
INetURLObject aURL(aDlg.GetPath());
OUString aFileName = aURL.GetLastName().getToken(0, '.');
OUString aName = aFileName;
XBitmapListRef pList = pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList();
tools::Long j = 1;
bool bValidBitmapName = false;
while( !bValidBitmapName )
{
if( aName == pList->GetBitmap(i)->GetName() )
bValidBitmapName = true;
for( tools::Long i = 0; i < pList->Count() && bValidBitmapName; i++ )
{
bValidBitmapName = false;
aName = aFileName + OUString::number(j++);
if( aName == pList->GetBitmap(i)->GetName() )
{
bValidBitmapName = false;
aName = aFileName + OUString::number(j++);
}
}
}
}
pList->Insert(std::make_unique<XBitmapEntry>(aGraphic, aName));
pList->Save();
mxLbFillAttr->clear();
SvxFillAttrBox::Fill(*mxLbFillAttr, pList);
mxLbFillAttr->set_active_text(aName);
SelectFillAttrHdl(*mxLbFillAttr);
pList->Insert(std::make_unique<XBitmapEntry>(aGraphic, aName));
pList->Save();
SvxFillAttrBox::Fill(*mxLbFillAttr, pList);
mxLbFillAttr->set_active_text(aName);
SelectFillAttrHdl(*mxLbFillAttr);
}
}
IMPL_LINK_NOARG(AreaPropertyPanelBase, SelectFillTypeHdl, weld::ComboBox&, void)
@ -285,7 +293,7 @@ void AreaPropertyPanelBase::SelectFillAttrHdl_Impl()
case eFillStyle::GRADIENT:
{
if(pSh && pSh->GetItem(SID_COLOR_TABLE))
if (pSh && pSh->GetItem(SID_COLOR_TABLE))
{
XGradient aGradient;
aGradient.SetAngle(Degree10(mxMTRAngle->get_value(FieldUnit::DEGREE) * 10));
@ -1097,10 +1105,12 @@ void AreaPropertyPanelBase::NotifyItemUpdate(
{
const OUString aString( mpFillGradientItem->GetName() );
const SfxObjectShell* pSh = SfxObjectShell::Current();
mxLbFillAttr->clear();
mxLbFillAttr->set_sensitive(true);
SvxFillAttrBox::Fill(*mxLbFillAttr, pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
if (pSh)
{
mxLbFillAttr->set_sensitive(true);
SvxFillAttrBox::Fill(*mxLbFillAttr, pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
}
mxLbFillAttr->set_active_text(aString);
}
else
@ -1121,10 +1131,12 @@ void AreaPropertyPanelBase::NotifyItemUpdate(
{
const OUString aString( mpHatchItem->GetName() );
const SfxObjectShell* pSh = SfxObjectShell::Current();
mxLbFillAttr->clear();
mxLbFillAttr->set_sensitive(true);
SvxFillAttrBox::Fill(*mxLbFillAttr, pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
if (pSh)
{
mxLbFillAttr->set_sensitive(true);
SvxFillAttrBox::Fill(*mxLbFillAttr, pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
}
mxLbFillAttr->set_active_text(aString);
}
else
@ -1148,13 +1160,12 @@ void AreaPropertyPanelBase::NotifyItemUpdate(
const SfxObjectShell* pSh = SfxObjectShell::Current();
mxLbFillAttr->clear();
mxLbFillAttr->show();
if(nSID == SID_BITMAP_LIST)
if (pSh)
{
SvxFillAttrBox::Fill(*mxLbFillAttr, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
}
else if(nSID == SID_PATTERN_LIST)
{
SvxFillAttrBox::Fill(*mxLbFillAttr, pSh->GetItem(SID_PATTERN_LIST)->GetPatternList());
if(nSID == SID_BITMAP_LIST)
SvxFillAttrBox::Fill(*mxLbFillAttr, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
else if(nSID == SID_PATTERN_LIST)
SvxFillAttrBox::Fill(*mxLbFillAttr, pSh->GetItem(SID_PATTERN_LIST)->GetPatternList());
}
mxLbFillAttr->set_active_text(aString);
}

View File

@ -786,9 +786,11 @@ void OutlineTypeMgr::ApplyNumRule(SvxNumRule& aNum, sal_uInt16 nIndex, sal_uInt1
//search for the font
if(!pList)
{
SfxObjectShell* pCurDocShell = SfxObjectShell::Current();
const SvxFontListItem* pFontListItem = static_cast<const SvxFontListItem*>( pCurDocShell->GetItem( SID_ATTR_CHAR_FONTLIST ) );
pList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
if (SfxObjectShell* pCurDocShell = SfxObjectShell::Current())
{
const SvxFontListItem* pFontListItem = static_cast<const SvxFontListItem*>(pCurDocShell->GetItem(SID_ATTR_CHAR_FONTLIST));
pList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
}
}
if(pList && pList->IsAvailable( pLevelSettings->sBulletFont ) )
{

View File

@ -275,11 +275,12 @@ void SvxFillToolBoxControl::StateChangedAtToolBoxControl(
if(mpFillGradientItem)
{
const OUString aString( mpFillGradientItem->GetName() );
const SfxObjectShell* pSh = SfxObjectShell::Current();
mpLbFillAttr->clear();
mpLbFillAttr->set_sensitive(true);
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
if (const SfxObjectShell* pSh = SfxObjectShell::Current())
{
mpLbFillAttr->set_sensitive(true);
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_GRADIENT_LIST)->GetGradientList());
}
mpLbFillAttr->set_active_text(aString);
}
else
@ -299,11 +300,12 @@ void SvxFillToolBoxControl::StateChangedAtToolBoxControl(
if(mpHatchItem)
{
const OUString aString( mpHatchItem->GetName() );
const SfxObjectShell* pSh = SfxObjectShell::Current();
mpLbFillAttr->clear();
mpLbFillAttr->set_sensitive(true);
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
if (const SfxObjectShell* pSh = SfxObjectShell::Current())
{
mpLbFillAttr->set_sensitive(true);
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_HATCH_LIST)->GetHatchList());
}
mpLbFillAttr->set_active_text(aString);
}
else
@ -323,11 +325,12 @@ void SvxFillToolBoxControl::StateChangedAtToolBoxControl(
if(mpBitmapItem)
{
const OUString aString( mpBitmapItem->GetName() );
const SfxObjectShell* pSh = SfxObjectShell::Current();
mpLbFillAttr->clear();
mpLbFillAttr->set_sensitive(true);
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
if (const SfxObjectShell* pSh = SfxObjectShell::Current())
{
mpLbFillAttr->set_sensitive(true);
SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList());
}
mpLbFillAttr->set_active_text(aString);
}
else

View File

@ -610,14 +610,12 @@ IMPL_LINK_NOARG(SvxLineBox, SelectHdl, ValueSet*, void)
default:
{
eXLS = drawing::LineStyle_DASH;
if ( nPos != -1 &&
SfxObjectShell::Current() &&
SfxObjectShell::Current()->GetItem( SID_DASH_LIST ) )
const SfxObjectShell* pObjSh = SfxObjectShell::Current();
if (nPos != -1 && pObjSh && pObjSh->GetItem(SID_DASH_LIST))
{
// LineDashItem will only be sent if it also has a dash.
// Notify cares!
SvxDashListItem const * pItem = SfxObjectShell::Current()->GetItem( SID_DASH_LIST );
SvxDashListItem const * pItem = pObjSh->GetItem( SID_DASH_LIST );
const XDashEntry* pEntry = pItem->GetDashList()->GetDash(nPos - 2);
XLineDashItem aLineDashItem(pEntry->GetName(), pEntry->GetDash());

View File

@ -777,7 +777,11 @@ static void equaliseNumberOfParagraph(std::vector<svx::ClassificationResult> con
void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationResult> const & rResults)
{
SwDocShell* pDocShell = GetDoc()->GetDocShell();
if (!pDocShell || !SfxObjectShell::Current())
if (!pDocShell)
return;
const SfxObjectShell* pObjSh = SfxObjectShell::Current();
if (!pObjSh)
return;
uno::Reference<frame::XModel> xModel = pDocShell->GetBaseModel();
@ -787,7 +791,7 @@ void SwEditShell::ApplyAdvancedClassification(std::vector<svx::ClassificationRes
uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY);
uno::Reference<document::XDocumentProperties> xDocumentProperties = SfxObjectShell::Current()->getDocProperties();
uno::Reference<document::XDocumentProperties> xDocumentProperties = pObjSh->getDocProperties();
const OUString sPolicy = SfxClassificationHelper::policyTypeToString(SfxClassificationHelper::getPolicyType());
const std::vector<OUString> aUsedPageStyles = lcl_getUsedPageStyles(this);
@ -949,12 +953,16 @@ std::vector<svx::ClassificationResult> SwEditShell::CollectAdvancedClassificatio
std::vector<svx::ClassificationResult> aResult;
SwDocShell* pDocShell = GetDoc()->GetDocShell();
if (!pDocShell || !SfxObjectShell::Current())
if (!pDocShell)
return aResult;
const SfxObjectShell* pObjSh = SfxObjectShell::Current();
if (!pObjSh)
return aResult;
const OUString sBlank;
uno::Reference<document::XDocumentProperties> xDocumentProperties = SfxObjectShell::Current()->getDocProperties();
uno::Reference<document::XDocumentProperties> xDocumentProperties = pObjSh->getDocProperties();
uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
sfx::ClassificationKeyCreator aCreator(SfxClassificationHelper::getPolicyType());

View File

@ -54,7 +54,7 @@ SwDocStatPage::SwDocStatPage(weld::Container* pPage, weld::DialogController* pCo
m_xUpdatePB->connect_clicked(LINK(this, SwDocStatPage, UpdateHdl));
//#111684# is the current view a page preview no SwFEShell can be found -> hide the update button
SwDocShell* pDocShell = static_cast<SwDocShell*>( SfxObjectShell::Current() );
SwFEShell* pFEShell = pDocShell->GetFEShell();
SwFEShell* pFEShell = pDocShell ? pDocShell->GetFEShell() : nullptr;
if(!pFEShell)
{
m_xUpdatePB->hide();
@ -118,7 +118,7 @@ IMPL_LINK_NOARG(SwDocStatPage, UpdateHdl, weld::Button&, void)
{
Update();
SwDocShell* pDocShell = static_cast<SwDocShell*>( SfxObjectShell::Current());
SwFEShell* pFEShell = pDocShell->GetFEShell();
SwFEShell* pFEShell = pDocShell ? pDocShell->GetFEShell() : nullptr;
if (pFEShell)
m_xLineNo->set_label(OUString::number(pFEShell->GetLineCount()));
}

View File

@ -187,8 +187,8 @@ SfxTabPage* SwFieldEditDlg::CreatePage(sal_uInt16 nGroup)
xTabPage = SwFieldRefPage::Create(get_content_area(), this, nullptr);
break;
case GRP_REG:
if (SfxObjectShell* pDocSh = SfxObjectShell::Current())
{
SfxObjectShell* pDocSh = SfxObjectShell::Current();
auto pSet = new SfxItemSetFixed<FN_FIELD_DIALOG_DOC_PROPS, FN_FIELD_DIALOG_DOC_PROPS>( pDocSh->GetPool() );
using namespace ::com::sun::star;
uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
@ -200,8 +200,8 @@ SfxTabPage* SwFieldEditDlg::CreatePage(sal_uInt16 nGroup)
uno::UNO_QUERY_THROW);
pSet->Put( SfxUnoAnyItem( FN_FIELD_DIALOG_DOC_PROPS, uno::Any(xUDProps) ) );
xTabPage = SwFieldDokInfPage::Create(get_content_area(), this, pSet);
break;
}
break;
#if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
case GRP_DB:
xTabPage = SwFieldDBPage::Create(get_content_area(), this, nullptr);

View File

@ -1223,36 +1223,38 @@ void SwDocShell::Execute(SfxRequest& rReq)
}
break;
case SID_CLASSIFICATION_DIALOG:
{
auto xDialog = std::make_shared<svx::ClassificationDialog>(GetView()->GetFrameWeld(), false);
SwWrtShell* pShell = GetWrtShell();
std::vector<svx::ClassificationResult> aInput = pShell->CollectAdvancedClassification();
xDialog->setupValues(std::move(aInput));
weld::DialogController::runAsync(xDialog, [xDialog, pShell](sal_Int32 nResult){
if (RET_OK == nResult)
pShell->ApplyAdvancedClassification(xDialog->getResult());
});
}
break;
case SID_PARAGRAPH_SIGN_CLASSIFY_DLG:
{
SwWrtShell* pShell = GetWrtShell();
auto xDialog = std::make_shared<svx::ClassificationDialog>(GetView()->GetFrameWeld(), true, [pShell]()
if (SfxObjectShell* pObjSh = SfxObjectShell::Current())
{
pShell->SignParagraph();
});
auto xDialog = std::make_shared<svx::ClassificationDialog>(GetView()->GetFrameWeld(), pObjSh->getDocProperties(), false);
std::vector<svx::ClassificationResult> aInput = pShell->CollectParagraphClassification();
xDialog->setupValues(std::move(aInput));
SwWrtShell* pShell = GetWrtShell();
std::vector<svx::ClassificationResult> aInput = pShell->CollectAdvancedClassification();
xDialog->setupValues(std::move(aInput));
weld::DialogController::runAsync(xDialog, [xDialog, pShell](sal_Int32 nResult){
if (RET_OK == nResult)
pShell->ApplyParagraphClassification(xDialog->getResult());
});
}
break;
weld::DialogController::runAsync(xDialog, [xDialog, pShell](sal_Int32 nResult){
if (RET_OK == nResult)
pShell->ApplyAdvancedClassification(xDialog->getResult());
});
}
break;
case SID_PARAGRAPH_SIGN_CLASSIFY_DLG:
if (SfxObjectShell* pObjSh = SfxObjectShell::Current())
{
SwWrtShell* pShell = GetWrtShell();
auto xDialog = std::make_shared<svx::ClassificationDialog>(GetView()->GetFrameWeld(), pObjSh->getDocProperties(), true, [pShell]()
{
pShell->SignParagraph();
});
std::vector<svx::ClassificationResult> aInput = pShell->CollectParagraphClassification();
xDialog->setupValues(std::move(aInput));
weld::DialogController::runAsync(xDialog, [xDialog, pShell](sal_Int32 nResult){
if (RET_OK == nResult)
pShell->ApplyParagraphClassification(xDialog->getResult());
});
}
break;
case SID_WATERMARK:
{
SwWrtShell* pSh = GetWrtShell();

View File

@ -560,9 +560,11 @@ IMPL_LINK_NOARG(SwJumpToSpecificBox_Impl, SelectHdl, weld::Entry&, bool)
OUString sEntry(m_xWidget->get_text());
SfxUInt16Item aPageNum(m_nSlotId);
aPageNum.SetValue(o3tl::narrowing<sal_uInt16>(sEntry.toInt32()));
SfxObjectShell* pCurrentShell = SfxObjectShell::Current();
pCurrentShell->GetDispatcher()->ExecuteList(m_nSlotId, SfxCallMode::ASYNCHRON,
{ &aPageNum });
if (SfxObjectShell* pCurrentShell = SfxObjectShell::Current())
{
pCurrentShell->GetDispatcher()->ExecuteList(m_nSlotId, SfxCallMode::ASYNCHRON,
{ &aPageNum });
}
return true;
}

View File

@ -224,8 +224,9 @@ void SwAnnotationShell::Exec( SfxRequest &rReq )
case FN_GROW_FONT_SIZE:
case FN_SHRINK_FONT_SIZE:
{
const SvxFontListItem* pFontListItem = static_cast< const SvxFontListItem* >
( SfxObjectShell::Current()->GetItem( SID_ATTR_CHAR_FONTLIST ) );
const SfxObjectShell* pObjSh = SfxObjectShell::Current();
const SvxFontListItem* pFontListItem = static_cast<const SvxFontListItem*>
(pObjSh ? pObjSh->GetItem(SID_ATTR_CHAR_FONTLIST) : nullptr);
const FontList* pFontList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
pOLV->GetEditView().ChangeFontSize( nSlot == FN_GROW_FONT_SIZE, pFontList );
}

View File

@ -624,8 +624,9 @@ void SwDrawTextShell::Execute( SfxRequest &rReq )
case FN_GROW_FONT_SIZE:
case FN_SHRINK_FONT_SIZE:
{
const SfxObjectShell* pObjSh = SfxObjectShell::Current();
const SvxFontListItem* pFontListItem = static_cast< const SvxFontListItem* >
( SfxObjectShell::Current()->GetItem( SID_ATTR_CHAR_FONTLIST ) );
(pObjSh ? pObjSh->GetItem(SID_ATTR_CHAR_FONTLIST) : nullptr);
const FontList* pFontList = pFontListItem ? pFontListItem->GetFontList() : nullptr;
pOLV->GetEditView().ChangeFontSize( nSlot == FN_GROW_FONT_SIZE, pFontList );
}

View File

@ -260,11 +260,14 @@ XGradient const & PageStylesPanel::GetGradientSetOrDefault()
{
if( !mpBgGradientItem )
{
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();
}
mpBgGradientItem.reset( new XFillGradientItem( aGradientName, aGradient ) );
}
@ -275,11 +278,14 @@ OUString const & PageStylesPanel::GetHatchingSetOrDefault()
{
if( !mpBgHatchItem )
{
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();
}
mpBgHatchItem.reset( new XFillHatchItem( aHatchName, aHatch ) );
}
@ -290,11 +296,14 @@ OUString const & PageStylesPanel::GetBitmapSetOrDefault()
{
if( !mpBgBitmapItem || mpBgBitmapItem->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();
}
mpBgBitmapItem.reset( new XFillBitmapItem( aBmpName, aGraphObj ) );
}
@ -305,11 +314,14 @@ OUString const & PageStylesPanel::GetPatternSetOrDefault()
{
if( !mpBgBitmapItem || !mpBgBitmapItem->isPattern() )
{
SfxObjectShell* pSh = SfxObjectShell::Current();
const SvxPatternListItem * pPatternListItem = pSh->GetItem(SID_PATTERN_LIST);
const GraphicObject aGraphObj = pPatternListItem->GetPatternList()->GetBitmap(0)->GetGraphicObject();
const OUString aPatternName = pPatternListItem->GetPatternList()->GetBitmap(0)->GetName();
GraphicObject aGraphObj;
OUString aPatternName;
if (SfxObjectShell* pSh = SfxObjectShell::Current())
{
const SvxPatternListItem * pPatternListItem = pSh->GetItem(SID_PATTERN_LIST);
aGraphObj = pPatternListItem->GetPatternList()->GetBitmap(0)->GetGraphicObject();
aPatternName = pPatternListItem->GetPatternList()->GetBitmap(0)->GetName();
}
mpBgBitmapItem.reset( new XFillBitmapItem( aPatternName, aGraphObj ) );
}
@ -547,40 +559,42 @@ void PageStylesPanel::ModifyFillColor()
}
break;
case HATCH:
{
const SvxHatchListItem * pHatchListItem = pSh->GetItem(SID_HATCH_LIST);
sal_uInt16 nPos = mxBgHatchingLB->get_active();
XHatch aHatch = pHatchListItem->GetHatchList()->GetHatch(nPos)->GetHatch();
const OUString aHatchName = pHatchListItem->GetHatchList()->GetHatch(nPos)->GetName();
if (pSh)
{
const SvxHatchListItem * pHatchListItem = pSh->GetItem(SID_HATCH_LIST);
sal_uInt16 nPos = mxBgHatchingLB->get_active();
XHatch aHatch = pHatchListItem->GetHatchList()->GetHatch(nPos)->GetHatch();
const OUString aHatchName = pHatchListItem->GetHatchList()->GetHatch(nPos)->GetName();
XFillHatchItem aItem(aHatchName, aHatch);
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_HATCH, SfxCallMode::RECORD, { &aItem });
}
break;
XFillHatchItem aItem(aHatchName, aHatch);
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_HATCH, SfxCallMode::RECORD, { &aItem });
}
break;
case BITMAP:
case PATTERN:
{
sal_Int16 nPos = mxBgBitmapLB->get_active();
GraphicObject aBitmap;
OUString aBitmapName;
if ( eXFS == BITMAP )
if (pSh)
{
SvxBitmapListItem const * pBitmapListItem = pSh->GetItem(SID_BITMAP_LIST);
aBitmap = pBitmapListItem->GetBitmapList()->GetBitmap(nPos)->GetGraphicObject();
aBitmapName = pBitmapListItem->GetBitmapList()->GetBitmap(nPos)->GetName();
}
else
{
SvxPatternListItem const * pPatternListItem = pSh->GetItem(SID_PATTERN_LIST);
aBitmap = pPatternListItem->GetPatternList()->GetBitmap(nPos)->GetGraphicObject();
aBitmapName = pPatternListItem->GetPatternList()->GetBitmap(nPos)->GetName();
}
sal_Int16 nPos = mxBgBitmapLB->get_active();
GraphicObject aBitmap;
OUString aBitmapName;
XFillBitmapItem aItem(aBitmapName, aBitmap);
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_BITMAP, SfxCallMode::RECORD, { &aItem });
}
break;
if ( eXFS == BITMAP )
{
SvxBitmapListItem const * pBitmapListItem = pSh->GetItem(SID_BITMAP_LIST);
aBitmap = pBitmapListItem->GetBitmapList()->GetBitmap(nPos)->GetGraphicObject();
aBitmapName = pBitmapListItem->GetBitmapList()->GetBitmap(nPos)->GetName();
}
else
{
SvxPatternListItem const * pPatternListItem = pSh->GetItem(SID_PATTERN_LIST);
aBitmap = pPatternListItem->GetPatternList()->GetBitmap(nPos)->GetGraphicObject();
aBitmapName = pPatternListItem->GetPatternList()->GetBitmap(nPos)->GetName();
}
XFillBitmapItem aItem(aBitmapName, aBitmap);
GetBindings()->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_BITMAP, SfxCallMode::RECORD, { &aItem });
}
break;
default:
break;
}

View File

@ -118,13 +118,13 @@ BitmapEx GenerateStylePreview(SfxObjectShell& rSource, OUString const & aName)
BitmapEx CreatePreview(OUString const & aUrl, OUString const & aName)
{
SfxMedium aMedium(aUrl, StreamMode::STD_READWRITE);
SfxObjectShell* pObjectShell = SfxObjectShell::Current();
SfxObjectShellLock xTemplDoc = SfxObjectShell::CreateObjectByFactoryName(pObjectShell->GetFactory().GetFactoryName(), SfxObjectCreateMode::ORGANIZER);
xTemplDoc->DoInitNew();
if (xTemplDoc->LoadFrom(aMedium))
if (SfxObjectShell* pObjectShell = SfxObjectShell::Current())
{
return GenerateStylePreview(*xTemplDoc, aName);
SfxMedium aMedium(aUrl, StreamMode::STD_READWRITE);
SfxObjectShellLock xTemplDoc = SfxObjectShell::CreateObjectByFactoryName(pObjectShell->GetFactory().GetFactoryName(), SfxObjectCreateMode::ORGANIZER);
xTemplDoc->DoInitNew();
if (xTemplDoc->LoadFrom(aMedium))
return GenerateStylePreview(*xTemplDoc, aName);
}
return BitmapEx();
}
@ -185,8 +185,7 @@ IMPL_LINK_NOARG(StylePresetsPanel, DoubleClickHdl, ValueSet*, void)
sal_Int32 nItemId = mxValueSet->GetSelectedItemId();
TemplateEntry* pEntry = static_cast<TemplateEntry*>(mxValueSet->GetItemData(nItemId));
SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
if (pDocSh)
if (SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current()))
{
SwgReaderOption aOption;
aOption.SetTextFormats(true);

View File

@ -419,15 +419,17 @@ static void MetadataToTreeNode(const css::uno::Reference<css::uno::XInterface>&
// list associated (predicate, object) pairs of the actual subject
// under the tree node "Metadata Reference"
SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current());
uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(pDocSh->GetBaseModel(),
uno::UNO_QUERY);
const uno::Reference<rdf::XRepository>& xRepo = xDocumentMetadataAccess->getRDFRepository();
const css::uno::Reference<css::rdf::XResource> xSubject(rSource, uno::UNO_QUERY);
std::map<OUString, OUString> xStatements
= SwRDFHelper::getStatements(pDocSh->GetBaseModel(), xRepo->getGraphNames(), xSubject);
for (const auto& pair : xStatements)
aCurNode.children.push_back(SimplePropToTreeNode(pair.first, uno::Any(pair.second)));
if (SwDocShell* pDocSh = static_cast<SwDocShell*>(SfxObjectShell::Current()))
{
uno::Reference<rdf::XDocumentMetadataAccess> xDocumentMetadataAccess(pDocSh->GetBaseModel(),
uno::UNO_QUERY);
const uno::Reference<rdf::XRepository>& xRepo = xDocumentMetadataAccess->getRDFRepository();
const css::uno::Reference<css::rdf::XResource> xSubject(rSource, uno::UNO_QUERY);
std::map<OUString, OUString> xStatements
= SwRDFHelper::getStatements(pDocSh->GetBaseModel(), xRepo->getGraphNames(), xSubject);
for (const auto& pair : xStatements)
aCurNode.children.push_back(SimplePropToTreeNode(pair.first, uno::Any(pair.second)));
}
rNode.children.push_back(aCurNode);
}