Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
25 :
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"
33 :
34 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScNameDlgWrapper, FID_DEFINE_NAME )
35 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScNameDefDlgWrapper, FID_ADD_NAME )
36 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScSolverDlgWrapper, SID_OPENDLG_SOLVE )
37 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScOptSolverDlgWrapper, SID_OPENDLG_OPTSOLVER )
38 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScXMLSourceDlgWrapper, SID_MANAGE_XML_SOURCE)
39 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScPivotLayoutWrapper, SID_OPENDLG_PIVOTTABLE )
40 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScTabOpDlgWrapper, SID_OPENDLG_TABOP )
41 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScFilterDlgWrapper, SID_FILTER )
42 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScSpecialFilterDlgWrapper, SID_SPECIAL_FILTER )
43 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScDbNameDlgWrapper, SID_DEFINE_DBNAME )
44 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScConsolidateDlgWrapper, SID_OPENDLG_CONSOLIDATE )
45 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScPrintAreasDlgWrapper, SID_OPENDLG_EDIT_PRINTAREA )
46 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScColRowNameRangesDlgWrapper, SID_DEFINE_COLROWNAMERANGES )
47 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScFormulaDlgWrapper, SID_OPENDLG_FUNCTION )
48 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScAcceptChgDlgWrapper, FID_CHG_ACCEPT )
49 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScHighlightChgDlgWrapper, FID_CHG_SHOW )
50 0 : SFX_IMPL_MODELESSDIALOG_WITHID(ScSimpleRefDlgWrapper, WID_SIMPLE_REF )
51 :
52 0 : SFX_IMPL_CHILDWINDOW_WITHID(ScValidityRefChildWin, SID_VALIDITY_REFERENCE)
53 :
54 0 : SfxChildWinInfo ScValidityRefChildWin::GetInfo() const
55 : {
56 0 : SfxChildWinInfo anInfo = SfxChildWindow::GetInfo();
57 :
58 0 : if( Window *pWnd = GetWindow() )
59 : {
60 0 : anInfo.aSize = pWnd->GetSizePixel();
61 :
62 0 : if( pWnd->IsDialog() )
63 0 : if ( static_cast<Dialog*>(pWnd)->IsRollUp() )
64 0 : anInfo.nFlags |= SFX_CHILDWIN_ZOOMIN;
65 : }
66 :
67 0 : return anInfo;
68 : }
69 :
70 : namespace
71 : {
72 : ScTabViewShell* lcl_GetTabViewShell( SfxBindings* pBindings );
73 : }
74 :
75 : #define IMPL_CHILD_CTOR(Class,sid) \
76 : Class::Class( Window* pParentP, \
77 : sal_uInt16 nId, \
78 : SfxBindings* p, \
79 : SfxChildWinInfo* pInfo ) \
80 : : SfxChildWindow(pParentP, nId) \
81 : { \
82 : /************************************************************************************/\
83 : /* When a new document is creating, the SfxViewFrame may be ready, */\
84 : /* But the ScTabViewShell may have not been activated yet. In this */\
85 : /* situation, SfxViewShell::Current() does not get the correct shell, */\
86 : /* and we should lcl_GetTabViewShell( p ) instead of SfxViewShell::Current() */\
87 : /************************************************************************************/\
88 : ScTabViewShell* pViewShell = lcl_GetTabViewShell( p ); \
89 : if (!pViewShell) \
90 : pViewShell = PTR_CAST( ScTabViewShell, SfxViewShell::Current() ); \
91 : OSL_ENSURE( pViewShell, "missing view shell :-(" ); \
92 : pWindow = pViewShell ? \
93 : pViewShell->CreateRefDialog( p, this, pInfo, pParentP, sid ) : NULL; \
94 : if (pViewShell && !pWindow) \
95 : pViewShell->GetViewFrame()->SetChildWindow( nId, false ); \
96 : }
97 :
98 0 : IMPL_CHILD_CTOR( ScNameDlgWrapper, FID_DEFINE_NAME )
99 :
100 0 : IMPL_CHILD_CTOR( ScNameDefDlgWrapper, FID_ADD_NAME )
101 :
102 0 : IMPL_CHILD_CTOR( ScSolverDlgWrapper, SID_OPENDLG_SOLVE )
103 :
104 0 : IMPL_CHILD_CTOR( ScOptSolverDlgWrapper, SID_OPENDLG_OPTSOLVER )
105 :
106 0 : IMPL_CHILD_CTOR( ScXMLSourceDlgWrapper, SID_MANAGE_XML_SOURCE)
107 :
108 0 : IMPL_CHILD_CTOR( ScPivotLayoutWrapper, SID_OPENDLG_PIVOTTABLE )
109 :
110 0 : IMPL_CHILD_CTOR( ScTabOpDlgWrapper, SID_OPENDLG_TABOP )
111 :
112 0 : IMPL_CHILD_CTOR( ScFilterDlgWrapper, SID_FILTER )
113 :
114 0 : IMPL_CHILD_CTOR( ScSpecialFilterDlgWrapper, SID_SPECIAL_FILTER )
115 :
116 0 : IMPL_CHILD_CTOR( ScDbNameDlgWrapper, SID_DEFINE_DBNAME )
117 :
118 0 : IMPL_CHILD_CTOR( ScColRowNameRangesDlgWrapper, SID_DEFINE_COLROWNAMERANGES )
119 :
120 0 : IMPL_CHILD_CTOR( ScConsolidateDlgWrapper, SID_OPENDLG_CONSOLIDATE )
121 :
122 0 : IMPL_CHILD_CTOR( ScPrintAreasDlgWrapper, SID_OPENDLG_EDIT_PRINTAREA )
123 :
124 0 : IMPL_CHILD_CTOR( ScFormulaDlgWrapper, SID_OPENDLG_FUNCTION )
125 :
126 :
127 : // ScSimpleRefDlgWrapper
128 :
129 :
130 : static bool bScSimpleRefFlag;
131 : static long nScSimpleRefHeight;
132 : static long nScSimpleRefWidth;
133 : static long nScSimpleRefX;
134 : static long nScSimpleRefY;
135 : static bool bAutoReOpen = true;
136 :
137 0 : ScSimpleRefDlgWrapper::ScSimpleRefDlgWrapper( Window* pParentP,
138 : sal_uInt16 nId,
139 : SfxBindings* p,
140 : SfxChildWinInfo* pInfo )
141 0 : : SfxChildWindow(pParentP, nId)
142 : {
143 :
144 0 : ScTabViewShell* pViewShell = NULL;
145 0 : SfxDispatcher* pDisp = p->GetDispatcher();
146 0 : if ( pDisp )
147 : {
148 0 : SfxViewFrame* pViewFrm = pDisp->GetFrame();
149 0 : if ( pViewFrm )
150 0 : pViewShell = PTR_CAST( ScTabViewShell, pViewFrm->GetViewShell() );
151 : }
152 :
153 : OSL_ENSURE( pViewShell, "missing view shell :-(" );
154 :
155 0 : if(pInfo!=NULL && bScSimpleRefFlag)
156 : {
157 0 : pInfo->aPos.X()=nScSimpleRefX;
158 0 : pInfo->aPos.Y()=nScSimpleRefY;
159 0 : pInfo->aSize.Height()=nScSimpleRefHeight;
160 0 : pInfo->aSize.Width()=nScSimpleRefWidth;
161 : }
162 0 : pWindow = NULL;
163 :
164 0 : if(bAutoReOpen && pViewShell)
165 0 : pWindow = pViewShell->CreateRefDialog( p, this, pInfo, pParentP, WID_SIMPLE_REF);
166 :
167 0 : if (!pWindow)
168 : {
169 0 : SC_MOD()->SetRefDialog( nId, false );
170 : }
171 0 : }
172 :
173 0 : void ScSimpleRefDlgWrapper::SetDefaultPosSize(Point aPos, Size aSize, bool bSet)
174 : {
175 0 : bScSimpleRefFlag=bSet;
176 0 : if(bScSimpleRefFlag)
177 : {
178 0 : nScSimpleRefX=aPos.X();
179 0 : nScSimpleRefY=aPos.Y();
180 0 : nScSimpleRefHeight=aSize.Height();
181 0 : nScSimpleRefWidth=aSize.Width();
182 : }
183 0 : }
184 :
185 :
186 0 : void ScSimpleRefDlgWrapper::SetAutoReOpen(bool bFlag)
187 : {
188 0 : bAutoReOpen=bFlag;
189 0 : }
190 :
191 0 : void ScSimpleRefDlgWrapper::SetRefString(const OUString& rStr)
192 : {
193 0 : if(pWindow!=NULL)
194 : {
195 0 : ((ScSimpleRefDlg*)pWindow)->SetRefString(rStr);
196 : }
197 0 : }
198 :
199 0 : void ScSimpleRefDlgWrapper::SetCloseHdl( const Link& rLink )
200 : {
201 0 : if(pWindow!=NULL)
202 : {
203 0 : ((ScSimpleRefDlg*)pWindow)->SetCloseHdl( rLink );
204 : }
205 0 : }
206 :
207 0 : void ScSimpleRefDlgWrapper::SetUnoLinks( const Link& rDone,
208 : const Link& rAbort, const Link& rChange )
209 : {
210 0 : if(pWindow!=NULL)
211 : {
212 0 : ((ScSimpleRefDlg*)pWindow)->SetUnoLinks( rDone, rAbort, rChange );
213 : }
214 0 : }
215 :
216 0 : void ScSimpleRefDlgWrapper::SetFlags( bool bCloseOnButtonUp, bool bSingleCell, bool bMultiSelection )
217 : {
218 0 : if(pWindow!=NULL)
219 : {
220 0 : ((ScSimpleRefDlg*)pWindow)->SetFlags( bCloseOnButtonUp, bSingleCell, bMultiSelection );
221 : }
222 0 : }
223 :
224 0 : void ScSimpleRefDlgWrapper::StartRefInput()
225 : {
226 0 : if(pWindow!=NULL)
227 : {
228 0 : ((ScSimpleRefDlg*)pWindow)->StartRefInput();
229 : }
230 0 : }
231 :
232 :
233 : // ScAcceptChgDlgWrapper //FIXME: should be moved into ViewShell
234 :
235 :
236 0 : ScAcceptChgDlgWrapper::ScAcceptChgDlgWrapper( Window* pParentP,
237 : sal_uInt16 nId,
238 : SfxBindings* pBindings,
239 : SfxChildWinInfo* pInfo ) :
240 0 : SfxChildWindow( pParentP, nId )
241 : {
242 : ScTabViewShell* pViewShell =
243 0 : PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
244 : OSL_ENSURE( pViewShell, "missing view shell :-(" );
245 : pWindow = pViewShell ?
246 0 : new ScAcceptChgDlg( pBindings, this, pParentP, pViewShell->GetViewData() ) :
247 0 : NULL;
248 0 : if(pWindow!=NULL)
249 : {
250 0 : ((ScAcceptChgDlg*)pWindow)->Initialize( pInfo );
251 : }
252 0 : if (pViewShell && !pWindow)
253 0 : pViewShell->GetViewFrame()->SetChildWindow( nId, false );
254 0 : }
255 :
256 0 : void ScAcceptChgDlgWrapper::ReInitDlg()
257 : {
258 : ScTabViewShell* pViewShell =
259 0 : PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
260 : OSL_ENSURE( pViewShell, "missing view shell :-(" );
261 :
262 0 : if(pWindow!=NULL && pViewShell)
263 : {
264 0 : ((ScAcceptChgDlg*)pWindow)->ReInit(pViewShell->GetViewData());
265 : }
266 0 : }
267 :
268 :
269 : // ScHighlightChgDlgWrapper
270 :
271 :
272 0 : IMPL_CHILD_CTOR( ScHighlightChgDlgWrapper, FID_CHG_SHOW )
273 :
274 :
275 : namespace
276 : {
277 0 : ScTabViewShell * lcl_GetTabViewShell( SfxBindings *pBindings )
278 : {
279 0 : if( pBindings )
280 0 : if( SfxDispatcher* pDisp = pBindings ->GetDispatcher() )
281 0 : if( SfxViewFrame *pFrm = pDisp->GetFrame() )
282 0 : if( SfxViewShell* pViewSh = pFrm->GetViewShell() )
283 0 : return dynamic_cast<ScTabViewShell*>( pViewSh );
284 :
285 0 : return NULL;
286 : }
287 : }
288 :
289 0 : ScValidityRefChildWin::ScValidityRefChildWin( Window* pParentP, \
290 : sal_uInt16 nId, \
291 : SfxBindings* p, \
292 : SfxChildWinInfo* /*pInfo*/ ) \
293 : : SfxChildWindow(pParentP, nId),
294 : m_bVisibleLock( false ),
295 : m_bFreeWindowLock( false ),
296 0 : m_pSavedWndParent( NULL )
297 : {
298 0 : SetWantsFocus( false );\
299 : ScTabViewShell* pViewShell = \
300 0 : NULL != ( pWindow = ScValidationDlg::Find1AliveObject( pParentP ) ) ? static_cast<ScValidationDlg*>(pWindow)->GetTabViewShell() :
301 0 : lcl_GetTabViewShell( p );
302 0 : if (!pViewShell)
303 0 : pViewShell = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
304 : OSL_ENSURE( pViewShell, "missing view shell :-(" ); \
305 0 : if (pViewShell && !pWindow) \
306 0 : pViewShell->GetViewFrame()->SetChildWindow( nId, false ); \
307 :
308 0 : if( pWindow ) m_pSavedWndParent = pWindow->GetParent();
309 0 : }
310 :
311 0 : ScValidityRefChildWin::~ScValidityRefChildWin()
312 : {
313 0 : if( pWindow ) pWindow->SetParent( m_pSavedWndParent );
314 :
315 0 : if( m_bFreeWindowLock )
316 0 : pWindow = NULL;
317 0 : }
318 :
319 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|