xref: /aoo41x/main/sc/source/ui/formdlg/formula.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 
33 //----------------------------------------------------------------------------
34 
35 #include "scitems.hxx"
36 #include <sfx2/dispatch.hxx>
37 #include <sfx2/docfile.hxx>
38 #include <sfx2/objsh.hxx>
39 #include <svl/zforlist.hxx>
40 #include <svl/stritem.hxx>
41 #include <svtools/svtreebx.hxx>
42 #include <sfx2/viewfrm.hxx>
43 #include <vcl/svapp.hxx>
44 #include <vcl/mnemonic.hxx>
45 #include <unotools/charclass.hxx>
46 #include <tools/urlobj.hxx>
47 #include <formula/formulahelper.hxx>
48 #include <formula/IFunctionDescription.hxx>
49 
50 #include "tokenuno.hxx"
51 #include "formula.hxx"
52 #include "formdata.hxx"
53 #include "globstr.hrc"
54 #include "scresid.hxx"
55 #include "reffact.hxx"
56 #include "document.hxx"
57 #include "cell.hxx"
58 #include "scmod.hxx"
59 #include "inputhdl.hxx"
60 #include "tabvwsh.hxx"
61 #include "appoptio.hxx"
62 #include "docsh.hxx"
63 #include "funcdesc.hxx"
64 #include "formula/token.hxx"
65 #include "tokenarray.hxx"
66 #include "sc.hrc"
67 #include "servuno.hxx"
68 #include "unonames.hxx"
69 #include "externalrefmgr.hxx"
70 
71 #include <com/sun/star/table/CellAddress.hpp>
72 
73 //============================================================================
74 using namespace formula;
75 using namespace com::sun::star;
76 
77 ScDocument*	ScFormulaDlg::pDoc = NULL;
78 ScAddress ScFormulaDlg::aCursorPos;
79 
80 
81 
82 //	--------------------------------------------------------------------------
83 //		Initialisierung / gemeinsame Funktionen  fuer Dialog
84 //	--------------------------------------------------------------------------
85 
86 ScFormulaDlg::ScFormulaDlg( SfxBindings* pB, SfxChildWindow* pCW,
87 									Window* pParent, ScViewData* pViewData,formula::IFunctionManager* _pFunctionMgr )
88     : formula::FormulaDlg( pB, pCW, pParent, true,true,true,this, _pFunctionMgr,this)
89     , m_aHelper(this,pB)
90 {
91     m_aHelper.SetWindow(this);
92     ScModule* pScMod = SC_MOD();
93     pScMod->InputEnterHandler();
94     ScTabViewShell* pScViewShell = NULL;
95 
96 	// title has to be from the view that opened the dialog,
97 	// even if it's not the current view
98 
99 	SfxObjectShell* pParentDoc = NULL;
100 	if ( pB )
101 	{
102 		SfxDispatcher* pMyDisp = pB->GetDispatcher();
103 		if (pMyDisp)
104 		{
105 			SfxViewFrame* pMyViewFrm = pMyDisp->GetFrame();
106 			if (pMyViewFrm)
107             {
108                 pScViewShell = PTR_CAST( ScTabViewShell, pMyViewFrm->GetViewShell() );
109                 if( pScViewShell )
110 		            pScViewShell->UpdateInputHandler(sal_True);
111 				pParentDoc = pMyViewFrm->GetObjectShell();
112             }
113 		}
114 	}
115 	//if ( !pParentDoc && pScViewShell )					// use current only if above fails
116 	//	pParentDoc = pScViewShell->GetObjectShell();
117 	//if ( pParentDoc )
118 	//	aDocName = pParentDoc->GetTitle();
119 
120     if ( pDoc == NULL )
121         pDoc = pViewData->GetDocument();
122     m_xParser.set(ScServiceProvider::MakeInstance(SC_SERVICE_FORMULAPARS,(ScDocShell*)pDoc->GetDocumentShell()),uno::UNO_QUERY);
123     uno::Reference< beans::XPropertySet> xSet(m_xParser,uno::UNO_QUERY);
124     xSet->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_UNO_COMPILEFAP)),uno::makeAny(sal_True));
125 
126     m_xOpCodeMapper.set(ScServiceProvider::MakeInstance(SC_SERVICE_OPCODEMAPPER,(ScDocShell*)pDoc->GetDocumentShell()),uno::UNO_QUERY);
127 
128     ScInputHandler*	pInputHdl = SC_MOD()->GetInputHdl(pScViewShell);
129 
130 	DBG_ASSERT( pInputHdl, "Missing input handler :-/" );
131 
132 	if ( pInputHdl )
133 		pInputHdl->NotifyChange( NULL );
134 
135 	m_aHelper.enableInput( sal_False );
136 	m_aHelper.EnableSpreadsheets();
137     m_aHelper.Init();
138 	m_aHelper.SetDispatcherLock( sal_True );
139 
140     notifyChange();
141     fill();
142 
143 	ScFormEditData* pData = pScMod->GetFormEditData();
144 	if (!pData)
145 	{
146 		//Nun wird es Zeit den Inputhandler festzulegen
147 		pScMod->SetRefInputHdl(pScMod->GetInputHdl());
148 
149 		pDoc = pViewData->GetDocument();
150 		SCCOL nCol = pViewData->GetCurX();
151 		SCROW nRow = pViewData->GetCurY();
152 		SCTAB nTab = pViewData->GetTabNo();
153 		aCursorPos = ScAddress( nCol, nRow, nTab );
154 
155 		pScMod->InitFormEditData();								// neu anlegen
156         pData = pScMod->GetFormEditData();
157 		pData->SetInputHandler(pScMod->GetInputHdl());
158 		pData->SetDocShell(pViewData->GetDocShell());
159 
160 		DBG_ASSERT(pData,"FormEditData ist nicht da");
161 
162         formula::FormulaDlgMode eMode = FORMULA_FORMDLG_FORMULA;			// Default...
163 
164 		//	Formel vorhanden? Dann editieren
165 
166 		String aFormula;
167 		pDoc->GetFormula( nCol, nRow, nTab, aFormula );
168 		sal_Bool bEdit   = ( aFormula.Len() > 1 );
169         sal_Bool bMatrix = sal_False;
170 		if ( bEdit )
171 		{
172             bMatrix = CheckMatrix(aFormula);
173 
174 			xub_StrLen nFStart = 0;
175 			xub_StrLen nFEnd   = 0;
176 			if ( GetFormulaHelper().GetNextFunc( aFormula, sal_False, nFStart, &nFEnd) )
177 			{
178 				pScMod->InputReplaceSelection( aFormula );
179 				pScMod->InputSetSelection( nFStart, nFEnd );
180                 xub_StrLen PrivStart, PrivEnd;
181 				pScMod->InputGetSelection( PrivStart, PrivEnd);
182 
183                 eMode = SetMeText(pScMod->InputGetFormulaStr(),PrivStart, PrivEnd,bMatrix,sal_True,sal_True);
184 				pData->SetFStart( nFStart );
185 			}
186 			else
187 				bEdit = sal_False;
188 		}
189 
190 		if ( !bEdit )
191 		{
192 			String aNewFormula = '=';
193 			if ( aFormula.Len() > 0 && aFormula.GetChar(0) == '=' )
194 				aNewFormula=aFormula;
195 
196 			pScMod->InputReplaceSelection( aNewFormula );
197 			pScMod->InputSetSelection( 1, aNewFormula.Len()+1 );
198             xub_StrLen PrivStart, PrivEnd;
199 			pScMod->InputGetSelection( PrivStart, PrivEnd);
200             SetMeText(pScMod->InputGetFormulaStr(),PrivStart, PrivEnd,bMatrix,sal_False,sal_False);
201 
202 			pData->SetFStart( 1 );		// hinter dem "="
203 		}
204 
205 		pData->SetMode( (sal_uInt16) eMode );
206 		String rStrExp = GetMeText();
207 
208 		pCell = new ScFormulaCell( pDoc, aCursorPos, rStrExp );
209 
210 		Update(rStrExp);
211     } // if (!pData)
212 
213 }
214 
215 void ScFormulaDlg::notifyChange()
216 {
217 	ScModule* pScMod = SC_MOD();
218 
219 	ScInputHandler*	pInputHdl = pScMod->GetInputHdl();
220 	if ( pInputHdl )
221 		pInputHdl->NotifyChange( NULL );
222 }
223 // -----------------------------------------------------------------------------
224 void ScFormulaDlg::fill()
225 {
226     ScModule* pScMod = SC_MOD();
227 	ScFormEditData* pData = pScMod->GetFormEditData();
228     notifyChange();
229 	String rStrExp;
230 	if (pData)
231 	{
232 		//	Daten schon vorhanden -> Zustand wiederherstellen (nach Umschalten)
233 		//	pDoc und aCursorPos nicht neu initialisieren
234 		//pDoc = pViewData->GetDocument();
235 		if(IsInputHdl(pData->GetInputHandler()))
236 		{
237 			pScMod->SetRefInputHdl(pData->GetInputHandler());
238 		}
239 		else
240 		{
241 			PtrTabViewShell pTabViewShell;
242 			ScInputHandler*	pInputHdl = GetNextInputHandler(pData->GetDocShell(),&pTabViewShell);
243 
244 			if ( pInputHdl == NULL ) //DocShell hat keinen InputHandler mehr,
245 			{					//hat der Anwender halt Pech gehabt.
246 				disableOk();
247 				pInputHdl = pScMod->GetInputHdl();
248 			}
249 			else
250 			{
251 				pInputHdl->SetRefViewShell(pTabViewShell);
252 			}
253 			pScMod->SetRefInputHdl(pInputHdl);
254 			pData->SetInputHandler(pInputHdl);
255 		}
256 
257         String aOldFormulaTmp(pScMod->InputGetFormulaStr());
258         pScMod->InputSetSelection( 0, aOldFormulaTmp.Len());
259 
260 		rStrExp=pData->GetUndoStr();
261 		pScMod->InputReplaceSelection(rStrExp);
262 
263         SetMeText(rStrExp);
264 
265 		pCell = new ScFormulaCell( pDoc, aCursorPos, rStrExp );
266 
267         Update();
268 		// Jetzt nochmals zurueckschalten, da evtl. neues Doc geoeffnet wurde!
269 		pScMod->SetRefInputHdl(NULL);
270 	}
271 }
272 
273 __EXPORT ScFormulaDlg::~ScFormulaDlg()
274 {
275 	ScModule* pScMod = SC_MOD();
276 	ScFormEditData* pData = pScMod->GetFormEditData();
277 
278 	if (pData) // wird nicht ueber Close zerstoert;
279 	{
280 		//Referenz Inputhandler zuruecksetzen
281 		pScMod->SetRefInputHdl(NULL);
282 	} // if (pData) // wird nicht ueber Close zerstoert;
283 
284 	delete pCell;
285 }
286 
287 sal_Bool ScFormulaDlg::IsInputHdl(ScInputHandler* pHdl)
288 {
289 	sal_Bool bAlive = sal_False;
290 
291 	//	gehoert der InputHandler zu irgendeiner ViewShell ?
292 
293 	TypeId aScType = TYPE(ScTabViewShell);
294 	SfxViewShell* pSh = SfxViewShell::GetFirst( &aScType );
295 	while ( pSh && !bAlive )
296 	{
297 		if (((ScTabViewShell*)pSh)->GetInputHandler() == pHdl)
298 			bAlive = sal_True;
299 		pSh = SfxViewShell::GetNext( *pSh, &aScType );
300 	}
301 
302 	return bAlive;
303 
304 }
305 
306 ScInputHandler* ScFormulaDlg::GetNextInputHandler(ScDocShell* pDocShell,PtrTabViewShell* ppViewSh)
307 {
308 	ScInputHandler* pHdl=NULL;
309 
310 	SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
311 	while( pFrame && pHdl==NULL)
312 	{
313 		SfxViewShell* p = pFrame->GetViewShell();
314 		ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,p);
315 		if(pViewSh!=NULL)
316 		{
317 			pHdl=pViewSh->GetInputHandler();
318 			if(ppViewSh!=NULL) *ppViewSh=pViewSh;
319 		}
320 		pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
321 	}
322 
323 
324 	return pHdl;
325 }
326 
327 
328 sal_Bool __EXPORT ScFormulaDlg::Close()
329 {
330 	DoEnter(sal_False);
331 	return sal_True;
332 }
333 
334 //	--------------------------------------------------------------------------
335 //							Funktionen fuer rechte Seite
336 //	--------------------------------------------------------------------------
337 bool ScFormulaDlg::calculateValue( const String& rStrExp, String& rStrResult )
338 {
339 	sal_Bool bResult = sal_True;
340 
341     ::std::auto_ptr<ScFormulaCell> pFCell( new ScFormulaCell( pDoc, aCursorPos, rStrExp ) );
342 
343 	// #35521# HACK! um bei ColRowNames kein #REF! zu bekommen,
344 	// wenn ein Name eigentlich als Bereich in die Gesamt-Formel
345 	// eingefuegt wird, bei der Einzeldarstellung aber als
346 	// single-Zellbezug interpretiert wird
347 	sal_Bool bColRowName = pCell->HasColRowName();
348 	if ( bColRowName )
349 	{
350 		// ColRowName im RPN-Code?
351 		if ( pCell->GetCode()->GetCodeLen() <= 1 )
352 		{	// ==1: einzelner ist als Parameter immer Bereich
353 			// ==0: es waere vielleicht einer, wenn..
354 			String aBraced( '(' );
355 			aBraced += rStrExp;
356 			aBraced += ')';
357 			pFCell.reset( new ScFormulaCell( pDoc, aCursorPos, aBraced ) );
358 		}
359 		else
360 			bColRowName = sal_False;
361 	}
362 
363 	sal_uInt16 nErrCode = pFCell->GetErrCode();
364 	if ( nErrCode == 0 )
365 	{
366 		SvNumberFormatter& aFormatter = *(pDoc->GetFormatTable());
367 		Color* pColor;
368 		if ( pFCell->IsValue() )
369 		{
370 			double n = pFCell->GetValue();
371 			sal_uLong nFormat = aFormatter.GetStandardFormat( n, 0,
372 							pFCell->GetFormatType(), ScGlobal::eLnge );
373 			aFormatter.GetOutputString( n, nFormat,
374 										rStrResult, &pColor );
375 		}
376 		else
377 		{
378 			String aStr;
379 
380 			pFCell->GetString( aStr );
381 			sal_uLong nFormat = aFormatter.GetStandardFormat(
382 							pFCell->GetFormatType(), ScGlobal::eLnge);
383 			aFormatter.GetOutputString( aStr, nFormat,
384 										rStrResult, &pColor );
385 		}
386 
387 		ScRange aTestRange;
388 		if ( bColRowName || (aTestRange.Parse(rStrExp) & SCA_VALID) )
389 			rStrResult.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " ..." ));
390 			// Bereich
391 	}
392 	else
393 		rStrResult += ScGlobal::GetErrorString(nErrCode);
394 
395 	if(!isUserMatrix() && pFCell->GetMatrixFlag())
396 	{
397 		CheckMatrix();
398 	}
399 
400 	return bResult;
401 }
402 
403 
404 
405 //	virtuelle Methoden von ScAnyRefDlg:
406 void ScFormulaDlg::RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton )
407 {
408     ::std::pair<formula::RefButton*,formula::RefEdit*> aPair = RefInputStartBefore( pEdit, pButton );
409     m_aHelper.RefInputStart( aPair.second, aPair.first);
410     RefInputStartAfter( aPair.second, aPair.first );
411 }
412 void ScFormulaDlg::RefInputDone( sal_Bool bForced )
413 {
414     m_aHelper.RefInputDone( bForced );
415     RefInputDoneAfter( bForced );
416 }
417 
418 void ScFormulaDlg::SetReference( const ScRange& rRef, ScDocument* pRefDoc )
419 {
420     const IFunctionDescription* pFunc = getCurrentFunctionDescription();
421 	if ( pFunc && pFunc->getSuppressedArgumentCount() > 0 )
422 	{
423         Selection theSel;
424 		sal_Bool bRefNull = UpdateParaWin(theSel);
425 
426 		if ( rRef.aStart != rRef.aEnd && bRefNull )
427 		{
428 			RefInputStart(GetActiveEdit());
429 		}
430 
431         String		aRefStr;
432 		sal_Bool bOtherDoc = ( pRefDoc != pDoc && pRefDoc->GetDocumentShell()->HasName() );
433 		if ( bOtherDoc )
434 		{
435 			//	Referenz auf anderes Dokument - wie inputhdl.cxx
436 
437 			DBG_ASSERT(rRef.aStart.Tab()==rRef.aEnd.Tab(), "nStartTab!=nEndTab");
438 
439 			String aTmp;
440 			rRef.Format( aTmp, SCA_VALID|SCA_TAB_3D, pRefDoc );		// immer 3d
441 
442 			SfxObjectShell* pObjSh = pRefDoc->GetDocumentShell();
443 
444             // #i75893# convert escaped URL of the document to something user friendly
445 //           String aFileName = pObjSh->GetMedium()->GetName();
446             String aFileName = pObjSh->GetMedium()->GetURLObject().GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS );
447 
448 			aRefStr = '\'';
449 			aRefStr += aFileName;
450 			aRefStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "'#" ));
451 			aRefStr += aTmp;
452 		}
453 		else
454 		{
455 			sal_uInt16 nFmt = ( rRef.aStart.Tab() == aCursorPos.Tab() )
456 								? SCA_VALID
457 								: SCA_VALID | SCA_TAB_3D;
458 			rRef.Format( aRefStr, nFmt, pRefDoc, pRefDoc->GetAddressConvention() );
459 		}
460 
461 		UpdateParaWin(theSel,aRefStr);
462 	}
463 }
464 
465 sal_Bool ScFormulaDlg::IsRefInputMode() const
466 {
467     const IFunctionDescription*	pDesc = getCurrentFunctionDescription();
468 	sal_Bool bRef = (pDesc && (pDesc->getSuppressedArgumentCount() > 0)) && (pDoc!=NULL);
469 	return bRef;
470 }
471 
472 sal_Bool ScFormulaDlg::IsDocAllowed(SfxObjectShell* pDocSh) const
473 {
474 	//	not allowed: different from this doc, and no name
475 	//	pDocSh is always a ScDocShell
476 	if ( pDocSh && ((ScDocShell*)pDocSh)->GetDocument() != pDoc && !pDocSh->HasName() )
477 		return sal_False;
478 
479 	return sal_True;		// everything else is allowed
480 }
481 
482 void ScFormulaDlg::SetActive()
483 {
484     const IFunctionDescription* pFunc = getCurrentFunctionDescription();
485 	if ( pFunc && pFunc->getSuppressedArgumentCount() > 0 )
486 	{
487 		RefInputDone();
488         SetEdSelection();
489 	}
490 }
491 
492 void ScFormulaDlg::SaveLRUEntry(const ScFuncDesc* pFuncDescP)
493 {
494 	if (pFuncDescP && pFuncDescP->nFIndex!=0)
495 	{
496 		ScModule* pScMod = SC_MOD();
497 		pScMod->InsertEntryToLRUList(pFuncDescP->nFIndex);
498 	}
499 }
500 
501 void ScFormulaDlg::doClose(sal_Bool /*_bOk*/)
502 {
503     m_aHelper.DoClose( ScFormulaDlgWrapper::GetChildWindowId() );
504 }
505 void ScFormulaDlg::insertEntryToLRUList(const formula::IFunctionDescription*	_pDesc)
506 {
507     const ScFuncDesc* pDesc = dynamic_cast<const ScFuncDesc*>(_pDesc);
508     SaveLRUEntry(pDesc);
509 }
510 void ScFormulaDlg::showReference(const String& _sFormula)
511 {
512     ShowReference(_sFormula);
513 }
514 void ScFormulaDlg::ShowReference(const String& _sFormula)
515 {
516     m_aHelper.ShowReference(_sFormula);
517 }
518 void ScFormulaDlg::HideReference( sal_Bool bDoneRefMode )
519 {
520     m_aHelper.HideReference(bDoneRefMode);
521 }
522 void ScFormulaDlg::ViewShellChanged( ScTabViewShell* pScViewShell )
523 {
524     m_aHelper.ViewShellChanged( pScViewShell );
525 }
526 void ScFormulaDlg::AddRefEntry( )
527 {
528 
529 }
530 sal_Bool ScFormulaDlg::IsTableLocked( ) const
531 {
532     // per Default kann bei Referenzeingabe auch die Tabelle umgeschaltet werden
533     return sal_False;
534 }
535 void ScFormulaDlg::ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton)
536 {
537     m_aHelper.ToggleCollapsed(pEdit,pButton);
538 }
539 void ScFormulaDlg::ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton)
540 {
541     m_aHelper.ReleaseFocus(pEdit,pButton);
542 }
543 void ScFormulaDlg::dispatch(sal_Bool _bOK,sal_Bool _bMartixChecked)
544 {
545     SfxBoolItem	  aRetItem( SID_DLG_RETOK, _bOK );
546 	SfxBoolItem	  aMatItem( SID_DLG_MATRIX, _bMartixChecked );
547 	SfxStringItem aStrItem( SCITEM_STRING, getCurrentFormula() );
548 
549 	// Wenn durch Dokument-Umschalterei die Eingabezeile weg war/ist,
550 	// ist der String leer. Dann nicht die alte Formel loeschen.
551 	if ( !aStrItem.GetValue().Len() )
552 		aRetItem.SetValue( sal_False );		// sal_False = Cancel
553 
554 	m_aHelper.SetDispatcherLock( sal_False ); // Modal-Modus ausschalten
555 
556     clear();
557 
558 	GetBindings().GetDispatcher()->Execute( SID_INS_FUNCTION,
559 							  SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD,
560 							  &aRetItem, &aStrItem, &aMatItem, 0L );
561 }
562 void ScFormulaDlg::setDispatcherLock( sal_Bool bLock )
563 {
564     m_aHelper.SetDispatcherLock( bLock );
565 }
566 void ScFormulaDlg::setReferenceInput(const formula::FormEditData* _pData)
567 {
568     ScModule* pScMod = SC_MOD();
569     ScFormEditData* pData = const_cast<ScFormEditData*>(dynamic_cast<const ScFormEditData*>(_pData));
570     pScMod->SetRefInputHdl(pData->GetInputHandler());
571 }
572 void ScFormulaDlg::deleteFormData()
573 {
574     ScModule* pScMod = SC_MOD();
575     pScMod->ClearFormEditData();		// pData wird ungueltig!
576 }
577 void ScFormulaDlg::clear()
578 {
579     pDoc = NULL;
580 
581 	//Referenz Inputhandler zuruecksetzen
582     ScModule* pScMod = SC_MOD();
583 	pScMod->SetRefInputHdl(NULL);
584 
585 	// Enable() der Eingabezeile erzwingen:
586     ScTabViewShell* pScViewShell = PTR_CAST(ScTabViewShell, SfxViewShell::Current());
587 	if ( pScViewShell )
588 		pScViewShell->UpdateInputHandler();
589 }
590 void ScFormulaDlg::switchBack()
591 {
592     ScModule* pScMod = SC_MOD();
593     // auf das Dokument zurueckschalten
594 	// (noetig, weil ein fremdes oben sein kann - #34222#)
595 	ScInputHandler* pHdl = pScMod->GetInputHdl();
596 	if ( pHdl )
597 	{
598 		pHdl->ViewShellGone(NULL);	// -> aktive View neu holen
599 		pHdl->ShowRefFrame();
600 	}
601 
602 	// aktuelle Tabelle ggF. restaurieren (wg. Maus-RefInput)
603 	ScTabViewShell* pScViewShell = PTR_CAST(ScTabViewShell, SfxViewShell::Current());
604 	if ( pScViewShell )
605 	{
606 		ScViewData* pVD=pScViewShell->GetViewData();
607 		SCTAB nExecTab = aCursorPos.Tab();
608 		if ( nExecTab != pVD->GetTabNo() )
609 			pScViewShell->SetTabNo( nExecTab );
610 
611 		SCROW nRow=aCursorPos.Row();
612 		SCCOL nCol=aCursorPos.Col();
613 
614 		if(pVD->GetCurX()!=nCol || pVD->GetCurY()!=nRow)
615 			pScViewShell->SetCursor(nCol,nRow);
616     }
617 }
618 formula::FormEditData* ScFormulaDlg::getFormEditData() const
619 {
620     ScModule* pScMod = SC_MOD();
621 	return pScMod->GetFormEditData();
622 }
623 void ScFormulaDlg::setCurrentFormula(const String& _sReplacement)
624 {
625     ScModule* pScMod = SC_MOD();
626     pScMod->InputReplaceSelection(_sReplacement);
627 }
628 void ScFormulaDlg::setSelection(xub_StrLen _nStart,xub_StrLen _nEnd)
629 {
630     ScModule* pScMod = SC_MOD();
631     pScMod->InputSetSelection( _nStart, _nEnd );
632 }
633 void ScFormulaDlg::getSelection(xub_StrLen& _nStart,xub_StrLen& _nEnd) const
634 {
635     ScModule* pScMod = SC_MOD();
636     pScMod->InputGetSelection( _nStart, _nEnd );
637 }
638 String ScFormulaDlg::getCurrentFormula() const
639 {
640     ScModule* pScMod = SC_MOD();
641     return pScMod->InputGetFormulaStr();
642 }
643 formula::IFunctionManager* ScFormulaDlg::getFunctionManager()
644 {
645     return ScGlobal::GetStarCalcFunctionMgr();
646 }
647 uno::Reference< sheet::XFormulaParser> ScFormulaDlg::getFormulaParser() const
648 {
649     return m_xParser;
650 }
651 uno::Reference< sheet::XFormulaOpCodeMapper> ScFormulaDlg::getFormulaOpCodeMapper() const
652 {
653     return m_xOpCodeMapper;
654 }
655 
656 table::CellAddress ScFormulaDlg::getReferencePosition() const
657 {
658     return table::CellAddress(aCursorPos.Tab(),aCursorPos.Col(),aCursorPos.Row());
659 }
660 
661 ::std::auto_ptr<formula::FormulaTokenArray> ScFormulaDlg::convertToTokenArray(const uno::Sequence< sheet::FormulaToken >& _aTokenList)
662 {
663     ::std::auto_ptr<formula::FormulaTokenArray> pArray(new ScTokenArray());
664     pArray->Fill( _aTokenList, pDoc->GetExternalRefManager());
665     return pArray;
666 }
667 
668