/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using std::unique_ptr; using namespace com::sun::star; void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) { ScViewData& rViewData = GetViewData(); ScDocument& rDoc = rViewData.GetDocument(); SCTAB nCurrentTab = rViewData.GetTabNo(); SCTAB nTabCount = rDoc.GetTableCount(); sal_uInt16 nSlot = rReq.GetSlot(); const SfxItemSet* pReqArgs = rReq.GetArgs(); HideListBox(); // Autofilter-DropDown-Listbox switch ( nSlot ) { case FID_TABLE_VISIBLE: { OUString aName; rDoc.GetName( nCurrentTab, aName ); bool bVisible=true; if( pReqArgs != nullptr ) { const SfxPoolItem* pItem; if( pReqArgs->HasItem( FID_TABLE_VISIBLE, &pItem ) ) bVisible = static_cast(pItem)->GetValue(); } if( ! bVisible ) // fade out { if ( rDoc.IsDocEditable() ) { ScMarkData& rMark = rViewData.GetMarkData(); HideTable( rMark ); } } else // fade in { std::vector rNames { aName }; ShowTable( rNames ); } } break; case FID_TABLE_HIDE: { if ( rDoc.IsDocEditable() ) { ScMarkData& rMark = rViewData.GetMarkData(); SCTAB nActiveTab = -1; // For the cases when user right clicks on a non-active tab and hides it. This case is possible for Online. if (pReqArgs) { const SfxPoolItem *pItem; if( pReqArgs->HasItem( FID_TABLE_HIDE, &pItem ) ) { SCTAB nTabNumber = static_cast(pItem)->GetValue(); // Does selected sheets (tabs) list include the sheet to be hidden? std::set::iterator it = rMark.GetSelectedTabs().find(nTabNumber); if (it == rMark.GetSelectedTabs().end()) { // No it doesn't, so we won't shift the selected tab. Let's remember its position. nActiveTab = GetViewData().GetTabNo(); } rMark.SelectOneTable(nTabNumber); } } HideTable( rMark, nActiveTab ); } } break; case FID_TABLE_SHOW: { std::vector rNames; if ( pReqArgs ) { const SfxPoolItem* pItem; if( pReqArgs->HasItem( FID_TABLE_SHOW, &pItem ) ) { OUString aName = static_cast(pItem)->GetValue(); rNames.push_back(aName); ShowTable( rNames ); if( ! rReq.IsAPI() ) rReq.Done(); } } else { ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); VclPtr pDlg(pFact->CreateScShowTabDlg(GetFrameWeld())); OUString aTabName; bool bFirst = true; for ( SCTAB i=0; i != nTabCount; i++ ) { if (!rDoc.IsVisible(i)) { rDoc.GetName( i, aTabName ); pDlg->Insert( aTabName, bFirst ); bFirst = false; } } std::shared_ptr pReq = std::make_shared(rReq); pDlg->StartExecuteAsync([this, pDlg, pReq](sal_Int32 nResult){ std::vector sTables; if (RET_OK == nResult) { std::vector aSelectedRows = pDlg->GetSelectedRows(); for (auto a : aSelectedRows) { OUString sTable = pDlg->GetEntry(a); pReq->AppendItem( SfxStringItem( FID_TABLE_SHOW, sTable ) ); sTables.push_back(sTable); } ShowTable( sTables ); pReq->Done(); } pDlg->disposeOnce(); }); rReq.Ignore(); } } break; case FID_INS_TABLE: case FID_INS_TABLE_EXT: { ScMarkData& rMark = rViewData.GetMarkData(); SCTAB nTabSelCount = rMark.GetSelectCount(); SCTAB nTabNr = nCurrentTab; if ( !rDoc.IsDocEditable() ) break; // locked if ( pReqArgs != nullptr ) // from basic { bool bOk = false; const SfxPoolItem* pTabItem; const SfxPoolItem* pNameItem; if ( pReqArgs->HasItem( FN_PARAM_1, &pTabItem ) && pReqArgs->HasItem( nSlot, &pNameItem ) ) { OUString aName = static_cast(pNameItem)->GetValue(); rDoc.CreateValidTabName(aName); // sheet number from basic: 1-based // 0 is special, means adding at the end nTabNr = static_cast(pTabItem)->GetValue(); if (nTabNr == 0) nTabNr = nTabCount; else --nTabNr; if (nTabNr > nTabCount) nTabNr = nTabCount; bOk = InsertTable(aName, nTabNr); } if (bOk) rReq.Done( *pReqArgs ); //! else set error } else // dialog { ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); ScopedVclPtr pDlg(pFact->CreateScInsertTableDlg(GetFrameWeld(), rViewData, nTabSelCount, nSlot == FID_INS_TABLE_EXT)); if ( RET_OK == pDlg->Execute() ) { if (pDlg->GetTablesFromFile()) { std::vector nTabs; sal_uInt16 n = 0; const OUString* pStr = pDlg->GetFirstTable( &n ); while ( pStr ) { nTabs.push_back( static_cast(n) ); pStr = pDlg->GetNextTable( &n ); } bool bLink = pDlg->GetTablesAsLink(); if (!nTabs.empty()) { if(pDlg->IsTableBefore()) { ImportTables( pDlg->GetDocShellTables(), nTabs.size(), nTabs.data(), bLink,nTabNr ); } else { SCTAB nTabAfter = nTabNr+1; for(SCTAB j=nCurrentTab+1;jGetDocShellTables(), nTabs.size(), nTabs.data(), bLink,nTabAfter ); } } } else { SCTAB nCount=pDlg->GetTableCount(); if(pDlg->IsTableBefore()) { if(nCount==1 && !pDlg->GetFirstTable()->isEmpty()) { rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) ); rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast(nTabNr) + 1 ) ); // 1-based rReq.Done(); InsertTable( *pDlg->GetFirstTable(), nTabNr ); } else { std::vector aNames(0); InsertTables( aNames, nTabNr,nCount ); } } else { SCTAB nTabAfter = nTabNr+1; SCTAB nSelHigh = rMark.GetLastSelected(); for(SCTAB j=nSelHigh+1;jGetFirstTable()->isEmpty()) { rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) ); rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast(nTabAfter) + 1 ) ); // 1-based rReq.Done(); InsertTable( *pDlg->GetFirstTable(), nTabAfter); } else { std::vector aNames(0); InsertTables( aNames, nTabAfter,nCount); } } } } } } break; case FID_TAB_APPEND: case FID_TAB_RENAME: case FID_TAB_MENU_RENAME: { // FID_TAB_MENU_RENAME - "rename" in menu // FID_TAB_RENAME - "name"-property for basic // equal execute, but MENU_RENAME may be disabled inside GetState if ( nSlot == FID_TAB_MENU_RENAME ) nSlot = FID_TAB_RENAME; // equal execute SCTAB nTabNr = rViewData.GetTabNo(); ScMarkData& rMark = rViewData.GetMarkData(); SCTAB nTabSelCount = rMark.GetSelectCount(); if ( !rDoc.IsDocEditable() ) break; // everything locked if ( nSlot != FID_TAB_APPEND && ( rDoc.IsTabProtected( nTabNr ) || nTabSelCount > 1 ) ) break; // no rename if( pReqArgs != nullptr ) { bool bDone = false; const SfxPoolItem* pItem; OUString aName; if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) ) { nTabNr = static_cast(pItem)->GetValue(); // inserting is 1-based, let's be consistent if (nTabNr > 0) --nTabNr; } if( pReqArgs->HasItem( nSlot, &pItem ) ) aName = static_cast(pItem)->GetValue(); switch ( nSlot ) { case FID_TAB_APPEND: bDone = AppendTable( aName ); break; case FID_TAB_RENAME: bDone = RenameTable( aName, nTabNr ); break; } if( bDone ) { rReq.Done( *pReqArgs ); } } else { sal_uInt16 nRet = RET_OK; bool bDone = false; OUString aErrMsg ( ScResId( STR_INVALIDTABNAME ) ); OUString aName; OUString aDlgTitle; OUString sHelpId; switch ( nSlot ) { case FID_TAB_APPEND: aDlgTitle = ScResId(SCSTR_APDTABLE); rDoc.CreateValidTabName( aName ); sHelpId = HID_SC_APPEND_NAME; break; case FID_TAB_RENAME: aDlgTitle = ScResId(SCSTR_RENAMETAB); rDoc.GetName( rViewData.GetTabNo(), aName ); sHelpId = HID_SC_RENAME_NAME; break; } ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); ScopedVclPtr pDlg(pFact->CreateScStringInputDlg( GetFrameWeld(), aDlgTitle, ScResId(SCSTR_NAME), aName, GetStaticInterface()->GetSlot(nSlot)->GetCommand(), sHelpId)); while ( !bDone && nRet == RET_OK ) { nRet = pDlg->Execute(); if ( nRet == RET_OK ) { aName = pDlg->GetInputString(); switch ( nSlot ) { case FID_TAB_APPEND: bDone = AppendTable( aName ); break; case FID_TAB_RENAME: bDone = RenameTable( aName, nTabNr ); break; } if ( bDone ) { rReq.AppendItem( SfxStringItem( nSlot, aName ) ); rReq.Done(); } else { if( rReq.IsAPI() ) { #if HAVE_FEATURE_SCRIPTING StarBASIC::Error( ERRCODE_BASIC_SETPROP_FAILED ); // XXX error handling??? #endif } else { std::unique_ptr xBox(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Warning, VclButtonsType::Ok, aErrMsg)); nRet = xBox->run(); } } } } } } break; case FID_TAB_MOVE: { if ( rDoc.GetChangeTrack() != nullptr ) break; // if ChangeTracking is active, then no TabMove bool bDoIt = false; sal_uInt16 nDoc = 0; SCTAB nTab = rViewData.GetTabNo(); bool bCpy = false, bUseCurrentDocument = false; OUString aDocName; OUString aTabName; if( pReqArgs != nullptr ) { SCTAB nTableCount = rDoc.GetTableCount(); const SfxPoolItem* pItem; // if UseCurrentDocument(FN_PARAM_3) is true ignore the document name provided and use current document if( pReqArgs->HasItem( FN_PARAM_3, &pItem ) ) bUseCurrentDocument = static_cast(pItem)->GetValue(); if (bUseCurrentDocument) aDocName = GetViewData().GetDocShell()->GetTitle(); else if(pReqArgs->HasItem( FID_TAB_MOVE, &pItem )) aDocName = static_cast(pItem)->GetValue(); if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) ) { // table is 1-based nTab = static_cast(pItem)->GetValue() - 1; if ( nTab >= nTableCount ) nTab = SC_TAB_APPEND; } if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) ) bCpy = static_cast(pItem)->GetValue(); if (!aDocName.isEmpty()) { SfxObjectShell* pSh = SfxObjectShell::GetFirst(); ScDocShell* pScSh = nullptr; sal_uInt16 i=0; while ( pSh ) { pScSh = dynamic_cast( pSh ); if( pScSh ) { pScSh->GetTitle(); if (aDocName == pScSh->GetTitle()) { nDoc = i; ScDocument& rDestDoc = pScSh->GetDocument(); nTableCount = rDestDoc.GetTableCount(); bDoIt = rDestDoc.IsDocEditable(); break; } i++; // only count ScDocShell } pSh = SfxObjectShell::GetNext( *pSh ); } } else // no doc-name -> new doc { nDoc = SC_DOC_NEW; bDoIt = true; } if ( bDoIt && nTab >= nTableCount ) // if necessary append nTab = SC_TAB_APPEND; } else { OUString aDefaultName; rDoc.GetName( rViewData.GetTabNo(), aDefaultName ); ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); ScopedVclPtr pDlg(pFact->CreateScMoveTableDlg(GetFrameWeld(), aDefaultName)); SCTAB nTableCount = rDoc.GetTableCount(); ScMarkData& rMark = GetViewData().GetMarkData(); SCTAB nTabSelCount = rMark.GetSelectCount(); if(nTableCount==nTabSelCount) { pDlg->SetForceCopyTable(); } // We support direct renaming of sheet only when one sheet // is selected. pDlg->EnableRenameTable(nTabSelCount == 1); if ( pDlg->Execute() == RET_OK ) { nDoc = pDlg->GetSelectedDocument(); nTab = pDlg->GetSelectedTable(); bCpy = pDlg->GetCopyTable(); bool bRna = pDlg->GetRenameTable(); // Leave aTabName string empty, when Rename is FALSE. if( bRna ) { pDlg->GetTabNameString( aTabName ); } bDoIt = true; OUString aFoundDocName; if ( nDoc != SC_DOC_NEW ) { ScDocShell* pSh = ScDocShell::GetShellByNum( nDoc ); if (pSh) { aFoundDocName = pSh->GetTitle(); if ( !pSh->GetDocument().IsDocEditable() ) { ErrorMessage(STR_READONLYERR); bDoIt = false; } } } rReq.AppendItem( SfxStringItem( FID_TAB_MOVE, aFoundDocName ) ); // 1-based table, if not APPEND SCTAB nBasicTab = ( nTab <= MAXTAB ) ? (nTab+1) : nTab; rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast(nBasicTab) ) ); rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) ); } } if( bDoIt ) { rReq.Done(); // record, while doc is active MoveTable( nDoc, nTab, bCpy, &aTabName ); } } break; case FID_TAB_DUPLICATE: { // Get info about current document and selected tab SCTAB nTab = rViewData.GetTabNo(); OUString aDocName = GetViewData().GetDocShell()->GetTitle(); sal_uInt16 nDoc = 0; bool bCpy = true; SfxObjectShell* pSh = SfxObjectShell::GetFirst(); ScDocShell* pScSh = nullptr; sal_uInt16 i = 0; // Determine the index of the current document while ( pSh ) { pScSh = dynamic_cast( pSh ); if( pScSh ) { pScSh->GetTitle(); if (aDocName == pScSh->GetTitle()) { nDoc = i; break; } // Only count ScDocShell i++; } pSh = SfxObjectShell::GetNext( *pSh ); } MoveTable( nDoc, nTab + 1, bCpy ); } break; case FID_DELETE_TABLE: { bool bHasIndex = (pReqArgs != nullptr); // allow removing via the Index/FID_DELETE_TABLE parameter SCTAB nTabNr = nCurrentTab; if (bHasIndex) { const SfxPoolItem* pItem; if (pReqArgs->HasItem(FID_DELETE_TABLE, &pItem)) { nTabNr = static_cast(pItem)->GetValue(); // inserting is 1-based, let's be consistent if (nTabNr > 0) --nTabNr; } } bool bDoIt = bHasIndex; if (!bDoIt) { bool bTabWithPivotTable = false; if (rDoc.HasPivotTable()) { const ScDPCollection* pDPs = rDoc.GetDPCollection(); if (pDPs) { const ScMarkData::MarkedTabsType& rSelectedTabs = rViewData.GetMarkData().GetSelectedTabs(); const size_t nCount = pDPs->GetCount(); for (size_t i = 0; i < nCount; ++i) { const ScDPObject& rDPObj = (*pDPs)[i]; const ScSheetSourceDesc* pSheetSourceDesc = rDPObj.GetSheetDesc(); if (pSheetSourceDesc) { SCTAB nTabOut = rDPObj.GetOutRange().aStart.Tab(); SCTAB nTabSource = pSheetSourceDesc->GetSourceRange().aStart.Tab(); bool bTabOutSel = false; for (const SCTAB nSelTab : rSelectedTabs) { if (nSelTab == nTabSource) bTabWithPivotTable = true; if (nSelTab == nTabOut) bTabOutSel = true; if (bTabWithPivotTable && bTabOutSel) break; } // if both pivot table and data are selected // no need to warn for source data losing if (bTabWithPivotTable && bTabOutSel) bTabWithPivotTable = false; if (bTabWithPivotTable) break; } } } } SCTAB nTabSelCnt = rViewData.GetMarkData().GetSelectCount(); OUString aTabSelCnt = Application::GetSettings().GetUILocaleDataWrapper().getNum( nTabSelCnt, 0 ); OUString aQueryDeleteTab = ScResId( STR_QUERY_DELTAB, nTabSelCnt ) .replaceAll( "%d", aTabSelCnt ); if (bTabWithPivotTable) { OUString aStr = ScResId( STR_QUERY_PIVOTTABLE_DELTAB, nTabSelCnt ) .replaceAll( "%d", aTabSelCnt ) + " " + aQueryDeleteTab; std::unique_ptr xQueryBox(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Question, VclButtonsType::YesNo, aStr)); xQueryBox->set_default_response(RET_NO); // Hard warning as there is potential of data loss on deletion bDoIt = (RET_YES == xQueryBox->run()); } else { bool bHasData = false; ScMarkData& rMark = rViewData.GetMarkData(); for ( SCTAB i = 0; i < nTabCount && !bHasData; i++ ) { if ( rMark.GetTableSelect(i) && !rDoc.IsTabProtected(i) ) { SCCOL nStartCol; SCROW nStartRow; bHasData = rDoc.GetDataStart( i, nStartCol, nStartRow ); } } // Do not ask for confirmation if all selected tabs are empty if (bHasData) { std::unique_ptr xQueryBox(Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Question, VclButtonsType::YesNo, aQueryDeleteTab)); xQueryBox->set_default_response(RET_YES); // no parameter given, ask for confirmation bDoIt = (RET_YES == xQueryBox->run()); } else bDoIt = true; } } if (bDoIt) { SCTAB nNewTab = nCurrentTab; std::vector TheTabs; if (bHasIndex) { // sheet no. provided by the parameter TheTabs.push_back(nTabNr); if (nNewTab > nTabNr && nNewTab > 0) --nNewTab; } else { SCTAB nFirstTab = 0; bool bTabFlag = false; ScMarkData& rMark = rViewData.GetMarkData(); for (SCTAB i = 0; i < nTabCount; i++) { if (rMark.GetTableSelect(i) && !rDoc.IsTabProtected(i)) { TheTabs.push_back(i); bTabFlag = true; if (nNewTab == i && i+1 < nTabCount) nNewTab++; } if (!bTabFlag) nFirstTab = i; } if (nNewTab >= nTabCount - static_cast(TheTabs.size())) nNewTab = nFirstTab; } rViewData.SetTabNo(nNewTab); DeleteTables(TheTabs); TheTabs.clear(); rReq.Done(); } } break; case FID_TAB_RTL: { ScDocShell* pDocSh = rViewData.GetDocShell(); ScDocFunc &rFunc = pDocSh->GetDocFunc(); bool bSet = !rDoc.IsLayoutRTL( nCurrentTab ); const ScMarkData& rMark = rViewData.GetMarkData(); if ( rMark.GetSelectCount() != 0 ) { // handle several sheets SfxUndoManager* pUndoManager = pDocSh->GetUndoManager(); OUString aUndo = ScResId( STR_UNDO_TAB_RTL ); pUndoManager->EnterListAction( aUndo, aUndo, 0, rViewData.GetViewShell()->GetViewShellId() ); for (const auto& rTab : rMark) rFunc.SetLayoutRTL( rTab, bSet ); pUndoManager->LeaveListAction(); } else rFunc.SetLayoutRTL( nCurrentTab, bSet ); } break; case FID_TAB_TOGGLE_GRID: { bool bShowGrid = rViewData.GetShowGrid(); rViewData.SetShowGrid(!bShowGrid); SfxBindings& rBindings = GetViewFrame().GetBindings(); rBindings.Invalidate( FID_TAB_TOGGLE_GRID ); ScDocShellModificator aModificator(*rViewData.GetDocShell()); aModificator.SetDocumentModified(); PaintGrid(); rReq.Done(); } break; case FID_TAB_SET_TAB_BG_COLOR: case FID_TAB_MENU_SET_TAB_BG_COLOR: { if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR ) nSlot = FID_TAB_SET_TAB_BG_COLOR; SCTAB nTabNr = rViewData.GetTabNo(); ScMarkData& rMark = rViewData.GetMarkData(); SCTAB nTabSelCount = rMark.GetSelectCount(); if ( !rDoc.IsDocEditable() ) break; if ( rDoc.IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1 break; if( pReqArgs != nullptr ) { bool bDone = false; const SfxPoolItem* pItem; Color aColor; if( pReqArgs->HasItem( nSlot, &pItem ) ) aColor = static_cast(pItem)->GetValue(); if ( nTabSelCount > 1 ) { std::unique_ptr pTabColorList(new ScUndoTabColorInfo::List); for (const auto& rTab : rMark) { if ( !rDoc.IsTabProtected(rTab) ) { ScUndoTabColorInfo aTabColorInfo(rTab); aTabColorInfo.maNewTabBgColor = aColor; pTabColorList->push_back(aTabColorInfo); } } bDone = SetTabBgColor( *pTabColorList ); } else { bDone = SetTabBgColor( aColor, nCurrentTab ); //ScViewFunc.SetTabBgColor } if( bDone ) { rReq.Done( *pReqArgs ); } } else { sal_uInt16 nRet = RET_OK; /// temp bool bDone = false; /// temp Color aTabBgColor = rDoc.GetTabBgColor( nCurrentTab ); ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); ScopedVclPtr pDlg(pFact->CreateScTabBgColorDlg( GetFrameWeld(), ScResId(SCSTR_SET_TAB_BG_COLOR), ScResId(SCSTR_NO_TAB_BG_COLOR), aTabBgColor)); while ( !bDone && nRet == RET_OK ) { nRet = pDlg->Execute(); if( nRet == RET_OK ) { Color aSelectedColor; pDlg->GetSelectedColor(aSelectedColor); std::unique_ptr pTabColorList(new ScUndoTabColorInfo::List); if ( nTabSelCount > 1 ) { for (const auto& rTab : rMark) { if ( !rDoc.IsTabProtected(rTab) ) { ScUndoTabColorInfo aTabColorInfo(rTab); aTabColorInfo.maNewTabBgColor = aSelectedColor; pTabColorList->push_back(aTabColorInfo); } } bDone = SetTabBgColor( *pTabColorList ); } else { bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor } if ( bDone ) { rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) ); rReq.Done(); } else { if( rReq.IsAPI() ) { #if HAVE_FEATURE_SCRIPTING StarBASIC::Error( ERRCODE_BASIC_SETPROP_FAILED ); #endif } } } } } } break; case FID_TAB_EVENTS: { ScDocShell* pDocSh = rViewData.GetDocShell(); uno::Reference xEvents( new ScSheetEventsObj( pDocSh, nCurrentTab ) ); uno::Reference xFrame = GetViewFrame().GetFrame().GetFrameInterface(); SvxAbstractDialogFactory* pDlgFactory = SvxAbstractDialogFactory::Create(); ScopedVclPtr pDialog( pDlgFactory->CreateSvxMacroAssignDlg( GetFrameWeld(), xFrame, false, xEvents, 0 ) ); if ( pDialog->Execute() == RET_OK ) { // the dialog modifies the settings directly } } break; case FID_TOGGLEHIDDENCOLROW: { svtools::EditableColorConfig aEditableConfig; svtools::ColorConfigValue aValue = aEditableConfig.GetColorValue(svtools::CALCHIDDENROWCOL); aValue.bIsVisible = !aValue.bIsVisible; aEditableConfig.SetColorValue(svtools::CALCHIDDENROWCOL, aValue); } break; default: OSL_FAIL("unknown message for ViewShell"); break; } } void ScTabViewShell::GetStateTable( SfxItemSet& rSet ) { ScViewData& rViewData = GetViewData(); ScDocument& rDoc = rViewData.GetDocument(); ScDocShell* pDocShell = rViewData.GetDocShell(); ScMarkData& rMark = GetViewData().GetMarkData(); SCTAB nTab = rViewData.GetTabNo(); SCTAB nTabCount = rDoc.GetTableCount(); SCTAB nTabSelCount = rMark.GetSelectCount(); SfxWhichIter aIter(rSet); sal_uInt16 nWhich = aIter.FirstWhich(); while ( nWhich ) { switch ( nWhich ) { case FID_TABLE_VISIBLE: rSet.Put( SfxBoolItem( nWhich, rDoc.IsVisible(nTab) )); break; case FID_TABLE_HIDE: { sal_uInt16 nVis = 0; // enable menu : check to make sure we won't hide all sheets. we need at least one visible at all times. for ( SCTAB i=0; i < nTabCount && nVis 1 ) rSet.DisableItem( nWhich ); } break; case FID_DELETE_TABLE: { if ( rDoc.GetChangeTrack() ) rSet.DisableItem( nWhich ); else { sal_uInt16 nVis = 0; for ( SCTAB i=0; i < nTabCount && nVis<2; i++ ) if (rDoc.IsVisible(i)) ++nVis; if ( rDoc.IsTabProtected(nTab) || !rDoc.IsDocEditable() || nVis < 2 || nTabSelCount == nTabCount) rSet.DisableItem( nWhich ); } } break; case FID_INS_TABLE: case FID_INS_TABLE_EXT: case FID_TAB_APPEND: if ( !rDoc.IsDocEditable() || nTabCount > MAXTAB || ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->IsDocShared() ) ) rSet.DisableItem( nWhich ); break; case FID_TAB_MOVE: if ( !rDoc.IsDocEditable() || rDoc.GetChangeTrack() != nullptr || nTabCount > MAXTAB) rSet.DisableItem( nWhich ); break; case FID_TAB_DUPLICATE: if ( !rDoc.IsDocEditable() || rDoc.GetChangeTrack() != nullptr || nTabCount > MAXTAB) rSet.DisableItem( nWhich ); break; // FID_TAB_MENU_RENAME - "rename" from Menu // FID_TAB_RENAME - "name"-property for Basic case FID_TAB_MENU_RENAME: if ( !rDoc.IsDocEditable() || rDoc.IsTabProtected(nTab) ||nTabSelCount > 1 || ( pDocShell && pDocShell->IsDocShared() ) ) rSet.DisableItem( nWhich ); break; case FID_TAB_RENAME: { OUString aTabName; rDoc.GetName( nTab, aTabName ); rSet.Put( SfxStringItem( nWhich, aTabName )); } break; case FID_TAB_RTL: { if ( !SvtCTLOptions().IsCTLFontEnabled() ) rSet.DisableItem( nWhich ); else rSet.Put( SfxBoolItem( nWhich, rDoc.IsLayoutRTL( nTab ) ) ); } break; case FID_TAB_MENU_SET_TAB_BG_COLOR: { if ( !rDoc.IsDocEditable() || ( pDocShell && pDocShell->IsDocShared() ) || rDoc.IsTabProtected(nTab) ) rSet.DisableItem( nWhich ); } break; case FID_TAB_SET_TAB_BG_COLOR: { Color aColor = rDoc.GetTabBgColor( nTab ); rSet.Put( SvxColorItem( aColor, nWhich ) ); } break; case FID_TAB_TOGGLE_GRID: rSet.Put( SfxBoolItem(nWhich, rViewData.GetShowGrid()) ); break; } nWhich = aIter.NextWhich(); } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */