sc/source/ui/docshell/docsh4.cxx | 259 ++++++++++++++------------- sc/source/ui/inc/docsh.hxx | 3 sc/source/ui/inc/tabvwsh.hxx | 17 + sc/source/ui/view/tabvwsha.cxx | 367 ++++++++++++++++++++++----------------- 4 files changed, 362 insertions(+), 284 deletions(-)
New commits: commit 92ba909fe8d9d1d1237571686e165c0a26def51d Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Jan 29 14:24:37 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Jan 29 17:17:47 2024 +0100 extract SID_CHART_ADDSOURCE code into another method Change-Id: Ia1d4023e636dc26187cebcdfca12c337339f1cca Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162688 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sc/source/ui/docshell/docsh4.cxx b/sc/source/ui/docshell/docsh4.cxx index 34e69724742c..c449a074ac73 100644 --- a/sc/source/ui/docshell/docsh4.cxx +++ b/sc/source/ui/docshell/docsh4.cxx @@ -380,132 +380,7 @@ void ScDocShell::Execute( SfxRequest& rReq ) case SID_CHART_SOURCE: case SID_CHART_ADDSOURCE: - if (pReqArgs) - { - ScDocument& rDoc = GetDocument(); - const SfxPoolItem* pItem; - OUString aChartName, aRangeName; - - ScRange aSingleRange; - ScRangeListRef aRangeListRef; - bool bMultiRange = false; - - bool bColHeaders = true; - bool bRowHeaders = true; - bool bColInit = false; - bool bRowInit = false; - bool bAddRange = (nSlot == SID_CHART_ADDSOURCE); - - if( const SfxStringItem* pChartItem = pReqArgs->GetItemIfSet( SID_CHART_NAME ) ) - aChartName = pChartItem->GetValue(); - - if( const SfxStringItem* pChartItem = pReqArgs->GetItemIfSet( SID_CHART_SOURCE ) ) - aRangeName = pChartItem->GetValue(); - - if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) ) - { - bColHeaders = static_cast<const SfxBoolItem*>(pItem)->GetValue(); - bColInit = true; - } - if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) ) - { - bRowHeaders = static_cast<const SfxBoolItem*>(pItem)->GetValue(); - bRowInit = true; - } - - ScAddress::Details aDetails(rDoc.GetAddressConvention(), 0, 0); - bool bValid = (aSingleRange.ParseAny(aRangeName, rDoc, aDetails) & ScRefFlags::VALID) != ScRefFlags::ZERO; - if (!bValid) - { - aRangeListRef = new ScRangeList; - aRangeListRef->Parse( aRangeName, rDoc, rDoc.GetAddressConvention()); - if ( !aRangeListRef->empty() ) - { - bMultiRange = true; - aSingleRange = aRangeListRef->front(); // for header - bValid = true; - } - else - aRangeListRef.clear(); - } - - ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); - if (pViewSh && bValid && !aChartName.isEmpty() ) - { - weld::Window* pParent = pViewSh->GetFrameWeld(); - - SCCOL nCol1 = aSingleRange.aStart.Col(); - SCROW nRow1 = aSingleRange.aStart.Row(); - SCCOL nCol2 = aSingleRange.aEnd.Col(); - SCROW nRow2 = aSingleRange.aEnd.Row(); - SCTAB nTab = aSingleRange.aStart.Tab(); - - //! limit always or not at all ??? - if (!bMultiRange) - m_pDocument->LimitChartArea( nTab, nCol1,nRow1, nCol2,nRow2 ); - - // Dialog for column/row headers - bool bOk = true; - if ( !bAddRange && ( !bColInit || !bRowInit ) ) - { - ScChartPositioner aChartPositioner( *m_pDocument, nTab, nCol1,nRow1, nCol2,nRow2 ); - if (!bColInit) - bColHeaders = aChartPositioner.HasColHeaders(); - if (!bRowInit) - bRowHeaders = aChartPositioner.HasRowHeaders(); - - ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); - - ScopedVclPtr<AbstractScColRowLabelDlg> pDlg(pFact->CreateScColRowLabelDlg(pParent, bRowHeaders, bColHeaders)); - if ( pDlg->Execute() == RET_OK ) - { - bColHeaders = pDlg->IsRow(); - bRowHeaders = pDlg->IsCol(); - - rReq.AppendItem(SfxBoolItem(FN_PARAM_1, bColHeaders)); - rReq.AppendItem(SfxBoolItem(FN_PARAM_2, bRowHeaders)); - } - else - bOk = false; - } - - if (bOk) // execute - { - if (bMultiRange) - { - if (bUndo) - { - GetUndoManager()->AddUndoAction( - std::make_unique<ScUndoChartData>( this, aChartName, aRangeListRef, - bColHeaders, bRowHeaders, bAddRange ) ); - } - m_pDocument->UpdateChartArea( aChartName, aRangeListRef, - bColHeaders, bRowHeaders, bAddRange ); - } - else - { - ScRange aNewRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab ); - if (bUndo) - { - GetUndoManager()->AddUndoAction( - std::make_unique<ScUndoChartData>( this, aChartName, aNewRange, - bColHeaders, bRowHeaders, bAddRange ) ); - } - m_pDocument->UpdateChartArea( aChartName, aNewRange, - bColHeaders, bRowHeaders, bAddRange ); - } - } - } - else - { - OSL_FAIL("UpdateChartArea: no ViewShell or wrong data"); - } - rReq.Done(); - } - else - { - OSL_FAIL("SID_CHART_SOURCE without arguments"); - } + ExecuteChartSource(rReq); break; case FID_AUTO_CALC: @@ -1470,6 +1345,138 @@ void UpdateAcceptChangesDialog() } } +void ScDocShell::ExecuteChartSource(SfxRequest& rReq) +{ + const SfxItemSet* pReqArgs = rReq.GetArgs(); + sal_uInt16 nSlot = rReq.GetSlot(); + bool bUndo (m_pDocument->IsUndoEnabled()); + if (!pReqArgs) + { + OSL_FAIL("SID_CHART_SOURCE without arguments"); + return; + } + + ScDocument& rDoc = GetDocument(); + const SfxPoolItem* pItem; + OUString aChartName, aRangeName; + + ScRange aSingleRange; + ScRangeListRef aRangeListRef; + bool bMultiRange = false; + + bool bColHeaders = true; + bool bRowHeaders = true; + bool bColInit = false; + bool bRowInit = false; + bool bAddRange = (nSlot == SID_CHART_ADDSOURCE); + + if( const SfxStringItem* pChartItem = pReqArgs->GetItemIfSet( SID_CHART_NAME ) ) + aChartName = pChartItem->GetValue(); + + if( const SfxStringItem* pChartItem = pReqArgs->GetItemIfSet( SID_CHART_SOURCE ) ) + aRangeName = pChartItem->GetValue(); + + if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) ) + { + bColHeaders = static_cast<const SfxBoolItem*>(pItem)->GetValue(); + bColInit = true; + } + if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) ) + { + bRowHeaders = static_cast<const SfxBoolItem*>(pItem)->GetValue(); + bRowInit = true; + } + + ScAddress::Details aDetails(rDoc.GetAddressConvention(), 0, 0); + bool bValid = (aSingleRange.ParseAny(aRangeName, rDoc, aDetails) & ScRefFlags::VALID) != ScRefFlags::ZERO; + if (!bValid) + { + aRangeListRef = new ScRangeList; + aRangeListRef->Parse( aRangeName, rDoc, rDoc.GetAddressConvention()); + if ( !aRangeListRef->empty() ) + { + bMultiRange = true; + aSingleRange = aRangeListRef->front(); // for header + bValid = true; + } + else + aRangeListRef.clear(); + } + + ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell(); + if (!pViewSh || !bValid || aChartName.isEmpty() ) + { + OSL_FAIL("UpdateChartArea: no ViewShell or wrong data"); + rReq.Done(); + return; + } + + weld::Window* pParent = pViewSh->GetFrameWeld(); + + SCCOL nCol1 = aSingleRange.aStart.Col(); + SCROW nRow1 = aSingleRange.aStart.Row(); + SCCOL nCol2 = aSingleRange.aEnd.Col(); + SCROW nRow2 = aSingleRange.aEnd.Row(); + SCTAB nTab = aSingleRange.aStart.Tab(); + + //! limit always or not at all ??? + if (!bMultiRange) + m_pDocument->LimitChartArea( nTab, nCol1,nRow1, nCol2,nRow2 ); + + // Dialog for column/row headers + bool bOk = true; + if ( !bAddRange && ( !bColInit || !bRowInit ) ) + { + ScChartPositioner aChartPositioner( *m_pDocument, nTab, nCol1,nRow1, nCol2,nRow2 ); + if (!bColInit) + bColHeaders = aChartPositioner.HasColHeaders(); + if (!bRowInit) + bRowHeaders = aChartPositioner.HasRowHeaders(); + + ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); + + ScopedVclPtr<AbstractScColRowLabelDlg> pDlg(pFact->CreateScColRowLabelDlg(pParent, bRowHeaders, bColHeaders)); + if ( pDlg->Execute() == RET_OK ) + { + bColHeaders = pDlg->IsRow(); + bRowHeaders = pDlg->IsCol(); + + rReq.AppendItem(SfxBoolItem(FN_PARAM_1, bColHeaders)); + rReq.AppendItem(SfxBoolItem(FN_PARAM_2, bRowHeaders)); + } + else + bOk = false; + } + + if (bOk) // execute + { + if (bMultiRange) + { + if (bUndo) + { + GetUndoManager()->AddUndoAction( + std::make_unique<ScUndoChartData>( this, aChartName, aRangeListRef, + bColHeaders, bRowHeaders, bAddRange ) ); + } + m_pDocument->UpdateChartArea( aChartName, aRangeListRef, + bColHeaders, bRowHeaders, bAddRange ); + } + else + { + ScRange aNewRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab ); + if (bUndo) + { + GetUndoManager()->AddUndoAction( + std::make_unique<ScUndoChartData>( this, aChartName, aNewRange, + bColHeaders, bRowHeaders, bAddRange ) ); + } + m_pDocument->UpdateChartArea( aChartName, aNewRange, + bColHeaders, bRowHeaders, bAddRange ); + } + } + rReq.Done(); +} + bool ScDocShell::ExecuteChangeProtectionDialog( bool bJustQueryIfProtected ) { bool bDone = false; diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx index dc4c32d61d80..744108a80002 100644 --- a/sc/source/ui/inc/docsh.hxx +++ b/sc/source/ui/inc/docsh.hxx @@ -433,6 +433,9 @@ public: void RegisterAutomationWorkbookObject(css::uno::Reference< ooo::vba::excel::XWorkbook > const& xWorkbook); ScModelObj* GetModel() const { return static_cast<ScModelObj*>(SfxObjectShell::GetModel().get()); } + +private: + void ExecuteChartSource(SfxRequest& rReq); }; void UpdateAcceptChangesDialog(); commit 93939460ee79586a6c6d3f9c32f6c893146f7abd Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Jan 24 15:11:31 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Mon Jan 29 17:17:37 2024 +0100 make calc style dialog async Change-Id: I2e4bd1e88f5b6dc155d02db234d846e3f1dfd8c8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162513 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx index 7e7a79142ea0..2a7f83c602fd 100644 --- a/sc/source/ui/inc/tabvwsh.hxx +++ b/sc/source/ui/inc/tabvwsh.hxx @@ -37,6 +37,7 @@ #include <map> class SdrOle2Obj; +class SfxAbstractTabDialog; class SfxBindings; class SfxChildWindow; class SvxNumberInfoItem; @@ -45,6 +46,7 @@ class AbstractScInsertTableDlg; class AbstractScMoveTableDlg; class AbstractScTabBgColorDlg; class AbstractScStringInputDlg; +class ScStyleSaveData; class ScArea; class ScAuditingShell; class ScDrawShell; @@ -466,6 +468,21 @@ private: void ExecuteSetTableBackgroundCol( SfxRequest& rReq ); void ExecuteTableBackgroundDialog( const VclPtr<AbstractScTabBgColorDlg>& pDlg, const std::shared_ptr<SfxRequest>& xReq, Color aOldTabBgColor, sal_uInt16 nSlot ); bool DoTableBackgroundDialog( sal_Int32 nResult, const VclPtr<AbstractScTabBgColorDlg>& pDlg, const std::shared_ptr<SfxRequest>& xReq, Color aOldTabBgColor, sal_uInt16 nSlot ); + void ExecuteStyleEdit(SfxRequest& rReq, SfxStyleSheetBase* pStyleSheet, sal_uInt16 nRetMask, sal_uInt16 nSlotId, + bool bAddUndo, bool bUndo, + ScStyleSaveData& rOldData, ScStyleSaveData& rNewData, + SfxStyleFamily eFamily, bool bStyleToMarked, bool bListAction, + SdrObject* pEditObject, ESelection aSelection); + void ExecuteStyleEditDialog(VclPtr<SfxAbstractTabDialog> pDlg, + SfxStyleSheetBase* pStyleSheet, sal_uInt16 nResult, sal_uInt16& rnRetMask, + std::shared_ptr<SfxItemSet> xOldSet, sal_uInt16 nSlotId, + bool& rbAddUndo, + ScStyleSaveData& rNewData, std::u16string_view aOldName); + void ExecuteStyleEditPost(SfxRequest& rReq, SfxStyleSheetBase* pStyleSheet, sal_uInt16 nSlotId, + sal_uInt16 nRetMask, bool bAddUndo, bool bUndo, SfxStyleFamily eFamily, + ScStyleSaveData& rOldData, ScStyleSaveData& rNewData, + bool bStyleToMarked, bool bListAction, + SdrObject* pEditObject, ESelection aSelection); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx index 52b815e34e16..df7233dcd288 100644 --- a/sc/source/ui/view/tabvwsha.cxx +++ b/sc/source/ui/view/tabvwsha.cxx @@ -1481,201 +1481,252 @@ void ScTabViewShell::ExecStyle( SfxRequest& rReq ) // create new or process through Dialog: if ( nSlotId == SID_STYLE_NEW || nSlotId == SID_STYLE_EDIT ) { - if ( pStyleSheet ) + if (pStyleSheet) { - SfxStyleFamily eFam = pStyleSheet->GetFamily(); - ScopedVclPtr<SfxAbstractTabDialog> pDlg; - bool bPage = false; - - // Store old Items from the style - SfxItemSet aOldSet = pStyleSheet->GetItemSet(); - OUString aOldName = pStyleSheet->GetName(); + ExecuteStyleEdit(rReq, pStyleSheet, nRetMask, nSlotId, bAddUndo, bUndo, + aOldData, aNewData, eFamily, bStyleToMarked, bListAction, pEditObject, aSelection); + return; // skip calling ExecuteStyleEditPost because we invoked an async dialog + } + } - switch ( eFam ) - { - case SfxStyleFamily::Page: - bPage = true; - break; + ExecuteStyleEditPost(rReq, pStyleSheet, nSlotId, nRetMask, bAddUndo, bUndo, + eFamily, aOldData, aNewData, bStyleToMarked, bListAction, pEditObject, aSelection); +} - case SfxStyleFamily::Para: - { - SfxItemSet& rSet = pStyleSheet->GetItemSet(); +void ScTabViewShell::ExecuteStyleEdit(SfxRequest& rReq, SfxStyleSheetBase* pStyleSheet, sal_uInt16 nRetMask, + sal_uInt16 nSlotId, bool bAddUndo, bool bUndo, + ScStyleSaveData& rOldData, ScStyleSaveData& rNewData, SfxStyleFamily eFamily, + bool bStyleToMarked, bool bListAction, + SdrObject* pEditObject, ESelection aSelection) +{ + ScDocShell* pDocSh = GetViewData().GetDocShell(); + ScDocument& rDoc = pDocSh->GetDocument(); + SfxStyleFamily eFam = pStyleSheet->GetFamily(); + VclPtr<SfxAbstractTabDialog> pDlg; + bool bPage = false; - if ( const SfxUInt32Item* pItem = rSet.GetItemIfSet( ATTR_VALUE_FORMAT, - false ) ) - { - // Produce and format NumberFormat Value from Value and Language - sal_uLong nFormat = pItem->GetValue(); - LanguageType eLang = - rSet.Get(ATTR_LANGUAGE_FORMAT ).GetLanguage(); - sal_uLong nLangFormat = rDoc.GetFormatTable()-> - GetFormatForLanguageIfBuiltIn( nFormat, eLang ); - if ( nLangFormat != nFormat ) - { - SfxUInt32Item aNewItem( ATTR_VALUE_FORMAT, nLangFormat ); - rSet.Put( aNewItem ); - aOldSet.Put( aNewItem ); - // Also in aOldSet for comparison after the dialog, - // Otherwise might miss a language change - } - } + // Store old Items from the style + std::shared_ptr<SfxItemSet> xOldSet = std::make_shared<SfxItemSet>(pStyleSheet->GetItemSet()); + OUString aOldName = pStyleSheet->GetName(); - std::unique_ptr<SvxNumberInfoItem> pNumberInfoItem( - ScTabViewShell::MakeNumberInfoItem(rDoc, GetViewData())); + switch ( eFam ) + { + case SfxStyleFamily::Page: + bPage = true; + break; - pDocSh->PutItem( *pNumberInfoItem ); - bPage = false; + case SfxStyleFamily::Para: + { + SfxItemSet& rSet = pStyleSheet->GetItemSet(); - // Definitely a SvxBoxInfoItem with Table = sal_False in set: - // (If there is no item, the dialogue will also delete the - // BORDER_OUTER SvxBoxItem from the Template Set) - if ( rSet.GetItemState( ATTR_BORDER_INNER, false ) != SfxItemState::SET ) - { - SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER ); - aBoxInfoItem.SetTable(false); // no inner lines - aBoxInfoItem.SetDist(true); - aBoxInfoItem.SetMinDist(false); - rSet.Put( aBoxInfoItem ); - } + if ( const SfxUInt32Item* pItem = rSet.GetItemIfSet( ATTR_VALUE_FORMAT, + false ) ) + { + // Produce and format NumberFormat Value from Value and Language + sal_uLong nFormat = pItem->GetValue(); + LanguageType eLang = + rSet.Get(ATTR_LANGUAGE_FORMAT ).GetLanguage(); + sal_uLong nLangFormat = rDoc.GetFormatTable()-> + GetFormatForLanguageIfBuiltIn( nFormat, eLang ); + if ( nLangFormat != nFormat ) + { + SfxUInt32Item aNewItem( ATTR_VALUE_FORMAT, nLangFormat ); + rSet.Put( aNewItem ); + xOldSet->Put( aNewItem ); + // Also in aOldSet for comparison after the dialog, + // Otherwise might miss a language change } - break; - - case SfxStyleFamily::Frame: - default: - break; - } - - SetInFormatDialog(true); - - SfxItemSet& rStyleSet = pStyleSheet->GetItemSet(); - rStyleSet.MergeRange( XATTR_FILL_FIRST, XATTR_FILL_LAST ); - - ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); + } - weld::Window* pDialogParent = rReq.GetFrameWeld(); - if (!pDialogParent) - pDialogParent = GetFrameWeld(); + std::unique_ptr<SvxNumberInfoItem> pNumberInfoItem( + ScTabViewShell::MakeNumberInfoItem(rDoc, GetViewData())); - if (eFam == SfxStyleFamily::Frame) - pDlg.disposeAndReset(pFact->CreateScDrawStyleDlg(pDialogParent, *pStyleSheet, GetDrawView())); - else - pDlg.disposeAndReset(pFact->CreateScStyleDlg(pDialogParent, *pStyleSheet, bPage)); + pDocSh->PutItem( *pNumberInfoItem ); + bPage = false; - short nResult = pDlg->Execute(); - SetInFormatDialog(false); - - if ( nResult == RET_OK ) - { - const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); - - if ( pOutSet ) + // Definitely a SvxBoxInfoItem with Table = sal_False in set: + // (If there is no item, the dialogue will also delete the + // BORDER_OUTER SvxBoxItem from the Template Set) + if ( rSet.GetItemState( ATTR_BORDER_INNER, false ) != SfxItemState::SET ) { - nRetMask = sal_uInt16(pStyleSheet->GetMask()); - - // Attribute comparisons (earlier in ModifyStyleSheet) now here - // with the old values (the style is already changed) - if ( SfxStyleFamily::Para == eFam ) - { - SfxItemSet& rNewSet = pStyleSheet->GetItemSet(); - bool bNumFormatChanged; - if ( ScGlobal::CheckWidthInvalidate( - bNumFormatChanged, rNewSet, aOldSet ) ) - rDoc.InvalidateTextWidth( nullptr, nullptr, bNumFormatChanged ); + SvxBoxInfoItem aBoxInfoItem( ATTR_BORDER_INNER ); + aBoxInfoItem.SetTable(false); // no inner lines + aBoxInfoItem.SetDist(true); + aBoxInfoItem.SetMinDist(false); + rSet.Put( aBoxInfoItem ); + } + } + break; - SCTAB nTabCount = rDoc.GetTableCount(); - for (SCTAB nTab=0; nTab<nTabCount; nTab++) - rDoc.SetStreamValid(nTab, false); + case SfxStyleFamily::Frame: + default: + break; + } - sal_uLong nOldFormat = aOldSet.Get( ATTR_VALUE_FORMAT ).GetValue(); - sal_uLong nNewFormat = rNewSet.Get( ATTR_VALUE_FORMAT ).GetValue(); - if ( nNewFormat != nOldFormat ) - { - SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); - const SvNumberformat* pOld = pFormatter->GetEntry( nOldFormat ); - const SvNumberformat* pNew = pFormatter->GetEntry( nNewFormat ); - if ( pOld && pNew && pOld->GetLanguage() != pNew->GetLanguage() ) - rNewSet.Put( SvxLanguageItem( - pNew->GetLanguage(), ATTR_LANGUAGE_FORMAT ) ); - } + SetInFormatDialog(true); - rDoc.getCellAttributeHelper().CellStyleCreated(rDoc, pStyleSheet->GetName()); - } - else if ( SfxStyleFamily::Page == eFam ) - { - //! Here also queries for Page Styles + SfxItemSet& rStyleSet = pStyleSheet->GetItemSet(); + rStyleSet.MergeRange( XATTR_FILL_FIRST, XATTR_FILL_LAST ); - OUString aNewName = pStyleSheet->GetName(); - if ( aNewName != aOldName && - rDoc.RenamePageStyleInUse( aOldName, aNewName ) ) - { - rBindings.Invalidate( SID_STATUS_PAGESTYLE ); - rBindings.Invalidate( FID_RESET_PRINTZOOM ); - } + ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); - rDoc.ModifyStyleSheet( *pStyleSheet, *pOutSet ); - rBindings.Invalidate( FID_RESET_PRINTZOOM ); - } - else - { - SfxItemSet& rAttr = pStyleSheet->GetItemSet(); - sdr::properties::CleanupFillProperties(rAttr); + weld::Window* pDialogParent = rReq.GetFrameWeld(); + if (!pDialogParent) + pDialogParent = GetFrameWeld(); - // check for unique names of named items for xml - auto checkForUniqueItem = [&] (auto nWhichId) - { - if (auto pOldItem = rAttr.GetItemIfSet(nWhichId, false)) - { - if (auto pNewItem = pOldItem->checkForUniqueItem(&GetDrawView()->GetModel())) - rAttr.Put(std::move(pNewItem)); - } - }; + if (eFam == SfxStyleFamily::Frame) + pDlg = pFact->CreateScDrawStyleDlg(pDialogParent, *pStyleSheet, GetDrawView()); + else + pDlg = pFact->CreateScStyleDlg(pDialogParent, *pStyleSheet, bPage); - checkForUniqueItem(XATTR_FILLBITMAP); - checkForUniqueItem(XATTR_LINEDASH); - checkForUniqueItem(XATTR_LINESTART); - checkForUniqueItem(XATTR_LINEEND); - checkForUniqueItem(XATTR_FILLGRADIENT); - checkForUniqueItem(XATTR_FILLFLOATTRANSPARENCE); - checkForUniqueItem(XATTR_FILLHATCH); + auto xRequest = std::make_shared<SfxRequest>(rReq); + rReq.Ignore(); // the 'old' request is not relevant any more + pDlg->StartExecuteAsync( + [this, pDlg, xRequest, pStyleSheet, nRetMask, xOldSet, nSlotId, bAddUndo, bUndo, + aOldData=rOldData, aNewData=rNewData, aOldName, eFamily, bStyleToMarked, bListAction, + pEditObject, aSelection] + (sal_Int32 nResult) mutable -> void + { + SetInFormatDialog(false); + ExecuteStyleEditDialog(pDlg, pStyleSheet, nResult, nRetMask, xOldSet, nSlotId, + bAddUndo, aNewData, aOldName); + pDlg->disposeOnce(); + ExecuteStyleEditPost(*xRequest, pStyleSheet, nSlotId, nRetMask, bAddUndo, bUndo, eFamily, + aOldData, aNewData, bStyleToMarked, bListAction, pEditObject, aSelection); + } + ); +} - static_cast<SfxStyleSheet*>(pStyleSheet)->Broadcast(SfxHint(SfxHintId::DataChanged)); - GetScDrawView()->InvalidateAttribs(); - } +void ScTabViewShell::ExecuteStyleEditDialog(VclPtr<SfxAbstractTabDialog> pDlg, + SfxStyleSheetBase* pStyleSheet, sal_uInt16 nResult, + sal_uInt16& rnRetMask, std::shared_ptr<SfxItemSet> xOldSet, const sal_uInt16 nSlotId, + bool& rbAddUndo, ScStyleSaveData& rNewData, std::u16string_view aOldName) +{ + ScDocShell* pDocSh = GetViewData().GetDocShell(); + ScDocument& rDoc = pDocSh->GetDocument(); + SfxBindings& rBindings = GetViewData().GetBindings(); + SfxStyleSheetBasePool* pStylePool = rDoc.GetStyleSheetPool(); + SfxStyleFamily eFam = pStyleSheet->GetFamily(); + if ( nResult == RET_OK ) + { + const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); - pDocSh->SetDocumentModified(); + if ( pOutSet ) + { + rnRetMask = sal_uInt16(pStyleSheet->GetMask()); - if ( SfxStyleFamily::Para == eFam ) - { - ScTabViewShell::UpdateNumberFormatter( - *( pDocSh->GetItem(SID_ATTR_NUMBERFORMAT_INFO) )); + // Attribute comparisons (earlier in ModifyStyleSheet) now here + // with the old values (the style is already changed) + if ( SfxStyleFamily::Para == eFam ) + { + SfxItemSet& rNewSet = pStyleSheet->GetItemSet(); + bool bNumFormatChanged; + if ( ScGlobal::CheckWidthInvalidate( + bNumFormatChanged, rNewSet, *xOldSet ) ) + rDoc.InvalidateTextWidth( nullptr, nullptr, bNumFormatChanged ); + + SCTAB nTabCount = rDoc.GetTableCount(); + for (SCTAB nTab=0; nTab<nTabCount; nTab++) + rDoc.SetStreamValid(nTab, false); + + sal_uLong nOldFormat = xOldSet->Get( ATTR_VALUE_FORMAT ).GetValue(); + sal_uLong nNewFormat = rNewSet.Get( ATTR_VALUE_FORMAT ).GetValue(); + if ( nNewFormat != nOldFormat ) + { + SvNumberFormatter* pFormatter = rDoc.GetFormatTable(); + const SvNumberformat* pOld = pFormatter->GetEntry( nOldFormat ); + const SvNumberformat* pNew = pFormatter->GetEntry( nNewFormat ); + if ( pOld && pNew && pOld->GetLanguage() != pNew->GetLanguage() ) + rNewSet.Put( SvxLanguageItem( + pNew->GetLanguage(), ATTR_LANGUAGE_FORMAT ) ); + } - UpdateStyleSheetInUse( pStyleSheet ); - InvalidateAttribs(); - } + rDoc.getCellAttributeHelper().CellStyleCreated(rDoc, pStyleSheet->GetName()); + } + else if ( SfxStyleFamily::Page == eFam ) + { + //! Here also queries for Page Styles - aNewData.InitFromStyle( pStyleSheet ); - bAddUndo = true; + OUString aNewName = pStyleSheet->GetName(); + if ( aNewName != aOldName && + rDoc.RenamePageStyleInUse( aOldName, aNewName ) ) + { + rBindings.Invalidate( SID_STATUS_PAGESTYLE ); + rBindings.Invalidate( FID_RESET_PRINTZOOM ); } + + rDoc.ModifyStyleSheet( *pStyleSheet, *pOutSet ); + rBindings.Invalidate( FID_RESET_PRINTZOOM ); } else { - if ( nSlotId == SID_STYLE_NEW ) - pStylePool->Remove( pStyleSheet ); - else + SfxItemSet& rAttr = pStyleSheet->GetItemSet(); + sdr::properties::CleanupFillProperties(rAttr); + + // check for unique names of named items for xml + auto checkForUniqueItem = [&] (auto nWhichId) { - // If in the meantime something was painted with the - // temporary changed item set - pDocSh->PostPaintGridAll(); - } + if (auto pOldItem = rAttr.GetItemIfSet(nWhichId, false)) + { + if (auto pNewItem = pOldItem->checkForUniqueItem(&GetDrawView()->GetModel())) + rAttr.Put(std::move(pNewItem)); + } + }; + + checkForUniqueItem(XATTR_FILLBITMAP); + checkForUniqueItem(XATTR_LINEDASH); + checkForUniqueItem(XATTR_LINESTART); + checkForUniqueItem(XATTR_LINEEND); + checkForUniqueItem(XATTR_FILLGRADIENT); + checkForUniqueItem(XATTR_FILLFLOATTRANSPARENCE); + checkForUniqueItem(XATTR_FILLHATCH); + + static_cast<SfxStyleSheet*>(pStyleSheet)->Broadcast(SfxHint(SfxHintId::DataChanged)); + GetScDrawView()->InvalidateAttribs(); + } + + pDocSh->SetDocumentModified(); + + if ( SfxStyleFamily::Para == eFam ) + { + ScTabViewShell::UpdateNumberFormatter( + *( pDocSh->GetItem(SID_ATTR_NUMBERFORMAT_INFO) )); + + UpdateStyleSheetInUse( pStyleSheet ); + InvalidateAttribs(); } + + rNewData.InitFromStyle( pStyleSheet ); + rbAddUndo = true; } } + else + { + if ( nSlotId == SID_STYLE_NEW ) + pStylePool->Remove( pStyleSheet ); + else + { + // If in the meantime something was painted with the + // temporary changed item set + pDocSh->PostPaintGridAll(); + } + } +} + +void ScTabViewShell::ExecuteStyleEditPost(SfxRequest& rReq, SfxStyleSheetBase* pStyleSheet, + sal_uInt16 nSlotId, sal_uInt16 nRetMask, bool bAddUndo, bool bUndo, + const SfxStyleFamily eFamily, + ScStyleSaveData& rOldData, ScStyleSaveData& rNewData, + bool bStyleToMarked, bool bListAction, + SdrObject* pEditObject, ESelection aSelection) +{ + ScDocShell* pDocSh = GetViewData().GetDocShell(); rReq.SetReturnValue( SfxUInt16Item( nSlotId, nRetMask ) ); if ( bAddUndo && bUndo) pDocSh->GetUndoManager()->AddUndoAction( - std::make_unique<ScUndoModifyStyle>( pDocSh, eFamily, aOldData, aNewData ) ); + std::make_unique<ScUndoModifyStyle>( pDocSh, eFamily, rOldData, rNewData ) ); if ( bStyleToMarked ) {