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 OString 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 for (const SCTAB nSelTab : rSelectedTabs)
664 {
665 const size_t nCount = pDPs->GetCount();
666 for (size_t i = 0; i < nCount; ++i)
667 {
668 const ScDPObject& rDPObj = (*pDPs)[i];
669 const ScSheetSourceDesc* pSheetSourceDesc = rDPObj.GetSheetDesc();
670 if (pSheetSourceDesc && pSheetSourceDesc->GetSourceRange().aStart.Tab() == nSelTab)
671 bTabWithPivotTable = true;
672 }
673 if (bTabWithPivotTable)
674 break;
675 }
676 }
677 }
678
679 if (bTabWithPivotTable)
680 {
681 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
682 VclMessageType::Question, VclButtonsType::YesNo,
683 ScResId(STR_QUERY_PIVOTTABLE_DELTAB)));
684 xQueryBox->set_default_response(RET_NO);
685
686 // Hard warning as there is potential of data loss on deletion
687 bDoIt = (RET_YES == xQueryBox->run());
688 }
689 else
690 {
691 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
692 VclMessageType::Question, VclButtonsType::YesNo,
693 ScResId(STR_QUERY_DELTAB)));
694 xQueryBox->set_default_response(RET_YES);
695
696 // no parameter given, ask for confirmation
697 bDoIt = (RET_YES == xQueryBox->run());
698 }
699 }
700
701 if (bDoIt)
702 {
703 SCTAB nNewTab = nCurrentTab;
704 std::vector<SCTAB> TheTabs;
705
706 if (bHasIndex)
707 {
708 // sheet no. provided by the parameter
709 TheTabs.push_back(nTabNr);
710 if (nNewTab > nTabNr && nNewTab > 0)
711 --nNewTab;
712 }
713 else
714 {
715 SCTAB nFirstTab = 0;
716 bool bTabFlag = false;
717 ScMarkData& rMark = rViewData.GetMarkData();
718 for (SCTAB i = 0; i < nTabCount; i++)
719 {
720 if (rMark.GetTableSelect(i) && !rDoc.IsTabProtected(i))
721 {
722 TheTabs.push_back(i);
723 bTabFlag = true;
724 if (nNewTab == i && i+1 < nTabCount)
725 nNewTab++;
726 }
727 if (!bTabFlag)
728 nFirstTab = i;
729 }
730 if (nNewTab >= nTabCount - static_cast<SCTAB>(TheTabs.size()))
731 nNewTab = nFirstTab;
732 }
733
734 rViewData.SetTabNo(nNewTab);
735 DeleteTables(TheTabs);
736 TheTabs.clear();
737 rReq.Done();
738 }
739 }
740 break;
741
742 case FID_TAB_RTL:
743 {
744 ScDocShell* pDocSh = rViewData.GetDocShell();
745 ScDocFunc &rFunc = pDocSh->GetDocFunc();
746 bool bSet = !rDoc.IsLayoutRTL( nCurrentTab );
747
748 const ScMarkData& rMark = rViewData.GetMarkData();
749 if ( rMark.GetSelectCount() != 0 )
750 {
751 // handle several sheets
752
753 SfxUndoManager* pUndoManager = pDocSh->GetUndoManager();
754 OUString aUndo = ScResId( STR_UNDO_TAB_RTL );
755 pUndoManager->EnterListAction( aUndo, aUndo, 0, rViewData.GetViewShell()->GetViewShellId() );
756
757 for (const auto& rTab : rMark)
758 rFunc.SetLayoutRTL( rTab, bSet );
759
760 pUndoManager->LeaveListAction();
761 }
762 else
763 rFunc.SetLayoutRTL( nCurrentTab, bSet );
764 }
765 break;
766
767 case FID_TAB_TOGGLE_GRID:
768 {
769 bool bShowGrid = rViewData.GetShowGrid();
770 rViewData.SetShowGrid(!bShowGrid);
771 SfxBindings& rBindings = GetViewFrame()->GetBindings();
772 rBindings.Invalidate( FID_TAB_TOGGLE_GRID );
773 ScDocShellModificator aModificator(*rViewData.GetDocShell());
774 aModificator.SetDocumentModified();
775 PaintGrid();
776 rReq.Done();
777 }
778 break;
779
780 case FID_TAB_SET_TAB_BG_COLOR:
781 case FID_TAB_MENU_SET_TAB_BG_COLOR:
782 {
783 if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
784 nSlot = FID_TAB_SET_TAB_BG_COLOR;
785 SCTAB nTabNr = rViewData.GetTabNo();
786 ScMarkData& rMark = rViewData.GetMarkData();
787 SCTAB nTabSelCount = rMark.GetSelectCount();
788 if ( !rDoc.IsDocEditable() )
789 break;
790
791 if ( rDoc.IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1
792 break;
793
794 if( pReqArgs != nullptr )
795 {
796 bool bDone = false;
797 const SfxPoolItem* pItem;
798 Color aColor;
799
800 if( pReqArgs->HasItem( nSlot, &pItem ) )
801 aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
802
803 if ( nTabSelCount > 1 )
804 {
805 std::unique_ptr<ScUndoTabColorInfo::List>
806 pTabColorList(new ScUndoTabColorInfo::List);
807 for (const auto& rTab : rMark)
808 {
809 if ( !rDoc.IsTabProtected(rTab) )
810 {
811 ScUndoTabColorInfo aTabColorInfo(rTab);
812 aTabColorInfo.maNewTabBgColor = aColor;
813 pTabColorList->push_back(aTabColorInfo);
814 }
815 }
816 bDone = SetTabBgColor( *pTabColorList );
817 }
818 else
819 {
820 bDone = SetTabBgColor( aColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
821 }
822 if( bDone )
823 {
824 rReq.Done( *pReqArgs );
825 }
826 }
827 else
828 {
829 sal_uInt16 nRet = RET_OK;
830 bool bDone = false;
831
832 Color aTabBgColor = rDoc.GetTabBgColor( nCurrentTab );
835 GetFrameWeld(),
836 ScResId(SCSTR_SET_TAB_BG_COLOR),
837 ScResId(SCSTR_NO_TAB_BG_COLOR),
838 aTabBgColor));
839 while ( !bDone && nRet == RET_OK )
840 {
841 nRet = pDlg->Execute();
842 if( nRet == RET_OK )
843 {
844 Color aSelectedColor;
845 pDlg->GetSelectedColor(aSelectedColor);
846 std::unique_ptr<ScUndoTabColorInfo::List>
847 pTabColorList(new ScUndoTabColorInfo::List);
848 if ( nTabSelCount > 1 )
849 {
850 for (const auto& rTab : rMark)
851 {
852 if ( !rDoc.IsTabProtected(rTab) )
853 {
854 ScUndoTabColorInfo aTabColorInfo(rTab);
855 aTabColorInfo.maNewTabBgColor = aSelectedColor;
856 pTabColorList->push_back(aTabColorInfo);
857 }
858 }
859 bDone = SetTabBgColor( *pTabColorList );
860 }
861 else
862 {
863 bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
864 }
865
866 if ( bDone )
867 {
868 rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) );
869 rReq.Done();
870 }
871 else
872 {
873 if( rReq.IsAPI() )
874 {
875#if HAVE_FEATURE_SCRIPTING
877#endif
878 }
879 }
880 }
881 }
882 }
883 }
884 break;
885
886 case FID_TAB_EVENTS:
887 {
888 ScDocShell* pDocSh = rViewData.GetDocShell();
889 uno::Reference<container::XNameReplace> xEvents( new ScSheetEventsObj( pDocSh, nCurrentTab ) );
890 uno::Reference<frame::XFrame> xFrame = GetViewFrame()->GetFrame().GetFrameInterface();
893 GetFrameWeld(), xFrame, false, xEvents, 0 ) );
894 if ( pDialog->Execute() == RET_OK )
895 {
896 // the dialog modifies the settings directly
897 }
898 }
899 break;
900 case FID_TOGGLEHIDDENCOLROW:
901 {
902 svtools::EditableColorConfig aEditableConfig;
904 aValue.bIsVisible = !aValue.bIsVisible;
905 aEditableConfig.SetColorValue(svtools::CALCHIDDENROWCOL, aValue);
906 }
907 break;
908 default:
909 OSL_FAIL("unknown message for ViewShell");
910 break;
911 }
912}
913
915{
916 ScViewData& rViewData = GetViewData();
917 ScDocument& rDoc = rViewData.GetDocument();
918 ScDocShell* pDocShell = rViewData.GetDocShell();
920 SCTAB nTab = rViewData.GetTabNo();
921
922 SCTAB nTabCount = rDoc.GetTableCount();
923 SCTAB nTabSelCount = rMark.GetSelectCount();
924
925 SfxWhichIter aIter(rSet);
926 sal_uInt16 nWhich = aIter.FirstWhich();
927
928 while ( nWhich )
929 {
930 switch ( nWhich )
931 {
932
933 case FID_TABLE_VISIBLE:
934 rSet.Put( SfxBoolItem( nWhich, rDoc.IsVisible(nTab) ));
935 break;
936
937 case FID_TABLE_HIDE:
938 {
939 sal_uInt16 nVis = 0;
940 // enable menu : check to make sure we won't hide all sheets. we need at least one visible at all times.
941 for ( SCTAB i=0; i < nTabCount && nVis<nTabSelCount + 1; i++ )
942 if (rDoc.IsVisible(i))
943 ++nVis;
944 if ( nVis<=nTabSelCount || !rDoc.IsDocEditable() )
945 rSet.DisableItem( nWhich );
946 }
947 break;
948
949 case FID_TABLE_SHOW:
950 {
951 bool bHasHidden = false;
952 for ( SCTAB i=0; i < nTabCount && !bHasHidden; i++ )
953 if (!rDoc.IsVisible(i))
954 bHasHidden = true;
955 if ( !bHasHidden || rDoc.IsDocProtected() || nTabSelCount > 1 )
956 rSet.DisableItem( nWhich );
957 }
958 break;
959
960 case FID_DELETE_TABLE:
961 {
962 if ( rDoc.GetChangeTrack() )
963 rSet.DisableItem( nWhich );
964 else
965 {
966 sal_uInt16 nVis = 0;
967 for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
968 if (rDoc.IsVisible(i))
969 ++nVis;
970 if ( rDoc.IsTabProtected(nTab)
971 || !rDoc.IsDocEditable()
972 || nVis < 2
973 || nTabSelCount == nTabCount)
974 rSet.DisableItem( nWhich );
975 }
976 }
977 break;
978
979 case FID_INS_TABLE:
980 case FID_INS_TABLE_EXT:
981 case FID_TAB_APPEND:
982 if ( !rDoc.IsDocEditable() ||
983 nTabCount > MAXTAB ||
984 ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->IsDocShared() ) )
985 rSet.DisableItem( nWhich );
986 break;
987
988 case FID_TAB_MOVE:
989 if ( !rDoc.IsDocEditable()
990 || rDoc.GetChangeTrack() != nullptr
991 || nTabCount > MAXTAB)
992 rSet.DisableItem( nWhich );
993 break;
994
995 case FID_TAB_DUPLICATE:
996 if ( !rDoc.IsDocEditable()
997 || rDoc.GetChangeTrack() != nullptr
998 || nTabCount > MAXTAB)
999 rSet.DisableItem( nWhich );
1000 break;
1001
1002 // FID_TAB_MENU_RENAME - "rename" from Menu
1003 // FID_TAB_RENAME - "name"-property for Basic
1004
1005 case FID_TAB_MENU_RENAME:
1006 if ( !rDoc.IsDocEditable() ||
1007 rDoc.IsTabProtected(nTab) ||nTabSelCount > 1 ||
1008 ( pDocShell && pDocShell->IsDocShared() ) )
1009 rSet.DisableItem( nWhich );
1010 break;
1011
1012 case FID_TAB_RENAME:
1013 {
1014 OUString aTabName;
1015 rDoc.GetName( nTab, aTabName );
1016
1017 rSet.Put( SfxStringItem( nWhich, aTabName ));
1018
1019 }
1020 break;
1021
1022 case FID_TAB_RTL:
1023 {
1024 if ( !SvtCTLOptions().IsCTLFontEnabled() )
1025 rSet.DisableItem( nWhich );
1026 else
1027 rSet.Put( SfxBoolItem( nWhich, rDoc.IsLayoutRTL( nTab ) ) );
1028 }
1029 break;
1030
1031 case FID_TAB_MENU_SET_TAB_BG_COLOR:
1032 {
1033 if ( !rDoc.IsDocEditable()
1034 || ( pDocShell && pDocShell->IsDocShared() )
1035 || rDoc.IsTabProtected(nTab) )
1036 rSet.DisableItem( nWhich );
1037 }
1038 break;
1039
1040 case FID_TAB_SET_TAB_BG_COLOR:
1041 {
1042 Color aColor = rDoc.GetTabBgColor( nTab );
1043 rSet.Put( SvxColorItem( aColor, nWhich ) );
1044 }
1045 break;
1046
1047 case FID_TAB_TOGGLE_GRID:
1048 rSet.Put( SfxBoolItem(nWhich, rViewData.GetShowGrid()) );
1049 break;
1050 }
1051 nWhich = aIter.NextWhich();
1052 }
1053}
1054
1055/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SCTAB MAXTAB
Definition: address.hxx:70
const SCTAB SC_TAB_APPEND
Definition: address.hxx:90
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage)
const OUString & GetValue() const
virtual VclPtr< AbstractScStringInputDlg > CreateScStringInputDlg(weld::Window *pParent, const OUString &rTitle, const OUString &rEditTitle, const OUString &rDefault, const OString &rHelpId, const OString &rEditHelpId)=0
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
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:3689
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:457
void SetDocumentModified()
Definition: docsh.cxx:3297
const ScDocument & GetDocument() const
Definition: docsh.hxx:220
static ScDocShell * GetShellByNum(sal_uInt16 nDocNo)
Definition: docsh4.cxx:2643
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2945
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:222
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
Definition: documen3.cxx:438
SC_DLLPUBLIC bool IsDocProtected() const
Definition: documen3.cxx:1908
SC_DLLPUBLIC Color GetTabBgColor(SCTAB nTab) const
Definition: documen3.cxx:454
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1919
SC_DLLPUBLIC bool HasPivotTable() const
Definition: documen3.cxx:366
bool IsDocEditable() const
Definition: documen3.cxx:1913
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
Definition: document.cxx:395
SC_DLLPUBLIC bool IsVisible(SCTAB nTab) const
Definition: document.cxx:920
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2487
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
Definition: document.cxx:998
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
Definition: document.cxx:217
SC_DLLPUBLIC ScDPCollection * GetDPCollection()
Definition: documen3.cxx:371
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:317
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:914
void ErrorMessage(TranslateId pGlobStrId)
Definition: tabview2.cxx:1446
ScViewData & GetViewData()
Definition: tabview.hxx:341
void HideListBox()
Definition: tabview3.cxx:2996
void PaintGrid()
Definition: tabview3.cxx:2656
bool GetShowGrid() const
Definition: viewdata.hxx:463
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3141
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
void SetTabNo(SCTAB nNewTab)
Definition: viewdata.cxx:2314
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:1109
bool AppendTable(const OUString &rName, bool bRecord=true)
Definition: viewfun2.cxx:2438
bool DeleteTables(const std::vector< SCTAB > &TheTabs, bool bRecord=true)
bool SetTabBgColor(const Color &rColor, SCTAB nTabNr)
Definition: viewfun2.cxx:2660
void ImportTables(ScDocShell *pSrcShell, SCTAB nCount, const SCTAB *pSrcTabs, bool bLink, SCTAB nTab)
Definition: viewfun2.cxx:2727
void HideTable(const ScMarkData &rMark, SCTAB nTabToSelect=-1)
Definition: viewfun2.cxx:3239
void ShowTable(const std::vector< OUString > &rNames)
Definition: viewfun2.cxx:3204
void MoveTable(sal_uInt16 nDestDocNo, SCTAB nDestTab, bool bCopy, const OUString *pNewTabName=nullptr)
Definition: viewfun2.cxx:2848
void InsertTables(std::vector< OUString > &aNames, SCTAB nTab, SCTAB nCount, bool bRecord=true)
Definition: viewfun2.cxx:2396
bool RenameTable(const OUString &rName, SCTAB nTabNr)
Definition: viewfun2.cxx:2647
bool InsertTable(const OUString &rName, SCTAB nTabNr, bool bRecord=true)
Definition: viewfun2.cxx:2383
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 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:247
constexpr OStringLiteral HID_SC_APPEND_NAME
Definition: helpids.h:45
constexpr OStringLiteral HID_SC_RENAME_NAME
Definition: helpids.h:44
OUString aName
sal_Int64 n
uno_Any a
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
RET_OK
RET_NO
RET_YES