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