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