LibreOffice Module sc (master) 1
tabvwshf.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <config_features.h>
21
22#include <memory>
23
24#include <sfx2/request.hxx>
25#include <sfx2/bindings.hxx>
26#include <sfx2/viewfrm.hxx>
27#include <basic/sbstar.hxx>
28#include <basic/sberrors.hxx>
29#include <svl/ctloptions.hxx>
30#include <svl/stritem.hxx>
31#include <svl/whiter.hxx>
32#include <vcl/svapp.hxx>
33#include <vcl/weld.hxx>
34#include <sfx2/objface.hxx>
35#include <svx/svxdlg.hxx>
36#include <editeng/colritem.hxx>
37
38#include <tabvwsh.hxx>
39#include <sc.hrc>
40#include <helpids.h>
41#include <docsh.hxx>
42#include <document.hxx>
43#include <scresid.hxx>
44#include <globstr.hrc>
45#include <strings.hrc>
46#include <docfunc.hxx>
47#include <eventuno.hxx>
48#include <dpobject.hxx>
49#include <dpshttab.hxx>
50
51#include <scabstdlg.hxx>
52
53#include <tabbgcolor.hxx>
54#include <markdata.hxx>
55
56#include <vector>
57
58using std::unique_ptr;
59using namespace com::sun::star;
60
62{
63 ScViewData& rViewData = GetViewData();
64 ScDocument& rDoc = rViewData.GetDocument();
65
66 SCTAB nCurrentTab = rViewData.GetTabNo();
67 SCTAB nTabCount = rDoc.GetTableCount();
68 sal_uInt16 nSlot = rReq.GetSlot();
69 const SfxItemSet* pReqArgs = rReq.GetArgs();
70
71 HideListBox(); // Autofilter-DropDown-Listbox
72
73 switch ( nSlot )
74 {
75 case FID_TABLE_VISIBLE:
76 {
77 OUString aName;
78 rDoc.GetName( nCurrentTab, aName );
79
80 bool bVisible=true;
81 if( pReqArgs != nullptr )
82 {
83 const SfxPoolItem* pItem;
84 if( pReqArgs->HasItem( FID_TABLE_VISIBLE, &pItem ) )
85 bVisible = static_cast<const SfxBoolItem*>(pItem)->GetValue();
86 }
87
88 if( ! bVisible ) // fade out
89 {
90 if ( rDoc.IsDocEditable() )
91 {
92 ScMarkData& rMark = rViewData.GetMarkData();
93 HideTable( rMark );
94 }
95 }
96 else // fade in
97 {
98 std::vector<OUString> rNames { aName };
99 ShowTable( rNames );
100 }
101 }
102 break;
103
104 case FID_TABLE_HIDE:
105 {
106 if ( rDoc.IsDocEditable() )
107 {
108 ScMarkData& rMark = rViewData.GetMarkData();
109 SCTAB nActiveTab = -1;
110 // For the cases when user right clicks on a non-active tab and hides it. This case is possible for Online.
111 if (pReqArgs)
112 {
113 const SfxPoolItem *pItem;
114 if( pReqArgs->HasItem( FID_TABLE_HIDE, &pItem ) )
115 {
116 SCTAB nTabNumber = static_cast<const SfxInt16Item*>(pItem)->GetValue();
117 // Does selected sheets (tabs) list include the sheet to be hidden?
118 std::set<SCTAB>::iterator it = rMark.GetSelectedTabs().find(nTabNumber);
119 if (it == rMark.GetSelectedTabs().end())
120 {
121 // No it doesn't, so we won't shift the selected tab. Let's remember its position.
122 nActiveTab = GetViewData().GetTabNo();
123 }
124 rMark.SelectOneTable(nTabNumber);
125 }
126 }
127 HideTable( rMark, nActiveTab );
128 }
129 }
130 break;
131
132 case FID_TABLE_SHOW:
133 {
134 std::vector<OUString> rNames;
135 if ( pReqArgs )
136 {
137 const SfxPoolItem* pItem;
138 if( pReqArgs->HasItem( FID_TABLE_SHOW, &pItem ) )
139 {
140 OUString aName = static_cast<const SfxStringItem*>(pItem)->GetValue();
141 rNames.push_back(aName);
142 ShowTable( rNames );
143
144 if( ! rReq.IsAPI() )
145 rReq.Done();
146 }
147 }
148 else
149 {
151
153
154 OUString aTabName;
155 bool bFirst = true;
156 for ( SCTAB i=0; i != nTabCount; i++ )
157 {
158 if (!rDoc.IsVisible(i))
159 {
160 rDoc.GetName( i, aTabName );
161 pDlg->Insert( aTabName, bFirst );
162 bFirst = false;
163 }
164 }
165
166 std::shared_ptr<SfxRequest> pReq = std::make_shared<SfxRequest>(rReq);
167 pDlg->StartExecuteAsync([this, pDlg, pReq](sal_Int32 nResult){
168 std::vector<OUString> sTables;
169 if (RET_OK == nResult)
170 {
171 std::vector<sal_Int32> aSelectedRows = pDlg->GetSelectedRows();
172 for (auto a : aSelectedRows)
173 {
174 OUString sTable = pDlg->GetEntry(a);
175 pReq->AppendItem( SfxStringItem( FID_TABLE_SHOW, sTable ) );
176 sTables.push_back(sTable);
177 }
178 ShowTable( sTables );
179 pReq->Done();
180 }
181 pDlg->disposeOnce();
182 });
183 rReq.Ignore();
184 }
185 }
186 break;
187
188 case FID_INS_TABLE:
189 case FID_INS_TABLE_EXT:
190 {
191 ScMarkData& rMark = rViewData.GetMarkData();
192 SCTAB nTabSelCount = rMark.GetSelectCount();
193 SCTAB nTabNr = nCurrentTab;
194
195 if ( !rDoc.IsDocEditable() )
196 break; // locked
197
198 if ( pReqArgs != nullptr ) // from basic
199 {
200 bool bOk = false;
201 const SfxPoolItem* pTabItem;
202 const SfxPoolItem* pNameItem;
203
204 if ( pReqArgs->HasItem( FN_PARAM_1, &pTabItem ) &&
205 pReqArgs->HasItem( nSlot, &pNameItem ) )
206 {
207 OUString aName = static_cast<const SfxStringItem*>(pNameItem)->GetValue();
209
210 // sheet number from basic: 1-based
211 // 0 is special, means adding at the end
212 nTabNr = static_cast<const SfxUInt16Item*>(pTabItem)->GetValue();
213 if (nTabNr == 0)
214 nTabNr = nTabCount;
215 else
216 --nTabNr;
217
218 if (nTabNr > nTabCount)
219 nTabNr = nTabCount;
220
221 bOk = InsertTable(aName, nTabNr);
222 }
223
224 if (bOk)
225 rReq.Done( *pReqArgs );
227 }
228 else // dialog
229 {
231
233 nTabSelCount, nSlot == FID_INS_TABLE_EXT));
234 if ( RET_OK == pDlg->Execute() )
235 {
236 if (pDlg->GetTablesFromFile())
237 {
238 std::vector<SCTAB> nTabs;
239 sal_uInt16 n = 0;
240 const OUString* pStr = pDlg->GetFirstTable( &n );
241 while ( pStr )
242 {
243 nTabs.push_back( static_cast<SCTAB>(n) );
244 pStr = pDlg->GetNextTable( &n );
245 }
246 bool bLink = pDlg->GetTablesAsLink();
247 if (!nTabs.empty())
248 {
249 if(pDlg->IsTableBefore())
250 {
251 ImportTables( pDlg->GetDocShellTables(), nTabs.size(), nTabs.data(),
252 bLink,nTabNr );
253 }
254 else
255 {
256 SCTAB nTabAfter = nTabNr+1;
257
258 for(SCTAB j=nCurrentTab+1;j<nTabCount;j++)
259 {
260 if(!rDoc.IsScenario(j))
261 {
262 nTabAfter=j;
263 break;
264 }
265 }
266
267 ImportTables( pDlg->GetDocShellTables(), nTabs.size(), nTabs.data(),
268 bLink,nTabAfter );
269 }
270 }
271 }
272 else
273 {
274 SCTAB nCount=pDlg->GetTableCount();
275 if(pDlg->IsTableBefore())
276 {
277 if(nCount==1 && !pDlg->GetFirstTable()->isEmpty())
278 {
279 rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
280 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabNr) + 1 ) ); // 1-based
281 rReq.Done();
282
283 InsertTable( *pDlg->GetFirstTable(), nTabNr );
284 }
285 else
286 {
287 std::vector<OUString> aNames(0);
288 InsertTables( aNames, nTabNr,nCount );
289 }
290 }
291 else
292 {
293 SCTAB nTabAfter = nTabNr+1;
294 SCTAB nSelHigh = rMark.GetLastSelected();
295
296 for(SCTAB j=nSelHigh+1;j<nTabCount;j++)
297 {
298 if(!rDoc.IsScenario(j))
299 {
300 nTabAfter=j;
301 break;
302 }
303 else // #101672#; increase nTabAfter, because it is possible that the scenario tables are the last
304 nTabAfter = j + 1;
305 }
306
307 if(nCount==1 && !pDlg->GetFirstTable()->isEmpty())
308 {
309 rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
310 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabAfter) + 1 ) ); // 1-based
311 rReq.Done();
312
313 InsertTable( *pDlg->GetFirstTable(), nTabAfter);
314 }
315 else
316 {
317 std::vector<OUString> aNames(0);
318 InsertTables( aNames, nTabAfter,nCount);
319 }
320 }
321 }
322 }
323 }
324 }
325 break;
326
327 case FID_TAB_APPEND:
328 case FID_TAB_RENAME:
329 case FID_TAB_MENU_RENAME:
330 {
331 // FID_TAB_MENU_RENAME - "rename" in menu
332 // FID_TAB_RENAME - "name"-property for basic
333 // equal execute, but MENU_RENAME may be disabled inside GetState
334
335 if ( nSlot == FID_TAB_MENU_RENAME )
336 nSlot = FID_TAB_RENAME; // equal execute
337
338 SCTAB nTabNr = rViewData.GetTabNo();
339 ScMarkData& rMark = rViewData.GetMarkData();
340 SCTAB nTabSelCount = rMark.GetSelectCount();
341
342 if ( !rDoc.IsDocEditable() )
343 break; // everything locked
344
345 if ( nSlot != FID_TAB_APPEND &&
346 ( rDoc.IsTabProtected( nTabNr ) || nTabSelCount > 1 ) )
347 break; // no rename
348
349 if( pReqArgs != nullptr )
350 {
351 bool bDone = false;
352 const SfxPoolItem* pItem;
353 OUString aName;
354
355 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
356 {
357 nTabNr = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
358
359 // inserting is 1-based, let's be consistent
360 if (nTabNr > 0)
361 --nTabNr;
362 }
363
364 if( pReqArgs->HasItem( nSlot, &pItem ) )
365 aName = static_cast<const SfxStringItem*>(pItem)->GetValue();
366
367 switch ( nSlot )
368 {
369 case FID_TAB_APPEND:
370 bDone = AppendTable( aName );
371 break;
372 case FID_TAB_RENAME:
373 bDone = RenameTable( aName, nTabNr );
374 break;
375 }
376
377 if( bDone )
378 {
379 rReq.Done( *pReqArgs );
380 }
381 }
382 else
383 {
384 sal_uInt16 nRet = RET_OK;
385 bool bDone = false;
386 OUString aErrMsg ( ScResId( STR_INVALIDTABNAME ) );
387 OUString aName;
388 OUString aDlgTitle;
389 OUString sHelpId;
390
391 switch ( nSlot )
392 {
393 case FID_TAB_APPEND:
394 aDlgTitle = ScResId(SCSTR_APDTABLE);
396 sHelpId = HID_SC_APPEND_NAME;
397 break;
398
399 case FID_TAB_RENAME:
400 aDlgTitle = ScResId(SCSTR_RENAMETAB);
401 rDoc.GetName( rViewData.GetTabNo(), aName );
402 sHelpId = HID_SC_RENAME_NAME;
403 break;
404 }
405
407
409 GetFrameWeld(), aDlgTitle, ScResId(SCSTR_NAME),
410 aName, GetStaticInterface()->GetSlot(nSlot)->GetCommand(),
411 sHelpId));
412
413
414 while ( !bDone && nRet == RET_OK )
415 {
416 nRet = pDlg->Execute();
417
418 if ( nRet == RET_OK )
419 {
420 aName = pDlg->GetInputString();
421
422 switch ( nSlot )
423 {
424 case FID_TAB_APPEND:
425 bDone = AppendTable( aName );
426 break;
427 case FID_TAB_RENAME:
428 bDone = RenameTable( aName, nTabNr );
429 break;
430 }
431
432 if ( bDone )
433 {
434 rReq.AppendItem( SfxStringItem( nSlot, aName ) );
435 rReq.Done();
436 }
437 else
438 {
439 if( rReq.IsAPI() )
440 {
441#if HAVE_FEATURE_SCRIPTING
442 StarBASIC::Error( ERRCODE_BASIC_SETPROP_FAILED ); // XXX error handling???
443#endif
444 }
445 else
446 {
447 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
448 VclMessageType::Warning, VclButtonsType::Ok, aErrMsg));
449 nRet = xBox->run();
450 }
451 }
452 }
453 }
454 }
455 }
456 break;
457
458 case FID_TAB_MOVE:
459 {
460 if ( rDoc.GetChangeTrack() != nullptr )
461 break; // if ChangeTracking is active, then no TabMove
462
463 bool bDoIt = false;
464 sal_uInt16 nDoc = 0;
465 SCTAB nTab = rViewData.GetTabNo();
466 bool bCpy = false, bUseCurrentDocument = false;
467 OUString aDocName;
468 OUString aTabName;
469
470 if( pReqArgs != nullptr )
471 {
472 SCTAB nTableCount = rDoc.GetTableCount();
473 const SfxPoolItem* pItem;
474
475 // if UseCurrentDocument(FN_PARAM_3) is true ignore the document name provided and use current document
476 if( pReqArgs->HasItem( FN_PARAM_3, &pItem ) )
477 bUseCurrentDocument = static_cast<const SfxBoolItem*>(pItem)->GetValue();
478
479 if (bUseCurrentDocument)
480 aDocName = GetViewData().GetDocShell()->GetTitle();
481 else if(pReqArgs->HasItem( FID_TAB_MOVE, &pItem ))
482 aDocName = static_cast<const SfxStringItem*>(pItem)->GetValue();
483
484 if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
485 {
486 // table is 1-based
487 nTab = static_cast<const SfxUInt16Item*>(pItem)->GetValue() - 1;
488 if ( nTab >= nTableCount )
489 nTab = SC_TAB_APPEND;
490 }
491 if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
492 bCpy = static_cast<const SfxBoolItem*>(pItem)->GetValue();
493
494 if (!aDocName.isEmpty())
495 {
497 ScDocShell* pScSh = nullptr;
498 sal_uInt16 i=0;
499
500 while ( pSh )
501 {
502 pScSh = dynamic_cast<ScDocShell*>( pSh );
503
504 if( pScSh )
505 {
506 pScSh->GetTitle();
507
508 if (aDocName == pScSh->GetTitle())
509 {
510 nDoc = i;
511 ScDocument& rDestDoc = pScSh->GetDocument();
512 nTableCount = rDestDoc.GetTableCount();
513 bDoIt = rDestDoc.IsDocEditable();
514 break;
515 }
516
517 i++; // only count ScDocShell
518 }
519 pSh = SfxObjectShell::GetNext( *pSh );
520 }
521 }
522 else // no doc-name -> new doc
523 {
524 nDoc = SC_DOC_NEW;
525 bDoIt = true;
526 }
527
528 if ( bDoIt && nTab >= nTableCount ) // if necessary append
529 nTab = SC_TAB_APPEND;
530 }
531 else
532 {
533 OUString aDefaultName;
534 rDoc.GetName( rViewData.GetTabNo(), aDefaultName );
535
537
539 aDefaultName));
540
541 SCTAB nTableCount = rDoc.GetTableCount();
543 SCTAB nTabSelCount = rMark.GetSelectCount();
544
545 if(nTableCount==nTabSelCount)
546 {
547 pDlg->SetForceCopyTable();
548 }
549
550 // We support direct renaming of sheet only when one sheet
551 // is selected.
552 pDlg->EnableRenameTable(nTabSelCount == 1);
553
554 if ( pDlg->Execute() == RET_OK )
555 {
556 nDoc = pDlg->GetSelectedDocument();
557 nTab = pDlg->GetSelectedTable();
558 bCpy = pDlg->GetCopyTable();
559 bool bRna = pDlg->GetRenameTable();
560 // Leave aTabName string empty, when Rename is FALSE.
561 if( bRna )
562 {
563 pDlg->GetTabNameString( aTabName );
564 }
565 bDoIt = true;
566
567 OUString aFoundDocName;
568 if ( nDoc != SC_DOC_NEW )
569 {
571 if (pSh)
572 {
573 aFoundDocName = pSh->GetTitle();
574 if ( !pSh->GetDocument().IsDocEditable() )
575 {
576 ErrorMessage(STR_READONLYERR);
577 bDoIt = false;
578 }
579 }
580 }
581 rReq.AppendItem( SfxStringItem( FID_TAB_MOVE, aFoundDocName ) );
582 // 1-based table, if not APPEND
583 SCTAB nBasicTab = ( nTab <= MAXTAB ) ? (nTab+1) : nTab;
584 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nBasicTab) ) );
585 rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) );
586 }
587 }
588
589 if( bDoIt )
590 {
591 rReq.Done(); // record, while doc is active
592
593 MoveTable( nDoc, nTab, bCpy, &aTabName );
594 }
595 }
596 break;
597
598 case FID_TAB_DUPLICATE:
599 {
600 // Get info about current document and selected tab
601 SCTAB nTab = rViewData.GetTabNo();
602 OUString aDocName = GetViewData().GetDocShell()->GetTitle();
603 sal_uInt16 nDoc = 0;
604 bool bCpy = true;
605
607 ScDocShell* pScSh = nullptr;
608 sal_uInt16 i = 0;
609
610 // Determine the index of the current document
611 while ( pSh )
612 {
613 pScSh = dynamic_cast<ScDocShell*>( pSh );
614
615 if( pScSh )
616 {
617 pScSh->GetTitle();
618
619 if (aDocName == pScSh->GetTitle())
620 {
621 nDoc = i;
622 break;
623 }
624 // Only count ScDocShell
625 i++;
626 }
627 pSh = SfxObjectShell::GetNext( *pSh );
628 }
629
630 MoveTable( nDoc, nTab + 1, bCpy );
631 }
632 break;
633
634 case FID_DELETE_TABLE:
635 {
636 bool bHasIndex = (pReqArgs != nullptr);
637
638 // allow removing via the Index/FID_DELETE_TABLE parameter
639 SCTAB nTabNr = nCurrentTab;
640 if (bHasIndex)
641 {
642 const SfxPoolItem* pItem;
643 if (pReqArgs->HasItem(FID_DELETE_TABLE, &pItem))
644 {
645 nTabNr = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
646
647 // inserting is 1-based, let's be consistent
648 if (nTabNr > 0)
649 --nTabNr;
650 }
651 }
652
653 bool bDoIt = bHasIndex;
654 if (!bDoIt)
655 {
656 bool bTabWithPivotTable = false;
657 if (rDoc.HasPivotTable())
658 {
659 const ScDPCollection* pDPs = rDoc.GetDPCollection();
660 if (pDPs)
661 {
662 const ScMarkData::MarkedTabsType& rSelectedTabs = rViewData.GetMarkData().GetSelectedTabs();
663 const size_t nCount = pDPs->GetCount();
664 for (size_t i = 0; i < nCount; ++i)
665 {
666 const ScDPObject& rDPObj = (*pDPs)[i];
667 const ScSheetSourceDesc* pSheetSourceDesc = rDPObj.GetSheetDesc();
668 if (pSheetSourceDesc)
669 {
670 SCTAB nTabOut = rDPObj.GetOutRange().aStart.Tab();
671 SCTAB nTabSource = pSheetSourceDesc->GetSourceRange().aStart.Tab();
672 bool bTabOutSel = false;
673 for (const SCTAB nSelTab : rSelectedTabs)
674 {
675 if (nSelTab == nTabSource)
676 bTabWithPivotTable = true;
677 if (nSelTab == nTabOut)
678 bTabOutSel = true;
679 if (bTabWithPivotTable && bTabOutSel)
680 break;
681 }
682 // if both pivot table and data are selected
683 // no need to warn for source data losing
684 if (bTabWithPivotTable && bTabOutSel)
685 bTabWithPivotTable = false;
686 if (bTabWithPivotTable)
687 break;
688 }
689 }
690 }
691 }
692
693 SCTAB nTabSelCnt = rViewData.GetMarkData().GetSelectCount();
694 OUString aTabSelCnt = Application::GetSettings().GetUILocaleDataWrapper().getNum( nTabSelCnt, 0 );
695 OUString aQueryDeleteTab = ScResId( STR_QUERY_DELTAB, nTabSelCnt )
696 .replaceAll( "%d", aTabSelCnt );
697 if (bTabWithPivotTable)
698 {
699 OUString aStr = ScResId( STR_QUERY_PIVOTTABLE_DELTAB, nTabSelCnt )
700 .replaceAll( "%d", aTabSelCnt )
701 + " " + aQueryDeleteTab;
702
703 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
704 VclMessageType::Question, VclButtonsType::YesNo,
705 aStr));
706 xQueryBox->set_default_response(RET_NO);
707
708 // Hard warning as there is potential of data loss on deletion
709 bDoIt = (RET_YES == xQueryBox->run());
710 }
711 else
712 {
713 bool bHasData = false;
714 ScMarkData& rMark = rViewData.GetMarkData();
715 for ( SCTAB i = 0; i < nTabCount && !bHasData; i++ )
716 {
717 if ( rMark.GetTableSelect(i) && !rDoc.IsTabProtected(i) )
718 {
719 SCCOL nStartCol;
720 SCROW nStartRow;
721 bHasData = rDoc.GetDataStart( i, nStartCol, nStartRow );
722 }
723 }
724 // Do not ask for confirmation if all selected tabs are empty
725 if (bHasData)
726 {
727 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
728 VclMessageType::Question, VclButtonsType::YesNo,
729 aQueryDeleteTab));
730 xQueryBox->set_default_response(RET_YES);
731
732 // no parameter given, ask for confirmation
733 bDoIt = (RET_YES == xQueryBox->run());
734 }
735 else
736 bDoIt = true;
737 }
738 }
739
740 if (bDoIt)
741 {
742 SCTAB nNewTab = nCurrentTab;
743 std::vector<SCTAB> TheTabs;
744
745 if (bHasIndex)
746 {
747 // sheet no. provided by the parameter
748 TheTabs.push_back(nTabNr);
749 if (nNewTab > nTabNr && nNewTab > 0)
750 --nNewTab;
751 }
752 else
753 {
754 SCTAB nFirstTab = 0;
755 bool bTabFlag = false;
756 ScMarkData& rMark = rViewData.GetMarkData();
757 for (SCTAB i = 0; i < nTabCount; i++)
758 {
759 if (rMark.GetTableSelect(i) && !rDoc.IsTabProtected(i))
760 {
761 TheTabs.push_back(i);
762 bTabFlag = true;
763 if (nNewTab == i && i+1 < nTabCount)
764 nNewTab++;
765 }
766 if (!bTabFlag)
767 nFirstTab = i;
768 }
769 if (nNewTab >= nTabCount - static_cast<SCTAB>(TheTabs.size()))
770 nNewTab = nFirstTab;
771 }
772
773 rViewData.SetTabNo(nNewTab);
774 DeleteTables(TheTabs);
775 TheTabs.clear();
776 rReq.Done();
777 }
778 }
779 break;
780
781 case FID_TAB_RTL:
782 {
783 ScDocShell* pDocSh = rViewData.GetDocShell();
784 ScDocFunc &rFunc = pDocSh->GetDocFunc();
785 bool bSet = !rDoc.IsLayoutRTL( nCurrentTab );
786
787 const ScMarkData& rMark = rViewData.GetMarkData();
788 if ( rMark.GetSelectCount() != 0 )
789 {
790 // handle several sheets
791
792 SfxUndoManager* pUndoManager = pDocSh->GetUndoManager();
793 OUString aUndo = ScResId( STR_UNDO_TAB_RTL );
794 pUndoManager->EnterListAction( aUndo, aUndo, 0, rViewData.GetViewShell()->GetViewShellId() );
795
796 for (const auto& rTab : rMark)
797 rFunc.SetLayoutRTL( rTab, bSet );
798
799 pUndoManager->LeaveListAction();
800 }
801 else
802 rFunc.SetLayoutRTL( nCurrentTab, bSet );
803 }
804 break;
805
806 case FID_TAB_TOGGLE_GRID:
807 {
808 bool bShowGrid = rViewData.GetShowGrid();
809 rViewData.SetShowGrid(!bShowGrid);
810 SfxBindings& rBindings = GetViewFrame().GetBindings();
811 rBindings.Invalidate( FID_TAB_TOGGLE_GRID );
812 ScDocShellModificator aModificator(*rViewData.GetDocShell());
813 aModificator.SetDocumentModified();
814 PaintGrid();
815 rReq.Done();
816 }
817 break;
818
819 case FID_TAB_SET_TAB_BG_COLOR:
820 case FID_TAB_MENU_SET_TAB_BG_COLOR:
821 {
822 if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
823 nSlot = FID_TAB_SET_TAB_BG_COLOR;
824 SCTAB nTabNr = rViewData.GetTabNo();
825 ScMarkData& rMark = rViewData.GetMarkData();
826 SCTAB nTabSelCount = rMark.GetSelectCount();
827 if ( !rDoc.IsDocEditable() )
828 break;
829
830 if ( rDoc.IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1
831 break;
832
833 if( pReqArgs != nullptr )
834 {
835 bool bDone = false;
836 const SfxPoolItem* pItem;
837 Color aColor;
838
839 if( pReqArgs->HasItem( nSlot, &pItem ) )
840 aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
841
842 if ( nTabSelCount > 1 )
843 {
844 std::unique_ptr<ScUndoTabColorInfo::List>
845 pTabColorList(new ScUndoTabColorInfo::List);
846 for (const auto& rTab : rMark)
847 {
848 if ( !rDoc.IsTabProtected(rTab) )
849 {
850 ScUndoTabColorInfo aTabColorInfo(rTab);
851 aTabColorInfo.maNewTabBgColor = aColor;
852 pTabColorList->push_back(aTabColorInfo);
853 }
854 }
855 bDone = SetTabBgColor( *pTabColorList );
856 }
857 else
858 {
859 bDone = SetTabBgColor( aColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
860 }
861 if( bDone )
862 {
863 rReq.Done( *pReqArgs );
864 }
865 }
866 else
867 {
868 sal_uInt16 nRet = RET_OK;
869 bool bDone = false;
870
871 Color aTabBgColor = rDoc.GetTabBgColor( nCurrentTab );
874 GetFrameWeld(),
875 ScResId(SCSTR_SET_TAB_BG_COLOR),
876 ScResId(SCSTR_NO_TAB_BG_COLOR),
877 aTabBgColor));
878 while ( !bDone && nRet == RET_OK )
879 {
880 nRet = pDlg->Execute();
881 if( nRet == RET_OK )
882 {
883 Color aSelectedColor;
884 pDlg->GetSelectedColor(aSelectedColor);
885 std::unique_ptr<ScUndoTabColorInfo::List>
886 pTabColorList(new ScUndoTabColorInfo::List);
887 if ( nTabSelCount > 1 )
888 {
889 for (const auto& rTab : rMark)
890 {
891 if ( !rDoc.IsTabProtected(rTab) )
892 {
893 ScUndoTabColorInfo aTabColorInfo(rTab);
894 aTabColorInfo.maNewTabBgColor = aSelectedColor;
895 pTabColorList->push_back(aTabColorInfo);
896 }
897 }
898 bDone = SetTabBgColor( *pTabColorList );
899 }
900 else
901 {
902 bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
903 }
904
905 if ( bDone )
906 {
907 rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) );
908 rReq.Done();
909 }
910 else
911 {
912 if( rReq.IsAPI() )
913 {
914#if HAVE_FEATURE_SCRIPTING
916#endif
917 }
918 }
919 }
920 }
921 }
922 }
923 break;
924
925 case FID_TAB_EVENTS:
926 {
927 ScDocShell* pDocSh = rViewData.GetDocShell();
928 uno::Reference<container::XNameReplace> xEvents( new ScSheetEventsObj( pDocSh, nCurrentTab ) );
929 uno::Reference<frame::XFrame> xFrame = GetViewFrame().GetFrame().GetFrameInterface();
932 GetFrameWeld(), xFrame, false, xEvents, 0 ) );
933 if ( pDialog->Execute() == RET_OK )
934 {
935 // the dialog modifies the settings directly
936 }
937 }
938 break;
939 case FID_TOGGLEHIDDENCOLROW:
940 {
941 svtools::EditableColorConfig aEditableConfig;
943 aValue.bIsVisible = !aValue.bIsVisible;
944 aEditableConfig.SetColorValue(svtools::CALCHIDDENROWCOL, aValue);
945 }
946 break;
947 default:
948 OSL_FAIL("unknown message for ViewShell");
949 break;
950 }
951}
952
954{
955 ScViewData& rViewData = GetViewData();
956 ScDocument& rDoc = rViewData.GetDocument();
957 ScDocShell* pDocShell = rViewData.GetDocShell();
959 SCTAB nTab = rViewData.GetTabNo();
960
961 SCTAB nTabCount = rDoc.GetTableCount();
962 SCTAB nTabSelCount = rMark.GetSelectCount();
963
964 SfxWhichIter aIter(rSet);
965 sal_uInt16 nWhich = aIter.FirstWhich();
966
967 while ( nWhich )
968 {
969 switch ( nWhich )
970 {
971
972 case FID_TABLE_VISIBLE:
973 rSet.Put( SfxBoolItem( nWhich, rDoc.IsVisible(nTab) ));
974 break;
975
976 case FID_TABLE_HIDE:
977 {
978 sal_uInt16 nVis = 0;
979 // enable menu : check to make sure we won't hide all sheets. we need at least one visible at all times.
980 for ( SCTAB i=0; i < nTabCount && nVis<nTabSelCount + 1; i++ )
981 if (rDoc.IsVisible(i))
982 ++nVis;
983 if ( nVis<=nTabSelCount || !rDoc.IsDocEditable() )
984 rSet.DisableItem( nWhich );
985 }
986 break;
987
988 case FID_TABLE_SHOW:
989 {
990 bool bHasHidden = false;
991 for ( SCTAB i=0; i < nTabCount && !bHasHidden; i++ )
992 if (!rDoc.IsVisible(i))
993 bHasHidden = true;
994 if ( !bHasHidden || rDoc.IsDocProtected() || nTabSelCount > 1 )
995 rSet.DisableItem( nWhich );
996 }
997 break;
998
999 case FID_DELETE_TABLE:
1000 {
1001 if ( rDoc.GetChangeTrack() )
1002 rSet.DisableItem( nWhich );
1003 else
1004 {
1005 sal_uInt16 nVis = 0;
1006 for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
1007 if (rDoc.IsVisible(i))
1008 ++nVis;
1009 if ( rDoc.IsTabProtected(nTab)
1010 || !rDoc.IsDocEditable()
1011 || nVis < 2
1012 || nTabSelCount == nTabCount)
1013 rSet.DisableItem( nWhich );
1014 }
1015 }
1016 break;
1017
1018 case FID_INS_TABLE:
1019 case FID_INS_TABLE_EXT:
1020 case FID_TAB_APPEND:
1021 if ( !rDoc.IsDocEditable() ||
1022 nTabCount > MAXTAB ||
1023 ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->IsDocShared() ) )
1024 rSet.DisableItem( nWhich );
1025 break;
1026
1027 case FID_TAB_MOVE:
1028 if ( !rDoc.IsDocEditable()
1029 || rDoc.GetChangeTrack() != nullptr
1030 || nTabCount > MAXTAB)
1031 rSet.DisableItem( nWhich );
1032 break;
1033
1034 case FID_TAB_DUPLICATE:
1035 if ( !rDoc.IsDocEditable()
1036 || rDoc.GetChangeTrack() != nullptr
1037 || nTabCount > MAXTAB)
1038 rSet.DisableItem( nWhich );
1039 break;
1040
1041 // FID_TAB_MENU_RENAME - "rename" from Menu
1042 // FID_TAB_RENAME - "name"-property for Basic
1043
1044 case FID_TAB_MENU_RENAME:
1045 if ( !rDoc.IsDocEditable() ||
1046 rDoc.IsTabProtected(nTab) ||nTabSelCount > 1 ||
1047 ( pDocShell && pDocShell->IsDocShared() ) )
1048 rSet.DisableItem( nWhich );
1049 break;
1050
1051 case FID_TAB_RENAME:
1052 {
1053 OUString aTabName;
1054 rDoc.GetName( nTab, aTabName );
1055
1056 rSet.Put( SfxStringItem( nWhich, aTabName ));
1057
1058 }
1059 break;
1060
1061 case FID_TAB_RTL:
1062 {
1064 rSet.DisableItem( nWhich );
1065 else
1066 rSet.Put( SfxBoolItem( nWhich, rDoc.IsLayoutRTL( nTab ) ) );
1067 }
1068 break;
1069
1070 case FID_TAB_MENU_SET_TAB_BG_COLOR:
1071 {
1072 if ( !rDoc.IsDocEditable()
1073 || ( pDocShell && pDocShell->IsDocShared() )
1074 || rDoc.IsTabProtected(nTab) )
1075 rSet.DisableItem( nWhich );
1076 }
1077 break;
1078
1079 case FID_TAB_SET_TAB_BG_COLOR:
1080 {
1081 Color aColor = rDoc.GetTabBgColor( nTab );
1082 rSet.Put( SvxColorItem( aColor, nWhich ) );
1083 }
1084 break;
1085
1086 case FID_TAB_TOGGLE_GRID:
1087 rSet.Put( SfxBoolItem(nWhich, rViewData.GetShowGrid()) );
1088 break;
1089 }
1090 nWhich = aIter.NextWhich();
1091 }
1092}
1093
1094/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SCTAB MAXTAB
Definition: address.hxx:70
const SCTAB SC_TAB_APPEND
Definition: address.hxx:90
const LocaleDataWrapper & GetUILocaleDataWrapper() const
static const AllSettings & GetSettings()
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
const OUString & GetValue() const
OUString getNum(sal_Int64 nNumber, sal_uInt16 nDecimals, bool bUseThousandSep=true, bool bTrailingZeros=true) const
virtual VclPtr< AbstractScShowTabDlg > CreateScShowTabDlg(weld::Window *pParent)=0
virtual VclPtr< AbstractScMoveTableDlg > CreateScMoveTableDlg(weld::Window *pParent, const OUString &rDefault)=0
virtual VclPtr< AbstractScTabBgColorDlg > CreateScTabBgColorDlg(weld::Window *pParent, const OUString &rTitle, const OUString &rTabBgColorNoColorText, const Color &rDefaultColor)=0
virtual VclPtr< AbstractScStringInputDlg > CreateScStringInputDlg(weld::Window *pParent, const OUString &rTitle, const OUString &rEditTitle, const OUString &rDefault, const OUString &rHelpId, const OUString &rEditHelpId)=0
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
virtual VclPtr< AbstractScInsertTableDlg > CreateScInsertTableDlg(weld::Window *pParent, ScViewData &rViewData, SCTAB nTabCount, bool bFromFile)=0
SCTAB Tab() const
Definition: address.hxx:283
SC_DLLPUBLIC size_t GetCount() const
Definition: dpobject.cxx:3717
const ScRange & GetOutRange() const
Definition: dpobject.cxx:410
const ScSheetSourceDesc * GetSheetDesc() const
Definition: dpobject.hxx:156
bool SetLayoutRTL(SCTAB nTab, bool bRTL)
Definition: docfunc.cxx:3469
Create before modifications of the document and destroy thereafter.
Definition: docsh.hxx:455
void SetDocumentModified()
Definition: docsh.cxx:3315
const ScDocument & GetDocument() const
Definition: docsh.hxx:219
static ScDocShell * GetShellByNum(sal_uInt16 nDocNo)
Definition: docsh4.cxx:2653
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2968
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:221
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
Definition: documen3.cxx:432
SC_DLLPUBLIC bool IsDocProtected() const
Definition: documen3.cxx:1894
SC_DLLPUBLIC Color GetTabBgColor(SCTAB nTab) const
Definition: documen3.cxx:449
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1905
SC_DLLPUBLIC bool HasPivotTable() const
Definition: documen3.cxx:360
bool IsDocEditable() const
Definition: documen3.cxx:1899
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
Definition: document.cxx:375
SC_DLLPUBLIC bool IsVisible(SCTAB nTab) const
Definition: document.cxx:890
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2494
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
Definition: document.cxx:974
SC_DLLPUBLIC bool GetDataStart(SCTAB nTab, SCCOL &rStartCol, SCROW &rStartRow) const
Definition: documen2.cxx:679
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
Definition: document.cxx:204
SC_DLLPUBLIC ScDPCollection * GetDPCollection()
Definition: documen3.cxx:365
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:297
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
void SelectOneTable(SCTAB nTab)
Definition: markdata.cxx:174
SCTAB GetLastSelected() const
Definition: markdata.cxx:194
bool GetTableSelect(SCTAB nTab) const
Definition: markdata.cxx:169
std::set< SCTAB > MarkedTabsType
Definition: markdata.hxx:45
SCTAB GetSelectCount() const
Definition: markdata.cxx:180
const MarkedTabsType & GetSelectedTabs() const
Definition: markdata.hxx:97
ScAddress aStart
Definition: address.hxx:497
This class contains authoritative information on the internal reference used as the data source for d...
Definition: dpshttab.hxx:40
SC_DLLPUBLIC const ScRange & GetSourceRange() const
Get the range that contains the source data.
Definition: dpshttab.cxx:230
void ExecuteTable(SfxRequest &rReq)
Definition: tabvwshf.cxx:61
void GetStateTable(SfxItemSet &rSet)
Definition: tabvwshf.cxx:953
void ErrorMessage(TranslateId pGlobStrId)
Definition: tabview2.cxx:1553
ScViewData & GetViewData()
Definition: tabview.hxx:344
void HideListBox()
Definition: tabview3.cxx:2996
void PaintGrid()
Definition: tabview3.cxx:2656
bool GetShowGrid() const
Definition: viewdata.hxx:463
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3146
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
void SetTabNo(SCTAB nNewTab)
Definition: viewdata.cxx:2319
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
void SetShowGrid(bool bShow)
Definition: viewdata.cxx:1110
bool AppendTable(const OUString &rName, bool bRecord=true)
Definition: viewfun2.cxx:2436
bool DeleteTables(const std::vector< SCTAB > &TheTabs, bool bRecord=true)
bool SetTabBgColor(const Color &rColor, SCTAB nTabNr)
Definition: viewfun2.cxx:2658
void ImportTables(ScDocShell *pSrcShell, SCTAB nCount, const SCTAB *pSrcTabs, bool bLink, SCTAB nTab)
Definition: viewfun2.cxx:2725
void HideTable(const ScMarkData &rMark, SCTAB nTabToSelect=-1)
Definition: viewfun2.cxx:3237
void ShowTable(const std::vector< OUString > &rNames)
Definition: viewfun2.cxx:3202
void MoveTable(sal_uInt16 nDestDocNo, SCTAB nDestTab, bool bCopy, const OUString *pNewTabName=nullptr)
Definition: viewfun2.cxx:2846
void InsertTables(std::vector< OUString > &aNames, SCTAB nTab, SCTAB nCount, bool bRecord=true)
Definition: viewfun2.cxx:2394
bool RenameTable(const OUString &rName, SCTAB nTabNr)
Definition: viewfun2.cxx:2645
bool InsertTable(const OUString &rName, SCTAB nTabNr, bool bRecord=true)
Definition: viewfun2.cxx:2381
void Invalidate(sal_uInt16 nId)
bool GetValue() const
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void DisableItem(sal_uInt16 nWhich)
static SAL_WARN_UNUSED_RESULT SfxObjectShell * GetNext(const SfxObjectShell &rPrev, const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
bool IsDocShared() const
OUString GetTitle(sal_uInt16 nMaxLen=0) const
static SAL_WARN_UNUSED_RESULT SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
sal_uInt16 GetSlot() const
void Ignore()
const SfxItemSet * GetArgs() const
void AppendItem(const SfxPoolItem &)
bool IsAPI() const
void Done(bool bRemove=false)
static SfxInterface * GetStaticInterface()
size_t LeaveListAction()
virtual void EnterListAction(const OUString &rComment, const OUString &rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId)
SfxBindings & GetBindings()
SfxFrame & GetFrame() const
weld::Window * GetFrameWeld() const
ViewShellId GetViewShellId() const override
SfxViewFrame & GetViewFrame() const
sal_uInt16 FirstWhich()
sal_uInt16 NextWhich()
static void Error(ErrCode, const OUString &rMsg={})
static bool IsCTLFontEnabled()
static SvxAbstractDialogFactory * Create()
virtual VclPtr< VclAbstractDialog > CreateSvxMacroAssignDlg(weld::Window *_pParent, const css::uno::Reference< css::frame::XFrame > &_rxDocumentFrame, const bool _bUnoDialogMode, const css::uno::Reference< css::container::XNameReplace > &_rxEvents, const sal_uInt16 _nInitiallySelectedEvent)=0
void SetColorValue(ColorConfigEntry eEntry, const ColorConfigValue &rValue)
const ColorConfigValue & GetColorValue(ColorConfigEntry eEntry) const
int nCount
#define SC_DOC_NEW
Definition: document.hxx:248
constexpr OUStringLiteral HID_SC_APPEND_NAME
Definition: helpids.h:45
constexpr OUStringLiteral HID_SC_RENAME_NAME
Definition: helpids.h:44
OUString aName
sal_Int64 n
uno_Any a
aStr
int i
const char GetValue[]
#define ERRCODE_BASIC_SETPROP_FAILED
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
static SfxItemSet & rSet
::std::vector< ScUndoTabColorInfo > List
Definition: tabbgcolor.hxx:36
Reference< XFrame > xFrame
bool bVisible
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
RET_OK
RET_NO
RET_YES