cid#1607171 Data race condition
[LibreOffice.git] / sc / source / ui / view / tabvwsh3.cxx
blob8d5888a5b5f3898e9356b36ef3523c6eb6369e99
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sfx2/bindings.hxx>
21 #include <sfx2/dispatch.hxx>
22 #include <sfx2/passwd.hxx>
23 #include <sfx2/request.hxx>
24 #include <sfx2/sidebar/Sidebar.hxx>
25 #include <svl/ptitem.hxx>
26 #include <svl/stritem.hxx>
27 #include <tools/urlobj.hxx>
28 #include <sfx2/objface.hxx>
29 #include <vcl/vclenum.hxx>
30 #include <vcl/uitest/logger.hxx>
31 #include <vcl/uitest/eventdescription.hxx>
33 #include <globstr.hrc>
34 #include <strings.hrc>
35 #include <scmod.hxx>
36 #include <appoptio.hxx>
37 #include <tabvwsh.hxx>
38 #include <document.hxx>
39 #include <sc.hrc>
40 #include <helpids.h>
41 #include <inputwin.hxx>
42 #include <scresid.hxx>
43 #include <docsh.hxx>
44 #include <rangeutl.hxx>
45 #include <reffact.hxx>
46 #include <tabprotection.hxx>
47 #include <protectiondlg.hxx>
48 #include <duplicaterecordsdlg.hxx>
49 #include <markdata.hxx>
51 #include <svl/ilstitem.hxx>
52 #include <vector>
54 #include <svx/zoomslideritem.hxx>
55 #include <svx/svxdlg.hxx>
56 #include <comphelper/lok.hxx>
57 #include <comphelper/string.hxx>
58 #include <com/sun/star/uno/Reference.h>
59 #include <com/sun/star/sheet/XCellRangeData.hpp>
60 #include <sfx2/lokhelper.hxx>
61 #include <scabstdlg.hxx>
62 #include <officecfg/Office/Calc.hxx>
64 #include <basegfx/utils/zoomtools.hxx>
66 #include <svx/dialog/ThemeDialog.hxx>
67 #include <ThemeColorChanger.hxx>
69 namespace
71 void collectUIInformation(const OUString& aZoom)
73 EventDescription aDescription;
74 aDescription.aID = "grid_window";
75 aDescription.aParameters = {{"ZOOM", aZoom}};
76 aDescription.aAction = "SET";
77 aDescription.aKeyWord = "ScGridWinUIObject";
78 aDescription.aParent = "MainWindow";
79 UITestLogger::getInstance().logEvent(aDescription);
82 enum class DetectFlags
84 NONE,
85 RANGE,
86 ADDRESS
89 struct ScRefFlagsAndType
91 ScRefFlags nResult;
92 DetectFlags eDetected;
95 ScRefFlagsAndType lcl_ParseRangeOrAddress(ScRange& rScRange, ScAddress& rScAddress,
96 const OUString& aAddress, const ScDocument& rDoc,
97 SCCOL nCurCol, SCROW nCurRow)
99 ScRefFlagsAndType aRet;
101 // Relative address parsing needs current position.
102 // row,col parameters, not col,row!
103 ScAddress::Details aDetails( rDoc.GetAddressConvention(), nCurRow, nCurCol);
105 // start with the address convention set in the document
106 aRet.nResult = rScRange.Parse(aAddress, rDoc, aDetails);
107 if (aRet.nResult & ScRefFlags::VALID)
109 aRet.eDetected = DetectFlags::RANGE;
110 return aRet;
113 aRet.nResult = rScAddress.Parse(aAddress, rDoc, aDetails);
114 if (aRet.nResult & ScRefFlags::VALID)
116 aRet.eDetected = DetectFlags::ADDRESS;
117 return aRet;
120 // try the default Calc (A1) address convention
121 aRet.nResult = rScRange.Parse(aAddress, rDoc);
122 if (aRet.nResult & ScRefFlags::VALID)
124 aRet.eDetected = DetectFlags::RANGE;
125 return aRet;
128 aRet.nResult = rScAddress.Parse(aAddress, rDoc);
129 if (aRet.nResult & ScRefFlags::VALID)
131 aRet.eDetected = DetectFlags::ADDRESS;
132 return aRet;
135 // try the Excel A1 address convention
136 aRet.nResult = rScRange.Parse(aAddress, rDoc, formula::FormulaGrammar::CONV_XL_A1);
137 if (aRet.nResult & ScRefFlags::VALID)
139 aRet.eDetected = DetectFlags::RANGE;
140 return aRet;
143 // try the Excel A1 address convention
144 aRet.nResult = rScAddress.Parse(aAddress, rDoc, formula::FormulaGrammar::CONV_XL_A1);
145 if (aRet.nResult & ScRefFlags::VALID)
147 aRet.eDetected = DetectFlags::ADDRESS;
148 return aRet;
151 // try Excel R1C1 address convention
152 aDetails.eConv = formula::FormulaGrammar::CONV_XL_R1C1;
153 aRet.nResult = rScRange.Parse(aAddress, rDoc, aDetails);
154 if (aRet.nResult & ScRefFlags::VALID)
156 aRet.eDetected = DetectFlags::RANGE;
157 return aRet;
160 aRet.nResult = rScAddress.Parse(aAddress, rDoc, aDetails);
161 if (aRet.nResult & ScRefFlags::VALID)
163 aRet.eDetected = DetectFlags::ADDRESS;
164 return aRet;
167 aRet.nResult = ScRefFlags::ZERO;
168 aRet.eDetected = DetectFlags::NONE;
170 return aRet;
174 void ScTabViewShell::FinishProtectTable()
176 TabChanged();
177 UpdateInputHandler(true); // to immediately enable input again
178 SelectionChanged();
181 void ScTabViewShell::ExecProtectTable( SfxRequest& rReq )
183 ScModule* pScMod = ScModule::get();
184 const SfxItemSet* pReqArgs = rReq.GetArgs();
185 ScDocument& rDoc = GetViewData().GetDocument();
186 SCTAB nTab = GetViewData().GetTabNo();
187 bool bOldProtection = rDoc.IsTabProtected(nTab);
189 if( pReqArgs )
191 const SfxPoolItem* pItem;
192 bool bNewProtection = !bOldProtection;
193 if( pReqArgs->HasItem( FID_PROTECT_TABLE, &pItem ) )
194 bNewProtection = static_cast<const SfxBoolItem*>(pItem)->GetValue();
195 if( bNewProtection == bOldProtection )
197 rReq.Ignore();
198 return;
202 if (bOldProtection)
204 // Unprotect a protected sheet.
206 const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
207 if (pProtect && pProtect->isProtectedWithPass())
209 std::shared_ptr<SfxRequest> xRequest;
210 if (!pReqArgs)
212 xRequest = std::make_shared<SfxRequest>(rReq);
213 rReq.Ignore(); // the 'old' request is not relevant any more
216 OUString aText( ScResId(SCSTR_PASSWORDOPT) );
217 auto pDlg = std::make_shared<SfxPasswordDialog>(GetFrameWeld(), &aText);
218 pDlg->set_title(ScResId(SCSTR_UNPROTECTTAB));
219 pDlg->SetMinLen(0);
220 pDlg->set_help_id(GetStaticInterface()->GetSlot(FID_PROTECT_TABLE)->GetCommand());
221 pDlg->SetEditHelpId(HID_PASSWD_TABLE);
223 pDlg->PreRun();
225 weld::DialogController::runAsync(pDlg, [this, nTab, pDlg,
226 xRequest=std::move(xRequest)](sal_Int32 response) {
227 if (response == RET_OK)
229 OUString aPassword = pDlg->GetPassword();
230 Unprotect(nTab, aPassword);
232 if (xRequest)
234 xRequest->AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
235 xRequest->Done();
237 FinishProtectTable();
239 return;
241 else
242 // this sheet is not password-protected.
243 Unprotect(nTab, OUString());
245 if (!pReqArgs)
247 rReq.AppendItem( SfxBoolItem(FID_PROTECT_TABLE, false) );
248 rReq.Done();
251 else
253 // Protect a current sheet.
254 std::shared_ptr<SfxRequest> xRequest;
255 if (!pReqArgs)
257 xRequest = std::make_shared<SfxRequest>(rReq);
258 rReq.Ignore(); // the 'old' request is not relevant any more
261 auto pDlg = std::make_shared<ScTableProtectionDlg>(GetFrameWeld());
263 const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
264 if (pProtect)
265 pDlg->SetDialogData(*pProtect);
266 weld::DialogController::runAsync(pDlg, [this, pDlg, pScMod, nTab,
267 xRequest=std::move(xRequest)](sal_uInt32 nResult) {
268 if (nResult == RET_OK)
270 pScMod->InputEnterHandler();
272 ScTableProtection aNewProtect;
273 pDlg->WriteData(aNewProtect);
274 ProtectSheet(nTab, aNewProtect);
275 if (xRequest)
277 xRequest->AppendItem( SfxBoolItem(FID_PROTECT_TABLE, true) );
278 xRequest->Done();
281 FinishProtectTable();
283 return;
285 FinishProtectTable();
288 void ScTabViewShell::Execute( SfxRequest& rReq )
290 SfxViewFrame& rThisFrame = GetViewFrame();
291 SfxBindings& rBindings = rThisFrame.GetBindings();
292 ScModule* pScMod = ScModule::get();
293 const SfxItemSet* pReqArgs = rReq.GetArgs();
294 sal_uInt16 nSlot = rReq.GetSlot();
296 if (nSlot != SID_CURRENTCELL) // comes with MouseButtonUp
297 HideListBox(); // Autofilter-DropDown-Listbox
299 switch ( nSlot )
301 case FID_INSERT_FILE:
303 const SfxPoolItem* pItem;
304 if ( pReqArgs &&
305 pReqArgs->GetItemState(FID_INSERT_FILE,true,&pItem) == SfxItemState::SET )
307 OUString aFileName = static_cast<const SfxStringItem*>(pItem)->GetValue();
309 // insert position
311 Point aInsertPos;
312 if ( pReqArgs->GetItemState(FN_PARAM_1,true,&pItem) == SfxItemState::SET )
313 aInsertPos = static_cast<const SfxPointItem*>(pItem)->GetValue();
314 else
315 aInsertPos = GetInsertPos();
317 // as Link?
319 bool bAsLink = false;
320 if ( pReqArgs->GetItemState(FN_PARAM_2,true,&pItem) == SfxItemState::SET )
321 bAsLink = static_cast<const SfxBoolItem*>(pItem)->GetValue();
323 // execute
325 PasteFile( aInsertPos, aFileName, bAsLink );
328 break;
330 case SID_OPENDLG_EDIT_PRINTAREA:
332 sal_uInt16 nId = ScPrintAreasDlgWrapper::GetChildWindowId();
333 SfxChildWindow* pWnd = rThisFrame.GetChildWindow( nId );
335 pScMod->SetRefDialog( nId, pWnd == nullptr );
337 break;
339 case SID_CHANGE_PRINTAREA:
341 if ( pReqArgs ) // OK from dialog
343 OUString aPrintStr;
344 OUString aRowStr;
345 OUString aColStr;
346 bool bEntire = false;
347 const SfxPoolItem* pItem;
348 if ( pReqArgs->GetItemState( SID_CHANGE_PRINTAREA, true, &pItem ) == SfxItemState::SET )
349 aPrintStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
350 if ( pReqArgs->GetItemState( FN_PARAM_2, true, &pItem ) == SfxItemState::SET )
351 aRowStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
352 if ( pReqArgs->GetItemState( FN_PARAM_3, true, &pItem ) == SfxItemState::SET )
353 aColStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
354 if ( pReqArgs->GetItemState( FN_PARAM_4, true, &pItem ) == SfxItemState::SET )
355 bEntire = static_cast<const SfxBoolItem*>(pItem)->GetValue();
357 SetPrintRanges( bEntire, &aPrintStr, &aColStr, &aRowStr, false );
359 rReq.Done();
362 break;
364 case SID_ADD_PRINTAREA:
365 case SID_DEFINE_PRINTAREA: // menu or basic
367 bool bAdd = ( nSlot == SID_ADD_PRINTAREA );
368 if ( pReqArgs )
370 OUString aPrintStr;
371 const SfxPoolItem* pItem;
372 if ( pReqArgs->GetItemState( SID_DEFINE_PRINTAREA, true, &pItem ) == SfxItemState::SET )
373 aPrintStr = static_cast<const SfxStringItem*>(pItem)->GetValue();
374 SetPrintRanges( false, &aPrintStr, nullptr, nullptr, bAdd );
376 else
378 SetPrintRanges( false, nullptr, nullptr, nullptr, bAdd ); // from selection
379 rReq.Done();
382 break;
384 case SID_DELETE_PRINTAREA:
386 // Clear currently defined print range if any, and reset it to
387 // print entire sheet which is the default.
388 OUString aEmpty;
389 SetPrintRanges(true, &aEmpty, nullptr, nullptr, false);
390 rReq.Done();
392 break;
394 case FID_DEL_MANUALBREAKS:
395 RemoveManualBreaks();
396 rReq.Done();
397 break;
399 case FID_ADJUST_PRINTZOOM:
400 AdjustPrintZoom();
401 rReq.Done();
402 break;
404 case FID_RESET_PRINTZOOM:
405 SetPrintZoom( 100 ); // 100%, not on pages
406 rReq.Done();
407 break;
409 case SID_FORMATPAGE:
410 case SID_STATUS_PAGESTYLE:
411 case SID_HFEDIT:
412 GetViewData().GetDocShell()->
413 ExecutePageStyle( *this, rReq, GetViewData().GetTabNo() );
414 break;
416 case SID_JUMPTOMARK:
417 case SID_CURRENTCELL:
418 if ( pReqArgs )
420 OUString aAddress;
421 const SfxPoolItem* pItem;
422 if ( pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET )
423 aAddress = static_cast<const SfxStringItem*>(pItem)->GetValue();
424 else if ( nSlot == SID_JUMPTOMARK && pReqArgs->GetItemState(
425 SID_JUMPTOMARK, true, &pItem ) == SfxItemState::SET )
426 aAddress = static_cast<const SfxStringItem*>(pItem)->GetValue();
428 // #i14927# SID_CURRENTCELL with a single cell must unmark if FN_PARAM_1
429 // isn't set (for recorded macros, because IsAPI is no longer available).
430 // ScGridWindow::MouseButtonUp no longer executes the slot for a single
431 // cell if there is a multi selection.
432 bool bUnmark = ( nSlot == SID_CURRENTCELL );
433 if ( pReqArgs->GetItemState( FN_PARAM_1, true, &pItem ) == SfxItemState::SET )
434 bUnmark = static_cast<const SfxBoolItem*>(pItem)->GetValue();
436 bool bAlignToCursor = true;
437 if (pReqArgs->GetItemState(FN_PARAM_2, true, &pItem) == SfxItemState::SET)
438 bAlignToCursor = static_cast<const SfxBoolItem*>(pItem)->GetValue();
440 bool bForceGlobalName = false;
441 if (pReqArgs->GetItemState(FN_PARAM_3, true, &pItem) == SfxItemState::SET)
442 bForceGlobalName = static_cast<const SfxBoolItem*>(pItem)->GetValue();
444 if ( nSlot == SID_JUMPTOMARK )
446 // URL has to be decoded for escaped characters (%20)
447 aAddress = INetURLObject::decode( aAddress,
448 INetURLObject::DecodeMechanism::WithCharset );
451 bool bFound = false;
452 ScViewData& rViewData = GetViewData();
453 ScDocument& rDoc = rViewData.GetDocument();
454 ScMarkData& rMark = rViewData.GetMarkData();
455 ScRange aScRange;
456 ScAddress aScAddress;
457 ScRefFlagsAndType aResult = lcl_ParseRangeOrAddress(aScRange, aScAddress, aAddress, rDoc,
458 rViewData.GetCurX(), rViewData.GetCurY());
459 ScRefFlags nResult = aResult.nResult;
460 SCTAB nTab = rViewData.GetTabNo();
461 bool bMark = true;
463 // Is this a range ?
464 if (aResult.eDetected == DetectFlags::RANGE)
466 if ( nResult & ScRefFlags::TAB_3D )
468 if( aScRange.aStart.Tab() != nTab )
470 nTab = aScRange.aStart.Tab();
471 SetTabNo( nTab );
474 else
476 aScRange.aStart.SetTab( nTab );
477 aScRange.aEnd.SetTab( nTab );
480 // Is this a cell ?
481 else if (aResult.eDetected == DetectFlags::ADDRESS)
483 if ( nResult & ScRefFlags::TAB_3D )
485 if( aScAddress.Tab() != nTab )
487 nTab = aScAddress.Tab();
488 SetTabNo( nTab );
491 else
492 aScAddress.SetTab( nTab );
494 aScRange = ScRange( aScAddress, aScAddress );
495 // cells should not be marked
496 bMark = false;
498 // Is it a named area (first named ranges then database ranges)?
499 else
501 const RutlNameScope eScope = (bForceGlobalName ? RUTL_NAMES_GLOBAL : RUTL_NAMES);
502 ScAddress::Details aDetails( rDoc.GetAddressConvention(), rViewData.GetCurY(), rViewData.GetCurX());
503 if (ScRangeUtil::MakeRangeFromName( aAddress, rDoc, nTab, aScRange, eScope, aDetails, true) ||
504 ScRangeUtil::MakeRangeFromName( aAddress, rDoc, nTab, aScRange, RUTL_DBASE, aDetails, true))
506 nResult |= ScRefFlags::VALID;
507 if( aScRange.aStart.Tab() != nTab )
509 nTab = aScRange.aStart.Tab();
510 SetTabNo( nTab );
515 if ( !(nResult & ScRefFlags::VALID) && comphelper::string::isdigitAsciiString(aAddress) )
517 sal_Int32 nNumeric = aAddress.toInt32();
518 if ( nNumeric > 0 && nNumeric <= rDoc.MaxRow()+1 )
520 // one-based row numbers
522 aScAddress.SetRow( static_cast<SCROW>(nNumeric - 1) );
523 aScAddress.SetCol( rViewData.GetCurX() );
524 aScAddress.SetTab( nTab );
525 aScRange = ScRange( aScAddress, aScAddress );
526 bMark = false;
527 nResult = ScRefFlags::VALID;
531 if ( !rDoc.ValidRow(aScRange.aStart.Row()) || !rDoc.ValidRow(aScRange.aEnd.Row()) )
532 nResult = ScRefFlags::ZERO;
534 // we have found something
535 if( nResult & ScRefFlags::VALID )
537 bFound = true;
538 SCCOL nCol = aScRange.aStart.Col();
539 SCROW nRow = aScRange.aStart.Row();
540 bool bNothing = ( rViewData.GetCurX()==nCol && rViewData.GetCurY()==nRow );
542 // mark
543 if( bMark )
545 if (rMark.IsMarked()) // is the same range already marked?
547 ScRange aOldMark = rMark.GetMarkArea();
548 aOldMark.PutInOrder();
549 ScRange aCurrent = aScRange;
550 aCurrent.PutInOrder();
551 bNothing = ( aCurrent == aOldMark );
553 else
554 bNothing = false;
556 if (!bNothing)
557 MarkRange( aScRange, false ); // cursor comes after...
559 else
561 // remove old selection, unless bUnmark argument is sal_False (from navigator)
562 if( bUnmark )
564 MoveCursorAbs( nCol, nRow,
565 SC_FOLLOW_NONE, false, false );
569 // and set cursor
571 // consider merged cells:
572 rDoc.SkipOverlapped(nCol, nRow, nTab);
574 // navigator calls are not part of the API!!!
576 if( bNothing )
578 if (rReq.IsAPI())
579 rReq.Ignore(); // if macro, then nothing
580 else
581 rReq.Done(); // then at least paint it
583 else
585 rViewData.ResetOldCursor();
586 SetCursor( nCol, nRow );
587 rBindings.Invalidate( SID_CURRENTCELL );
588 rBindings.Update( nSlot );
590 if (!rReq.IsAPI())
591 rReq.Done();
594 if (bAlignToCursor)
596 // align to cursor even if the cursor position hasn't changed,
597 // because the cursor may be set outside the visible area.
598 AlignToCursor( nCol, nRow, SC_FOLLOW_JUMP );
599 if ( nSlot == SID_JUMPTOMARK && comphelper::LibreOfficeKit::isActive() )
600 rViewData.GetActiveWin()->notifyKitCellFollowJump();
603 rReq.SetReturnValue( SfxStringItem( SID_CURRENTCELL, aAddress ) );
606 if (!bFound) // no valid range
608 // if it is a sheet name, then switch (for Navigator/URL)
610 SCTAB nNameTab;
611 if ( rDoc.GetTable( aAddress, nNameTab ) )
613 bFound = true;
614 if ( nNameTab != nTab )
615 SetTabNo( nNameTab );
619 if ( !bFound && nSlot == SID_JUMPTOMARK )
621 // test graphics objects (only for URL)
623 bFound = SelectObject( aAddress );
626 if (!bFound && !rReq.IsAPI())
627 ErrorMessage( STR_ERR_INVALID_AREA );
629 break;
631 case SID_CURRENTOBJECT:
632 if ( pReqArgs )
634 OUString aName = static_cast<const SfxStringItem&>(pReqArgs->Get(nSlot)).GetValue();
635 SelectObject( aName );
637 break;
639 case SID_CURRENTTAB:
641 SCTAB nTab;
642 ScViewData& rViewData = GetViewData();
643 ScDocument& rDoc = rViewData.GetDocument();
644 SCTAB nTabCount = rDoc.GetTableCount();
645 if ( pReqArgs ) // command from Navigator with nTab
647 // sheet for basic is one-based
648 nTab = static_cast<const SfxUInt16Item&>(pReqArgs->Get(nSlot)).GetValue() - 1;
650 else // command from Menu: ask for nTab
652 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
654 ScopedVclPtr<AbstractScGoToTabDlg> pDlg(pFact->CreateScGoToTabDlg(GetFrameWeld()));
655 pDlg->SetDescription(
656 ScResId( STR_DLG_SELECTTABLE_TITLE ),
657 ScResId( STR_DLG_SELECTTABLE_MASK ),
658 ScResId( STR_DLG_SELECTTABLE_LBNAME ),
659 GetStaticInterface()->GetSlot(SID_CURRENTTAB)->GetCommand(), HID_GOTOTABLEMASK, HID_GOTOTABLE );
661 // fill all table names and select current tab
662 OUString aTabName;
663 for( nTab = 0; nTab < nTabCount; ++nTab )
665 if( rDoc.IsVisible( nTab ) )
667 rDoc.GetName( nTab, aTabName );
668 pDlg->Insert( aTabName, rViewData.GetTabNo() == nTab );
672 if( pDlg->Execute() == RET_OK )
674 if( !rDoc.GetTable( pDlg->GetSelectedEntry(), nTab ) )
675 nTab = nTabCount;
676 pDlg.disposeAndClear();
678 else
680 rReq.Ignore();
683 if ( nTab < nTabCount )
685 SetTabNo( nTab );
686 rBindings.Update( nSlot );
688 if( ! rReq.IsAPI() )
689 rReq.Done();
691 //! otherwise an error ?
693 break;
695 case SID_CURRENTDOC:
696 if ( pReqArgs )
698 OUString aStrDocName( static_cast<const SfxStringItem&>(pReqArgs->
699 Get(nSlot)).GetValue() );
701 SfxViewFrame* pViewFrame = nullptr;
702 ScDocShell* pDocSh = static_cast<ScDocShell*>(SfxObjectShell::GetFirst());
703 bool bFound = false;
705 // search for ViewFrame to be activated
707 while ( pDocSh && !bFound )
709 if ( pDocSh->GetTitle() == aStrDocName )
711 pViewFrame = SfxViewFrame::GetFirst( pDocSh );
712 bFound = ( nullptr != pViewFrame );
715 pDocSh = static_cast<ScDocShell*>(SfxObjectShell::GetNext( *pDocSh ));
718 if ( bFound )
719 pViewFrame->GetFrame().Appear();
721 rReq.Ignore();//XXX is handled by SFX
723 break;
725 case SID_PRINTPREVIEW:
727 if ( !rThisFrame.GetFrame().IsInPlace() ) // not for OLE
729 // print preview is now always in the same frame as the tab view
730 // -> always switch this frame back to normal view
731 // (ScPreviewShell ctor reads view data)
733 // #102785#; finish input
734 pScMod->InputEnterHandler();
736 rThisFrame.GetDispatcher()->Execute( SID_VIEWSHELL1, SfxCallMode::ASYNCHRON );
738 // else error (e.g. Ole)
740 break;
742 case SID_DETECTIVE_DEL_ALL:
743 DetectiveDelAll();
744 rReq.Done();
745 break;
747 // SID_TABLE_ACTIVATE and SID_MARKAREA are called by basic for the
748 // hidden View, to mark/switch on the visible View:
750 case SID_TABLE_ACTIVATE:
751 OSL_FAIL("old slot SID_TABLE_ACTIVATE");
752 break;
754 case SID_REPAINT:
755 PaintGrid();
756 PaintTop();
757 PaintLeft();
758 PaintExtras();
759 rReq.Done();
760 break;
762 case FID_NORMALVIEWMODE:
763 case FID_PAGEBREAKMODE:
765 bool bWantPageBreak = nSlot == FID_PAGEBREAKMODE;
767 // check whether there is an explicit argument, use it
768 const SfxPoolItem* pItem;
769 if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
771 bool bItemValue = static_cast<const SfxBoolItem*>(pItem)->GetValue();
772 bWantPageBreak = (nSlot == FID_PAGEBREAKMODE) == bItemValue;
775 if( GetViewData().IsPagebreakMode() != bWantPageBreak )
777 SetPagebreakMode( bWantPageBreak );
778 UpdatePageBreakData();
779 SetCurSubShell( GetCurObjectSelectionType(), true );
780 PaintGrid();
781 PaintTop();
782 PaintLeft();
783 rBindings.Invalidate( nSlot );
784 rReq.AppendItem( SfxBoolItem( nSlot, true ) );
785 rReq.Done();
788 break;
790 case FID_FUNCTION_BOX:
792 // First make sure that the sidebar is visible
793 rThisFrame.ShowChildWindow(SID_SIDEBAR);
795 ::sfx2::sidebar::Sidebar::ShowPanel(u"ScFunctionsPanel",
796 rThisFrame.GetFrame().GetFrameInterface(),
797 true);
798 rReq.Done ();
800 break;
802 case FID_TOGGLESYNTAX:
804 bool bSet = !GetViewData().IsSyntaxMode();
805 const SfxPoolItem* pItem;
806 if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
807 bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue();
808 GetViewData().SetSyntaxMode( bSet );
809 PaintGrid();
810 rBindings.Invalidate( FID_TOGGLESYNTAX );
811 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
812 rReq.Done();
814 break;
815 case FID_HANDLEDUPLICATERECORDS:
817 using namespace com::sun::star;
818 table::CellRangeAddress aCellRange;
819 uno::Reference<sheet::XSpreadsheet> xActiveSheet;
820 DuplicatesResponse aResponse;
821 bool bHasData = true;
823 if (pReqArgs)
825 const SfxPoolItem* pItem;
827 if (pReqArgs->HasItem(FID_HANDLEDUPLICATERECORDS, &pItem))
828 aResponse.bRemove = static_cast<const SfxBoolItem*>(pItem)->GetValue();
829 if (pReqArgs->HasItem(FN_PARAM_1, &pItem))
830 aResponse.bIncludesHeaders = static_cast<const SfxBoolItem*>(pItem)->GetValue();
831 if (pReqArgs->HasItem(FN_PARAM_2, &pItem))
832 aResponse.bDuplicateRows = static_cast<const SfxBoolItem*>(pItem)->GetValue();
833 if (pReqArgs->HasItem(FN_PARAM_3, &pItem))
834 aCellRange.StartColumn = static_cast<const SfxInt32Item*>(pItem)->GetValue();
835 if (pReqArgs->HasItem(FN_PARAM_4, &pItem))
836 aCellRange.StartRow = static_cast<const SfxInt32Item*>(pItem)->GetValue();
837 if (pReqArgs->HasItem(FN_PARAM_5, &pItem))
838 aCellRange.EndColumn = static_cast<const SfxInt32Item*>(pItem)->GetValue();
839 if (pReqArgs->HasItem(FN_PARAM_6, &pItem))
840 aCellRange.EndRow = static_cast<const SfxInt32Item*>(pItem)->GetValue();
841 if (pReqArgs->HasItem(FN_PARAM_7, &pItem))
842 aCellRange.Sheet = static_cast<const SfxInt32Item*>(pItem)->GetValue();
844 // check for the tab range here
845 if (aCellRange.StartColumn < 0 || aCellRange.StartRow < 0
846 || aCellRange.EndColumn < 0 || aCellRange.EndRow < 0
847 || aCellRange.StartRow > aCellRange.EndRow
848 || aCellRange.StartColumn > aCellRange.EndColumn || aCellRange.Sheet < 0
849 || aCellRange.Sheet >= GetViewData().GetDocument().GetTableCount())
851 rReq.Done();
852 break;
854 xActiveSheet = GetViewData().GetViewShell()->GetRangeWithSheet(aCellRange,
855 bHasData, true);
856 if (!bHasData)
858 rReq.Done();
859 break;
861 int nLenEntries
862 = (aResponse.bDuplicateRows ? aCellRange.EndColumn - aCellRange.StartColumn
863 : aCellRange.EndRow - aCellRange.StartRow);
864 for (int i = 0; i <= nLenEntries; ++i)
865 aResponse.vEntries.push_back(i);
867 else
869 xActiveSheet = GetViewData().GetViewShell()->GetRangeWithSheet(aCellRange,
870 bHasData, false);
871 if (bHasData)
873 if (!GetViewData().GetMarkData().IsMarked())
874 GetViewData().GetViewShell()->ExtendSingleSelection(aCellRange);
876 uno::Reference<frame::XModel> xModel(GetViewData().GetDocShell()->GetModel());
877 uno::Reference<sheet::XSheetCellRange> xSheetRange(
878 xActiveSheet->getCellRangeByPosition(
879 aCellRange.StartColumn, aCellRange.StartRow, aCellRange.EndColumn,
880 aCellRange.EndRow),
881 uno::UNO_QUERY);
883 ScRange aRange(ScAddress(aCellRange.StartColumn, aCellRange.StartRow,
884 GetViewData().GetTabNo()),
885 ScAddress(aCellRange.EndColumn, aCellRange.EndRow,
886 GetViewData().GetTabNo()));
888 uno::Reference<sheet::XCellRangeData> xCellRangeData(xSheetRange,
889 uno::UNO_QUERY);
890 uno::Sequence<uno::Sequence<uno::Any>> aDataArray
891 = xCellRangeData->getDataArray();
893 ScDuplicateRecordsDlg aDlg(GetFrameWeld(), aDataArray, GetViewData(), aRange);
895 bHasData = aDlg.run();
896 if (bHasData)
897 aResponse = aDlg.GetDialogData();
898 else
900 rReq.Done();
901 break;
904 else
906 std::unique_ptr<weld::MessageDialog> aDialog(
907 Application::CreateMessageDialog(GetFrameWeld(),
908 VclMessageType::Warning,
909 VclButtonsType::Ok,
910 ScResId(STR_DUPLICATERECORDSDLG_NODATAFOUND)));
911 aDialog->set_title(ScResId(STR_DUPLICATERECORDSDLG_WARNING));
912 aDialog->run();
916 if (bHasData)
917 GetViewData().GetViewShell()->HandleDuplicateRecords(
918 xActiveSheet, aCellRange, aResponse.bRemove, aResponse.bIncludesHeaders,
919 aResponse.bDuplicateRows, aResponse.vEntries);
921 rReq.Done();
923 break;
924 case FID_TOGGLECOLROWHIGHLIGHTING:
926 bool bNewVal = !officecfg::Office::Calc::Content::Display::ColumnRowHighlighting::get();
928 auto pChange(comphelper::ConfigurationChanges::create());
929 officecfg::Office::Calc::Content::Display::ColumnRowHighlighting::set(bNewVal, pChange);
930 pChange->commit();
932 rReq.AppendItem(SfxBoolItem(nSlot, bNewVal));
933 rReq.Done();
935 break;
936 case FID_TOGGLEHEADERS:
938 bool bSet = !GetViewData().IsHeaderMode();
939 const SfxPoolItem* pItem;
940 if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
941 bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue();
942 GetViewData().SetHeaderMode( bSet );
943 RepeatResize();
944 rBindings.Invalidate( FID_TOGGLEHEADERS );
945 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
946 rReq.Done();
948 break;
950 case FID_TOGGLEFORMULA:
952 ScViewData& rViewData = GetViewData();
953 const ScViewOptions& rOpts = rViewData.GetOptions();
954 bool bFormulaMode = !rOpts.GetOption( VOPT_FORMULAS );
955 const SfxPoolItem *pItem;
956 if( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
957 bFormulaMode = static_cast<const SfxBoolItem *>(pItem)->GetValue();
959 ScViewOptions aSetOpts = rOpts;
960 aSetOpts.SetOption( VOPT_FORMULAS, bFormulaMode );
961 rViewData.SetOptions( aSetOpts );
962 ScDocument& rDoc = rViewData.GetDocument();
963 rDoc.SetViewOptions(aSetOpts);
965 rViewData.GetDocShell()->PostPaintGridAll();
967 rBindings.Invalidate( FID_TOGGLEFORMULA );
968 rReq.AppendItem( SfxBoolItem( nSlot, bFormulaMode ) );
969 rReq.Done();
971 break;
973 case FID_TOGGLEINPUTLINE:
975 sal_uInt16 nId = ScInputWindowWrapper::GetChildWindowId();
976 SfxChildWindow* pWnd = rThisFrame.GetChildWindow( nId );
977 bool bSet = ( pWnd == nullptr );
978 const SfxPoolItem* pItem;
979 if ( pReqArgs && pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
980 bSet = static_cast<const SfxBoolItem*>(pItem)->GetValue();
982 rThisFrame.SetChildWindow( nId, bSet );
983 rBindings.Invalidate( FID_TOGGLEINPUTLINE );
984 rReq.AppendItem( SfxBoolItem( nSlot, bSet ) );
985 rReq.Done();
987 break;
989 // handling for SID_ZOOM_IN and SID_ZOOM_OUT is ScTabView::ScrollCommand
990 // CommandWheelMode::ZOOM inspired
991 case SID_ZOOM_IN:
992 case SID_ZOOM_OUT:
994 HideNoteMarker();
996 if (!GetViewData().GetViewShell()->GetViewFrame().GetFrame().IsInPlace())
998 // for ole inplace editing, the scale is defined by the visarea and client size
999 // and can't be changed directly
1001 const Fraction& rOldY = GetViewData().GetZoomY();
1002 sal_uInt16 nOld = tools::Long(rOldY * 100);
1003 sal_uInt16 nNew;
1004 if (SID_ZOOM_OUT == nSlot)
1005 nNew = std::max(MINZOOM, basegfx::zoomtools::zoomOut(nOld));
1006 else
1007 nNew = std::min(MAXZOOM, basegfx::zoomtools::zoomIn(nOld));
1008 if ( nNew != nOld)
1010 bool bSyncZoom = pScMod->GetAppOptions().GetSynchronizeZoom();
1011 SetZoomType(SvxZoomType::PERCENT, bSyncZoom);
1012 Fraction aFract(nNew, 100);
1013 SetZoom(aFract, aFract, bSyncZoom);
1014 PaintGrid();
1015 PaintTop();
1016 PaintLeft();
1017 rBindings.Invalidate(SID_ATTR_ZOOM);
1018 rBindings.Invalidate(SID_ATTR_ZOOMSLIDER);
1019 rBindings.Invalidate(SID_ZOOM_IN);
1020 rBindings.Invalidate(SID_ZOOM_OUT);
1021 rReq.Done();
1025 break;
1027 case SID_ATTR_ZOOM: // status row
1028 case FID_SCALE:
1030 bool bSyncZoom = pScMod->GetAppOptions().GetSynchronizeZoom();
1031 SvxZoomType eOldZoomType = GetZoomType();
1032 SvxZoomType eNewZoomType = eOldZoomType;
1033 const Fraction& rOldY = GetViewData().GetZoomY(); // Y is shown
1034 sal_uInt16 nOldZoom = static_cast<sal_uInt16>(tools::Long( rOldY * 100 ));
1035 sal_uInt16 nZoom = nOldZoom;
1036 bool bCancel = false;
1038 if ( pReqArgs )
1040 const SvxZoomItem& rZoomItem = pReqArgs->Get(SID_ATTR_ZOOM);
1042 eNewZoomType = rZoomItem.GetType();
1043 nZoom = rZoomItem.GetValue();
1045 else
1047 SfxItemSetFixed<SID_ATTR_ZOOM, SID_ATTR_ZOOM> aSet( GetPool() );
1048 SvxZoomItem aZoomItem( eOldZoomType, nOldZoom, SID_ATTR_ZOOM );
1049 ScopedVclPtr<AbstractSvxZoomDialog> pDlg;
1050 ScMarkData& rMark = GetViewData().GetMarkData();
1051 SvxZoomEnableFlags nBtnFlags = SvxZoomEnableFlags::N50
1052 | SvxZoomEnableFlags::N75
1053 | SvxZoomEnableFlags::N100
1054 | SvxZoomEnableFlags::N150
1055 | SvxZoomEnableFlags::N200
1056 | SvxZoomEnableFlags::WHOLEPAGE
1057 | SvxZoomEnableFlags::PAGEWIDTH;
1059 if ( rMark.IsMarked() || rMark.IsMultiMarked() )
1060 nBtnFlags = nBtnFlags | SvxZoomEnableFlags::OPTIMAL;
1062 aZoomItem.SetValueSet( nBtnFlags );
1063 aSet.Put( aZoomItem );
1064 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1065 pDlg.disposeAndReset(pFact->CreateSvxZoomDialog(GetFrameWeld(), aSet));
1066 pDlg->SetLimits( MINZOOM, MAXZOOM );
1068 bCancel = ( RET_CANCEL == pDlg->Execute() );
1070 // bCancel is True only if we were in the previous if block,
1071 // so no need to check again pDlg
1072 if ( !bCancel )
1074 const SvxZoomItem& rZoomItem = pDlg->GetOutputItemSet()->
1075 Get( SID_ATTR_ZOOM );
1077 eNewZoomType = rZoomItem.GetType();
1078 nZoom = rZoomItem.GetValue();
1082 if ( !bCancel )
1084 if ( eNewZoomType == SvxZoomType::PERCENT )
1086 if ( nZoom < MINZOOM ) nZoom = MINZOOM;
1087 if ( nZoom > MAXZOOM ) nZoom = MAXZOOM;
1089 else
1091 nZoom = CalcZoom( eNewZoomType, nOldZoom );
1092 bCancel = nZoom == 0;
1095 switch ( eNewZoomType )
1097 case SvxZoomType::WHOLEPAGE:
1098 case SvxZoomType::PAGEWIDTH:
1099 SetZoomType( eNewZoomType, bSyncZoom );
1100 break;
1102 default:
1103 SetZoomType( SvxZoomType::PERCENT, bSyncZoom );
1107 if ( nZoom != nOldZoom && !bCancel )
1109 if (!GetViewData().IsPagebreakMode())
1111 ScAppOptions aNewOpt = pScMod->GetAppOptions();
1112 aNewOpt.SetZoom( nZoom );
1113 aNewOpt.SetZoomType( GetZoomType() );
1114 pScMod->SetAppOptions( aNewOpt );
1116 Fraction aFract( nZoom, 100 );
1117 SetZoom( aFract, aFract, bSyncZoom );
1118 PaintGrid();
1119 PaintTop();
1120 PaintLeft();
1121 rBindings.Invalidate( SID_ATTR_ZOOM );
1122 rReq.AppendItem( SvxZoomItem( GetZoomType(), nZoom, TypedWhichId<SvxZoomItem>(nSlot) ) );
1123 rReq.Done();
1126 break;
1128 case SID_ATTR_ZOOMSLIDER:
1130 const SfxPoolItem* pItem = nullptr;
1131 bool bSyncZoom = pScMod->GetAppOptions().GetSynchronizeZoom();
1132 if ( pReqArgs && pReqArgs->GetItemState(SID_ATTR_ZOOMSLIDER, true, &pItem) == SfxItemState::SET )
1134 const sal_uInt16 nCurrentZoom = static_cast<const SvxZoomSliderItem *>(pItem)->GetValue();
1135 if( nCurrentZoom )
1137 SetZoomType( SvxZoomType::PERCENT, bSyncZoom );
1138 if (!GetViewData().IsPagebreakMode())
1140 ScAppOptions aNewOpt = pScMod->GetAppOptions();
1141 aNewOpt.SetZoom( nCurrentZoom );
1142 collectUIInformation(OUString::number(nCurrentZoom));
1143 aNewOpt.SetZoomType( GetZoomType() );
1144 pScMod->SetAppOptions( aNewOpt );
1146 Fraction aFract( nCurrentZoom,100 );
1147 SetZoom( aFract, aFract, bSyncZoom );
1148 PaintGrid();
1149 PaintTop();
1150 PaintLeft();
1151 rBindings.Invalidate( SID_ATTR_ZOOMSLIDER );
1152 rBindings.Invalidate( SID_ZOOM_IN );
1153 rBindings.Invalidate( SID_ZOOM_OUT );
1154 rReq.Done();
1158 break;
1160 case FID_TAB_SELECTALL:
1161 SelectAllTables();
1162 rReq.Done();
1163 break;
1165 case FID_TAB_DESELECTALL:
1166 DeselectAllTables();
1167 rReq.Done();
1168 break;
1170 case SID_SELECT_TABLES:
1172 ScViewData& rViewData = GetViewData();
1173 ScDocument& rDoc = rViewData.GetDocument();
1174 ScMarkData& rMark = rViewData.GetMarkData();
1175 SCTAB nTabCount = rDoc.GetTableCount();
1176 SCTAB nTab;
1178 ::std::vector < sal_Int32 > aIndexList;
1179 const SfxIntegerListItem* pItem = rReq.GetArg<SfxIntegerListItem>(SID_SELECT_TABLES);
1180 if ( pItem )
1181 aIndexList = pItem->GetList();
1182 else
1184 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1186 ScopedVclPtr<AbstractScShowTabDlg> pDlg(pFact->CreateScShowTabDlg(GetFrameWeld()));
1187 pDlg->SetDescription(
1188 ScResId( STR_DLG_SELECTTABLES_TITLE ),
1189 ScResId( STR_DLG_SELECTTABLES_LBNAME ),
1190 GetStaticInterface()->GetSlot(SID_SELECT_TABLES)->GetCommand(), HID_SELECTTABLES );
1192 // fill all table names with selection state
1193 OUString aTabName;
1194 for( nTab = 0; nTab < nTabCount; ++nTab )
1196 rDoc.GetName( nTab, aTabName );
1197 pDlg->Insert( aTabName, rMark.GetTableSelect( nTab ) );
1200 if( pDlg->Execute() == RET_OK )
1202 aIndexList = pDlg->GetSelectedRows();
1203 pDlg.disposeAndClear();
1204 rReq.AppendItem( SfxIntegerListItem( SID_SELECT_TABLES, std::vector(aIndexList) ) );
1206 else
1207 rReq.Ignore();
1210 if ( !aIndexList.empty() )
1212 sal_uInt16 nSelCount = aIndexList.size();
1213 sal_uInt16 nSelIx;
1214 SCTAB nFirstVisTab = 0;
1216 // special case: only hidden tables selected -> do nothing
1217 bool bVisSelected = false;
1218 for( nSelIx = 0; !bVisSelected && (nSelIx < nSelCount); ++nSelIx )
1220 nFirstVisTab = static_cast<SCTAB>(aIndexList[nSelIx]);
1221 bVisSelected = rDoc.IsVisible( nFirstVisTab );
1223 if( !bVisSelected )
1224 nSelCount = 0;
1226 // select the tables
1227 if( nSelCount )
1229 for( nTab = 0; nTab < nTabCount; ++nTab )
1230 rMark.SelectTable( nTab, false );
1232 for( nSelIx = 0; nSelIx < nSelCount; ++nSelIx )
1233 rMark.SelectTable( static_cast<SCTAB>(aIndexList[nSelIx]), true );
1235 // activate another table, if current is deselected
1236 if( !rMark.GetTableSelect( rViewData.GetTabNo() ) )
1238 rMark.SelectTable( nFirstVisTab, true );
1239 SetTabNo( nFirstVisTab );
1242 rViewData.GetDocShell()->PostPaintExtras();
1243 SfxBindings& rBind = rViewData.GetBindings();
1244 rBind.Invalidate( FID_FILL_TAB );
1245 rBind.Invalidate( FID_TAB_DESELECTALL );
1248 rReq.Done();
1251 break;
1253 case SID_OUTLINE_DELETEALL:
1254 RemoveAllOutlines();
1255 rReq.Done();
1256 break;
1258 case SID_AUTO_OUTLINE:
1259 AutoOutline();
1260 rReq.Done();
1261 break;
1263 case SID_WINDOW_SPLIT:
1265 ScSplitMode eHSplit = GetViewData().GetHSplitMode();
1266 ScSplitMode eVSplit = GetViewData().GetVSplitMode();
1267 if ( eHSplit == SC_SPLIT_NORMAL || eVSplit == SC_SPLIT_NORMAL ) // remove
1268 RemoveSplit();
1269 else if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // normal
1270 FreezeSplitters( false );
1271 else // create
1272 SplitAtCursor();
1273 rReq.Done();
1275 InvalidateSplit();
1277 break;
1279 case SID_WINDOW_FIX:
1281 if (!comphelper::LibreOfficeKit::isActive())
1283 ScSplitMode eHSplit = GetViewData().GetHSplitMode();
1284 ScSplitMode eVSplit = GetViewData().GetVSplitMode();
1285 if ( eHSplit == SC_SPLIT_FIX || eVSplit == SC_SPLIT_FIX ) // remove
1286 RemoveSplit();
1287 else
1288 FreezeSplitters( true, SC_SPLIT_METHOD_CURSOR); // create or fixate
1289 rReq.Done();
1290 InvalidateSplit();
1292 else
1294 ScViewData& rViewData = GetViewData();
1295 SCTAB nThisTab = rViewData.GetTabNo();
1296 bool bChangedX = false, bChangedY = false;
1297 if (rViewData.GetLOKSheetFreezeIndex(true) > 0 ||
1298 rViewData.GetLOKSheetFreezeIndex(false) > 0 ) // remove freeze
1300 bChangedX = rViewData.RemoveLOKFreeze();
1301 } // create or fixate
1302 else
1304 bChangedX = rViewData.SetLOKSheetFreezeIndex(rViewData.GetCurX(), true); // Freeze column
1305 bChangedY = rViewData.SetLOKSheetFreezeIndex(rViewData.GetCurY(), false); // Freeze row
1308 rReq.Done();
1309 if (bChangedX || bChangedY)
1311 rBindings.Invalidate( SID_WINDOW_FIX );
1312 rBindings.Invalidate( SID_WINDOW_FIX_COL );
1313 rBindings.Invalidate( SID_WINDOW_FIX_ROW );
1314 // Invalidate the slot for all views on the same tab of the document.
1315 SfxLokHelper::forEachOtherView(this, [nThisTab](ScTabViewShell* pOther) {
1316 ScViewData& rOtherViewData = pOther->GetViewData();
1317 if (rOtherViewData.GetTabNo() != nThisTab)
1318 return;
1320 SfxBindings& rOtherBind = rOtherViewData.GetBindings();
1321 rOtherBind.Invalidate( SID_WINDOW_FIX );
1322 rOtherBind.Invalidate( SID_WINDOW_FIX_COL );
1323 rOtherBind.Invalidate( SID_WINDOW_FIX_ROW );
1325 if (!GetViewData().GetDocShell()->IsReadOnly())
1326 GetViewData().GetDocShell()->SetDocumentModified();
1330 break;
1332 case SID_WINDOW_FIX_COL:
1333 case SID_WINDOW_FIX_ROW:
1335 bool bIsCol = (nSlot == SID_WINDOW_FIX_COL);
1336 sal_Int32 nFreezeIndex = 1;
1337 if (const SfxInt32Item* pItem = rReq.GetArg<SfxInt32Item>(FN_PARAM_1))
1339 nFreezeIndex = pItem->GetValue();
1340 if (nFreezeIndex < 0)
1341 nFreezeIndex = 0;
1344 if (comphelper::LibreOfficeKit::isActive())
1346 ScViewData& rViewData = GetViewData();
1347 SCTAB nThisTab = rViewData.GetTabNo();
1348 bool bChanged = rViewData.SetLOKSheetFreezeIndex(nFreezeIndex, bIsCol);
1349 rReq.Done();
1350 if (bChanged)
1352 rBindings.Invalidate( SID_WINDOW_FIX );
1353 rBindings.Invalidate(nSlot);
1354 // Invalidate the slot for all views on the same tab of the document.
1355 SfxLokHelper::forEachOtherView(this, [nSlot, nThisTab](ScTabViewShell* pOther) {
1356 ScViewData& rOtherViewData = pOther->GetViewData();
1357 if (rOtherViewData.GetTabNo() != nThisTab)
1358 return;
1360 SfxBindings& rOtherBind = rOtherViewData.GetBindings();
1361 rOtherBind.Invalidate( SID_WINDOW_FIX );
1362 rOtherBind.Invalidate(nSlot);
1364 if (!GetViewData().GetDocShell()->IsReadOnly())
1365 GetViewData().GetDocShell()->SetDocumentModified();
1368 else
1370 FreezeSplitters( true, bIsCol ? SC_SPLIT_METHOD_COL : SC_SPLIT_METHOD_ROW, nFreezeIndex);
1371 rReq.Done();
1372 InvalidateSplit();
1375 break;
1377 case FID_CHG_SHOW:
1379 sal_uInt16 nId = ScHighlightChgDlgWrapper::GetChildWindowId();
1380 SfxChildWindow* pWnd = rThisFrame.GetChildWindow( nId );
1382 pScMod->SetRefDialog( nId, pWnd == nullptr );
1384 break;
1386 case FID_CHG_ACCEPT:
1388 rThisFrame.ToggleChildWindow(ScAcceptChgDlgWrapper::GetChildWindowId());
1389 GetViewFrame().GetBindings().Invalidate(FID_CHG_ACCEPT);
1390 rReq.Done ();
1393 sal_uInt16 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
1394 SfxChildWindow* pWnd = rThisFrame.GetChildWindow( nId );
1396 pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True );
1399 break;
1401 case FID_CHG_COMMENT:
1403 ScViewData& rData = GetViewData();
1404 ScAddress aCursorPos( rData.GetCurX(), rData.GetCurY(), rData.GetTabNo() );
1405 ScDocShell* pDocSh = rData.GetDocShell();
1407 ScChangeAction* pAction = pDocSh->GetChangeAction( aCursorPos );
1408 if ( pAction )
1410 const SfxPoolItem* pItem;
1411 if ( pReqArgs &&
1412 pReqArgs->GetItemState( nSlot, true, &pItem ) == SfxItemState::SET &&
1413 dynamic_cast<const SfxStringItem*>( pItem) != nullptr )
1415 OUString aComment = static_cast<const SfxStringItem*>(pItem)->GetValue();
1416 pDocSh->SetChangeComment( pAction, aComment );
1417 rReq.Done();
1419 else
1421 pDocSh->ExecuteChangeCommentDialog(pAction, GetFrameWeld());
1422 rReq.Done();
1426 break;
1428 case SID_CREATE_SW_DRAWVIEW:
1429 // is called by Forms, when the DrawView has to be created with all
1430 // the extras
1431 if (!GetScDrawView())
1433 GetViewData().GetDocShell()->MakeDrawLayer();
1434 rBindings.InvalidateAll(false);
1436 break;
1438 case FID_PROTECT_DOC:
1440 ScDocument& rDoc = GetViewData().GetDocument();
1442 if( pReqArgs )
1444 const SfxPoolItem* pItem;
1445 if( pReqArgs->HasItem( FID_PROTECT_DOC, &pItem ) &&
1446 static_cast<const SfxBoolItem*>(pItem)->GetValue() == rDoc.IsDocProtected() )
1448 rReq.Ignore();
1449 break;
1453 ScDocProtection* pProtect = rDoc.GetDocProtection();
1454 if (pProtect && pProtect->isProtected())
1456 bool bCancel = false;
1457 OUString aPassword;
1459 if (pProtect->isProtectedWithPass())
1461 OUString aText(ScResId(SCSTR_PASSWORD));
1463 SfxPasswordDialog aDlg(GetFrameWeld(), &aText);
1464 aDlg.set_title(ScResId(SCSTR_UNPROTECTDOC));
1465 aDlg.SetMinLen(0);
1466 aDlg.set_help_id(GetStaticInterface()->GetSlot(FID_PROTECT_DOC)->GetCommand());
1467 aDlg.SetEditHelpId(HID_PASSWD_DOC);
1469 if (aDlg.run() == RET_OK)
1470 aPassword = aDlg.GetPassword();
1471 else
1472 bCancel = true;
1474 if (!bCancel)
1476 Unprotect( TABLEID_DOC, aPassword );
1477 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, false ) );
1478 rReq.Done();
1481 else
1483 OUString aText(ScResId(SCSTR_PASSWORDOPT));
1485 SfxPasswordDialog aDlg(GetFrameWeld(), &aText);
1486 aDlg.set_title(ScResId(SCSTR_PROTECTDOC));
1487 aDlg.SetMinLen( 0 );
1488 aDlg.set_help_id(GetStaticInterface()->GetSlot(FID_PROTECT_DOC)->GetCommand());
1489 aDlg.SetEditHelpId(HID_PASSWD_DOC);
1490 aDlg.ShowExtras(SfxShowExtras::CONFIRM);
1491 aDlg.SetConfirmHelpId(HID_PASSWD_DOC_CONFIRM);
1493 if (aDlg.run() == RET_OK)
1495 OUString aPassword = aDlg.GetPassword();
1496 ProtectDoc( aPassword );
1497 rReq.AppendItem( SfxBoolItem( FID_PROTECT_DOC, true ) );
1498 rReq.Done();
1501 rBindings.Invalidate( FID_PROTECT_DOC );
1503 break;
1505 case FID_PROTECT_TABLE:
1506 ExecProtectTable( rReq );
1507 break;
1509 case SID_THEME_DIALOG:
1511 MakeDrawLayer();
1512 ScViewData& rViewData = GetViewData();
1513 ScDocument& rDocument = rViewData.GetDocument();
1514 ScDrawLayer* pModel = rDocument.GetDrawLayer();
1515 auto const& pTheme = pModel->getTheme();
1516 if (pTheme)
1518 vcl::Window* pWin = rViewData.GetActiveWin();
1519 auto pDialog = std::make_shared<svx::ThemeDialog>(pWin ? pWin->GetFrameWeld() : nullptr, pTheme.get());
1520 weld::DialogController::runAsync(pDialog, [this, pDialog](sal_uInt32 nResult) {
1521 if (RET_OK != nResult)
1522 return;
1524 auto pColorSet = pDialog->getCurrentColorSet();
1525 if (pColorSet)
1527 sc::ThemeColorChanger aChanger(*GetViewData().GetDocShell());
1528 aChanger.apply(pColorSet);
1532 rReq.Done();
1534 break;
1535 case SID_OPT_LOCALE_CHANGED :
1536 { // locale changed, SYSTEM number formats changed => repaint cell contents
1537 PaintGrid();
1538 rReq.Done();
1540 break;
1542 default:
1543 OSL_FAIL("Unknown Slot at ScTabViewShell::Execute");
1544 break;
1548 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */