Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / sc / source / ui / view / tabvwshc.cxx
blob857294ad4796caa91e5662e2ed27f2628a1b9dcb
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 "scitems.hxx"
21 #include <vcl/msgbox.hxx>
22 #include <sfx2/childwin.hxx>
23 #include <sfx2/dispatch.hxx>
25 #include "tabvwsh.hxx"
26 #include "sc.hrc"
27 #include "globstr.hrc"
28 #include "global.hxx"
29 #include "scmod.hxx"
30 #include "docsh.hxx"
31 #include "document.hxx"
32 #include "uiitems.hxx"
33 #include "pivot.hxx"
34 #include "namedlg.hxx"
35 #include "namedefdlg.hxx"
36 #include "solvrdlg.hxx"
37 #include "optsolver.hxx"
38 #include "tabopdlg.hxx"
39 #include "autoform.hxx" // Core
40 #include "autofmt.hxx" // Dialog
41 #include "consdlg.hxx"
42 #include "filtdlg.hxx"
43 #include "dbnamdlg.hxx"
44 #include "pvlaydlg.hxx"
45 #include "areasdlg.hxx"
46 #include "rangeutl.hxx"
47 #include "crnrdlg.hxx"
48 #include "formula.hxx"
49 #include "cell.hxx" // Input Status Edit-Zellen
50 #include "acredlin.hxx"
51 #include "highred.hxx"
52 #include "simpref.hxx"
53 #include "funcdesc.hxx"
54 #include "dpobject.hxx"
55 #include "markdata.hxx"
56 #include "reffact.hxx"
57 #include "condformatdlg.hxx"
58 #include "xmlsourcedlg.hxx"
60 //------------------------------------------------------------------
62 void ScTabViewShell::SetCurRefDlgId( sal_uInt16 nNew )
64 // CurRefDlgId is stored in ScModule to find if a ref dialog is open,
65 // and in the view to identify the view that has opened the dialog
66 nCurRefDlgId = nNew;
69 //ugly hack to call Define Name from Manage Names
70 void ScTabViewShell::SwitchBetweenRefDialogs(SfxModelessDialog* pDialog)
72 sal_uInt16 nSlotId = SC_MOD()->GetCurRefDlgId();
73 if (nSlotId == FID_DEFINE_NAME)
75 mbInSwitch = true;
76 static_cast<ScNameDlg*>(pDialog)->GetRangeNames(maRangeMap);
77 static_cast<ScNameDlg*>(pDialog)->Close();
78 sal_uInt16 nId = ScNameDefDlgWrapper::GetChildWindowId();
79 SfxViewFrame* pViewFrm = GetViewFrame();
80 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
82 SC_MOD()->SetRefDialog( nId, pWnd ? false : sal_True );
84 else if( nSlotId == FID_ADD_NAME )
86 static_cast<ScNameDefDlg*>(pDialog)->GetNewData(maName, maScope);
87 static_cast<ScNameDlg*>(pDialog)->Close();
88 sal_uInt16 nId = ScNameDlgWrapper::GetChildWindowId();
89 SfxViewFrame* pViewFrm = GetViewFrame();
90 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
92 SC_MOD()->SetRefDialog( nId, pWnd ? false : sal_True );
94 else
100 SfxModelessDialog* ScTabViewShell::CreateRefDialog(
101 SfxBindings* pB, SfxChildWindow* pCW, SfxChildWinInfo* pInfo,
102 Window* pParent, sal_uInt16 nSlotId )
104 // Dialog nur aufmachen, wenn ueber ScModule::SetRefDialog gerufen, damit
105 // z.B. nach einem Absturz offene Ref-Dialoge nicht wiederkommen (#42341#).
107 if ( SC_MOD()->GetCurRefDlgId() != nSlotId )
108 return NULL;
110 if ( nCurRefDlgId != nSlotId )
112 // the dialog has been opened in a different view
113 // -> lock the dispatcher for this view (modal mode)
115 GetViewData()->GetDispatcher().Lock( sal_True ); // lock is reset when closing dialog
116 return NULL;
119 SfxModelessDialog* pResult = 0;
121 if(pCW)
122 pCW->SetHideNotDelete(sal_True);
124 ScDocument* pDoc = GetViewData()->GetDocument();
126 switch( nSlotId )
128 case FID_DEFINE_NAME:
130 if (!mbInSwitch)
132 pResult = new ScNameDlg( pB, pCW, pParent, GetViewData(),
133 ScAddress( GetViewData()->GetCurX(),
134 GetViewData()->GetCurY(),
135 GetViewData()->GetTabNo() ) );
137 else
139 pResult = new ScNameDlg( pB, pCW, pParent, GetViewData(),
140 ScAddress( GetViewData()->GetCurX(),
141 GetViewData()->GetCurY(),
142 GetViewData()->GetTabNo() ), &maRangeMap);
143 static_cast<ScNameDlg*>(pResult)->SetEntry( maName, maScope);
144 mbInSwitch = false;
147 break;
149 case FID_ADD_NAME:
151 if (!mbInSwitch)
153 std::map<rtl::OUString, ScRangeName*> aRangeMap;
154 pDoc->GetRangeNameMap(aRangeMap);
155 pResult = new ScNameDefDlg( pB, pCW, pParent, GetViewData(), aRangeMap,
156 ScAddress( GetViewData()->GetCurX(),
157 GetViewData()->GetCurY(),
158 GetViewData()->GetTabNo() ), true );
160 else
162 std::map<rtl::OUString, ScRangeName*> aRangeMap;
163 for (boost::ptr_map<rtl::OUString, ScRangeName>::iterator itr = maRangeMap.begin();
164 itr != maRangeMap.end(); ++itr)
166 aRangeMap.insert(std::pair<rtl::OUString, ScRangeName*>(itr->first, itr->second));
168 pResult = new ScNameDefDlg( pB, pCW, pParent, GetViewData(), aRangeMap,
169 ScAddress( GetViewData()->GetCurX(),
170 GetViewData()->GetCurY(),
171 GetViewData()->GetTabNo() ), false );
174 break;
176 case SID_DEFINE_COLROWNAMERANGES:
178 pResult = new ScColRowNameRangesDlg( pB, pCW, pParent, GetViewData() );
180 break;
182 case SID_OPENDLG_CONSOLIDATE:
184 SfxItemSet aArgSet( GetPool(),
185 SCITEM_CONSOLIDATEDATA,
186 SCITEM_CONSOLIDATEDATA );
188 const ScConsolidateParam* pDlgData =
189 pDoc->GetConsolidateDlgData();
191 if ( !pDlgData )
193 ScConsolidateParam aConsParam;
194 SCCOL nStartCol, nEndCol;
195 SCROW nStartRow, nEndRow;
196 SCTAB nStartTab, nEndTab;
198 GetViewData()->GetSimpleArea( nStartCol, nStartRow, nStartTab,
199 nEndCol, nEndRow, nEndTab );
201 PutInOrder( nStartCol, nEndCol );
202 PutInOrder( nStartRow, nEndRow );
203 PutInOrder( nStartTab, nEndTab );
205 aConsParam.nCol = nStartCol;
206 aConsParam.nRow = nStartRow;
207 aConsParam.nTab = nStartTab;
209 aArgSet.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA,
210 &aConsParam ) );
212 else
214 aArgSet.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA, pDlgData ) );
216 pResult = new ScConsolidateDlg( pB, pCW, pParent, aArgSet );
218 break;
220 case SID_DEFINE_DBNAME:
222 // wenn auf einem bestehenden Bereich aufgerufen, den markieren
223 GetDBData( sal_True, SC_DB_OLD );
224 const ScMarkData& rMark = GetViewData()->GetMarkData();
225 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
226 MarkDataArea( false );
228 pResult = new ScDbNameDlg( pB, pCW, pParent, GetViewData() );
230 break;
232 case SID_SPECIAL_FILTER:
234 ScQueryParam aQueryParam;
235 SfxItemSet aArgSet( GetPool(),
236 SCITEM_QUERYDATA,
237 SCITEM_QUERYDATA );
239 ScDBData* pDBData = GetDBData(false, SC_DB_MAKE, SC_DBSEL_ROW_DOWN);
240 pDBData->ExtendDataArea(pDoc);
241 pDBData->GetQueryParam( aQueryParam );
243 ScRange aArea;
244 pDBData->GetArea(aArea);
245 MarkRange(aArea, false);
247 ScQueryItem aItem( SCITEM_QUERYDATA, GetViewData(), &aQueryParam );
248 ScRange aAdvSource;
249 if (pDBData->GetAdvancedQuerySource(aAdvSource))
250 aItem.SetAdvancedQuerySource( &aAdvSource );
252 aArgSet.Put( aItem );
254 // aktuelle Tabelle merken (wg. RefInput im Dialog)
255 GetViewData()->SetRefTabNo( GetViewData()->GetTabNo() );
257 pResult = new ScSpecialFilterDlg( pB, pCW, pParent, aArgSet );
259 break;
261 case SID_FILTER:
264 ScQueryParam aQueryParam;
265 SfxItemSet aArgSet( GetPool(),
266 SCITEM_QUERYDATA,
267 SCITEM_QUERYDATA );
269 ScDBData* pDBData = GetDBData(false, SC_DB_MAKE, SC_DBSEL_ROW_DOWN);
270 pDBData->ExtendDataArea(pDoc);
271 pDBData->GetQueryParam( aQueryParam );
273 ScRange aArea;
274 pDBData->GetArea(aArea);
275 MarkRange(aArea, false);
277 aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA,
278 GetViewData(),
279 &aQueryParam ) );
281 // aktuelle Tabelle merken (wg. RefInput im Dialog)
282 GetViewData()->SetRefTabNo( GetViewData()->GetTabNo() );
284 pResult = new ScFilterDlg( pB, pCW, pParent, aArgSet );
286 break;
288 case SID_OPENDLG_TABOP:
290 ScViewData* pViewData = GetViewData();
291 ScRefAddress aCurPos ( pViewData->GetCurX(),
292 pViewData->GetCurY(),
293 pViewData->GetTabNo(),
294 false, false, false );
296 pResult = new ScTabOpDlg( pB, pCW, pParent, pViewData->GetDocument(), aCurPos );
298 break;
300 case SID_OPENDLG_SOLVE:
302 ScViewData* pViewData = GetViewData();
303 ScAddress aCurPos( pViewData->GetCurX(),
304 pViewData->GetCurY(),
305 pViewData->GetTabNo());
306 pResult = new ScSolverDlg( pB, pCW, pParent, pViewData->GetDocument(), aCurPos );
308 break;
310 case SID_OPENDLG_OPTSOLVER:
312 ScViewData* pViewData = GetViewData();
313 ScAddress aCurPos( pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo());
314 pResult = new ScOptSolverDlg( pB, pCW, pParent, pViewData->GetDocShell(), aCurPos );
316 break;
318 case SID_OPENDLG_PIVOTTABLE:
320 // all settings must be in pDialogDPObject
322 if( pDialogDPObject )
324 // Check for an existing datapilot output.
325 ScViewData* pViewData = GetViewData();
326 ScDPObject* pObj = pDoc->GetDPAtCursor(
327 pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo());
329 GetViewData()->SetRefTabNo( GetViewData()->GetTabNo() );
330 pResult = new ScPivotLayoutDlg( pB, pCW, pParent, *pDialogDPObject, pObj == NULL);
333 break;
335 case SID_OPENDLG_EDIT_PRINTAREA:
337 pResult = new ScPrintAreasDlg( pB, pCW, pParent );
339 break;
341 case SID_OPENDLG_FUNCTION:
343 // Dialog schaut selber, was in der Zelle steht
345 pResult = new ScFormulaDlg( pB, pCW, pParent, GetViewData(),ScGlobal::GetStarCalcFunctionMgr() );
347 break;
349 case SID_MANAGE_XML_SOURCE:
351 pResult = new ScXMLSourceDlg(pB, pCW, pParent, pDoc);
353 break;
355 case FID_CHG_SHOW:
357 // Dialog schaut selber, was in der Zelle steht
359 pResult = new ScHighlightChgDlg( pB, pCW, pParent, GetViewData() );
361 break;
363 case WID_SIMPLE_REF:
365 // Dialog schaut selber, was in der Zelle steht
367 ScViewData* pViewData = GetViewData();
368 pViewData->SetRefTabNo( pViewData->GetTabNo() );
369 pResult = new ScSimpleRefDlg( pB, pCW, pParent, pViewData );
371 break;
374 default:
375 OSL_FAIL( "ScTabViewShell::CreateRefDialog: unbekannte ID" );
376 break;
379 if (pResult)
381 // Die Dialoge gehen immer mit eingeklapptem Zusaetze-Button auf,
382 // darum muss die Groesse ueber das Initialize gerettet werden
383 // (oder den Zusaetze-Status mit speichern !!!)
385 Size aSize = pResult->GetSizePixel();
386 pResult->Initialize( pInfo );
387 pResult->SetSizePixel(aSize);
390 return pResult;
395 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */