tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / view / tabvwshc.cxx
blob8fc9fb1276cfd5f393c0e99d4ffa1b37576b604b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <scitems.hxx>
21 #include <sfx2/childwin.hxx>
22 #include <sfx2/dispatch.hxx>
23 #include <svx/theme/ThemeColorChangerCommon.hxx>
24 #include <editeng/editview.hxx>
25 #include <inputhdl.hxx>
27 #include <tabvwsh.hxx>
28 #include <sc.hrc>
29 #include <scres.hrc>
30 #include <global.hxx>
31 #include <scmod.hxx>
32 #include <document.hxx>
33 #include <uiitems.hxx>
34 #include <namedlg.hxx>
35 #include <namedefdlg.hxx>
36 #include <solvrdlg.hxx>
37 #include <optsolver.hxx>
38 #include <tabopdlg.hxx>
39 #include <consdlg.hxx>
40 #include <filtdlg.hxx>
41 #include <dbnamdlg.hxx>
42 #include <areasdlg.hxx>
43 #include <crnrdlg.hxx>
44 #include <formula.hxx>
45 #include <highred.hxx>
46 #include <simpref.hxx>
47 #include <funcdesc.hxx>
48 #include <dpobject.hxx>
49 #include <markdata.hxx>
50 #include <reffact.hxx>
51 #include <condformatdlg.hxx>
52 #include <condformateasydlg.hxx>
53 #include <xmlsourcedlg.hxx>
54 #include <condformatdlgdata.hxx>
55 #include <formdata.hxx>
56 #include <inputwin.hxx>
58 #include <RandomNumberGeneratorDialog.hxx>
59 #include <SamplingDialog.hxx>
60 #include <DescriptiveStatisticsDialog.hxx>
61 #include <AnalysisOfVarianceDialog.hxx>
62 #include <CorrelationDialog.hxx>
63 #include <CovarianceDialog.hxx>
64 #include <ExponentialSmoothingDialog.hxx>
65 #include <MovingAverageDialog.hxx>
66 #include <RegressionDialog.hxx>
67 #include <TTestDialog.hxx>
68 #include <FTestDialog.hxx>
69 #include <ZTestDialog.hxx>
70 #include <ChiSquareTestDialog.hxx>
71 #include <FourierAnalysisDialog.hxx>
73 #include <PivotLayoutDialog.hxx>
74 #include <SparklineDialog.hxx>
75 #include <SparklineDataRangeDialog.hxx>
77 #include <svtools/colorcfg.hxx>
78 #include <comphelper/lok.hxx>
79 #include <o3tl/unreachable.hxx>
80 #include <o3tl/make_shared.hxx>
81 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
83 void ScTabViewShell::SetCurRefDlgId( sal_uInt16 nNew )
85 // CurRefDlgId is stored in ScModule to find if a ref dialog is open,
86 // and in the view to identify the view that has opened the dialog
87 nCurRefDlgId = nNew;
90 //ugly hack to call Define Name from Manage Names
91 void ScTabViewShell::SwitchBetweenRefDialogs(SfxModelessDialogController* pDialog)
93 ScModule* mod = ScModule::get();
94 sal_uInt16 nSlotId = mod->GetCurRefDlgId();
95 if( nSlotId == FID_ADD_NAME )
97 static_cast<ScNameDefDlg*>(pDialog)->GetNewData(maName, maScope);
98 static_cast<ScNameDefDlg*>(pDialog)->Close();
99 sal_uInt16 nId = ScNameDlgWrapper::GetChildWindowId();
100 SfxViewFrame& rViewFrm = GetViewFrame();
101 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
103 mod->SetRefDialog( nId, pWnd == nullptr );
105 else if (nSlotId == FID_DEFINE_NAME)
107 mbInSwitch = true;
108 static_cast<ScNameDlg*>(pDialog)->GetRangeNames(m_RangeMap);
109 static_cast<ScNameDlg*>(pDialog)->Close();
110 sal_uInt16 nId = ScNameDefDlgWrapper::GetChildWindowId();
111 SfxViewFrame& rViewFrm = GetViewFrame();
112 SfxChildWindow* pWnd = rViewFrm.GetChildWindow( nId );
114 mod->SetRefDialog( nId, pWnd == nullptr );
118 std::shared_ptr<SfxModelessDialogController> ScTabViewShell::CreateRefDialogController(
119 SfxBindings* pB, SfxChildWindow* pCW,
120 SfxChildWinInfo* pInfo,
121 weld::Window* pParent, sal_uInt16 nSlotId)
123 // only open dialog when called through ScModule::SetRefDialog,
124 // so that it does not re appear for instance after a crash (#42341#).
126 if (ScModule::get()->GetCurRefDlgId() != nSlotId)
127 return nullptr;
129 if ( nCurRefDlgId != nSlotId )
131 if (!comphelper::LibreOfficeKit::isActive())
133 // the dialog has been opened in a different view
134 // -> lock the dispatcher for this view (modal mode)
136 GetViewData().GetDispatcher().Lock( true ); // lock is reset when closing dialog
138 return nullptr;
141 std::shared_ptr<SfxModelessDialogController> xResult;
143 if(pCW)
144 pCW->SetHideNotDelete(true);
146 ScDocument& rDoc = GetViewData().GetDocument();
148 switch( nSlotId )
150 case SID_CORRELATION_DIALOG:
151 xResult = std::make_shared<ScCorrelationDialog>(pB, pCW, pParent, GetViewData());
152 break;
153 case SID_SAMPLING_DIALOG:
154 xResult = std::make_shared<ScSamplingDialog>(pB, pCW, pParent, GetViewData());
155 break;
156 case SID_DESCRIPTIVE_STATISTICS_DIALOG:
157 xResult = std::make_shared<ScDescriptiveStatisticsDialog>(pB, pCW, pParent, GetViewData());
158 break;
159 case SID_ANALYSIS_OF_VARIANCE_DIALOG:
160 xResult = std::make_shared<ScAnalysisOfVarianceDialog>(pB, pCW, pParent, GetViewData());
161 break;
162 case SID_COVARIANCE_DIALOG:
163 xResult = std::make_shared<ScCovarianceDialog>(pB, pCW, pParent, GetViewData());
164 break;
165 case SID_EXPONENTIAL_SMOOTHING_DIALOG:
166 xResult = std::make_shared<ScExponentialSmoothingDialog>(pB, pCW, pParent, GetViewData());
167 break;
168 case SID_MOVING_AVERAGE_DIALOG:
169 xResult = std::make_shared<ScMovingAverageDialog>(pB, pCW, pParent, GetViewData());
170 break;
171 case SID_REGRESSION_DIALOG:
172 xResult = std::make_shared<ScRegressionDialog>(pB, pCW, pParent, GetViewData());
173 break;
174 case SID_FTEST_DIALOG:
175 xResult = std::make_shared<ScFTestDialog>(pB, pCW, pParent, GetViewData());
176 break;
177 case SID_TTEST_DIALOG:
178 xResult = std::make_shared<ScTTestDialog>(pB, pCW, pParent, GetViewData());
179 break;
180 case SID_ZTEST_DIALOG:
181 xResult = std::make_shared<ScZTestDialog>(pB, pCW, pParent, GetViewData());
182 break;
183 case SID_CHI_SQUARE_TEST_DIALOG:
184 xResult = std::make_shared<ScChiSquareTestDialog>(pB, pCW, pParent, GetViewData());
185 break;
186 case SID_FOURIER_ANALYSIS_DIALOG:
187 xResult = std::make_shared<ScFourierAnalysisDialog>(pB, pCW, pParent, GetViewData());
188 break;
189 case WID_SIMPLE_REF:
191 // dialog checks, what is in the cell
193 ScViewData& rViewData = GetViewData();
194 rViewData.SetRefTabNo( rViewData.GetTabNo() );
195 xResult = std::make_shared<ScSimpleRefDlg>(pB, pCW, pParent);
196 break;
198 case FID_DEFINE_NAME:
200 if (!mbInSwitch)
202 xResult = std::make_shared<ScNameDlg>(pB, pCW, pParent, GetViewData(),
203 ScAddress( GetViewData().GetCurX(),
204 GetViewData().GetCurY(),
205 GetViewData().GetTabNo() ) );
207 else
209 xResult = std::make_shared<ScNameDlg>( pB, pCW, pParent, GetViewData(),
210 ScAddress( GetViewData().GetCurX(),
211 GetViewData().GetCurY(),
212 GetViewData().GetTabNo() ), &m_RangeMap);
213 static_cast<ScNameDlg*>(xResult.get())->SetEntry(maName, maScope);
214 mbInSwitch = false;
216 break;
218 case FID_ADD_NAME:
220 if (!mbInSwitch)
222 std::map<OUString, ScRangeName*> aRangeMap;
223 rDoc.GetRangeNameMap(aRangeMap);
224 xResult = std::make_shared<ScNameDefDlg>(pB, pCW, pParent, GetViewData(), std::move(aRangeMap),
225 ScAddress(GetViewData().GetCurX(),
226 GetViewData().GetCurY(),
227 GetViewData().GetTabNo()), true);
229 else
231 std::map<OUString, ScRangeName*> aRangeMap;
232 for (auto& itr : m_RangeMap)
234 aRangeMap.insert(std::pair<OUString, ScRangeName*>(itr.first, &itr.second));
236 xResult = std::make_shared<ScNameDefDlg>(pB, pCW, pParent, GetViewData(), std::move(aRangeMap),
237 ScAddress(GetViewData().GetCurX(),
238 GetViewData().GetCurY(),
239 GetViewData().GetTabNo()), false);
241 break;
243 case SID_RANDOM_NUMBER_GENERATOR_DIALOG:
244 xResult = std::make_shared<ScRandomNumberGeneratorDialog>(pB, pCW, pParent, GetViewData());
245 break;
246 case SID_SPARKLINE_DIALOG:
248 xResult = std::make_shared<sc::SparklineDialog>(pB, pCW, pParent, GetViewData());
249 break;
251 case SID_SPARKLINE_DATA_RANGE_DIALOG:
253 xResult = std::make_shared<sc::SparklineDataRangeDialog>(pB, pCW, pParent, GetViewData());
254 break;
256 case SID_DEFINE_DBNAME:
258 // when called for an existing range, then mark
259 GetDBData( true, SC_DB_OLD );
260 const ScMarkData& rMark = GetViewData().GetMarkData();
261 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
262 MarkDataArea( false );
264 xResult = std::make_shared<ScDbNameDlg>(pB, pCW, pParent, GetViewData());
265 break;
267 case SID_OPENDLG_EDIT_PRINTAREA:
268 xResult = std::make_shared<ScPrintAreasDlg>(pB, pCW, pParent);
269 break;
270 case SID_DEFINE_COLROWNAMERANGES:
271 xResult = std::make_shared<ScColRowNameRangesDlg>(pB, pCW, pParent, GetViewData());
272 break;
273 case SID_OPENDLG_SOLVE:
275 ScViewData& rViewData = GetViewData();
276 ScAddress aCurPos( rViewData.GetCurX(),
277 rViewData.GetCurY(),
278 rViewData.GetTabNo());
279 xResult = std::make_shared<ScSolverDlg>(pB, pCW, pParent, &rViewData.GetDocument(), aCurPos);
280 break;
282 case SID_OPENDLG_TABOP:
284 ScViewData& rViewData = GetViewData();
285 ScRefAddress aCurPos ( rViewData.GetCurX(),
286 rViewData.GetCurY(),
287 rViewData.GetTabNo());
289 xResult = std::make_shared<ScTabOpDlg>(pB, pCW, pParent, &rViewData.GetDocument(), aCurPos);
290 break;
292 case SID_OPENDLG_CONSOLIDATE:
294 SfxItemSetFixed<SCITEM_CONSOLIDATEDATA,
295 SCITEM_CONSOLIDATEDATA> aArgSet( GetPool() );
297 const ScConsolidateParam* pDlgData =
298 rDoc.GetConsolidateDlgData();
300 if ( !pDlgData )
302 ScConsolidateParam aConsParam;
303 SCCOL nStartCol, nEndCol;
304 SCROW nStartRow, nEndRow;
305 SCTAB nStartTab, nEndTab;
307 GetViewData().GetSimpleArea( nStartCol, nStartRow, nStartTab,
308 nEndCol, nEndRow, nEndTab );
310 PutInOrder( nStartCol, nEndCol );
311 PutInOrder( nStartRow, nEndRow );
312 PutInOrder( nStartTab, nEndTab );
314 aConsParam.nCol = nStartCol;
315 aConsParam.nRow = nStartRow;
316 aConsParam.nTab = nStartTab;
318 aArgSet.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA,
319 &aConsParam ) );
321 else
323 aArgSet.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA, pDlgData ) );
325 xResult = std::make_shared<ScConsolidateDlg>(pB, pCW, pParent, aArgSet);
326 break;
328 case SID_EASY_CONDITIONAL_FORMAT_DIALOG:
330 xResult = std::make_shared<sc::ConditionalFormatEasyDialog>(pB, pCW, pParent, &GetViewData());
331 break;
333 case SID_FILTER:
336 ScQueryParam aQueryParam;
337 SfxItemSetFixed<SCITEM_QUERYDATA, SCITEM_QUERYDATA> aArgSet( GetPool() );
339 ScDBData* pDBData = GetDBData(false, SC_DB_MAKE, ScGetDBSelection::RowDown);
340 pDBData->ExtendDataArea(rDoc);
341 pDBData->ExtendBackColorArea(rDoc);
342 pDBData->GetQueryParam( aQueryParam );
344 ScRange aArea;
345 pDBData->GetArea(aArea);
346 MarkRange(aArea, false);
348 aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA,
349 &GetViewData(),
350 &aQueryParam ) );
352 // mark current sheet (due to RefInput in dialog)
353 GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
355 xResult = std::make_shared<ScFilterDlg>(pB, pCW, pParent, aArgSet);
356 break;
358 case SID_SPECIAL_FILTER:
360 ScQueryParam aQueryParam;
361 SfxItemSetFixed<SCITEM_QUERYDATA,
362 SCITEM_QUERYDATA> aArgSet( GetPool() );
364 ScDBData* pDBData = GetDBData(false, SC_DB_MAKE, ScGetDBSelection::RowDown);
365 pDBData->ExtendDataArea(rDoc);
366 pDBData->GetQueryParam( aQueryParam );
368 ScRange aArea;
369 pDBData->GetArea(aArea);
370 MarkRange(aArea, false);
372 ScQueryItem aItem( SCITEM_QUERYDATA, &GetViewData(), &aQueryParam );
373 ScRange aAdvSource;
374 if (pDBData->GetAdvancedQuerySource(aAdvSource))
375 aItem.SetAdvancedQuerySource( &aAdvSource );
377 aArgSet.Put( aItem );
379 // mark current sheet (due to RefInput in dialog)
380 GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
382 xResult = std::make_shared<ScSpecialFilterDlg>(pB, pCW, pParent, aArgSet);
383 break;
385 case SID_OPENDLG_OPTSOLVER:
387 ScViewData& rViewData = GetViewData();
388 ScAddress aCurPos( rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo());
389 xResult = std::make_shared<ScOptSolverDlg>(pB, pCW, pParent, rViewData.GetDocShell(), aCurPos);
390 break;
392 case FID_CHG_SHOW:
394 // dialog checks, what is in the cell
395 xResult = std::make_shared<ScHighlightChgDlg>(pB, pCW, pParent, GetViewData());
396 break;
398 case SID_MANAGE_XML_SOURCE:
400 xResult = std::make_shared<ScXMLSourceDlg>(pB, pCW, pParent, &rDoc);
401 break;
403 case SID_OPENDLG_PIVOTTABLE:
405 // all settings must be in pDialogDPObject
407 if( pDialogDPObject )
409 // Check for an existing datapilot output.
410 ScViewData& rViewData = GetViewData();
411 rViewData.SetRefTabNo( rViewData.GetTabNo() );
412 ScDPObject* pObj = rDoc.GetDPAtCursor(rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo());
413 xResult = std::make_shared<ScPivotLayoutDialog>(pB, pCW, pParent, &rViewData, pDialogDPObject.get(), pObj == nullptr);
416 break;
418 case SID_OPENDLG_FUNCTION:
420 if (!isLOKMobilePhone())
422 // dialog checks, what is in the cell
423 xResult = o3tl::make_shared<ScFormulaDlg>(pB, pCW, pParent, GetViewData(), ScGlobal::GetStarCalcFunctionMgr());
425 break;
427 case WID_CONDFRMT_REF:
429 // Get the pool item stored by Conditional Format Manager Dialog.
430 const std::shared_ptr<ScCondFormatDlgData>& rDlgItem(getScCondFormatDlgItem());
432 if (rDlgItem)
434 ScViewData& rViewData = GetViewData();
435 rViewData.SetRefTabNo( rViewData.GetTabNo() );
437 xResult = std::make_shared<ScCondFormatDlg>(pB, pCW, pParent, &rViewData, rDlgItem);
439 // Remove the pool item stored by Conditional Format Manager Dialog.
440 // tdf#160252 still needed *after* change to ScCondFormatDlgData due to
441 // UnitTest UITest_conditional_format
442 setScCondFormatDlgItem(nullptr);
445 break;
449 if (xResult)
451 pInfo->nFlags = SfxChildWindowFlags::NEVERHIDE;
452 xResult->Initialize(pInfo);
454 return xResult;
457 int ScTabViewShell::getPart() const
459 return GetViewData().GetTabNo();
462 void ScTabViewShell::afterCallbackRegistered()
464 // common tasks
465 SfxViewShell::afterCallbackRegistered();
467 UpdateInputHandler(true, false);
469 ScInputHandler* pHdl = mpInputHandler ? mpInputHandler.get() : ScModule::get()->GetInputHdl();
470 if (pHdl)
472 ScInputWindow* pInputWindow = pHdl->GetInputWindow();
473 if (pInputWindow)
475 pInputWindow->NotifyLOKClient();
479 SfxObjectShell* pDocShell = GetObjectShell();
480 if (pDocShell)
482 std::shared_ptr<model::ColorSet> pThemeColors = pDocShell->GetThemeColors();
483 std::set<Color> aDocumentColors = pDocShell->GetDocColors();
484 svx::theme::notifyLOK(pThemeColors, aDocumentColors);
488 void ScTabViewShell::NotifyCursor(SfxViewShell* pOtherShell) const
490 ScDrawView* pDrView = const_cast<ScTabViewShell*>(this)->GetScDrawView();
491 if (pDrView)
493 if (pDrView->GetTextEditObject())
495 // Blinking cursor.
496 EditView& rEditView = pDrView->GetTextEditOutlinerView()->GetEditView();
497 rEditView.RegisterOtherShell(pOtherShell);
498 rEditView.ShowCursor();
499 rEditView.RegisterOtherShell(nullptr);
500 // Text selection, if any.
501 rEditView.DrawSelectionXOR(pOtherShell);
503 else
505 // Graphic selection.
506 pDrView->AdjustMarkHdl(pOtherShell);
510 const ScGridWindow* pWin = GetViewData().GetActiveWin();
511 if (pWin)
512 pWin->updateKitCellCursor(pOtherShell);
515 ::Color ScTabViewShell::GetColorConfigColor(svtools::ColorConfigEntry nColorType) const
517 switch (nColorType)
519 case svtools::ColorConfigEntry::DOCCOLOR:
521 const ScViewRenderingOptions& rViewRenderingOptions = GetViewRenderingData();
522 return rViewRenderingOptions.GetDocColor();
524 // Should never be called for an unimplemented color type
525 default:
527 O3TL_UNREACHABLE;
532 css::uno::Reference<css::datatransfer::XTransferable2> ScTabViewShell::GetClipData(vcl::Window* pWin)
534 SfxViewFrame* pViewFrame = nullptr;
535 css::uno::Reference<css::datatransfer::XTransferable2> xTransferable;
536 css::uno::Reference<css::datatransfer::clipboard::XClipboard> xClipboard;
538 if (pWin)
539 xClipboard = pWin->GetClipboard();
540 else if ((pViewFrame = SfxViewFrame::GetFirst(nullptr, false)))
541 xClipboard = pViewFrame->GetWindow().GetClipboard();
543 xTransferable.set(xClipboard.is() ? xClipboard->getContents() : nullptr, css::uno::UNO_QUERY);
545 return xTransferable;
548 void ScTabViewShell::notifyAllViewsHeaderInvalidation(const SfxViewShell* pForViewShell, HeaderType eHeaderType, SCTAB nCurrentTabIndex)
550 if (!comphelper::LibreOfficeKit::isActive())
551 return;
553 OString aPayload;
554 switch (eHeaderType)
556 case COLUMN_HEADER:
557 aPayload = "column"_ostr;
558 break;
559 case ROW_HEADER:
560 aPayload = "row"_ostr;
561 break;
562 case BOTH_HEADERS:
563 default:
564 aPayload = "all"_ostr;
565 break;
568 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
569 while (pViewShell)
571 ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
572 if (pTabViewShell && pViewShell->GetDocId() == pForViewShell->GetDocId()
573 && (nCurrentTabIndex == -1 || pTabViewShell->getPart() == nCurrentTabIndex))
575 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_HEADER, aPayload);
577 pViewShell = SfxViewShell::GetNext(*pViewShell);
581 bool ScTabViewShell::isAnyEditViewInRange(const SfxViewShell* pForViewShell, bool bColumns, SCCOLROW nStart, SCCOLROW nEnd)
583 if (comphelper::LibreOfficeKit::isActive())
585 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
586 while (pViewShell)
588 ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
589 if (pTabViewShell && pTabViewShell->GetDocId() == pForViewShell->GetDocId())
591 ScInputHandler* pInputHandler = pTabViewShell->GetInputHandler();
592 if (pInputHandler && pInputHandler->GetActiveView())
594 const ScViewData& rViewData = pTabViewShell->GetViewData();
595 SCCOLROW nPos = bColumns ? rViewData.GetCurX() : rViewData.GetCurY();
596 if (nStart <= nPos && nPos <= nEnd)
597 return true;
600 pViewShell = SfxViewShell::GetNext(*pViewShell);
603 return false;
606 void ScTabViewShell::notifyAllViewsSheetGeomInvalidation(const SfxViewShell* pForViewShell, bool bColumns,
607 bool bRows, bool bSizes, bool bHidden, bool bFiltered,
608 bool bGroups, SCTAB nCurrentTabIndex)
610 if (!comphelper::LibreOfficeKit::isActive() ||
611 !comphelper::LibreOfficeKit::isCompatFlagSet(
612 comphelper::LibreOfficeKit::Compat::scPrintTwipsMsgs))
613 return;
615 if (!bColumns && !bRows)
616 return;
618 bool bAllTypes = bSizes && bHidden && bFiltered && bGroups;
619 bool bAllDims = bColumns && bRows;
620 OString aPayload = bAllDims ? "all" : bColumns ? "columns" : "rows";
622 if (!bAllTypes)
624 if (bSizes)
625 aPayload += " sizes";
627 if (bHidden)
628 aPayload += " hidden";
630 if (bFiltered)
631 aPayload += " filtered";
633 if (bGroups)
634 aPayload += " groups";
637 SfxViewShell* pViewShell = SfxViewShell::GetFirst();
638 while (pViewShell)
640 ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
641 if (pTabViewShell && pViewShell->GetDocId() == pForViewShell->GetDocId() &&
642 (nCurrentTabIndex == -1 || pTabViewShell->getPart() == nCurrentTabIndex))
644 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_SHEET_GEOMETRY, aPayload);
646 pViewShell = SfxViewShell::GetNext(*pViewShell);
650 bool ScTabViewShell::UseSubTotal(ScRangeList* pRangeList)
652 bool bSubTotal = false;
653 ScDocument& rDoc = GetViewData().GetDocument();
654 size_t nRangeCount (pRangeList->size());
655 size_t nRangeIndex (0);
656 while (!bSubTotal && nRangeIndex < nRangeCount)
658 const ScRange& rRange = (*pRangeList)[nRangeIndex];
659 SCTAB nTabEnd(rRange.aEnd.Tab());
660 SCTAB nTab(rRange.aStart.Tab());
661 while (!bSubTotal && nTab <= nTabEnd)
663 SCROW nRowEnd(rRange.aEnd.Row());
664 SCROW nRow(rRange.aStart.Row());
665 while (!bSubTotal && nRow <= nRowEnd)
667 if (rDoc.RowFiltered(nRow, nTab))
668 bSubTotal = true;
669 else
670 ++nRow;
672 ++nTab;
674 ++nRangeIndex;
677 if (!bSubTotal)
679 const ScDBCollection::NamedDBs& rDBs = rDoc.GetDBCollection()->getNamedDBs();
680 for (const auto& rxDB : rDBs)
682 const ScDBData& rDB = *rxDB;
683 if (!rDB.HasAutoFilter())
684 continue;
686 nRangeIndex = 0;
687 while (!bSubTotal && nRangeIndex < nRangeCount)
689 const ScRange & rRange = (*pRangeList)[nRangeIndex];
690 ScRange aDBArea;
691 rDB.GetArea(aDBArea);
692 if (aDBArea.Intersects(rRange))
693 bSubTotal = true;
694 ++nRangeIndex;
697 if (bSubTotal)
698 break;
701 return bSubTotal;
704 OUString ScTabViewShell::DoAutoSum(bool& rRangeFinder, bool& rSubTotal, const OpCode eCode)
706 OUString aFormula;
707 const ScMarkData& rMark = GetViewData().GetMarkData();
708 if ( rMark.IsMarked() || rMark.IsMultiMarked() )
710 ScRangeList aMarkRangeList;
711 rRangeFinder = rSubTotal = false;
712 rMark.FillRangeListWithMarks( &aMarkRangeList, false );
713 ScDocument& rDoc = GetViewData().GetDocument();
715 // check if one of the marked ranges is empty
716 bool bEmpty = false;
717 const size_t nCount = aMarkRangeList.size();
718 for ( size_t i = 0; i < nCount; ++i )
720 const ScRange & rRange( aMarkRangeList[i] );
721 if ( rDoc.IsBlockEmpty( rRange.aStart.Col(), rRange.aStart.Row(),
722 rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aStart.Tab() ) )
724 bEmpty = true;
725 break;
729 if ( bEmpty )
731 ScRangeList aRangeList;
732 const bool bDataFound = GetAutoSumArea( aRangeList );
733 if ( bDataFound )
735 ScAddress aAddr = aRangeList.back().aEnd;
736 aAddr.IncRow();
737 const bool bSubTotal( UseSubTotal( &aRangeList ) );
738 EnterAutoSum( aRangeList, bSubTotal, aAddr, eCode );
741 else
743 const bool bSubTotal( UseSubTotal( &aMarkRangeList ) );
744 for ( size_t i = 0; i < nCount; ++i )
746 const ScRange & rRange = aMarkRangeList[i];
747 const bool bSetCursor = ( i == nCount - 1 );
748 const bool bContinue = ( i != 0 );
749 if ( !AutoSum( rRange, bSubTotal, bSetCursor, bContinue, eCode ) )
751 MarkRange( rRange, false );
752 SetCursor( rRange.aEnd.Col(), rRange.aEnd.Row() );
753 const ScRangeList aRangeList;
754 ScAddress aAddr = rRange.aEnd;
755 aAddr.IncRow();
756 aFormula = GetAutoSumFormula( aRangeList, bSubTotal, aAddr , eCode);
757 break;
762 else // Only insert into input row
764 ScRangeList aRangeList;
765 rRangeFinder = GetAutoSumArea( aRangeList );
766 rSubTotal = UseSubTotal( &aRangeList );
767 ScAddress aAddr = GetViewData().GetCurPos();
768 aFormula = GetAutoSumFormula( aRangeList, rSubTotal, aAddr , eCode);
770 return aFormula;
773 void ScTabViewShell::InitFormEditData()
775 mpFormEditData.reset(new ScFormEditData);
778 void ScTabViewShell::ClearFormEditData()
780 mpFormEditData.reset();
783 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */