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(), 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(), 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  {
277  SfxItemSet aArgSet( GetPool(),
280 
281  const ScConsolidateParam* pDlgData =
282  rDoc.GetConsolidateDlgData();
283 
284  if ( !pDlgData )
285  {
286  ScConsolidateParam aConsParam;
287  SCCOL nStartCol, nEndCol;
288  SCROW nStartRow, nEndRow;
289  SCTAB nStartTab, nEndTab;
290 
291  GetViewData().GetSimpleArea( nStartCol, nStartRow, nStartTab,
292  nEndCol, nEndRow, nEndTab );
293 
294  PutInOrder( nStartCol, nEndCol );
295  PutInOrder( nStartRow, nEndRow );
296  PutInOrder( nStartTab, nEndTab );
297 
298  aConsParam.nCol = nStartCol;
299  aConsParam.nRow = nStartRow;
300  aConsParam.nTab = nStartTab;
301 
303  &aConsParam ) );
304  }
305  else
306  {
307  aArgSet.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA, pDlgData ) );
308  }
309  xResult = std::make_shared<ScConsolidateDlg>(pB, pCW, pParent, aArgSet);
310  break;
311  }
312  case SID_FILTER:
313  {
314 
315  ScQueryParam aQueryParam;
316  SfxItemSet aArgSet( GetPool(),
318  SCITEM_QUERYDATA>{} );
319 
321  pDBData->ExtendDataArea(rDoc);
322  pDBData->GetQueryParam( aQueryParam );
323 
324  ScRange aArea;
325  pDBData->GetArea(aArea);
326  MarkRange(aArea, false);
327 
328  aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA,
329  &GetViewData(),
330  &aQueryParam ) );
331 
332  // mark current sheet (due to RefInput in dialog)
333  GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
334 
335  xResult = std::make_shared<ScFilterDlg>(pB, pCW, pParent, aArgSet);
336  break;
337  }
338  case SID_SPECIAL_FILTER:
339  {
340  ScQueryParam aQueryParam;
341  SfxItemSet aArgSet( GetPool(),
343  SCITEM_QUERYDATA>{} );
344 
346  pDBData->ExtendDataArea(rDoc);
347  pDBData->GetQueryParam( aQueryParam );
348 
349  ScRange aArea;
350  pDBData->GetArea(aArea);
351  MarkRange(aArea, false);
352 
353  ScQueryItem aItem( SCITEM_QUERYDATA, &GetViewData(), &aQueryParam );
354  ScRange aAdvSource;
355  if (pDBData->GetAdvancedQuerySource(aAdvSource))
356  aItem.SetAdvancedQuerySource( &aAdvSource );
357 
358  aArgSet.Put( aItem );
359 
360  // mark current sheet (due to RefInput in dialog)
361  GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
362 
363  xResult = std::make_shared<ScSpecialFilterDlg>(pB, pCW, pParent, aArgSet);
364  break;
365  }
366  case SID_OPENDLG_OPTSOLVER:
367  {
368  ScViewData& rViewData = GetViewData();
369  ScAddress aCurPos( rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo());
370  xResult = std::make_shared<ScOptSolverDlg>(pB, pCW, pParent, rViewData.GetDocShell(), aCurPos);
371  break;
372  }
373  case FID_CHG_SHOW:
374  {
375  // dialog checks, what is in the cell
376  xResult = std::make_shared<ScHighlightChgDlg>(pB, pCW, pParent, GetViewData());
377  break;
378  }
379  case SID_MANAGE_XML_SOURCE:
380  {
381  xResult = std::make_shared<ScXMLSourceDlg>(pB, pCW, pParent, &rDoc);
382  break;
383  }
384  case SID_OPENDLG_PIVOTTABLE:
385  {
386  // all settings must be in pDialogDPObject
387 
388  if( pDialogDPObject )
389  {
390  // Check for an existing datapilot output.
391  ScViewData& rViewData = GetViewData();
392  rViewData.SetRefTabNo( rViewData.GetTabNo() );
393  ScDPObject* pObj = rDoc.GetDPAtCursor(rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo());
394  xResult = std::make_shared<ScPivotLayoutDialog>(pB, pCW, pParent, &rViewData, pDialogDPObject.get(), pObj == nullptr);
395  }
396 
397  break;
398  }
399  case SID_OPENDLG_FUNCTION:
400  {
401  if (!isLOKMobilePhone())
402  {
403  // dialog checks, what is in the cell
404  xResult = o3tl::make_shared<ScFormulaDlg>(pB, pCW, pParent, GetViewData(), ScGlobal::GetStarCalcFunctionMgr());
405  }
406  break;
407  }
408  case WID_CONDFRMT_REF:
409  {
410  const ScCondFormatDlgItem* pDlgItem = nullptr;
411  // Get the pool item stored by Conditional Format Manager Dialog.
413  if (itemsRange.begin() != itemsRange.end())
414  {
415  const SfxPoolItem* pItem = *itemsRange.begin();
416  pDlgItem = static_cast<const ScCondFormatDlgItem*>(pItem);
417  }
418 
419  if (pDlgItem)
420  {
421  ScViewData& rViewData = GetViewData();
422  rViewData.SetRefTabNo( rViewData.GetTabNo() );
423 
424  xResult = std::make_shared<ScCondFormatDlg>(pB, pCW, pParent, &rViewData, pDlgItem);
425 
426  // Remove the pool item stored by Conditional Format Manager Dialog.
427  GetPool().Remove(*pDlgItem);
428  }
429 
430  break;
431  }
432  }
433 
434  if (xResult)
435  xResult->Initialize( pInfo );
436  return xResult;
437 }
438 
440 {
441  return GetViewData().GetTabNo();
442 }
443 
445 {
446  UpdateInputHandler(true, false);
447 
448  ScInputHandler* pHdl = mpInputHandler ? mpInputHandler.get() : SC_MOD()->GetInputHdl();
449  if (pHdl)
450  {
451  ScInputWindow* pInputWindow = pHdl->GetInputWindow();
452  if (pInputWindow)
453  {
454  pInputWindow->NotifyLOKClient();
455  }
456  }
457 }
458 
460 {
461  ScDrawView* pDrView = const_cast<ScTabViewShell*>(this)->GetScDrawView();
462  if (pDrView)
463  {
464  if (pDrView->GetTextEditObject())
465  {
466  // Blinking cursor.
467  EditView& rEditView = pDrView->GetTextEditOutlinerView()->GetEditView();
468  rEditView.RegisterOtherShell(pOtherShell);
469  rEditView.ShowCursor();
470  rEditView.RegisterOtherShell(nullptr);
471  // Text selection, if any.
472  rEditView.DrawSelectionXOR(pOtherShell);
473  }
474  else
475  {
476  // Graphic selection.
477  pDrView->AdjustMarkHdl(pOtherShell);
478  }
479  }
480 
481  const ScGridWindow* pWin = GetViewData().GetActiveWin();
482  if (pWin)
483  pWin->updateKitCellCursor(pOtherShell);
484 }
485 
486 css::uno::Reference<css::datatransfer::XTransferable2> ScTabViewShell::GetClipData(vcl::Window* pWin)
487 {
488  SfxViewFrame* pViewFrame = nullptr;
489  css::uno::Reference<css::datatransfer::XTransferable2> xTransferable;
490  css::uno::Reference<css::datatransfer::clipboard::XClipboard> xClipboard;
491 
492  if (pWin)
493  xClipboard = pWin->GetClipboard();
494  else if ((pViewFrame = SfxViewFrame::GetFirst(nullptr, false)))
495  xClipboard = pViewFrame->GetWindow().GetClipboard();
496 
497  xTransferable.set(xClipboard.is() ? xClipboard->getContents() : nullptr, css::uno::UNO_QUERY);
498 
499  return xTransferable;
500 }
501 
502 void ScTabViewShell::notifyAllViewsHeaderInvalidation(const SfxViewShell* pForViewShell, HeaderType eHeaderType, SCTAB nCurrentTabIndex)
503 {
505  return;
506 
507  OString aPayload;
508  switch (eHeaderType)
509  {
510  case COLUMN_HEADER:
511  aPayload = "column";
512  break;
513  case ROW_HEADER:
514  aPayload = "row";
515  break;
516  case BOTH_HEADERS:
517  default:
518  aPayload = "all";
519  break;
520  }
521 
522  SfxViewShell* pViewShell = SfxViewShell::GetFirst();
523  while (pViewShell)
524  {
525  ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
526  if (pTabViewShell && pViewShell->GetDocId() == pForViewShell->GetDocId()
527  && (nCurrentTabIndex == -1 || pTabViewShell->getPart() == nCurrentTabIndex))
528  {
529  pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_HEADER, aPayload.getStr());
530  }
531  pViewShell = SfxViewShell::GetNext(*pViewShell);
532  }
533 }
534 
535 bool ScTabViewShell::isAnyEditViewInRange(const SfxViewShell* pForViewShell, bool bColumns, SCCOLROW nStart, SCCOLROW nEnd)
536 {
538  {
539  SfxViewShell* pViewShell = SfxViewShell::GetFirst();
540  while (pViewShell)
541  {
542  ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
543  if (pTabViewShell && pTabViewShell->GetDocId() == pForViewShell->GetDocId())
544  {
545  ScInputHandler* pInputHandler = pTabViewShell->GetInputHandler();
546  if (pInputHandler && pInputHandler->GetActiveView())
547  {
548  const ScViewData& rViewData = pTabViewShell->GetViewData();
549  SCCOLROW nPos = bColumns ? rViewData.GetCurX() : rViewData.GetCurY();
550  if (nStart <= nPos && nPos <= nEnd)
551  return true;
552  }
553  }
554  pViewShell = SfxViewShell::GetNext(*pViewShell);
555  }
556  }
557  return false;
558 }
559 
560 void ScTabViewShell::notifyAllViewsSheetGeomInvalidation(const SfxViewShell* pForViewShell, bool bColumns,
561  bool bRows, bool bSizes, bool bHidden, bool bFiltered,
562  bool bGroups, SCTAB nCurrentTabIndex)
563 {
566  comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
567  return;
568 
569  if (!bColumns && !bRows)
570  return;
571 
572  bool bAllTypes = bSizes && bHidden && bFiltered && bGroups;
573  bool bAllDims = bColumns && bRows;
574  OString aPayload = bAllDims ? "all" : bColumns ? "columns" : "rows";
575 
576  if (!bAllTypes)
577  {
578  if (bSizes)
579  aPayload += " sizes";
580 
581  if (bHidden)
582  aPayload += " hidden";
583 
584  if (bFiltered)
585  aPayload += " filtered";
586 
587  if (bGroups)
588  aPayload += " groups";
589  }
590 
591  SfxViewShell* pViewShell = SfxViewShell::GetFirst();
592  while (pViewShell)
593  {
594  ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
595  if (pTabViewShell && pViewShell->GetDocId() == pForViewShell->GetDocId() &&
596  (nCurrentTabIndex == -1 || pTabViewShell->getPart() == nCurrentTabIndex))
597  {
598  pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_SHEET_GEOMETRY, aPayload.getStr());
599  }
600  pViewShell = SfxViewShell::GetNext(*pViewShell);
601  }
602 }
603 
605 {
606  bool bSubTotal = false;
607  ScDocument& rDoc = GetViewData().GetDocument();
608  size_t nRangeCount (pRangeList->size());
609  size_t nRangeIndex (0);
610  while (!bSubTotal && nRangeIndex < nRangeCount)
611  {
612  const ScRange& rRange = (*pRangeList)[nRangeIndex];
613  SCTAB nTabEnd(rRange.aEnd.Tab());
614  SCTAB nTab(rRange.aStart.Tab());
615  while (!bSubTotal && nTab <= nTabEnd)
616  {
617  SCROW nRowEnd(rRange.aEnd.Row());
618  SCROW nRow(rRange.aStart.Row());
619  while (!bSubTotal && nRow <= nRowEnd)
620  {
621  if (rDoc.RowFiltered(nRow, nTab))
622  bSubTotal = true;
623  else
624  ++nRow;
625  }
626  ++nTab;
627  }
628  ++nRangeIndex;
629  }
630 
631  if (!bSubTotal)
632  {
633  const ScDBCollection::NamedDBs& rDBs = rDoc.GetDBCollection()->getNamedDBs();
634  for (const auto& rxDB : rDBs)
635  {
636  const ScDBData& rDB = *rxDB;
637  if (!rDB.HasAutoFilter())
638  continue;
639 
640  nRangeIndex = 0;
641  while (!bSubTotal && nRangeIndex < nRangeCount)
642  {
643  const ScRange & rRange = (*pRangeList)[nRangeIndex];
644  ScRange aDBArea;
645  rDB.GetArea(aDBArea);
646  if (aDBArea.Intersects(rRange))
647  bSubTotal = true;
648  ++nRangeIndex;
649  }
650 
651  if (bSubTotal)
652  break;
653  }
654  }
655  return bSubTotal;
656 }
657 
658 OUString ScTabViewShell::DoAutoSum(bool& rRangeFinder, bool& rSubTotal, const OpCode eCode)
659 {
660  OUString aFormula;
661  const ScMarkData& rMark = GetViewData().GetMarkData();
662  if ( rMark.IsMarked() || rMark.IsMultiMarked() )
663  {
664  ScRangeList aMarkRangeList;
665  rRangeFinder = rSubTotal = false;
666  rMark.FillRangeListWithMarks( &aMarkRangeList, false );
667  ScDocument& rDoc = GetViewData().GetDocument();
668 
669  // check if one of the marked ranges is empty
670  bool bEmpty = false;
671  const size_t nCount = aMarkRangeList.size();
672  for ( size_t i = 0; i < nCount; ++i )
673  {
674  const ScRange & rRange( aMarkRangeList[i] );
675  if ( rDoc.IsBlockEmpty( rRange.aStart.Tab(),
676  rRange.aStart.Col(), rRange.aStart.Row(),
677  rRange.aEnd.Col(), rRange.aEnd.Row() ) )
678  {
679  bEmpty = true;
680  break;
681  }
682  }
683 
684  if ( bEmpty )
685  {
686  ScRangeList aRangeList;
687  const bool bDataFound = GetAutoSumArea( aRangeList );
688  if ( bDataFound )
689  {
690  ScAddress aAddr = aRangeList.back().aEnd;
691  aAddr.IncRow();
692  const bool bSubTotal( UseSubTotal( &aRangeList ) );
693  EnterAutoSum( aRangeList, bSubTotal, aAddr, eCode );
694  }
695  }
696  else
697  {
698  const bool bSubTotal( UseSubTotal( &aMarkRangeList ) );
699  for ( size_t i = 0; i < nCount; ++i )
700  {
701  const ScRange & rRange = aMarkRangeList[i];
702  const bool bSetCursor = ( i == nCount - 1 );
703  const bool bContinue = ( i != 0 );
704  if ( !AutoSum( rRange, bSubTotal, bSetCursor, bContinue, eCode ) )
705  {
706  MarkRange( rRange, false );
707  SetCursor( rRange.aEnd.Col(), rRange.aEnd.Row() );
708  const ScRangeList aRangeList;
709  ScAddress aAddr = rRange.aEnd;
710  aAddr.IncRow();
711  aFormula = GetAutoSumFormula( aRangeList, bSubTotal, aAddr , eCode);
712  break;
713  }
714  }
715  }
716  }
717  else // Only insert into input row
718  {
719  ScRangeList aRangeList;
720  rRangeFinder = GetAutoSumArea( aRangeList );
721  rSubTotal = UseSubTotal( &aRangeList );
722  ScAddress aAddr = GetViewData().GetCurPos();
723  aFormula = GetAutoSumFormula( aRangeList, rSubTotal, aAddr , eCode);
724  }
725  return aFormula;
726 }
727 
729 {
730  mpFormEditData.reset(new ScFormEditData);
731 }
732 
734 {
735  mpFormEditData.reset();
736 }
737 
738 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3047
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:1654
bool HasAutoFilter() const
Definition: dbdata.hxx:203
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: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:477
css::uno::Reference< css::datatransfer::clipboard::XClipboard > GetClipboard()
void MarkRange(const ScRange &rRange, bool bSetCursor=true, bool bContinue=false)
Definition: tabview3.cxx:1685
std::unique_ptr< ScDPObject > pDialogDPObject
Definition: tabvwsh.hxx:125
SC_DLLPUBLIC bool Intersects(const ScRange &rRange) const
Definition: address.cxx:1558
int getPart() const override
See SfxViewShell::getPart().
Definition: tabvwshc.cxx:439
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:395
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: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:486
void Remove(const SfxPoolItem &)
SC_DLLPUBLIC void SetCursor(SCCOL nPosX, SCROW nPosY, bool bNew=false)
Definition: tabview3.cxx:361
#define SCITEM_QUERYDATA
Definition: scitems.hxx:90
OUString DoAutoSum(bool &rRangeFinder, bool &rSubTotal, const OpCode eCode)
Definition: tabvwshc.cxx:658
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:560
void updateKitCellCursor(const SfxViewShell *pOtherShell) const
Definition: gridwin.cxx:5630
EditView * GetActiveView()
Definition: inputhdl.cxx:2236
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:262
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: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:809
void SetHideNotDelete(bool bOn)
void ClearFormEditData()
Definition: tabvwshc.cxx:733
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:392
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:4491
sal_Int16 SCCOL
Definition: types.hxx:21
#define SC_MOD()
Definition: scmod.hxx:249
static ScFunctionMgr * GetStarCalcFunctionMgr()
Definition: global.cxx:618
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:1171
ScGridWindow * GetActiveWin()
Definition: viewdata.cxx:3063
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:5283
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:502
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:4008
void NotifyCursor(SfxViewShell *pViewShell) const override
See SfxViewShell::NotifyCursor().
Definition: tabvwshc.cxx:459
Stores global named database ranges.
Definition: dbdata.hxx:234
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:589
bool UseSubTotal(ScRangeList *pRangeList)
Definition: tabvwshc.cxx:604
void InitFormEditData()
Definition: tabvwshc.cxx:728
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:3041
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:162
const ScConsolidateParam * GetConsolidateDlgData() const
Definition: document.hxx:640
NamedDBs & getNamedDBs()
Definition: dbdata.hxx:314
static bool isAnyEditViewInRange(const SfxViewShell *pForViewShell, bool bColumns, SCCOLROW nStart, SCCOLROW nEnd)
Definition: tabvwshc.cxx:535
void NotifyLOKClient()
Definition: inputwin.cxx:538
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
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:444