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 
127  GetViewData().GetDispatcher().Lock( true ); // lock is reset when closing dialog
128  return nullptr;
129  }
130 
131  std::shared_ptr<SfxModelessDialogController> xResult;
132 
133  if(pCW)
134  pCW->SetHideNotDelete(true);
135 
136  ScDocument& rDoc = GetViewData().GetDocument();
137 
138  switch( nSlotId )
139  {
140  case SID_CORRELATION_DIALOG:
141  xResult = std::make_shared<ScCorrelationDialog>(pB, pCW, pParent, GetViewData());
142  break;
143  case SID_SAMPLING_DIALOG:
144  xResult = std::make_shared<ScSamplingDialog>(pB, pCW, pParent, GetViewData());
145  break;
146  case SID_DESCRIPTIVE_STATISTICS_DIALOG:
147  xResult = std::make_shared<ScDescriptiveStatisticsDialog>(pB, pCW, pParent, GetViewData());
148  break;
149  case SID_ANALYSIS_OF_VARIANCE_DIALOG:
150  xResult = std::make_shared<ScAnalysisOfVarianceDialog>(pB, pCW, pParent, GetViewData());
151  break;
152  case SID_COVARIANCE_DIALOG:
153  xResult = std::make_shared<ScCovarianceDialog>(pB, pCW, pParent, GetViewData());
154  break;
155  case SID_EXPONENTIAL_SMOOTHING_DIALOG:
156  xResult = std::make_shared<ScExponentialSmoothingDialog>(pB, pCW, pParent, GetViewData());
157  break;
158  case SID_MOVING_AVERAGE_DIALOG:
159  xResult = std::make_shared<ScMovingAverageDialog>(pB, pCW, pParent, GetViewData());
160  break;
161  case SID_REGRESSION_DIALOG:
162  xResult = std::make_shared<ScRegressionDialog>(pB, pCW, pParent, GetViewData());
163  break;
164  case SID_FTEST_DIALOG:
165  xResult = std::make_shared<ScFTestDialog>(pB, pCW, pParent, GetViewData());
166  break;
167  case SID_TTEST_DIALOG:
168  xResult = std::make_shared<ScTTestDialog>(pB, pCW, pParent, GetViewData());
169  break;
170  case SID_ZTEST_DIALOG:
171  xResult = std::make_shared<ScZTestDialog>(pB, pCW, pParent, GetViewData());
172  break;
173  case SID_CHI_SQUARE_TEST_DIALOG:
174  xResult = std::make_shared<ScChiSquareTestDialog>(pB, pCW, pParent, GetViewData());
175  break;
176  case SID_FOURIER_ANALYSIS_DIALOG:
177  xResult = std::make_shared<ScFourierAnalysisDialog>(pB, pCW, pParent, GetViewData());
178  break;
179  case WID_SIMPLE_REF:
180  {
181  // dialog checks, what is in the cell
182 
183  ScViewData& rViewData = GetViewData();
184  rViewData.SetRefTabNo( rViewData.GetTabNo() );
185  xResult = std::make_shared<ScSimpleRefDlg>(pB, pCW, pParent);
186  break;
187  }
188  case FID_DEFINE_NAME:
189  {
190  if (!mbInSwitch)
191  {
192  xResult = std::make_shared<ScNameDlg>(pB, pCW, pParent, GetViewData(),
193  ScAddress( GetViewData().GetCurX(),
194  GetViewData().GetCurY(),
195  GetViewData().GetTabNo() ) );
196  }
197  else
198  {
199  xResult = std::make_shared<ScNameDlg>( pB, pCW, pParent, GetViewData(),
200  ScAddress( GetViewData().GetCurX(),
201  GetViewData().GetCurY(),
202  GetViewData().GetTabNo() ), &m_RangeMap);
203  static_cast<ScNameDlg*>(xResult.get())->SetEntry(maName, maScope);
204  mbInSwitch = false;
205  }
206  break;
207  }
208  case FID_ADD_NAME:
209  {
210  if (!mbInSwitch)
211  {
212  std::map<OUString, ScRangeName*> aRangeMap;
213  rDoc.GetRangeNameMap(aRangeMap);
214  xResult = std::make_shared<ScNameDefDlg>(pB, pCW, pParent, GetViewData(), aRangeMap,
215  ScAddress(GetViewData().GetCurX(),
216  GetViewData().GetCurY(),
217  GetViewData().GetTabNo()), true);
218  }
219  else
220  {
221  std::map<OUString, ScRangeName*> aRangeMap;
222  for (auto const& itr : m_RangeMap)
223  {
224  aRangeMap.insert(std::pair<OUString, ScRangeName*>(itr.first, itr.second.get()));
225  }
226  xResult = std::make_shared<ScNameDefDlg>(pB, pCW, pParent, GetViewData(), aRangeMap,
227  ScAddress(GetViewData().GetCurX(),
228  GetViewData().GetCurY(),
229  GetViewData().GetTabNo()), false);
230  }
231  break;
232  }
233  case SID_RANDOM_NUMBER_GENERATOR_DIALOG:
234  xResult = std::make_shared<ScRandomNumberGeneratorDialog>(pB, pCW, pParent, GetViewData());
235  break;
236  case SID_DEFINE_DBNAME:
237  {
238  // when called for an existing range, then mark
239  GetDBData( true, SC_DB_OLD );
240  const ScMarkData& rMark = GetViewData().GetMarkData();
241  if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
242  MarkDataArea( false );
243 
244  xResult = std::make_shared<ScDbNameDlg>(pB, pCW, pParent, GetViewData());
245  break;
246  }
247  case SID_OPENDLG_EDIT_PRINTAREA:
248  xResult = std::make_shared<ScPrintAreasDlg>(pB, pCW, pParent);
249  break;
250  case SID_DEFINE_COLROWNAMERANGES:
251  xResult = std::make_shared<ScColRowNameRangesDlg>(pB, pCW, pParent, GetViewData());
252  break;
253  case SID_OPENDLG_SOLVE:
254  {
255  ScViewData& rViewData = GetViewData();
256  ScAddress aCurPos( rViewData.GetCurX(),
257  rViewData.GetCurY(),
258  rViewData.GetTabNo());
259  xResult = std::make_shared<ScSolverDlg>(pB, pCW, pParent, &rViewData.GetDocument(), aCurPos);
260  break;
261  }
262  case SID_OPENDLG_TABOP:
263  {
264  ScViewData& rViewData = GetViewData();
265  ScRefAddress aCurPos ( rViewData.GetCurX(),
266  rViewData.GetCurY(),
267  rViewData.GetTabNo());
268 
269  xResult = std::make_shared<ScTabOpDlg>(pB, pCW, pParent, &rViewData.GetDocument(), aCurPos);
270  break;
271  }
272  case SID_OPENDLG_CONSOLIDATE:
273  {
274  SfxItemSet aArgSet( GetPool(),
277 
278  const ScConsolidateParam* pDlgData =
279  rDoc.GetConsolidateDlgData();
280 
281  if ( !pDlgData )
282  {
283  ScConsolidateParam aConsParam;
284  SCCOL nStartCol, nEndCol;
285  SCROW nStartRow, nEndRow;
286  SCTAB nStartTab, nEndTab;
287 
288  GetViewData().GetSimpleArea( nStartCol, nStartRow, nStartTab,
289  nEndCol, nEndRow, nEndTab );
290 
291  PutInOrder( nStartCol, nEndCol );
292  PutInOrder( nStartRow, nEndRow );
293  PutInOrder( nStartTab, nEndTab );
294 
295  aConsParam.nCol = nStartCol;
296  aConsParam.nRow = nStartRow;
297  aConsParam.nTab = nStartTab;
298 
300  &aConsParam ) );
301  }
302  else
303  {
304  aArgSet.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA, pDlgData ) );
305  }
306  xResult = std::make_shared<ScConsolidateDlg>(pB, pCW, pParent, aArgSet);
307  break;
308  }
309  case SID_FILTER:
310  {
311 
312  ScQueryParam aQueryParam;
313  SfxItemSet aArgSet( GetPool(),
315  SCITEM_QUERYDATA>{} );
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;
338  SfxItemSet aArgSet( GetPool(),
340  SCITEM_QUERYDATA>{} );
341 
343  pDBData->ExtendDataArea(rDoc);
344  pDBData->GetQueryParam( aQueryParam );
345 
346  ScRange aArea;
347  pDBData->GetArea(aArea);
348  MarkRange(aArea, false);
349 
350  ScQueryItem aItem( SCITEM_QUERYDATA, &GetViewData(), &aQueryParam );
351  ScRange aAdvSource;
352  if (pDBData->GetAdvancedQuerySource(aAdvSource))
353  aItem.SetAdvancedQuerySource( &aAdvSource );
354 
355  aArgSet.Put( aItem );
356 
357  // mark current sheet (due to RefInput in dialog)
358  GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
359 
360  xResult = std::make_shared<ScSpecialFilterDlg>(pB, pCW, pParent, aArgSet);
361  break;
362  }
363  case SID_OPENDLG_OPTSOLVER:
364  {
365  ScViewData& rViewData = GetViewData();
366  ScAddress aCurPos( rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo());
367  xResult = std::make_shared<ScOptSolverDlg>(pB, pCW, pParent, rViewData.GetDocShell(), aCurPos);
368  break;
369  }
370  case FID_CHG_SHOW:
371  {
372  // dialog checks, what is in the cell
373  xResult = std::make_shared<ScHighlightChgDlg>(pB, pCW, pParent, GetViewData());
374  break;
375  }
376  case SID_MANAGE_XML_SOURCE:
377  {
378  xResult = std::make_shared<ScXMLSourceDlg>(pB, pCW, pParent, &rDoc);
379  break;
380  }
381  case SID_OPENDLG_PIVOTTABLE:
382  {
383  // all settings must be in pDialogDPObject
384 
385  if( pDialogDPObject )
386  {
387  // Check for an existing datapilot output.
388  ScViewData& rViewData = GetViewData();
389  rViewData.SetRefTabNo( rViewData.GetTabNo() );
390  ScDPObject* pObj = rDoc.GetDPAtCursor(rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo());
391  xResult = std::make_shared<ScPivotLayoutDialog>(pB, pCW, pParent, &rViewData, pDialogDPObject.get(), pObj == nullptr);
392  }
393 
394  break;
395  }
396  case SID_OPENDLG_FUNCTION:
397  {
398  if (!isLOKMobilePhone())
399  {
400  // dialog checks, what is in the cell
401  xResult = o3tl::make_shared<ScFormulaDlg>(pB, pCW, pParent, GetViewData(), ScGlobal::GetStarCalcFunctionMgr());
402  }
403  break;
404  }
405  case WID_CONDFRMT_REF:
406  {
407  const ScCondFormatDlgItem* pDlgItem = nullptr;
408  // Get the pool item stored by Conditional Format Manager Dialog.
410  if (itemsRange.begin() != itemsRange.end())
411  {
412  const SfxPoolItem* pItem = *itemsRange.begin();
413  pDlgItem = static_cast<const ScCondFormatDlgItem*>(pItem);
414  }
415 
416  if (pDlgItem)
417  {
418  ScViewData& rViewData = GetViewData();
419  rViewData.SetRefTabNo( rViewData.GetTabNo() );
420 
421  xResult = std::make_shared<ScCondFormatDlg>(pB, pCW, pParent, &rViewData, pDlgItem);
422 
423  // Remove the pool item stored by Conditional Format Manager Dialog.
424  GetPool().Remove(*pDlgItem);
425  }
426 
427  break;
428  }
429  }
430 
431  if (xResult)
432  xResult->Initialize( pInfo );
433  return xResult;
434 }
435 
437 {
438  return GetViewData().GetTabNo();
439 }
440 
442 {
443  UpdateInputHandler(true, false);
444 
445  ScInputHandler* pHdl = mpInputHandler ? mpInputHandler.get() : SC_MOD()->GetInputHdl();
446  if (pHdl)
447  {
448  ScInputWindow* pInputWindow = pHdl->GetInputWindow();
449  if (pInputWindow)
450  {
451  pInputWindow->NotifyLOKClient();
452  }
453  }
454 }
455 
457 {
458  ScDrawView* pDrView = const_cast<ScTabViewShell*>(this)->GetScDrawView();
459  if (pDrView)
460  {
461  if (pDrView->GetTextEditObject())
462  {
463  // Blinking cursor.
464  EditView& rEditView = pDrView->GetTextEditOutlinerView()->GetEditView();
465  rEditView.RegisterOtherShell(pOtherShell);
466  rEditView.ShowCursor();
467  rEditView.RegisterOtherShell(nullptr);
468  // Text selection, if any.
469  rEditView.DrawSelectionXOR(pOtherShell);
470  }
471  else
472  {
473  // Graphic selection.
474  pDrView->AdjustMarkHdl(pOtherShell);
475  }
476  }
477 
478  const ScGridWindow* pWin = GetViewData().GetActiveWin();
479  if (pWin)
480  pWin->updateKitCellCursor(pOtherShell);
481 }
482 
483 css::uno::Reference<css::datatransfer::XTransferable2> ScTabViewShell::GetClipData(vcl::Window* pWin)
484 {
485  SfxViewFrame* pViewFrame = nullptr;
486  css::uno::Reference<css::datatransfer::XTransferable2> xTransferable;
487  css::uno::Reference<css::datatransfer::clipboard::XClipboard> xClipboard;
488 
489  if (pWin)
490  xClipboard = pWin->GetClipboard();
491  else if ((pViewFrame = SfxViewFrame::GetFirst(nullptr, false)))
492  xClipboard = pViewFrame->GetWindow().GetClipboard();
493 
494  xTransferable.set(xClipboard.is() ? xClipboard->getContents() : nullptr, css::uno::UNO_QUERY);
495 
496  return xTransferable;
497 }
498 
499 void ScTabViewShell::notifyAllViewsHeaderInvalidation(const SfxViewShell* pForViewShell, HeaderType eHeaderType, SCTAB nCurrentTabIndex)
500 {
502  return;
503 
504  OString aPayload;
505  switch (eHeaderType)
506  {
507  case COLUMN_HEADER:
508  aPayload = "column";
509  break;
510  case ROW_HEADER:
511  aPayload = "row";
512  break;
513  case BOTH_HEADERS:
514  default:
515  aPayload = "all";
516  break;
517  }
518 
519  SfxViewShell* pViewShell = SfxViewShell::GetFirst();
520  while (pViewShell)
521  {
522  ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
523  if (pTabViewShell && pViewShell->GetDocId() == pForViewShell->GetDocId() && (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:3046
SfxViewFrame * GetViewFrame() const
SC_DLLPUBLIC ScDPObject * GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: documen3.cxx:372
void MarkDataArea(bool bIncludeCursor=true)
Definition: tabview3.cxx:1651
bool HasAutoFilter() const
Definition: dbdata.hxx:204
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:816
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:117
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:1682
std::unique_ptr< ScDPObject > pDialogDPObject
Definition: tabvwsh.hxx:127
SC_DLLPUBLIC bool Intersects(const ScRange &rRange) const
Definition: address.cxx:1549
int getPart() const override
See SfxViewShell::getPart().
Definition: tabvwshc.cxx:436
std::map< OUString, std::unique_ptr< ScRangeName > > m_RangeMap
Definition: tabvwsh.hxx:162
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:157
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: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:483
void Remove(const SfxPoolItem &)
SC_DLLPUBLIC void SetCursor(SCCOL nPosX, SCROW nPosY, bool bNew=false)
Definition: tabview3.cxx:358
#define SCITEM_QUERYDATA
Definition: scitems.hxx:91
OUString DoAutoSum(bool &rRangeFinder, bool &rSubTotal, const OpCode eCode)
Definition: tabvwshc.cxx:654
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:5780
EditView * GetActiveView()
Definition: inputhdl.cxx:2218
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:259
bool isCompatFlagSet(Compat flag)
void libreOfficeKitViewCallback(int nType, const char *pPayload) const override
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:638
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:729
ScViewData & GetViewData()
Definition: tabview.hxx:332
#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:392
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:146
int i
bool RowFiltered(SCROW nRow, SCTAB nTab, SCROW *pFirstRow=nullptr, SCROW *pLastRow=nullptr) const
Definition: document.cxx:4499
sal_Int16 SCCOL
Definition: types.hxx:22
#define SC_MOD()
Definition: scmod.hxx:253
static ScFunctionMgr * GetStarCalcFunctionMgr()
Definition: global.cxx:620
size_t size() const
Definition: rangelst.hxx:90
OUString maScope
Definition: tabvwsh.hxx:165
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:5296
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:499
ScRange & back()
Definition: rangelst.hxx:95
void GetArea(SCTAB &rTab, SCCOL &rCol1, SCROW &rRow1, SCCOL &rCol2, SCROW &rRow2) const
Definition: dbdata.cxx:301
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:456
Stores global named database ranges.
Definition: dbdata.hxx:235
sal_Int32 SCROW
Definition: types.hxx:18
std::unique_ptr< ScFormEditData > mpFormEditData
Definition: tabvwsh.hxx:116
ScDrawView * GetScDrawView()
Definition: tabview.hxx:340
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: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
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:164
const ScConsolidateParam * GetConsolidateDlgData() const
Definition: document.hxx:649
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:520
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
const ScInputHandler * GetInputHandler() const
Definition: tabvwsh.hxx:233
#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:441