xref: /aoo41x/main/sc/source/ui/view/reffact.cxx (revision b3f79822)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 
29 // INCLUDE ---------------------------------------------------------------
30 
31 #include <sfx2/app.hxx>
32 #include <sfx2/basedlgs.hxx>
33 #include <sfx2/bindings.hxx>
34 #include <sfx2/dispatch.hxx>
35 #include <sfx2/viewfrm.hxx>
36 
37 #include "reffact.hxx"
38 #include "tabvwsh.hxx"
39 #include "sc.hrc"
40 #include "acredlin.hxx"
41 #include "simpref.hxx"
42 #include "scmod.hxx"
43 //<!--Added by PengYunQuan for Validity Cell Range Picker
44 #include "validate.hxx"
45 //<!--Added by PengYunQuan for Validity Cell Range Picker
46 
47 // -----------------------------------------------------------------------
48 
SFX_IMPL_MODELESSDIALOG(ScNameDlgWrapper,FID_DEFINE_NAME)49 SFX_IMPL_MODELESSDIALOG(ScNameDlgWrapper, FID_DEFINE_NAME )
50 SFX_IMPL_MODELESSDIALOG(ScSolverDlgWrapper, SID_OPENDLG_SOLVE )
51 SFX_IMPL_MODELESSDIALOG(ScOptSolverDlgWrapper, SID_OPENDLG_OPTSOLVER )
52 SFX_IMPL_MODELESSDIALOG(ScPivotLayoutWrapper, SID_OPENDLG_PIVOTTABLE )
53 SFX_IMPL_MODELESSDIALOG(ScTabOpDlgWrapper, SID_OPENDLG_TABOP )
54 SFX_IMPL_MODELESSDIALOG(ScFilterDlgWrapper, SID_FILTER )
55 SFX_IMPL_MODELESSDIALOG(ScSpecialFilterDlgWrapper, SID_SPECIAL_FILTER )
56 SFX_IMPL_MODELESSDIALOG(ScDbNameDlgWrapper, SID_DEFINE_DBNAME )
57 SFX_IMPL_MODELESSDIALOG(ScConsolidateDlgWrapper, SID_OPENDLG_CONSOLIDATE )
58 SFX_IMPL_MODELESSDIALOG(ScPrintAreasDlgWrapper, SID_OPENDLG_EDIT_PRINTAREA )
59 SFX_IMPL_MODELESSDIALOG(ScCondFormatDlgWrapper, SID_OPENDLG_CONDFRMT )
60 SFX_IMPL_MODELESSDIALOG(ScColRowNameRangesDlgWrapper, SID_DEFINE_COLROWNAMERANGES )
61 SFX_IMPL_MODELESSDIALOG(ScFormulaDlgWrapper, SID_OPENDLG_FUNCTION )
62 SFX_IMPL_MODELESSDIALOG(ScAcceptChgDlgWrapper, FID_CHG_ACCEPT )
63 SFX_IMPL_MODELESSDIALOG(ScHighlightChgDlgWrapper, FID_CHG_SHOW )
64 SFX_IMPL_MODELESSDIALOG(ScSimpleRefDlgWrapper, WID_SIMPLE_REF )
65 /*!!! dafuer muss der Funktionsautopilot noch umgebaut werden
66 SFX_IMPL_CHILDWINDOW(ScFunctionDlgWrapper, SID_OPENDLG_FUNCTION )
67 SFX_IMPL_CHILDWINDOW(ScEditFunctionDlgWrapper, SID_OPENDLG_EDITFUNCTION )
68 SFX_IMPL_CHILDWINDOW(ScArgumentDlgWrapper, SID_OPENDLG_ARGUMENT )
69 */
70 //<!--Added by PengYunQuan for Validity Cell Range Picker
71 //SFX_IMPL_MODELESSDIALOG(ScValidityRefChildWin, SID_VALIDITY_REFERENCE )
72 SFX_IMPL_CHILDWINDOW(ScValidityRefChildWin, SID_VALIDITY_REFERENCE)
73 SfxChildWinInfo __EXPORT ScValidityRefChildWin::GetInfo() const
74 {
75 	SfxChildWinInfo anInfo = SfxChildWindow::GetInfo();
76 
77 	if( Window *pWnd = GetWindow() )
78 	{
79 		anInfo.aSize  = pWnd->GetSizePixel();
80 
81 		if( pWnd->IsDialog() )
82 			if ( static_cast<Dialog*>(pWnd)->IsRollUp() )
83 				anInfo.nFlags |= SFX_CHILDWIN_ZOOMIN;
84 	}
85 
86 	return anInfo;
87 }
88 
89 namespace { ScTabViewShell * lcl_GetTabViewShell( SfxBindings *pBindings ); }
90 //<!--Added by PengYunQuan for Validity Cell Range Picker
91 
92 #define IMPL_CHILD_CTOR(Class,sid) \
93 	Class::Class( Window*  	 			pParentP,					\
94 					sal_uInt16		 		nId,						\
95 					SfxBindings*		p,							\
96 					SfxChildWinInfo*	pInfo )						\
97 		: SfxChildWindow(pParentP, nId)								\
98 	{																\
99 		/*//<!--Added by PengYunQuan for Validity Cell Range Picker*/\
100 		/************************************************************************************/\
101 		/*		When a new document is creating, the SfxViewFrame may be ready,				*/\
102 		/*		But the ScTabViewShell may have not been activated yet. In this 			*/\
103 		/*		situation, SfxViewShell::Current() does not get the correct shell, 			*/\
104 		/*		and we should lcl_GetTabViewShell( p ) instead of SfxViewShell::Current()	*/\
105 		/************************************************************************************/\
106         ScTabViewShell* pViewShell = lcl_GetTabViewShell( p );      \
107 		/*//-->Added by PengYunQuan for Validity Cell Range Picker*/\
108         if (!pViewShell)                                            \
109             pViewShell = PTR_CAST( ScTabViewShell, SfxViewShell::Current() ); \
110 		DBG_ASSERT( pViewShell, "missing view shell :-(" );			\
111 		pWindow = pViewShell ?										\
112 			pViewShell->CreateRefDialog( p, this, pInfo, pParentP, sid ) : NULL;	\
113 		if (pViewShell && !pWindow)												\
114 			pViewShell->GetViewFrame()->SetChildWindow( nId, sal_False );			\
115 	}
116 
117 
118 //=========================================================================
119 
120 //-------------------------------------------------------------------------
121 // ScNameDlgWrapper
122 //-------------------------------------------------------------------------
123 
124 IMPL_CHILD_CTOR( ScNameDlgWrapper, FID_DEFINE_NAME )
125 
126 //-------------------------------------------------------------------------
127 // ScSolverDlgWrapper
128 //-------------------------------------------------------------------------
129 
130 IMPL_CHILD_CTOR( ScSolverDlgWrapper, SID_OPENDLG_SOLVE )
131 
132 //-------------------------------------------------------------------------
133 // ScOptSolverDlgWrapper
134 //-------------------------------------------------------------------------
135 
136 IMPL_CHILD_CTOR( ScOptSolverDlgWrapper, SID_OPENDLG_OPTSOLVER )
137 
138 //-------------------------------------------------------------------------
139 // ScPivotLayoutWrapper
140 //-------------------------------------------------------------------------
141 
142 IMPL_CHILD_CTOR( ScPivotLayoutWrapper, SID_OPENDLG_PIVOTTABLE )
143 
144 //-------------------------------------------------------------------------
145 // ScTabOpDlgWrapper
146 //-------------------------------------------------------------------------
147 
148 IMPL_CHILD_CTOR( ScTabOpDlgWrapper, SID_OPENDLG_TABOP )
149 
150 //-------------------------------------------------------------------------
151 // ScFilterDlgWrapper
152 //-------------------------------------------------------------------------
153 
154 IMPL_CHILD_CTOR( ScFilterDlgWrapper, SID_FILTER )
155 
156 //-------------------------------------------------------------------------
157 // ScSpecialFilterDlgWrapper
158 //-------------------------------------------------------------------------
159 
160 IMPL_CHILD_CTOR( ScSpecialFilterDlgWrapper, SID_SPECIAL_FILTER )
161 
162 //-------------------------------------------------------------------------
163 // ScDbNameDlgWrapper
164 //-------------------------------------------------------------------------
165 
166 IMPL_CHILD_CTOR( ScDbNameDlgWrapper, SID_DEFINE_DBNAME )
167 
168 //-------------------------------------------------------------------------
169 // ScColRowNameRangesDlgWrapper
170 //-------------------------------------------------------------------------
171 
172 IMPL_CHILD_CTOR( ScColRowNameRangesDlgWrapper, SID_DEFINE_COLROWNAMERANGES )
173 
174 //-------------------------------------------------------------------------
175 // ScConsolidateDlgWrapper
176 //-------------------------------------------------------------------------
177 
178 IMPL_CHILD_CTOR( ScConsolidateDlgWrapper, SID_OPENDLG_CONSOLIDATE )
179 
180 //-------------------------------------------------------------------------
181 // ScPrintAreasDlgWrapper
182 //-------------------------------------------------------------------------
183 
184 IMPL_CHILD_CTOR( ScPrintAreasDlgWrapper, SID_OPENDLG_EDIT_PRINTAREA )
185 
186 //-------------------------------------------------------------------------
187 // ScCondFormatDlgWrapper
188 //-------------------------------------------------------------------------
189 
190 IMPL_CHILD_CTOR( ScCondFormatDlgWrapper, SID_OPENDLG_CONDFRMT )
191 
192 //-------------------------------------------------------------------------
193 // ScFormulaDlgWrapper
194 //-------------------------------------------------------------------------
195 
196 IMPL_CHILD_CTOR( ScFormulaDlgWrapper, SID_OPENDLG_FUNCTION )
197 
198 
199 //-------------------------------------------------------------------------
200 // ScSimpleRefDlgWrapper
201 //-------------------------------------------------------------------------
202 
203 static sal_Bool		bScSimpleRefFlag;
204 static long		nScSimpleRefHeight;
205 static long		nScSimpleRefWidth;
206 static long		nScSimpleRefX;
207 static long		nScSimpleRefY;
208 static sal_Bool		bAutoReOpen=sal_True;
209 
ScSimpleRefDlgWrapper(Window * pParentP,sal_uInt16 nId,SfxBindings * p,SfxChildWinInfo * pInfo)210 ScSimpleRefDlgWrapper::ScSimpleRefDlgWrapper( Window* pParentP,
211 								sal_uInt16		 		nId,
212 								SfxBindings*		p,
213 								SfxChildWinInfo*	pInfo )
214 		: SfxChildWindow(pParentP, nId)
215 {
216 //	ScTabViewShell* pViewShell =
217 //		PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
218 
219     ScTabViewShell* pViewShell = NULL;
220     SfxDispatcher* pDisp = p->GetDispatcher();
221     if ( pDisp )
222     {
223         SfxViewFrame* pViewFrm = pDisp->GetFrame();
224         if ( pViewFrm )
225             pViewShell = PTR_CAST( ScTabViewShell, pViewFrm->GetViewShell() );
226     }
227 
228 	DBG_ASSERT( pViewShell, "missing view shell :-(" );
229 
230 	if(pInfo!=NULL && bScSimpleRefFlag)
231 	{
232 		pInfo->aPos.X()=nScSimpleRefX;
233 		pInfo->aPos.Y()=nScSimpleRefY;
234 		pInfo->aSize.Height()=nScSimpleRefHeight;
235 		pInfo->aSize.Width()=nScSimpleRefWidth;
236 	}
237 	pWindow = NULL;
238 
239 	if(bAutoReOpen && pViewShell)
240 		pWindow = pViewShell->CreateRefDialog( p, this, pInfo, pParentP, WID_SIMPLE_REF);
241 
242 	if (!pWindow)
243 	{
244 		SC_MOD()->SetRefDialog( nId, sal_False );
245 	}
246 }
247 
SetDefaultPosSize(Point aPos,Size aSize,sal_Bool bSet)248 void ScSimpleRefDlgWrapper::SetDefaultPosSize(Point aPos, Size aSize, sal_Bool bSet)
249 {
250 	bScSimpleRefFlag=bSet;
251 	if(bScSimpleRefFlag)
252 	{
253 		nScSimpleRefX=aPos.X();
254 		nScSimpleRefY=aPos.Y();
255 		nScSimpleRefHeight=aSize.Height();
256 		nScSimpleRefWidth=aSize.Width();
257 	}
258 }
259 
260 
GetRefString()261 String ScSimpleRefDlgWrapper::GetRefString()
262 {
263 	String aResult;
264 	if(pWindow!=NULL)
265 	{
266 		aResult=((ScSimpleRefDlg*)pWindow)->GetRefString();
267 	}
268 	return aResult;
269 }
270 
SetAutoReOpen(sal_Bool bFlag)271 void ScSimpleRefDlgWrapper::SetAutoReOpen(sal_Bool bFlag)
272 {
273 	bAutoReOpen=bFlag;
274 }
275 
SetRefString(const String & rStr)276 void ScSimpleRefDlgWrapper::SetRefString(const String& rStr)
277 {
278 	if(pWindow!=NULL)
279 	{
280 		((ScSimpleRefDlg*)pWindow)->SetRefString(rStr);
281 	}
282 }
283 
SetCloseHdl(const Link & rLink)284 void ScSimpleRefDlgWrapper::SetCloseHdl( const Link& rLink )
285 {
286 	if(pWindow!=NULL)
287 	{
288 		((ScSimpleRefDlg*)pWindow)->SetCloseHdl( rLink );
289 	}
290 }
291 
SetUnoLinks(const Link & rDone,const Link & rAbort,const Link & rChange)292 void ScSimpleRefDlgWrapper::SetUnoLinks( const Link& rDone,
293 					const Link& rAbort, const Link& rChange )
294 {
295 	if(pWindow!=NULL)
296 	{
297 		((ScSimpleRefDlg*)pWindow)->SetUnoLinks( rDone, rAbort, rChange );
298 	}
299 }
300 
SetFlags(sal_Bool bCloseOnButtonUp,sal_Bool bSingleCell,sal_Bool bMultiSelection)301 void ScSimpleRefDlgWrapper::SetFlags( sal_Bool bCloseOnButtonUp, sal_Bool bSingleCell, sal_Bool bMultiSelection )
302 {
303 	if(pWindow!=NULL)
304 	{
305 		((ScSimpleRefDlg*)pWindow)->SetFlags( bCloseOnButtonUp, bSingleCell, bMultiSelection );
306 	}
307 }
308 
StartRefInput()309 void ScSimpleRefDlgWrapper::StartRefInput()
310 {
311 	if(pWindow!=NULL)
312 	{
313 		((ScSimpleRefDlg*)pWindow)->StartRefInput();
314 	}
315 }
316 
317 
318 
319 //-------------------------------------------------------------------------
320 // ScAcceptChgDlgWrapper //Kommentar: sollte in die ViewShell
321 //-------------------------------------------------------------------------
322 
ScAcceptChgDlgWrapper(Window * pParentP,sal_uInt16 nId,SfxBindings * pBindings,SfxChildWinInfo * pInfo)323 ScAcceptChgDlgWrapper::ScAcceptChgDlgWrapper(	Window* pParentP,
324 											sal_uInt16 nId,
325 											SfxBindings* pBindings,
326 											SfxChildWinInfo* pInfo ) :
327 											SfxChildWindow( pParentP, nId )
328 {
329 		ScTabViewShell* pViewShell =
330 			PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
331 		DBG_ASSERT( pViewShell, "missing view shell :-(" );
332         pWindow = pViewShell ?
333             new ScAcceptChgDlg( pBindings, this, pParentP, pViewShell->GetViewData() ) :
334             NULL;
335 		if(pWindow!=NULL)
336 		{
337 			((ScAcceptChgDlg*)pWindow)->Initialize( pInfo );
338 		}
339 		if (pViewShell && !pWindow)
340 			pViewShell->GetViewFrame()->SetChildWindow( nId, sal_False );
341 }
342 
ReInitDlg()343 void ScAcceptChgDlgWrapper::ReInitDlg()
344 {
345 	ScTabViewShell* pViewShell =
346 		PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
347 	DBG_ASSERT( pViewShell, "missing view shell :-(" );
348 
349     if(pWindow!=NULL && pViewShell)
350 	{
351 		((ScAcceptChgDlg*)pWindow)->ReInit(pViewShell->GetViewData());
352 	}
353 }
354 
355 //-------------------------------------------------------------------------
356 // ScHighlightChgDlgWrapper
357 //-------------------------------------------------------------------------
358 
359 IMPL_CHILD_CTOR( ScHighlightChgDlgWrapper, FID_CHG_SHOW )
360 
361 /*------------------------------------------------------------------------*/
362 /*@@@
363 		//-------------------------------------------------------------------------
364 		// ScFunctionDlgWrapper
365 		//-------------------------------------------------------------------------
366 
367 		IMPL_CHILD_CTOR( ScFunctionDlgWrapper, SID_OPENDLG_FUNCTION )
368 
369 		//-------------------------------------------------------------------------
370 		// ScEditFunctionDlgWrapper
371 		//-------------------------------------------------------------------------
372 
373 		IMPL_CHILD_CTOR( ScEditFunctionDlgWrapper, SID_OPENDLG_EDITFUNCTION )
374 
375 		//-------------------------------------------------------------------------
376 		// ScArgumentDlgWrapper
377 		//-------------------------------------------------------------------------
378 
379 		IMPL_CHILD_CTOR( ScArgumentDlgWrapper, SID_OPENDLG_ARGUMENT )
380 @@@*/
381 /*------------------------------------------------------------------------*/
382 
383 
384 //<!--Added by PengYunQuan for Validity Cell Range Picker
385 namespace
386 {
lcl_GetTabViewShell(SfxBindings * pBindings)387 	ScTabViewShell * lcl_GetTabViewShell( SfxBindings *pBindings )
388 	{
389 		if( pBindings )
390 			if( SfxDispatcher* pDisp = pBindings ->GetDispatcher() )
391 				if( SfxViewFrame *pFrm = pDisp->GetFrame() )
392 					if( SfxViewShell* pViewSh = pFrm->GetViewShell() )
393 						return dynamic_cast<ScTabViewShell*>( pViewSh );
394 
395 		return NULL;
396 	}
397 }
398 
ScValidityRefChildWin(Window * pParentP,sal_uInt16 nId,SfxBindings * p,SfxChildWinInfo *)399 ScValidityRefChildWin::ScValidityRefChildWin( Window*  	 			pParentP,					\
400 											 sal_uInt16		 		nId,						\
401 											 SfxBindings*		p,							\
402 											 SfxChildWinInfo*	/*pInfo*/ )						\
403 											 : SfxChildWindow(pParentP, nId),
404 											 m_bVisibleLock( false ),
405 											 m_bFreeWindowLock( false ),
406 											 m_pSavedWndParent( NULL )
407 {
408 	SetWantsFocus( sal_False );\
409 		ScTabViewShell* pViewShell =								\
410             NULL != ( pWindow =  ScValidationDlg::Find1AliveObject( pParentP ) ) ? static_cast<ScValidationDlg*>(pWindow)->GetTabViewShell() :
411             lcl_GetTabViewShell( p );
412         if (!pViewShell)
413             pViewShell = PTR_CAST( ScTabViewShell, SfxViewShell::Current() );
414 		DBG_ASSERT( pViewShell, "missing view shell :-(" );			\
415 		if (pViewShell && !pWindow)												\
416 			pViewShell->GetViewFrame()->SetChildWindow( nId, sal_False );			\
417 		else if( pWindow /*&& pWindow->ISA(ScValidationDlg)*/ )
418 		{}//pWindow = new Window( pParentP, WB_HIDE );
419 
420 	if( pWindow ) m_pSavedWndParent = pWindow->GetParent();
421 }
422 
~ScValidityRefChildWin()423 ScValidityRefChildWin::~ScValidityRefChildWin()
424 {
425 	if( pWindow ) pWindow->SetParent( m_pSavedWndParent );
426 
427 	if( m_bFreeWindowLock )
428 		pWindow = NULL;
429 }
430 //-->Added by PengYunQuan for Validity Cell Range Picker
431