xref: /aoo41x/main/sc/source/ui/miscdlgs/anyrefdg.cxx (revision b3f79822)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b3f79822SAndrew Rist  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19*b3f79822SAndrew Rist  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir //----------------------------------------------------------------------------
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "rangelst.hxx"
32cdf0e10cSrcweir #include <sfx2/app.hxx>
33cdf0e10cSrcweir #include <sfx2/viewsh.hxx>
34cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
35cdf0e10cSrcweir #include <vcl/mnemonic.hxx>
36cdf0e10cSrcweir #include <tools/shl.hxx>
37cdf0e10cSrcweir #include <svtools/taskbar.hxx>
38cdf0e10cSrcweir #include <sfx2/bindings.hxx>
39cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #define ANYREFDG_CXX
43cdf0e10cSrcweir #include "anyrefdg.hxx"
44cdf0e10cSrcweir #undef ANYREFDG_CXX
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include "sc.hrc"
47cdf0e10cSrcweir #include "inputhdl.hxx"
48cdf0e10cSrcweir #include "scmod.hxx"
49cdf0e10cSrcweir #include "scresid.hxx"
50cdf0e10cSrcweir #include "inputwin.hxx"
51cdf0e10cSrcweir #include "tabvwsh.hxx"
52cdf0e10cSrcweir #include "docsh.hxx"
53cdf0e10cSrcweir #include "rfindlst.hxx"
54cdf0e10cSrcweir #include "compiler.hxx"
55cdf0e10cSrcweir #include "cell.hxx"
56cdf0e10cSrcweir #include "global.hxx"
57cdf0e10cSrcweir #include "inputopt.hxx"
58cdf0e10cSrcweir #include "rangeutl.hxx"
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
ScFormulaReferenceHelper(IAnyRefDialog * _pDlg,SfxBindings * _pBindings)61cdf0e10cSrcweir ScFormulaReferenceHelper::ScFormulaReferenceHelper(IAnyRefDialog* _pDlg,SfxBindings* _pBindings)
62cdf0e10cSrcweir  : m_pDlg(_pDlg)
63cdf0e10cSrcweir  , pRefEdit (NULL)
64cdf0e10cSrcweir  , m_pWindow(NULL)
65cdf0e10cSrcweir  , m_pBindings(_pBindings)
66cdf0e10cSrcweir  , pAccel( NULL )
67cdf0e10cSrcweir  , pHiddenMarks(NULL)
68cdf0e10cSrcweir  , nRefTab(0)
69cdf0e10cSrcweir  , bHighLightRef( sal_False )
70cdf0e10cSrcweir  , bAccInserted( sal_False )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     ScInputOptions aInputOption=SC_MOD()->GetInputOptions();
73cdf0e10cSrcweir 	bEnableColorRef=aInputOption.GetRangeFinder();
74cdf0e10cSrcweir }
75cdf0e10cSrcweir // -----------------------------------------------------------------------------
~ScFormulaReferenceHelper()76cdf0e10cSrcweir ScFormulaReferenceHelper::~ScFormulaReferenceHelper()
77cdf0e10cSrcweir {
78cdf0e10cSrcweir     if (bAccInserted)
79cdf0e10cSrcweir 		Application::RemoveAccel( pAccel.get() );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     // common cleanup for ScAnyRefDlg and ScFormulaDlg is done here
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     HideReference();
84cdf0e10cSrcweir     enableInput( sal_True );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl();
87cdf0e10cSrcweir     if ( pInputHdl )
88cdf0e10cSrcweir         pInputHdl->ResetDelayTimer();   // stop the timer for disabling the input line
89cdf0e10cSrcweir }
90cdf0e10cSrcweir // -----------------------------------------------------------------------------
enableInput(sal_Bool bEnable)91cdf0e10cSrcweir void ScFormulaReferenceHelper::enableInput( sal_Bool bEnable )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     TypeId aType(TYPE(ScDocShell));
94cdf0e10cSrcweir     ScDocShell* pDocShell = (ScDocShell*)SfxObjectShell::GetFirst(&aType);
95cdf0e10cSrcweir     while( pDocShell )
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir 	    SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
98cdf0e10cSrcweir 	    while( pFrame )
99cdf0e10cSrcweir 	    {
100cdf0e10cSrcweir 		    //	#71577# enable everything except InPlace, including bean frames
101cdf0e10cSrcweir             if ( !pFrame->GetFrame().IsInPlace() )
102cdf0e10cSrcweir 		    {
103cdf0e10cSrcweir 			    SfxViewShell* p = pFrame->GetViewShell();
104cdf0e10cSrcweir 			    ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,p);
105cdf0e10cSrcweir 			    if(pViewSh!=NULL)
106cdf0e10cSrcweir 			    {
107cdf0e10cSrcweir 				    Window *pWin=pViewSh->GetWindow();
108cdf0e10cSrcweir 				    if(pWin)
109cdf0e10cSrcweir 				    {
110cdf0e10cSrcweir 					    Window *pParent=pWin->GetParent();
111cdf0e10cSrcweir 					    if(pParent)
112cdf0e10cSrcweir 					    {
113cdf0e10cSrcweir 						    pParent->EnableInput(bEnable,sal_True /* sal_False */);
114cdf0e10cSrcweir 						    if(sal_True /*bChilds*/)
115cdf0e10cSrcweir 							    pViewSh->EnableRefInput(bEnable);
116cdf0e10cSrcweir 					    }
117cdf0e10cSrcweir 				    }
118cdf0e10cSrcweir 			    }
119cdf0e10cSrcweir 		    }
120cdf0e10cSrcweir 		    pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
121cdf0e10cSrcweir 	    }
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 	    pDocShell = (ScDocShell*)SfxObjectShell::GetNext(*pDocShell, &aType);
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir }
126cdf0e10cSrcweir // -----------------------------------------------------------------------------
ShowSimpleReference(const XubString & rStr)127cdf0e10cSrcweir void ScFormulaReferenceHelper::ShowSimpleReference( const XubString& rStr )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     if( /*!pRefEdit &&*/ bEnableColorRef )
130cdf0e10cSrcweir 	{
131cdf0e10cSrcweir 		bHighLightRef=sal_True;
132cdf0e10cSrcweir 		ScViewData* pViewData=ScDocShell::GetViewData();
133cdf0e10cSrcweir 		if ( pViewData )
134cdf0e10cSrcweir 		{
135cdf0e10cSrcweir 			ScDocument* pDoc=pViewData->GetDocument();
136cdf0e10cSrcweir 			ScTabViewShell*	pTabViewShell=pViewData->GetViewShell();
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 			ScRangeList aRangeList;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 			pTabViewShell->DoneRefMode( sal_False );
141cdf0e10cSrcweir 			pTabViewShell->ClearHighlightRanges();
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 			if( ParseWithNames( aRangeList, rStr, pDoc ) )
144cdf0e10cSrcweir 			{
145cdf0e10cSrcweir 				ScRange* pRangeEntry = aRangeList.First();
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 				sal_uInt16 nIndex=0;
148cdf0e10cSrcweir 				while(pRangeEntry != NULL)
149cdf0e10cSrcweir 				{
150cdf0e10cSrcweir 					ColorData aColName = ScRangeFindList::GetColorName(nIndex++);
151cdf0e10cSrcweir 					pTabViewShell->AddHighlightRange(*pRangeEntry, aColName);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 					pRangeEntry = aRangeList.Next();
154cdf0e10cSrcweir 				}
155cdf0e10cSrcweir 			}
156cdf0e10cSrcweir 		}
157cdf0e10cSrcweir 	}
158cdf0e10cSrcweir }
159cdf0e10cSrcweir // -----------------------------------------------------------------------------
ParseWithNames(ScRangeList & rRanges,const String & rStr,ScDocument * pDoc)160cdf0e10cSrcweir bool ScFormulaReferenceHelper::ParseWithNames( ScRangeList& rRanges, const String& rStr, ScDocument* pDoc )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     bool bError = false;
163cdf0e10cSrcweir     rRanges.RemoveAll();
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     ScAddress::Details aDetails(pDoc->GetAddressConvention(), 0, 0);
166cdf0e10cSrcweir     ScRangeUtil aRangeUtil;
167cdf0e10cSrcweir     xub_StrLen nTokenCnt = rStr.GetTokenCount();
168cdf0e10cSrcweir     for( xub_StrLen nToken = 0; nToken < nTokenCnt; ++nToken )
169cdf0e10cSrcweir     {
170cdf0e10cSrcweir         ScRange aRange;
171cdf0e10cSrcweir         String aRangeStr( rStr.GetToken( nToken ) );
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         sal_uInt16 nFlags = aRange.ParseAny( aRangeStr, pDoc, aDetails );
174cdf0e10cSrcweir         if ( nFlags & SCA_VALID )
175cdf0e10cSrcweir         {
176cdf0e10cSrcweir             if ( (nFlags & SCA_TAB_3D) == 0 )
177cdf0e10cSrcweir                 aRange.aStart.SetTab( nRefTab );
178cdf0e10cSrcweir             if ( (nFlags & SCA_TAB2_3D) == 0 )
179cdf0e10cSrcweir                 aRange.aEnd.SetTab( aRange.aStart.Tab() );
180cdf0e10cSrcweir             rRanges.Append( aRange );
181cdf0e10cSrcweir         }
182cdf0e10cSrcweir         else if ( aRangeUtil.MakeRangeFromName( aRangeStr, pDoc, nRefTab, aRange, RUTL_NAMES, aDetails ) )
183cdf0e10cSrcweir             rRanges.Append( aRange );
184cdf0e10cSrcweir         else
185cdf0e10cSrcweir             bError = true;
186cdf0e10cSrcweir     }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     return !bError;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir // -----------------------------------------------------------------------------
ShowFormulaReference(const XubString & rStr)191cdf0e10cSrcweir void ScFormulaReferenceHelper::ShowFormulaReference( const XubString& rStr )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir     if( /*!pRefEdit &&*/ bEnableColorRef)
194cdf0e10cSrcweir 	{
195cdf0e10cSrcweir 		bHighLightRef=sal_True;
196cdf0e10cSrcweir 		ScViewData* pViewData=ScDocShell::GetViewData();
197cdf0e10cSrcweir 		if ( pViewData && pRefComp.get() )
198cdf0e10cSrcweir 		{
199cdf0e10cSrcweir 			ScTabViewShell*	pTabViewShell=pViewData->GetViewShell();
200cdf0e10cSrcweir 			SCCOL nCol = pViewData->GetCurX();
201cdf0e10cSrcweir 			SCROW nRow = pViewData->GetCurY();
202cdf0e10cSrcweir 			SCTAB nTab = pViewData->GetTabNo();
203cdf0e10cSrcweir 			ScAddress aPos( nCol, nRow, nTab );
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 			ScTokenArray* pScTokA=pRefComp->CompileString(rStr);
206cdf0e10cSrcweir 			//pRefComp->CompileTokenArray();
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 			if(pTabViewShell!=NULL && pScTokA!=NULL)
209cdf0e10cSrcweir 			{
210cdf0e10cSrcweir 				pTabViewShell->DoneRefMode( sal_False );
211cdf0e10cSrcweir 				pTabViewShell->ClearHighlightRanges();
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 				pScTokA->Reset();
214cdf0e10cSrcweir 				const ScToken* pToken = static_cast<const ScToken*>(pScTokA->GetNextReference());
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 				sal_uInt16 nIndex=0;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 				while(pToken!=NULL)
219cdf0e10cSrcweir 				{
220cdf0e10cSrcweir 					sal_Bool bDoubleRef=(pToken->GetType()==formula::svDoubleRef);
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 					if(pToken->GetType()==formula::svSingleRef || bDoubleRef)
224cdf0e10cSrcweir 					{
225cdf0e10cSrcweir 						ScRange aRange;
226cdf0e10cSrcweir 						if(bDoubleRef)
227cdf0e10cSrcweir 						{
228cdf0e10cSrcweir 							ScComplexRefData aRef( pToken->GetDoubleRef() );
229cdf0e10cSrcweir 							aRef.CalcAbsIfRel( aPos );
230cdf0e10cSrcweir 							aRange.aStart.Set( aRef.Ref1.nCol, aRef.Ref1.nRow, aRef.Ref1.nTab );
231cdf0e10cSrcweir 							aRange.aEnd.Set( aRef.Ref2.nCol, aRef.Ref2.nRow, aRef.Ref2.nTab );
232cdf0e10cSrcweir 						}
233cdf0e10cSrcweir 						else
234cdf0e10cSrcweir 						{
235cdf0e10cSrcweir 							ScSingleRefData aRef( pToken->GetSingleRef() );
236cdf0e10cSrcweir 							aRef.CalcAbsIfRel( aPos );
237cdf0e10cSrcweir 							aRange.aStart.Set( aRef.nCol, aRef.nRow, aRef.nTab );
238cdf0e10cSrcweir 							aRange.aEnd = aRange.aStart;
239cdf0e10cSrcweir 						}
240cdf0e10cSrcweir 						ColorData aColName=ScRangeFindList::GetColorName(nIndex++);
241cdf0e10cSrcweir 						pTabViewShell->AddHighlightRange(aRange, aColName);
242cdf0e10cSrcweir 					}
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 					pToken = static_cast<const ScToken*>(pScTokA->GetNextReference());
245cdf0e10cSrcweir 				}
246cdf0e10cSrcweir 			}
247cdf0e10cSrcweir 			if(pScTokA!=NULL) delete pScTokA;
248cdf0e10cSrcweir 		}
249cdf0e10cSrcweir 	}
250cdf0e10cSrcweir }
251cdf0e10cSrcweir // -----------------------------------------------------------------------------
HideReference(sal_Bool bDoneRefMode)252cdf0e10cSrcweir void ScFormulaReferenceHelper::HideReference( sal_Bool bDoneRefMode )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir 	ScViewData* pViewData=ScDocShell::GetViewData();
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     if( pViewData && /*!pRefEdit &&*/ bHighLightRef && bEnableColorRef)
257cdf0e10cSrcweir 	{
258cdf0e10cSrcweir 		ScTabViewShell*	pTabViewShell=pViewData->GetViewShell();
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 		if(pTabViewShell!=NULL)
261cdf0e10cSrcweir 		{
262cdf0e10cSrcweir 			//	bDoneRefMode is sal_False when called from before SetReference.
263cdf0e10cSrcweir 			//	In that case, RefMode was just started and must not be ended now.
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 			if ( bDoneRefMode )
266cdf0e10cSrcweir 				pTabViewShell->DoneRefMode( sal_False );
267cdf0e10cSrcweir 			pTabViewShell->ClearHighlightRanges();
268cdf0e10cSrcweir 		}
269cdf0e10cSrcweir 		bHighLightRef=sal_False;
270cdf0e10cSrcweir 	}
271cdf0e10cSrcweir }
272cdf0e10cSrcweir // -----------------------------------------------------------------------------
ShowReference(const XubString & rStr)273cdf0e10cSrcweir void ScFormulaReferenceHelper::ShowReference( const XubString& rStr )
274cdf0e10cSrcweir {
275cdf0e10cSrcweir     if( /*!pRefEdit &&*/ bEnableColorRef )
276cdf0e10cSrcweir 	{
277cdf0e10cSrcweir 		if(	rStr.Search('(')!=STRING_NOTFOUND ||
278cdf0e10cSrcweir 			rStr.Search('+')!=STRING_NOTFOUND ||
279cdf0e10cSrcweir 			rStr.Search('*')!=STRING_NOTFOUND ||
280cdf0e10cSrcweir 			rStr.Search('-')!=STRING_NOTFOUND ||
281cdf0e10cSrcweir 			rStr.Search('/')!=STRING_NOTFOUND ||
282cdf0e10cSrcweir 			rStr.Search('&')!=STRING_NOTFOUND ||
283cdf0e10cSrcweir 			rStr.Search('<')!=STRING_NOTFOUND ||
284cdf0e10cSrcweir 			rStr.Search('>')!=STRING_NOTFOUND ||
285cdf0e10cSrcweir 			rStr.Search('=')!=STRING_NOTFOUND ||
286cdf0e10cSrcweir 			rStr.Search('^')!=STRING_NOTFOUND)
287cdf0e10cSrcweir 		{
288cdf0e10cSrcweir 			ShowFormulaReference(rStr);
289cdf0e10cSrcweir 		}
290cdf0e10cSrcweir 		else
291cdf0e10cSrcweir 		{
292cdf0e10cSrcweir 			ShowSimpleReference(rStr);
293cdf0e10cSrcweir 		}
294cdf0e10cSrcweir 	}
295cdf0e10cSrcweir }
296cdf0e10cSrcweir // -----------------------------------------------------------------------------
ReleaseFocus(formula::RefEdit * pEdit,formula::RefButton * pButton)297cdf0e10cSrcweir void ScFormulaReferenceHelper::ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton )
298cdf0e10cSrcweir {
299cdf0e10cSrcweir     if( !pRefEdit && pEdit )
300cdf0e10cSrcweir     {
301cdf0e10cSrcweir         m_pDlg->RefInputStart( pEdit, pButton );
302cdf0e10cSrcweir //        if( pRefEdit )
303cdf0e10cSrcweir //            pRefEdit->SilentGrabFocus();
304cdf0e10cSrcweir     }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
307cdf0e10cSrcweir     if( pViewShell )
308cdf0e10cSrcweir     {
309cdf0e10cSrcweir         pViewShell->ActiveGrabFocus();
310cdf0e10cSrcweir         if( pRefEdit )
311cdf0e10cSrcweir         {
312cdf0e10cSrcweir             const ScViewData* pViewData = pViewShell->GetViewData();
313cdf0e10cSrcweir             ScDocument* pDoc = pViewData->GetDocument();
314cdf0e10cSrcweir 			ScRangeList aRangeList;
315cdf0e10cSrcweir             if( ParseWithNames( aRangeList, pRefEdit->GetText(), pDoc ) )
316cdf0e10cSrcweir 			{
317cdf0e10cSrcweir                 const ScRange* pRange = aRangeList.GetObject( 0 );
318cdf0e10cSrcweir                 if( pRange )
319cdf0e10cSrcweir                 {
320cdf0e10cSrcweir                     pViewShell->SetTabNo( pRange->aStart.Tab() );
321cdf0e10cSrcweir                     pViewShell->MoveCursorAbs(  pRange->aStart.Col(),
322cdf0e10cSrcweir                         pRange->aStart.Row(), SC_FOLLOW_JUMP, sal_False, sal_False );
323cdf0e10cSrcweir                     pViewShell->MoveCursorAbs( pRange->aEnd.Col(),
324cdf0e10cSrcweir                         pRange->aEnd.Row(), SC_FOLLOW_JUMP, sal_True, sal_False );
325cdf0e10cSrcweir                     m_pDlg->SetReference( *pRange, pDoc );
326cdf0e10cSrcweir                 }
327cdf0e10cSrcweir             }
328cdf0e10cSrcweir         }
329cdf0e10cSrcweir     }
330cdf0e10cSrcweir }
331cdf0e10cSrcweir // -----------------------------------------------------------------------------
Init()332cdf0e10cSrcweir void ScFormulaReferenceHelper::Init()
333cdf0e10cSrcweir {
334cdf0e10cSrcweir     ScViewData* pViewData=ScDocShell::GetViewData();    //! use pScViewShell?
335cdf0e10cSrcweir 	if ( pViewData )
336cdf0e10cSrcweir 	{
337cdf0e10cSrcweir 		ScDocument* pDoc = pViewData->GetDocument();
338cdf0e10cSrcweir 		SCCOL nCol = pViewData->GetCurX();
339cdf0e10cSrcweir 		SCROW nRow = pViewData->GetCurY();
340cdf0e10cSrcweir 		SCTAB nTab = pViewData->GetTabNo();
341cdf0e10cSrcweir 		ScAddress aCursorPos( nCol, nRow, nTab );
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 		String rStrExp;
344cdf0e10cSrcweir 		pRefCell.reset( new ScFormulaCell( pDoc, aCursorPos, rStrExp ) );
345cdf0e10cSrcweir 		pRefComp.reset( new ScCompiler( pDoc, aCursorPos) );
346cdf0e10cSrcweir         pRefComp->SetGrammar( pDoc->GetGrammar() );
347cdf0e10cSrcweir 		pRefComp->SetCompileForFAP(sal_True);
348cdf0e10cSrcweir 
349cdf0e10cSrcweir         nRefTab = nTab;
350cdf0e10cSrcweir 	} // if ( pViewData )
351cdf0e10cSrcweir }
352cdf0e10cSrcweir // -----------------------------------------------------------------------------
IMPL_LINK(ScFormulaReferenceHelper,AccelSelectHdl,Accelerator *,pSelAccel)353cdf0e10cSrcweir IMPL_LINK( ScFormulaReferenceHelper, AccelSelectHdl, Accelerator *, pSelAccel )
354cdf0e10cSrcweir {
355cdf0e10cSrcweir     if ( !pSelAccel )
356cdf0e10cSrcweir 		return 0;
357cdf0e10cSrcweir 
358cdf0e10cSrcweir     switch ( pSelAccel->GetCurKeyCode().GetCode() )
359cdf0e10cSrcweir 	{
360cdf0e10cSrcweir 		case KEY_RETURN:
361cdf0e10cSrcweir 		case KEY_ESCAPE:
362cdf0e10cSrcweir             if( pRefEdit )
363cdf0e10cSrcweir                 pRefEdit->GrabFocus();
364cdf0e10cSrcweir             m_pDlg->RefInputDone( sal_True );
365cdf0e10cSrcweir         break;
366cdf0e10cSrcweir 	}
367cdf0e10cSrcweir 	return sal_True;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir //----------------------------------------------------------------------------
RefInputDone(sal_Bool bForced)370cdf0e10cSrcweir void ScFormulaReferenceHelper::RefInputDone( sal_Bool bForced )
371cdf0e10cSrcweir {
372cdf0e10cSrcweir 	//<!--Modified by PengYunQuan for Validity Cell Range Picker
373cdf0e10cSrcweir 	//if (pRefEdit && (bForced || !pRefBtn))
374cdf0e10cSrcweir 	if ( CanInputDone( bForced ) )//if (pRefEdit && (bForced || !pRefBtn))
375cdf0e10cSrcweir 	//-->Modified by PengYunQuan for Validity Cell Range Picker
376cdf0e10cSrcweir 	{
377cdf0e10cSrcweir 		if (bAccInserted)			// Accelerator wieder abschalten
378cdf0e10cSrcweir 		{
379cdf0e10cSrcweir 			Application::RemoveAccel( pAccel.get() );
380cdf0e10cSrcweir 			bAccInserted = sal_False;
381cdf0e10cSrcweir 		}
382cdf0e10cSrcweir 
383cdf0e10cSrcweir 		// Fenstertitel anpassen
384cdf0e10cSrcweir 		m_pWindow->SetText(sOldDialogText);
385cdf0e10cSrcweir 
386cdf0e10cSrcweir 		// Fenster wieder gross
387cdf0e10cSrcweir 		m_pWindow->SetOutputSizePixel(aOldDialogSize);
388cdf0e10cSrcweir 
389cdf0e10cSrcweir 		// pEditCell an alte Position
390cdf0e10cSrcweir 		pRefEdit->SetPosSizePixel(aOldEditPos, aOldEditSize);
391cdf0e10cSrcweir 
392cdf0e10cSrcweir         // set button position and image
393cdf0e10cSrcweir         if( pRefBtn )
394cdf0e10cSrcweir         {
395cdf0e10cSrcweir             pRefBtn->SetPosPixel( aOldButtonPos );
396cdf0e10cSrcweir             pRefBtn->SetStartImage();
397cdf0e10cSrcweir         }
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 		// Alle anderen: Show();
400cdf0e10cSrcweir 		sal_uInt16 nChildren = m_pWindow->GetChildCount();
401cdf0e10cSrcweir 		for ( sal_uInt16 i = 0; i < nChildren; i++ )
402cdf0e10cSrcweir 			if (pHiddenMarks[i])
403cdf0e10cSrcweir 			{
404cdf0e10cSrcweir 				m_pWindow->GetChild(i)->GetWindow( WINDOW_CLIENT )->Show();
405cdf0e10cSrcweir 			}
406cdf0e10cSrcweir 		delete [] pHiddenMarks;
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 		pRefEdit = NULL;
409cdf0e10cSrcweir         pRefBtn = NULL;
410cdf0e10cSrcweir 	}
411cdf0e10cSrcweir }
412cdf0e10cSrcweir // -----------------------------------------------------------------------------
RefInputStart(formula::RefEdit * pEdit,formula::RefButton * pButton)413cdf0e10cSrcweir void ScFormulaReferenceHelper::RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton )
414cdf0e10cSrcweir {
415cdf0e10cSrcweir 	if (!pRefEdit)
416cdf0e10cSrcweir 	{
417cdf0e10cSrcweir 		pRefEdit = pEdit;
418cdf0e10cSrcweir 		pRefBtn  = pButton;
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 		// Neuen Fenstertitel basteln
421cdf0e10cSrcweir 		String sNewDialogText;
422cdf0e10cSrcweir 		sOldDialogText = m_pWindow->GetText();
423cdf0e10cSrcweir 		sNewDialogText  = sOldDialogText;
424cdf0e10cSrcweir 		sNewDialogText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ": " ));
425cdf0e10cSrcweir 
426cdf0e10cSrcweir 		// Alle Elemente ausser EditCell und Button verstecken
427cdf0e10cSrcweir 		sal_uInt16 nChildren = m_pWindow->GetChildCount();
428cdf0e10cSrcweir 		pHiddenMarks = new sal_Bool [nChildren];
429cdf0e10cSrcweir 		for (sal_uInt16 i = 0; i < nChildren; i++)
430cdf0e10cSrcweir 		{
431cdf0e10cSrcweir 			pHiddenMarks[i] = sal_False;
432cdf0e10cSrcweir 			Window* pWin = m_pWindow->GetChild(i);
433cdf0e10cSrcweir 			pWin = pWin->GetWindow( WINDOW_CLIENT );
434cdf0e10cSrcweir 			if (pWin == (Window*)pRefEdit)
435cdf0e10cSrcweir 			{
436cdf0e10cSrcweir 				sNewDialogText += m_pWindow->GetChild(i-1)->GetWindow( WINDOW_CLIENT )->GetText();
437cdf0e10cSrcweir 			}
438cdf0e10cSrcweir 			else if (pWin == (Window*)pRefBtn)
439cdf0e10cSrcweir 				;	// do nothing
440cdf0e10cSrcweir 			else if (pWin->IsVisible())
441cdf0e10cSrcweir 			{
442cdf0e10cSrcweir 				pHiddenMarks[i] = sal_True;
443cdf0e10cSrcweir 				pWin->Hide();
444cdf0e10cSrcweir 			}
445cdf0e10cSrcweir 		}
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 		// Alte Daten merken
448cdf0e10cSrcweir 		aOldDialogSize = m_pWindow->GetOutputSizePixel();
449cdf0e10cSrcweir 		aOldEditPos = pRefEdit->GetPosPixel();
450cdf0e10cSrcweir 		aOldEditSize = pRefEdit->GetSizePixel();
451cdf0e10cSrcweir 		if (pRefBtn)
452cdf0e10cSrcweir 			aOldButtonPos = pRefBtn->GetPosPixel();
453cdf0e10cSrcweir 
454cdf0e10cSrcweir 		// Edit-Feld verschieben und anpassen
455cdf0e10cSrcweir 		Size aNewDlgSize(aOldDialogSize.Width(), aOldEditSize.Height());
456cdf0e10cSrcweir 		Size aNewEditSize(aNewDlgSize);
457cdf0e10cSrcweir         long nOffset = 0;
458cdf0e10cSrcweir 		if (pRefBtn)
459cdf0e10cSrcweir 		{
460cdf0e10cSrcweir 			aNewEditSize.Width() -= pRefBtn->GetSizePixel().Width();
461cdf0e10cSrcweir 			aNewEditSize.Width() -= aOldButtonPos.X() - (aOldEditPos.X()+aOldEditSize.Width());
462cdf0e10cSrcweir 
463cdf0e10cSrcweir             long nHeight = pRefBtn->GetSizePixel().Height();
464cdf0e10cSrcweir             if ( nHeight > aOldEditSize.Height() )
465cdf0e10cSrcweir             {
466cdf0e10cSrcweir                 aNewDlgSize.Height() = nHeight;
467cdf0e10cSrcweir                 nOffset = (nHeight-aOldEditSize.Height()) / 2;
468cdf0e10cSrcweir             }
469cdf0e10cSrcweir             aNewEditSize.Width() -= nOffset;
470cdf0e10cSrcweir 		}
471cdf0e10cSrcweir 		pRefEdit->SetPosSizePixel(Point(nOffset, nOffset), aNewEditSize);
472cdf0e10cSrcweir 
473cdf0e10cSrcweir         // set button position and image
474cdf0e10cSrcweir         if( pRefBtn )
475cdf0e10cSrcweir         {
476cdf0e10cSrcweir             pRefBtn->SetPosPixel( Point( aOldDialogSize.Width() - pRefBtn->GetSizePixel().Width(), 0 ) );
477cdf0e10cSrcweir             pRefBtn->SetEndImage();
478cdf0e10cSrcweir         }
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 		// Fenster verkleinern
481cdf0e10cSrcweir 		m_pWindow->SetOutputSizePixel(aNewDlgSize);
482cdf0e10cSrcweir 
483cdf0e10cSrcweir 		// Fenstertitel anpassen
484cdf0e10cSrcweir 		m_pWindow->SetText( MnemonicGenerator::EraseAllMnemonicChars( sNewDialogText ) );
485cdf0e10cSrcweir 
486cdf0e10cSrcweir //        if ( pButton )      // ueber den Button: Enter und Escape abfangen
487cdf0e10cSrcweir //        {
488cdf0e10cSrcweir 			if (!pAccel.get())
489cdf0e10cSrcweir 			{
490cdf0e10cSrcweir 				pAccel.reset( new Accelerator );
491cdf0e10cSrcweir 				pAccel->InsertItem( 1, KeyCode( KEY_RETURN ) );
492cdf0e10cSrcweir 				pAccel->InsertItem( 2, KeyCode( KEY_ESCAPE ) );
493cdf0e10cSrcweir 				pAccel->SetSelectHdl( LINK( this, ScFormulaReferenceHelper, AccelSelectHdl ) );
494cdf0e10cSrcweir 			}
495cdf0e10cSrcweir 			Application::InsertAccel( pAccel.get() );
496cdf0e10cSrcweir 			bAccInserted = sal_True;
497cdf0e10cSrcweir //        }
498cdf0e10cSrcweir 	}
499cdf0e10cSrcweir }
500cdf0e10cSrcweir // -----------------------------------------------------------------------------
ToggleCollapsed(formula::RefEdit * pEdit,formula::RefButton * pButton)501cdf0e10cSrcweir void ScFormulaReferenceHelper::ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton )
502cdf0e10cSrcweir {
503cdf0e10cSrcweir     if( pEdit )
504cdf0e10cSrcweir     {
505cdf0e10cSrcweir         if( pRefEdit == pEdit )                 // is this the active ref edit field?
506cdf0e10cSrcweir         {
507cdf0e10cSrcweir             pRefEdit->GrabFocus();              // before RefInputDone()
508cdf0e10cSrcweir             m_pDlg->RefInputDone( sal_True );               // finish ref input
509cdf0e10cSrcweir         }
510cdf0e10cSrcweir         else
511cdf0e10cSrcweir         {
512cdf0e10cSrcweir             m_pDlg->RefInputDone( sal_True );               // another active ref edit?
513cdf0e10cSrcweir             m_pDlg->RefInputStart( pEdit, pButton );    // start ref input
514cdf0e10cSrcweir             // pRefEdit might differ from pEdit after RefInputStart() (i.e. ScFormulaDlg)
515cdf0e10cSrcweir             if( pRefEdit )
516cdf0e10cSrcweir                 pRefEdit->GrabFocus();
517cdf0e10cSrcweir         }
518cdf0e10cSrcweir     }
519cdf0e10cSrcweir }
520cdf0e10cSrcweir // -----------------------------------------------------------------------------
DoClose(sal_uInt16 nId)521cdf0e10cSrcweir sal_Bool ScFormulaReferenceHelper::DoClose( sal_uInt16 nId )
522cdf0e10cSrcweir {
523cdf0e10cSrcweir 	SfxApplication* pSfxApp = SFX_APP();
524cdf0e10cSrcweir 
525cdf0e10cSrcweir 	SetDispatcherLock( sal_False );			//! here and in dtor ?
526cdf0e10cSrcweir 
527cdf0e10cSrcweir 	SfxViewFrame* pViewFrm = SfxViewFrame::Current();
528cdf0e10cSrcweir 	if ( pViewFrm && pViewFrm->HasChildWindow(FID_INPUTLINE_STATUS) )
529cdf0e10cSrcweir 	{
530cdf0e10cSrcweir 		//	Die Eingabezeile wird per ToolBox::Disable disabled, muss darum auch
531cdf0e10cSrcweir 		//	per ToolBox::Enable wieder aktiviert werden (vor dem Enable des AppWindow),
532cdf0e10cSrcweir 		//	damit die Buttons auch wieder enabled gezeichnet werden.
533cdf0e10cSrcweir 		SfxChildWindow* pChild = pViewFrm->GetChildWindow(FID_INPUTLINE_STATUS);
534cdf0e10cSrcweir 		if (pChild)
535cdf0e10cSrcweir 		{
536cdf0e10cSrcweir 			ScInputWindow* pWin = (ScInputWindow*)pChild->GetWindow();
537cdf0e10cSrcweir 			pWin->Enable();
538cdf0e10cSrcweir 		}
539cdf0e10cSrcweir 	}
540cdf0e10cSrcweir 
541cdf0e10cSrcweir 	// find parent view frame to close dialog
542cdf0e10cSrcweir 	SfxViewFrame* pMyViewFrm = NULL;
543cdf0e10cSrcweir 	if ( m_pBindings )
544cdf0e10cSrcweir 	{
545cdf0e10cSrcweir 		SfxDispatcher* pMyDisp = m_pBindings->GetDispatcher();
546cdf0e10cSrcweir 		if (pMyDisp)
547cdf0e10cSrcweir 			pMyViewFrm = pMyDisp->GetFrame();
548cdf0e10cSrcweir 	}
549cdf0e10cSrcweir 	SC_MOD()->SetRefDialog( nId, sal_False, pMyViewFrm );
550cdf0e10cSrcweir 
551cdf0e10cSrcweir 	pSfxApp->Broadcast( SfxSimpleHint( FID_KILLEDITVIEW ) );
552cdf0e10cSrcweir 
553cdf0e10cSrcweir     ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell();
554cdf0e10cSrcweir 	if ( pScViewShell )
555cdf0e10cSrcweir 		pScViewShell->UpdateInputHandler(sal_True);
556cdf0e10cSrcweir 
557cdf0e10cSrcweir 	return sal_True;
558cdf0e10cSrcweir }
SetDispatcherLock(sal_Bool bLock)559cdf0e10cSrcweir void ScFormulaReferenceHelper::SetDispatcherLock( sal_Bool bLock )
560cdf0e10cSrcweir {
561cdf0e10cSrcweir 	//	lock / unlock only the dispatchers of Calc documents
562cdf0e10cSrcweir 
563cdf0e10cSrcweir 	TypeId aType(TYPE(ScDocShell));
564cdf0e10cSrcweir 	ScDocShell* pDocShell = (ScDocShell*)SfxObjectShell::GetFirst(&aType);
565cdf0e10cSrcweir 	while( pDocShell )
566cdf0e10cSrcweir 	{
567cdf0e10cSrcweir 		SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
568cdf0e10cSrcweir 		while( pFrame )
569cdf0e10cSrcweir 		{
570cdf0e10cSrcweir 			SfxDispatcher* pDisp = pFrame->GetDispatcher();
571cdf0e10cSrcweir 			if (pDisp)
572cdf0e10cSrcweir 				pDisp->Lock( bLock );
573cdf0e10cSrcweir 
574cdf0e10cSrcweir 			pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
575cdf0e10cSrcweir 		}
576cdf0e10cSrcweir 		pDocShell = (ScDocShell*)SfxObjectShell::GetNext(*pDocShell, &aType);
577cdf0e10cSrcweir 	}
578cdf0e10cSrcweir 
579cdf0e10cSrcweir 	//	if a new view is created while the dialog is open,
580cdf0e10cSrcweir 	//	that view's dispatcher is locked when trying to create the dialog
581cdf0e10cSrcweir 	//	for that view (ScTabViewShell::CreateRefDialog)
582cdf0e10cSrcweir }
583cdf0e10cSrcweir // -----------------------------------------------------------------------------
ViewShellChanged(ScTabViewShell *)584cdf0e10cSrcweir void ScFormulaReferenceHelper::ViewShellChanged(ScTabViewShell* /* pScViewShell */)
585cdf0e10cSrcweir {
586cdf0e10cSrcweir 	enableInput( sal_False );
587cdf0e10cSrcweir 
588cdf0e10cSrcweir 	EnableSpreadsheets();
589cdf0e10cSrcweir }
EnableSpreadsheets(sal_Bool bFlag,sal_Bool bChilds)590cdf0e10cSrcweir void ScFormulaReferenceHelper::EnableSpreadsheets(sal_Bool bFlag, sal_Bool bChilds)
591cdf0e10cSrcweir {
592cdf0e10cSrcweir 	TypeId aType(TYPE(ScDocShell));
593cdf0e10cSrcweir 	ScDocShell* pDocShell = (ScDocShell*)SfxObjectShell::GetFirst(&aType);
594cdf0e10cSrcweir 	while( pDocShell )
595cdf0e10cSrcweir 	{
596cdf0e10cSrcweir 		SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
597cdf0e10cSrcweir 		while( pFrame )
598cdf0e10cSrcweir 		{
599cdf0e10cSrcweir 			//	#71577# enable everything except InPlace, including bean frames
600cdf0e10cSrcweir             if ( !pFrame->GetFrame().IsInPlace() )
601cdf0e10cSrcweir 			{
602cdf0e10cSrcweir 				SfxViewShell* p = pFrame->GetViewShell();
603cdf0e10cSrcweir 				ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,p);
604cdf0e10cSrcweir 				if(pViewSh!=NULL)
605cdf0e10cSrcweir 				{
606cdf0e10cSrcweir 					Window *pWin=pViewSh->GetWindow();
607cdf0e10cSrcweir 					if(pWin)
608cdf0e10cSrcweir 					{
609cdf0e10cSrcweir 						Window *pParent=pWin->GetParent();
610cdf0e10cSrcweir 						if(pParent)
611cdf0e10cSrcweir 						{
612cdf0e10cSrcweir 							pParent->EnableInput(bFlag,sal_False);
613cdf0e10cSrcweir 							if(bChilds)
614cdf0e10cSrcweir 								pViewSh->EnableRefInput(bFlag);
615cdf0e10cSrcweir 						}
616cdf0e10cSrcweir 					}
617cdf0e10cSrcweir 				}
618cdf0e10cSrcweir 			}
619cdf0e10cSrcweir 			pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
620cdf0e10cSrcweir 		}
621cdf0e10cSrcweir 
622cdf0e10cSrcweir 		pDocShell = (ScDocShell*)SfxObjectShell::GetNext(*pDocShell, &aType);
623cdf0e10cSrcweir 	}
624cdf0e10cSrcweir }
625cdf0e10cSrcweir 
626cdf0e10cSrcweir //----------------------------------------------------------------------------
627cdf0e10cSrcweir 
628cdf0e10cSrcweir 
629cdf0e10cSrcweir 
lcl_InvalidateWindows()630cdf0e10cSrcweir void lcl_InvalidateWindows()
631cdf0e10cSrcweir {
632cdf0e10cSrcweir 	TypeId aType(TYPE(ScDocShell));
633cdf0e10cSrcweir 	ScDocShell* pDocShell = (ScDocShell*)SfxObjectShell::GetFirst(&aType);
634cdf0e10cSrcweir 	while( pDocShell )
635cdf0e10cSrcweir 	{
636cdf0e10cSrcweir 		SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
637cdf0e10cSrcweir 		while( pFrame )
638cdf0e10cSrcweir 		{
639cdf0e10cSrcweir 			//	#71577# enable everything except InPlace, including bean frames
640cdf0e10cSrcweir             if ( !pFrame->GetFrame().IsInPlace() )
641cdf0e10cSrcweir 			{
642cdf0e10cSrcweir 				SfxViewShell* p = pFrame->GetViewShell();
643cdf0e10cSrcweir 				ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,p);
644cdf0e10cSrcweir 				if(pViewSh!=NULL)
645cdf0e10cSrcweir 				{
646cdf0e10cSrcweir 					Window *pWin=pViewSh->GetWindow();
647cdf0e10cSrcweir 					if(pWin)
648cdf0e10cSrcweir 					{
649cdf0e10cSrcweir 						Window *pParent=pWin->GetParent();
650cdf0e10cSrcweir 						if(pParent)
651cdf0e10cSrcweir 							pParent->Invalidate();
652cdf0e10cSrcweir 					}
653cdf0e10cSrcweir 				}
654cdf0e10cSrcweir 			}
655cdf0e10cSrcweir 			pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
656cdf0e10cSrcweir 		}
657cdf0e10cSrcweir 
658cdf0e10cSrcweir 		pDocShell = (ScDocShell*)SfxObjectShell::GetNext(*pDocShell, &aType);
659cdf0e10cSrcweir 	}
660cdf0e10cSrcweir }
661cdf0e10cSrcweir //----------------------------------------------------------------------------
662cdf0e10cSrcweir 
lcl_HideAllReferences()663cdf0e10cSrcweir void lcl_HideAllReferences()
664cdf0e10cSrcweir {
665cdf0e10cSrcweir 	TypeId aScType = TYPE(ScTabViewShell);
666cdf0e10cSrcweir 	SfxViewShell* pSh = SfxViewShell::GetFirst( &aScType );
667cdf0e10cSrcweir 	while ( pSh )
668cdf0e10cSrcweir 	{
669cdf0e10cSrcweir 		((ScTabViewShell*)pSh)->ClearHighlightRanges();
670cdf0e10cSrcweir 		pSh = SfxViewShell::GetNext( *pSh, &aScType );
671cdf0e10cSrcweir 	}
672cdf0e10cSrcweir }
673cdf0e10cSrcweir 
674cdf0e10cSrcweir //============================================================================
675cdf0e10cSrcweir //The class of ScAnyRefDlg is rewritten by PengYunQuan for Validity Cell Range Picker
676cdf0e10cSrcweir //	class ScRefHandler
677cdf0e10cSrcweir //----------------------------------------------------------------------------
678cdf0e10cSrcweir 
ScRefHandler(Window & rWindow,SfxBindings * pB,bool bBindRef)679cdf0e10cSrcweir ScRefHandler::ScRefHandler( Window &rWindow, SfxBindings* pB/*, SfxChildWindow* pCW,
680cdf0e10cSrcweir 						  Window* pParent, sal_uInt16 nResId*/, bool bBindRef )
681cdf0e10cSrcweir 	:	//SfxModelessDialog ( pB, pCW, pParent, ScResId( nResId ) ),
682cdf0e10cSrcweir 		m_rWindow( rWindow ),
683cdf0e10cSrcweir 		m_bInRefMode( false ),
684cdf0e10cSrcweir         m_aHelper(this,pB),
685cdf0e10cSrcweir 		pMyBindings( pB ),
686cdf0e10cSrcweir         pActiveWin(NULL)
687cdf0e10cSrcweir {
688cdf0e10cSrcweir 	m_aHelper.SetWindow(/*this*/&m_rWindow);
689cdf0e10cSrcweir 	if(m_rWindow.GetHelpId().getLength()==0)				//Hack, da im SfxModelessDialog die HelpId
690cdf0e10cSrcweir 		m_rWindow.SetHelpId(m_rWindow.GetUniqueId());	//fuer einen ModelessDialog entfernt und
691cdf0e10cSrcweir 									//in eine UniqueId gewandelt wird, machen
692cdf0e10cSrcweir 									//wir das an dieser Stelle rueckgaengig.
693cdf0e10cSrcweir 	aTimer.SetTimeout(200);
694cdf0e10cSrcweir 	aTimer.SetTimeoutHdl(LINK( this, ScRefHandler, UpdateFocusHdl));
695cdf0e10cSrcweir 
696cdf0e10cSrcweir 	if( bBindRef ) EnterRefMode();
697cdf0e10cSrcweir }
698cdf0e10cSrcweir 
EnterRefMode()699cdf0e10cSrcweir bool ScRefHandler::EnterRefMode()
700cdf0e10cSrcweir {
701cdf0e10cSrcweir 	if( m_bInRefMode ) return false;
702cdf0e10cSrcweir 
703cdf0e10cSrcweir 	SC_MOD()->InputEnterHandler();
704cdf0e10cSrcweir //    ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell();
705cdf0e10cSrcweir 
706cdf0e10cSrcweir     ScTabViewShell* pScViewShell = NULL;
707cdf0e10cSrcweir 
708cdf0e10cSrcweir 	// title has to be from the view that opened the dialog,
709cdf0e10cSrcweir 	// even if it's not the current view
710cdf0e10cSrcweir 
711cdf0e10cSrcweir 	SfxObjectShell* pParentDoc = NULL;
712cdf0e10cSrcweir 	if ( pMyBindings )
713cdf0e10cSrcweir 	{
714cdf0e10cSrcweir 		SfxDispatcher* pMyDisp = pMyBindings->GetDispatcher();
715cdf0e10cSrcweir 		if (pMyDisp)
716cdf0e10cSrcweir 		{
717cdf0e10cSrcweir 			SfxViewFrame* pMyViewFrm = pMyDisp->GetFrame();
718cdf0e10cSrcweir 			if (pMyViewFrm)
719cdf0e10cSrcweir             {
720cdf0e10cSrcweir                 pScViewShell = PTR_CAST( ScTabViewShell, pMyViewFrm->GetViewShell() );
721cdf0e10cSrcweir                 if( pScViewShell )
722cdf0e10cSrcweir 		            pScViewShell->UpdateInputHandler(sal_True);
723cdf0e10cSrcweir 				pParentDoc = pMyViewFrm->GetObjectShell();
724cdf0e10cSrcweir             }
725cdf0e10cSrcweir 		}
726cdf0e10cSrcweir 	}
727cdf0e10cSrcweir 	if ( !pParentDoc && pScViewShell )					// use current only if above fails
728cdf0e10cSrcweir 		pParentDoc = pScViewShell->GetObjectShell();
729cdf0e10cSrcweir 	if ( pParentDoc )
730cdf0e10cSrcweir 		aDocName = pParentDoc->GetTitle();
731cdf0e10cSrcweir 
732cdf0e10cSrcweir     ScInputHandler*	pInputHdl = SC_MOD()->GetInputHdl(pScViewShell);
733cdf0e10cSrcweir 
734cdf0e10cSrcweir 	DBG_ASSERT( pInputHdl, "Missing input handler :-/" );
735cdf0e10cSrcweir 
736cdf0e10cSrcweir 	if ( pInputHdl )
737cdf0e10cSrcweir 		pInputHdl->NotifyChange( NULL );
738cdf0e10cSrcweir 
739cdf0e10cSrcweir 	m_aHelper.enableInput( sal_False );
740cdf0e10cSrcweir 
741cdf0e10cSrcweir 	m_aHelper.EnableSpreadsheets();
742cdf0e10cSrcweir 
743cdf0e10cSrcweir     m_aHelper.Init();
744cdf0e10cSrcweir 
745cdf0e10cSrcweir 	m_aHelper.SetDispatcherLock( sal_True );
746cdf0e10cSrcweir 	//@Test
747cdf0e10cSrcweir 	//SFX_APPWINDOW->Disable(sal_True);	  //@BugID 54702
748cdf0e10cSrcweir 
749cdf0e10cSrcweir 	return m_bInRefMode = true;
750cdf0e10cSrcweir }
751cdf0e10cSrcweir 
752cdf0e10cSrcweir //----------------------------------------------------------------------------
753cdf0e10cSrcweir 
~ScRefHandler()754cdf0e10cSrcweir ScRefHandler::~ScRefHandler()
755cdf0e10cSrcweir {
756cdf0e10cSrcweir 	LeaveRefMode();
757cdf0e10cSrcweir }
758cdf0e10cSrcweir 
LeaveRefMode()759cdf0e10cSrcweir bool ScRefHandler::LeaveRefMode()
760cdf0e10cSrcweir {
761cdf0e10cSrcweir 	if( !m_bInRefMode ) return false;
762cdf0e10cSrcweir 
763cdf0e10cSrcweir 	lcl_HideAllReferences();
764cdf0e10cSrcweir 
765cdf0e10cSrcweir 	if( Dialog *pDlg = dynamic_cast<Dialog*>( static_cast<Window*>(*this) ) )
766cdf0e10cSrcweir 		pDlg->SetModalInputMode(sal_False);
767cdf0e10cSrcweir 	SetDispatcherLock( sal_False );			//! here and in DoClose ?
768cdf0e10cSrcweir 
769cdf0e10cSrcweir     ScTabViewShell* pScViewShell = ScTabViewShell::GetActiveViewShell();
770cdf0e10cSrcweir     if( pScViewShell )
771cdf0e10cSrcweir 		pScViewShell->UpdateInputHandler(sal_True);
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 	//SFX_APPWINDOW->Enable(sal_True,sal_True);
774cdf0e10cSrcweir 	lcl_InvalidateWindows();
775cdf0e10cSrcweir 
776cdf0e10cSrcweir 	m_bInRefMode = false;
777cdf0e10cSrcweir 	return true;
778cdf0e10cSrcweir }
779cdf0e10cSrcweir 
780cdf0e10cSrcweir //----------------------------------------------------------------------------
781cdf0e10cSrcweir 
782cdf0e10cSrcweir //SfxBindings& ScRefHandler::GetBindings()
783cdf0e10cSrcweir //{
784cdf0e10cSrcweir //	//!	SfxModelessDialog should allow access to pBindings pointer
785cdf0e10cSrcweir //
786cdf0e10cSrcweir //	return *pMyBindings;
787cdf0e10cSrcweir //}
788cdf0e10cSrcweir 
789cdf0e10cSrcweir //----------------------------------------------------------------------------
790cdf0e10cSrcweir 
SwitchToDocument()791cdf0e10cSrcweir void ScRefHandler::SwitchToDocument()
792cdf0e10cSrcweir {
793cdf0e10cSrcweir 	ScTabViewShell* pCurrent = ScTabViewShell::GetActiveViewShell();
794cdf0e10cSrcweir 	if (pCurrent)
795cdf0e10cSrcweir 	{
796cdf0e10cSrcweir 		SfxObjectShell* pObjSh = pCurrent->GetObjectShell();
797cdf0e10cSrcweir 		if ( pObjSh && pObjSh->GetTitle() == aDocName )
798cdf0e10cSrcweir 		{
799cdf0e10cSrcweir 			//	right document already visible -> nothing to do
800cdf0e10cSrcweir 			return;
801cdf0e10cSrcweir 		}
802cdf0e10cSrcweir 	}
803cdf0e10cSrcweir 
804cdf0e10cSrcweir 	TypeId aScType = TYPE(ScTabViewShell);
805cdf0e10cSrcweir 	SfxViewShell* pSh = SfxViewShell::GetFirst( &aScType );
806cdf0e10cSrcweir 	while ( pSh )
807cdf0e10cSrcweir 	{
808cdf0e10cSrcweir 		SfxObjectShell* pObjSh = pSh->GetObjectShell();
809cdf0e10cSrcweir 		if ( pObjSh && pObjSh->GetTitle() == aDocName )
810cdf0e10cSrcweir 		{
811cdf0e10cSrcweir 			//	switch to first TabViewShell for document
812cdf0e10cSrcweir 			((ScTabViewShell*)pSh)->SetActive();
813cdf0e10cSrcweir 			return;
814cdf0e10cSrcweir 		}
815cdf0e10cSrcweir 		pSh = SfxViewShell::GetNext( *pSh, &aScType );
816cdf0e10cSrcweir 	}
817cdf0e10cSrcweir }
818cdf0e10cSrcweir 
819cdf0e10cSrcweir //----------------------------------------------------------------------------
820cdf0e10cSrcweir 
IsDocAllowed(SfxObjectShell * pDocSh) const821cdf0e10cSrcweir sal_Bool ScRefHandler::IsDocAllowed(SfxObjectShell* pDocSh) const	// pDocSh may be 0
822cdf0e10cSrcweir {
823cdf0e10cSrcweir 	//	default: allow only same document (overridden in function dialog)
824cdf0e10cSrcweir 	String aCmpName;
825cdf0e10cSrcweir 	if ( pDocSh )
826cdf0e10cSrcweir 		aCmpName = pDocSh->GetTitle();
827cdf0e10cSrcweir 
828cdf0e10cSrcweir 	//	if aDocName isn't initialized, allow
829cdf0e10cSrcweir 	return ( aDocName.Len() == 0 || aDocName == aCmpName );
830cdf0e10cSrcweir }
831cdf0e10cSrcweir 
832cdf0e10cSrcweir //----------------------------------------------------------------------------
833cdf0e10cSrcweir 
IsRefInputMode() const834cdf0e10cSrcweir sal_Bool __EXPORT ScRefHandler::IsRefInputMode() const
835cdf0e10cSrcweir {
836cdf0e10cSrcweir 	return m_rWindow.IsVisible(); // nur wer sichtbar ist kann auch Referenzen bekommen
837cdf0e10cSrcweir }
838cdf0e10cSrcweir 
839cdf0e10cSrcweir //----------------------------------------------------------------------------
840cdf0e10cSrcweir 
DoClose(sal_uInt16 nId)841cdf0e10cSrcweir sal_Bool __EXPORT ScRefHandler::DoClose( sal_uInt16 nId )
842cdf0e10cSrcweir {
843cdf0e10cSrcweir     m_aHelper.DoClose(nId);
844cdf0e10cSrcweir 	return sal_True;
845cdf0e10cSrcweir }
846cdf0e10cSrcweir 
SetDispatcherLock(sal_Bool bLock)847cdf0e10cSrcweir void ScRefHandler::SetDispatcherLock( sal_Bool bLock )
848cdf0e10cSrcweir {
849cdf0e10cSrcweir 	m_aHelper.SetDispatcherLock( bLock );
850cdf0e10cSrcweir }
851cdf0e10cSrcweir 
852cdf0e10cSrcweir //----------------------------------------------------------------------------
853cdf0e10cSrcweir 
ViewShellChanged(ScTabViewShell * pScViewShell)854cdf0e10cSrcweir void ScRefHandler::ViewShellChanged(ScTabViewShell*  pScViewShell )
855cdf0e10cSrcweir {
856cdf0e10cSrcweir 	m_aHelper.ViewShellChanged(pScViewShell);
857cdf0e10cSrcweir }
858cdf0e10cSrcweir 
859cdf0e10cSrcweir //----------------------------------------------------------------------------
860cdf0e10cSrcweir 
AddRefEntry()861cdf0e10cSrcweir void ScRefHandler::AddRefEntry()
862cdf0e10cSrcweir {
863cdf0e10cSrcweir 	//	wenn nicht ueberladen, gibt es keine Mehrfach-Referenzen
864cdf0e10cSrcweir }
865cdf0e10cSrcweir 
866cdf0e10cSrcweir //----------------------------------------------------------------------------
867cdf0e10cSrcweir 
IsTableLocked() const868cdf0e10cSrcweir sal_Bool __EXPORT ScRefHandler::IsTableLocked() const
869cdf0e10cSrcweir {
870cdf0e10cSrcweir 	// per Default kann bei Referenzeingabe auch die Tabelle umgeschaltet werden
871cdf0e10cSrcweir 
872cdf0e10cSrcweir 	return sal_False;
873cdf0e10cSrcweir }
874cdf0e10cSrcweir 
875cdf0e10cSrcweir //----------------------------------------------------------------------------
876cdf0e10cSrcweir //
877cdf0e10cSrcweir //	RefInputStart/Done: Zoom-In (AutoHide) auf einzelnes Feld
878cdf0e10cSrcweir //	(per Button oder Bewegung)
879cdf0e10cSrcweir //
880cdf0e10cSrcweir //----------------------------------------------------------------------------
881cdf0e10cSrcweir 
RefInputStart(formula::RefEdit * pEdit,formula::RefButton * pButton)882cdf0e10cSrcweir void ScRefHandler::RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton )
883cdf0e10cSrcweir {
884cdf0e10cSrcweir     m_aHelper.RefInputStart( pEdit, pButton );
885cdf0e10cSrcweir }
886cdf0e10cSrcweir 
887cdf0e10cSrcweir 
ToggleCollapsed(formula::RefEdit * pEdit,formula::RefButton * pButton)888cdf0e10cSrcweir void ScRefHandler::ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton )
889cdf0e10cSrcweir {
890cdf0e10cSrcweir     m_aHelper.ToggleCollapsed( pEdit, pButton );
891cdf0e10cSrcweir }
892cdf0e10cSrcweir 
893cdf0e10cSrcweir //The two following function is commentted out by PengYunQuan for Validity Cell Range Picker
894cdf0e10cSrcweir //long ScAnyRefDlg::PreNotify( NotifyEvent& rNEvt )
895cdf0e10cSrcweir //{
896cdf0e10cSrcweir //	sal_uInt16 nSwitch=rNEvt.GetType();
897cdf0e10cSrcweir //	if(nSwitch==EVENT_GETFOCUS)
898cdf0e10cSrcweir //	{
899cdf0e10cSrcweir //		pActiveWin=rNEvt.GetWindow();
900cdf0e10cSrcweir //	}
901cdf0e10cSrcweir //	return SfxModelessDialog::PreNotify(rNEvt);
902cdf0e10cSrcweir //}
903cdf0e10cSrcweir //
904cdf0e10cSrcweir //void ScAnyRefDlg::StateChanged( StateChangedType nStateChange )
905cdf0e10cSrcweir //{
906cdf0e10cSrcweir //	SfxModelessDialog::StateChanged( nStateChange );
907cdf0e10cSrcweir //
908cdf0e10cSrcweir //	if(nStateChange == STATE_CHANGE_VISIBLE)
909cdf0e10cSrcweir //	{
910cdf0e10cSrcweir //		if(IsVisible())
911cdf0e10cSrcweir //		{
912cdf0e10cSrcweir //			m_aHelper.enableInput( sal_False );
913cdf0e10cSrcweir //			m_aHelper.EnableSpreadsheets();
914cdf0e10cSrcweir //			m_aHelper.SetDispatcherLock( sal_True );
915cdf0e10cSrcweir //			aTimer.Start();
916cdf0e10cSrcweir //		}
917cdf0e10cSrcweir //		else
918cdf0e10cSrcweir //		{
919cdf0e10cSrcweir //			m_aHelper.enableInput( sal_True );
920cdf0e10cSrcweir //			m_aHelper.SetDispatcherLock( sal_False );			//! here and in DoClose ?
921cdf0e10cSrcweir //		}
922cdf0e10cSrcweir //	}
923cdf0e10cSrcweir //}
924cdf0e10cSrcweir 
925cdf0e10cSrcweir #if defined( _MSC_VER )
926cdf0e10cSrcweir #define INTRODUCE_TEMPLATE
927cdf0e10cSrcweir #else
928cdf0e10cSrcweir #define INTRODUCE_TEMPLATE	template <>
929cdf0e10cSrcweir #endif
930cdf0e10cSrcweir 
931cdf0e10cSrcweir #define IMPL_TWINDOW_PRENOTIFY( TWindow,bBindRef )	\
932cdf0e10cSrcweir INTRODUCE_TEMPLATE long ScRefHdlrImplBase<TWindow,bBindRef>::PreNotify( NotifyEvent& rNEvt )\
933cdf0e10cSrcweir {\
934cdf0e10cSrcweir 	if( bBindRef || m_bInRefMode )\
935cdf0e10cSrcweir 	{\
936cdf0e10cSrcweir 		sal_uInt16 nSwitch=rNEvt.GetType();\
937cdf0e10cSrcweir 		if(nSwitch==EVENT_GETFOCUS)\
938cdf0e10cSrcweir 		{\
939cdf0e10cSrcweir 			pActiveWin=rNEvt.GetWindow();\
940cdf0e10cSrcweir 		}\
941cdf0e10cSrcweir 	}\
942cdf0e10cSrcweir 	return TWindow::PreNotify(rNEvt);\
943cdf0e10cSrcweir }
944cdf0e10cSrcweir 
945cdf0e10cSrcweir #define IMPL_TWINDOW_STATECHANGED( TWindow,bBindRef )	\
946cdf0e10cSrcweir INTRODUCE_TEMPLATE void ScRefHdlrImplBase<TWindow,bBindRef>::StateChanged( StateChangedType nStateChange )\
947cdf0e10cSrcweir {\
948cdf0e10cSrcweir 	TWindow::StateChanged( nStateChange );\
949cdf0e10cSrcweir \
950cdf0e10cSrcweir 	if( !bBindRef && !m_bInRefMode ) return;\
951cdf0e10cSrcweir 	\
952cdf0e10cSrcweir 	if(nStateChange == STATE_CHANGE_VISIBLE)\
953cdf0e10cSrcweir 	{\
954cdf0e10cSrcweir 		if(m_rWindow.IsVisible())\
955cdf0e10cSrcweir 		{\
956cdf0e10cSrcweir 			m_aHelper.enableInput( sal_False );\
957cdf0e10cSrcweir 			m_aHelper.EnableSpreadsheets();\
958cdf0e10cSrcweir 			m_aHelper.SetDispatcherLock( sal_True );\
959cdf0e10cSrcweir 			aTimer.Start();\
960cdf0e10cSrcweir 		}\
961cdf0e10cSrcweir 		else\
962cdf0e10cSrcweir 		{\
963cdf0e10cSrcweir 			m_aHelper.enableInput( sal_True );\
964cdf0e10cSrcweir 			m_aHelper.SetDispatcherLock( sal_False );			/*//! here and in DoClose ?*/\
965cdf0e10cSrcweir 		}\
966cdf0e10cSrcweir 	}\
967cdf0e10cSrcweir }
968cdf0e10cSrcweir 
IMPL_TWINDOW_PRENOTIFY(SfxModelessDialog,true)969cdf0e10cSrcweir IMPL_TWINDOW_PRENOTIFY( SfxModelessDialog, true )
970cdf0e10cSrcweir IMPL_TWINDOW_PRENOTIFY( SfxTabDialog, false )
971cdf0e10cSrcweir IMPL_TWINDOW_STATECHANGED( SfxModelessDialog, true )
972cdf0e10cSrcweir IMPL_TWINDOW_STATECHANGED( SfxTabDialog, false )
973cdf0e10cSrcweir 
974cdf0e10cSrcweir IMPL_LINK( ScRefHandler, UpdateFocusHdl, Timer*, EMPTYARG )
975cdf0e10cSrcweir {
976cdf0e10cSrcweir 	if (pActiveWin)
977cdf0e10cSrcweir 	{
978cdf0e10cSrcweir 		pActiveWin->GrabFocus();
979cdf0e10cSrcweir 	}
980cdf0e10cSrcweir 	return 0;
981cdf0e10cSrcweir }
982cdf0e10cSrcweir // -----------------------------------------------------------------------------
ParseWithNames(ScRangeList & rRanges,const String & rStr,ScDocument * pDoc)983cdf0e10cSrcweir bool ScRefHandler::ParseWithNames( ScRangeList& rRanges, const String& rStr, ScDocument* pDoc )
984cdf0e10cSrcweir {
985cdf0e10cSrcweir     return m_aHelper.ParseWithNames( rRanges, rStr, pDoc );
986cdf0e10cSrcweir }
987cdf0e10cSrcweir // -----------------------------------------------------------------------------
HideReference(sal_Bool bDoneRefMode)988cdf0e10cSrcweir void ScRefHandler::HideReference( sal_Bool bDoneRefMode )
989cdf0e10cSrcweir {
990cdf0e10cSrcweir     m_aHelper.HideReference( bDoneRefMode );
991cdf0e10cSrcweir }
992cdf0e10cSrcweir // -----------------------------------------------------------------------------
ShowReference(const XubString & rStr)993cdf0e10cSrcweir void ScRefHandler::ShowReference( const XubString& rStr )
994cdf0e10cSrcweir {
995cdf0e10cSrcweir     m_aHelper.ShowReference( rStr );
996cdf0e10cSrcweir }
997cdf0e10cSrcweir // -----------------------------------------------------------------------------
ReleaseFocus(formula::RefEdit * pEdit,formula::RefButton * pButton)998cdf0e10cSrcweir void ScRefHandler::ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton )
999cdf0e10cSrcweir {
1000cdf0e10cSrcweir     m_aHelper.ReleaseFocus( pEdit,pButton );
1001cdf0e10cSrcweir }
1002cdf0e10cSrcweir //----------------------------------------------------------------------------
RefInputDone(sal_Bool bForced)1003cdf0e10cSrcweir void ScRefHandler::RefInputDone( sal_Bool bForced )
1004cdf0e10cSrcweir {
1005cdf0e10cSrcweir     m_aHelper.RefInputDone( bForced );
1006cdf0e10cSrcweir }
1007cdf0e10cSrcweir 
1008