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 "scitems.hxx"
21 #include <vcl/msgbox.hxx>
22 #include <sfx2/childwin.hxx>
23 #include <sfx2/dispatch.hxx>
25 #include "tabvwsh.hxx"
27 #include "globstr.hrc"
31 #include "document.hxx"
32 #include "uiitems.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
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
)
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
);
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
)
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
119 SfxModelessDialog
* pResult
= 0;
122 pCW
->SetHideNotDelete(sal_True
);
124 ScDocument
* pDoc
= GetViewData()->GetDocument();
128 case FID_DEFINE_NAME
:
132 pResult
= new ScNameDlg( pB
, pCW
, pParent
, GetViewData(),
133 ScAddress( GetViewData()->GetCurX(),
134 GetViewData()->GetCurY(),
135 GetViewData()->GetTabNo() ) );
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
);
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 );
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 );
176 case SID_DEFINE_COLROWNAMERANGES
:
178 pResult
= new ScColRowNameRangesDlg( pB
, pCW
, pParent
, GetViewData() );
182 case SID_OPENDLG_CONSOLIDATE
:
184 SfxItemSet
aArgSet( GetPool(),
185 SCITEM_CONSOLIDATEDATA
,
186 SCITEM_CONSOLIDATEDATA
);
188 const ScConsolidateParam
* pDlgData
=
189 pDoc
->GetConsolidateDlgData();
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
,
214 aArgSet
.Put( ScConsolidateItem( SCITEM_CONSOLIDATEDATA
, pDlgData
) );
216 pResult
= new ScConsolidateDlg( pB
, pCW
, pParent
, aArgSet
);
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() );
232 case SID_SPECIAL_FILTER
:
234 ScQueryParam aQueryParam
;
235 SfxItemSet
aArgSet( GetPool(),
239 ScDBData
* pDBData
= GetDBData(false, SC_DB_MAKE
, SC_DBSEL_ROW_DOWN
);
240 pDBData
->ExtendDataArea(pDoc
);
241 pDBData
->GetQueryParam( aQueryParam
);
244 pDBData
->GetArea(aArea
);
245 MarkRange(aArea
, false);
247 ScQueryItem
aItem( SCITEM_QUERYDATA
, GetViewData(), &aQueryParam
);
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
);
264 ScQueryParam aQueryParam
;
265 SfxItemSet
aArgSet( GetPool(),
269 ScDBData
* pDBData
= GetDBData(false, SC_DB_MAKE
, SC_DBSEL_ROW_DOWN
);
270 pDBData
->ExtendDataArea(pDoc
);
271 pDBData
->GetQueryParam( aQueryParam
);
274 pDBData
->GetArea(aArea
);
275 MarkRange(aArea
, false);
277 aArgSet
.Put( ScQueryItem( SCITEM_QUERYDATA
,
281 // aktuelle Tabelle merken (wg. RefInput im Dialog)
282 GetViewData()->SetRefTabNo( GetViewData()->GetTabNo() );
284 pResult
= new ScFilterDlg( pB
, pCW
, pParent
, aArgSet
);
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
);
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
);
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
);
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
);
335 case SID_OPENDLG_EDIT_PRINTAREA
:
337 pResult
= new ScPrintAreasDlg( pB
, pCW
, pParent
);
341 case SID_OPENDLG_FUNCTION
:
343 // Dialog schaut selber, was in der Zelle steht
345 pResult
= new ScFormulaDlg( pB
, pCW
, pParent
, GetViewData(),ScGlobal::GetStarCalcFunctionMgr() );
349 case SID_MANAGE_XML_SOURCE
:
351 pResult
= new ScXMLSourceDlg(pB
, pCW
, pParent
, pDoc
);
357 // Dialog schaut selber, was in der Zelle steht
359 pResult
= new ScHighlightChgDlg( pB
, pCW
, pParent
, GetViewData() );
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
);
375 OSL_FAIL( "ScTabViewShell::CreateRefDialog: unbekannte ID" );
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
);
395 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */