bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / view / tabvwshc.cxx
blobf8e7763d35adc7cbdf182338d5d4c96682c31700
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" // Core
42 #include "autofmt.hxx" // Dialog
43 #include "consdlg.hxx"
44 #include "filtdlg.hxx"
45 #include "dbnamdlg.hxx"
46 #if ! MPL_HAVE_SUBSET
47 # include "pvlaydlg.hxx"
48 #endif
49 #include "areasdlg.hxx"
50 #include "rangeutl.hxx"
51 #include "crnrdlg.hxx"
52 #include "formula.hxx"
53 #include "formulacell.hxx" // Input Status Edit-Zellen
54 #include "acredlin.hxx"
55 #include "highred.hxx"
56 #include "simpref.hxx"
57 #include "funcdesc.hxx"
58 #include "dpobject.hxx"
59 #include "markdata.hxx"
60 #include "reffact.hxx"
61 #include "condformatdlg.hxx"
62 #include "xmlsourcedlg.hxx"
64 //------------------------------------------------------------------
66 void ScTabViewShell::SetCurRefDlgId( sal_uInt16 nNew )
68 // CurRefDlgId is stored in ScModule to find if a ref dialog is open,
69 // and in the view to identify the view that has opened the dialog
70 nCurRefDlgId = nNew;
73 //ugly hack to call Define Name from Manage Names
74 void ScTabViewShell::SwitchBetweenRefDialogs(SfxModelessDialog* pDialog)
76 sal_uInt16 nSlotId = SC_MOD()->GetCurRefDlgId();
77 if (nSlotId == FID_DEFINE_NAME)
79 mbInSwitch = true;
80 static_cast<ScNameDlg*>(pDialog)->GetRangeNames(maRangeMap);
81 static_cast<ScNameDlg*>(pDialog)->Close();
82 sal_uInt16 nId = ScNameDefDlgWrapper::GetChildWindowId();
83 SfxViewFrame* pViewFrm = GetViewFrame();
84 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
86 SC_MOD()->SetRefDialog( nId, pWnd ? false : sal_True );
88 else if( nSlotId == FID_ADD_NAME )
90 static_cast<ScNameDefDlg*>(pDialog)->GetNewData(maName, maScope);
91 static_cast<ScNameDlg*>(pDialog)->Close();
92 sal_uInt16 nId = ScNameDlgWrapper::GetChildWindowId();
93 SfxViewFrame* pViewFrm = GetViewFrame();
94 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
96 SC_MOD()->SetRefDialog( nId, pWnd ? false : sal_True );
98 else
104 SfxModelessDialog* ScTabViewShell::CreateRefDialog(
105 SfxBindings* pB, SfxChildWindow* pCW, SfxChildWinInfo* pInfo,
106 Window* pParent, sal_uInt16 nSlotId )
108 // Dialog nur aufmachen, wenn ueber ScModule::SetRefDialog gerufen, damit
109 // z.B. nach einem Absturz offene Ref-Dialoge nicht wiederkommen (#42341#).
111 if ( SC_MOD()->GetCurRefDlgId() != nSlotId )
112 return NULL;
114 if ( nCurRefDlgId != nSlotId )
116 // the dialog has been opened in a different view
117 // -> lock the dispatcher for this view (modal mode)
119 GetViewData()->GetDispatcher().Lock( sal_True ); // lock is reset when closing dialog
120 return NULL;
123 SfxModelessDialog* pResult = 0;
125 if(pCW)
126 pCW->SetHideNotDelete(sal_True);
128 ScDocument* pDoc = GetViewData()->GetDocument();
130 switch( nSlotId )
132 case FID_DEFINE_NAME:
134 if (!mbInSwitch)
136 pResult = new ScNameDlg( pB, pCW, pParent, GetViewData(),
137 ScAddress( GetViewData()->GetCurX(),
138 GetViewData()->GetCurY(),
139 GetViewData()->GetTabNo() ) );
141 else
143 pResult = new ScNameDlg( pB, pCW, pParent, GetViewData(),
144 ScAddress( GetViewData()->GetCurX(),
145 GetViewData()->GetCurY(),
146 GetViewData()->GetTabNo() ), &maRangeMap);
147 static_cast<ScNameDlg*>(pResult)->SetEntry( maName, maScope);
148 mbInSwitch = false;
151 break;
153 case FID_ADD_NAME:
155 if (!mbInSwitch)
157 std::map<OUString, ScRangeName*> aRangeMap;
158 pDoc->GetRangeNameMap(aRangeMap);
159 pResult = new ScNameDefDlg( pB, pCW, pParent, GetViewData(), aRangeMap,
160 ScAddress( GetViewData()->GetCurX(),
161 GetViewData()->GetCurY(),
162 GetViewData()->GetTabNo() ), true );
164 else
166 std::map<OUString, ScRangeName*> aRangeMap;
167 for (boost::ptr_map<OUString, ScRangeName>::iterator itr = maRangeMap.begin();
168 itr != maRangeMap.end(); ++itr)
170 aRangeMap.insert(std::pair<OUString, ScRangeName*>(itr->first, itr->second));
172 pResult = new ScNameDefDlg( pB, pCW, pParent, GetViewData(), aRangeMap,
173 ScAddress( GetViewData()->GetCurX(),
174 GetViewData()->GetCurY(),
175 GetViewData()->GetTabNo() ), false );
178 break;
180 case SID_DEFINE_COLROWNAMERANGES:
182 pResult = new ScColRowNameRangesDlg( pB, pCW, pParent, GetViewData() );
184 break;
186 case SID_OPENDLG_CONSOLIDATE:
188 SfxItemSet aArgSet( GetPool(),
189 SCITEM_CONSOLIDATEDATA,
190 SCITEM_CONSOLIDATEDATA );
192 const ScConsolidateParam* pDlgData =
193 pDoc->GetConsolidateDlgData();
195 if ( !pDlgData )
197 ScConsolidateParam aConsParam;
198 SCCOL nStartCol, nEndCol;
199 SCROW nStartRow, nEndRow;
200 SCTAB nStartTab, nEndTab;
202 GetViewData()->GetSimpleArea( nStartCol, nStartRow, nStartTab,
203 nEndCol, nEndRow, nEndTab );
205 PutInOrder( nStartCol, nEndCol );
206 PutInOrder( nStartRow, nEndRow );
207 PutInOrder( nStartTab, nEndTab );
209 aConsParam.nCol = nStartCol;
210 aConsParam.nRow = nStartRow;
211 aConsParam.nTab = nStartTab;
213 aArgSet.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA,
214 &aConsParam ) );
216 else
218 aArgSet.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA, pDlgData ) );
220 pResult = new ScConsolidateDlg( pB, pCW, pParent, aArgSet );
222 break;
224 case SID_DEFINE_DBNAME:
226 // wenn auf einem bestehenden Bereich aufgerufen, den markieren
227 GetDBData( sal_True, SC_DB_OLD );
228 const ScMarkData& rMark = GetViewData()->GetMarkData();
229 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
230 MarkDataArea( false );
232 pResult = new ScDbNameDlg( pB, pCW, pParent, GetViewData() );
234 break;
236 case SID_SPECIAL_FILTER:
238 ScQueryParam aQueryParam;
239 SfxItemSet aArgSet( GetPool(),
240 SCITEM_QUERYDATA,
241 SCITEM_QUERYDATA );
243 ScDBData* pDBData = GetDBData(false, SC_DB_MAKE, SC_DBSEL_ROW_DOWN);
244 pDBData->ExtendDataArea(pDoc);
245 pDBData->GetQueryParam( aQueryParam );
247 ScRange aArea;
248 pDBData->GetArea(aArea);
249 MarkRange(aArea, false);
251 ScQueryItem aItem( SCITEM_QUERYDATA, GetViewData(), &aQueryParam );
252 ScRange aAdvSource;
253 if (pDBData->GetAdvancedQuerySource(aAdvSource))
254 aItem.SetAdvancedQuerySource( &aAdvSource );
256 aArgSet.Put( aItem );
258 // aktuelle Tabelle merken (wg. RefInput im Dialog)
259 GetViewData()->SetRefTabNo( GetViewData()->GetTabNo() );
261 pResult = new ScSpecialFilterDlg( pB, pCW, pParent, aArgSet );
263 break;
265 case SID_FILTER:
268 ScQueryParam aQueryParam;
269 SfxItemSet aArgSet( GetPool(),
270 SCITEM_QUERYDATA,
271 SCITEM_QUERYDATA );
273 ScDBData* pDBData = GetDBData(false, SC_DB_MAKE, SC_DBSEL_ROW_DOWN);
274 pDBData->ExtendDataArea(pDoc);
275 pDBData->GetQueryParam( aQueryParam );
277 ScRange aArea;
278 pDBData->GetArea(aArea);
279 MarkRange(aArea, false);
281 aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA,
282 GetViewData(),
283 &aQueryParam ) );
285 // aktuelle Tabelle merken (wg. RefInput im Dialog)
286 GetViewData()->SetRefTabNo( GetViewData()->GetTabNo() );
288 pResult = new ScFilterDlg( pB, pCW, pParent, aArgSet );
290 break;
292 case SID_OPENDLG_TABOP:
294 ScViewData* pViewData = GetViewData();
295 ScRefAddress aCurPos ( pViewData->GetCurX(),
296 pViewData->GetCurY(),
297 pViewData->GetTabNo(),
298 false, false, false );
300 pResult = new ScTabOpDlg( pB, pCW, pParent, pViewData->GetDocument(), aCurPos );
302 break;
304 case SID_OPENDLG_SOLVE:
306 ScViewData* pViewData = GetViewData();
307 ScAddress aCurPos( pViewData->GetCurX(),
308 pViewData->GetCurY(),
309 pViewData->GetTabNo());
310 pResult = new ScSolverDlg( pB, pCW, pParent, pViewData->GetDocument(), aCurPos );
312 break;
314 case SID_OPENDLG_OPTSOLVER:
316 ScViewData* pViewData = GetViewData();
317 ScAddress aCurPos( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo());
318 pResult = new ScOptSolverDlg( pB, pCW, pParent, pViewData->GetDocShell(), aCurPos );
320 break;
322 case SID_OPENDLG_PIVOTTABLE:
324 #if ! MPL_HAVE_SUBSET
325 // all settings must be in pDialogDPObject
327 if( pDialogDPObject )
329 // Check for an existing datapilot output.
330 ScViewData* pViewData = GetViewData();
331 ScDPObject* pObj = pDoc->GetDPAtCursor(
332 pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo());
334 GetViewData()->SetRefTabNo( GetViewData()->GetTabNo() );
335 pResult = new ScPivotLayoutDlg( pB, pCW, pParent, *pDialogDPObject, pObj == NULL);
337 #endif
339 break;
341 case SID_OPENDLG_EDIT_PRINTAREA:
343 pResult = new ScPrintAreasDlg( pB, pCW, pParent );
345 break;
347 case SID_OPENDLG_FUNCTION:
349 // Dialog schaut selber, was in der Zelle steht
351 pResult = new ScFormulaDlg( pB, pCW, pParent, GetViewData(),ScGlobal::GetStarCalcFunctionMgr() );
353 break;
355 case SID_MANAGE_XML_SOURCE:
357 pResult = new ScXMLSourceDlg(pB, pCW, pParent, pDoc);
359 break;
361 case FID_CHG_SHOW:
363 // Dialog schaut selber, was in der Zelle steht
365 pResult = new ScHighlightChgDlg( pB, pCW, pParent, GetViewData() );
367 break;
369 case WID_SIMPLE_REF:
371 // Dialog schaut selber, was in der Zelle steht
373 ScViewData* pViewData = GetViewData();
374 pViewData->SetRefTabNo( pViewData->GetTabNo() );
375 pResult = new ScSimpleRefDlg( pB, pCW, pParent, pViewData );
377 break;
380 default:
381 OSL_FAIL( "ScTabViewShell::CreateRefDialog: unbekannte ID" );
382 break;
385 if (pResult)
387 // Die Dialoge gehen immer mit eingeklapptem Zusaetze-Button auf,
388 // darum muss die Groesse ueber das Initialize gerettet werden
389 // (oder den Zusaetze-Status mit speichern !!!)
391 Size aSize = pResult->GetSizePixel();
392 pResult->Initialize( pInfo );
393 pResult->SetSizePixel(aSize);
396 return pResult;
401 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */