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