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