Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / sc / source / ui / view / reffact.cxx
blob72d8f20af5ffea68d014f5b433da45fb3a2f9a5a
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 <sfx2/app.hxx>
21 #include <sfx2/basedlgs.hxx>
22 #include <sfx2/bindings.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <sfx2/viewfrm.hxx>
26 #include "reffact.hxx"
27 #include "tabvwsh.hxx"
28 #include "sc.hrc"
29 #include "acredlin.hxx"
30 #include "simpref.hxx"
31 #include "scmod.hxx"
32 #include "validate.hxx"
34 // -----------------------------------------------------------------------
36 SFX_IMPL_MODELESSDIALOG_WITHID(ScNameDlgWrapper, FID_DEFINE_NAME )
37 SFX_IMPL_MODELESSDIALOG_WITHID(ScNameDefDlgWrapper, FID_ADD_NAME )
38 SFX_IMPL_MODELESSDIALOG_WITHID(ScSolverDlgWrapper, SID_OPENDLG_SOLVE )
39 SFX_IMPL_MODELESSDIALOG_WITHID(ScOptSolverDlgWrapper, SID_OPENDLG_OPTSOLVER )
40 SFX_IMPL_MODELESSDIALOG_WITHID(ScXMLSourceDlgWrapper, SID_MANAGE_XML_SOURCE)
41 SFX_IMPL_MODELESSDIALOG_WITHID(ScPivotLayoutWrapper, SID_OPENDLG_PIVOTTABLE )
42 SFX_IMPL_MODELESSDIALOG_WITHID(ScTabOpDlgWrapper, SID_OPENDLG_TABOP )
43 SFX_IMPL_MODELESSDIALOG_WITHID(ScFilterDlgWrapper, SID_FILTER )
44 SFX_IMPL_MODELESSDIALOG_WITHID(ScSpecialFilterDlgWrapper, SID_SPECIAL_FILTER )
45 SFX_IMPL_MODELESSDIALOG_WITHID(ScDbNameDlgWrapper, SID_DEFINE_DBNAME )
46 SFX_IMPL_MODELESSDIALOG_WITHID(ScConsolidateDlgWrapper, SID_OPENDLG_CONSOLIDATE )
47 SFX_IMPL_MODELESSDIALOG_WITHID(ScPrintAreasDlgWrapper, SID_OPENDLG_EDIT_PRINTAREA )
48 SFX_IMPL_MODELESSDIALOG_WITHID(ScColRowNameRangesDlgWrapper, SID_DEFINE_COLROWNAMERANGES )
49 SFX_IMPL_MODELESSDIALOG_WITHID(ScFormulaDlgWrapper, SID_OPENDLG_FUNCTION )
50 SFX_IMPL_MODELESSDIALOG_WITHID(ScAcceptChgDlgWrapper, FID_CHG_ACCEPT )
51 SFX_IMPL_MODELESSDIALOG_WITHID(ScHighlightChgDlgWrapper, FID_CHG_SHOW )
52 SFX_IMPL_MODELESSDIALOG_WITHID(ScSimpleRefDlgWrapper, WID_SIMPLE_REF )
53 SFX_IMPL_CHILDWINDOW_WITHID(ScValidityRefChildWin, SID_VALIDITY_REFERENCE)
55 SfxChildWinInfo ScValidityRefChildWin::GetInfo() const
57 SfxChildWinInfo anInfo = SfxChildWindow::GetInfo();
59 if( Window *pWnd = GetWindow() )
61 anInfo.aSize = pWnd->GetSizePixel();
63 if( pWnd->IsDialog() )
64 if ( static_cast<Dialog*>(pWnd)->IsRollUp() )
65 anInfo.nFlags |= SFX_CHILDWIN_ZOOMIN;
68 return anInfo;
71 namespace { ScTabViewShell * lcl_GetTabViewShell( SfxBindings *pBindings ); }
73 #define IMPL_CHILD_CTOR(Class,sid) \
74 Class::Class( Window* pParentP, \
75 sal_uInt16 nId, \
76 SfxBindings* p, \
77 SfxChildWinInfo* pInfo ) \
78 : SfxChildWindow(pParentP, nId) \
79 { \
80 /************************************************************************************/\
81 /* When a new document is creating, the SfxViewFrame may be ready, */\
82 /* But the ScTabViewShell may have not been activated yet. In this */\
83 /* situation, SfxViewShell::Current() does not get the correct shell, */\
84 /* and we should lcl_GetTabViewShell( p ) instead of SfxViewShell::Current() */\
85 /************************************************************************************/\
86 ScTabViewShell* pViewShell = lcl_GetTabViewShell( p ); \
87 if (!pViewShell) \
88 pViewShell = PTR_CAST( ScTabViewShell, SfxViewShell::Current() ); \
89 OSL_ENSURE( pViewShell, "missing view shell :-(" ); \
90 pWindow = pViewShell ? \
91 pViewShell->CreateRefDialog( p, this, pInfo, pParentP, sid ) : NULL; \
92 if (pViewShell && !pWindow) \
93 pViewShell->GetViewFrame()->SetChildWindow( nId, false ); \
97 //=========================================================================
99 //-------------------------------------------------------------------------
100 // ScNameDlgWrapper
101 //-------------------------------------------------------------------------
103 IMPL_CHILD_CTOR( ScNameDlgWrapper, FID_DEFINE_NAME )
105 //-------------------------------------------------------------------------
106 // ScNameDlgWrapper
107 //-------------------------------------------------------------------------
109 IMPL_CHILD_CTOR( ScNameDefDlgWrapper, FID_ADD_NAME )
111 //-------------------------------------------------------------------------
112 // ScSolverDlgWrapper
113 //-------------------------------------------------------------------------
115 IMPL_CHILD_CTOR( ScSolverDlgWrapper, SID_OPENDLG_SOLVE )
117 //-------------------------------------------------------------------------
118 // ScOptSolverDlgWrapper
119 //-------------------------------------------------------------------------
121 IMPL_CHILD_CTOR( ScOptSolverDlgWrapper, SID_OPENDLG_OPTSOLVER )
123 IMPL_CHILD_CTOR(ScXMLSourceDlgWrapper, SID_MANAGE_XML_SOURCE)
125 //-------------------------------------------------------------------------
126 // ScPivotLayoutWrapper
127 //-------------------------------------------------------------------------
129 IMPL_CHILD_CTOR( ScPivotLayoutWrapper, SID_OPENDLG_PIVOTTABLE )
131 //-------------------------------------------------------------------------
132 // ScTabOpDlgWrapper
133 //-------------------------------------------------------------------------
135 IMPL_CHILD_CTOR( ScTabOpDlgWrapper, SID_OPENDLG_TABOP )
137 //-------------------------------------------------------------------------
138 // ScFilterDlgWrapper
139 //-------------------------------------------------------------------------
141 IMPL_CHILD_CTOR( ScFilterDlgWrapper, SID_FILTER )
143 //-------------------------------------------------------------------------
144 // ScSpecialFilterDlgWrapper
145 //-------------------------------------------------------------------------
147 IMPL_CHILD_CTOR( ScSpecialFilterDlgWrapper, SID_SPECIAL_FILTER )
149 //-------------------------------------------------------------------------
150 // ScDbNameDlgWrapper
151 //-------------------------------------------------------------------------
153 IMPL_CHILD_CTOR( ScDbNameDlgWrapper, SID_DEFINE_DBNAME )
155 //-------------------------------------------------------------------------
156 // ScColRowNameRangesDlgWrapper
157 //-------------------------------------------------------------------------
159 IMPL_CHILD_CTOR( ScColRowNameRangesDlgWrapper, SID_DEFINE_COLROWNAMERANGES )
161 //-------------------------------------------------------------------------
162 // ScConsolidateDlgWrapper
163 //-------------------------------------------------------------------------
165 IMPL_CHILD_CTOR( ScConsolidateDlgWrapper, SID_OPENDLG_CONSOLIDATE )
167 //-------------------------------------------------------------------------
168 // ScPrintAreasDlgWrapper
169 //-------------------------------------------------------------------------
171 IMPL_CHILD_CTOR( ScPrintAreasDlgWrapper, SID_OPENDLG_EDIT_PRINTAREA )
173 //-------------------------------------------------------------------------
174 // ScFormulaDlgWrapper
175 //-------------------------------------------------------------------------
177 IMPL_CHILD_CTOR( ScFormulaDlgWrapper, SID_OPENDLG_FUNCTION )
180 //-------------------------------------------------------------------------
181 // ScSimpleRefDlgWrapper
182 //-------------------------------------------------------------------------
184 static sal_Bool bScSimpleRefFlag;
185 static long nScSimpleRefHeight;
186 static long nScSimpleRefWidth;
187 static long nScSimpleRefX;
188 static long nScSimpleRefY;
189 static sal_Bool bAutoReOpen=sal_True;
191 ScSimpleRefDlgWrapper::ScSimpleRefDlgWrapper( Window* pParentP,
192 sal_uInt16 nId,
193 SfxBindings* p,
194 SfxChildWinInfo* pInfo )
195 : SfxChildWindow(pParentP, nId)
198 ScTabViewShell* pViewShell = NULL;
199 SfxDispatcher* pDisp = p->GetDispatcher();
200 if ( pDisp )
202 SfxViewFrame* pViewFrm = pDisp->GetFrame();
203 if ( pViewFrm )
204 pViewShell = PTR_CAST( ScTabViewShell, pViewFrm->GetViewShell() );
207 OSL_ENSURE( pViewShell, "missing view shell :-(" );
209 if(pInfo!=NULL && bScSimpleRefFlag)
211 pInfo->aPos.X()=nScSimpleRefX;
212 pInfo->aPos.Y()=nScSimpleRefY;
213 pInfo->aSize.Height()=nScSimpleRefHeight;
214 pInfo->aSize.Width()=nScSimpleRefWidth;
216 pWindow = NULL;
218 if(bAutoReOpen && pViewShell)
219 pWindow = pViewShell->CreateRefDialog( p, this, pInfo, pParentP, WID_SIMPLE_REF);
221 if (!pWindow)
223 SC_MOD()->SetRefDialog( nId, false );
227 void ScSimpleRefDlgWrapper::SetDefaultPosSize(Point aPos, Size aSize, sal_Bool bSet)
229 bScSimpleRefFlag=bSet;
230 if(bScSimpleRefFlag)
232 nScSimpleRefX=aPos.X();
233 nScSimpleRefY=aPos.Y();
234 nScSimpleRefHeight=aSize.Height();
235 nScSimpleRefWidth=aSize.Width();
240 String ScSimpleRefDlgWrapper::GetRefString()
242 String aResult;
243 if(pWindow!=NULL)
245 aResult=((ScSimpleRefDlg*)pWindow)->GetRefString();
247 return aResult;
250 void ScSimpleRefDlgWrapper::SetAutoReOpen(sal_Bool bFlag)
252 bAutoReOpen=bFlag;
255 void ScSimpleRefDlgWrapper::SetRefString(const String& rStr)
257 if(pWindow!=NULL)
259 ((ScSimpleRefDlg*)pWindow)->SetRefString(rStr);
263 void ScSimpleRefDlgWrapper::SetCloseHdl( const Link& rLink )
265 if(pWindow!=NULL)
267 ((ScSimpleRefDlg*)pWindow)->SetCloseHdl( rLink );
271 void ScSimpleRefDlgWrapper::SetUnoLinks( const Link& rDone,
272 const Link& rAbort, const Link& rChange )
274 if(pWindow!=NULL)
276 ((ScSimpleRefDlg*)pWindow)->SetUnoLinks( rDone, rAbort, rChange );
280 void ScSimpleRefDlgWrapper::SetFlags( sal_Bool bCloseOnButtonUp, sal_Bool bSingleCell, sal_Bool bMultiSelection )
282 if(pWindow!=NULL)
284 ((ScSimpleRefDlg*)pWindow)->SetFlags( bCloseOnButtonUp, bSingleCell, bMultiSelection );
288 void ScSimpleRefDlgWrapper::StartRefInput()
290 if(pWindow!=NULL)
292 ((ScSimpleRefDlg*)pWindow)->StartRefInput();
298 //-------------------------------------------------------------------------
299 // ScAcceptChgDlgWrapper //Kommentar: sollte in die ViewShell
300 //-------------------------------------------------------------------------
302 ScAcceptChgDlgWrapper::ScAcceptChgDlgWrapper( Window* pParentP,
303 sal_uInt16 nId,
304 SfxBindings* pBindings,
305 SfxChildWinInfo* pInfo ) :
306 SfxChildWindow( pParentP, nId )
308 ScTabViewShell* pViewShell =
309 PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
310 OSL_ENSURE( pViewShell, "missing view shell :-(" );
311 pWindow = pViewShell ?
312 new ScAcceptChgDlg( pBindings, this, pParentP, pViewShell->GetViewData() ) :
313 NULL;
314 if(pWindow!=NULL)
316 ((ScAcceptChgDlg*)pWindow)->Initialize( pInfo );
318 if (pViewShell && !pWindow)
319 pViewShell->GetViewFrame()->SetChildWindow( nId, false );
322 void ScAcceptChgDlgWrapper::ReInitDlg()
324 ScTabViewShell* pViewShell =
325 PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
326 OSL_ENSURE( pViewShell, "missing view shell :-(" );
328 if(pWindow!=NULL && pViewShell)
330 ((ScAcceptChgDlg*)pWindow)->ReInit(pViewShell->GetViewData());
334 //-------------------------------------------------------------------------
335 // ScHighlightChgDlgWrapper
336 //-------------------------------------------------------------------------
338 IMPL_CHILD_CTOR( ScHighlightChgDlgWrapper, FID_CHG_SHOW )
341 namespace
343 ScTabViewShell * lcl_GetTabViewShell( SfxBindings *pBindings )
345 if( pBindings )
346 if( SfxDispatcher* pDisp = pBindings ->GetDispatcher() )
347 if( SfxViewFrame *pFrm = pDisp->GetFrame() )
348 if( SfxViewShell* pViewSh = pFrm->GetViewShell() )
349 return dynamic_cast<ScTabViewShell*>( pViewSh );
351 return NULL;
355 ScValidityRefChildWin::ScValidityRefChildWin( Window* pParentP, \
356 sal_uInt16 nId, \
357 SfxBindings* p, \
358 SfxChildWinInfo* /*pInfo*/ ) \
359 : SfxChildWindow(pParentP, nId),
360 m_bVisibleLock( false ),
361 m_bFreeWindowLock( false ),
362 m_pSavedWndParent( NULL )
364 SetWantsFocus( false );\
365 ScTabViewShell* pViewShell = \
366 NULL != ( pWindow = ScValidationDlg::Find1AliveObject( pParentP ) ) ? static_cast<ScValidationDlg*>(pWindow)->GetTabViewShell() :
367 lcl_GetTabViewShell( p );
368 if (!pViewShell)
369 pViewShell = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
370 OSL_ENSURE( pViewShell, "missing view shell :-(" ); \
371 if (pViewShell && !pWindow) \
372 pViewShell->GetViewFrame()->SetChildWindow( nId, false ); \
374 if( pWindow ) m_pSavedWndParent = pWindow->GetParent();
377 ScValidityRefChildWin::~ScValidityRefChildWin()
379 if( pWindow ) pWindow->SetParent( m_pSavedWndParent );
381 if( m_bFreeWindowLock )
382 pWindow = NULL;
385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */