LibreOffice Module sc (master)  1
formula.cxx
Go to the documentation of this file.
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 <memory>
21 #include <scitems.hxx>
22 #include <sfx2/dispatch.hxx>
23 #include <sfx2/docfile.hxx>
24 #include <sfx2/objsh.hxx>
25 #include <svl/numformat.hxx>
26 #include <svl/zforlist.hxx>
27 #include <svl/stritem.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <tools/urlobj.hxx>
32 #include <formula/errorcodes.hxx>
33 
34 #include <compiler.hxx>
35 #include <formula.hxx>
36 #include <formdata.hxx>
37 #include <reffact.hxx>
38 #include <document.hxx>
39 #include <simpleformulacalc.hxx>
40 #include <scmod.hxx>
41 #include <inputhdl.hxx>
42 #include <tabvwsh.hxx>
43 #include <docsh.hxx>
44 #include <funcdesc.hxx>
45 #include <tokenarray.hxx>
46 #include <sc.hrc>
47 #include <servuno.hxx>
48 #include <unonames.hxx>
49 #include <externalrefmgr.hxx>
50 
51 #include <com/sun/star/table/CellAddress.hpp>
52 #include <com/sun/star/sheet/XFormulaOpCodeMapper.hpp>
53 #include <com/sun/star/sheet/XFormulaParser.hpp>
54 
55 using namespace formula;
56 using namespace com::sun::star;
57 
58 // init/ shared functions for dialog
59 
61  weld::Window* pParent, const ScViewData& rViewData, const formula::IFunctionManager* _pFunctionMgr)
62  : formula::FormulaDlg(pB, pCW, pParent, _pFunctionMgr, this)
63  , m_aHelper(this,pB)
64  , m_pViewShell( nullptr )
65 {
67  ScModule* pScMod = SC_MOD();
68  pScMod->InputEnterHandler();
69  m_pViewShell = nullptr;
70 
71  // title has to be from the view that opened the dialog,
72  // even if it's not the current view
73 
74  if ( pB )
75  {
76  SfxDispatcher* pMyDisp = pB->GetDispatcher();
77  if (pMyDisp)
78  {
79  SfxViewFrame* pMyViewFrm = pMyDisp->GetFrame();
80  if (pMyViewFrm)
81  {
82  m_pViewShell = dynamic_cast<ScTabViewShell*>( pMyViewFrm->GetViewShell() );
83  if( m_pViewShell )
85  }
86  }
87  }
88 
89  m_pDoc = &rViewData.GetDocument();
91  static_cast<ScDocShell*>(m_pDoc->GetDocumentShell())),uno::UNO_QUERY);
92  uno::Reference< beans::XPropertySet> xSet(m_xParser,uno::UNO_QUERY);
93  xSet->setPropertyValue(SC_UNO_COMPILEFAP, uno::makeAny(true));
94 
96  static_cast<ScDocShell*>(m_pDoc->GetDocumentShell())),uno::UNO_QUERY);
97 
98  ScInputHandler* pInputHdl = SC_MOD()->GetInputHdl(m_pViewShell);
99 
100  assert(pInputHdl && "Missing input handler :-/");
101 
102  pInputHdl->NotifyChange( nullptr );
103 
106  m_aHelper.Init();
108 
109  notifyChange();
110  fill();
111 
113  if (pData)
114  return;
115 
116  pScMod->SetRefInputHdl(pInputHdl);
117 
118  m_pDoc = &rViewData.GetDocument();
119  SCCOL nCol = rViewData.GetCurX();
120  SCROW nRow = rViewData.GetCurY();
121  SCTAB nTab = rViewData.GetTabNo();
122  m_CursorPos = ScAddress( nCol, nRow, nTab );
123 
124  m_pViewShell->InitFormEditData(); // create new
125  pData = m_pViewShell->GetFormEditData();
126  pData->SetInputHandler(pInputHdl);
127  pData->SetDocShell(rViewData.GetDocShell());
128 
129  OSL_ENSURE(pData,"FormEditData not available");
130 
131  formula::FormulaDlgMode eMode = FormulaDlgMode::Formula; // default...
132 
133  // edit if formula exists
134 
135  OUString aFormula = m_pDoc->GetFormula( nCol, nRow, nTab );
136  bool bEdit = ( aFormula.getLength() > 1 );
137  bool bMatrix = false;
138  if ( bEdit )
139  {
140  bMatrix = CheckMatrix(aFormula);
141 
142  sal_Int32 nFStart = 0;
143  sal_Int32 nFEnd = 0;
144  if ( GetFormulaHelper().GetNextFunc( aFormula, false, nFStart, &nFEnd) )
145  {
146  pInputHdl->InputReplaceSelection( aFormula );
147  pInputHdl->InputSetSelection( nFStart, nFEnd );
148  sal_Int32 PrivStart, PrivEnd;
149  pInputHdl->InputGetSelection( PrivStart, PrivEnd);
150 
151  eMode = SetMeText(pInputHdl->GetFormString(),PrivStart, PrivEnd, bMatrix, true, true);
152  pData->SetFStart( nFStart );
153  }
154  else
155  bEdit = false;
156  }
157 
158  if ( !bEdit )
159  {
160  OUString aNewFormula('=');
161  if ( aFormula.startsWith("=") )
162  aNewFormula = aFormula;
163 
164  pInputHdl->InputReplaceSelection( aNewFormula );
165  pInputHdl->InputSetSelection( 1, aNewFormula.getLength()+1 );
166  sal_Int32 PrivStart, PrivEnd;
167  pInputHdl->InputGetSelection( PrivStart, PrivEnd);
168  SetMeText(pInputHdl->GetFormString(),PrivStart, PrivEnd,bMatrix,false,false);
169 
170  pData->SetFStart( 1 ); // after "="
171  }
172 
173  pData->SetMode( eMode );
174  OUString rStrExp = GetMeText();
175 
176  Update(rStrExp);
177 
178 }
179 
181 {
183  if ( pInputHdl )
184  pInputHdl->NotifyChange( nullptr );
185 }
186 
188 {
189  ScModule* pScMod = SC_MOD();
191  notifyChange();
192  OUString rStrExp;
193  if (!pData)
194  return;
195 
196  // data exists -> restore state (after switch)
197  // don't reinitialise m_pDoc and m_CursorPos
198  //pDoc = rViewData.GetDocument();
199  if(IsInputHdl(pData->GetInputHandler()))
200  {
201  pScMod->SetRefInputHdl(pData->GetInputHandler());
202  }
203  else
204  {
205  ScTabViewShell* pTabViewShell;
206  ScInputHandler* pInputHdl = GetNextInputHandler(pData->GetDocShell(),&pTabViewShell);
207 
208  if ( pInputHdl == nullptr ) //no more InputHandler for DocShell
209  {
210  disableOk();
211  pInputHdl = pScMod->GetInputHdl();
212  }
213  else
214  {
215  pInputHdl->SetRefViewShell(pTabViewShell);
216  }
217  pScMod->SetRefInputHdl(pInputHdl);
218  pData->SetInputHandler(pInputHdl);
219  }
220 
221  OUString aOldFormulaTmp(pData->GetInputHandler()->GetFormString());
222  pData->GetInputHandler()->InputSetSelection( 0, aOldFormulaTmp.getLength());
223 
224  rStrExp=pData->GetUndoStr();
225  pData->GetInputHandler()->InputReplaceSelection(rStrExp);
226 
227  SetMeText(rStrExp);
228 
229  Update();
230  // switch back, maybe new Doc has been opened
231  pScMod->SetRefInputHdl(nullptr);
232 }
233 
234 ScFormulaDlg::~ScFormulaDlg() COVERITY_NOEXCEPT_FALSE
235 {
237 
238  m_aHelper.dispose();
239 
240  if (pData) // close doesn't destroy;
241  {
242  //set back reference input handler
243  SC_MOD()->SetRefInputHdl(nullptr);
244  StoreFormEditData(pData);
245  }
246 
248 }
249 
251 {
252  bool bAlive = false;
253 
254  // belongs InputHandler to a ViewShell?
255 
256  SfxViewShell* pSh = SfxViewShell::GetFirst( true, checkSfxViewShell<ScTabViewShell> );
257  while ( pSh && !bAlive )
258  {
259  if (static_cast<ScTabViewShell*>(pSh)->GetInputHandler() == pHdl)
260  bAlive = true;
261  pSh = SfxViewShell::GetNext( *pSh, true, checkSfxViewShell<ScTabViewShell> );
262  }
263 
264  return bAlive;
265 
266 }
267 
269 {
270  ScInputHandler* pHdl=nullptr;
271 
272  SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell );
273  while( pFrame && pHdl==nullptr)
274  {
275  SfxViewShell* p = pFrame->GetViewShell();
276  ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell *>( p );
277  if(pViewSh!=nullptr)
278  {
279  pHdl=pViewSh->GetInputHandler();
280  if(ppViewSh!=nullptr) *ppViewSh=pViewSh;
281  }
282  pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell );
283  }
284 
285  return pHdl;
286 }
287 
289 {
290  if (IsClosing())
291  return;
292 
293  DoEnter();
294 }
295 
296 // functions for right side
297 
298 bool ScFormulaDlg::calculateValue( const OUString& rStrExp, OUString& rStrResult, bool bMatrixFormula )
299 {
300  std::optional<ScSimpleFormulaCalculator> pFCell(std::in_place,
301  *m_pDoc, m_CursorPos, rStrExp, bMatrixFormula);
302  pFCell->SetLimitString(true);
303 
304  // HACK! to avoid neither #REF! from ColRowNames
305  // if a name is added as actually range in the overall formula,
306  // but is interpreted at the individual representation as single-cell reference
307  bool bColRowName = pFCell->HasColRowName();
308  if ( bColRowName )
309  {
310  // ColRowName from RPN-Code?
311  if ( pFCell->GetCode()->GetCodeLen() <= 1 )
312  { // ==1: area
313  // ==0: would be an area if...
314  OUString aBraced = "(" + rStrExp + ")";
315  pFCell.emplace(*m_pDoc, m_CursorPos, aBraced, bMatrixFormula);
316  pFCell->SetLimitString(true);
317  }
318  else
319  bColRowName = false;
320  }
321 
322  FormulaError nErrCode = pFCell->GetErrCode();
323  if ( nErrCode == FormulaError::NONE || pFCell->IsMatrix() )
324  {
325  SvNumberFormatter& aFormatter = *(m_pDoc->GetFormatTable());
326  const Color* pColor;
327  if (pFCell->IsMatrix())
328  {
329  rStrResult = pFCell->GetString().getString();
330  }
331  else if (pFCell->IsValue())
332  {
333  double n = pFCell->GetValue();
334  sal_uLong nFormat = aFormatter.GetStandardFormat( n, 0,
335  pFCell->GetFormatType(), ScGlobal::eLnge );
336  aFormatter.GetOutputString( n, nFormat, rStrResult, &pColor );
337  }
338  else
339  {
340  sal_uLong nFormat = aFormatter.GetStandardFormat(
341  pFCell->GetFormatType(), ScGlobal::eLnge);
342  aFormatter.GetOutputString( pFCell->GetString().getString(), nFormat,
343  rStrResult, &pColor );
344  // Indicate it's a string, so a number string doesn't look numeric.
345  // Escape embedded quotation marks first by doubling them, as
346  // usual. Actually the result can be copy-pasted from the result
347  // box as literal into a formula expression.
348  rStrResult = "\"" + rStrResult.replaceAll( "\"", "\"\"") + "\"";
349  }
350 
351  ScRange aTestRange;
352  if ( bColRowName || (aTestRange.Parse(rStrExp, *m_pDoc) & ScRefFlags::VALID) )
353  rStrResult += " ...";
354  // area
355  }
356  else
357  rStrResult += ScGlobal::GetErrorString(nErrCode);
358 
359  return true;
360 }
361 
362 std::shared_ptr<formula::FormulaCompiler> ScFormulaDlg::getCompiler() const
363 {
364  if (!m_xCompiler)
365  m_xCompiler = std::make_shared<ScCompiler>(*m_pDoc, m_CursorPos, m_pDoc->GetGrammar());
366  return m_xCompiler;
367 }
368 
369 std::unique_ptr<formula::FormulaCompiler> ScFormulaDlg::createCompiler( formula::FormulaTokenArray& rArray ) const
370 {
371  ScCompiler* pCompiler = nullptr;
372  ScTokenArray* pArr = dynamic_cast<ScTokenArray*>(&rArray);
373  assert(pArr); // violation of contract and not created using convertToTokenArray()?
374  if (pArr)
375  pCompiler = new ScCompiler(*m_pDoc, m_CursorPos, *pArr, m_pDoc->GetGrammar());
376  return std::unique_ptr<formula::FormulaCompiler>(pCompiler);
377 }
378 
379 // virtual methods of ScAnyRefDlg:
381 {
382  pEdit->SelectAll();
383  ::std::pair<formula::RefButton*,formula::RefEdit*> aPair = RefInputStartBefore( pEdit, pButton );
384  m_aHelper.RefInputStart( aPair.second, aPair.first);
386 }
387 
388 void ScFormulaDlg::RefInputDone( bool bForced )
389 {
390  m_aHelper.RefInputDone( bForced );
391  RefInputDoneAfter( bForced );
392 }
393 
394 void ScFormulaDlg::SetReference( const ScRange& rRef, ScDocument& rRefDoc )
395 {
397  if ( !(pFunc && pFunc->getSuppressedArgumentCount() > 0) )
398  return;
399 
400  Selection theSel;
401  bool bRefNull = UpdateParaWin(theSel);
402 
403  if ( rRef.aStart != rRef.aEnd && bRefNull )
404  {
406  }
407 
408  // Pointer-selected => absolute range references for the non-single
409  // dimensions, so in the other dimension (if any) it's still
410  // copy-adjustable.
411  constexpr ScRefFlags eColFlags = ScRefFlags::COL_ABS | ScRefFlags::COL2_ABS;
412  constexpr ScRefFlags eRowFlags = ScRefFlags::ROW_ABS | ScRefFlags::ROW2_ABS;
413  ScRefFlags eRangeFlags = ScRefFlags::ZERO;
414  if (rRef.aStart.Col() != rRef.aEnd.Col())
415  eRangeFlags |= eColFlags;
416  if (rRef.aStart.Row() != rRef.aEnd.Row())
417  eRangeFlags |= eRowFlags;
418  OUString aRefStr;
419  bool bOtherDoc = (&rRefDoc != m_pDoc && rRefDoc.GetDocumentShell()->HasName());
420  if ( bOtherDoc )
421  {
422  // reference to other document - like inputhdl.cxx
423 
424  OSL_ENSURE(rRef.aStart.Tab()==rRef.aEnd.Tab(), "nStartTab!=nEndTab");
425 
426  // Sheet always 3D and absolute.
427  OUString aTmp( rRef.Format(rRefDoc, ScRefFlags::VALID | ScRefFlags::TAB_ABS_3D | eRangeFlags));
428 
429  SfxObjectShell* pObjSh = rRefDoc.GetDocumentShell();
430 
431  // #i75893# convert escaped URL of the document to something user friendly
432 // OUString aFileName = pObjSh->GetMedium()->GetName();
434 
435  aRefStr = "'" + aFileName + "'#" + aTmp;
436  }
437  else
438  {
439  // We can't use ScRange::Format here because in R1C1 mode we need
440  // to display the reference position relative to the cursor
441  // position.
442  ScTokenArray aArray(rRefDoc);
443  ScComplexRefData aRefData;
444  aRefData.InitRangeRel(rRefDoc, rRef, m_CursorPos);
445  if ((eRangeFlags & eColFlags) == eColFlags)
446  {
447  aRefData.Ref1.SetAbsCol( rRef.aStart.Col() );
448  aRefData.Ref2.SetAbsCol( rRef.aEnd.Col() );
449  }
450  if ((eRangeFlags & eRowFlags) == eRowFlags)
451  {
452  aRefData.Ref1.SetAbsRow( rRef.aStart.Row() );
453  aRefData.Ref2.SetAbsRow( rRef.aEnd.Row() );
454  }
455  bool bSingle = aRefData.Ref1 == aRefData.Ref2;
456  if (m_CursorPos.Tab() != rRef.aStart.Tab())
457  {
458  // pointer-selected => absolute sheet reference
459  aRefData.Ref1.SetAbsTab( rRef.aStart.Tab() );
460  aRefData.Ref1.SetFlag3D(true);
461  }
462  if (bSingle)
463  aArray.AddSingleReference(aRefData.Ref1);
464  else
465  aArray.AddDoubleReference(aRefData);
466  ScCompiler aComp(*m_pDoc, m_CursorPos, aArray, m_pDoc->GetGrammar());
467  OUStringBuffer aBuf;
468  aComp.CreateStringFromTokenArray(aBuf);
469  aRefStr = aBuf.makeStringAndClear();
470  }
471 
472  UpdateParaWin(theSel,aRefStr);
473 }
474 
476 {
478  bool bRef = (pDesc && (pDesc->getSuppressedArgumentCount() > 0)) && (m_pDoc != nullptr);
479  return bRef;
480 }
481 
483 {
484  // not allowed: different from this doc, and no name
485  // pDocSh is always a ScDocShell
486  return !pDocSh || &static_cast<ScDocShell*>(pDocSh)->GetDocument() == m_pDoc || pDocSh->HasName(); // everything else is allowed
487 }
488 
490 {
492  if ( pFunc && pFunc->getSuppressedArgumentCount() > 0 )
493  {
494  RefInputDone();
495  SetEdSelection();
496  }
497 }
498 
499 void ScFormulaDlg::SaveLRUEntry(const ScFuncDesc* pFuncDescP)
500 {
501  if (pFuncDescP && pFuncDescP->nFIndex!=0)
502  {
503  ScModule* pScMod = SC_MOD();
504  pScMod->InsertEntryToLRUList(pFuncDescP->nFIndex);
505  }
506 }
507 
508 void ScFormulaDlg::doClose(bool /*_bOk*/)
509 {
510  m_aHelper.DoClose( ScFormulaDlgWrapper::GetChildWindowId() );
511 }
513 {
514  const ScFuncDesc* pDesc = dynamic_cast<const ScFuncDesc*>(_pDesc);
515  SaveLRUEntry(pDesc);
516 }
517 void ScFormulaDlg::showReference(const OUString& _sFormula)
518 {
519  ShowReference(_sFormula);
520 }
521 void ScFormulaDlg::ShowReference(const OUString& _sFormula)
522 {
523  m_aHelper.ShowReference(_sFormula);
524 }
525 void ScFormulaDlg::HideReference( bool bDoneRefMode )
526 {
527  m_aHelper.HideReference(bDoneRefMode);
528 }
530 {
532 }
534 {
535 
536 }
538 {
539  // default: reference input can also be used to switch the table
540  return false;
541 }
542 
544 {
545  m_aHelper.ToggleCollapsed(pEdit,pButton);
546 }
547 
549 {
550  m_aHelper.ReleaseFocus(pEdit);
551 }
552 
553 void ScFormulaDlg::dispatch(bool _bOK, bool _bMatrixChecked)
554 {
555  SfxBoolItem aRetItem( SID_DLG_RETOK, _bOK );
556  SfxBoolItem aMatItem( SID_DLG_MATRIX, _bMatrixChecked );
558 
559  // if edit line is empty (caused by document switching) -> string is empty
560  // -> don't delete old formula
561  if ( aStrItem.GetValue().isEmpty() )
562  aRetItem.SetValue( false ); // sal_False = Cancel
563 
564  m_aHelper.SetDispatcherLock( false ); // turn off modal-mode
565 
566  clear();
567 
568  GetBindings().GetDispatcher()->ExecuteList( SID_INS_FUNCTION,
569  SfxCallMode::ASYNCHRON | SfxCallMode::RECORD,
570  { &aRetItem, &aStrItem, &aMatItem });
571 }
573 {
574  m_aHelper.SetDispatcherLock( bLock );
575 }
577 {
578  if (m_pViewShell)
579  m_pViewShell->ClearFormEditData(); // pData is invalid!
580 }
582 {
583  m_pDoc = nullptr;
584 
585  //restore reference inputhandler
586  ScModule* pScMod = SC_MOD();
587  pScMod->SetRefInputHdl(nullptr);
588 
589  // force Enable() of edit line
590  ScTabViewShell* pScViewShell = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() );
591  if ( pScViewShell )
592  pScViewShell->UpdateInputHandler();
593 }
595 {
596  // back to the document
597  // (foreign doc could be above - #34222#)
599  if ( pHdl )
600  {
601  pHdl->ViewShellGone(nullptr); // -> get active view
602  pHdl->ShowRefFrame();
603  }
604 
605  // restore current chart (cause mouse-RefInput)
606  ScTabViewShell* pScViewShell = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() );
607  if ( !pScViewShell )
608  return;
609 
610  ScViewData& rVD=pScViewShell->GetViewData();
611  SCTAB nExecTab = m_CursorPos.Tab();
612  if ( nExecTab != rVD.GetTabNo() )
613  pScViewShell->SetTabNo( nExecTab );
614 
615  SCROW nRow = m_CursorPos.Row();
616  SCCOL nCol = m_CursorPos.Col();
617 
618  if(rVD.GetCurX()!=nCol || rVD.GetCurY()!=nRow)
619  pScViewShell->SetCursor(nCol,nRow);
620 }
622 {
623  ScTabViewShell* pViewShell = m_pViewShell;
624  if (pViewShell)
625  return pViewShell->GetFormEditData();
626  return nullptr;
627 }
628 void ScFormulaDlg::setCurrentFormula(const OUString& _sReplacement)
629 {
630  ScModule* pScMod = SC_MOD();
631  {
632  //fdo#69971 We need the EditEngine Modification handler of the inputbar that we
633  //are feeding to be disabled while this dialog is open. Otherwise we end up in
634  //a situation where...
635  //a) this ScFormulaDlg changes the editengine
636  //b) the modify callback gets called
637  //c) which also modifies the editengine
638  //d) on return from that modify handler the editengine attempts to use
639  // old node pointers which were replaced and removed by c
640  //
641  //We turn it off in the ctor and back on in the dtor, but if calc has
642  //to repaint, e.g. when switching to another window and back, then in
643  //ScMultiTextWnd::Paint a new editengine will have been created via
644  //GetEditView with its default Modification handler enabled. So ensure
645  //its off when we will access it via InputReplaceSelection
646  pScMod->InputTurnOffWinEngine();
647  }
648  pScMod->InputReplaceSelection(_sReplacement);
649 }
650 void ScFormulaDlg::setSelection(sal_Int32 _nStart, sal_Int32 _nEnd)
651 {
652  ScModule* pScMod = SC_MOD();
653  pScMod->InputSetSelection( _nStart, _nEnd );
654 }
655 void ScFormulaDlg::getSelection(sal_Int32& _nStart, sal_Int32& _nEnd) const
656 {
657  ScModule* pScMod = SC_MOD();
658  pScMod->InputGetSelection( _nStart, _nEnd );
659 }
661 {
663  if (pData && pData->GetInputHandler())
664  return pData->GetInputHandler()->GetFormString();
665  return "";
666 }
668 {
670 }
671 uno::Reference< sheet::XFormulaParser> ScFormulaDlg::getFormulaParser() const
672 {
673  return m_xParser;
674 }
675 uno::Reference< sheet::XFormulaOpCodeMapper> ScFormulaDlg::getFormulaOpCodeMapper() const
676 {
677  return m_xOpCodeMapper;
678 }
679 
680 table::CellAddress ScFormulaDlg::getReferencePosition() const
681 {
682  return table::CellAddress(m_CursorPos.Tab(), m_CursorPos.Col(), m_CursorPos.Row());
683 }
684 
685 ::std::unique_ptr<formula::FormulaTokenArray> ScFormulaDlg::convertToTokenArray(const uno::Sequence< sheet::FormulaToken >& _aTokenList)
686 {
687  ::std::unique_ptr<formula::FormulaTokenArray> pArray(new ScTokenArray(*m_pDoc));
688  pArray->Fill(_aTokenList, m_pDoc->GetSharedStringPool(), m_pDoc->GetExternalRefManager());
689  return pArray;
690 }
691 
692 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:422
formula::FormulaToken * AddDoubleReference(const ScComplexRefData &rRef)
Definition: token.cxx:2281
void StoreFormEditData(FormEditData *pData)
static bool IsInputHdl(const ScInputHandler *pHdl)
Definition: formula.cxx:250
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
RefEdit * GetActiveEdit()
ScAddress aStart
Definition: address.hxx:499
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:353
SC_DLLPUBLIC svl::SharedStringPool & GetSharedStringPool()
Definition: documen2.cxx:567
virtual void switchBack() override
Definition: formula.cxx:594
void SetMeText(const OUString &_sText)
SCROW Row() const
Definition: address.hxx:261
virtual bool IsTableLocked() const override
Definition: formula.cxx:537
const OUString & GetUndoStr() const
std::unique_ptr< sal_Int32[]> pData
sal_uInt16 char char * pDesc
Definition: callform.cxx:57
sal_uIntPtr sal_uLong
void InputGetSelection(sal_Int32 &rStart, sal_Int32 &rEnd)
Definition: scmod.cxx:1404
void RefInputDoneAfter(bool bForced)
SCROW GetCurY() const
Definition: viewdata.hxx:401
sal_Int64 n
virtual void clear() override
Definition: formula.cxx:581
void SetDialog(weld::Dialog *pDialog)
Definition: anyrefdg.hxx:68
aBuf
virtual void RefInputStart(formula::RefEdit *pEdit, formula::RefButton *pButton=nullptr) override
Definition: formula.cxx:380
formula::FormulaToken * AddSingleReference(const ScSingleRefData &rRef)
ScSingleRefToken with ocPush.
Definition: token.cxx:2271
virtual bool calculateValue(const OUString &_sExpression, OUString &_rResult, bool bMatrixFormula) override
Definition: formula.cxx:298
SCTAB GetTabNo() const
Definition: viewdata.hxx:394
#define SC_UNO_COMPILEFAP
Definition: unonames.hxx:678
ScInputHandler * GetInputHandler()
Definition: formdata.hxx:32
void InitRangeRel(const ScDocument &rDoc, const ScRange &rRange, const ScAddress &rPos)
Definition: refdata.hxx:135
ScAddress aEnd
Definition: address.hxx:500
void SetAbsRow(SCROW nVal)
Definition: refdata.cxx:76
virtual css::uno::Reference< css::sheet::XFormulaParser > getFormulaParser() const override
Definition: formula.cxx:671
ScDocument & GetDocument() const
Definition: viewdata.hxx:379
virtual SfxBindings & GetBindings() override
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
Definition: document.hxx:990
virtual ::std::unique_ptr< formula::FormulaTokenArray > convertToTokenArray(const css::uno::Sequence< css::sheet::FormulaToken > &_aTokenList) override
Definition: formula.cxx:685
SC_DLLPUBLIC void SetCursor(SCCOL nPosX, SCROW nPosY, bool bNew=false)
Definition: tabview3.cxx:363
void SetRefViewShell(ScTabViewShell *pRefVsh)
Definition: inputhdl.hxx:217
void ViewShellGone(const ScTabViewShell *pViewSh)
Definition: inputhdl.cxx:2208
void ShowRefFrame()
Definition: inputhdl.cxx:2804
virtual void SetReference(const ScRange &rRef, ScDocument &rD) override
Definition: formula.cxx:394
virtual void getSelection(sal_Int32 &_nStart, sal_Int32 &_nEnd) const override
Definition: formula.cxx:655
virtual void setCurrentFormula(const OUString &_sReplacement) override
Definition: formula.cxx:628
virtual void setSelection(sal_Int32 _nStart, sal_Int32 _nEnd) override
Definition: formula.cxx:650
SC_DLLPUBLIC void InputEnterHandler(ScEnterMode nBlockMode=ScEnterMode::NORMAL)
Definition: scmod.cxx:1361
bool UpdateParaWin(Selection &_rSelection)
void ReleaseFocus(formula::RefEdit *pEdit)
Definition: anyrefdg.cxx:284
void InputReplaceSelection(const OUString &rStr)
Definition: inputhdl.cxx:4476
OUString GetMeText() const
virtual void AddRefEntry() override
Definition: formula.cxx:533
static ScInputHandler * GetNextInputHandler(const ScDocShell *pDocShell, ScTabViewShell **ppViewSh)
Definition: formula.cxx:268
void InsertEntryToLRUList(sal_uInt16 nFIndex)
Definition: scmod.cxx:681
virtual void SetActive() override
Definition: formula.cxx:489
static SfxViewShell * GetNext(const SfxViewShell &rPrev, bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
void SetRefInputHdl(ScInputHandler *pNew)
Definition: scmod.cxx:1399
static SfxViewShell * Current()
SC_DLLPUBLIC ScExternalRefManager * GetExternalRefManager() const
Definition: documen3.cxx:627
Mode eMode
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:653
SCTAB Tab() const
Definition: address.hxx:270
virtual void setDispatcherLock(bool bLock) override
Definition: formula.cxx:572
ScFormulaDlg(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, const ScViewData &rViewData, const formula::IFunctionManager *_pFunctionMgr)
Definition: formula.cxx:60
SC_DLLPUBLIC OUString GetFormula(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:3735
void InputSetSelection(sal_Int32 nStart, sal_Int32 nEnd)
Definition: inputhdl.cxx:4456
void ClearFormEditData()
Definition: tabvwshc.cxx:729
ScViewData & GetViewData()
Definition: tabview.hxx:333
virtual void notifyChange() override
Definition: formula.cxx:180
const IFunctionDescription * getCurrentFunctionDescription() const
void ToggleCollapsed(formula::RefEdit *pEdit, formula::RefButton *pButton)
Definition: anyrefdg.cxx:402
static css::uno::Reference< css::uno::XInterface > MakeInstance(Type nType, ScDocShell *pDocShell)
Definition: servuno.cxx:397
virtual css::table::CellAddress getReferencePosition() const override
Definition: formula.cxx:680
ScDocShell * GetDocShell()
Definition: formdata.hxx:33
virtual void ReleaseFocus(formula::RefEdit *pEdit) override
Definition: formula.cxx:548
ScAddress m_CursorPos
Definition: formula.hxx:43
virtual formula::FormEditData * getFormEditData() const override
Definition: formula.cxx:621
virtual bool IsRefInputMode() const override
Definition: formula.cxx:475
virtual void insertEntryToLRUList(const formula::IFunctionDescription *pDesc) override
Definition: formula.cxx:512
virtual void deleteFormData() override
Definition: formula.cxx:576
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:442
static void EnableSpreadsheets(bool bFlag=true)
Definition: anyrefdg.cxx:505
#define SCITEM_STRING
Definition: scitems.hxx:87
ScFormEditData * GetFormEditData()
Definition: tabvwsh.hxx:400
void SetFlag3D(bool bVal)
Definition: refdata.hxx:89
virtual void ToggleCollapsed(formula::RefEdit *pEdit, formula::RefButton *pButton) override
Definition: formula.cxx:543
sal_Int16 SCCOL
Definition: types.hxx:21
ScFormulaReferenceHelper m_aHelper
Definition: formula.hxx:38
ScTabViewShell * m_pViewShell
Definition: formula.hxx:44
#define SC_MOD()
Definition: scmod.hxx:250
virtual std::unique_ptr< formula::FormulaCompiler > createCompiler(formula::FormulaTokenArray &rArray) const override
Definition: formula.cxx:369
void SetAbsCol(SCCOL nVal)
Definition: refdata.cxx:59
ScSingleRefData Ref1
Definition: refdata.hxx:124
OUString Format(const ScDocument &rDocument, ScRefFlags nFlags=ScRefFlags::ZERO, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, bool bFullAddressNotation=false) const
Returns string with formatted cell range from aStart to aEnd, according to provided address conventio...
Definition: address.cxx:2204
const OUString & GetValue() const
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1798
static SfxViewFrame * GetNext(const SfxViewFrame &rPrev, const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
static ScFunctionMgr * GetStarCalcFunctionMgr()
Definition: global.cxx:618
ScSingleRefData Ref2
Definition: refdata.hxx:125
::std::pair< RefButton *, RefEdit * > RefInputStartBefore(RefEdit *pEdit, RefButton *pButton)
const OUString & GetFormString() const
Definition: inputhdl.hxx:191
void HideReference(bool bDoneRefMode=true)
Definition: anyrefdg.cxx:232
bool HasName() const
static void SaveLRUEntry(const ScFuncDesc *pFuncDesc)
Definition: formula.cxx:499
static SC_DLLPUBLIC LanguageType eLnge
Definition: global.hxx:538
void SetAbsTab(SCTAB nVal)
Definition: refdata.cxx:93
static SfxViewShell * GetFirst(bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
virtual void Close() override
Definition: formula.cxx:288
SfxViewShell * GetViewShell() const
static void enableInput(bool _bInput)
Definition: anyrefdg.cxx:77
void SetValue(bool const bTheValue)
FormulaError
void SetInputHandler(ScInputHandler *pHdl)
Definition: formdata.hxx:35
SCCOL Col() const
Definition: address.hxx:266
void SetDocShell(ScDocShell *pSds)
Definition: formdata.hxx:36
virtual void ViewShellChanged() override
Definition: formula.cxx:529
css::uno::Reference< css::sheet::XFormulaParser > m_xParser
Definition: formula.hxx:39
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
virtual formula::IFunctionManager * getFunctionManager() override
Definition: formula.cxx:667
sal_Int32 SCROW
Definition: types.hxx:17
std::shared_ptr< ScCompiler > m_xCompiler
Definition: formula.hxx:45
virtual ~ScFormulaDlg() COVERITY_NOEXCEPT_FALSE override
Definition: formula.cxx:234
void SetDispatcherLock(bool bLock)
Definition: anyrefdg.cxx:459
virtual css::uno::Reference< css::sheet::XFormulaOpCodeMapper > getFormulaOpCodeMapper() const override
Definition: formula.cxx:675
void InputGetSelection(sal_Int32 &rStart, sal_Int32 &rEnd)
Methods for FunctionAutoPilot: InputGetSelection, InputSetSelection, InputReplaceSelection, InputGetFormulaStr.
Definition: inputhdl.cxx:4424
virtual void doClose(bool _bOk) override
Definition: formula.cxx:508
void InitFormEditData()
Definition: tabvwshc.cxx:724
sal_uInt32 GetStandardFormat(SvNumFormatType eType, LanguageType eLnge=LANGUAGE_DONTKNOW)
virtual sal_Int32 getSuppressedArgumentCount() const =0
SfxViewFrame * GetFrame() const
void InputReplaceSelection(const OUString &rStr)
Definition: scmod.cxx:1418
ScRefFlags Parse(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, ScAddress::ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, const OUString *pErrRef=nullptr)
Definition: address.cxx:1734
void NotifyChange(const ScInputHdlState *pState, bool bForce=false, ScTabViewShell *pSourceSh=nullptr, bool bStopEditing=true)
Definition: inputhdl.cxx:4079
Reference< XExecutableDialog > m_xDialog
const INetURLObject & GetURLObject() const
virtual void ShowReference(const OUString &_sRef) override
Definition: formula.cxx:521
void * p
sal_uInt16 nFIndex
Unique function index.
Definition: funcdesc.hxx:221
virtual OUString getCurrentFormula() const override
Definition: formula.cxx:660
const FormulaHelper & GetFormulaHelper() const
void InputSetSelection(sal_Int32 nStart, sal_Int32 nEnd)
Definition: scmod.cxx:1411
void RefInputStart(formula::RefEdit *pEdit, formula::RefButton *pButton)
Definition: anyrefdg.cxx:371
void RefInputDone(bool bForced)
Definition: anyrefdg.cxx:344
ScDocument * m_pDoc
Definition: formula.hxx:42
virtual void HideReference(bool bDoneRefMode=true) override
Definition: formula.cxx:525
static void ViewShellChanged()
Definition: anyrefdg.cxx:499
Complex reference (a range) into the sheet.
Definition: refdata.hxx:122
SfxDispatcher * GetDispatcher() const
virtual void dispatch(bool _bOK, bool _bMatrixChecked) override
Definition: formula.cxx:553
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
SfxObjectShell * GetDocumentShell() const
Definition: document.hxx:1063
void InputTurnOffWinEngine()
Definition: scmod.cxx:1425
bool CheckMatrix(OUString &aFormula)
ScInputHandler * GetInputHdl(ScTabViewShell *pViewSh=nullptr, bool bUseRef=true)
Input-Handler.
Definition: scmod.cxx:1305
virtual void showReference(const OUString &_sFormula) override
Definition: formula.cxx:517
ScRefFlags
Definition: address.hxx:144
virtual bool IsDocAllowed(SfxObjectShell *pDocSh) const override
Definition: formula.cxx:482
void ShowReference(const OUString &rStr)
Definition: anyrefdg.cxx:260
void SetFStart(sal_Int32 nNew)
virtual std::shared_ptr< formula::FormulaCompiler > getCompiler() const override
Definition: formula.cxx:362
Stores and generates human readable descriptions for spreadsheet-functions, e.g. functions used in fo...
Definition: funcdesc.hxx:40
const ScInputHandler * GetInputHandler() const
Definition: tabvwsh.hxx:231
void GetOutputString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &sOutString, const Color **ppColor, bool bUseStarFormat=false)
static OUString GetErrorString(FormulaError nErrNumber)
Definition: global.cxx:301
virtual void RefInputDone(bool bForced=false) override
Definition: formula.cxx:388
virtual void fill() override
Definition: formula.cxx:187
sal_Int16 SCTAB
Definition: types.hxx:22
void SetMode(FormulaDlgMode nNew)
SCCOL GetCurX() const
Definition: viewdata.hxx:400
css::uno::Reference< css::sheet::XFormulaOpCodeMapper > m_xOpCodeMapper
Definition: formula.hxx:40
SfxMedium * GetMedium() const