diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2023-03-17 11:09:49 +0200 |
---|---|---|
committer | Maxim Monastirsky <momonasmon@gmail.com> | 2023-03-17 14:34:04 +0000 |
commit | 796c9c5ac2196e62546bcef229dcd08a3b8724db (patch) | |
tree | 017d19598153c5d86d82f73139451138c2591dff | |
parent | 34f7c8cce9c16861940f403f9a633fe8b26ba4ad (diff) |
sc drawstyles: Move style commands to ScTabViewShell
For them to be available also when shapes are selected.
This commit alone shouldn't cause any change in behavior.
Change-Id: Ic038618fe8b450ef2c93a19efb2e27c41f6de0f4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149047
Tested-by: Jenkins
Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com>
-rw-r--r-- | sc/sdi/formatsh.sdi | 11 | ||||
-rw-r--r-- | sc/sdi/tabvwsh.sdi | 12 | ||||
-rw-r--r-- | sc/source/ui/inc/formatsh.hxx | 1 | ||||
-rw-r--r-- | sc/source/ui/inc/tabvwsh.hxx | 3 | ||||
-rw-r--r-- | sc/source/ui/view/formatsh.cxx | 726 | ||||
-rw-r--r-- | sc/source/ui/view/tabvwsha.cxx | 723 |
6 files changed, 738 insertions, 738 deletions
diff --git a/sc/sdi/formatsh.sdi b/sc/sdi/formatsh.sdi index 4e566eb5069e..3cb4c050feaa 100644 --- a/sc/sdi/formatsh.sdi +++ b/sc/sdi/formatsh.sdi @@ -39,17 +39,6 @@ interface TableFont interface FormatForSelection { // slots which are disabled in the DrawShell {{ - SID_STYLE_FAMILY2 [ ExecMethod = ExecuteStyle; StateMethod = GetStyleState; ] - SID_STYLE_APPLY [ ExecMethod = ExecuteStyle; StateMethod = GetStyleState; ] - SID_STYLE_WATERCAN [ ExecMethod = ExecuteStyle; StateMethod = GetStyleState; ] - SID_STYLE_NEW_BY_EXAMPLE [ ExecMethod = ExecuteStyle; StateMethod = GetStyleState; ] - SID_STYLE_UPDATE_BY_EXAMPLE [ ExecMethod = ExecuteStyle; StateMethod = GetStyleState; ] - SID_STYLE_NEW [ ExecMethod = ExecuteStyle; StateMethod = GetStyleState; ] - SID_STYLE_FAMILY4 [ ExecMethod = ExecuteStyle; StateMethod = GetStyleState; ] - SID_STYLE_EDIT [ ExecMethod = ExecuteStyle; StateMethod = GetStyleState; ] - SID_STYLE_DELETE [ ExecMethod = ExecuteStyle; StateMethod = GetStyleState; ] - SID_STYLE_HIDE [ ExecMethod = ExecuteStyle; StateMethod = GetStyleState; ] - SID_STYLE_SHOW [ ExecMethod = ExecuteStyle; StateMethod = GetStyleState; ] SID_STYLE_PREVIEW [ ExecMethod = ExecuteStyle; ] SID_STYLE_END_PREVIEW [ ExecMethod = ExecuteStyle; ] SID_CLASSIFICATION_APPLY [ ExecMethod = ExecuteStyle; ] diff --git a/sc/sdi/tabvwsh.sdi b/sc/sdi/tabvwsh.sdi index 50049bad7abc..5938317eb8aa 100644 --- a/sc/sdi/tabvwsh.sdi +++ b/sc/sdi/tabvwsh.sdi @@ -205,6 +205,18 @@ interface TableEditView SID_GRID_USE [ ExecMethod = ExecDrawOpt; StateMethod = GetDrawOptState; ] SID_HELPLINES_MOVE [ ExecMethod = ExecDrawOpt; StateMethod = GetDrawOptState; ] + SID_STYLE_FAMILY2 [ ExecMethod = ExecStyle; StateMethod = GetStyleState; ] + SID_STYLE_FAMILY4 [ ExecMethod = ExecStyle; StateMethod = GetStyleState; ] + SID_STYLE_APPLY [ ExecMethod = ExecStyle; StateMethod = GetStyleState; ] + SID_STYLE_WATERCAN [ ExecMethod = ExecStyle; StateMethod = GetStyleState; ] + SID_STYLE_NEW_BY_EXAMPLE [ ExecMethod = ExecStyle; StateMethod = GetStyleState; ] + SID_STYLE_UPDATE_BY_EXAMPLE [ ExecMethod = ExecStyle; StateMethod = GetStyleState; ] + SID_STYLE_NEW [ ExecMethod = ExecStyle; StateMethod = GetStyleState; ] + SID_STYLE_EDIT [ ExecMethod = ExecStyle; StateMethod = GetStyleState; ] + SID_STYLE_DELETE [ ExecMethod = ExecStyle; StateMethod = GetStyleState; ] + SID_STYLE_HIDE [ ExecMethod = ExecStyle; StateMethod = GetStyleState; ] + SID_STYLE_SHOW [ ExecMethod = ExecStyle; StateMethod = GetStyleState; ] + SID_GETUNDOSTRINGS [ StateMethod = GetUndoState; ] SID_GETREDOSTRINGS [ StateMethod = GetUndoState; ] SID_UNDO [ ExecMethod = ExecuteUndo; StateMethod = GetUndoState; ] diff --git a/sc/source/ui/inc/formatsh.hxx b/sc/source/ui/inc/formatsh.hxx index 193c98e04b4e..85819b1ac50f 100644 --- a/sc/source/ui/inc/formatsh.hxx +++ b/sc/source/ui/inc/formatsh.hxx @@ -60,7 +60,6 @@ public: void GetBorderState( SfxItemSet& rSet ); void ExecuteStyle( SfxRequest& rReq ); - void GetStyleState( SfxItemSet& rSet ); void ExecuteTextDirection( const SfxRequest& rReq ); void GetTextDirectionState( SfxItemSet& rSet ); diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx index 31709a47c16a..e87b6355198c 100644 --- a/sc/source/ui/inc/tabvwsh.hxx +++ b/sc/source/ui/inc/tabvwsh.hxx @@ -277,6 +277,9 @@ public: void ExecDrawOpt(const SfxRequest& rReq); void GetDrawOptState(SfxItemSet &rSet); + void ExecStyle(SfxRequest& rReq); + void GetStyleState(SfxItemSet &rSet); + void UpdateDrawShell(); void SetDrawShell( bool bActive ); void SetDrawTextShell( bool bActive ); diff --git a/sc/source/ui/view/formatsh.cxx b/sc/source/ui/view/formatsh.cxx index 6bcd7119ecb7..b02c79a02957 100644 --- a/sc/source/ui/view/formatsh.cxx +++ b/sc/source/ui/view/formatsh.cxx @@ -26,7 +26,6 @@ #include <sfx2/viewfrm.hxx> #include <sfx2/bindings.hxx> -#include <sfx2/newstyle.hxx> #include <sfx2/objface.hxx> #include <sfx2/request.hxx> #include <sfx2/sfxdlg.hxx> @@ -41,8 +40,6 @@ #include <editeng/boxitem.hxx> #include <editeng/langitem.hxx> #include <svx/numinf.hxx> -#include <sfx2/dispatch.hxx> -#include <sfx2/tplpitem.hxx> #include <editeng/svxenum.hxx> #include <editeng/wghtitem.hxx> #include <editeng/postitem.hxx> @@ -71,8 +68,6 @@ #include <printfun.hxx> #include <docpool.hxx> #include <tabvwsh.hxx> -#include <undostyl.hxx> -#include <markdata.hxx> #include <attrib.hxx> #define ShellClass_ScFormatShell @@ -80,7 +75,6 @@ #define ShellClass_FormatForSelection #include <scslots.hxx> -#include <scabstdlg.hxx> #include <editeng/fontitem.hxx> #include <sfx2/classificationhelper.hxx> @@ -151,121 +145,14 @@ ScFormatShell::~ScFormatShell() { } -void ScFormatShell::GetStyleState( SfxItemSet& rSet ) -{ - ScDocument& rDoc = GetViewData().GetDocument(); - ScTabViewShell* pTabViewShell = GetViewData().GetViewShell(); - SfxStyleSheetBasePool* pStylePool = rDoc.GetStyleSheetPool(); - - bool bProtected = false; - SCTAB nTabCount = rDoc.GetTableCount(); - for (SCTAB i=0; i<nTabCount && !bProtected; i++) - if (rDoc.IsTabProtected(i)) // look after protected table - bProtected = true; - - SfxWhichIter aIter(rSet); - sal_uInt16 nWhich = aIter.FirstWhich(); - sal_uInt16 nSlotId = 0; - - while ( nWhich ) - { - nSlotId = SfxItemPool::IsWhich( nWhich ) - ? GetPool().GetSlotId( nWhich ) - : nWhich; - - switch ( nSlotId ) - { - case SID_STYLE_APPLY: - if ( !pStylePool ) - rSet.DisableItem( nSlotId ); - break; - - case SID_STYLE_FAMILY2: // cell style sheets - { - SfxStyleSheet* pStyleSheet = const_cast<SfxStyleSheet*>( - pTabViewShell->GetStyleSheetFromMarked()); - - if ( pStyleSheet ) - rSet.Put( SfxTemplateItem( nSlotId, pStyleSheet->GetName() ) ); - else - rSet.Put( SfxTemplateItem( nSlotId, OUString() ) ); - } - break; - - case SID_STYLE_FAMILY4: // page style sheets - { - SCTAB nCurTab = GetViewData().GetTabNo(); - OUString aPageStyle = rDoc.GetPageStyle( nCurTab ); - SfxStyleSheet* pStyleSheet = pStylePool ? static_cast<SfxStyleSheet*>(pStylePool-> - Find( aPageStyle, SfxStyleFamily::Page )) : nullptr; - - if ( pStyleSheet ) - rSet.Put( SfxTemplateItem( nSlotId, aPageStyle ) ); - else - rSet.Put( SfxTemplateItem( nSlotId, OUString() ) ); - } - break; - - case SID_STYLE_WATERCAN: - { - rSet.Put( SfxBoolItem( nSlotId, SC_MOD()->GetIsWaterCan() ) ); - } - break; - - case SID_STYLE_UPDATE_BY_EXAMPLE: - { - std::unique_ptr<SfxUInt16Item> pFamilyItem; - pTabViewShell->GetViewFrame().GetBindings().QueryState(SID_STYLE_FAMILY, pFamilyItem); - - bool bPage = pFamilyItem && SfxStyleFamily::Page == static_cast<SfxStyleFamily>(pFamilyItem->GetValue()); - - if ( bProtected || bPage ) - rSet.DisableItem( nSlotId ); - } - break; - - case SID_STYLE_EDIT: - case SID_STYLE_DELETE: - case SID_STYLE_HIDE: - case SID_STYLE_SHOW: - { - std::unique_ptr<SfxUInt16Item> pFamilyItem; - pTabViewShell->GetViewFrame().GetBindings().QueryState(SID_STYLE_FAMILY, pFamilyItem); - bool bPage = pFamilyItem && SfxStyleFamily::Page == static_cast<SfxStyleFamily>(pFamilyItem->GetValue()); - - if ( bProtected && !bPage ) - rSet.DisableItem( nSlotId ); - } - break; - - default: - break; - } - - nWhich = aIter.NextWhich(); - } -} - void ScFormatShell::ExecuteStyle( SfxRequest& rReq ) { const SfxItemSet* pArgs = rReq.GetArgs(); const sal_uInt16 nSlotId = rReq.GetSlot(); - if ( !pArgs && nSlotId != SID_STYLE_NEW_BY_EXAMPLE && nSlotId != SID_STYLE_UPDATE_BY_EXAMPLE ) - { - // in case of vertical toolbar - rViewData.GetDispatcher().Execute( SID_STYLE_DESIGNER, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD ); - return; - } - SfxBindings& rBindings = rViewData.GetBindings(); - const SCTAB nCurTab = GetViewData().GetTabNo(); ScDocShell* pDocSh = GetViewData().GetDocShell(); ScTabViewShell* pTabViewShell= GetViewData().GetViewShell(); ScDocument& rDoc = pDocSh->GetDocument(); - ScMarkData& rMark = GetViewData().GetMarkData(); - ScModule* pScMod = SC_MOD(); - OUString aRefName; - bool bUndo = rDoc.IsUndoEnabled(); SfxStyleSheetBasePool* pStylePool = rDoc.GetStyleSheetPool(); if ( (nSlotId == SID_STYLE_PREVIEW) @@ -334,619 +221,6 @@ void ScFormatShell::ExecuteStyle( SfxRequest& rReq ) } } } - else if ( (nSlotId == SID_STYLE_NEW) - || (nSlotId == SID_STYLE_EDIT) - || (nSlotId == SID_STYLE_DELETE) - || (nSlotId == SID_STYLE_HIDE) - || (nSlotId == SID_STYLE_SHOW) - || (nSlotId == SID_STYLE_APPLY) - || (nSlotId == SID_STYLE_WATERCAN) - || (nSlotId == SID_STYLE_FAMILY) - || (nSlotId == SID_STYLE_NEW_BY_EXAMPLE) - || (nSlotId == SID_STYLE_UPDATE_BY_EXAMPLE) ) - { - SfxStyleSheetBase* pStyleSheet = nullptr; - - bool bStyleToMarked = false; - bool bListAction = false; - bool bAddUndo = false; // add ScUndoModifyStyle (style modified) - ScStyleSaveData aOldData; // for undo/redo - ScStyleSaveData aNewData; - - SfxStyleFamily eFamily = SfxStyleFamily::Para; - const SfxUInt16Item* pFamItem; - const SfxStringItem* pFamilyNameItem; - if ( pArgs && (pFamItem = pArgs->GetItemIfSet( SID_STYLE_FAMILY )) ) - eFamily = static_cast<SfxStyleFamily>(pFamItem->GetValue()); - else if ( pArgs && (pFamilyNameItem = pArgs->GetItemIfSet( SID_STYLE_FAMILYNAME )) ) - { - OUString sFamily = pFamilyNameItem->GetValue(); - if (sFamily == "CellStyles") - eFamily = SfxStyleFamily::Para; - else if (sFamily == "PageStyles") - eFamily = SfxStyleFamily::Page; - } - - OUString aStyleName; - sal_uInt16 nRetMask = 0xffff; - - switch ( nSlotId ) - { - case SID_STYLE_NEW: - { - const SfxPoolItem* pNameItem; - if (pArgs && SfxItemState::SET == pArgs->GetItemState( nSlotId, true, &pNameItem )) - aStyleName = static_cast<const SfxStringItem*>(pNameItem)->GetValue(); - - const SfxStringItem* pRefItem=nullptr; - if (pArgs && (pRefItem = pArgs->GetItemIfSet( SID_STYLE_REFERENCE ))) - { - aRefName = pRefItem->GetValue(); - } - - pStyleSheet = &(pStylePool->Make( aStyleName, eFamily, - SfxStyleSearchBits::UserDefined ) ); - - if (pStyleSheet->HasParentSupport()) - pStyleSheet->SetParent(aRefName); - } - break; - - case SID_STYLE_APPLY: - { - const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(SID_APPLY_STYLE); - const SfxStringItem* pFamilyItem = rReq.GetArg<SfxStringItem>(SID_STYLE_FAMILYNAME); - if ( pFamilyItem && pNameItem ) - { - try - { - css::uno::Reference< css::container::XNameAccess > xStyles; - css::uno::Reference< css::container::XNameAccess > xCont = pDocSh->GetModel()->getStyleFamilies(); - xCont->getByName(pFamilyItem->GetValue()) >>= xStyles; - css::uno::Reference< css::beans::XPropertySet > xInfo; - xStyles->getByName( pNameItem->GetValue() ) >>= xInfo; - OUString aUIName; - xInfo->getPropertyValue("DisplayName") >>= aUIName; - if ( !aUIName.isEmpty() ) - rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aUIName ) ); - } - catch( css::uno::Exception& ) - { - } - } - [[fallthrough]]; - } - case SID_STYLE_EDIT: - case SID_STYLE_DELETE: - case SID_STYLE_HIDE: - case SID_STYLE_SHOW: - case SID_STYLE_NEW_BY_EXAMPLE: - { - const SfxPoolItem* pNameItem; - if (pArgs && SfxItemState::SET == pArgs->GetItemState( nSlotId, true, &pNameItem )) - aStyleName = static_cast<const SfxStringItem*>(pNameItem)->GetValue(); - else if ( nSlotId == SID_STYLE_NEW_BY_EXAMPLE ) - { - weld::Window* pDialogParent = rReq.GetFrameWeld(); - if (!pDialogParent) - pDialogParent = pTabViewShell->GetFrameWeld(); - SfxNewStyleDlg aDlg(pDialogParent, *pStylePool, eFamily); - if (aDlg.run() != RET_OK) - return; - aStyleName = aDlg.GetName(); - } - - pStyleSheet = pStylePool->Find( aStyleName, eFamily ); - - aOldData.InitFromStyle( pStyleSheet ); - } - break; - - case SID_STYLE_WATERCAN: - { - bool bWaterCan = pScMod->GetIsWaterCan(); - - if( !bWaterCan ) - { - const SfxPoolItem* pItem; - - if ( SfxItemState::SET == - pArgs->GetItemState( nSlotId, true, &pItem ) ) - { - const SfxStringItem* pStrItem = dynamic_cast< const SfxStringItem *>( pItem ); - if ( pStrItem ) - { - aStyleName = pStrItem->GetValue(); - pStyleSheet = pStylePool->Find( aStyleName, eFamily ); - - if ( pStyleSheet ) - { - static_cast<ScStyleSheetPool*>(pStylePool)-> - SetActualStyleSheet( pStyleSheet ); - rReq.Done(); - } - } - } - } - - if ( !bWaterCan && pStyleSheet ) - { - pScMod->SetWaterCan( true ); - pTabViewShell->SetActivePointer( PointerStyle::Fill ); - rReq.Done(); - } - else - { - pScMod->SetWaterCan( false ); - pTabViewShell->SetActivePointer( PointerStyle::Arrow ); - rReq.Done(); - } - } - break; - - default: - break; - } - - // set new style for paintbrush format mode - if ( nSlotId == SID_STYLE_APPLY && pScMod->GetIsWaterCan() && pStyleSheet ) - static_cast<ScStyleSheetPool*>(pStylePool)->SetActualStyleSheet( pStyleSheet ); - - switch ( eFamily ) - { - case SfxStyleFamily::Para: - { - switch ( nSlotId ) - { - case SID_STYLE_DELETE: - { - if ( pStyleSheet ) - { - pTabViewShell->RemoveStyleSheetInUse( pStyleSheet ); - pStylePool->Remove( pStyleSheet ); - pTabViewShell->InvalidateAttribs(); - nRetMask = sal_uInt16(true); - bAddUndo = true; - rReq.Done(); - } - else - nRetMask = sal_uInt16(false); - } - break; - - case SID_STYLE_HIDE: - case SID_STYLE_SHOW: - { - if ( pStyleSheet ) - { - pStyleSheet->SetHidden( nSlotId == SID_STYLE_HIDE ); - pTabViewShell->InvalidateAttribs(); - rReq.Done(); - } - else - nRetMask = sal_uInt16(false); - } - break; - - case SID_STYLE_APPLY: - { - if ( pStyleSheet && !pScMod->GetIsWaterCan() ) - { - // apply style sheet to document - pTabViewShell->SetStyleSheetToMarked( static_cast<SfxStyleSheet*>(pStyleSheet) ); - pTabViewShell->InvalidateAttribs(); - rReq.Done(); - } - } - break; - - case SID_STYLE_NEW_BY_EXAMPLE: - case SID_STYLE_UPDATE_BY_EXAMPLE: - { - // create/replace style sheet by attributes - // at cursor position: - - const ScPatternAttr* pAttrItem = nullptr; - - // The query if marked, was always wrong here, - // so now no more, and just from the cursor. - // If attributes are to be removed from the selection, still need to be - // cautious not to adopt items from templates - // (GetSelectionPattern also collects items from originals) (# 44748 #) - SCCOL nCol = rViewData.GetCurX(); - SCROW nRow = rViewData.GetCurY(); - pAttrItem = rDoc.GetPattern( nCol, nRow, nCurTab ); - - SfxItemSet aAttrSet = pAttrItem->GetItemSet(); - aAttrSet.ClearItem( ATTR_MERGE ); - aAttrSet.ClearItem( ATTR_MERGE_FLAG ); - - // Do not adopt conditional formatting and validity, - // because they can not be edited in the template - aAttrSet.ClearItem( ATTR_VALIDDATA ); - aAttrSet.ClearItem( ATTR_CONDITIONAL ); - - if ( SID_STYLE_NEW_BY_EXAMPLE == nSlotId ) - { - if ( bUndo ) - { - OUString aUndo = ScResId( STR_UNDO_EDITCELLSTYLE ); - pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, pTabViewShell->GetViewShellId() ); - bListAction = true; - } - - bool bConvertBack = false; - SfxStyleSheet* pSheetInUse = const_cast<SfxStyleSheet*>( - pTabViewShell->GetStyleSheetFromMarked()); - - // when a new style is present and is used in the selection, - // then the parent can not be adopted: - if ( pStyleSheet && pSheetInUse && pStyleSheet == pSheetInUse ) - pSheetInUse = nullptr; - - // if already present, first remove ... - if ( pStyleSheet ) - { - // style pointer to names before erase, - // otherwise cells will get invalid pointer - //!!! As it happens, a method that does it for a particular style - rDoc.StylesToNames(); - bConvertBack = true; - pStylePool->Remove(pStyleSheet); - } - - // ...and create new - pStyleSheet = &pStylePool->Make( aStyleName, eFamily, - SfxStyleSearchBits::UserDefined ); - - // when a style is present, then this will become - // the parent of the new style: - if ( pSheetInUse && pStyleSheet->HasParentSupport() ) - pStyleSheet->SetParent( pSheetInUse->GetName() ); - - if ( bConvertBack ) - // Name to style pointer - rDoc.UpdStlShtPtrsFrmNms(); - else - rDoc.GetPool()->CellStyleCreated( aStyleName, rDoc ); - - // Adopt attribute and use style - pStyleSheet->GetItemSet().Put( aAttrSet ); - pTabViewShell->UpdateStyleSheetInUse( pStyleSheet ); - - // call SetStyleSheetToMarked after adding the ScUndoModifyStyle - // (pStyleSheet pointer is used!) - bStyleToMarked = true; - } - else // ( nSlotId == SID_STYLE_UPDATE_BY_EXAMPLE ) - { - pStyleSheet = const_cast<SfxStyleSheet*>(pTabViewShell->GetStyleSheetFromMarked()); - - if ( pStyleSheet ) - { - aOldData.InitFromStyle( pStyleSheet ); - - if ( bUndo ) - { - OUString aUndo = ScResId( STR_UNDO_EDITCELLSTYLE ); - pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, pTabViewShell->GetViewShellId() ); - bListAction = true; - } - - pStyleSheet->GetItemSet().Put( aAttrSet ); - pTabViewShell->UpdateStyleSheetInUse( pStyleSheet ); - - // call SetStyleSheetToMarked after adding the ScUndoModifyStyle - // (pStyleSheet pointer is used!) - bStyleToMarked = true; - } - } - - aNewData.InitFromStyle( pStyleSheet ); - bAddUndo = true; - rReq.Done(); - } - break; - - default: - break; - } - } // case SfxStyleFamily::Para: - break; - - case SfxStyleFamily::Page: - { - switch ( nSlotId ) - { - case SID_STYLE_DELETE: - { - nRetMask = sal_uInt16( nullptr != pStyleSheet ); - if ( pStyleSheet ) - { - if ( rDoc.RemovePageStyleInUse( pStyleSheet->GetName() ) ) - { - ScPrintFunc( pDocSh, pTabViewShell->GetPrinter(true), nCurTab ).UpdatePages(); - rBindings.Invalidate( SID_STATUS_PAGESTYLE ); - rBindings.Invalidate( FID_RESET_PRINTZOOM ); - } - pStylePool->Remove( pStyleSheet ); - rBindings.Invalidate( SID_STYLE_FAMILY4 ); - pDocSh->SetDocumentModified(); - bAddUndo = true; - rReq.Done(); - } - } - break; - - case SID_STYLE_HIDE: - case SID_STYLE_SHOW: - { - nRetMask = sal_uInt16( nullptr != pStyleSheet ); - if ( pStyleSheet ) - { - pStyleSheet->SetHidden( nSlotId == SID_STYLE_HIDE ); - rBindings.Invalidate( SID_STYLE_FAMILY4 ); - pDocSh->SetDocumentModified(); - rReq.Done(); - } - } - break; - - case SID_STYLE_APPLY: - { - nRetMask = sal_uInt16( nullptr != pStyleSheet ); - if ( pStyleSheet && !pScMod->GetIsWaterCan() ) - { - std::unique_ptr<ScUndoApplyPageStyle> pUndoAction; - SCTAB nTabCount = rDoc.GetTableCount(); - for (const auto& rTab : rMark) - { - if (rTab >= nTabCount) - break; - OUString aOldName = rDoc.GetPageStyle( rTab ); - if ( aOldName != aStyleName ) - { - rDoc.SetPageStyle( rTab, aStyleName ); - ScPrintFunc( pDocSh, pTabViewShell->GetPrinter(true), rTab ).UpdatePages(); - if( !pUndoAction ) - pUndoAction.reset(new ScUndoApplyPageStyle( pDocSh, aStyleName )); - pUndoAction->AddSheetAction( rTab, aOldName ); - } - } - if( pUndoAction ) - { - pDocSh->GetUndoManager()->AddUndoAction( std::move(pUndoAction) ); - pDocSh->SetDocumentModified(); - rBindings.Invalidate( SID_STYLE_FAMILY4 ); - rBindings.Invalidate( SID_STATUS_PAGESTYLE ); - rBindings.Invalidate( FID_RESET_PRINTZOOM ); - } - rReq.Done(); - } - } - break; - - case SID_STYLE_NEW_BY_EXAMPLE: - { - const OUString& rStrCurStyle = rDoc.GetPageStyle( nCurTab ); - - if ( rStrCurStyle != aStyleName ) - { - SfxStyleSheetBase* pCurStyle = pStylePool->Find( rStrCurStyle, eFamily ); - SfxItemSet aAttrSet = pCurStyle->GetItemSet(); - SCTAB nInTab; - bool bUsed = rDoc.IsPageStyleInUse( aStyleName, &nInTab ); - - // if already present, first remove... - if ( pStyleSheet ) - pStylePool->Remove( pStyleSheet ); - - // ...and create new - pStyleSheet = &pStylePool->Make( aStyleName, eFamily, - SfxStyleSearchBits::UserDefined ); - - // Adopt attribute - pStyleSheet->GetItemSet().Put( aAttrSet ); - pDocSh->SetDocumentModified(); - - // If being used -> Update - if ( bUsed ) - ScPrintFunc( pDocSh, pTabViewShell->GetPrinter(true), nInTab ).UpdatePages(); - - aNewData.InitFromStyle( pStyleSheet ); - bAddUndo = true; - rReq.Done(); - nRetMask = sal_uInt16(true); - } - } - break; - - default: - break; - } // switch ( nSlotId ) - } // case SfxStyleFamily::Page: - break; - - default: - break; - } // switch ( eFamily ) - - // create new or process through Dialog: - if ( nSlotId == SID_STYLE_NEW || nSlotId == SID_STYLE_EDIT ) - { - 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(); - - switch ( eFam ) - { - case SfxStyleFamily::Page: - bPage = true; - break; - - case SfxStyleFamily::Para: - default: - { - SfxItemSet& rSet = pStyleSheet->GetItemSet(); - - 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 - } - } - - std::unique_ptr<SvxNumberInfoItem> pNumberInfoItem( - ScTabViewShell::MakeNumberInfoItem(rDoc, GetViewData())); - - pDocSh->PutItem( *pNumberInfoItem ); - bPage = false; - - // 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 ); - } - } - break; - } - - pTabViewShell->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 = pTabViewShell->GetFrameWeld(); - pDlg.disposeAndReset(pFact->CreateScStyleDlg(pDialogParent, *pStyleSheet, bPage)); - short nResult = pDlg->Execute(); - pTabViewShell->SetInFormatDialog(false); - - if ( nResult == RET_OK ) - { - const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); - - if ( pOutSet ) - { - 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 ); - - SCTAB nTabCount = rDoc.GetTableCount(); - for (SCTAB nTab=0; nTab<nTabCount; nTab++) - rDoc.SetStreamValid(nTab, false); - - 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 ) ); - } - - rDoc.GetPool()->CellStyleCreated( pStyleSheet->GetName(), rDoc ); - } - else - { - //! Here also queries for Page Styles - - 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 ); - } - - pDocSh->SetDocumentModified(); - - if ( SfxStyleFamily::Para == eFam ) - { - ScTabViewShell::UpdateNumberFormatter( - *( pDocSh->GetItem(SID_ATTR_NUMBERFORMAT_INFO) )); - - pTabViewShell->UpdateStyleSheetInUse( pStyleSheet ); - pTabViewShell->InvalidateAttribs(); - } - - aNewData.InitFromStyle( pStyleSheet ); - bAddUndo = 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(); - } - } - } - } - - rReq.SetReturnValue( SfxUInt16Item( nSlotId, nRetMask ) ); - - if ( bAddUndo && bUndo) - pDocSh->GetUndoManager()->AddUndoAction( - std::make_unique<ScUndoModifyStyle>( pDocSh, eFamily, aOldData, aNewData ) ); - - if ( bStyleToMarked ) - { - // call SetStyleSheetToMarked after adding the ScUndoModifyStyle, - // so redo will find the modified style - pTabViewShell->SetStyleSheetToMarked( static_cast<SfxStyleSheet*>(pStyleSheet) ); - pTabViewShell->InvalidateAttribs(); - } - - if ( bListAction ) - pDocSh->GetUndoManager()->LeaveListAction(); - } else if (nSlotId == SID_CLASSIFICATION_APPLY) { const SfxPoolItem* pItem = nullptr; diff --git a/sc/source/ui/view/tabvwsha.cxx b/sc/source/ui/view/tabvwsha.cxx index d30733cf1ea9..4c9a6e4a39d1 100644 --- a/sc/source/ui/view/tabvwsha.cxx +++ b/sc/source/ui/view/tabvwsha.cxx @@ -21,12 +21,16 @@ #include <comphelper/lok.hxx> #include <editeng/boxitem.hxx> +#include <editeng/langitem.hxx> #include <o3tl/temporary.hxx> #include <sfx2/bindings.hxx> #include <sfx2/request.hxx> #include <sfx2/sfxdlg.hxx> #include <sfx2/sidebar/Sidebar.hxx> #include <sfx2/viewfrm.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/newstyle.hxx> +#include <sfx2/tplpitem.hxx> #include <svl/ilstitem.hxx> #include <svl/numformat.hxx> #include <svl/zformat.hxx> @@ -61,6 +65,9 @@ #include <tabvwsh.hxx> #include <tokenarray.hxx> #include <viewdata.hxx> +#include <docpool.hxx> +#include <printfun.hxx> +#include <undostyl.hxx> #include <memory> @@ -894,4 +901,720 @@ void ScTabViewShell::GetDrawOptState( SfxItemSet& rSet ) rSet.Put( aBool ); } +void ScTabViewShell::ExecStyle( SfxRequest& rReq ) +{ + const SfxItemSet* pArgs = rReq.GetArgs(); + const sal_uInt16 nSlotId = rReq.GetSlot(); + if ( !pArgs && nSlotId != SID_STYLE_NEW_BY_EXAMPLE && nSlotId != SID_STYLE_UPDATE_BY_EXAMPLE ) + { + // in case of vertical toolbar + GetDispatcher()->Execute( SID_STYLE_DESIGNER, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD ); + return; + } + + SfxBindings& rBindings = GetViewData().GetBindings(); + const SCTAB nCurTab = GetViewData().GetTabNo(); + ScDocShell* pDocSh = GetViewData().GetDocShell(); + ScDocument& rDoc = pDocSh->GetDocument(); + ScMarkData& rMark = GetViewData().GetMarkData(); + ScModule* pScMod = SC_MOD(); + OUString aRefName; + bool bUndo = rDoc.IsUndoEnabled(); + + SfxStyleSheetBasePool* pStylePool = rDoc.GetStyleSheetPool(); + SfxStyleSheetBase* pStyleSheet = nullptr; + + bool bStyleToMarked = false; + bool bListAction = false; + bool bAddUndo = false; // add ScUndoModifyStyle (style modified) + ScStyleSaveData aOldData; // for undo/redo + ScStyleSaveData aNewData; + + SfxStyleFamily eFamily = SfxStyleFamily::Para; + const SfxUInt16Item* pFamItem; + const SfxStringItem* pFamilyNameItem; + if ( pArgs && (pFamItem = pArgs->GetItemIfSet( SID_STYLE_FAMILY )) ) + eFamily = static_cast<SfxStyleFamily>(pFamItem->GetValue()); + else if ( pArgs && (pFamilyNameItem = pArgs->GetItemIfSet( SID_STYLE_FAMILYNAME )) ) + { + OUString sFamily = pFamilyNameItem->GetValue(); + if (sFamily == "CellStyles") + eFamily = SfxStyleFamily::Para; + else if (sFamily == "PageStyles") + eFamily = SfxStyleFamily::Page; + } + + OUString aStyleName; + sal_uInt16 nRetMask = 0xffff; + + switch ( nSlotId ) + { + case SID_STYLE_NEW: + { + const SfxPoolItem* pNameItem; + if (pArgs && SfxItemState::SET == pArgs->GetItemState( nSlotId, true, &pNameItem )) + aStyleName = static_cast<const SfxStringItem*>(pNameItem)->GetValue(); + + const SfxStringItem* pRefItem=nullptr; + if (pArgs && (pRefItem = pArgs->GetItemIfSet( SID_STYLE_REFERENCE ))) + { + aRefName = pRefItem->GetValue(); + } + + pStyleSheet = &(pStylePool->Make( aStyleName, eFamily, + SfxStyleSearchBits::UserDefined ) ); + + if (pStyleSheet->HasParentSupport()) + pStyleSheet->SetParent(aRefName); + } + break; + + case SID_STYLE_APPLY: + { + const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(SID_APPLY_STYLE); + const SfxStringItem* pFamilyItem = rReq.GetArg<SfxStringItem>(SID_STYLE_FAMILYNAME); + if ( pFamilyItem && pNameItem ) + { + try + { + css::uno::Reference< css::container::XNameAccess > xStyles; + css::uno::Reference< css::container::XNameAccess > xCont = pDocSh->GetModel()->getStyleFamilies(); + xCont->getByName(pFamilyItem->GetValue()) >>= xStyles; + css::uno::Reference< css::beans::XPropertySet > xInfo; + xStyles->getByName( pNameItem->GetValue() ) >>= xInfo; + OUString aUIName; + xInfo->getPropertyValue("DisplayName") >>= aUIName; + if ( !aUIName.isEmpty() ) + rReq.AppendItem( SfxStringItem( SID_STYLE_APPLY, aUIName ) ); + } + catch( css::uno::Exception& ) + { + } + } + [[fallthrough]]; + } + case SID_STYLE_EDIT: + case SID_STYLE_DELETE: + case SID_STYLE_HIDE: + case SID_STYLE_SHOW: + case SID_STYLE_NEW_BY_EXAMPLE: + { + const SfxPoolItem* pNameItem; + if (pArgs && SfxItemState::SET == pArgs->GetItemState( nSlotId, true, &pNameItem )) + aStyleName = static_cast<const SfxStringItem*>(pNameItem)->GetValue(); + else if ( nSlotId == SID_STYLE_NEW_BY_EXAMPLE ) + { + weld::Window* pDialogParent = rReq.GetFrameWeld(); + if (!pDialogParent) + pDialogParent = GetFrameWeld(); + SfxNewStyleDlg aDlg(pDialogParent, *pStylePool, eFamily); + if (aDlg.run() != RET_OK) + return; + aStyleName = aDlg.GetName(); + } + + pStyleSheet = pStylePool->Find( aStyleName, eFamily ); + + aOldData.InitFromStyle( pStyleSheet ); + } + break; + + case SID_STYLE_WATERCAN: + { + bool bWaterCan = pScMod->GetIsWaterCan(); + + if( !bWaterCan ) + { + const SfxPoolItem* pItem; + + if ( SfxItemState::SET == + pArgs->GetItemState( nSlotId, true, &pItem ) ) + { + const SfxStringItem* pStrItem = dynamic_cast< const SfxStringItem *>( pItem ); + if ( pStrItem ) + { + aStyleName = pStrItem->GetValue(); + pStyleSheet = pStylePool->Find( aStyleName, eFamily ); + + if ( pStyleSheet ) + { + static_cast<ScStyleSheetPool*>(pStylePool)-> + SetActualStyleSheet( pStyleSheet ); + rReq.Done(); + } + } + } + } + + if ( !bWaterCan && pStyleSheet ) + { + pScMod->SetWaterCan( true ); + SetActivePointer( PointerStyle::Fill ); + rReq.Done(); + } + else + { + pScMod->SetWaterCan( false ); + SetActivePointer( PointerStyle::Arrow ); + rReq.Done(); + } + } + break; + + default: + break; + } + + // set new style for paintbrush format mode + if ( nSlotId == SID_STYLE_APPLY && pScMod->GetIsWaterCan() && pStyleSheet ) + static_cast<ScStyleSheetPool*>(pStylePool)->SetActualStyleSheet( pStyleSheet ); + + switch ( eFamily ) + { + case SfxStyleFamily::Para: + { + switch ( nSlotId ) + { + case SID_STYLE_DELETE: + { + if ( pStyleSheet ) + { + RemoveStyleSheetInUse( pStyleSheet ); + pStylePool->Remove( pStyleSheet ); + InvalidateAttribs(); + nRetMask = sal_uInt16(true); + bAddUndo = true; + rReq.Done(); + } + else + nRetMask = sal_uInt16(false); + } + break; + + case SID_STYLE_HIDE: + case SID_STYLE_SHOW: + { + if ( pStyleSheet ) + { + pStyleSheet->SetHidden( nSlotId == SID_STYLE_HIDE ); + InvalidateAttribs(); + rReq.Done(); + } + else + nRetMask = sal_uInt16(false); + } + break; + + case SID_STYLE_APPLY: + { + if ( pStyleSheet && !pScMod->GetIsWaterCan() ) + { + // apply style sheet to document + SetStyleSheetToMarked( static_cast<SfxStyleSheet*>(pStyleSheet) ); + InvalidateAttribs(); + rReq.Done(); + } + } + break; + + case SID_STYLE_NEW_BY_EXAMPLE: + case SID_STYLE_UPDATE_BY_EXAMPLE: + { + // create/replace style sheet by attributes + // at cursor position: + + const ScPatternAttr* pAttrItem = nullptr; + + // The query if marked, was always wrong here, + // so now no more, and just from the cursor. + // If attributes are to be removed from the selection, still need to be + // cautious not to adopt items from templates + // (GetSelectionPattern also collects items from originals) (# 44748 #) + SCCOL nCol = GetViewData().GetCurX(); + SCROW nRow = GetViewData().GetCurY(); + pAttrItem = rDoc.GetPattern( nCol, nRow, nCurTab ); + + SfxItemSet aAttrSet = pAttrItem->GetItemSet(); + aAttrSet.ClearItem( ATTR_MERGE ); + aAttrSet.ClearItem( ATTR_MERGE_FLAG ); + + // Do not adopt conditional formatting and validity, + // because they can not be edited in the template + aAttrSet.ClearItem( ATTR_VALIDDATA ); + aAttrSet.ClearItem( ATTR_CONDITIONAL ); + + if ( SID_STYLE_NEW_BY_EXAMPLE == nSlotId ) + { + if ( bUndo ) + { + OUString aUndo = ScResId( STR_UNDO_EDITCELLSTYLE ); + pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, GetViewShellId() ); + bListAction = true; + } + + bool bConvertBack = false; + SfxStyleSheet* pSheetInUse = const_cast<SfxStyleSheet*>(GetStyleSheetFromMarked()); + + // when a new style is present and is used in the selection, + // then the parent can not be adopted: + if ( pStyleSheet && pSheetInUse && pStyleSheet == pSheetInUse ) + pSheetInUse = nullptr; + + // if already present, first remove ... + if ( pStyleSheet ) + { + // style pointer to names before erase, + // otherwise cells will get invalid pointer + //!!! As it happens, a method that does it for a particular style + rDoc.StylesToNames(); + bConvertBack = true; + pStylePool->Remove(pStyleSheet); + } + + // ...and create new + pStyleSheet = &pStylePool->Make( aStyleName, eFamily, + SfxStyleSearchBits::UserDefined ); + + // when a style is present, then this will become + // the parent of the new style: + if ( pSheetInUse && pStyleSheet->HasParentSupport() ) + pStyleSheet->SetParent( pSheetInUse->GetName() ); + + if ( bConvertBack ) + // Name to style pointer + rDoc.UpdStlShtPtrsFrmNms(); + else + rDoc.GetPool()->CellStyleCreated( aStyleName, rDoc ); + + // Adopt attribute and use style + pStyleSheet->GetItemSet().Put( aAttrSet ); + UpdateStyleSheetInUse( pStyleSheet ); + + // call SetStyleSheetToMarked after adding the ScUndoModifyStyle + // (pStyleSheet pointer is used!) + bStyleToMarked = true; + } + else // ( nSlotId == SID_STYLE_UPDATE_BY_EXAMPLE ) + { + pStyleSheet = const_cast<SfxStyleSheet*>(GetStyleSheetFromMarked()); + + if ( pStyleSheet ) + { + aOldData.InitFromStyle( pStyleSheet ); + + if ( bUndo ) + { + OUString aUndo = ScResId( STR_UNDO_EDITCELLSTYLE ); + pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo, 0, GetViewShellId() ); + bListAction = true; + } + + pStyleSheet->GetItemSet().Put( aAttrSet ); + UpdateStyleSheetInUse( pStyleSheet ); + + // call SetStyleSheetToMarked after adding the ScUndoModifyStyle + // (pStyleSheet pointer is used!) + bStyleToMarked = true; + } + } + + aNewData.InitFromStyle( pStyleSheet ); + bAddUndo = true; + rReq.Done(); + } + break; + + default: + break; + } + } // case SfxStyleFamily::Para: + break; + + case SfxStyleFamily::Page: + { + switch ( nSlotId ) + { + case SID_STYLE_DELETE: + { + nRetMask = sal_uInt16( nullptr != pStyleSheet ); + if ( pStyleSheet ) + { + if ( rDoc.RemovePageStyleInUse( pStyleSheet->GetName() ) ) + { + ScPrintFunc( pDocSh, GetPrinter(true), nCurTab ).UpdatePages(); + rBindings.Invalidate( SID_STATUS_PAGESTYLE ); + rBindings.Invalidate( FID_RESET_PRINTZOOM ); + } + pStylePool->Remove( pStyleSheet ); + rBindings.Invalidate( SID_STYLE_FAMILY4 ); + pDocSh->SetDocumentModified(); + bAddUndo = true; + rReq.Done(); + } + } + break; + + case SID_STYLE_HIDE: + case SID_STYLE_SHOW: + { + nRetMask = sal_uInt16( nullptr != pStyleSheet ); + if ( pStyleSheet ) + { + pStyleSheet->SetHidden( nSlotId == SID_STYLE_HIDE ); + rBindings.Invalidate( SID_STYLE_FAMILY4 ); + pDocSh->SetDocumentModified(); + rReq.Done(); + } + } + break; + + case SID_STYLE_APPLY: + { + nRetMask = sal_uInt16( nullptr != pStyleSheet ); + if ( pStyleSheet && !pScMod->GetIsWaterCan() ) + { + std::unique_ptr<ScUndoApplyPageStyle> pUndoAction; + SCTAB nTabCount = rDoc.GetTableCount(); + for (const auto& rTab : rMark) + { + if (rTab >= nTabCount) + break; + OUString aOldName = rDoc.GetPageStyle( rTab ); + if ( aOldName != aStyleName ) + { + rDoc.SetPageStyle( rTab, aStyleName ); + ScPrintFunc( pDocSh, GetPrinter(true), rTab ).UpdatePages(); + if( !pUndoAction ) + pUndoAction.reset(new ScUndoApplyPageStyle( pDocSh, aStyleName )); + pUndoAction->AddSheetAction( rTab, aOldName ); + } + } + if( pUndoAction ) + { + pDocSh->GetUndoManager()->AddUndoAction( std::move(pUndoAction) ); + pDocSh->SetDocumentModified(); + rBindings.Invalidate( SID_STYLE_FAMILY4 ); + rBindings.Invalidate( SID_STATUS_PAGESTYLE ); + rBindings.Invalidate( FID_RESET_PRINTZOOM ); + } + rReq.Done(); + } + } + break; + + case SID_STYLE_NEW_BY_EXAMPLE: + { + const OUString& rStrCurStyle = rDoc.GetPageStyle( nCurTab ); + + if ( rStrCurStyle != aStyleName ) + { + SfxStyleSheetBase* pCurStyle = pStylePool->Find( rStrCurStyle, eFamily ); + SfxItemSet aAttrSet = pCurStyle->GetItemSet(); + SCTAB nInTab; + bool bUsed = rDoc.IsPageStyleInUse( aStyleName, &nInTab ); + + // if already present, first remove... + if ( pStyleSheet ) + pStylePool->Remove( pStyleSheet ); + + // ...and create new + pStyleSheet = &pStylePool->Make( aStyleName, eFamily, + SfxStyleSearchBits::UserDefined ); + + // Adopt attribute + pStyleSheet->GetItemSet().Put( aAttrSet ); + pDocSh->SetDocumentModified(); + + // If being used -> Update + if ( bUsed ) + ScPrintFunc( pDocSh, GetPrinter(true), nInTab ).UpdatePages(); + + aNewData.InitFromStyle( pStyleSheet ); + bAddUndo = true; + rReq.Done(); + nRetMask = sal_uInt16(true); + } + } + break; + + default: + break; + } // switch ( nSlotId ) + } // case SfxStyleFamily::Page: + break; + + default: + break; + } // switch ( eFamily ) + + // create new or process through Dialog: + if ( nSlotId == SID_STYLE_NEW || nSlotId == SID_STYLE_EDIT ) + { + 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(); + + switch ( eFam ) + { + case SfxStyleFamily::Page: + bPage = true; + break; + + case SfxStyleFamily::Para: + default: + { + SfxItemSet& rSet = pStyleSheet->GetItemSet(); + + 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 + } + } + + std::unique_ptr<SvxNumberInfoItem> pNumberInfoItem( + ScTabViewShell::MakeNumberInfoItem(rDoc, GetViewData())); + + pDocSh->PutItem( *pNumberInfoItem ); + bPage = false; + + // 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 ); + } + } + 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(); + pDlg.disposeAndReset(pFact->CreateScStyleDlg(pDialogParent, *pStyleSheet, bPage)); + short nResult = pDlg->Execute(); + SetInFormatDialog(false); + + if ( nResult == RET_OK ) + { + const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); + + if ( pOutSet ) + { + 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 ); + + SCTAB nTabCount = rDoc.GetTableCount(); + for (SCTAB nTab=0; nTab<nTabCount; nTab++) + rDoc.SetStreamValid(nTab, false); + + 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 ) ); + } + + rDoc.GetPool()->CellStyleCreated( pStyleSheet->GetName(), rDoc ); + } + else + { + //! Here also queries for Page Styles + + 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 ); + } + + pDocSh->SetDocumentModified(); + + if ( SfxStyleFamily::Para == eFam ) + { + ScTabViewShell::UpdateNumberFormatter( + *( pDocSh->GetItem(SID_ATTR_NUMBERFORMAT_INFO) )); + + UpdateStyleSheetInUse( pStyleSheet ); + InvalidateAttribs(); + } + + aNewData.InitFromStyle( pStyleSheet ); + bAddUndo = 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(); + } + } + } + } + + rReq.SetReturnValue( SfxUInt16Item( nSlotId, nRetMask ) ); + + if ( bAddUndo && bUndo) + pDocSh->GetUndoManager()->AddUndoAction( + std::make_unique<ScUndoModifyStyle>( pDocSh, eFamily, aOldData, aNewData ) ); + + if ( bStyleToMarked ) + { + // call SetStyleSheetToMarked after adding the ScUndoModifyStyle, + // so redo will find the modified style + SetStyleSheetToMarked( static_cast<SfxStyleSheet*>(pStyleSheet) ); + InvalidateAttribs(); + } + + if ( bListAction ) + pDocSh->GetUndoManager()->LeaveListAction(); +} + +void ScTabViewShell::GetStyleState( SfxItemSet& rSet ) +{ + ScDocument& rDoc = GetViewData().GetDocument(); + SfxStyleSheetBasePool* pStylePool = rDoc.GetStyleSheetPool(); + + bool bProtected = false; + SCTAB nTabCount = rDoc.GetTableCount(); + for (SCTAB i=0; i<nTabCount && !bProtected; i++) + if (rDoc.IsTabProtected(i)) // look after protected table + bProtected = true; + + SfxWhichIter aIter(rSet); + sal_uInt16 nWhich = aIter.FirstWhich(); + sal_uInt16 nSlotId = 0; + + while ( nWhich ) + { + nSlotId = SfxItemPool::IsWhich( nWhich ) + ? GetPool().GetSlotId( nWhich ) + : nWhich; + + switch ( nSlotId ) + { + case SID_STYLE_APPLY: + if ( !pStylePool ) + rSet.DisableItem( nSlotId ); + break; + + case SID_STYLE_FAMILY2: // cell style sheets + { + SfxStyleSheet* pStyleSheet = const_cast<SfxStyleSheet*>(GetStyleSheetFromMarked()); + + if ( pStyleSheet ) + rSet.Put( SfxTemplateItem( nSlotId, pStyleSheet->GetName() ) ); + else + rSet.Put( SfxTemplateItem( nSlotId, OUString() ) ); + } + break; + + case SID_STYLE_FAMILY4: // page style sheets + { + SCTAB nCurTab = GetViewData().GetTabNo(); + OUString aPageStyle = rDoc.GetPageStyle( nCurTab ); + SfxStyleSheet* pStyleSheet = pStylePool ? static_cast<SfxStyleSheet*>(pStylePool-> + Find( aPageStyle, SfxStyleFamily::Page )) : nullptr; + + if ( pStyleSheet ) + rSet.Put( SfxTemplateItem( nSlotId, aPageStyle ) ); + else + rSet.Put( SfxTemplateItem( nSlotId, OUString() ) ); + } + break; + + case SID_STYLE_WATERCAN: + { + rSet.Put( SfxBoolItem( nSlotId, SC_MOD()->GetIsWaterCan() ) ); + } + break; + + case SID_STYLE_UPDATE_BY_EXAMPLE: + { + std::unique_ptr<SfxUInt16Item> pFamilyItem; + GetViewFrame().GetBindings().QueryState(SID_STYLE_FAMILY, pFamilyItem); + + bool bPage = pFamilyItem && SfxStyleFamily::Page == static_cast<SfxStyleFamily>(pFamilyItem->GetValue()); + + if ( bProtected || bPage ) + rSet.DisableItem( nSlotId ); + } + break; + + case SID_STYLE_EDIT: + case SID_STYLE_DELETE: + case SID_STYLE_HIDE: + case SID_STYLE_SHOW: + { + std::unique_ptr<SfxUInt16Item> pFamilyItem; + GetViewFrame().GetBindings().QueryState(SID_STYLE_FAMILY, pFamilyItem); + bool bPage = pFamilyItem && SfxStyleFamily::Page == static_cast<SfxStyleFamily>(pFamilyItem->GetValue()); + + if ( bProtected && !bPage ) + rSet.DisableItem( nSlotId ); + } + break; + + default: + break; + } + + nWhich = aIter.NextWhich(); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |