1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <config_mpl.h>
22 #include "scitems.hxx"
23 #include <vcl/msgbox.hxx>
24 #include <sfx2/childwin.hxx>
25 #include <sfx2/dispatch.hxx>
27 #include "tabvwsh.hxx"
29 #include "globstr.hrc"
33 #include "document.hxx"
34 #include "uiitems.hxx"
36 #include "namedlg.hxx"
37 #include "namedefdlg.hxx"
38 #include "solvrdlg.hxx"
39 #include "optsolver.hxx"
40 #include "tabopdlg.hxx"
41 #include "autoform.hxx"
42 #include "autofmt.hxx"
43 #include "consdlg.hxx"
44 #include "filtdlg.hxx"
45 #include "dbnamdlg.hxx"
46 #include "areasdlg.hxx"
47 #include "rangeutl.hxx"
48 #include "crnrdlg.hxx"
49 #include "formula.hxx"
50 #include "formulacell.hxx"
51 #include "acredlin.hxx"
52 #include "highred.hxx"
53 #include "simpref.hxx"
54 #include "funcdesc.hxx"
55 #include "dpobject.hxx"
56 #include "markdata.hxx"
57 #include "reffact.hxx"
58 #include "condformatdlg.hxx"
59 #include "xmlsourcedlg.hxx"
60 #include "condformatdlgitem.hxx"
62 #include "RandomNumberGeneratorDialog.hxx"
63 #include "SamplingDialog.hxx"
64 #include "DescriptiveStatisticsDialog.hxx"
65 #include "AnalysisOfVarianceDialog.hxx"
66 #include "CorrelationDialog.hxx"
67 #include "CovarianceDialog.hxx"
68 #include "ExponentialSmoothingDialog.hxx"
69 #include "MovingAverageDialog.hxx"
70 #include "RegressionDialog.hxx"
71 #include "TTestDialog.hxx"
72 #include "FTestDialog.hxx"
73 #include "ZTestDialog.hxx"
74 #include "ChiSquareTestDialog.hxx"
76 #include "PivotLayoutDialog.hxx"
78 #include <config_orcus.h>
80 void ScTabViewShell::SetCurRefDlgId( sal_uInt16 nNew
)
82 // CurRefDlgId is stored in ScModule to find if a ref dialog is open,
83 // and in the view to identify the view that has opened the dialog
87 //ugly hack to call Define Name from Manage Names
88 void ScTabViewShell::SwitchBetweenRefDialogs(SfxModelessDialog
* pDialog
)
90 sal_uInt16 nSlotId
= SC_MOD()->GetCurRefDlgId();
91 if (nSlotId
== FID_DEFINE_NAME
)
94 static_cast<ScNameDlg
*>(pDialog
)->GetRangeNames(m_RangeMap
);
95 static_cast<ScNameDlg
*>(pDialog
)->Close();
96 sal_uInt16 nId
= ScNameDefDlgWrapper::GetChildWindowId();
97 SfxViewFrame
* pViewFrm
= GetViewFrame();
98 SfxChildWindow
* pWnd
= pViewFrm
->GetChildWindow( nId
);
100 SC_MOD()->SetRefDialog( nId
, pWnd
== nullptr );
102 else if( nSlotId
== FID_ADD_NAME
)
104 static_cast<ScNameDefDlg
*>(pDialog
)->GetNewData(maName
, maScope
);
105 static_cast<ScNameDlg
*>(pDialog
)->Close();
106 sal_uInt16 nId
= ScNameDlgWrapper::GetChildWindowId();
107 SfxViewFrame
* pViewFrm
= GetViewFrame();
108 SfxChildWindow
* pWnd
= pViewFrm
->GetChildWindow( nId
);
110 SC_MOD()->SetRefDialog( nId
, pWnd
== nullptr );
118 VclPtr
<SfxModelessDialog
> ScTabViewShell::CreateRefDialog(
119 SfxBindings
* pB
, SfxChildWindow
* pCW
,
120 SfxChildWinInfo
* pInfo
,
121 vcl::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 ( SC_MOD()->GetCurRefDlgId() != nSlotId
)
129 if ( nCurRefDlgId
!= nSlotId
)
131 // the dialog has been opened in a different view
132 // -> lock the dispatcher for this view (modal mode)
134 GetViewData().GetDispatcher().Lock( true ); // lock is reset when closing dialog
138 VclPtr
<SfxModelessDialog
> pResult
;
141 pCW
->SetHideNotDelete(true);
143 ScDocument
* pDoc
= GetViewData().GetDocument();
147 case FID_DEFINE_NAME
:
151 pResult
= VclPtr
<ScNameDlg
>::Create( pB
, pCW
, pParent
, &GetViewData(),
152 ScAddress( GetViewData().GetCurX(),
153 GetViewData().GetCurY(),
154 GetViewData().GetTabNo() ) );
158 pResult
= VclPtr
<ScNameDlg
>::Create( pB
, pCW
, pParent
, &GetViewData(),
159 ScAddress( GetViewData().GetCurX(),
160 GetViewData().GetCurY(),
161 GetViewData().GetTabNo() ), &m_RangeMap
);
162 static_cast<ScNameDlg
*>(pResult
.get())->SetEntry( maName
, maScope
);
172 std::map
<OUString
, ScRangeName
*> aRangeMap
;
173 pDoc
->GetRangeNameMap(aRangeMap
);
174 pResult
= VclPtr
<ScNameDefDlg
>::Create( pB
, pCW
, pParent
, &GetViewData(), aRangeMap
,
175 ScAddress( GetViewData().GetCurX(),
176 GetViewData().GetCurY(),
177 GetViewData().GetTabNo() ), true );
181 std::map
<OUString
, ScRangeName
*> aRangeMap
;
182 for (auto const& itr
: m_RangeMap
)
184 aRangeMap
.insert(std::pair
<OUString
, ScRangeName
*>(itr
.first
, itr
.second
.get()));
186 pResult
= VclPtr
<ScNameDefDlg
>::Create( pB
, pCW
, pParent
, &GetViewData(), aRangeMap
,
187 ScAddress( GetViewData().GetCurX(),
188 GetViewData().GetCurY(),
189 GetViewData().GetTabNo() ), false );
194 case SID_DEFINE_COLROWNAMERANGES
:
196 pResult
= VclPtr
<ScColRowNameRangesDlg
>::Create( pB
, pCW
, pParent
, &GetViewData() );
200 case SID_OPENDLG_CONSOLIDATE
:
202 SfxItemSet
aArgSet( GetPool(),
203 SCITEM_CONSOLIDATEDATA
,
204 SCITEM_CONSOLIDATEDATA
);
206 const ScConsolidateParam
* pDlgData
=
207 pDoc
->GetConsolidateDlgData();
211 ScConsolidateParam aConsParam
;
212 SCCOL nStartCol
, nEndCol
;
213 SCROW nStartRow
, nEndRow
;
214 SCTAB nStartTab
, nEndTab
;
216 GetViewData().GetSimpleArea( nStartCol
, nStartRow
, nStartTab
,
217 nEndCol
, nEndRow
, nEndTab
);
219 PutInOrder( nStartCol
, nEndCol
);
220 PutInOrder( nStartRow
, nEndRow
);
221 PutInOrder( nStartTab
, nEndTab
);
223 aConsParam
.nCol
= nStartCol
;
224 aConsParam
.nRow
= nStartRow
;
225 aConsParam
.nTab
= nStartTab
;
227 aArgSet
.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA
,
232 aArgSet
.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA
, pDlgData
) );
234 pResult
= VclPtr
<ScConsolidateDlg
>::Create( pB
, pCW
, pParent
, aArgSet
);
238 case SID_DEFINE_DBNAME
:
240 // when called for an existing range, then mark
241 GetDBData( true, SC_DB_OLD
);
242 const ScMarkData
& rMark
= GetViewData().GetMarkData();
243 if ( !rMark
.IsMarked() && !rMark
.IsMultiMarked() )
244 MarkDataArea( false );
246 pResult
= VclPtr
<ScDbNameDlg
>::Create( pB
, pCW
, pParent
, &GetViewData() );
250 case SID_SPECIAL_FILTER
:
252 ScQueryParam aQueryParam
;
253 SfxItemSet
aArgSet( GetPool(),
257 ScDBData
* pDBData
= GetDBData(false, SC_DB_MAKE
, SC_DBSEL_ROW_DOWN
);
258 pDBData
->ExtendDataArea(pDoc
);
259 pDBData
->GetQueryParam( aQueryParam
);
262 pDBData
->GetArea(aArea
);
263 MarkRange(aArea
, false);
265 ScQueryItem
aItem( SCITEM_QUERYDATA
, &GetViewData(), &aQueryParam
);
267 if (pDBData
->GetAdvancedQuerySource(aAdvSource
))
268 aItem
.SetAdvancedQuerySource( &aAdvSource
);
270 aArgSet
.Put( aItem
);
272 // mark current sheet (due to RefInput in dialog)
273 GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
275 pResult
= VclPtr
<ScSpecialFilterDlg
>::Create( pB
, pCW
, pParent
, aArgSet
);
282 ScQueryParam aQueryParam
;
283 SfxItemSet
aArgSet( GetPool(),
287 ScDBData
* pDBData
= GetDBData(false, SC_DB_MAKE
, SC_DBSEL_ROW_DOWN
);
288 pDBData
->ExtendDataArea(pDoc
);
289 pDBData
->GetQueryParam( aQueryParam
);
292 pDBData
->GetArea(aArea
);
293 MarkRange(aArea
, false);
295 aArgSet
.Put( ScQueryItem( SCITEM_QUERYDATA
,
299 // mark current sheet (due to RefInput in dialog)
300 GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
302 pResult
= VclPtr
<ScFilterDlg
>::Create( pB
, pCW
, pParent
, aArgSet
);
306 case SID_OPENDLG_TABOP
:
308 ScViewData
& rViewData
= GetViewData();
309 ScRefAddress
aCurPos ( rViewData
.GetCurX(),
311 rViewData
.GetTabNo(),
312 false, false, false );
314 pResult
= VclPtr
<ScTabOpDlg
>::Create( pB
, pCW
, pParent
, rViewData
.GetDocument(), aCurPos
);
318 case SID_OPENDLG_SOLVE
:
320 ScViewData
& rViewData
= GetViewData();
321 ScAddress
aCurPos( rViewData
.GetCurX(),
323 rViewData
.GetTabNo());
324 pResult
= VclPtr
<ScSolverDlg
>::Create( pB
, pCW
, pParent
, rViewData
.GetDocument(), aCurPos
);
328 case SID_RANDOM_NUMBER_GENERATOR_DIALOG
:
330 pResult
= VclPtr
<ScRandomNumberGeneratorDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
334 case SID_SAMPLING_DIALOG
:
336 pResult
= VclPtr
<ScSamplingDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
340 case SID_DESCRIPTIVE_STATISTICS_DIALOG
:
342 pResult
= VclPtr
<ScDescriptiveStatisticsDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
346 case SID_ANALYSIS_OF_VARIANCE_DIALOG
:
348 pResult
= VclPtr
<ScAnalysisOfVarianceDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
352 case SID_CORRELATION_DIALOG
:
354 pResult
= VclPtr
<ScCorrelationDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
358 case SID_COVARIANCE_DIALOG
:
360 pResult
= VclPtr
<ScCovarianceDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
364 case SID_EXPONENTIAL_SMOOTHING_DIALOG
:
366 pResult
= VclPtr
<ScExponentialSmoothingDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
370 case SID_MOVING_AVERAGE_DIALOG
:
372 pResult
= VclPtr
<ScMovingAverageDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
376 case SID_REGRESSION_DIALOG
:
378 pResult
= VclPtr
<ScRegressionDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
382 case SID_TTEST_DIALOG
:
384 pResult
= VclPtr
<ScTTestDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
388 case SID_FTEST_DIALOG
:
390 pResult
= VclPtr
<ScFTestDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
394 case SID_ZTEST_DIALOG
:
396 pResult
= VclPtr
<ScZTestDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
400 case SID_CHI_SQUARE_TEST_DIALOG
:
402 pResult
= VclPtr
<ScChiSquareTestDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
406 case SID_OPENDLG_OPTSOLVER
:
408 ScViewData
& rViewData
= GetViewData();
409 ScAddress
aCurPos( rViewData
.GetCurX(), rViewData
.GetCurY(), rViewData
.GetTabNo());
410 pResult
= VclPtr
<ScOptSolverDlg
>::Create( pB
, pCW
, pParent
, rViewData
.GetDocShell(), aCurPos
);
414 case SID_OPENDLG_PIVOTTABLE
:
416 // all settings must be in pDialogDPObject
418 if( pDialogDPObject
)
420 // Check for an existing datapilot output.
421 ScViewData
& rViewData
= GetViewData();
422 rViewData
.SetRefTabNo( rViewData
.GetTabNo() );
423 ScDPObject
* pObj
= pDoc
->GetDPAtCursor(rViewData
.GetCurX(), rViewData
.GetCurY(), rViewData
.GetTabNo());
424 pResult
= VclPtr
<ScPivotLayoutDialog
>::Create(pB
, pCW
, pParent
, &rViewData
, pDialogDPObject
, pObj
== nullptr);
429 case SID_OPENDLG_EDIT_PRINTAREA
:
431 pResult
= VclPtr
<ScPrintAreasDlg
>::Create( pB
, pCW
, pParent
);
435 case SID_OPENDLG_FUNCTION
:
437 // dialog checks, what is in the cell
439 pResult
= VclPtr
<ScFormulaDlg
>::Create( pB
, pCW
, pParent
, &GetViewData(),ScGlobal::GetStarCalcFunctionMgr() );
443 case SID_MANAGE_XML_SOURCE
:
446 pResult
= VclPtr
<ScXMLSourceDlg
>::Create(pB
, pCW
, pParent
, pDoc
);
453 // dialog checks, what is in the cell
455 pResult
= VclPtr
<ScHighlightChgDlg
>::Create( pB
, pCW
, pParent
, &GetViewData() );
461 // dialog checks, what is in the cell
463 ScViewData
& rViewData
= GetViewData();
464 rViewData
.SetRefTabNo( rViewData
.GetTabNo() );
465 pResult
= VclPtr
<ScSimpleRefDlg
>::Create( pB
, pCW
, pParent
);
469 case WID_CONDFRMT_REF
:
472 const ScCondFormatDlgItem
* pDlgItem
= nullptr;
473 // Get the pool item stored by Conditional Format Manager Dialog.
474 const SfxPoolItem
* pItem
= nullptr;
475 sal_uInt32
nItems(GetPool().GetItemCount2( SCITEM_CONDFORMATDLGDATA
));
476 for( sal_uInt32 nIter
= 0; nIter
< nItems
; ++nIter
)
478 if( nullptr != (pItem
= GetPool().GetItem2( SCITEM_CONDFORMATDLGDATA
, nIter
) ) )
480 pDlgItem
= static_cast<const ScCondFormatDlgItem
*>(pItem
);
486 ScViewData
& rViewData
= GetViewData();
487 rViewData
.SetRefTabNo( rViewData
.GetTabNo() );
489 pResult
= VclPtr
<ScCondFormatDlg
>::Create( pB
, pCW
, pParent
, &rViewData
, pDlgItem
);
491 // Remove the pool item stored by Conditional Format Manager Dialog.
492 if ( bFound
&& pItem
)
493 GetPool().Remove( *pItem
);
500 // the dialogs are always displayed with the option button collapsed,
501 // the size has to be carried over initialize
502 // (or store the option status !!!)
504 Size aSize
= pResult
->GetSizePixel();
505 pResult
->Initialize( pInfo
);
506 pResult
->SetSizePixel(aSize
);
512 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */