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  PaintGrid();
739  rReq.Done();
740  }
741  break;
742 
743  case FID_TAB_SET_TAB_BG_COLOR:
744  case FID_TAB_MENU_SET_TAB_BG_COLOR:
745  {
746  if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR )
747  nSlot = FID_TAB_SET_TAB_BG_COLOR;
748  SCTAB nTabNr = rViewData.GetTabNo();
749  ScMarkData& rMark = rViewData.GetMarkData();
750  SCTAB nTabSelCount = rMark.GetSelectCount();
751  if ( !rDoc.IsDocEditable() )
752  break;
753 
754  if ( rDoc.IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1
755  break;
756 
757  if( pReqArgs != nullptr )
758  {
759  bool bDone = false;
760  const SfxPoolItem* pItem;
761  Color aColor;
762 
763  if( pReqArgs->HasItem( nSlot, &pItem ) )
764  aColor = static_cast<const SvxColorItem*>(pItem)->GetValue();
765 
766  if ( nTabSelCount > 1 )
767  {
768  std::unique_ptr<ScUndoTabColorInfo::List>
769  pTabColorList(new ScUndoTabColorInfo::List);
770  for (const auto& rTab : rMark)
771  {
772  if ( !rDoc.IsTabProtected(rTab) )
773  {
774  ScUndoTabColorInfo aTabColorInfo(rTab);
775  aTabColorInfo.maNewTabBgColor = aColor;
776  pTabColorList->push_back(aTabColorInfo);
777  }
778  }
779  bDone = SetTabBgColor( *pTabColorList );
780  }
781  else
782  {
783  bDone = SetTabBgColor( aColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
784  }
785  if( bDone )
786  {
787  rReq.Done( *pReqArgs );
788  }
789  }
790  else
791  {
792  sal_uInt16 nRet = RET_OK;
793  bool bDone = false;
794 
795  Color aTabBgColor = rDoc.GetTabBgColor( nCurrentTab );
798  GetFrameWeld(),
799  ScResId(SCSTR_SET_TAB_BG_COLOR),
800  ScResId(SCSTR_NO_TAB_BG_COLOR),
801  aTabBgColor));
802  while ( !bDone && nRet == RET_OK )
803  {
804  nRet = pDlg->Execute();
805  if( nRet == RET_OK )
806  {
807  Color aSelectedColor;
808  pDlg->GetSelectedColor(aSelectedColor);
809  std::unique_ptr<ScUndoTabColorInfo::List>
810  pTabColorList(new ScUndoTabColorInfo::List);
811  if ( nTabSelCount > 1 )
812  {
813  for (const auto& rTab : rMark)
814  {
815  if ( !rDoc.IsTabProtected(rTab) )
816  {
817  ScUndoTabColorInfo aTabColorInfo(rTab);
818  aTabColorInfo.maNewTabBgColor = aSelectedColor;
819  pTabColorList->push_back(aTabColorInfo);
820  }
821  }
822  bDone = SetTabBgColor( *pTabColorList );
823  }
824  else
825  {
826  bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor
827  }
828 
829  if ( bDone )
830  {
831  rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) );
832  rReq.Done();
833  }
834  else
835  {
836  if( rReq.IsAPI() )
837  {
838 #if HAVE_FEATURE_SCRIPTING
840 #endif
841  }
842  }
843  }
844  }
845  }
846  }
847  break;
848 
849  case FID_TAB_EVENTS:
850  {
851  ScDocShell* pDocSh = rViewData.GetDocShell();
852  uno::Reference<container::XNameReplace> xEvents( new ScSheetEventsObj( pDocSh, nCurrentTab ) );
853  uno::Reference<frame::XFrame> xFrame = GetViewFrame()->GetFrame().GetFrameInterface();
856  GetFrameWeld(), xFrame, false, xEvents, 0 ) );
857  if ( pDialog->Execute() == RET_OK )
858  {
859  // the dialog modifies the settings directly
860  }
861  }
862  break;
863 
864  default:
865  OSL_FAIL("unknown message for ViewShell");
866  break;
867  }
868 }
869 
871 {
872  ScViewData& rViewData = GetViewData();
873  ScDocument& rDoc = rViewData.GetDocument();
874  ScDocShell* pDocShell = rViewData.GetDocShell();
875  ScMarkData& rMark = GetViewData().GetMarkData();
876  SCTAB nTab = rViewData.GetTabNo();
877 
878  SCTAB nTabCount = rDoc.GetTableCount();
879  SCTAB nTabSelCount = rMark.GetSelectCount();
880 
881  SfxWhichIter aIter(rSet);
882  sal_uInt16 nWhich = aIter.FirstWhich();
883 
884  while ( nWhich )
885  {
886  switch ( nWhich )
887  {
888 
889  case FID_TABLE_VISIBLE:
890  rSet.Put( SfxBoolItem( nWhich, rDoc.IsVisible(nTab) ));
891  break;
892 
893  case FID_TABLE_HIDE:
894  {
895  sal_uInt16 nVis = 0;
896  // enable menu : check to make sure we won't hide all sheets. we need at least one visible at all times.
897  for ( SCTAB i=0; i < nTabCount && nVis<nTabSelCount + 1; i++ )
898  if (rDoc.IsVisible(i))
899  ++nVis;
900  if ( nVis<=nTabSelCount || !rDoc.IsDocEditable() )
901  rSet.DisableItem( nWhich );
902  }
903  break;
904 
905  case FID_TABLE_SHOW:
906  {
907  bool bHasHidden = false;
908  for ( SCTAB i=0; i < nTabCount && !bHasHidden; i++ )
909  if (!rDoc.IsVisible(i))
910  bHasHidden = true;
911  if ( !bHasHidden || rDoc.IsDocProtected() || nTabSelCount > 1 )
912  rSet.DisableItem( nWhich );
913  }
914  break;
915 
916  case FID_DELETE_TABLE:
917  {
918  if ( rDoc.GetChangeTrack() )
919  rSet.DisableItem( nWhich );
920  else
921  {
922  sal_uInt16 nVis = 0;
923  for ( SCTAB i=0; i < nTabCount && nVis<2; i++ )
924  if (rDoc.IsVisible(i))
925  ++nVis;
926  if ( rDoc.IsTabProtected(nTab)
927  || !rDoc.IsDocEditable()
928  || nVis < 2
929  || nTabSelCount == nTabCount)
930  rSet.DisableItem( nWhich );
931  }
932  }
933  break;
934 
935  case FID_INS_TABLE:
936  case FID_INS_TABLE_EXT:
937  case FID_TAB_APPEND:
938  if ( !rDoc.IsDocEditable() ||
939  nTabCount > MAXTAB ||
940  ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->IsDocShared() ) )
941  rSet.DisableItem( nWhich );
942  break;
943 
944  case FID_TAB_MOVE:
945  if ( !rDoc.IsDocEditable()
946  || rDoc.GetChangeTrack() != nullptr
947  || nTabCount > MAXTAB)
948  rSet.DisableItem( nWhich );
949  break;
950 
951  // FID_TAB_MENU_RENAME - "rename" from Menu
952  // FID_TAB_RENAME - "name"-property for Basic
953 
954  case FID_TAB_MENU_RENAME:
955  if ( !rDoc.IsDocEditable() ||
956  rDoc.IsTabProtected(nTab) ||nTabSelCount > 1 ||
957  ( pDocShell && pDocShell->IsDocShared() ) )
958  rSet.DisableItem( nWhich );
959  break;
960 
961  case FID_TAB_RENAME:
962  {
963  OUString aTabName;
964  rDoc.GetName( nTab, aTabName );
965 
966  rSet.Put( SfxStringItem( nWhich, aTabName ));
967 
968  }
969  break;
970 
971  case FID_TAB_RTL:
972  {
973  SvtLanguageOptions aLangOpt;
974  if ( !aLangOpt.IsCTLFontEnabled() )
975  rSet.DisableItem( nWhich );
976  else
977  rSet.Put( SfxBoolItem( nWhich, rDoc.IsLayoutRTL( nTab ) ) );
978  }
979  break;
980 
981  case FID_TAB_MENU_SET_TAB_BG_COLOR:
982  {
983  if ( !rDoc.IsDocEditable()
984  || ( pDocShell && pDocShell->IsDocShared() )
985  || rDoc.IsTabProtected(nTab) )
986  rSet.DisableItem( nWhich );
987  }
988  break;
989 
990  case FID_TAB_SET_TAB_BG_COLOR:
991  {
992  Color aColor = rDoc.GetTabBgColor( nTab );
993  rSet.Put( SvxColorItem( aColor, nWhich ) );
994  }
995  break;
996 
997  case FID_TAB_TOGGLE_GRID:
998  rSet.Put( SfxBoolItem(nWhich, rViewData.GetShowGrid()) );
999  break;
1000  }
1001  nWhich = aIter.NextWhich();
1002  }
1003 }
1004 
1005 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC bool IsDocProtected() const
Definition: documen3.cxx:1878
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:1889
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:359
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:2806
RET_NO
#define ERRCODE_BASIC_SETPROP_FAILED
RET_YES
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:312
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:2389
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:354
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:390
void SelectOneTable(SCTAB nTab)
Definition: markdata.cxx:189
OUString ScResId(const char *pId)
Definition: scdll.cxx:89
void GetStateTable(SfxItemSet &rSet)
Definition: tabvwshf.cxx:870
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:2595
#define HID_SC_RENAME_NAME
Definition: helpids.h:43
SC_DLLPUBLIC Color GetTabBgColor(SCTAB nTab) const
Definition: documen3.cxx:442
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:3456
void DisableItem(sal_uInt16 nWhich)
SC_DLLPUBLIC bool IsScenario(SCTAB nTab) const
Definition: documen3.cxx:426
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:37
bool IsDocEditable() const
Definition: documen3.cxx:1883
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:217
void ExecuteTable(SfxRequest &rReq)
Definition: tabvwshf.cxx:61
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
Definition: document.cxx:992
SC_DLLPUBLIC bool IsVisible(SCTAB nTab) const
Definition: document.cxx:906
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:219
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:211
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