Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / view / tabvwshc.cxx
blob5b4b073e1ce6ece65f8b32796e7c0d4e35734484
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 <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"
28 #include "sc.hrc"
29 #include "globstr.hrc"
30 #include "global.hxx"
31 #include "scmod.hxx"
32 #include "docsh.hxx"
33 #include "document.hxx"
34 #include "uiitems.hxx"
35 #include "pivot.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
84 nCurRefDlgId = nNew;
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)
93 mbInSwitch = true;
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 );
112 else
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 )
127 return nullptr;
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
135 return nullptr;
138 VclPtr<SfxModelessDialog> pResult;
140 if(pCW)
141 pCW->SetHideNotDelete(true);
143 ScDocument* pDoc = GetViewData().GetDocument();
145 switch( nSlotId )
147 case FID_DEFINE_NAME:
149 if (!mbInSwitch)
151 pResult = VclPtr<ScNameDlg>::Create( pB, pCW, pParent, &GetViewData(),
152 ScAddress( GetViewData().GetCurX(),
153 GetViewData().GetCurY(),
154 GetViewData().GetTabNo() ) );
156 else
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);
163 mbInSwitch = false;
166 break;
168 case FID_ADD_NAME:
170 if (!mbInSwitch)
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 );
179 else
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 );
192 break;
194 case SID_DEFINE_COLROWNAMERANGES:
196 pResult = VclPtr<ScColRowNameRangesDlg>::Create( pB, pCW, pParent, &GetViewData() );
198 break;
200 case SID_OPENDLG_CONSOLIDATE:
202 SfxItemSet aArgSet( GetPool(),
203 SCITEM_CONSOLIDATEDATA,
204 SCITEM_CONSOLIDATEDATA );
206 const ScConsolidateParam* pDlgData =
207 pDoc->GetConsolidateDlgData();
209 if ( !pDlgData )
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,
228 &aConsParam ) );
230 else
232 aArgSet.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA, pDlgData ) );
234 pResult = VclPtr<ScConsolidateDlg>::Create( pB, pCW, pParent, aArgSet );
236 break;
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() );
248 break;
250 case SID_SPECIAL_FILTER:
252 ScQueryParam aQueryParam;
253 SfxItemSet aArgSet( GetPool(),
254 SCITEM_QUERYDATA,
255 SCITEM_QUERYDATA );
257 ScDBData* pDBData = GetDBData(false, SC_DB_MAKE, SC_DBSEL_ROW_DOWN);
258 pDBData->ExtendDataArea(pDoc);
259 pDBData->GetQueryParam( aQueryParam );
261 ScRange aArea;
262 pDBData->GetArea(aArea);
263 MarkRange(aArea, false);
265 ScQueryItem aItem( SCITEM_QUERYDATA, &GetViewData(), &aQueryParam );
266 ScRange aAdvSource;
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 );
277 break;
279 case SID_FILTER:
282 ScQueryParam aQueryParam;
283 SfxItemSet aArgSet( GetPool(),
284 SCITEM_QUERYDATA,
285 SCITEM_QUERYDATA );
287 ScDBData* pDBData = GetDBData(false, SC_DB_MAKE, SC_DBSEL_ROW_DOWN);
288 pDBData->ExtendDataArea(pDoc);
289 pDBData->GetQueryParam( aQueryParam );
291 ScRange aArea;
292 pDBData->GetArea(aArea);
293 MarkRange(aArea, false);
295 aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA,
296 &GetViewData(),
297 &aQueryParam ) );
299 // mark current sheet (due to RefInput in dialog)
300 GetViewData().SetRefTabNo( GetViewData().GetTabNo() );
302 pResult = VclPtr<ScFilterDlg>::Create( pB, pCW, pParent, aArgSet );
304 break;
306 case SID_OPENDLG_TABOP:
308 ScViewData& rViewData = GetViewData();
309 ScRefAddress aCurPos ( rViewData.GetCurX(),
310 rViewData.GetCurY(),
311 rViewData.GetTabNo(),
312 false, false, false );
314 pResult = VclPtr<ScTabOpDlg>::Create( pB, pCW, pParent, rViewData.GetDocument(), aCurPos );
316 break;
318 case SID_OPENDLG_SOLVE:
320 ScViewData& rViewData = GetViewData();
321 ScAddress aCurPos( rViewData.GetCurX(),
322 rViewData.GetCurY(),
323 rViewData.GetTabNo());
324 pResult = VclPtr<ScSolverDlg>::Create( pB, pCW, pParent, rViewData.GetDocument(), aCurPos );
326 break;
328 case SID_RANDOM_NUMBER_GENERATOR_DIALOG:
330 pResult = VclPtr<ScRandomNumberGeneratorDialog>::Create( pB, pCW, pParent, &GetViewData() );
332 break;
334 case SID_SAMPLING_DIALOG:
336 pResult = VclPtr<ScSamplingDialog>::Create( pB, pCW, pParent, &GetViewData() );
338 break;
340 case SID_DESCRIPTIVE_STATISTICS_DIALOG:
342 pResult = VclPtr<ScDescriptiveStatisticsDialog>::Create( pB, pCW, pParent, &GetViewData() );
344 break;
346 case SID_ANALYSIS_OF_VARIANCE_DIALOG:
348 pResult = VclPtr<ScAnalysisOfVarianceDialog>::Create( pB, pCW, pParent, &GetViewData() );
350 break;
352 case SID_CORRELATION_DIALOG:
354 pResult = VclPtr<ScCorrelationDialog>::Create( pB, pCW, pParent, &GetViewData() );
356 break;
358 case SID_COVARIANCE_DIALOG:
360 pResult = VclPtr<ScCovarianceDialog>::Create( pB, pCW, pParent, &GetViewData() );
362 break;
364 case SID_EXPONENTIAL_SMOOTHING_DIALOG:
366 pResult = VclPtr<ScExponentialSmoothingDialog>::Create( pB, pCW, pParent, &GetViewData() );
368 break;
370 case SID_MOVING_AVERAGE_DIALOG:
372 pResult = VclPtr<ScMovingAverageDialog>::Create( pB, pCW, pParent, &GetViewData() );
374 break;
376 case SID_REGRESSION_DIALOG:
378 pResult = VclPtr<ScRegressionDialog>::Create( pB, pCW, pParent, &GetViewData() );
380 break;
382 case SID_TTEST_DIALOG:
384 pResult = VclPtr<ScTTestDialog>::Create( pB, pCW, pParent, &GetViewData() );
386 break;
388 case SID_FTEST_DIALOG:
390 pResult = VclPtr<ScFTestDialog>::Create( pB, pCW, pParent, &GetViewData() );
392 break;
394 case SID_ZTEST_DIALOG:
396 pResult = VclPtr<ScZTestDialog>::Create( pB, pCW, pParent, &GetViewData() );
398 break;
400 case SID_CHI_SQUARE_TEST_DIALOG:
402 pResult = VclPtr<ScChiSquareTestDialog>::Create( pB, pCW, pParent, &GetViewData() );
404 break;
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 );
412 break;
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);
427 break;
429 case SID_OPENDLG_EDIT_PRINTAREA:
431 pResult = VclPtr<ScPrintAreasDlg>::Create( pB, pCW, pParent );
433 break;
435 case SID_OPENDLG_FUNCTION:
437 // dialog checks, what is in the cell
439 pResult = VclPtr<ScFormulaDlg>::Create( pB, pCW, pParent, &GetViewData(),ScGlobal::GetStarCalcFunctionMgr() );
441 break;
443 case SID_MANAGE_XML_SOURCE:
445 #if ENABLE_ORCUS
446 pResult = VclPtr<ScXMLSourceDlg>::Create(pB, pCW, pParent, pDoc);
447 #endif
449 break;
451 case FID_CHG_SHOW:
453 // dialog checks, what is in the cell
455 pResult = VclPtr<ScHighlightChgDlg>::Create( pB, pCW, pParent, &GetViewData() );
457 break;
459 case WID_SIMPLE_REF:
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 );
467 break;
469 case WID_CONDFRMT_REF:
471 bool bFound = false;
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);
481 bFound = true;
482 break;
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 );
495 break;
498 if (pResult)
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);
509 return pResult;
512 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */