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