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