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