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;
468  OUString aDocName;
469  OUString aTabName;
470 
471  if( pReqArgs != nullptr )
472  {
473  SCTAB nTableCount = rDoc.GetTableCount();
474  const SfxPoolItem* pItem;
475 
476  if( pReqArgs->HasItem( FID_TAB_MOVE, &pItem ) )
477  aDocName = static_cast<const SfxStringItem*>(pItem)->GetValue();
478  if( pReqArgs->HasItem( FN_PARAM_1, &pItem ) )
479  {
480  // table is 1-based
481  nTab = static_cast<const SfxUInt16Item*>(pItem)->GetValue() - 1;
482  if ( nTab >= nTableCount )
483  nTab = SC_TAB_APPEND;
484  }
485  if( pReqArgs->HasItem( FN_PARAM_2, &pItem ) )
486  bCpy = static_cast<const SfxBoolItem*>(pItem)->GetValue();
487 
488  if (!aDocName.isEmpty())
489  {
491  ScDocShell* pScSh = nullptr;
492  sal_uInt16 i=0;
493 
494  while ( pSh )
495  {
496  pScSh = dynamic_cast<ScDocShell*>( pSh );
497 
498  if( pScSh )
499  {
500  pScSh->GetTitle();
501 
502  if (aDocName == pScSh->GetTitle())
503  {
504  nDoc = i;
505  ScDocument& rDestDoc = pScSh->GetDocument();
506  nTableCount = rDestDoc.GetTableCount();
507  bDoIt = rDestDoc.IsDocEditable();
508  break;
509  }
510 
511  i++; // only count ScDocShell
512  }
513  pSh = SfxObjectShell::GetNext( *pSh );
514  }
515  }
516  else // no doc-name -> new doc
517  {
518  nDoc = SC_DOC_NEW;
519  bDoIt = true;
520  }
521 
522  if ( bDoIt && nTab >= nTableCount ) // if necessary append
523  nTab = SC_TAB_APPEND;
524  }
525  else
526  {
527  OUString aDefaultName;
528  rDoc.GetName( rViewData.GetTabNo(), aDefaultName );
529 
531 
533  aDefaultName));
534 
535  SCTAB nTableCount = rDoc.GetTableCount();
536  ScMarkData& rMark = GetViewData().GetMarkData();
537  SCTAB nTabSelCount = rMark.GetSelectCount();
538 
539  if(nTableCount==nTabSelCount)
540  {
541  pDlg->SetForceCopyTable();
542  }
543 
544  // We support direct renaming of sheet only when one sheet
545  // is selected.
546  pDlg->EnableRenameTable(nTabSelCount == 1);
547 
548  if ( pDlg->Execute() == RET_OK )
549  {
550  nDoc = pDlg->GetSelectedDocument();
551  nTab = pDlg->GetSelectedTable();
552  bCpy = pDlg->GetCopyTable();
553  bool bRna = pDlg->GetRenameTable();
554  // Leave aTabName string empty, when Rename is FALSE.
555  if( bRna )
556  {
557  pDlg->GetTabNameString( aTabName );
558  }
559  bDoIt = true;
560 
561  OUString aFoundDocName;
562  if ( nDoc != SC_DOC_NEW )
563  {
564  ScDocShell* pSh = ScDocShell::GetShellByNum( nDoc );
565  if (pSh)
566  {
567  aFoundDocName = pSh->GetTitle();
568  if ( !pSh->GetDocument().IsDocEditable() )
569  {
570  ErrorMessage(STR_READONLYERR);
571  bDoIt = false;
572  }
573  }
574  }
575  rReq.AppendItem( SfxStringItem( FID_TAB_MOVE, aFoundDocName ) );
576  // 1-based table, if not APPEND
577  SCTAB nBasicTab = ( nTab <= MAXTAB ) ? (nTab+1) : nTab;
578  rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nBasicTab) ) );
579  rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) );
580  }
581  }
582 
583  if( bDoIt )
584  {
585  rReq.Done(); // record, while doc is active
586 
587  MoveTable( nDoc, nTab, bCpy, &aTabName );
588  }
589  }
590  break;
591 
592  case FID_DELETE_TABLE:
593  {
594  bool bHasIndex = (pReqArgs != nullptr);
595 
596  // allow removing via the Index/FID_DELETE_TABLE parameter
597  SCTAB nTabNr = nCurrentTab;
598  if (bHasIndex)
599  {
600  const SfxPoolItem* pItem;
601  if (pReqArgs->HasItem(FID_DELETE_TABLE, &pItem))
602  {
603  nTabNr = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
604 
605  // inserting is 1-based, let's be consistent
606  if (nTabNr > 0)
607  --nTabNr;
608  }
609  }
610 
611  bool bDoIt = bHasIndex;
612  if (!bDoIt)
613  {
614  bool bTabWithPivotTable = false;
615  if (rDoc.HasPivotTable())
616  {
617  const ScDPCollection* pDPs = rDoc.GetDPCollection();
618  if (pDPs)
619  {
620  const ScMarkData::MarkedTabsType& rSelectedTabs = rViewData.GetMarkData().GetSelectedTabs();
621  for (const SCTAB nSelTab : rSelectedTabs)
622  {
623  const size_t nCount = pDPs->GetCount();
624  for (size_t i = 0; i < nCount; ++i)
625  {
626  const ScDPObject& rDPObj = (*pDPs)[i];
627  const ScSheetSourceDesc* pSheetSourceDesc = rDPObj.GetSheetDesc();
628  if (pSheetSourceDesc && pSheetSourceDesc->GetSourceRange().aStart.Tab() == nSelTab)
629  bTabWithPivotTable = true;
630  }
631  if (bTabWithPivotTable)
632  break;
633  }
634  }
635  }
636 
637  if (bTabWithPivotTable)
638  {
639  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
640  VclMessageType::Question, VclButtonsType::YesNo,
641  ScResId(STR_QUERY_PIVOTTABLE_DELTAB)));
642  xQueryBox->set_default_response(RET_NO);
643 
644  // Hard warning as there is potential of data loss on deletion
645  bDoIt = (RET_YES == xQueryBox->run());
646  }
647  else
648  {
649  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
650  VclMessageType::Question, VclButtonsType::YesNo,
651  ScResId(STR_QUERY_DELTAB)));
652  xQueryBox->set_default_response(RET_YES);
653 
654  // no parameter given, ask for confirmation
655  bDoIt = (RET_YES == xQueryBox->run());
656  }
657  }
658 
659  if (bDoIt)
660  {
661  SCTAB nNewTab = nCurrentTab;
662  std::vector<SCTAB> TheTabs;
663 
664  if (bHasIndex)
665  {
666  // sheet no. provided by the parameter
667  TheTabs.push_back(nTabNr);
668  if (nNewTab > nTabNr && nNewTab > 0)
669  --nNewTab;
670  }
671  else
672  {
673  SCTAB nFirstTab = 0;
674  bool bTabFlag = false;
675  ScMarkData& rMark = rViewData.GetMarkData();
676  for (SCTAB i = 0; i < nTabCount; i++)
677  {
678  if (rMark.GetTableSelect(i) && !rDoc.IsTabProtected(i))
679  {
680  TheTabs.push_back(i);
681  bTabFlag = true;
682  if (nNewTab == i && i+1 < nTabCount)
683  nNewTab++;
684  }
685  if (!bTabFlag)
686  nFirstTab = i;
687  }
688  if (nNewTab >= nTabCount - static_cast<SCTAB>(TheTabs.size()))
689  nNewTab = nFirstTab;
690  }
691 
692  rViewData.SetTabNo(nNewTab);
693  DeleteTables(TheTabs);
694  TheTabs.clear();
695  rReq.Done();
696  }
697  }
698  break;
699 
700  case FID_TAB_RTL:
701  {
702  ScDocShell* pDocSh = rViewData.GetDocShell();
703  ScDocFunc &rFunc = pDocSh->GetDocFunc();
704  bool bSet = !rDoc.IsLayoutRTL( nCurrentTab );
705 
706  const ScMarkData& rMark = rViewData.GetMarkData();
707  if ( rMark.GetSelectCount() != 0 )
708  {
709  // handle several sheets
710 
711  SfxUndoManager* pUndoManager = pDocSh->GetUndoManager();
712  OUString aUndo = ScResId( STR_UNDO_TAB_RTL );
713  pUndoManager->EnterListAction( aUndo, aUndo, 0, rViewData.GetViewShell()->GetViewShellId() );
714 
715  for (const auto& rTab : rMark)
716  rFunc.SetLayoutRTL( rTab, bSet );
717 
718  pUndoManager->LeaveListAction();
719  }
720  else
721  rFunc.SetLayoutRTL( nCurrentTab, bSet );
722  }
723  break;
724 
725  case FID_TAB_TOGGLE_GRID:
726  {
727  bool bShowGrid = rViewData.GetShowGrid();
728  rViewData.SetShowGrid(!bShowGrid);
729  SfxBindings& rBindings = GetViewFrame()->GetBindings();
730  rBindings.Invalidate( FID_TAB_TOGGLE_GRID );
731  PaintGrid();
732  rReq.Done();
733  }
734  break;
735 
736  case FID_TAB_SET_TAB_BG_COLOR:
737  case FID_TAB_MENU_SET_TAB_BG_COLOR:
738  {
739  if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
740  nSlot = FID_TAB_SET_TAB_BG_COLOR;
741  SCTAB nTabNr = rViewData.GetTabNo();
742  ScMarkData& rMark = rViewData.GetMarkData();
743  SCTAB nTabSelCount = rMark.GetSelectCount();
744  if ( !rDoc.IsDocEditable() )
745  break;
746 
747  if ( rDoc.IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1
748  break;
749 
750  if( pReqArgs != nullptr )
751  {
752  bool bDone = false;
753  const SfxPoolItem* pItem;
754  Color aColor;
755 
756  if( pReqArgs->HasItem( nSlot, &pItem ) )
757  aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
758 
759  if ( nTabSelCount > 1 )
760  {
761  std::unique_ptr<ScUndoTabColorInfo::List>
762  pTabColorList(new ScUndoTabColorInfo::List);
763  for (const auto& rTab : rMark)
764  {
765  if ( !rDoc.IsTabProtected(rTab) )
766  {
767  ScUndoTabColorInfo aTabColorInfo(rTab);
768  aTabColorInfo.maNewTabBgColor = aColor;
769  pTabColorList->push_back(aTabColorInfo);
770  }
771  }
772  bDone = SetTabBgColor( *pTabColorList );
773  }
774  else
775  {
776  bDone = SetTabBgColor( aColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
777  }
778  if( bDone )
779  {
780  rReq.Done( *pReqArgs );
781  }
782  }
783  else
784  {
785  sal_uInt16 nRet = RET_OK;
786  bool bDone = false;
787 
788  Color aTabBgColor = rDoc.GetTabBgColor( nCurrentTab );
791  GetFrameWeld(),
792  ScResId(SCSTR_SET_TAB_BG_COLOR),
793  ScResId(SCSTR_NO_TAB_BG_COLOR),
794  aTabBgColor));
795  while ( !bDone && nRet == RET_OK )
796  {
797  nRet = pDlg->Execute();
798  if( nRet == RET_OK )
799  {
800  Color aSelectedColor;
801  pDlg->GetSelectedColor(aSelectedColor);
802  std::unique_ptr<ScUndoTabColorInfo::List>
803  pTabColorList(new ScUndoTabColorInfo::List);
804  if ( nTabSelCount > 1 )
805  {
806  for (const auto& rTab : rMark)
807  {
808  if ( !rDoc.IsTabProtected(rTab) )
809  {
810  ScUndoTabColorInfo aTabColorInfo(rTab);
811  aTabColorInfo.maNewTabBgColor = aSelectedColor;
812  pTabColorList->push_back(aTabColorInfo);
813  }
814  }
815  bDone = SetTabBgColor( *pTabColorList );
816  }
817  else
818  {
819  bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
820  }
821 
822  if ( bDone )
823  {
824  rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) );
825  rReq.Done();
826  }
827  else
828  {
829  if( rReq.IsAPI() )
830  {
831 #if HAVE_FEATURE_SCRIPTING
833 #endif
834  }
835  }
836  }
837  }
838  }
839  }
840  break;
841 
842  case FID_TAB_EVENTS:
843  {
844  ScDocShell* pDocSh = rViewData.GetDocShell();
845  uno::Reference<container::XNameReplace> xEvents( new ScSheetEventsObj( pDocSh, nCurrentTab ) );
846  uno::Reference<frame::XFrame> xFrame = GetViewFrame()->GetFrame().GetFrameInterface();
849  GetFrameWeld(), xFrame, false, xEvents, 0 ) );
850  if ( pDialog->Execute() == RET_OK )
851  {
852  // the dialog modifies the settings directly
853  }
854  }
855  break;
856 
857  default:
858  OSL_FAIL("unknown message for ViewShell");
859  break;
860  }
861 }
862 
864 {
865  ScViewData& rViewData = GetViewData();
866  ScDocument& rDoc = rViewData.GetDocument();
867  ScDocShell* pDocShell = rViewData.GetDocShell();
868  ScMarkData& rMark = GetViewData().GetMarkData();
869  SCTAB nTab = rViewData.GetTabNo();
870 
871  SCTAB nTabCount = rDoc.GetTableCount();
872  SCTAB nTabSelCount = rMark.GetSelectCount();
873 
874  SfxWhichIter aIter(rSet);
875  sal_uInt16 nWhich = aIter.FirstWhich();
876 
877  while ( nWhich )
878  {
879  switch ( nWhich )
880  {
881 
882  case FID_TABLE_VISIBLE:
883  rSet.Put( SfxBoolItem( nWhich, rDoc.IsVisible(nTab) ));
884  break;
885 
886  case FID_TABLE_HIDE:
887  {
888  sal_uInt16 nVis = 0;
889  // enable menu : check to make sure we won't hide all sheets. we need at least one visible at all times.
890  for ( SCTAB i=0; i < nTabCount && nVis<nTabSelCount + 1; i++ )
891  if (rDoc.IsVisible(i))
892  ++nVis;
893  if ( nVis<=nTabSelCount || !rDoc.IsDocEditable() )
894  rSet.DisableItem( nWhich );
895  }
896  break;
897 
898  case FID_TABLE_SHOW:
899  {
900  bool bHasHidden = false;
901  for ( SCTAB i=0; i < nTabCount && !bHasHidden; i++ )
902  if (!rDoc.IsVisible(i))
903  bHasHidden = true;
904  if ( !bHasHidden || rDoc.IsDocProtected() || nTabSelCount > 1 )
905  rSet.DisableItem( nWhich );
906  }
907  break;
908 
909  case FID_DELETE_TABLE:
910  {
911  if ( rDoc.GetChangeTrack() )
912  rSet.DisableItem( nWhich );
913  else
914  {
915  sal_uInt16 nVis = 0;
916  for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
917  if (rDoc.IsVisible(i))
918  ++nVis;
919  if ( rDoc.IsTabProtected(nTab)
920  || !rDoc.IsDocEditable()
921  || nVis < 2
922  || nTabSelCount == nTabCount)
923  rSet.DisableItem( nWhich );
924  }
925  }
926  break;
927 
928  case FID_INS_TABLE:
929  case FID_INS_TABLE_EXT:
930  case FID_TAB_APPEND:
931  if ( !rDoc.IsDocEditable() ||
932  nTabCount > MAXTAB ||
933  ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->IsDocShared() ) )
934  rSet.DisableItem( nWhich );
935  break;
936 
937  case FID_TAB_MOVE:
938  if ( !rDoc.IsDocEditable()
939  || rDoc.GetChangeTrack() != nullptr
940  || nTabCount > MAXTAB)
941  rSet.DisableItem( nWhich );
942  break;
943 
944  // FID_TAB_MENU_RENAME - "rename" from Menu
945  // FID_TAB_RENAME - "name"-property for Basic
946 
947  case FID_TAB_MENU_RENAME:
948  if ( !rDoc.IsDocEditable() ||
949  rDoc.IsTabProtected(nTab) ||nTabSelCount > 1 ||
950  ( pDocShell && pDocShell->IsDocShared() ) )
951  rSet.DisableItem( nWhich );
952  break;
953 
954  case FID_TAB_RENAME:
955  {
956  OUString aTabName;
957  rDoc.GetName( nTab, aTabName );
958 
959  rSet.Put( SfxStringItem( nWhich, aTabName ));
960 
961  }
962  break;
963 
964  case FID_TAB_RTL:
965  {
966  SvtLanguageOptions aLangOpt;
967  if ( !aLangOpt.IsCTLFontEnabled() )
968  rSet.DisableItem( nWhich );
969  else
970  rSet.Put( SfxBoolItem( nWhich, rDoc.IsLayoutRTL( nTab ) ) );
971  }
972  break;
973 
974  case FID_TAB_MENU_SET_TAB_BG_COLOR:
975  {
976  if ( !rDoc.IsDocEditable()
977  || ( pDocShell && pDocShell->IsDocShared() )
978  || rDoc.IsTabProtected(nTab) )
979  rSet.DisableItem( nWhich );
980  }
981  break;
982 
983  case FID_TAB_SET_TAB_BG_COLOR:
984  {
985  Color aColor = rDoc.GetTabBgColor( nTab );
986  rSet.Put( SvxColorItem( aColor, nWhich ) );
987  }
988  break;
989 
990  case FID_TAB_TOGGLE_GRID:
991  rSet.Put( SfxBoolItem(nWhich, rViewData.GetShowGrid()) );
992  break;
993  }
994  nWhich = aIter.NextWhich();
995  }
996 }
997 
998 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC bool IsDocProtected() const
Definition: documen3.cxx:1879
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3046
#define HID_SC_APPEND_NAME
Definition: helpids.h:44
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
ScAddress aStart
Definition: address.hxx:500
bool bVisible
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1890
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
SC_DLLPUBLIC size_t GetCount() const
Definition: dpobject.cxx:3677
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:360
virtual VclPtr< AbstractScInsertTableDlg > CreateScInsertTableDlg(weld::Window *pParent, ScViewData &rViewData, SCTAB nTabCount, bool bFromFile)=0
sal_uInt16 FirstWhich()
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
void Done(bool bRemove=false)
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
const MarkedTabsType & GetSelectedTabs() const
Definition: markdata.hxx:98
sal_uInt16 NextWhich()
#define SC_DOC_NEW
Definition: document.hxx:238
virtual SfxUndoManager * GetUndoManager() override
Definition: docsh.cxx:2805
RET_NO
#define ERRCODE_BASIC_SETPROP_FAILED
RET_YES
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:314
SCTAB GetSelectCount() const
Definition: markdata.cxx:195
int nCount
bool IsDocShared() const
SCTAB Tab() const
Definition: address.hxx:271
SC_DLLPUBLIC const ScRange & GetSourceRange() const
Get the range that contains the source data.
Definition: dpshttab.cxx:229
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2392
ScTabViewShell * GetViewShell() const
Definition: viewdata.hxx:357
void SetTabNo(SCTAB nNewTab)
Definition: viewdata.cxx:2254
const SCTAB SC_TAB_APPEND
Definition: address.hxx:84
SC_DLLPUBLIC bool HasPivotTable() const
Definition: documen3.cxx:355
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:392
void SelectOneTable(SCTAB nTab)
Definition: markdata.cxx:189
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
void GetStateTable(SfxItemSet &rSet)
Definition: tabvwshf.cxx:863
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:71
size_t LeaveListAction()
static ScDocShell * GetShellByNum(sal_uInt16 nDocNo)
Definition: docsh4.cxx:2586
#define HID_SC_RENAME_NAME
Definition: helpids.h:43
SC_DLLPUBLIC Color GetTabBgColor(SCTAB nTab) const
Definition: documen3.cxx:443
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
static void Error(ErrCode)
bool SetLayoutRTL(SCTAB nTab, bool bRTL)
Definition: docfunc.cxx:3455
void DisableItem(sal_uInt16 nWhich)
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
Definition: documen3.cxx:427
static SfxObjectShell * GetFirst(const std::function< bool(const SfxObjectShell *)> &isObjectShell=nullptr, bool bOnlyVisible=true)
bool GetShowGrid() const
Definition: viewdata.hxx:463
OUString aName
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:38
bool IsDocEditable() const
Definition: documen3.cxx:1884
RET_OK
bool IsCTLFontEnabled() const
SCTAB GetLastSelected() const
Definition: markdata.cxx:209
const ScSheetSourceDesc * GetSheetDesc() const
Definition: dpobject.hxx:156
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:994
SC_DLLPUBLIC bool IsVisible(SCTAB nTab) const
Definition: document.cxx:908
void AppendItem(const SfxPoolItem &)
void SetShowGrid(bool bShow)
Definition: viewdata.cxx:1098
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:46
This class contains authoritative information on the internal reference used as the data source for d...
Definition: dpshttab.hxx:39
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
SC_DLLPUBLIC bool GetName(SCTAB nTab, OUString &rName) const
Definition: document.cxx:213
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
::std::vector< ScUndoTabColorInfo > List
Definition: tabbgcolor.hxx:37
sal_Int16 SCTAB
Definition: types.hxx:23
ViewShellId GetViewShellId() const override