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/languageoptions.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 
58 using std::unique_ptr;
59 using 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;
99  rNames.push_back(aName);
100  ShowTable( rNames );
101  }
102  }
103  break;
104 
105  case FID_TABLE_HIDE:
106  {
107  if ( rDoc.IsDocEditable() )
108  {
109  ScMarkData& rMark = rViewData.GetMarkData();
110  SCTAB nActiveTab = -1;
111  // For the cases when user right clicks on a non-active tab and hides it. This case is possible for Online.
112  if (pReqArgs)
113  {
114  const SfxPoolItem *pItem;
115  if( pReqArgs->HasItem( FID_TABLE_HIDE, &pItem ) )
116  {
117  SCTAB nTabNumber = static_cast<const SfxInt16Item*>(pItem)->GetValue();
118  // Does selected sheets (tabs) list include the sheet to be hidden?
119  std::set<SCTAB>::iterator it = rMark.GetSelectedTabs().find(nTabNumber);
120  if (it == rMark.GetSelectedTabs().end())
121  {
122  // No it doesn't, so we won't shift the selected tab. Let's remember its position.
123  nActiveTab = GetViewData().GetTabNo();
124  }
125  rMark.SelectOneTable(nTabNumber);
126  }
127  }
128  HideTable( rMark, nActiveTab );
129  }
130  }
131  break;
132 
133  case FID_TABLE_SHOW:
134  {
135  std::vector<OUString> rNames;
136  if ( pReqArgs )
137  {
138  const SfxPoolItem* pItem;
139  if( pReqArgs->HasItem( FID_TABLE_SHOW, &pItem ) )
140  {
141  OUString aName = static_cast<const SfxStringItem*>(pItem)->GetValue();
142  rNames.push_back(aName);
143  ShowTable( rNames );
144 
145  if( ! rReq.IsAPI() )
146  rReq.Done();
147  }
148  }
149  else
150  {
152 
154 
155  OUString aTabName;
156  bool bFirst = true;
157  for ( SCTAB i=0; i != nTabCount; i++ )
158  {
159  if (!rDoc.IsVisible(i))
160  {
161  rDoc.GetName( i, aTabName );
162  pDlg->Insert( aTabName, bFirst );
163  bFirst = false;
164  }
165  }
166 
167  std::shared_ptr<SfxRequest> pReq = std::make_shared<SfxRequest>(rReq);
168  pDlg->StartExecuteAsync([this, pDlg, pReq](sal_Int32 nResult){
169  std::vector<OUString> sTables;
170  if (RET_OK == nResult)
171  {
172  std::vector<sal_Int32> aSelectedRows = pDlg->GetSelectedRows();
173  for (auto a : aSelectedRows)
174  {
175  OUString sTable = pDlg->GetEntry(a);
176  pReq->AppendItem( SfxStringItem( FID_TABLE_SHOW, sTable ) );
177  sTables.push_back(sTable);
178  }
179  ShowTable( sTables );
180  pReq->Done();
181  }
182  pDlg->disposeOnce();
183  });
184  rReq.Ignore();
185  }
186  }
187  break;
188 
189  case FID_INS_TABLE:
190  case FID_INS_TABLE_EXT:
191  {
192  ScMarkData& rMark = rViewData.GetMarkData();
193  SCTAB nTabSelCount = rMark.GetSelectCount();
194  SCTAB nTabNr = nCurrentTab;
195 
196  if ( !rDoc.IsDocEditable() )
197  break; // locked
198 
199  if ( pReqArgs != nullptr ) // from basic
200  {
201  bool bOk = false;
202  const SfxPoolItem* pTabItem;
203  const SfxPoolItem* pNameItem;
204 
205  if ( pReqArgs->HasItem( FN_PARAM_1, &pTabItem ) &&
206  pReqArgs->HasItem( nSlot, &pNameItem ) )
207  {
208  OUString aName = static_cast<const SfxStringItem*>(pNameItem)->GetValue();
209  rDoc.CreateValidTabName(aName);
210 
211  // sheet number from basic: 1-based
212  // 0 is special, means adding at the end
213  nTabNr = static_cast<const SfxUInt16Item*>(pTabItem)->GetValue();
214  if (nTabNr == 0)
215  nTabNr = nTabCount;
216  else
217  --nTabNr;
218 
219  if (nTabNr > nTabCount)
220  nTabNr = nTabCount;
221 
222  bOk = InsertTable(aName, nTabNr);
223  }
224 
225  if (bOk)
226  rReq.Done( *pReqArgs );
228  }
229  else // dialog
230  {
232 
234  nTabSelCount, nSlot == FID_INS_TABLE_EXT));
235  if ( RET_OK == pDlg->Execute() )
236  {
237  if (pDlg->GetTablesFromFile())
238  {
239  std::vector<SCTAB> nTabs;
240  sal_uInt16 n = 0;
241  const OUString* pStr = pDlg->GetFirstTable( &n );
242  while ( pStr )
243  {
244  nTabs.push_back( static_cast<SCTAB>(n) );
245  pStr = pDlg->GetNextTable( &n );
246  }
247  bool bLink = pDlg->GetTablesAsLink();
248  if (!nTabs.empty())
249  {
250  if(pDlg->IsTableBefore())
251  {
252  ImportTables( pDlg->GetDocShellTables(), nTabs.size(), nTabs.data(),
253  bLink,nTabNr );
254  }
255  else
256  {
257  SCTAB nTabAfter = nTabNr+1;
258 
259  for(SCTAB j=nCurrentTab+1;j<nTabCount;j++)
260  {
261  if(!rDoc.IsScenario(j))
262  {
263  nTabAfter=j;
264  break;
265  }
266  }
267 
268  ImportTables( pDlg->GetDocShellTables(), nTabs.size(), nTabs.data(),
269  bLink,nTabAfter );
270  }
271  }
272  }
273  else
274  {
275  SCTAB nCount=pDlg->GetTableCount();
276  if(pDlg->IsTableBefore())
277  {
278  if(nCount==1 && !pDlg->GetFirstTable()->isEmpty())
279  {
280  rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
281  rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabNr) + 1 ) ); // 1-based
282  rReq.Done();
283 
284  InsertTable( *pDlg->GetFirstTable(), nTabNr );
285  }
286  else
287  {
288  std::vector<OUString> aNames(0);
289  InsertTables( aNames, nTabNr,nCount );
290  }
291  }
292  else
293  {
294  SCTAB nTabAfter = nTabNr+1;
295  SCTAB nSelHigh = rMark.GetLastSelected();
296 
297  for(SCTAB j=nSelHigh+1;j<nTabCount;j++)
298  {
299  if(!rDoc.IsScenario(j))
300  {
301  nTabAfter=j;
302  break;
303  }
304  else // #101672#; increase nTabAfter, because it is possible that the scenario tables are the last
305  nTabAfter = j + 1;
306  }
307 
308  if(nCount==1 && !pDlg->GetFirstTable()->isEmpty())
309  {
310  rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) );
311  rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabAfter) + 1 ) ); // 1-based
312  rReq.Done();
313 
314  InsertTable( *pDlg->GetFirstTable(), nTabAfter);
315  }
316  else
317  {
318  std::vector<OUString> aNames(0);
319  InsertTables( aNames, nTabAfter,nCount);
320  }
321  }
322  }
323  }
324  }
325  }
326  break;
327 
328  case FID_TAB_APPEND:
329  case FID_TAB_RENAME:
330  case FID_TAB_MENU_RENAME:
331  {
332  // FID_TAB_MENU_RENAME - "rename" in menu
333  // FID_TAB_RENAME - "name"-property for basic
334  // equal execute, but MENU_RENAME may be disabled inside GetState
335 
336  if ( nSlot == FID_TAB_MENU_RENAME )
337  nSlot = FID_TAB_RENAME; // equal execute
338 
339  SCTAB nTabNr = rViewData.GetTabNo();
340  ScMarkData& rMark = rViewData.GetMarkData();
341  SCTAB nTabSelCount = rMark.GetSelectCount();
342 
343  if ( !rDoc.IsDocEditable() )
344  break; // everything locked
345 
346  if ( nSlot != FID_TAB_APPEND &&
347  ( rDoc.IsTabProtected( nTabNr ) || nTabSelCount > 1 ) )
348  break; // no rename
349 
350  if( pReqArgs != nullptr )
351  {
352  bool bDone = false;
353  const SfxPoolItem* pItem;
354  OUString aName;
355 
356  if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
357  {
358  nTabNr = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
359 
360  // inserting is 1-based, let's be consistent
361  if (nTabNr > 0)
362  --nTabNr;
363  }
364 
365  if( pReqArgs->HasItem( nSlot, &pItem ) )
366  aName = static_cast<const SfxStringItem*>(pItem)->GetValue();
367 
368  switch ( nSlot )
369  {
370  case FID_TAB_APPEND:
371  bDone = AppendTable( aName );
372  break;
373  case FID_TAB_RENAME:
374  bDone = RenameTable( aName, nTabNr );
375  break;
376  }
377 
378  if( bDone )
379  {
380  rReq.Done( *pReqArgs );
381  }
382  }
383  else
384  {
385  sal_uInt16 nRet = RET_OK;
386  bool bDone = false;
387  OUString aErrMsg ( ScResId( STR_INVALIDTABNAME ) );
388  OUString aName;
389  OUString aDlgTitle;
390  const char* pHelpId = nullptr;
391 
392  switch ( nSlot )
393  {
394  case FID_TAB_APPEND:
395  aDlgTitle = ScResId(SCSTR_APDTABLE);
396  rDoc.CreateValidTabName( aName );
397  pHelpId = HID_SC_APPEND_NAME;
398  break;
399 
400  case FID_TAB_RENAME:
401  aDlgTitle = ScResId(SCSTR_RENAMETAB);
402  rDoc.GetName( rViewData.GetTabNo(), aName );
403  pHelpId = HID_SC_RENAME_NAME;
404  break;
405  }
406 
408 
410  GetFrameWeld(), aDlgTitle, ScResId(SCSTR_NAME),
411  aName, GetStaticInterface()->GetSlot(nSlot)->GetCommand(),
412  pHelpId));
413 
414 
415  while ( !bDone && nRet == RET_OK )
416  {
417  nRet = pDlg->Execute();
418 
419  if ( nRet == RET_OK )
420  {
421  aName = pDlg->GetInputString();
422 
423  switch ( nSlot )
424  {
425  case FID_TAB_APPEND:
426  bDone = AppendTable( aName );
427  break;
428  case FID_TAB_RENAME:
429  bDone = RenameTable( aName, nTabNr );
430  break;
431  }
432 
433  if ( bDone )
434  {
435  rReq.AppendItem( SfxStringItem( nSlot, aName ) );
436  rReq.Done();
437  }
438  else
439  {
440  if( rReq.IsAPI() )
441  {
442 #if HAVE_FEATURE_SCRIPTING
443  StarBASIC::Error( ERRCODE_BASIC_SETPROP_FAILED ); // XXX error handling???
444 #endif
445  }
446  else
447  {
448  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
449  VclMessageType::Warning, VclButtonsType::Ok, aErrMsg));
450  nRet = xBox->run();
451  }
452  }
453  }
454  }
455  }
456  }
457  break;
458 
459  case FID_TAB_MOVE:
460  {
461  if ( rDoc.GetChangeTrack() != nullptr )
462  break; // if ChangeTracking is active, then no TabMove
463 
464  bool bDoIt = false;
465  sal_uInt16 nDoc = 0;
466  SCTAB nTab = rViewData.GetTabNo();
467  bool bCpy = false, bUseCurrentDocument = false;
468  OUString aDocName;
469  OUString aTabName;
470 
471  if( pReqArgs != nullptr )
472  {
473  SCTAB nTableCount = rDoc.GetTableCount();
474  const SfxPoolItem* pItem;
475 
476  // if UseCurrentDocument(FN_PARAM_3) is true ignore the document name provided and use current document
477  if( pReqArgs->HasItem( FN_PARAM_3, &pItem ) )
478  bUseCurrentDocument = static_cast<const SfxBoolItem*>(pItem)->GetValue();
479 
480  if (bUseCurrentDocument)
481  aDocName = GetViewData().GetDocShell()->GetTitle();
482  else if(pReqArgs->HasItem( FID_TAB_MOVE, &pItem ))
483  aDocName = static_cast<const SfxStringItem*>(pItem)->GetValue();
484 
485  if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
486  {
487  // table is 1-based
488  nTab = static_cast<const SfxUInt16Item*>(pItem)->GetValue() - 1;
489  if ( nTab >= nTableCount )
490  nTab = SC_TAB_APPEND;
491  }
492  if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
493  bCpy = static_cast<const SfxBoolItem*>(pItem)->GetValue();
494 
495  if (!aDocName.isEmpty())
496  {
498  ScDocShell* pScSh = nullptr;
499  sal_uInt16 i=0;
500 
501  while ( pSh )
502  {
503  pScSh = dynamic_cast<ScDocShell*>( pSh );
504 
505  if( pScSh )
506  {
507  pScSh->GetTitle();
508 
509  if (aDocName == pScSh->GetTitle())
510  {
511  nDoc = i;
512  ScDocument& rDestDoc = pScSh->GetDocument();
513  nTableCount = rDestDoc.GetTableCount();
514  bDoIt = rDestDoc.IsDocEditable();
515  break;
516  }
517 
518  i++; // only count ScDocShell
519  }
520  pSh = SfxObjectShell::GetNext( *pSh );
521  }
522  }
523  else // no doc-name -> new doc
524  {
525  nDoc = SC_DOC_NEW;
526  bDoIt = true;
527  }
528 
529  if ( bDoIt && nTab >= nTableCount ) // if necessary append
530  nTab = SC_TAB_APPEND;
531  }
532  else
533  {
534  OUString aDefaultName;
535  rDoc.GetName( rViewData.GetTabNo(), aDefaultName );
536 
538 
540  aDefaultName));
541 
542  SCTAB nTableCount = rDoc.GetTableCount();
543  ScMarkData& rMark = GetViewData().GetMarkData();
544  SCTAB nTabSelCount = rMark.GetSelectCount();
545 
546  if(nTableCount==nTabSelCount)
547  {
548  pDlg->SetForceCopyTable();
549  }
550 
551  // We support direct renaming of sheet only when one sheet
552  // is selected.
553  pDlg->EnableRenameTable(nTabSelCount == 1);
554 
555  if ( pDlg->Execute() == RET_OK )
556  {
557  nDoc = pDlg->GetSelectedDocument();
558  nTab = pDlg->GetSelectedTable();
559  bCpy = pDlg->GetCopyTable();
560  bool bRna = pDlg->GetRenameTable();
561  // Leave aTabName string empty, when Rename is FALSE.
562  if( bRna )
563  {
564  pDlg->GetTabNameString( aTabName );
565  }
566  bDoIt = true;
567 
568  OUString aFoundDocName;
569  if ( nDoc != SC_DOC_NEW )
570  {
571  ScDocShell* pSh = ScDocShell::GetShellByNum( nDoc );
572  if (pSh)
573  {
574  aFoundDocName = pSh->GetTitle();
575  if ( !pSh->GetDocument().IsDocEditable() )
576  {
577  ErrorMessage(STR_READONLYERR);
578  bDoIt = false;
579  }
580  }
581  }
582  rReq.AppendItem( SfxStringItem( FID_TAB_MOVE, aFoundDocName ) );
583  // 1-based table, if not APPEND
584  SCTAB nBasicTab = ( nTab <= MAXTAB ) ? (nTab+1) : nTab;
585  rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nBasicTab) ) );
586  rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) );
587  }
588  }
589 
590  if( bDoIt )
591  {
592  rReq.Done(); // record, while doc is active
593 
594  MoveTable( nDoc, nTab, bCpy, &aTabName );
595  }
596  }
597  break;
598 
599  case FID_DELETE_TABLE:
600  {
601  bool bHasIndex = (pReqArgs != nullptr);
602 
603  // allow removing via the Index/FID_DELETE_TABLE parameter
604  SCTAB nTabNr = nCurrentTab;
605  if (bHasIndex)
606  {
607  const SfxPoolItem* pItem;
608  if (pReqArgs->HasItem(FID_DELETE_TABLE, &pItem))
609  {
610  nTabNr = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
611 
612  // inserting is 1-based, let's be consistent
613  if (nTabNr > 0)
614  --nTabNr;
615  }
616  }
617 
618  bool bDoIt = bHasIndex;
619  if (!bDoIt)
620  {
621  bool bTabWithPivotTable = false;
622  if (rDoc.HasPivotTable())
623  {
624  const ScDPCollection* pDPs = rDoc.GetDPCollection();
625  if (pDPs)
626  {
627  const ScMarkData::MarkedTabsType& rSelectedTabs = rViewData.GetMarkData().GetSelectedTabs();
628  for (const SCTAB nSelTab : rSelectedTabs)
629  {
630  const size_t nCount = pDPs->GetCount();
631  for (size_t i = 0; i < nCount; ++i)
632  {
633  const ScDPObject& rDPObj = (*pDPs)[i];
634  const ScSheetSourceDesc* pSheetSourceDesc = rDPObj.GetSheetDesc();
635  if (pSheetSourceDesc && pSheetSourceDesc->GetSourceRange().aStart.Tab() == nSelTab)
636  bTabWithPivotTable = true;
637  }
638  if (bTabWithPivotTable)
639  break;
640  }
641  }
642  }
643 
644  if (bTabWithPivotTable)
645  {
646  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
647  VclMessageType::Question, VclButtonsType::YesNo,
648  ScResId(STR_QUERY_PIVOTTABLE_DELTAB)));
649  xQueryBox->set_default_response(RET_NO);
650 
651  // Hard warning as there is potential of data loss on deletion
652  bDoIt = (RET_YES == xQueryBox->run());
653  }
654  else
655  {
656  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
657  VclMessageType::Question, VclButtonsType::YesNo,
658  ScResId(STR_QUERY_DELTAB)));
659  xQueryBox->set_default_response(RET_YES);
660 
661  // no parameter given, ask for confirmation
662  bDoIt = (RET_YES == xQueryBox->run());
663  }
664  }
665 
666  if (bDoIt)
667  {
668  SCTAB nNewTab = nCurrentTab;
669  std::vector<SCTAB> TheTabs;
670 
671  if (bHasIndex)
672  {
673  // sheet no. provided by the parameter
674  TheTabs.push_back(nTabNr);
675  if (nNewTab > nTabNr && nNewTab > 0)
676  --nNewTab;
677  }
678  else
679  {
680  SCTAB nFirstTab = 0;
681  bool bTabFlag = false;
682  ScMarkData& rMark = rViewData.GetMarkData();
683  for (SCTAB i = 0; i < nTabCount; i++)
684  {
685  if (rMark.GetTableSelect(i) && !rDoc.IsTabProtected(i))
686  {
687  TheTabs.push_back(i);
688  bTabFlag = true;
689  if (nNewTab == i && i+1 < nTabCount)
690  nNewTab++;
691  }
692  if (!bTabFlag)
693  nFirstTab = i;
694  }
695  if (nNewTab >= nTabCount - static_cast<SCTAB>(TheTabs.size()))
696  nNewTab = nFirstTab;
697  }
698 
699  rViewData.SetTabNo(nNewTab);
700  DeleteTables(TheTabs);
701  TheTabs.clear();
702  rReq.Done();
703  }
704  }
705  break;
706 
707  case FID_TAB_RTL:
708  {
709  ScDocShell* pDocSh = rViewData.GetDocShell();
710  ScDocFunc &rFunc = pDocSh->GetDocFunc();
711  bool bSet = !rDoc.IsLayoutRTL( nCurrentTab );
712 
713  const ScMarkData& rMark = rViewData.GetMarkData();
714  if ( rMark.GetSelectCount() != 0 )
715  {
716  // handle several sheets
717 
718  SfxUndoManager* pUndoManager = pDocSh->GetUndoManager();
719  OUString aUndo = ScResId( STR_UNDO_TAB_RTL );
720  pUndoManager->EnterListAction( aUndo, aUndo, 0, rViewData.GetViewShell()->GetViewShellId() );
721 
722  for (const auto& rTab : rMark)
723  rFunc.SetLayoutRTL( rTab, bSet );
724 
725  pUndoManager->LeaveListAction();
726  }
727  else
728  rFunc.SetLayoutRTL( nCurrentTab, bSet );
729  }
730  break;
731 
732  case FID_TAB_TOGGLE_GRID:
733  {
734  bool bShowGrid = rViewData.GetShowGrid();
735  rViewData.SetShowGrid(!bShowGrid);
736  SfxBindings& rBindings = GetViewFrame()->GetBindings();
737  rBindings.Invalidate( FID_TAB_TOGGLE_GRID );
738  ScDocShellModificator aModificator(*rViewData.GetDocShell());
739  aModificator.SetDocumentModified();
740  PaintGrid();
741  rReq.Done();
742  }
743  break;
744 
745  case FID_TAB_SET_TAB_BG_COLOR:
746  case FID_TAB_MENU_SET_TAB_BG_COLOR:
747  {
748  if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
749  nSlot = FID_TAB_SET_TAB_BG_COLOR;
750  SCTAB nTabNr = rViewData.GetTabNo();
751  ScMarkData& rMark = rViewData.GetMarkData();
752  SCTAB nTabSelCount = rMark.GetSelectCount();
753  if ( !rDoc.IsDocEditable() )
754  break;
755 
756  if ( rDoc.IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1
757  break;
758 
759  if( pReqArgs != nullptr )
760  {
761  bool bDone = false;
762  const SfxPoolItem* pItem;
763  Color aColor;
764 
765  if( pReqArgs->HasItem( nSlot, &pItem ) )
766  aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
767 
768  if ( nTabSelCount > 1 )
769  {
770  std::unique_ptr<ScUndoTabColorInfo::List>
771  pTabColorList(new ScUndoTabColorInfo::List);
772  for (const auto& rTab : rMark)
773  {
774  if ( !rDoc.IsTabProtected(rTab) )
775  {
776  ScUndoTabColorInfo aTabColorInfo(rTab);
777  aTabColorInfo.maNewTabBgColor = aColor;
778  pTabColorList->push_back(aTabColorInfo);
779  }
780  }
781  bDone = SetTabBgColor( *pTabColorList );
782  }
783  else
784  {
785  bDone = SetTabBgColor( aColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
786  }
787  if( bDone )
788  {
789  rReq.Done( *pReqArgs );
790  }
791  }
792  else
793  {
794  sal_uInt16 nRet = RET_OK;
795  bool bDone = false;
796 
797  Color aTabBgColor = rDoc.GetTabBgColor( nCurrentTab );
800  GetFrameWeld(),
801  ScResId(SCSTR_SET_TAB_BG_COLOR),
802  ScResId(SCSTR_NO_TAB_BG_COLOR),
803  aTabBgColor));
804  while ( !bDone && nRet == RET_OK )
805  {
806  nRet = pDlg->Execute();
807  if( nRet == RET_OK )
808  {
809  Color aSelectedColor;
810  pDlg->GetSelectedColor(aSelectedColor);
811  std::unique_ptr<ScUndoTabColorInfo::List>
812  pTabColorList(new ScUndoTabColorInfo::List);
813  if ( nTabSelCount > 1 )
814  {
815  for (const auto& rTab : rMark)
816  {
817  if ( !rDoc.IsTabProtected(rTab) )
818  {
819  ScUndoTabColorInfo aTabColorInfo(rTab);
820  aTabColorInfo.maNewTabBgColor = aSelectedColor;
821  pTabColorList->push_back(aTabColorInfo);
822  }
823  }
824  bDone = SetTabBgColor( *pTabColorList );
825  }
826  else
827  {
828  bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
829  }
830 
831  if ( bDone )
832  {
833  rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) );
834  rReq.Done();
835  }
836  else
837  {
838  if( rReq.IsAPI() )
839  {
840 #if HAVE_FEATURE_SCRIPTING
842 #endif
843  }
844  }
845  }
846  }
847  }
848  }
849  break;
850 
851  case FID_TAB_EVENTS:
852  {
853  ScDocShell* pDocSh = rViewData.GetDocShell();
854  uno::Reference<container::XNameReplace> xEvents( new ScSheetEventsObj( pDocSh, nCurrentTab ) );
855  uno::Reference<frame::XFrame> xFrame = GetViewFrame()->GetFrame().GetFrameInterface();
858  GetFrameWeld(), xFrame, false, xEvents, 0 ) );
859  if ( pDialog->Execute() == RET_OK )
860  {
861  // the dialog modifies the settings directly
862  }
863  }
864  break;
865 
866  default:
867  OSL_FAIL("unknown message for ViewShell");
868  break;
869  }
870 }
871 
873 {
874  ScViewData& rViewData = GetViewData();
875  ScDocument& rDoc = rViewData.GetDocument();
876  ScDocShell* pDocShell = rViewData.GetDocShell();
877  ScMarkData& rMark = GetViewData().GetMarkData();
878  SCTAB nTab = rViewData.GetTabNo();
879 
880  SCTAB nTabCount = rDoc.GetTableCount();
881  SCTAB nTabSelCount = rMark.GetSelectCount();
882 
883  SfxWhichIter aIter(rSet);
884  sal_uInt16 nWhich = aIter.FirstWhich();
885 
886  while ( nWhich )
887  {
888  switch ( nWhich )
889  {
890 
891  case FID_TABLE_VISIBLE:
892  rSet.Put( SfxBoolItem( nWhich, rDoc.IsVisible(nTab) ));
893  break;
894 
895  case FID_TABLE_HIDE:
896  {
897  sal_uInt16 nVis = 0;
898  // enable menu : check to make sure we won't hide all sheets. we need at least one visible at all times.
899  for ( SCTAB i=0; i < nTabCount && nVis<nTabSelCount + 1; i++ )
900  if (rDoc.IsVisible(i))
901  ++nVis;
902  if ( nVis<=nTabSelCount || !rDoc.IsDocEditable() )
903  rSet.DisableItem( nWhich );
904  }
905  break;
906 
907  case FID_TABLE_SHOW:
908  {
909  bool bHasHidden = false;
910  for ( SCTAB i=0; i < nTabCount && !bHasHidden; i++ )
911  if (!rDoc.IsVisible(i))
912  bHasHidden = true;
913  if ( !bHasHidden || rDoc.IsDocProtected() || nTabSelCount > 1 )
914  rSet.DisableItem( nWhich );
915  }
916  break;
917 
918  case FID_DELETE_TABLE:
919  {
920  if ( rDoc.GetChangeTrack() )
921  rSet.DisableItem( nWhich );
922  else
923  {
924  sal_uInt16 nVis = 0;
925  for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
926  if (rDoc.IsVisible(i))
927  ++nVis;
928  if ( rDoc.IsTabProtected(nTab)
929  || !rDoc.IsDocEditable()
930  || nVis < 2
931  || nTabSelCount == nTabCount)
932  rSet.DisableItem( nWhich );
933  }
934  }
935  break;
936 
937  case FID_INS_TABLE:
938  case FID_INS_TABLE_EXT:
939  case FID_TAB_APPEND:
940  if ( !rDoc.IsDocEditable() ||
941  nTabCount > MAXTAB ||
942  ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->IsDocShared() ) )
943  rSet.DisableItem( nWhich );
944  break;
945 
946  case FID_TAB_MOVE:
947  if ( !rDoc.IsDocEditable()
948  || rDoc.GetChangeTrack() != nullptr
949  || nTabCount > MAXTAB)
950  rSet.DisableItem( nWhich );
951  break;
952 
953  // FID_TAB_MENU_RENAME - "rename" from Menu
954  // FID_TAB_RENAME - "name"-property for Basic
955 
956  case FID_TAB_MENU_RENAME:
957  if ( !rDoc.IsDocEditable() ||
958  rDoc.IsTabProtected(nTab) ||nTabSelCount > 1 ||
959  ( pDocShell && pDocShell->IsDocShared() ) )
960  rSet.DisableItem( nWhich );
961  break;
962 
963  case FID_TAB_RENAME:
964  {
965  OUString aTabName;
966  rDoc.GetName( nTab, aTabName );
967 
968  rSet.Put( SfxStringItem( nWhich, aTabName ));
969 
970  }
971  break;
972 
973  case FID_TAB_RTL:
974  {
975  SvtLanguageOptions aLangOpt;
976  if ( !aLangOpt.IsCTLFontEnabled() )
977  rSet.DisableItem( nWhich );
978  else
979  rSet.Put( SfxBoolItem( nWhich, rDoc.IsLayoutRTL( nTab ) ) );
980  }
981  break;
982 
983  case FID_TAB_MENU_SET_TAB_BG_COLOR:
984  {
985  if ( !rDoc.IsDocEditable()
986  || ( pDocShell && pDocShell->IsDocShared() )
987  || rDoc.IsTabProtected(nTab) )
988  rSet.DisableItem( nWhich );
989  }
990  break;
991 
992  case FID_TAB_SET_TAB_BG_COLOR:
993  {
994  Color aColor = rDoc.GetTabBgColor( nTab );
995  rSet.Put( SvxColorItem( aColor, nWhich ) );
996  }
997  break;
998 
999  case FID_TAB_TOGGLE_GRID:
1000  rSet.Put( SfxBoolItem(nWhich, rViewData.GetShowGrid()) );
1001  break;
1002  }
1003  nWhich = aIter.NextWhich();
1004  }
1005 }
1006 
1007 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC bool IsDocProtected() const
Definition: documen3.cxx:1895
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3099
#define HID_SC_APPEND_NAME
Definition: helpids.h:43
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:353
ScAddress aStart
Definition: address.hxx:499
bool bVisible
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1906
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
SC_DLLPUBLIC size_t GetCount() const
Definition: dpobject.cxx:3676
OUString GetTitle(sal_uInt16 nMaxLen=0) const
std::string GetValue
static SvxAbstractDialogFactory * Create()
Reference< XFrame > xFrame
virtual VclPtr< AbstractScStringInputDlg > CreateScStringInputDlg(weld::Window *pParent, const OUString &rTitle, const OUString &rEditTitle, const OUString &rDefault, const OString &rHelpId, const OString &rEditHelpId)=0
sal_Int64 n
SC_DLLPUBLIC ScDPCollection * GetDPCollection()
Definition: documen3.cxx:365
virtual VclPtr< AbstractScInsertTableDlg > CreateScInsertTableDlg(weld::Window *pParent, ScViewData &rViewData, SCTAB nTabCount, bool bFromFile)=0
sal_uInt16 FirstWhich()
SCTAB GetTabNo() const
Definition: viewdata.hxx:394
void Done(bool bRemove=false)
ScDocument & GetDocument() const
Definition: viewdata.hxx:379
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
const MarkedTabsType & GetSelectedTabs() const
Definition: markdata.hxx:97
sal_uInt16 NextWhich()
#define SC_DOC_NEW
Definition: document.hxx:238
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2806
RET_NO
#define ERRCODE_BASIC_SETPROP_FAILED
RET_YES
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:313
SCTAB GetSelectCount() const
Definition: markdata.cxx:195
int nCount
bool IsDocShared() const
SCTAB Tab() const
Definition: address.hxx:270
SC_DLLPUBLIC const ScRange & GetSourceRange() const
Get the range that contains the source data.
Definition: dpshttab.cxx:229
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2403
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:356
void SetTabNo(SCTAB nNewTab)
Definition: viewdata.cxx:2307
const SCTAB SC_TAB_APPEND
Definition: address.hxx:83
SC_DLLPUBLIC bool HasPivotTable() const
Definition: documen3.cxx:360
virtual VclPtr< AbstractScMoveTableDlg > CreateScMoveTableDlg(weld::Window *pParent, const OUString &rDefault)=0
int i
uno_Any a
virtual VclPtr< AbstractScTabBgColorDlg > CreateScTabBgColorDlg(weld::Window *pParent, const OUString &rTitle, const OUString &rTabBgColorNoColorText, const Color &rDefaultColor)=0
virtual VclPtr< AbstractScShowTabDlg > CreateScShowTabDlg(weld::Window *pParent)=0
SC_DLLPUBLIC void CreateValidTabName(OUString &rName) const
Definition: document.cxx:391
void SelectOneTable(SCTAB nTab)
Definition: markdata.cxx:189
void GetStateTable(SfxItemSet &rSet)
Definition: tabvwshf.cxx:872
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
const SCTAB MAXTAB
Definition: address.hxx:70
size_t LeaveListAction()
static ScDocShell * GetShellByNum(sal_uInt16 nDocNo)
Definition: docsh4.cxx:2604
#define HID_SC_RENAME_NAME
Definition: helpids.h:42
SC_DLLPUBLIC Color GetTabBgColor(SCTAB nTab) const
Definition: documen3.cxx:448
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
static void Error(ErrCode)
OUString ScResId(std::string_view aId)
Definition: scdll.cxx:89
bool SetLayoutRTL(SCTAB nTab, bool bRTL)
Definition: docfunc.cxx:3458
void DisableItem(sal_uInt16 nWhich)
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
Definition: documen3.cxx:432
static SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
bool GetShowGrid() const
Definition: viewdata.hxx:462
OUString aName
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
bool IsDocEditable() const
Definition: documen3.cxx:1900
RET_OK
bool IsCTLFontEnabled() const
SCTAB GetLastSelected() const
Definition: markdata.cxx:209
const ScSheetSourceDesc * GetSheetDesc() const
Definition: dpobject.hxx:155
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
virtual void EnterListAction(const OUString &rComment, const OUString &rRepeatComment, sal_uInt16 nId, ViewShellId nViewShellId)
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
void ExecuteTable(SfxRequest &rReq)
Definition: tabvwshf.cxx:61
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
Definition: document.cxx:985
void SetDocumentModified()
Definition: docsh.cxx:3159
SC_DLLPUBLIC bool IsVisible(SCTAB nTab) const
Definition: document.cxx:907
void AppendItem(const SfxPoolItem &)
void SetShowGrid(bool bShow)
Definition: viewdata.cxx:1101
static SfxObjectShell * GetNext(const SfxObjectShell &rPrev, const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
bool IsAPI() const
ScDocFunc & GetDocFunc()
Definition: docsh.hxx:218
bool GetTableSelect(SCTAB nTab) const
Definition: markdata.cxx:184
void Ignore()
std::set< SCTAB > MarkedTabsType
Definition: markdata.hxx:45
This class contains authoritative information on the internal reference used as the data source for d...
Definition: dpshttab.hxx:38
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
Definition: document.cxx:212
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
Create before modifications of the document and destroy thereafter.
Definition: docsh.hxx:451
::std::vector< ScUndoTabColorInfo > List
Definition: tabbgcolor.hxx:36
sal_Int16 SCTAB
Definition: types.hxx:22
ViewShellId GetViewShellId() const override