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