LibreOffice Module sc (master)  1
tabvwshc.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 <scitems.hxx>
21 #include <sfx2/childwin.hxx>
22 #include <sfx2/dispatch.hxx>
23 #include <editeng/editview.hxx>
24 #include <inputhdl.hxx>
25 
26 #include <tabvwsh.hxx>
27 #include <sc.hrc>
28 #include <scres.hrc>
29 #include <global.hxx>
30 #include <scmod.hxx>
31 #include <document.hxx>
32 #include <uiitems.hxx>
33 #include <namedlg.hxx>
34 #include <namedefdlg.hxx>
35 #include <solvrdlg.hxx>
36 #include <optsolver.hxx>
37 #include <tabopdlg.hxx>
38 #include <consdlg.hxx>
39 #include <filtdlg.hxx>
40 #include <dbnamdlg.hxx>
41 #include <areasdlg.hxx>
42 #include <crnrdlg.hxx>
43 #include <formula.hxx>
44 #include <highred.hxx>
45 #include <simpref.hxx>
46 #include <funcdesc.hxx>
47 #include <dpobject.hxx>
48 #include <markdata.hxx>
49 #include <reffact.hxx>
50 #include <condformatdlg.hxx>
51 #include <xmlsourcedlg.hxx>
52 #include <condformatdlgitem.hxx>
53 #include <formdata.hxx>
54 #include <inputwin.hxx>
55 
57 #include <SamplingDialog.hxx>
60 #include <CorrelationDialog.hxx>
61 #include <CovarianceDialog.hxx>
63 #include <MovingAverageDialog.hxx>
64 #include <RegressionDialog.hxx>
65 #include <TTestDialog.hxx>
66 #include <FTestDialog.hxx>
67 #include <ZTestDialog.hxx>
68 #include <ChiSquareTestDialog.hxx>
70 
71 #include <PivotLayoutDialog.hxx>
72 
73 #include <comphelper/lok.hxx>
74 #include <o3tl/make_shared.hxx>
75 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
76 
77 void ScTabViewShell::SetCurRefDlgId( sal_uInt16 nNew )
78 {
79  // CurRefDlgId is stored in ScModule to find if a ref dialog is open,
80  // and in the view to identify the view that has opened the dialog
81  nCurRefDlgId = nNew;
82 }
83 
84 //ugly hack to call Define Name from Manage Names
86 {
87  sal_uInt16 nSlotId = SC_MOD()->GetCurRefDlgId();
88  if( nSlotId == FID_ADD_NAME )
89  {
90  static_cast<ScNameDefDlg*>(pDialog)->GetNewData(maName, maScope);
91  static_cast<ScNameDefDlg*>(pDialog)->Close();
92  sal_uInt16 nId = ScNameDlgWrapper::GetChildWindowId();
93  SfxViewFrame* pViewFrm = GetViewFrame();
94  SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
95 
96  SC_MOD()->SetRefDialog( nId, pWnd == nullptr );
97  }
98  else if (nSlotId == FID_DEFINE_NAME)
99  {
100  mbInSwitch = true;
101  static_cast<ScNameDlg*>(pDialog)->GetRangeNames(m_RangeMap);
102  static_cast<ScNameDlg*>(pDialog)->Close();
103  sal_uInt16 nId = ScNameDefDlgWrapper::GetChildWindowId();
104  SfxViewFrame* pViewFrm = GetViewFrame();
105  SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
106 
107  SC_MOD()->SetRefDialog( nId, pWnd == nullptr );
108  }
109 }
110 
111 std::shared_ptr<SfxModelessDialogController> ScTabViewShell::CreateRefDialogController(
112  SfxBindings* pB, SfxChildWindow* pCW,
113  const SfxChildWinInfo* pInfo,
114  weld::Window* pParent, sal_uInt16 nSlotId)
115 {
116  // only open dialog when called through ScModule::SetRefDialog,
117  // so that it does not re appear for instance after a crash (#42341#).
118 
119  if ( SC_MOD()->GetCurRefDlgId() != nSlotId )
120  return nullptr;
121 
122  if ( nCurRefDlgId != nSlotId )
123  {
124  // the dialog has been opened in a different view
125  // -> lock the dispatcher for this view (modal mode)
126 
128  GetViewData().GetDispatcher().Lock( true ); // lock is reset when closing dialog
129 
130  return nullptr;
131  }
132 
133  std::shared_ptr<SfxModelessDialogController> xResult;
134 
135  if(pCW)
136  pCW->SetHideNotDelete(true);
137 
138  ScDocument& rDoc = GetViewData().GetDocument();
139 
140  switch( nSlotId )
141  {
142  case SID_CORRELATION_DIALOG:
143  xResult = std::make_shared<ScCorrelationDialog>(pB, pCW, pParent, GetViewData());
144  break;
145  case SID_SAMPLING_DIALOG:
146  xResult = std::make_shared<ScSamplingDialog>(pB, pCW, pParent, GetViewData());
147  break;
148  case SID_DESCRIPTIVE_STATISTICS_DIALOG:
149  xResult = std::make_shared<ScDescriptiveStatisticsDialog>(pB, pCW, pParent, GetViewData());
150  break;
151  case SID_ANALYSIS_OF_VARIANCE_DIALOG:
152  xResult = std::make_shared<ScAnalysisOfVarianceDialog>(pB, pCW, pParent, GetViewData());
153  break;
154  case SID_COVARIANCE_DIALOG:
155  xResult = std::make_shared<ScCovarianceDialog>(pB, pCW, pParent, GetViewData());
156  break;
157  case SID_EXPONENTIAL_SMOOTHING_DIALOG:
158  xResult = std::make_shared<ScExponentialSmoothingDialog>(pB, pCW, pParent, GetViewData());
159  break;
160  case SID_MOVING_AVERAGE_DIALOG:
161  xResult = std::make_shared<ScMovingAverageDialog>(pB, pCW, pParent, GetViewData());
162  break;
163  case SID_REGRESSION_DIALOG:
164  xResult = std::make_shared<ScRegressionDialog>(pB, pCW, pParent, GetViewData());
165  break;
166  case SID_FTEST_DIALOG:
167  xResult = std::make_shared<ScFTestDialog>(pB, pCW, pParent, GetViewData());
168  break;
169  case SID_TTEST_DIALOG:
170  xResult = std::make_shared<ScTTestDialog>(pB, pCW, pParent, GetViewData());
171  break;
172  case SID_ZTEST_DIALOG:
173  xResult = std::make_shared<ScZTestDialog>(pB, pCW, pParent, GetViewData());
174  break;
175  case SID_CHI_SQUARE_TEST_DIALOG:
176  xResult = std::make_shared<ScChiSquareTestDialog>(pB, pCW, pParent, GetViewData());
177  break;
178  case SID_FOURIER_ANALYSIS_DIALOG:
179  xResult = std::make_shared<ScFourierAnalysisDialog>(pB, pCW, pParent, GetViewData());
180  break;
181  case WID_SIMPLE_REF:
182  {
183  // dialog checks, what is in the cell
184 
185  ScViewData& rViewData = GetViewData();
186  rViewData.SetRefTabNo( rViewData.GetTabNo() );
187  xResult = std::make_shared<ScSimpleRefDlg>(pB, pCW, pParent);
188  break;
189  }
190  case FID_DEFINE_NAME:
191  {
192  if (!mbInSwitch)
193  {
194  xResult = std::make_shared<ScNameDlg>(pB, pCW, pParent, GetViewData(),
195  ScAddress( GetViewData().GetCurX(),
196  GetViewData().GetCurY(),
197  GetViewData().GetTabNo() ) );
198  }
199  else
200  {
201  xResult = std::make_shared<ScNameDlg>( pB, pCW, pParent, GetViewData(),
202  ScAddress( GetViewData().GetCurX(),
203  GetViewData().GetCurY(),
204  GetViewData().GetTabNo() ), &m_RangeMap);
205  static_cast<ScNameDlg*>(xResult.get())->SetEntry(maName, maScope);
206  mbInSwitch = false;
207  }
208  break;
209  }
210  case FID_ADD_NAME:
211  {
212  if (!mbInSwitch)
213  {
214  std::map<OUString, ScRangeName*> aRangeMap;
215  rDoc.GetRangeNameMap(aRangeMap);
216  xResult = std::make_shared<ScNameDefDlg>(pB, pCW, pParent, GetViewData(), aRangeMap,
217  ScAddress(GetViewData().GetCurX(),
218  GetViewData().GetCurY(),
219  GetViewData().GetTabNo()), true);
220  }
221  else
222  {
223  std::map<OUString, ScRangeName*> aRangeMap;
224  for (auto const& itr : m_RangeMap)
225  {
226  aRangeMap.insert(std::pair<OUString, ScRangeName*>(itr.first, itr.second.get()));
227  }
228  xResult = std::make_shared<ScNameDefDlg>(pB, pCW, pParent, GetViewData(), aRangeMap,
229  ScAddress(GetViewData().GetCurX(),
230  GetViewData().GetCurY(),
231  GetViewData().GetTabNo()), false);
232  }
233  break;
234  }
235  case SID_RANDOM_NUMBER_GENERATOR_DIALOG:
236  xResult = std::make_shared<ScRandomNumberGeneratorDialog>(pB, pCW, pParent, GetViewData());
237  break;
238  case SID_DEFINE_DBNAME:
239  {
240  // when called for an existing range, then mark
241  GetDBData( true, SC_DB_OLD );
242  const ScMarkData& rMark = GetViewData().GetMarkData();
243  if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
244  MarkDataArea( false );
245 
246  xResult = std::make_shared<ScDbNameDlg>(pB, pCW, pParent, GetViewData());
247  break;
248  }
249  case SID_OPENDLG_EDIT_PRINTAREA:
250  xResult = std::make_shared<ScPrintAreasDlg>(pB, pCW, pParent);
251  break;
252  case SID_DEFINE_COLROWNAMERANGES:
253  xResult = std::make_shared<ScColRowNameRangesDlg>(pB, pCW, pParent, GetViewData());
254  break;
255  case SID_OPENDLG_SOLVE:
256  {
257  ScViewData& rViewData = GetViewData();
258  ScAddress aCurPos( rViewData.GetCurX(),
259  rViewData.GetCurY(),
260  rViewData.GetTabNo());
261  xResult = std::make_shared<ScSolverDlg>(pB, pCW, pParent, &rViewData.GetDocument(), aCurPos);
262  break;
263  }
264  case SID_OPENDLG_TABOP:
265  {
266  ScViewData& rViewData = GetViewData();
267  ScRefAddress aCurPos ( rViewData.GetCurX(),
268  rViewData.GetCurY(),
269  rViewData.GetTabNo());
270 
271  xResult = std::make_shared<ScTabOpDlg>(pB, pCW, pParent, &rViewData.GetDocument(), aCurPos);
272  break;
273  }
274  case SID_OPENDLG_CONSOLIDATE:
275  {
276  SfxItemSet aArgSet( GetPool(),
279 
280  const ScConsolidateParam* pDlgData =
281  rDoc.GetConsolidateDlgData();
282 
283  if ( !pDlgData )
284  {
285  ScConsolidateParam aConsParam;
286  SCCOL nStartCol, nEndCol;
287  SCROW nStartRow, nEndRow;
288  SCTAB nStartTab, nEndTab;
289 
290  GetViewData().GetSimpleArea( nStartCol, nStartRow, nStartTab,
291  nEndCol, nEndRow, nEndTab );
292 
293  PutInOrder( nStartCol, nEndCol );
294  PutInOrder( nStartRow, nEndRow );
295  PutInOrder( nStartTab, nEndTab );
296 
297  aConsParam.nCol = nStartCol;
298  aConsParam.nRow = nStartRow;
299  aConsParam.nTab = nStartTab;
300 
302  &aConsParam ) );
303  }
304  else
305  {
306  aArgSet.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA, pDlgData ) );
307  }
308  xResult = std::make_shared<ScConsolidateDlg>(pB, pCW, pParent, aArgSet);
309  break;
310  }
311  case SID_FILTER:
312  {
313 
314  ScQueryParam aQueryParam;
315  SfxItemSet aArgSet( GetPool(),
317  SCITEM_QUERYDATA>{} );
318 
320  pDBData->ExtendDataArea(rDoc);
321  pDBData->GetQueryParam( aQueryParam );
322 
323  ScRange aArea;
324  pDBData->GetArea(aArea);
325  MarkRange(aArea, false);
326 
327  aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA,
328  &GetViewData(),
329  &aQueryParam ) );
330 
331  // mark current sheet (due to RefInput in dialog)
332  GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
333 
334  xResult = std::make_shared<ScFilterDlg>(pB, pCW, pParent, aArgSet);
335  break;
336  }
337  case SID_SPECIAL_FILTER:
338  {
339  ScQueryParam aQueryParam;
340  SfxItemSet aArgSet( GetPool(),
342  SCITEM_QUERYDATA>{} );
343 
345  pDBData->ExtendDataArea(rDoc);
346  pDBData->GetQueryParam( aQueryParam );
347 
348  ScRange aArea;
349  pDBData->GetArea(aArea);
350  MarkRange(aArea, false);
351 
352  ScQueryItem aItem( SCITEM_QUERYDATA, &GetViewData(), &aQueryParam );
353  ScRange aAdvSource;
354  if (pDBData->GetAdvancedQuerySource(aAdvSource))
355  aItem.SetAdvancedQuerySource( &aAdvSource );
356 
357  aArgSet.Put( aItem );
358 
359  // mark current sheet (due to RefInput in dialog)
360  GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
361 
362  xResult = std::make_shared<ScSpecialFilterDlg>(pB, pCW, pParent, aArgSet);
363  break;
364  }
365  case SID_OPENDLG_OPTSOLVER:
366  {
367  ScViewData& rViewData = GetViewData();
368  ScAddress aCurPos( rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo());
369  xResult = std::make_shared<ScOptSolverDlg>(pB, pCW, pParent, rViewData.GetDocShell(), aCurPos);
370  break;
371  }
372  case FID_CHG_SHOW:
373  {
374  // dialog checks, what is in the cell
375  xResult = std::make_shared<ScHighlightChgDlg>(pB, pCW, pParent, GetViewData());
376  break;
377  }
378  case SID_MANAGE_XML_SOURCE:
379  {
380  xResult = std::make_shared<ScXMLSourceDlg>(pB, pCW, pParent, &rDoc);
381  break;
382  }
383  case SID_OPENDLG_PIVOTTABLE:
384  {
385  // all settings must be in pDialogDPObject
386 
387  if( pDialogDPObject )
388  {
389  // Check for an existing datapilot output.
390  ScViewData& rViewData = GetViewData();
391  rViewData.SetRefTabNo( rViewData.GetTabNo() );
392  ScDPObject* pObj = rDoc.GetDPAtCursor(rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo());
393  xResult = std::make_shared<ScPivotLayoutDialog>(pB, pCW, pParent, &rViewData, pDialogDPObject.get(), pObj == nullptr);
394  }
395 
396  break;
397  }
398  case SID_OPENDLG_FUNCTION:
399  {
400  if (!isLOKMobilePhone())
401  {
402  // dialog checks, what is in the cell
403  xResult = o3tl::make_shared<ScFormulaDlg>(pB, pCW, pParent, GetViewData(), ScGlobal::GetStarCalcFunctionMgr());
404  }
405  break;
406  }
407  case WID_CONDFRMT_REF:
408  {
409  const ScCondFormatDlgItem* pDlgItem = nullptr;
410  // Get the pool item stored by Conditional Format Manager Dialog.
412  if (itemsRange.begin() != itemsRange.end())
413  {
414  const SfxPoolItem* pItem = *itemsRange.begin();
415  pDlgItem = static_cast<const ScCondFormatDlgItem*>(pItem);
416  }
417 
418  if (pDlgItem)
419  {
420  ScViewData& rViewData = GetViewData();
421  rViewData.SetRefTabNo( rViewData.GetTabNo() );
422 
423  xResult = std::make_shared<ScCondFormatDlg>(pB, pCW, pParent, &rViewData, pDlgItem);
424 
425  // Remove the pool item stored by Conditional Format Manager Dialog.
426  GetPool().Remove(*pDlgItem);
427  }
428 
429  break;
430  }
431  }
432 
433  if (xResult)
434  xResult->Initialize( pInfo );
435  return xResult;
436 }
437 
439 {
440  return GetViewData().GetTabNo();
441 }
442 
444 {
445  UpdateInputHandler(true, false);
446 
447  ScInputHandler* pHdl = mpInputHandler ? mpInputHandler.get() : SC_MOD()->GetInputHdl();
448  if (pHdl)
449  {
450  ScInputWindow* pInputWindow = pHdl->GetInputWindow();
451  if (pInputWindow)
452  {
453  pInputWindow->NotifyLOKClient();
454  }
455  }
456 }
457 
459 {
460  ScDrawView* pDrView = const_cast<ScTabViewShell*>(this)->GetScDrawView();
461  if (pDrView)
462  {
463  if (pDrView->GetTextEditObject())
464  {
465  // Blinking cursor.
466  EditView& rEditView = pDrView->GetTextEditOutlinerView()->GetEditView();
467  rEditView.RegisterOtherShell(pOtherShell);
468  rEditView.ShowCursor();
469  rEditView.RegisterOtherShell(nullptr);
470  // Text selection, if any.
471  rEditView.DrawSelectionXOR(pOtherShell);
472  }
473  else
474  {
475  // Graphic selection.
476  pDrView->AdjustMarkHdl(pOtherShell);
477  }
478  }
479 
480  const ScGridWindow* pWin = GetViewData().GetActiveWin();
481  if (pWin)
482  pWin->updateKitCellCursor(pOtherShell);
483 }
484 
485 css::uno::Reference<css::datatransfer::XTransferable2> ScTabViewShell::GetClipData(vcl::Window* pWin)
486 {
487  SfxViewFrame* pViewFrame = nullptr;
488  css::uno::Reference<css::datatransfer::XTransferable2> xTransferable;
489  css::uno::Reference<css::datatransfer::clipboard::XClipboard> xClipboard;
490 
491  if (pWin)
492  xClipboard = pWin->GetClipboard();
493  else if ((pViewFrame = SfxViewFrame::GetFirst(nullptr, false)))
494  xClipboard = pViewFrame->GetWindow().GetClipboard();
495 
496  xTransferable.set(xClipboard.is() ? xClipboard->getContents() : nullptr, css::uno::UNO_QUERY);
497 
498  return xTransferable;
499 }
500 
501 void ScTabViewShell::notifyAllViewsHeaderInvalidation(const SfxViewShell* pForViewShell, HeaderType eHeaderType, SCTAB nCurrentTabIndex)
502 {
504  return;
505 
506  OString aPayload;
507  switch (eHeaderType)
508  {
509  case COLUMN_HEADER:
510  aPayload = "column";
511  break;
512  case ROW_HEADER:
513  aPayload = "row";
514  break;
515  case BOTH_HEADERS:
516  default:
517  aPayload = "all";
518  break;
519  }
520 
521  SfxViewShell* pViewShell = SfxViewShell::GetFirst();
522  while (pViewShell)
523  {
524  ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
525  if (pTabViewShell && pViewShell->GetDocId() == pForViewShell->GetDocId()
526  && (nCurrentTabIndex == -1 || pTabViewShell->getPart() == nCurrentTabIndex))
527  {
528  pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_HEADER, aPayload.getStr());
529  }
530  pViewShell = SfxViewShell::GetNext(*pViewShell);
531  }
532 }
533 
534 bool ScTabViewShell::isAnyEditViewInRange(const SfxViewShell* pForViewShell, bool bColumns, SCCOLROW nStart, SCCOLROW nEnd)
535 {
537  {
538  SfxViewShell* pViewShell = SfxViewShell::GetFirst();
539  while (pViewShell)
540  {
541  ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
542  if (pTabViewShell && pTabViewShell->GetDocId() == pForViewShell->GetDocId())
543  {
544  ScInputHandler* pInputHandler = pTabViewShell->GetInputHandler();
545  if (pInputHandler && pInputHandler->GetActiveView())
546  {
547  const ScViewData& rViewData = pTabViewShell->GetViewData();
548  SCCOLROW nPos = bColumns ? rViewData.GetCurX() : rViewData.GetCurY();
549  if (nStart <= nPos && nPos <= nEnd)
550  return true;
551  }
552  }
553  pViewShell = SfxViewShell::GetNext(*pViewShell);
554  }
555  }
556  return false;
557 }
558 
559 void ScTabViewShell::notifyAllViewsSheetGeomInvalidation(const SfxViewShell* pForViewShell, bool bColumns,
560  bool bRows, bool bSizes, bool bHidden, bool bFiltered,
561  bool bGroups, SCTAB nCurrentTabIndex)
562 {
565  comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
566  return;
567 
568  if (!bColumns && !bRows)
569  return;
570 
571  bool bAllTypes = bSizes && bHidden && bFiltered && bGroups;
572  bool bAllDims = bColumns && bRows;
573  OString aPayload = bAllDims ? "all" : bColumns ? "columns" : "rows";
574 
575  if (!bAllTypes)
576  {
577  if (bSizes)
578  aPayload += " sizes";
579 
580  if (bHidden)
581  aPayload += " hidden";
582 
583  if (bFiltered)
584  aPayload += " filtered";
585 
586  if (bGroups)
587  aPayload += " groups";
588  }
589 
590  SfxViewShell* pViewShell = SfxViewShell::GetFirst();
591  while (pViewShell)
592  {
593  ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
594  if (pTabViewShell && pViewShell->GetDocId() == pForViewShell->GetDocId() &&
595  (nCurrentTabIndex == -1 || pTabViewShell->getPart() == nCurrentTabIndex))
596  {
597  pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_SHEET_GEOMETRY, aPayload.getStr());
598  }
599  pViewShell = SfxViewShell::GetNext(*pViewShell);
600  }
601 }
602 
604 {
605  bool bSubTotal = false;
606  ScDocument& rDoc = GetViewData().GetDocument();
607  size_t nRangeCount (pRangeList->size());
608  size_t nRangeIndex (0);
609  while (!bSubTotal && nRangeIndex < nRangeCount)
610  {
611  const ScRange& rRange = (*pRangeList)[nRangeIndex];
612  SCTAB nTabEnd(rRange.aEnd.Tab());
613  SCTAB nTab(rRange.aStart.Tab());
614  while (!bSubTotal && nTab <= nTabEnd)
615  {
616  SCROW nRowEnd(rRange.aEnd.Row());
617  SCROW nRow(rRange.aStart.Row());
618  while (!bSubTotal && nRow <= nRowEnd)
619  {
620  if (rDoc.RowFiltered(nRow, nTab))
621  bSubTotal = true;
622  else
623  ++nRow;
624  }
625  ++nTab;
626  }
627  ++nRangeIndex;
628  }
629 
630  if (!bSubTotal)
631  {
632  const ScDBCollection::NamedDBs& rDBs = rDoc.GetDBCollection()->getNamedDBs();
633  for (const auto& rxDB : rDBs)
634  {
635  const ScDBData& rDB = *rxDB;
636  if (!rDB.HasAutoFilter())
637  continue;
638 
639  nRangeIndex = 0;
640  while (!bSubTotal && nRangeIndex < nRangeCount)
641  {
642  const ScRange & rRange = (*pRangeList)[nRangeIndex];
643  ScRange aDBArea;
644  rDB.GetArea(aDBArea);
645  if (aDBArea.Intersects(rRange))
646  bSubTotal = true;
647  ++nRangeIndex;
648  }
649 
650  if (bSubTotal)
651  break;
652  }
653  }
654  return bSubTotal;
655 }
656 
657 OUString ScTabViewShell::DoAutoSum(bool& rRangeFinder, bool& rSubTotal, const OpCode eCode)
658 {
659  OUString aFormula;
660  const ScMarkData& rMark = GetViewData().GetMarkData();
661  if ( rMark.IsMarked() || rMark.IsMultiMarked() )
662  {
663  ScRangeList aMarkRangeList;
664  rRangeFinder = rSubTotal = false;
665  rMark.FillRangeListWithMarks( &aMarkRangeList, false );
666  ScDocument& rDoc = GetViewData().GetDocument();
667 
668  // check if one of the marked ranges is empty
669  bool bEmpty = false;
670  const size_t nCount = aMarkRangeList.size();
671  for ( size_t i = 0; i < nCount; ++i )
672  {
673  const ScRange & rRange( aMarkRangeList[i] );
674  if ( rDoc.IsBlockEmpty( rRange.aStart.Tab(),
675  rRange.aStart.Col(), rRange.aStart.Row(),
676  rRange.aEnd.Col(), rRange.aEnd.Row() ) )
677  {
678  bEmpty = true;
679  break;
680  }
681  }
682 
683  if ( bEmpty )
684  {
685  ScRangeList aRangeList;
686  const bool bDataFound = GetAutoSumArea( aRangeList );
687  if ( bDataFound )
688  {
689  ScAddress aAddr = aRangeList.back().aEnd;
690  aAddr.IncRow();
691  const bool bSubTotal( UseSubTotal( &aRangeList ) );
692  EnterAutoSum( aRangeList, bSubTotal, aAddr, eCode );
693  }
694  }
695  else
696  {
697  const bool bSubTotal( UseSubTotal( &aMarkRangeList ) );
698  for ( size_t i = 0; i < nCount; ++i )
699  {
700  const ScRange & rRange = aMarkRangeList[i];
701  const bool bSetCursor = ( i == nCount - 1 );
702  const bool bContinue = ( i != 0 );
703  if ( !AutoSum( rRange, bSubTotal, bSetCursor, bContinue, eCode ) )
704  {
705  MarkRange( rRange, false );
706  SetCursor( rRange.aEnd.Col(), rRange.aEnd.Row() );
707  const ScRangeList aRangeList;
708  ScAddress aAddr = rRange.aEnd;
709  aAddr.IncRow();
710  aFormula = GetAutoSumFormula( aRangeList, bSubTotal, aAddr , eCode);
711  break;
712  }
713  }
714  }
715  }
716  else // Only insert into input row
717  {
718  ScRangeList aRangeList;
719  rRangeFinder = GetAutoSumArea( aRangeList );
720  rSubTotal = UseSubTotal( &aRangeList );
721  ScAddress aAddr = GetViewData().GetCurPos();
722  aFormula = GetAutoSumFormula( aRangeList, rSubTotal, aAddr , eCode);
723  }
724  return aFormula;
725 }
726 
728 {
729  mpFormEditData.reset(new ScFormEditData);
730 }
731 
733 {
734  mpFormEditData.reset();
735 }
736 
737 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3046
SfxViewFrame * GetViewFrame() const
SC_DLLPUBLIC ScDPObject * GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: documen3.cxx:371
void MarkDataArea(bool bIncludeCursor=true)
Definition: tabview3.cxx:1652
bool HasAutoFilter() const
Definition: dbdata.hxx:204
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:813
ScDBData * GetDBData(bool bMarkArea=true, ScGetDBMode eMode=SC_DB_MAKE, ScGetDBSelection eSel=ScGetDBSelection::Keep)
Definition: dbfunc.cxx:80
ScAddress aStart
Definition: address.hxx:500
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
std::unique_ptr< ScInputHandler, o3tl::default_delete< ScInputHandler > > mpInputHandler
Definition: tabvwsh.hxx:116
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
SfxChildWindow * GetChildWindow(sal_uInt16)
bool isLOKMobilePhone() const
SCROW Row() const
Definition: address.hxx:262
HeaderType
Definition: tabview.hxx:58
bool GetAutoSumArea(ScRangeList &rRangeList)
Definition: viewfun2.cxx:477
css::uno::Reference< css::datatransfer::clipboard::XClipboard > GetClipboard()
void MarkRange(const ScRange &rRange, bool bSetCursor=true, bool bContinue=false)
Definition: tabview3.cxx:1683
std::unique_ptr< ScDPObject > pDialogDPObject
Definition: tabvwsh.hxx:126
SC_DLLPUBLIC bool Intersects(const ScRange &rRange) const
Definition: address.cxx:1558
int getPart() const override
See SfxViewShell::getPart().
Definition: tabvwshc.cxx:438
std::map< OUString, std::unique_ptr< ScRangeName > > m_RangeMap
Definition: tabvwsh.hxx:161
SdrTextObj * GetTextEditObject() const
SCROW GetCurY() const
Definition: viewdata.hxx:402
void ShowCursor(bool bGotoCursor=true, bool bForceVisCursor=true, bool bActivate=false)
sal_uInt16 nCurRefDlgId
Definition: tabvwsh.hxx:156
don't create
Definition: global.hxx:397
ViewShellDocId GetDocId() const override
void FillRangeListWithMarks(ScRangeList *pList, bool bClear, SCTAB nForTab=-1) const
Create a range list of marks.
Definition: markdata.cxx:387
sal_Int16 nId
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScAddress aEnd
Definition: address.hxx:501
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
static css::uno::Reference< css::datatransfer::XTransferable2 > GetClipData(vcl::Window *pWin)
Definition: tabvwshc.cxx:485
void Remove(const SfxPoolItem &)
SC_DLLPUBLIC void SetCursor(SCCOL nPosX, SCROW nPosY, bool bNew=false)
Definition: tabview3.cxx:359
#define SCITEM_QUERYDATA
Definition: scitems.hxx:91
OUString DoAutoSum(bool &rRangeFinder, bool &rSubTotal, const OpCode eCode)
Definition: tabvwshc.cxx:657
static void notifyAllViewsSheetGeomInvalidation(const SfxViewShell *pForViewShell, bool bColumns, bool bRows, bool bSizes, bool bHidden, bool bFiltered, bool bGroups, SCTAB nCurrentTabIndex)
Emits a LOK_CALLBACK_INVALIDATE_SHEET_GEOMETRY for all views whose current tab is equal to nCurrentTa...
Definition: tabvwshc.cxx:559
void updateKitCellCursor(const SfxViewShell *pOtherShell) const
Definition: gridwin.cxx:5664
EditView * GetActiveView()
Definition: inputhdl.cxx:2220
vcl::Window & GetWindow() const
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:24
bool IsMultiMarked() const
Definition: markdata.hxx:83
OpCode
void SetCurRefDlgId(sal_uInt16 nNew)
Definition: tabvwshc.cxx:77
void SetRefTabNo(SCTAB nNewTab)
Definition: viewdata.hxx:393
int nCount
static SfxViewShell * GetNext(const SfxViewShell &rPrev, bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
void RegisterOtherShell(OutlinerViewShell *pOtherShell)
ScInputWindow * GetInputWindow()
Definition: inputhdl.hxx:263
bool isCompatFlagSet(Compat flag)
void libreOfficeKitViewCallback(int nType, const char *pPayload) const override
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:653
SCTAB Tab() const
Definition: address.hxx:271
If only one row or portion thereof is selected, shrink row to used data columns and select further ro...
OUString GetAutoSumFormula(const ScRangeList &rRangeList, bool bSubTotal, const ScAddress &rAddr, const OpCode eCode)
Definition: viewfun2.cxx:809
void SetHideNotDelete(bool bOn)
void ClearFormEditData()
Definition: tabvwshc.cxx:732
ScViewData & GetViewData()
Definition: tabview.hxx:334
#define SCITEM_CONDFORMATDLGDATA
Definition: scitems.hxx:97
EditView & GetEditView() const
SfxItemPool & GetPool() const
void PutInOrder(T &nStart, T &nEnd)
Definition: address.hxx:954
create "untitled" (if necessary)
Definition: global.hxx:394
void SetAdvancedQuerySource(const ScRange *pSource)
Definition: uiitems.cxx:203
bool IsMarked() const
Definition: markdata.hxx:82
SC_DLLPUBLIC void GetRangeNameMap(std::map< OUString, ScRangeName * > &rRangeName)
Definition: documen3.cxx:145
int i
bool RowFiltered(SCROW nRow, SCTAB nTab, SCROW *pFirstRow=nullptr, SCROW *pLastRow=nullptr) const
Definition: document.cxx:4497
sal_Int16 SCCOL
Definition: types.hxx:22
#define SC_MOD()
Definition: scmod.hxx:250
static ScFunctionMgr * GetStarCalcFunctionMgr()
Definition: global.cxx:618
size_t size() const
Definition: rangelst.hxx:90
OUString maScope
Definition: tabvwsh.hxx:164
void IncRow(SCROW nDelta=1)
Definition: address.hxx:300
ScMarkType GetSimpleArea(SCCOL &rStartCol, SCROW &rStartRow, SCTAB &rStartTab, SCCOL &rEndCol, SCROW &rEndRow, SCTAB &rEndTab) const
Definition: viewdata.cxx:1170
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3062
const OutlinerView * GetTextEditOutlinerView() const
void DrawSelectionXOR(OutlinerViewShell *pOtherShell)
void Lock(bool bLock)
bool IsBlockEmpty(SCTAB nTab, SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bIgnoreNotes=false) const
Definition: document.cxx:5289
static SfxViewShell * GetFirst(bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
static void notifyAllViewsHeaderInvalidation(const SfxViewShell *pForViewShell, HeaderType eHeaderType, SCTAB nCurrentTabIndex)
Emits a LOK_CALLBACK_INVALIDATE_HEADER for all views whose current tab is equal to nCurrentTabIndex...
Definition: tabvwshc.cxx:501
ScRange & back()
Definition: rangelst.hxx:95
void GetArea(SCTAB &rTab, SCCOL &rCol1, SCROW &rRow1, SCCOL &rCol2, SCROW &rRow2) const
Definition: dbdata.cxx:300
SCCOL Col() const
Definition: address.hxx:267
ScAddress GetCurPos() const
Definition: viewdata.cxx:4007
void NotifyCursor(SfxViewShell *pViewShell) const override
See SfxViewShell::NotifyCursor().
Definition: tabvwshc.cxx:458
Stores global named database ranges.
Definition: dbdata.hxx:235
sal_Int32 SCROW
Definition: types.hxx:18
std::unique_ptr< ScFormEditData > mpFormEditData
Definition: tabvwsh.hxx:115
ScDrawView * GetScDrawView()
Definition: tabview.hxx:342
bool AutoSum(const ScRange &rRange, bool bSubTotal, bool bSetCursor, bool bContinue, const OpCode eCode)
Definition: viewfun2.cxx:589
bool UseSubTotal(ScRangeList *pRangeList)
Definition: tabvwshc.cxx:603
void InitFormEditData()
Definition: tabvwshc.cxx:727
std::shared_ptr< SfxModelessDialogController > CreateRefDialogController(SfxBindings *pB, SfxChildWindow *pCW, const SfxChildWinInfo *pInfo, weld::Window *pParent, sal_uInt16 nSlotId)
Definition: tabvwshc.cxx:111
Close
SfxDispatcher & GetDispatcher()
Definition: viewdata.cxx:3040
void AdjustMarkHdl(SfxViewShell *pOtherShell=nullptr)
Item2Range GetItemSurrogates(sal_uInt16 nWhich) const
void EnterAutoSum(const ScRangeList &rRangeList, bool bSubTotal, const ScAddress &rAddr, const OpCode eCode)
Definition: viewfun2.cxx:583
OUString maName
Definition: tabvwsh.hxx:163
const ScConsolidateParam * GetConsolidateDlgData() const
Definition: document.hxx:640
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:315
static bool isAnyEditViewInRange(const SfxViewShell *pForViewShell, bool bColumns, SCCOLROW nStart, SCCOLROW nEnd)
Definition: tabvwshc.cxx:534
void NotifyLOKClient()
Definition: inputwin.cxx:519
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
const ScInputHandler * GetInputHandler() const
Definition: tabvwsh.hxx:232
#define SCITEM_CONSOLIDATEDATA
Definition: scitems.hxx:93
sal_uInt16 nPos
sal_Int16 SCTAB
Definition: types.hxx:23
void SwitchBetweenRefDialogs(SfxModelessDialogController *pDialog)
Definition: tabvwshc.cxx:85
SCCOL GetCurX() const
Definition: viewdata.hxx:401
void afterCallbackRegistered() override
See SfxViewShell::afterCallbackRegistered().
Definition: tabvwshc.cxx:443