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"
61 #include "RandomNumberGeneratorDialog.hxx"
62 #include "SamplingDialog.hxx"
63 #include "DescriptiveStatisticsDialog.hxx"
64 #include "AnalysisOfVarianceDialog.hxx"
65 #include "CorrelationDialog.hxx"
66 #include "CovarianceDialog.hxx"
67 #include "ExponentialSmoothingDialog.hxx"
68 #include "MovingAverageDialog.hxx"
69 #include "TTestDialog.hxx"
70 #include "FTestDialog.hxx"
71 #include "ZTestDialog.hxx"
72 #include "ChiSquareTestDialog.hxx"
74 #include "PivotLayoutDialog.hxx"
76 #include <config_orcus.h>
78 void ScTabViewShell::SetCurRefDlgId( sal_uInt16 nNew
)
80 // CurRefDlgId is stored in ScModule to find if a ref dialog is open,
81 // and in the view to identify the view that has opened the dialog
85 //ugly hack to call Define Name from Manage Names
86 void ScTabViewShell::SwitchBetweenRefDialogs(SfxModelessDialog
* pDialog
)
88 sal_uInt16 nSlotId
= SC_MOD()->GetCurRefDlgId();
89 if (nSlotId
== FID_DEFINE_NAME
)
92 static_cast<ScNameDlg
*>(pDialog
)->GetRangeNames(maRangeMap
);
93 static_cast<ScNameDlg
*>(pDialog
)->Close();
94 sal_uInt16 nId
= ScNameDefDlgWrapper::GetChildWindowId();
95 SfxViewFrame
* pViewFrm
= GetViewFrame();
96 SfxChildWindow
* pWnd
= pViewFrm
->GetChildWindow( nId
);
98 SC_MOD()->SetRefDialog( nId
, pWnd
== nullptr );
100 else if( nSlotId
== FID_ADD_NAME
)
102 static_cast<ScNameDefDlg
*>(pDialog
)->GetNewData(maName
, maScope
);
103 static_cast<ScNameDlg
*>(pDialog
)->Close();
104 sal_uInt16 nId
= ScNameDlgWrapper::GetChildWindowId();
105 SfxViewFrame
* pViewFrm
= GetViewFrame();
106 SfxChildWindow
* pWnd
= pViewFrm
->GetChildWindow( nId
);
108 SC_MOD()->SetRefDialog( nId
, pWnd
== nullptr );
116 VclPtr
<SfxModelessDialog
> ScTabViewShell::CreateRefDialog(
117 SfxBindings
* pB
, SfxChildWindow
* pCW
,
118 SfxChildWinInfo
* pInfo
,
119 vcl::Window
* pParent
, sal_uInt16 nSlotId
)
121 // Dialog nur aufmachen, wenn ueber ScModule::SetRefDialog gerufen, damit
122 // z.B. nach einem Absturz offene Ref-Dialoge nicht wiederkommen (#42341#).
124 if ( SC_MOD()->GetCurRefDlgId() != nSlotId
)
127 if ( nCurRefDlgId
!= nSlotId
)
129 // the dialog has been opened in a different view
130 // -> lock the dispatcher for this view (modal mode)
132 GetViewData().GetDispatcher().Lock( true ); // lock is reset when closing dialog
136 VclPtr
<SfxModelessDialog
> pResult
;
139 pCW
->SetHideNotDelete(true);
141 ScDocument
* pDoc
= GetViewData().GetDocument();
145 case FID_DEFINE_NAME
:
149 pResult
= VclPtr
<ScNameDlg
>::Create( pB
, pCW
, pParent
, &GetViewData(),
150 ScAddress( GetViewData().GetCurX(),
151 GetViewData().GetCurY(),
152 GetViewData().GetTabNo() ) );
156 pResult
= VclPtr
<ScNameDlg
>::Create( pB
, pCW
, pParent
, &GetViewData(),
157 ScAddress( GetViewData().GetCurX(),
158 GetViewData().GetCurY(),
159 GetViewData().GetTabNo() ), &maRangeMap
);
160 static_cast<ScNameDlg
*>(pResult
.get())->SetEntry( maName
, maScope
);
170 std::map
<OUString
, ScRangeName
*> aRangeMap
;
171 pDoc
->GetRangeNameMap(aRangeMap
);
172 pResult
= VclPtr
<ScNameDefDlg
>::Create( pB
, pCW
, pParent
, &GetViewData(), aRangeMap
,
173 ScAddress( GetViewData().GetCurX(),
174 GetViewData().GetCurY(),
175 GetViewData().GetTabNo() ), true );
179 std::map
<OUString
, ScRangeName
*> aRangeMap
;
180 for (boost::ptr_map
<OUString
, ScRangeName
>::iterator itr
= maRangeMap
.begin();
181 itr
!= maRangeMap
.end(); ++itr
)
183 aRangeMap
.insert(std::pair
<OUString
, ScRangeName
*>(itr
->first
, itr
->second
));
185 pResult
= VclPtr
<ScNameDefDlg
>::Create( pB
, pCW
, pParent
, &GetViewData(), aRangeMap
,
186 ScAddress( GetViewData().GetCurX(),
187 GetViewData().GetCurY(),
188 GetViewData().GetTabNo() ), false );
193 case SID_DEFINE_COLROWNAMERANGES
:
195 pResult
= VclPtr
<ScColRowNameRangesDlg
>::Create( pB
, pCW
, pParent
, &GetViewData() );
199 case SID_OPENDLG_CONSOLIDATE
:
201 SfxItemSet
aArgSet( GetPool(),
202 SCITEM_CONSOLIDATEDATA
,
203 SCITEM_CONSOLIDATEDATA
);
205 const ScConsolidateParam
* pDlgData
=
206 pDoc
->GetConsolidateDlgData();
210 ScConsolidateParam aConsParam
;
211 SCCOL nStartCol
, nEndCol
;
212 SCROW nStartRow
, nEndRow
;
213 SCTAB nStartTab
, nEndTab
;
215 GetViewData().GetSimpleArea( nStartCol
, nStartRow
, nStartTab
,
216 nEndCol
, nEndRow
, nEndTab
);
218 PutInOrder( nStartCol
, nEndCol
);
219 PutInOrder( nStartRow
, nEndRow
);
220 PutInOrder( nStartTab
, nEndTab
);
222 aConsParam
.nCol
= nStartCol
;
223 aConsParam
.nRow
= nStartRow
;
224 aConsParam
.nTab
= nStartTab
;
226 aArgSet
.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA
,
231 aArgSet
.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA
, pDlgData
) );
233 pResult
= VclPtr
<ScConsolidateDlg
>::Create( pB
, pCW
, pParent
, aArgSet
);
237 case SID_DEFINE_DBNAME
:
239 // wenn auf einem bestehenden Bereich aufgerufen, den markieren
240 GetDBData( true, SC_DB_OLD
);
241 const ScMarkData
& rMark
= GetViewData().GetMarkData();
242 if ( !rMark
.IsMarked() && !rMark
.IsMultiMarked() )
243 MarkDataArea( false );
245 pResult
= VclPtr
<ScDbNameDlg
>::Create( pB
, pCW
, pParent
, &GetViewData() );
249 case SID_SPECIAL_FILTER
:
251 ScQueryParam aQueryParam
;
252 SfxItemSet
aArgSet( GetPool(),
256 ScDBData
* pDBData
= GetDBData(false, SC_DB_MAKE
, SC_DBSEL_ROW_DOWN
);
257 pDBData
->ExtendDataArea(pDoc
);
258 pDBData
->GetQueryParam( aQueryParam
);
261 pDBData
->GetArea(aArea
);
262 MarkRange(aArea
, false);
264 ScQueryItem
aItem( SCITEM_QUERYDATA
, &GetViewData(), &aQueryParam
);
266 if (pDBData
->GetAdvancedQuerySource(aAdvSource
))
267 aItem
.SetAdvancedQuerySource( &aAdvSource
);
269 aArgSet
.Put( aItem
);
271 // aktuelle Tabelle merken (wg. RefInput im Dialog)
272 GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
274 pResult
= VclPtr
<ScSpecialFilterDlg
>::Create( pB
, pCW
, pParent
, aArgSet
);
281 ScQueryParam aQueryParam
;
282 SfxItemSet
aArgSet( GetPool(),
286 ScDBData
* pDBData
= GetDBData(false, SC_DB_MAKE
, SC_DBSEL_ROW_DOWN
);
287 pDBData
->ExtendDataArea(pDoc
);
288 pDBData
->GetQueryParam( aQueryParam
);
291 pDBData
->GetArea(aArea
);
292 MarkRange(aArea
, false);
294 aArgSet
.Put( ScQueryItem( SCITEM_QUERYDATA
,
298 // aktuelle Tabelle merken (wg. RefInput im Dialog)
299 GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
301 pResult
= VclPtr
<ScFilterDlg
>::Create( pB
, pCW
, pParent
, aArgSet
);
305 case SID_OPENDLG_TABOP
:
307 ScViewData
& rViewData
= GetViewData();
308 ScRefAddress
aCurPos ( rViewData
.GetCurX(),
310 rViewData
.GetTabNo(),
311 false, false, false );
313 pResult
= VclPtr
<ScTabOpDlg
>::Create( pB
, pCW
, pParent
, rViewData
.GetDocument(), aCurPos
);
317 case SID_OPENDLG_SOLVE
:
319 ScViewData
& rViewData
= GetViewData();
320 ScAddress
aCurPos( rViewData
.GetCurX(),
322 rViewData
.GetTabNo());
323 pResult
= VclPtr
<ScSolverDlg
>::Create( pB
, pCW
, pParent
, rViewData
.GetDocument(), aCurPos
);
327 case SID_RANDOM_NUMBER_GENERATOR_DIALOG
:
329 pResult
= VclPtr
<ScRandomNumberGeneratorDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
333 case SID_SAMPLING_DIALOG
:
335 pResult
= VclPtr
<ScSamplingDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
339 case SID_DESCRIPTIVE_STATISTICS_DIALOG
:
341 pResult
= VclPtr
<ScDescriptiveStatisticsDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
345 case SID_ANALYSIS_OF_VARIANCE_DIALOG
:
347 pResult
= VclPtr
<ScAnalysisOfVarianceDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
351 case SID_CORRELATION_DIALOG
:
353 pResult
= VclPtr
<ScCorrelationDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
357 case SID_COVARIANCE_DIALOG
:
359 pResult
= VclPtr
<ScCovarianceDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
363 case SID_EXPONENTIAL_SMOOTHING_DIALOG
:
365 pResult
= VclPtr
<ScExponentialSmoothingDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
369 case SID_MOVING_AVERAGE_DIALOG
:
371 pResult
= VclPtr
<ScMovingAverageDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
375 case SID_TTEST_DIALOG
:
377 pResult
= VclPtr
<ScTTestDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
381 case SID_FTEST_DIALOG
:
383 pResult
= VclPtr
<ScFTestDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
387 case SID_ZTEST_DIALOG
:
389 pResult
= VclPtr
<ScZTestDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
393 case SID_CHI_SQUARE_TEST_DIALOG
:
395 pResult
= VclPtr
<ScChiSquareTestDialog
>::Create( pB
, pCW
, pParent
, &GetViewData() );
399 case SID_OPENDLG_OPTSOLVER
:
401 ScViewData
& rViewData
= GetViewData();
402 ScAddress
aCurPos( rViewData
.GetCurX(), rViewData
.GetCurY(), rViewData
.GetTabNo());
403 pResult
= VclPtr
<ScOptSolverDlg
>::Create( pB
, pCW
, pParent
, rViewData
.GetDocShell(), aCurPos
);
407 case SID_OPENDLG_PIVOTTABLE
:
409 // all settings must be in pDialogDPObject
411 if( pDialogDPObject
)
413 // Check for an existing datapilot output.
414 ScViewData
& rViewData
= GetViewData();
415 rViewData
.SetRefTabNo( rViewData
.GetTabNo() );
416 ScDPObject
* pObj
= pDoc
->GetDPAtCursor(rViewData
.GetCurX(), rViewData
.GetCurY(), rViewData
.GetTabNo());
417 pResult
= VclPtr
<ScPivotLayoutDialog
>::Create(pB
, pCW
, pParent
, &rViewData
, pDialogDPObject
, pObj
== nullptr);
422 case SID_OPENDLG_EDIT_PRINTAREA
:
424 pResult
= VclPtr
<ScPrintAreasDlg
>::Create( pB
, pCW
, pParent
);
428 case SID_OPENDLG_FUNCTION
:
430 // Dialog schaut selber, was in der Zelle steht
432 pResult
= VclPtr
<ScFormulaDlg
>::Create( pB
, pCW
, pParent
, &GetViewData(),ScGlobal::GetStarCalcFunctionMgr() );
436 case SID_MANAGE_XML_SOURCE
:
439 pResult
= VclPtr
<ScXMLSourceDlg
>::Create(pB
, pCW
, pParent
, pDoc
);
446 // Dialog schaut selber, was in der Zelle steht
448 pResult
= VclPtr
<ScHighlightChgDlg
>::Create( pB
, pCW
, pParent
, &GetViewData() );
454 // Dialog schaut selber, was in der Zelle steht
456 ScViewData
& rViewData
= GetViewData();
457 rViewData
.SetRefTabNo( rViewData
.GetTabNo() );
458 pResult
= VclPtr
<ScSimpleRefDlg
>::Create( pB
, pCW
, pParent
);
462 case WID_CONDFRMT_REF
:
464 sal_uInt32 nIndex
= sal_uInt32(-1);
466 bool bManaged
= false;
469 ScRangeList aRangeList
;
470 ScConditionalFormat
* pCondFormat
;
471 condformat::dialog::ScCondFormatDialogType aDialogType
;
473 // Get the pool item stored it by Conditional Format Manager Dialog.
474 const SfxPoolItem
* pItem
= NULL
;
475 sal_uInt32
nItems(GetPool().GetItemCount2( SCITEM_STRING
));
476 for( sal_uInt32 nIter
= 0; nIter
< nItems
; ++nIter
)
478 if( NULL
!= (pItem
= GetPool().GetItem2( SCITEM_STRING
, nIter
) ) )
480 if ( ScCondFormatDlg::ParseXmlString(
481 static_cast<const SfxStringItem
*>(pItem
)->GetValue(),
482 nIndex
, nType
, bManaged
))
490 ScViewData
& rViewData
= GetViewData();
491 rViewData
.SetRefTabNo( rViewData
.GetTabNo() );
493 aDialogType
= static_cast< condformat::dialog::ScCondFormatDialogType
> ( nType
);
494 pCondFormat
= pDoc
->GetCondFormList(rViewData
.GetTabNo())->GetFormat ( nIndex
);
497 aRangeList
= pCondFormat
->GetRange();
500 rViewData
.GetMarkData().FillRangeListWithMarks(&aRangeList
, false);
501 ScAddress
aPos(rViewData
.GetCurX(), rViewData
.GetCurY(), rViewData
.GetTabNo());
502 if(aRangeList
.empty())
504 ScRange
* pRange
= new ScRange(aPos
);
505 aRangeList
.push_back(pRange
);
509 pResult
= VclPtr
<ScCondFormatDlg
>::Create( pB
, pCW
, pParent
, &rViewData
, pCondFormat
, aRangeList
,
510 aRangeList
.GetTopLeftCorner(), aDialogType
, bManaged
);
512 // Remove the pool item stored it by Conditional Format Manager Dialog.
513 if ( bFound
&& pItem
)
514 GetPool().Remove( *pItem
);
521 // Die Dialoge gehen immer mit eingeklapptem Zusaetze-Button auf,
522 // darum muss die Groesse ueber das Initialize gerettet werden
523 // (oder den Zusaetze-Status mit speichern !!!)
525 Size aSize
= pResult
->GetSizePixel();
526 pResult
->Initialize( pInfo
);
527 pResult
->SetSizePixel(aSize
);
533 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */