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 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScNameDlgWrapper, FID_DEFINE_NAME )
35 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScNameDefDlgWrapper, FID_ADD_NAME )
36 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScSolverDlgWrapper, SID_OPENDLG_SOLVE )
37 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScOptSolverDlgWrapper, SID_OPENDLG_OPTSOLVER )
38 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScXMLSourceDlgWrapper, SID_MANAGE_XML_SOURCE)
39 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScPivotLayoutWrapper, SID_OPENDLG_PIVOTTABLE )
40 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScTabOpDlgWrapper, SID_OPENDLG_TABOP )
41 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScFilterDlgWrapper, SID_FILTER )
42 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScSpecialFilterDlgWrapper, SID_SPECIAL_FILTER )
43 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScDbNameDlgWrapper, SID_DEFINE_DBNAME )
44 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScConsolidateDlgWrapper, SID_OPENDLG_CONSOLIDATE )
45 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScPrintAreasDlgWrapper, SID_OPENDLG_EDIT_PRINTAREA )
46 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScColRowNameRangesDlgWrapper, SID_DEFINE_COLROWNAMERANGES )
47 228 : SFX_IMPL_MODELESSDIALOG_WITHID(ScFormulaDlgWrapper, SID_OPENDLG_FUNCTION )
48 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScAcceptChgDlgWrapper, FID_CHG_ACCEPT )
49 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScHighlightChgDlgWrapper, FID_CHG_SHOW )
50 152 : SFX_IMPL_MODELESSDIALOG_WITHID(ScSimpleRefDlgWrapper, WID_SIMPLE_REF )
51 :
52 152 : 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( vcl::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( vcl::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 : // ScSimpleRefDlgWrapper
127 :
128 : static bool bScSimpleRefFlag;
129 : static long nScSimpleRefHeight;
130 : static long nScSimpleRefWidth;
131 : static long nScSimpleRefX;
132 : static long nScSimpleRefY;
133 : static bool bAutoReOpen = true;
134 :
135 0 : ScSimpleRefDlgWrapper::ScSimpleRefDlgWrapper( vcl::Window* pParentP,
136 : sal_uInt16 nId,
137 : SfxBindings* p,
138 : SfxChildWinInfo* pInfo )
139 0 : : SfxChildWindow(pParentP, nId)
140 : {
141 :
142 0 : ScTabViewShell* pViewShell = NULL;
143 0 : SfxDispatcher* pDisp = p->GetDispatcher();
144 0 : if ( pDisp )
145 : {
146 0 : SfxViewFrame* pViewFrm = pDisp->GetFrame();
147 0 : if ( pViewFrm )
148 0 : pViewShell = PTR_CAST( ScTabViewShell, pViewFrm->GetViewShell() );
149 : }
150 :
151 : OSL_ENSURE( pViewShell, "missing view shell :-(" );
152 :
153 0 : if(pInfo!=NULL && bScSimpleRefFlag)
154 : {
155 0 : pInfo->aPos.X()=nScSimpleRefX;
156 0 : pInfo->aPos.Y()=nScSimpleRefY;
157 0 : pInfo->aSize.Height()=nScSimpleRefHeight;
158 0 : pInfo->aSize.Width()=nScSimpleRefWidth;
159 : }
160 0 : pWindow = NULL;
161 :
162 0 : if(bAutoReOpen && pViewShell)
163 0 : pWindow = pViewShell->CreateRefDialog( p, this, pInfo, pParentP, WID_SIMPLE_REF);
164 :
165 0 : if (!pWindow)
166 : {
167 0 : SC_MOD()->SetRefDialog( nId, false );
168 : }
169 0 : }
170 :
171 0 : void ScSimpleRefDlgWrapper::SetDefaultPosSize(Point aPos, Size aSize, bool bSet)
172 : {
173 0 : bScSimpleRefFlag=bSet;
174 0 : if(bScSimpleRefFlag)
175 : {
176 0 : nScSimpleRefX=aPos.X();
177 0 : nScSimpleRefY=aPos.Y();
178 0 : nScSimpleRefHeight=aSize.Height();
179 0 : nScSimpleRefWidth=aSize.Width();
180 : }
181 0 : }
182 :
183 0 : void ScSimpleRefDlgWrapper::SetAutoReOpen(bool bFlag)
184 : {
185 0 : bAutoReOpen=bFlag;
186 0 : }
187 :
188 0 : void ScSimpleRefDlgWrapper::SetRefString(const OUString& rStr)
189 : {
190 0 : if(pWindow!=NULL)
191 : {
192 0 : static_cast<ScSimpleRefDlg*>(pWindow)->SetRefString(rStr);
193 : }
194 0 : }
195 :
196 0 : void ScSimpleRefDlgWrapper::SetCloseHdl( const Link& rLink )
197 : {
198 0 : if(pWindow!=NULL)
199 : {
200 0 : static_cast<ScSimpleRefDlg*>(pWindow)->SetCloseHdl( rLink );
201 : }
202 0 : }
203 :
204 0 : void ScSimpleRefDlgWrapper::SetUnoLinks( const Link& rDone,
205 : const Link& rAbort, const Link& rChange )
206 : {
207 0 : if(pWindow!=NULL)
208 : {
209 0 : static_cast<ScSimpleRefDlg*>(pWindow)->SetUnoLinks( rDone, rAbort, rChange );
210 : }
211 0 : }
212 :
213 0 : void ScSimpleRefDlgWrapper::SetFlags( bool bCloseOnButtonUp, bool bSingleCell, bool bMultiSelection )
214 : {
215 0 : if(pWindow!=NULL)
216 : {
217 0 : static_cast<ScSimpleRefDlg*>(pWindow)->SetFlags( bCloseOnButtonUp, bSingleCell, bMultiSelection );
218 : }
219 0 : }
220 :
221 0 : void ScSimpleRefDlgWrapper::StartRefInput()
222 : {
223 0 : if(pWindow!=NULL)
224 : {
225 0 : static_cast<ScSimpleRefDlg*>(pWindow)->StartRefInput();
226 : }
227 0 : }
228 :
229 : // ScAcceptChgDlgWrapper //FIXME: should be moved into ViewShell
230 :
231 0 : ScAcceptChgDlgWrapper::ScAcceptChgDlgWrapper( vcl::Window* pParentP,
232 : sal_uInt16 nId,
233 : SfxBindings* pBindings,
234 : SfxChildWinInfo* pInfo ) :
235 0 : SfxChildWindow( pParentP, nId )
236 : {
237 : ScTabViewShell* pViewShell =
238 0 : PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
239 : OSL_ENSURE( pViewShell, "missing view shell :-(" );
240 : pWindow = pViewShell ?
241 0 : new ScAcceptChgDlg( pBindings, this, pParentP, &pViewShell->GetViewData() ) :
242 0 : NULL;
243 0 : if(pWindow!=NULL)
244 : {
245 0 : static_cast<ScAcceptChgDlg*>(pWindow)->Initialize( pInfo );
246 : }
247 0 : if (pViewShell && !pWindow)
248 0 : pViewShell->GetViewFrame()->SetChildWindow( nId, false );
249 0 : }
250 :
251 0 : void ScAcceptChgDlgWrapper::ReInitDlg()
252 : {
253 : ScTabViewShell* pViewShell =
254 0 : PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
255 : OSL_ENSURE( pViewShell, "missing view shell :-(" );
256 :
257 0 : if(pWindow!=NULL && pViewShell)
258 : {
259 0 : static_cast<ScAcceptChgDlg*>(pWindow)->ReInit(&pViewShell->GetViewData());
260 : }
261 0 : }
262 :
263 : // ScHighlightChgDlgWrapper
264 :
265 0 : IMPL_CHILD_CTOR( ScHighlightChgDlgWrapper, FID_CHG_SHOW )
266 :
267 : namespace
268 : {
269 0 : ScTabViewShell * lcl_GetTabViewShell( SfxBindings *pBindings )
270 : {
271 0 : if( pBindings )
272 0 : if( SfxDispatcher* pDisp = pBindings ->GetDispatcher() )
273 0 : if( SfxViewFrame *pFrm = pDisp->GetFrame() )
274 0 : if( SfxViewShell* pViewSh = pFrm->GetViewShell() )
275 0 : return dynamic_cast<ScTabViewShell*>( pViewSh );
276 :
277 0 : return NULL;
278 : }
279 : }
280 :
281 0 : ScValidityRefChildWin::ScValidityRefChildWin( vcl::Window* pParentP,
282 : sal_uInt16 nId,
283 : SfxBindings* p,
284 : SfxChildWinInfo* /*pInfo*/ )
285 : : SfxChildWindow(pParentP, nId),
286 : m_bVisibleLock( false ),
287 : m_bFreeWindowLock( false ),
288 0 : m_pSavedWndParent( NULL )
289 : {
290 0 : SetWantsFocus( false );
291 : ScTabViewShell* pViewShell =
292 0 : NULL != ( pWindow = ScValidationDlg::Find1AliveObject( pParentP ) ) ? static_cast<ScValidationDlg*>(pWindow)->GetTabViewShell() :
293 0 : lcl_GetTabViewShell( p );
294 0 : if (!pViewShell)
295 0 : pViewShell = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
296 : OSL_ENSURE( pViewShell, "missing view shell :-(" );
297 0 : if (pViewShell && !pWindow)
298 0 : pViewShell->GetViewFrame()->SetChildWindow( nId, false );
299 :
300 0 : if( pWindow ) m_pSavedWndParent = pWindow->GetParent();
301 0 : }
302 :
303 0 : ScValidityRefChildWin::~ScValidityRefChildWin()
304 : {
305 0 : if( pWindow ) pWindow->SetParent( m_pSavedWndParent );
306 :
307 0 : if( m_bFreeWindowLock )
308 0 : pWindow = NULL;
309 228 : }
310 :
311 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|