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  if (!(comphelper::LibreOfficeKit::isActive() && nSlotId == SID_OPENDLG_FUNCTION))
125  {
126  // the dialog has been opened in a different view
127  // -> lock the dispatcher for this view (modal mode)
128 
129  GetViewData().GetDispatcher().Lock( true ); // lock is reset when closing dialog
130  }
131  return nullptr;
132  }
133 
134  std::shared_ptr<SfxModelessDialogController> xResult;
135 
136  if(pCW)
137  pCW->SetHideNotDelete(true);
138 
139  ScDocument& rDoc = GetViewData().GetDocument();
140 
141  switch( nSlotId )
142  {
143  case SID_CORRELATION_DIALOG:
144  xResult = std::make_shared<ScCorrelationDialog>(pB, pCW, pParent, GetViewData());
145  break;
146  case SID_SAMPLING_DIALOG:
147  xResult = std::make_shared<ScSamplingDialog>(pB, pCW, pParent, GetViewData());
148  break;
149  case SID_DESCRIPTIVE_STATISTICS_DIALOG:
150  xResult = std::make_shared<ScDescriptiveStatisticsDialog>(pB, pCW, pParent, GetViewData());
151  break;
152  case SID_ANALYSIS_OF_VARIANCE_DIALOG:
153  xResult = std::make_shared<ScAnalysisOfVarianceDialog>(pB, pCW, pParent, GetViewData());
154  break;
155  case SID_COVARIANCE_DIALOG:
156  xResult = std::make_shared<ScCovarianceDialog>(pB, pCW, pParent, GetViewData());
157  break;
158  case SID_EXPONENTIAL_SMOOTHING_DIALOG:
159  xResult = std::make_shared<ScExponentialSmoothingDialog>(pB, pCW, pParent, GetViewData());
160  break;
161  case SID_MOVING_AVERAGE_DIALOG:
162  xResult = std::make_shared<ScMovingAverageDialog>(pB, pCW, pParent, GetViewData());
163  break;
164  case SID_REGRESSION_DIALOG:
165  xResult = std::make_shared<ScRegressionDialog>(pB, pCW, pParent, GetViewData());
166  break;
167  case SID_FTEST_DIALOG:
168  xResult = std::make_shared<ScFTestDialog>(pB, pCW, pParent, GetViewData());
169  break;
170  case SID_TTEST_DIALOG:
171  xResult = std::make_shared<ScTTestDialog>(pB, pCW, pParent, GetViewData());
172  break;
173  case SID_ZTEST_DIALOG:
174  xResult = std::make_shared<ScZTestDialog>(pB, pCW, pParent, GetViewData());
175  break;
176  case SID_CHI_SQUARE_TEST_DIALOG:
177  xResult = std::make_shared<ScChiSquareTestDialog>(pB, pCW, pParent, GetViewData());
178  break;
179  case SID_FOURIER_ANALYSIS_DIALOG:
180  xResult = std::make_shared<ScFourierAnalysisDialog>(pB, pCW, pParent, GetViewData());
181  break;
182  case WID_SIMPLE_REF:
183  {
184  // dialog checks, what is in the cell
185 
186  ScViewData& rViewData = GetViewData();
187  rViewData.SetRefTabNo( rViewData.GetTabNo() );
188  xResult = std::make_shared<ScSimpleRefDlg>(pB, pCW, pParent);
189  break;
190  }
191  case FID_DEFINE_NAME:
192  {
193  if (!mbInSwitch)
194  {
195  xResult = std::make_shared<ScNameDlg>(pB, pCW, pParent, GetViewData(),
196  ScAddress( GetViewData().GetCurX(),
197  GetViewData().GetCurY(),
198  GetViewData().GetTabNo() ) );
199  }
200  else
201  {
202  xResult = std::make_shared<ScNameDlg>( pB, pCW, pParent, GetViewData(),
203  ScAddress( GetViewData().GetCurX(),
204  GetViewData().GetCurY(),
205  GetViewData().GetTabNo() ), &m_RangeMap);
206  static_cast<ScNameDlg*>(xResult.get())->SetEntry(maName, maScope);
207  mbInSwitch = false;
208  }
209  break;
210  }
211  case FID_ADD_NAME:
212  {
213  if (!mbInSwitch)
214  {
215  std::map<OUString, ScRangeName*> aRangeMap;
216  rDoc.GetRangeNameMap(aRangeMap);
217  xResult = std::make_shared<ScNameDefDlg>(pB, pCW, pParent, GetViewData(), std::move(aRangeMap),
218  ScAddress(GetViewData().GetCurX(),
219  GetViewData().GetCurY(),
220  GetViewData().GetTabNo()), true);
221  }
222  else
223  {
224  std::map<OUString, ScRangeName*> aRangeMap;
225  for (auto const& itr : m_RangeMap)
226  {
227  aRangeMap.insert(std::pair<OUString, ScRangeName*>(itr.first, itr.second.get()));
228  }
229  xResult = std::make_shared<ScNameDefDlg>(pB, pCW, pParent, GetViewData(), std::move(aRangeMap),
230  ScAddress(GetViewData().GetCurX(),
231  GetViewData().GetCurY(),
232  GetViewData().GetTabNo()), false);
233  }
234  break;
235  }
236  case SID_RANDOM_NUMBER_GENERATOR_DIALOG:
237  xResult = std::make_shared<ScRandomNumberGeneratorDialog>(pB, pCW, pParent, GetViewData());
238  break;
239  case SID_DEFINE_DBNAME:
240  {
241  // when called for an existing range, then mark
242  GetDBData( true, SC_DB_OLD );
243  const ScMarkData& rMark = GetViewData().GetMarkData();
244  if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
245  MarkDataArea( false );
246 
247  xResult = std::make_shared<ScDbNameDlg>(pB, pCW, pParent, GetViewData());
248  break;
249  }
250  case SID_OPENDLG_EDIT_PRINTAREA:
251  xResult = std::make_shared<ScPrintAreasDlg>(pB, pCW, pParent);
252  break;
253  case SID_DEFINE_COLROWNAMERANGES:
254  xResult = std::make_shared<ScColRowNameRangesDlg>(pB, pCW, pParent, GetViewData());
255  break;
256  case SID_OPENDLG_SOLVE:
257  {
258  ScViewData& rViewData = GetViewData();
259  ScAddress aCurPos( rViewData.GetCurX(),
260  rViewData.GetCurY(),
261  rViewData.GetTabNo());
262  xResult = std::make_shared<ScSolverDlg>(pB, pCW, pParent, &rViewData.GetDocument(), aCurPos);
263  break;
264  }
265  case SID_OPENDLG_TABOP:
266  {
267  ScViewData& rViewData = GetViewData();
268  ScRefAddress aCurPos ( rViewData.GetCurX(),
269  rViewData.GetCurY(),
270  rViewData.GetTabNo());
271 
272  xResult = std::make_shared<ScTabOpDlg>(pB, pCW, pParent, &rViewData.GetDocument(), aCurPos);
273  break;
274  }
275  case SID_OPENDLG_CONSOLIDATE:
276  {
278  SCITEM_CONSOLIDATEDATA> 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 
301  aArgSet.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA,
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;
316 
318  pDBData->ExtendDataArea(rDoc);
319  pDBData->GetQueryParam( aQueryParam );
320 
321  ScRange aArea;
322  pDBData->GetArea(aArea);
323  MarkRange(aArea, false);
324 
325  aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA,
326  &GetViewData(),
327  &aQueryParam ) );
328 
329  // mark current sheet (due to RefInput in dialog)
330  GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
331 
332  xResult = std::make_shared<ScFilterDlg>(pB, pCW, pParent, aArgSet);
333  break;
334  }
335  case SID_SPECIAL_FILTER:
336  {
337  ScQueryParam aQueryParam;
339  SCITEM_QUERYDATA> aArgSet( GetPool() );
340 
342  pDBData->ExtendDataArea(rDoc);
343  pDBData->GetQueryParam( aQueryParam );
344 
345  ScRange aArea;
346  pDBData->GetArea(aArea);
347  MarkRange(aArea, false);
348 
349  ScQueryItem aItem( SCITEM_QUERYDATA, &GetViewData(), &aQueryParam );
350  ScRange aAdvSource;
351  if (pDBData->GetAdvancedQuerySource(aAdvSource))
352  aItem.SetAdvancedQuerySource( &aAdvSource );
353 
354  aArgSet.Put( aItem );
355 
356  // mark current sheet (due to RefInput in dialog)
357  GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
358 
359  xResult = std::make_shared<ScSpecialFilterDlg>(pB, pCW, pParent, aArgSet);
360  break;
361  }
362  case SID_OPENDLG_OPTSOLVER:
363  {
364  ScViewData& rViewData = GetViewData();
365  ScAddress aCurPos( rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo());
366  xResult = std::make_shared<ScOptSolverDlg>(pB, pCW, pParent, rViewData.GetDocShell(), aCurPos);
367  break;
368  }
369  case FID_CHG_SHOW:
370  {
371  // dialog checks, what is in the cell
372  xResult = std::make_shared<ScHighlightChgDlg>(pB, pCW, pParent, GetViewData());
373  break;
374  }
375  case SID_MANAGE_XML_SOURCE:
376  {
377  xResult = std::make_shared<ScXMLSourceDlg>(pB, pCW, pParent, &rDoc);
378  break;
379  }
380  case SID_OPENDLG_PIVOTTABLE:
381  {
382  // all settings must be in pDialogDPObject
383 
384  if( pDialogDPObject )
385  {
386  // Check for an existing datapilot output.
387  ScViewData& rViewData = GetViewData();
388  rViewData.SetRefTabNo( rViewData.GetTabNo() );
389  ScDPObject* pObj = rDoc.GetDPAtCursor(rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo());
390  xResult = std::make_shared<ScPivotLayoutDialog>(pB, pCW, pParent, &rViewData, pDialogDPObject.get(), pObj == nullptr);
391  }
392 
393  break;
394  }
395  case SID_OPENDLG_FUNCTION:
396  {
397  if (!isLOKMobilePhone())
398  {
399  // dialog checks, what is in the cell
400  xResult = o3tl::make_shared<ScFormulaDlg>(pB, pCW, pParent, GetViewData(), ScGlobal::GetStarCalcFunctionMgr());
401  }
402  break;
403  }
404  case WID_CONDFRMT_REF:
405  {
406  const ScCondFormatDlgItem* pDlgItem = nullptr;
407  // Get the pool item stored by Conditional Format Manager Dialog.
409  if (itemsRange.begin() != itemsRange.end())
410  {
411  const SfxPoolItem* pItem = *itemsRange.begin();
412  pDlgItem = static_cast<const ScCondFormatDlgItem*>(pItem);
413  }
414 
415  if (pDlgItem)
416  {
417  ScViewData& rViewData = GetViewData();
418  rViewData.SetRefTabNo( rViewData.GetTabNo() );
419 
420  xResult = std::make_shared<ScCondFormatDlg>(pB, pCW, pParent, &rViewData, pDlgItem);
421 
422  // Remove the pool item stored by Conditional Format Manager Dialog.
423  GetPool().Remove(*pDlgItem);
424  }
425 
426  break;
427  }
428  }
429 
430  if (xResult)
431  xResult->Initialize( pInfo );
432  return xResult;
433 }
434 
436 {
437  return GetViewData().GetTabNo();
438 }
439 
441 {
442  UpdateInputHandler(true, false);
443 
444  ScInputHandler* pHdl = mpInputHandler ? mpInputHandler.get() : SC_MOD()->GetInputHdl();
445  if (pHdl)
446  {
447  ScInputWindow* pInputWindow = pHdl->GetInputWindow();
448  if (pInputWindow)
449  {
450  pInputWindow->NotifyLOKClient();
451  }
452  }
453 }
454 
456 {
457  ScDrawView* pDrView = const_cast<ScTabViewShell*>(this)->GetScDrawView();
458  if (pDrView)
459  {
460  if (pDrView->GetTextEditObject())
461  {
462  // Blinking cursor.
463  EditView& rEditView = pDrView->GetTextEditOutlinerView()->GetEditView();
464  rEditView.RegisterOtherShell(pOtherShell);
465  rEditView.ShowCursor();
466  rEditView.RegisterOtherShell(nullptr);
467  // Text selection, if any.
468  rEditView.DrawSelectionXOR(pOtherShell);
469  }
470  else
471  {
472  // Graphic selection.
473  pDrView->AdjustMarkHdl(pOtherShell);
474  }
475  }
476 
477  const ScGridWindow* pWin = GetViewData().GetActiveWin();
478  if (pWin)
479  pWin->updateKitCellCursor(pOtherShell);
480 }
481 
482 css::uno::Reference<css::datatransfer::XTransferable2> ScTabViewShell::GetClipData(vcl::Window* pWin)
483 {
484  SfxViewFrame* pViewFrame = nullptr;
485  css::uno::Reference<css::datatransfer::XTransferable2> xTransferable;
486  css::uno::Reference<css::datatransfer::clipboard::XClipboard> xClipboard;
487 
488  if (pWin)
489  xClipboard = pWin->GetClipboard();
490  else if ((pViewFrame = SfxViewFrame::GetFirst(nullptr, false)))
491  xClipboard = pViewFrame->GetWindow().GetClipboard();
492 
493  xTransferable.set(xClipboard.is() ? xClipboard->getContents() : nullptr, css::uno::UNO_QUERY);
494 
495  return xTransferable;
496 }
497 
498 void ScTabViewShell::notifyAllViewsHeaderInvalidation(const SfxViewShell* pForViewShell, HeaderType eHeaderType, SCTAB nCurrentTabIndex)
499 {
501  return;
502 
503  OString aPayload;
504  switch (eHeaderType)
505  {
506  case COLUMN_HEADER:
507  aPayload = "column";
508  break;
509  case ROW_HEADER:
510  aPayload = "row";
511  break;
512  case BOTH_HEADERS:
513  default:
514  aPayload = "all";
515  break;
516  }
517 
518  SfxViewShell* pViewShell = SfxViewShell::GetFirst();
519  while (pViewShell)
520  {
521  ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
522  if (pTabViewShell && pViewShell->GetDocId() == pForViewShell->GetDocId()
523  && (nCurrentTabIndex == -1 || pTabViewShell->getPart() == nCurrentTabIndex))
524  {
525  pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_HEADER, aPayload.getStr());
526  }
527  pViewShell = SfxViewShell::GetNext(*pViewShell);
528  }
529 }
530 
531 bool ScTabViewShell::isAnyEditViewInRange(const SfxViewShell* pForViewShell, bool bColumns, SCCOLROW nStart, SCCOLROW nEnd)
532 {
534  {
535  SfxViewShell* pViewShell = SfxViewShell::GetFirst();
536  while (pViewShell)
537  {
538  ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
539  if (pTabViewShell && pTabViewShell->GetDocId() == pForViewShell->GetDocId())
540  {
541  ScInputHandler* pInputHandler = pTabViewShell->GetInputHandler();
542  if (pInputHandler && pInputHandler->GetActiveView())
543  {
544  const ScViewData& rViewData = pTabViewShell->GetViewData();
545  SCCOLROW nPos = bColumns ? rViewData.GetCurX() : rViewData.GetCurY();
546  if (nStart <= nPos && nPos <= nEnd)
547  return true;
548  }
549  }
550  pViewShell = SfxViewShell::GetNext(*pViewShell);
551  }
552  }
553  return false;
554 }
555 
556 void ScTabViewShell::notifyAllViewsSheetGeomInvalidation(const SfxViewShell* pForViewShell, bool bColumns,
557  bool bRows, bool bSizes, bool bHidden, bool bFiltered,
558  bool bGroups, SCTAB nCurrentTabIndex)
559 {
562  comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
563  return;
564 
565  if (!bColumns && !bRows)
566  return;
567 
568  bool bAllTypes = bSizes && bHidden && bFiltered && bGroups;
569  bool bAllDims = bColumns && bRows;
570  OString aPayload = bAllDims ? "all" : bColumns ? "columns" : "rows";
571 
572  if (!bAllTypes)
573  {
574  if (bSizes)
575  aPayload += " sizes";
576 
577  if (bHidden)
578  aPayload += " hidden";
579 
580  if (bFiltered)
581  aPayload += " filtered";
582 
583  if (bGroups)
584  aPayload += " groups";
585  }
586 
587  SfxViewShell* pViewShell = SfxViewShell::GetFirst();
588  while (pViewShell)
589  {
590  ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
591  if (pTabViewShell && pViewShell->GetDocId() == pForViewShell->GetDocId() &&
592  (nCurrentTabIndex == -1 || pTabViewShell->getPart() == nCurrentTabIndex))
593  {
594  pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_SHEET_GEOMETRY, aPayload.getStr());
595  }
596  pViewShell = SfxViewShell::GetNext(*pViewShell);
597  }
598 }
599 
601 {
602  bool bSubTotal = false;
603  ScDocument& rDoc = GetViewData().GetDocument();
604  size_t nRangeCount (pRangeList->size());
605  size_t nRangeIndex (0);
606  while (!bSubTotal && nRangeIndex < nRangeCount)
607  {
608  const ScRange& rRange = (*pRangeList)[nRangeIndex];
609  SCTAB nTabEnd(rRange.aEnd.Tab());
610  SCTAB nTab(rRange.aStart.Tab());
611  while (!bSubTotal && nTab <= nTabEnd)
612  {
613  SCROW nRowEnd(rRange.aEnd.Row());
614  SCROW nRow(rRange.aStart.Row());
615  while (!bSubTotal && nRow <= nRowEnd)
616  {
617  if (rDoc.RowFiltered(nRow, nTab))
618  bSubTotal = true;
619  else
620  ++nRow;
621  }
622  ++nTab;
623  }
624  ++nRangeIndex;
625  }
626 
627  if (!bSubTotal)
628  {
629  const ScDBCollection::NamedDBs& rDBs = rDoc.GetDBCollection()->getNamedDBs();
630  for (const auto& rxDB : rDBs)
631  {
632  const ScDBData& rDB = *rxDB;
633  if (!rDB.HasAutoFilter())
634  continue;
635 
636  nRangeIndex = 0;
637  while (!bSubTotal && nRangeIndex < nRangeCount)
638  {
639  const ScRange & rRange = (*pRangeList)[nRangeIndex];
640  ScRange aDBArea;
641  rDB.GetArea(aDBArea);
642  if (aDBArea.Intersects(rRange))
643  bSubTotal = true;
644  ++nRangeIndex;
645  }
646 
647  if (bSubTotal)
648  break;
649  }
650  }
651  return bSubTotal;
652 }
653 
654 OUString ScTabViewShell::DoAutoSum(bool& rRangeFinder, bool& rSubTotal, const OpCode eCode)
655 {
656  OUString aFormula;
657  const ScMarkData& rMark = GetViewData().GetMarkData();
658  if ( rMark.IsMarked() || rMark.IsMultiMarked() )
659  {
660  ScRangeList aMarkRangeList;
661  rRangeFinder = rSubTotal = false;
662  rMark.FillRangeListWithMarks( &aMarkRangeList, false );
663  ScDocument& rDoc = GetViewData().GetDocument();
664 
665  // check if one of the marked ranges is empty
666  bool bEmpty = false;
667  const size_t nCount = aMarkRangeList.size();
668  for ( size_t i = 0; i < nCount; ++i )
669  {
670  const ScRange & rRange( aMarkRangeList[i] );
671  if ( rDoc.IsBlockEmpty( rRange.aStart.Tab(),
672  rRange.aStart.Col(), rRange.aStart.Row(),
673  rRange.aEnd.Col(), rRange.aEnd.Row() ) )
674  {
675  bEmpty = true;
676  break;
677  }
678  }
679 
680  if ( bEmpty )
681  {
682  ScRangeList aRangeList;
683  const bool bDataFound = GetAutoSumArea( aRangeList );
684  if ( bDataFound )
685  {
686  ScAddress aAddr = aRangeList.back().aEnd;
687  aAddr.IncRow();
688  const bool bSubTotal( UseSubTotal( &aRangeList ) );
689  EnterAutoSum( aRangeList, bSubTotal, aAddr, eCode );
690  }
691  }
692  else
693  {
694  const bool bSubTotal( UseSubTotal( &aMarkRangeList ) );
695  for ( size_t i = 0; i < nCount; ++i )
696  {
697  const ScRange & rRange = aMarkRangeList[i];
698  const bool bSetCursor = ( i == nCount - 1 );
699  const bool bContinue = ( i != 0 );
700  if ( !AutoSum( rRange, bSubTotal, bSetCursor, bContinue, eCode ) )
701  {
702  MarkRange( rRange, false );
703  SetCursor( rRange.aEnd.Col(), rRange.aEnd.Row() );
704  const ScRangeList aRangeList;
705  ScAddress aAddr = rRange.aEnd;
706  aAddr.IncRow();
707  aFormula = GetAutoSumFormula( aRangeList, bSubTotal, aAddr , eCode);
708  break;
709  }
710  }
711  }
712  }
713  else // Only insert into input row
714  {
715  ScRangeList aRangeList;
716  rRangeFinder = GetAutoSumArea( aRangeList );
717  rSubTotal = UseSubTotal( &aRangeList );
718  ScAddress aAddr = GetViewData().GetCurPos();
719  aFormula = GetAutoSumFormula( aRangeList, rSubTotal, aAddr , eCode);
720  }
721  return aFormula;
722 }
723 
725 {
726  mpFormEditData.reset(new ScFormEditData);
727 }
728 
730 {
731  mpFormEditData.reset();
732 }
733 
734 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3108
SfxViewFrame * GetViewFrame() const
SC_DLLPUBLIC ScDPObject * GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: documen3.cxx:377
void MarkDataArea(bool bIncludeCursor=true)
Definition: tabview3.cxx:1656
bool HasAutoFilter() const
Definition: dbdata.hxx:204
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:814
ScDBData * GetDBData(bool bMarkArea=true, ScGetDBMode eMode=SC_DB_MAKE, ScGetDBSelection eSel=ScGetDBSelection::Keep)
Definition: dbfunc.cxx:81
ScAddress aStart
Definition: address.hxx:499
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:353
std::unique_ptr< ScInputHandler, o3tl::default_delete< ScInputHandler > > mpInputHandler
Definition: tabvwsh.hxx:115
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
SfxChildWindow * GetChildWindow(sal_uInt16)
bool isLOKMobilePhone() const
SCROW Row() const
Definition: address.hxx:261
HeaderType
Definition: tabview.hxx:57
bool GetAutoSumArea(ScRangeList &rRangeList)
Definition: viewfun2.cxx:478
css::uno::Reference< css::datatransfer::clipboard::XClipboard > GetClipboard()
void MarkRange(const ScRange &rRange, bool bSetCursor=true, bool bContinue=false)
Definition: tabview3.cxx:1687
std::unique_ptr< ScDPObject > pDialogDPObject
Definition: tabvwsh.hxx:125
bool Intersects(const ScRange &rRange) const
Definition: address.cxx:1558
int getPart() const override
See SfxViewShell::getPart().
Definition: tabvwshc.cxx:435
std::map< OUString, std::unique_ptr< ScRangeName > > m_RangeMap
Definition: tabvwsh.hxx:160
SdrTextObj * GetTextEditObject() const
SCROW GetCurY() const
Definition: viewdata.hxx:401
void ShowCursor(bool bGotoCursor=true, bool bForceVisCursor=true, bool bActivate=false)
sal_uInt16 nCurRefDlgId
Definition: tabvwsh.hxx:155
don't create
Definition: global.hxx:396
ViewShellDocId GetDocId() const override
void FillRangeListWithMarks(ScRangeList *pList, bool bClear, SCTAB nForTab=-1) const
Create a range list of marks.
Definition: markdata.cxx:386
sal_Int16 nId
SCTAB GetTabNo() const
Definition: viewdata.hxx:394
ScAddress aEnd
Definition: address.hxx:500
ScDocument & GetDocument() const
Definition: viewdata.hxx:379
static css::uno::Reference< css::datatransfer::XTransferable2 > GetClipData(vcl::Window *pWin)
Definition: tabvwshc.cxx:482
void Remove(const SfxPoolItem &)
SC_DLLPUBLIC void SetCursor(SCCOL nPosX, SCROW nPosY, bool bNew=false)
Definition: tabview3.cxx:363
#define SCITEM_QUERYDATA
Definition: scitems.hxx:90
OUString DoAutoSum(bool &rRangeFinder, bool &rSubTotal, const OpCode eCode)
Definition: tabvwshc.cxx:654
void ExtendDataArea(const ScDocument &rDoc)
Definition: dbdata.cxx:650
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:556
void updateKitCellCursor(const SfxViewShell *pOtherShell) const
Definition: gridwin.cxx:5785
EditView * GetActiveView()
Definition: inputhdl.cxx:2290
vcl::Window & GetWindow() const
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
bool IsMultiMarked() const
Definition: markdata.hxx:82
OpCode
void SetCurRefDlgId(sal_uInt16 nNew)
Definition: tabvwshc.cxx:77
void SetRefTabNo(SCTAB nNewTab)
Definition: viewdata.hxx:392
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:265
bool isCompatFlagSet(Compat flag)
virtual 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:270
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:810
void SetHideNotDelete(bool bOn)
void ClearFormEditData()
Definition: tabvwshc.cxx:729
ScViewData & GetViewData()
Definition: tabview.hxx:333
#define SCITEM_CONDFORMATDLGDATA
Definition: scitems.hxx:96
EditView & GetEditView() const
SfxItemPool & GetPool() const
void PutInOrder(T &nStart, T &nEnd)
Definition: address.hxx:953
create "untitled" (if necessary)
Definition: global.hxx:393
void SetAdvancedQuerySource(const ScRange *pSource)
Definition: uiitems.cxx:203
bool IsMarked() const
Definition: markdata.hxx:81
SC_DLLPUBLIC void GetRangeNameMap(std::map< OUString, ScRangeName * > &rRangeName)
Definition: documen3.cxx:146
int i
SC_DLLPUBLIC bool RowFiltered(SCROW nRow, SCTAB nTab, SCROW *pFirstRow=nullptr, SCROW *pLastRow=nullptr) const
Definition: document.cxx:4530
sal_Int16 SCCOL
Definition: types.hxx:21
#define SC_MOD()
Definition: scmod.hxx:250
static ScFunctionMgr * GetStarCalcFunctionMgr()
Definition: global.cxx:621
size_t size() const
Definition: rangelst.hxx:89
OUString maScope
Definition: tabvwsh.hxx:163
void IncRow(SCROW nDelta=1)
Definition: address.hxx:299
ScMarkType GetSimpleArea(SCCOL &rStartCol, SCROW &rStartRow, SCTAB &rStartTab, SCCOL &rEndCol, SCROW &rEndRow, SCTAB &rEndTab) const
Definition: viewdata.cxx:1179
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3124
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:5322
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:498
ScRange & back()
Definition: rangelst.hxx:94
void GetArea(SCTAB &rTab, SCCOL &rCol1, SCROW &rRow1, SCCOL &rCol2, SCROW &rRow2) const
Definition: dbdata.cxx:300
SCCOL Col() const
Definition: address.hxx:266
ScAddress GetCurPos() const
Definition: viewdata.cxx:4076
void NotifyCursor(SfxViewShell *pViewShell) const override
See SfxViewShell::NotifyCursor().
Definition: tabvwshc.cxx:455
Stores global named database ranges.
Definition: dbdata.hxx:234
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_Int32 SCROW
Definition: types.hxx:17
std::unique_ptr< ScFormEditData > mpFormEditData
Definition: tabvwsh.hxx:114
ScDrawView * GetScDrawView()
Definition: tabview.hxx:341
bool AutoSum(const ScRange &rRange, bool bSubTotal, bool bSetCursor, bool bContinue, const OpCode eCode)
Definition: viewfun2.cxx:590
bool UseSubTotal(ScRangeList *pRangeList)
Definition: tabvwshc.cxx:600
void InitFormEditData()
Definition: tabvwshc.cxx:724
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:3102
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:584
OUString maName
Definition: tabvwsh.hxx:162
const ScConsolidateParam * GetConsolidateDlgData() const
Definition: document.hxx:641
SC_DLLPUBLIC void GetQueryParam(ScQueryParam &rQueryParam) const
Definition: dbdata.cxx:424
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:315
static bool isAnyEditViewInRange(const SfxViewShell *pForViewShell, bool bColumns, SCCOLROW nStart, SCCOLROW nEnd)
Definition: tabvwshc.cxx:531
void NotifyLOKClient()
Definition: inputwin.cxx:536
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
SC_DLLPUBLIC bool GetAdvancedQuerySource(ScRange &rSource) const
Definition: dbdata.cxx:457
const ScInputHandler * GetInputHandler() const
Definition: tabvwsh.hxx:231
#define SCITEM_CONSOLIDATEDATA
Definition: scitems.hxx:92
sal_uInt16 nPos
sal_Int16 SCTAB
Definition: types.hxx:22
void SwitchBetweenRefDialogs(SfxModelessDialogController *pDialog)
Definition: tabvwshc.cxx:85
SCCOL GetCurX() const
Definition: viewdata.hxx:400
void afterCallbackRegistered() override
See SfxViewShell::afterCallbackRegistered().
Definition: tabvwshc.cxx:440