merge the formfield patch from ooo-build
[ooovba.git] / formula / source / ui / dlg / formula.cxx
blob897f53b59be3e2969fc8d7c169134884d910a9c2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: formula.cxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_formula.hxx"
34 //----------------------------------------------------------------------------
35 #include <sfx2/dispatch.hxx>
36 #include <sfx2/docfile.hxx>
37 #include <sfx2/viewfrm.hxx>
38 #include <sfx2/topfrm.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/mnemonic.hxx>
41 #include <vcl/tabpage.hxx>
42 #include <vcl/tabctrl.hxx>
43 #include <vcl/lstbox.hxx>
44 #include <vcl/group.hxx>
45 #include <vcl/wall.hxx>
47 #include <svtools/stdctrl.hxx>
48 #include <svtools/svmedit.hxx>
49 #include <svtools/svtreebx.hxx>
50 #include <svtools/stritem.hxx>
51 #include <svtools/zforlist.hxx>
52 #include <svtools/eitem.hxx>
54 #include <unotools/charclass.hxx>
55 #include <tools/urlobj.hxx>
56 #include <tools/diagnose_ex.h>
58 #include "formdlgs.hrc"
59 #include "funcpage.hxx"
60 #include "formula/formula.hxx"
61 #include "formula/IFunctionDescription.hxx"
62 #include "formula/FormulaCompiler.hxx"
63 #include "formula/token.hxx"
64 #include "formula/tokenarray.hxx"
65 #include "formula/formdata.hxx"
66 #include "formula/formulahelper.hxx"
67 #include "structpg.hxx"
68 #include "parawin.hxx"
69 #include "ModuleHelper.hxx"
70 #include "ForResId.hrc"
71 #include <com/sun/star/sheet/FormulaToken.hpp>
72 #include <com/sun/star/sheet/FormulaLanguage.hpp>
73 #include <com/sun/star/sheet/FormulaMapGroup.hpp>
74 #include <com/sun/star/sheet/FormulaMapGroupSpecialOffset.hpp>
75 #include <com/sun/star/beans/XPropertySet.hpp>
76 #include <boost/bind.hpp>
77 #include <comphelper/processfactory.hxx>
78 #include <map>
80 #define TOKEN_OPEN 0
81 #define TOKEN_CLOSE 1
82 #define TOKEN_SEP 2
83 namespace formula
85 using namespace ::com::sun::star;
87 class OFormulaToken : public IFormulaToken
89 sal_Int32 m_nParaCount;
90 bool m_bIsFunction;
92 public:
93 OFormulaToken(bool _bFunction,sal_Int32 _nParaCount) : m_nParaCount(_nParaCount),m_bIsFunction(_bFunction){}
95 virtual bool isFunction() const { return m_bIsFunction; }
96 virtual sal_uInt32 getArgumentCount() const { return m_nParaCount; }
100 class FormulaDlg_Impl
102 public:
103 ::std::pair<RefButton*,RefEdit*>
104 RefInputStartBefore( RefEdit* pEdit, RefButton* pButton );
105 void RefInputStartAfter( RefEdit* pEdit, RefButton* pButton );
106 void RefInputDoneAfter( BOOL bForced );
107 BOOL CalcValue( const String& rStrExp, String& rStrResult );
108 BOOL CalcStruct( const String& rStrExp);
109 void UpdateValues();
110 void DeleteArgs();
111 xub_StrLen GetFunctionPos(xub_StrLen nPos);
112 void ClearAllParas();
114 void MakeTree(IStructHelper* _pTree,SvLBoxEntry* pParent,FormulaToken* _pToken,long Count);
115 void fillTree(IStructHelper* _pTree);
116 void UpdateTokenArray( const String& rStrExp);
117 String RepairFormula(const String& aFormula);
118 void FillDialog(BOOL nFlag=TRUE);
119 void EditNextFunc( BOOL bForward, xub_StrLen nFStart=NOT_FOUND );
120 void EditThisFunc(xub_StrLen nFStart);
121 void EditFuncParas(xub_StrLen nEditPos);
124 void UpdateArgInput( USHORT nOffset, USHORT nInput );
125 void Update();
126 void Update(const String& _sExp);
129 void SaveArg( USHORT nEd );
130 void UpdateSelection();
131 void DoEnter( BOOL bOk );
132 void UpdateFunctionDesc();
133 void ResizeArgArr( const IFunctionDescription* pNewFunc );
134 void FillListboxes();
135 void FillControls(BOOL &rbNext, BOOL &rbPrev);
137 FormulaDlgMode SetMeText(const String& _sText,xub_StrLen PrivStart, xub_StrLen PrivEnd,BOOL bMatrix,BOOL _bSelect,BOOL _bUpdate);
138 void SetMeText(const String& _sText);
139 BOOL CheckMatrix(String& aFormula /*IN/OUT*/);
141 void SetEdSelection();
143 BOOL UpdateParaWin(Selection& _rSelection);
144 void UpdateParaWin(const Selection& _rSelection,const String& _sRefStr);
146 void SetData(xub_StrLen nFStart,xub_StrLen nNextFStart,xub_StrLen nNextFEnd,xub_StrLen& PrivStart,xub_StrLen& PrivEnd);
147 void PreNotify( NotifyEvent& rNEvt );
149 RefEdit* GetCurrRefEdit();
150 ULONG FindFocusWin(Window *pWin);
152 const FormulaHelper& GetFormulaHelper() const;
153 uno::Reference< sheet::XFormulaOpCodeMapper > GetFormulaOpCodeMapper() const;
155 DECL_LINK( ModifyHdl, ParaWin* );
156 DECL_LINK( FxHdl, ParaWin* );
158 DECL_LINK( MatrixHdl, CheckBox *);
159 DECL_LINK( FormulaHdl, MultiLineEdit* );
160 DECL_LINK( FormulaCursorHdl, EditBox*);
161 DECL_LINK( BtnHdl, PushButton* );
162 DECL_LINK( GetEdFocusHdl, ArgInput* );
163 DECL_LINK( GetFxFocusHdl, ArgInput* );
164 DECL_LINK( DblClkHdl, FuncPage* );
165 DECL_LINK( FuncSelHdl, FuncPage*);
166 DECL_LINK( StructSelHdl, StructPage * );
167 public:
168 OModuleClient m_aModuleClient;
169 mutable uno::Reference< sheet::XFormulaOpCodeMapper> m_xOpCodeMapper;
170 uno::Sequence< sheet::FormulaToken > m_aTokenList;
171 ::std::auto_ptr<FormulaTokenArray> m_pTokenArray;
172 mutable uno::Sequence< sheet::FormulaOpCodeMapEntry > m_aSpecialOpCodes;
173 mutable const sheet::FormulaOpCodeMapEntry* m_pSpecialOpCodesEnd;
174 mutable uno::Sequence< sheet::FormulaToken > m_aSeparatorsOpCodes;
175 mutable uno::Sequence< sheet::FormulaOpCodeMapEntry > m_aFunctionOpCodes;
176 mutable const sheet::FormulaOpCodeMapEntry* m_pFunctionOpCodesEnd;
177 mutable uno::Sequence< sheet::FormulaOpCodeMapEntry > m_aUnaryOpCodes;
178 mutable const sheet::FormulaOpCodeMapEntry* m_pUnaryOpCodesEnd;
179 mutable uno::Sequence< sheet::FormulaOpCodeMapEntry > m_aBinaryOpCodes;
180 mutable const sheet::FormulaOpCodeMapEntry* m_pBinaryOpCodesEnd;
181 ::std::vector< ::boost::shared_ptr<OFormulaToken> > m_aTokens;
182 ::std::map<FormulaToken*,sheet::FormulaToken> m_aTokenMap;
183 IFormulaEditorHelper* m_pHelper;
184 Dialog* m_pParent;
185 IControlReferenceHandler* m_pDlg;
186 TabControl aTabCtrl;
187 GroupBox aGEdit; //! MUST be placed before pParaWin for initializing
188 ParaWin* pParaWin;
189 FixedText aFtHeadLine;
190 FixedInfo aFtFuncName;
191 FixedInfo aFtFuncDesc;
193 FixedText aFtEditName;
194 //FixedInfo aFtEditDesc;
196 FixedText aFtResult;
197 ValWnd aWndResult;
199 FixedText aFtFormula;
200 EditBox aMEFormula;
202 CheckBox aBtnMatrix;
203 HelpButton aBtnHelp;
204 CancelButton aBtnCancel;
206 PushButton aBtnBackward;
207 PushButton aBtnForward;
208 OKButton aBtnEnd;
210 RefEdit aEdRef;
211 RefButton aRefBtn;
213 FixedText aFtFormResult;
214 ValWnd aWndFormResult;
216 RefEdit* pTheRefEdit;
217 RefButton* pTheRefButton;
218 FuncPage* pFuncPage;
219 StructPage* pStructPage;
220 String aOldFormula;
221 BOOL bStructUpdate;
222 MultiLineEdit* pMEdit;
223 BOOL bUserMatrixFlag;
224 Timer aTimer;
226 const String aTitle1;
227 const String aTitle2;
228 const String aTxtEnd;
229 const String aTxtOk; // hinter aBtnEnd
230 FormulaHelper
231 m_aFormulaHelper;
233 SmartId m_aSmartEditHelpId;
235 ULONG nOldHelp;
236 ULONG nOldUnique;
237 ULONG nActivWinId;
238 BOOL bIsShutDown;
242 Font aFntBold;
243 Font aFntLight;
244 USHORT nEdFocus;
245 // Selection theCurSel;
246 BOOL bEditFlag;
247 const IFunctionDescription* pFuncDesc;
248 xub_StrLen nArgs;
249 ::std::vector< ::rtl::OUString > m_aArguments;
250 Selection aFuncSel;
252 FormulaDlg_Impl(Dialog* pParent
253 , bool _bSupportFunctionResult
254 , bool _bSupportResult
255 , bool _bSupportMatrix
256 ,IFormulaEditorHelper* _pHelper
257 ,const IFunctionManager* _pFunctionMgr
258 ,IControlReferenceHandler* _pDlg);
259 ~FormulaDlg_Impl();
262 FormulaDlg_Impl::FormulaDlg_Impl(Dialog* pParent
263 , bool _bSupportFunctionResult
264 , bool _bSupportResult
265 , bool _bSupportMatrix
266 ,IFormulaEditorHelper* _pHelper
267 ,const IFunctionManager* _pFunctionMgr
268 ,IControlReferenceHandler* _pDlg)
270 m_pHelper (_pHelper),
271 m_pParent (pParent),
272 m_pDlg (_pDlg),
273 aTabCtrl ( pParent, ModuleRes( TC_FUNCTION ) ),
274 aGEdit ( pParent, ModuleRes( GB_EDIT ) ),
275 aFtHeadLine ( pParent, ModuleRes( FT_HEADLINE ) ),
276 aFtFuncName ( pParent, ModuleRes( FT_FUNCNAME ) ),
277 aFtFuncDesc ( pParent, ModuleRes( FT_FUNCDESC ) ),
279 aFtEditName ( pParent, ModuleRes( FT_EDITNAME ) ),
280 aFtResult ( pParent, ModuleRes( FT_RESULT ) ),
281 aWndResult ( pParent, ModuleRes( WND_RESULT ) ),
283 aFtFormula ( pParent, ModuleRes( FT_FORMULA ) ),
284 aMEFormula ( pParent, ModuleRes( ED_FORMULA ) ),
286 aBtnMatrix ( pParent, ModuleRes( BTN_MATRIX ) ),
287 aBtnHelp ( pParent, ModuleRes( BTN_HELP ) ),
288 aBtnCancel ( pParent, ModuleRes( BTN_CANCEL ) ),
289 aBtnBackward ( pParent, ModuleRes( BTN_BACKWARD ) ),
290 aBtnForward ( pParent, ModuleRes( BTN_FORWARD ) ),
291 aBtnEnd ( pParent, ModuleRes( BTN_END ) ),
292 aEdRef ( pParent, _pDlg, ModuleRes( ED_REF) ),
293 aRefBtn ( pParent, ModuleRes( RB_REF),&aEdRef,_pDlg ),
294 aFtFormResult ( pParent, ModuleRes( FT_FORMULA_RESULT)),
295 aWndFormResult ( pParent, ModuleRes( WND_FORMULA_RESULT)),
297 pTheRefEdit (NULL),
298 pMEdit (NULL),
299 bUserMatrixFlag (FALSE),
301 aTitle1 ( ModuleRes( STR_TITLE1 ) ), // lokale Resource
302 aTitle2 ( ModuleRes( STR_TITLE2 ) ), // lokale Resource
303 aTxtEnd ( ModuleRes( STR_END ) ), // lokale Resource
304 aTxtOk ( aBtnEnd.GetText() ),
305 m_aFormulaHelper(_pFunctionMgr),
307 nActivWinId (0),
308 bIsShutDown (FALSE),
309 nEdFocus (0),
310 pFuncDesc (NULL),
311 nArgs (0)
313 pParaWin = new ParaWin( pParent,_pDlg, aGEdit.GetPosPixel());
314 aGEdit.Hide();
315 pParaWin->Hide();
316 aFtEditName.Hide();
317 aEdRef.Hide();
318 aRefBtn.Hide();
320 pMEdit = aMEFormula.GetEdit();
321 m_aSmartEditHelpId = pMEdit->GetSmartHelpId();
322 pMEdit->SetSmartUniqueId(m_aSmartEditHelpId);
324 bEditFlag=FALSE;
325 bStructUpdate=TRUE;
326 Point aPos=aGEdit.GetPosPixel();
327 pParaWin->SetPosPixel(aPos);
328 pParaWin->SetArgModifiedHdl(LINK( this, FormulaDlg_Impl, ModifyHdl ) );
329 pParaWin->SetFxHdl(LINK( this, FormulaDlg_Impl, FxHdl ) );
331 pFuncPage= new FuncPage( &aTabCtrl,_pFunctionMgr);
332 pStructPage= new StructPage( &aTabCtrl);
333 pFuncPage->Hide();
334 pStructPage->Hide();
335 aTabCtrl.SetTabPage( TP_FUNCTION, pFuncPage);
336 aTabCtrl.SetTabPage( TP_STRUCT, pStructPage);
338 nOldHelp = pParent->GetHelpId(); // HelpId aus Resource immer fuer "Seite 1"
339 nOldUnique = pParent->GetUniqueId();
341 aFtResult.Show( _bSupportResult );
342 aWndResult.Show( _bSupportResult );
344 aFtFormResult.Show( _bSupportFunctionResult );
345 aWndFormResult.Show( _bSupportFunctionResult );
347 if ( _bSupportMatrix )
348 aBtnMatrix.SetClickHdl(LINK( this, FormulaDlg_Impl, MatrixHdl ) );
349 else
350 aBtnMatrix.Hide();
352 aBtnCancel .SetClickHdl( LINK( this, FormulaDlg_Impl, BtnHdl ) );
353 aBtnEnd .SetClickHdl( LINK( this, FormulaDlg_Impl, BtnHdl ) );
354 aBtnForward .SetClickHdl( LINK( this, FormulaDlg_Impl, BtnHdl ) );
355 aBtnBackward.SetClickHdl( LINK( this, FormulaDlg_Impl, BtnHdl ) );
357 pFuncPage->SetDoubleClickHdl( LINK( this, FormulaDlg_Impl, DblClkHdl ) );
358 pFuncPage->SetSelectHdl( LINK( this, FormulaDlg_Impl, FuncSelHdl) );
359 pStructPage->SetSelectionHdl( LINK( this, FormulaDlg_Impl, StructSelHdl ) );
360 pMEdit->SetModifyHdl( LINK( this, FormulaDlg_Impl, FormulaHdl ) );
361 aMEFormula.SetSelChangedHdl( LINK( this, FormulaDlg_Impl, FormulaCursorHdl ) );
363 aFntLight = aFtFormula.GetFont();
364 aFntLight.SetTransparent( TRUE );
365 aFntBold = aFntLight;
366 aFntBold.SetWeight( WEIGHT_BOLD );
368 pParaWin->SetArgumentFonts(aFntBold,aFntLight);
370 // function description for choosing a function is no longer in a different color
372 aFtHeadLine.SetFont(aFntBold);
373 aFtFuncName.SetFont(aFntLight);
374 aFtFuncDesc.SetFont(aFntLight);
376 FormulaDlg_Impl::~FormulaDlg_Impl()
378 if(aTimer.IsActive())
380 aTimer.SetTimeoutHdl(Link());
381 aTimer.Stop();
382 } // if(aTimer.IsActive())
383 bIsShutDown=TRUE;// Setzen, damit PreNotify keinen GetFocus speichert.
384 FormEditData* pData = m_pHelper->getFormEditData();
385 if (pData) // wird nicht ueber Close zerstoert;
387 pData->SetFStart((xub_StrLen)pMEdit->GetSelection().Min());
388 pData->SetSelection(pMEdit->GetSelection());
390 if(aTabCtrl.GetCurPageId()==TP_FUNCTION)
391 pData->SetMode( (USHORT) FORMULA_FORMDLG_FORMULA );
392 else
393 pData->SetMode( (USHORT) FORMULA_FORMDLG_EDIT );
394 pData->SetUndoStr(pMEdit->GetText());
395 pData->SetMatrixFlag(aBtnMatrix.IsChecked());
398 aTabCtrl.RemovePage(TP_FUNCTION);
399 aTabCtrl.RemovePage(TP_STRUCT);
401 delete pStructPage;
402 delete pFuncPage;
403 delete pParaWin;
404 DeleteArgs();
406 // -----------------------------------------------------------------------------
407 void FormulaDlg_Impl::PreNotify( NotifyEvent& rNEvt )
409 USHORT nSwitch=rNEvt.GetType();
410 if(nSwitch==EVENT_GETFOCUS && !bIsShutDown)
412 Window* pWin=rNEvt.GetWindow();
413 if(pWin!=NULL)
415 nActivWinId = pWin->GetUniqueId();
416 if(nActivWinId==0)
418 Window* pParent=pWin->GetParent();
419 while(pParent!=NULL)
421 nActivWinId=pParent->GetUniqueId();
423 if(nActivWinId!=0) break;
425 pParent=pParent->GetParent();
428 if(nActivWinId!=0)
431 FormEditData* pData = m_pHelper->getFormEditData();
433 if (pData && !aTimer.IsActive()) // wird nicht ueber Close zerstoert;
435 pData->SetUniqueId(nActivWinId);
441 uno::Reference< sheet::XFormulaOpCodeMapper > FormulaDlg_Impl::GetFormulaOpCodeMapper() const
443 if ( !m_xOpCodeMapper.is() )
445 m_xOpCodeMapper = m_pHelper->getFormulaOpCodeMapper();
446 m_aFunctionOpCodes = m_xOpCodeMapper->getAvailableMappings(sheet::FormulaLanguage::ODFF,sheet::FormulaMapGroup::FUNCTIONS);
447 m_pFunctionOpCodesEnd = m_aFunctionOpCodes.getConstArray() + m_aFunctionOpCodes.getLength();
449 m_aUnaryOpCodes = m_xOpCodeMapper->getAvailableMappings(sheet::FormulaLanguage::ODFF,sheet::FormulaMapGroup::UNARY_OPERATORS);
450 m_pUnaryOpCodesEnd = m_aUnaryOpCodes.getConstArray() + m_aUnaryOpCodes.getLength();
452 m_aBinaryOpCodes = m_xOpCodeMapper->getAvailableMappings(sheet::FormulaLanguage::ODFF,sheet::FormulaMapGroup::BINARY_OPERATORS);
453 m_pBinaryOpCodesEnd = m_aBinaryOpCodes.getConstArray() + m_aBinaryOpCodes.getLength();
455 uno::Sequence< ::rtl::OUString > aArgs(3);
456 aArgs[TOKEN_OPEN] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("("));
457 aArgs[TOKEN_CLOSE] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")"));
458 aArgs[TOKEN_SEP] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(";"));
459 m_aSeparatorsOpCodes = m_xOpCodeMapper->getMappings(aArgs,sheet::FormulaLanguage::ODFF);
461 m_aSpecialOpCodes = m_xOpCodeMapper->getAvailableMappings(sheet::FormulaLanguage::ODFF,sheet::FormulaMapGroup::SPECIAL);
462 m_pSpecialOpCodesEnd = m_aSpecialOpCodes.getConstArray() + m_aSpecialOpCodes.getLength();
463 } // if ( !m_xOpCodeMapper.is() )
464 return m_xOpCodeMapper;
467 void FormulaDlg_Impl::DeleteArgs()
469 ::std::vector< ::rtl::OUString>().swap(m_aArguments);
470 nArgs = 0;
472 namespace
474 // comparing two property instances
475 struct OpCodeCompare : public ::std::binary_function< sheet::FormulaOpCodeMapEntry, sal_Int32 , bool >
477 bool operator() (const sheet::FormulaOpCodeMapEntry& x, sal_Int32 y) const
479 return x.Token.OpCode == y;
483 // -----------------------------------------------------------------------------
484 xub_StrLen FormulaDlg_Impl::GetFunctionPos(xub_StrLen nPos)
486 const sal_Unicode sep = m_pHelper->getFunctionManager()->getSingleToken(IFunctionManager::eSep);
488 xub_StrLen nTokPos=1;
489 xub_StrLen nOldTokPos=1;
490 xub_StrLen nFuncPos=STRING_NOTFOUND; //@ Testweise
491 xub_StrLen nPrevFuncPos=1;
492 short nBracketCount=0;
493 BOOL bFlag=FALSE;
494 String aFormString = pMEdit->GetText();
495 m_aFormulaHelper.GetCharClass()->toUpper( aFormString );
497 if ( m_aTokenList.getLength() )
499 const uno::Reference< sheet::XFormulaParser > xParser(m_pHelper->getFormulaParser());
500 const table::CellAddress aRefPos(m_pHelper->getReferencePosition());
502 const sheet::FormulaToken* pIter = m_aTokenList.getConstArray();
503 const sheet::FormulaToken* pEnd = pIter + m_aTokenList.getLength();
504 //if ( pIter != pEnd && aFormString.GetChar(0) == '=' )
505 // ++pIter;
508 while ( pIter != pEnd )
510 const sal_Int32 eOp = pIter->OpCode;
511 uno::Sequence<sheet::FormulaToken> aArgs(1);
512 aArgs[0] = *pIter;
513 const String aString = xParser->printFormula(aArgs, aRefPos);
514 const sheet::FormulaToken* pNextToken = pIter + 1;
516 if(!bUserMatrixFlag && FormulaCompiler::IsMatrixFunction((OpCode)eOp) )
518 aBtnMatrix.Check();
521 if ( eOp == m_aSpecialOpCodes[sheet::FormulaMapGroupSpecialOffset::PUSH].Token.OpCode || eOp == m_aSpecialOpCodes[sheet::FormulaMapGroupSpecialOffset::SPACES].Token.OpCode )
523 const xub_StrLen n1=aFormString.Search(sep, nTokPos);
524 const xub_StrLen n2=aFormString.Search(')',nTokPos);
525 xub_StrLen nXXX=nTokPos;
526 if(n1<n2)
528 nTokPos=n1;
530 else
532 nTokPos=n2;
534 if ( pNextToken != pEnd )
536 aArgs[0] = *pNextToken;
537 const String a2String = xParser->printFormula(aArgs, aRefPos);
538 const xub_StrLen n3 = aFormString.Search(a2String,nXXX);
539 if ( n3 < nTokPos )
540 nTokPos = n3;
543 else
545 nTokPos = sal::static_int_cast<xub_StrLen>( nTokPos + aString.Len() );
548 if ( eOp == m_aSeparatorsOpCodes[TOKEN_OPEN].OpCode )
550 nBracketCount++;
551 bFlag=TRUE;
553 else if ( eOp == m_aSeparatorsOpCodes[TOKEN_CLOSE].OpCode )
555 nBracketCount--;
556 bFlag=FALSE;
557 nFuncPos=nPrevFuncPos;
559 bool bIsFunction = ::std::find_if(m_aFunctionOpCodes.getConstArray(),m_pFunctionOpCodesEnd,::std::bind2nd(OpCodeCompare(),boost::cref(eOp))) != m_pFunctionOpCodesEnd;
561 if ( bIsFunction && m_aSpecialOpCodes[sheet::FormulaMapGroupSpecialOffset::SPACES].Token.OpCode != eOp )
563 nPrevFuncPos = nFuncPos;
564 nFuncPos = nOldTokPos;
567 if ( nOldTokPos <= nPos && nPos < nTokPos )
569 if ( !bIsFunction )
571 if ( nBracketCount < 1 )
573 nFuncPos= pMEdit->GetText().Len();
575 else if ( !bFlag )
577 nFuncPos=nPrevFuncPos;
580 break;
583 pIter = pNextToken;
584 nOldTokPos = nTokPos;
585 } // while ( pIter != pEnd )
587 catch(const uno::Exception& )
589 DBG_ERROR("Exception caught!");
593 return nFuncPos;
595 // -----------------------------------------------------------------------------
596 BOOL FormulaDlg_Impl::CalcValue( const String& rStrExp, String& rStrResult )
598 BOOL bResult = TRUE;
600 if ( rStrExp.Len() > 0 )
602 // nur, wenn keine Tastatureingabe mehr anliegt, den Wert berechnen:
604 if ( !Application::AnyInput( INPUT_KEYBOARD ) )
606 bResult = m_pHelper->calculateValue(rStrExp,rStrResult);
608 else
609 bResult = FALSE;
612 return bResult;
615 void FormulaDlg_Impl::UpdateValues()
617 String aStrResult;
619 if ( CalcValue( pFuncDesc->getFormula( m_aArguments ), aStrResult ) )
620 aWndResult.SetValue( aStrResult );
622 aStrResult.Erase();
623 if ( CalcValue(m_pHelper->getCurrentFormula(), aStrResult ) )
624 aWndFormResult.SetValue( aStrResult );
625 else
627 aStrResult.Erase();
628 aWndFormResult.SetValue( aStrResult );
630 CalcStruct(pMEdit->GetText());
633 BOOL FormulaDlg_Impl::CalcStruct( const String& rStrExp)
635 BOOL bResult = TRUE;
636 xub_StrLen nLength=rStrExp.Len();
638 if ( rStrExp.Len() > 0 && aOldFormula!=rStrExp && bStructUpdate)
640 // nur, wenn keine Tastatureingabe mehr anliegt, den Wert berechnen:
642 if ( !Application::AnyInput( INPUT_KEYBOARD ) )
644 pStructPage->ClearStruct();
646 String aString=rStrExp;
647 if(rStrExp.GetChar(nLength-1)=='(')
649 aString.Erase((xub_StrLen)(nLength-1));
652 aString.EraseAllChars('\n');
653 String aStrResult;
655 if ( CalcValue(aString, aStrResult ) )
656 aWndFormResult.SetValue( aStrResult );
658 UpdateTokenArray(aString);
659 fillTree(pStructPage);
661 aOldFormula=rStrExp;
662 if(rStrExp.GetChar(nLength-1)=='(')
663 UpdateTokenArray(rStrExp);
665 else
666 bResult = FALSE;
668 return bResult;
671 // -----------------------------------------------------------------------------
672 void FormulaDlg_Impl::MakeTree(IStructHelper* _pTree,SvLBoxEntry* pParent,FormulaToken* _pToken,long Count)
674 if( _pToken != NULL && Count > 0 )
676 long nParas = _pToken->GetParamCount();
677 OpCode eOp = _pToken->GetOpCode();
679 // #i101512# for output, the original token is needed
680 FormulaToken* pOrigToken = (_pToken->GetType() == svFAP) ? _pToken->GetFAPOrigToken() : _pToken;
681 uno::Sequence<sheet::FormulaToken> aArgs(1);
682 aArgs[0] = m_aTokenMap.find(pOrigToken)->second;
685 const table::CellAddress aRefPos(m_pHelper->getReferencePosition());
686 const String aResult = m_pHelper->getFormulaParser()->printFormula(aArgs, aRefPos);
688 if ( nParas > 0 )
690 SvLBoxEntry* pEntry;
692 String aTest=_pTree->GetEntryText(pParent);
694 if(aTest==aResult &&
695 (eOp==ocAdd || eOp==ocMul ||
696 eOp==ocAmpersand))
698 pEntry=pParent;
700 else
702 if(eOp==ocBad)
704 pEntry=_pTree->InsertEntry(aResult,pParent,STRUCT_ERROR,0,_pToken);
706 else
708 pEntry=_pTree->InsertEntry(aResult,pParent,STRUCT_FOLDER,0,_pToken);
712 MakeTree(_pTree,pEntry,m_pTokenArray->PrevRPN(),nParas);
713 --Count;
714 m_pTokenArray->NextRPN();
715 MakeTree(_pTree,pParent,m_pTokenArray->PrevRPN(),Count);
717 else
719 if(eOp==ocBad)
721 _pTree->InsertEntry(aResult,pParent,STRUCT_ERROR,0,_pToken);
723 else
725 _pTree->InsertEntry(aResult,pParent,STRUCT_END,0,_pToken);
727 --Count;
728 MakeTree(_pTree,pParent,m_pTokenArray->PrevRPN(),Count);
731 catch(uno::Exception&)
733 DBG_UNHANDLED_EXCEPTION();
738 void FormulaDlg_Impl::fillTree(IStructHelper* _pTree)
740 GetFormulaOpCodeMapper();
741 FormulaToken* pToken = m_pTokenArray->LastRPN();
743 if( pToken != NULL)
745 MakeTree(_pTree,NULL,pToken,1);
748 void FormulaDlg_Impl::UpdateTokenArray( const String& rStrExp)
750 m_aTokenMap.clear();
751 m_aTokenList.realloc(0);
754 const table::CellAddress aRefPos(m_pHelper->getReferencePosition());
755 m_aTokenList = m_pHelper->getFormulaParser()->parseFormula(rStrExp, aRefPos);
757 catch(const uno::Exception&)
759 DBG_UNHANDLED_EXCEPTION();
761 GetFormulaOpCodeMapper(); // just to get it initialized
762 m_pTokenArray = m_pHelper->convertToTokenArray(m_aTokenList);
763 const sal_Int32 nLen = static_cast<sal_Int32>(m_pTokenArray->GetLen());
764 FormulaToken** pTokens = m_pTokenArray->GetArray();
765 if ( pTokens && nLen == m_aTokenList.getLength() )
767 for (sal_Int32 nPos=0; nPos<nLen; nPos++)
769 m_aTokenMap.insert(::std::map<FormulaToken*,sheet::FormulaToken>::value_type(pTokens[nPos],m_aTokenList[nPos]));
771 } // if ( pTokens && nLen == m_aTokenList.getLength() )
773 FormulaCompiler aCompiler(*m_pTokenArray.get());
774 aCompiler.SetCompileForFAP(TRUE); // #i101512# special handling is needed
775 aCompiler.CompileTokenArray();
778 void FormulaDlg_Impl::FillDialog(BOOL nFlag)
780 BOOL bNext=TRUE, bPrev=TRUE;
781 if(nFlag)
782 FillControls(bNext, bPrev);
783 FillListboxes();
784 if(nFlag)
786 aBtnBackward.Enable(bPrev);
787 aBtnForward.Enable(bNext);
790 String aStrResult;
792 if ( CalcValue(m_pHelper->getCurrentFormula(), aStrResult ) )
793 aWndFormResult.SetValue( aStrResult );
794 else
796 aStrResult.Erase();
797 aWndFormResult.SetValue( aStrResult );
801 // -----------------------------------------------------------------------------
802 void FormulaDlg_Impl::FillListboxes()
804 // Umschalten zwischen den "Seiten"
805 FormEditData* pData = m_pHelper->getFormEditData();
806 String aNewTitle;
807 // 1. Seite: Funktion auswaehlen
808 if ( pFuncDesc && pFuncDesc->getCategory() )
810 if( pFuncPage->GetCategory() != pFuncDesc->getCategory()->getNumber() + 1 )
811 pFuncPage->SetCategory(static_cast<USHORT>(pFuncDesc->getCategory()->getNumber() + 1));
813 USHORT nPos=pFuncPage->GetFuncPos(pFuncDesc);
815 pFuncPage->SetFunction(nPos);
817 else if ( pData )
819 pFuncPage->SetCategory( pData->GetCatSel() );
820 pFuncPage->SetFunction( pData->GetFuncSel() );
822 FuncSelHdl(NULL);
824 // ResizeArgArr jetzt schon in UpdateFunctionDesc
827 m_pHelper->setDispatcherLock( TRUE);// Modal-Modus einschalten
829 aNewTitle = aTitle1;
831 // HelpId fuer 1. Seite ist die aus der Resource
832 m_pParent->SetHelpId( nOldHelp );
833 m_pParent->SetUniqueId( nOldUnique );
835 // -----------------------------------------------------------------------------
836 void FormulaDlg_Impl::FillControls(BOOL &rbNext, BOOL &rbPrev)
838 // Umschalten zwischen den "Seiten"
839 FormEditData* pData = m_pHelper->getFormEditData();
840 if (!pData )
841 return;
843 String aNewTitle;
844 // 2. Seite oder Editieren: ausgewaehlte Funktion anzeigen
846 xub_StrLen nFStart = pData->GetFStart();
847 String aFormula = m_pHelper->getCurrentFormula();
848 xub_StrLen nNextFStart = nFStart;
849 xub_StrLen nNextFEnd = 0;
851 aFormula.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " )" ));
852 DeleteArgs();
853 const IFunctionDescription* pOldFuncDesc = pFuncDesc;
854 BOOL bTestFlag = FALSE;
856 if ( m_aFormulaHelper.GetNextFunc( aFormula, FALSE,
857 nNextFStart, &nNextFEnd, &pFuncDesc, &m_aArguments ) )
859 bTestFlag = (pOldFuncDesc != pFuncDesc);
860 if(bTestFlag)
862 aFtHeadLine.Hide();
863 aFtFuncName.Hide();
864 aFtFuncDesc.Hide();
865 pParaWin->SetFunctionDesc(pFuncDesc);
866 aFtEditName.SetText( pFuncDesc->getFunctionName() );
867 aFtEditName.Show();
868 pParaWin->Show();
869 const long nHelpId = pFuncDesc->getHelpId();
870 if ( nHelpId )
871 pMEdit->SetSmartHelpId(SmartId(nHelpId));
874 xub_StrLen nOldStart, nOldEnd;
875 m_pHelper->getSelection( nOldStart, nOldEnd );
876 if ( nOldStart != nNextFStart || nOldEnd != nNextFEnd )
878 m_pHelper->setSelection( nNextFStart, nNextFEnd );
880 aFuncSel.Min() = nNextFStart;
881 aFuncSel.Max() = nNextFEnd;
883 if(!bEditFlag)
884 pMEdit->SetText(m_pHelper->getCurrentFormula());
885 xub_StrLen PrivStart, PrivEnd;
886 m_pHelper->getSelection( PrivStart, PrivEnd);
887 if(!bEditFlag)
888 pMEdit->SetSelection( Selection(PrivStart, PrivEnd));
890 nArgs = pFuncDesc->getSuppressedArgumentCount();
891 USHORT nOffset = pData->GetOffset();
892 nEdFocus = pData->GetEdFocus();
894 // Verkettung der Edit's fuer Focus-Kontrolle
896 if(bTestFlag)
897 pParaWin->SetArgumentOffset(nOffset);
898 USHORT nActiv=0;
899 xub_StrLen nArgPos= m_aFormulaHelper.GetArgStart( aFormula, nFStart, 0 );
900 xub_StrLen nEditPos=(xub_StrLen) pMEdit->GetSelection().Min();
901 BOOL bFlag=FALSE;
903 for(USHORT i=0;i<nArgs;i++)
905 sal_Int32 nLength = m_aArguments[i].getLength()+1;
906 pParaWin->SetArgument(i,m_aArguments[i]);
907 if(nArgPos<=nEditPos && nEditPos<nArgPos+nLength)
909 nActiv=i;
910 bFlag=TRUE;
912 nArgPos = sal::static_int_cast<xub_StrLen>( nArgPos + nLength );
914 pParaWin->UpdateParas();
916 if(bFlag)
918 pParaWin->SetActiveLine(nActiv);
921 //pParaWin->SetEdFocus( nEdFocus );
922 UpdateValues();
924 else
926 aFtEditName.SetText(String());
927 pMEdit->SetSmartHelpId(m_aSmartEditHelpId);
929 // Test, ob vorne/hinten noch mehr Funktionen sind
931 xub_StrLen nTempStart = m_aFormulaHelper.GetArgStart( aFormula, nFStart, 0 );
932 rbNext = m_aFormulaHelper.GetNextFunc( aFormula, FALSE, nTempStart );
933 nTempStart=(xub_StrLen)pMEdit->GetSelection().Min();
934 pData->SetFStart(nTempStart);
935 rbPrev = m_aFormulaHelper.GetNextFunc( aFormula, TRUE, nTempStart );
937 // -----------------------------------------------------------------------------
939 void FormulaDlg_Impl::ClearAllParas()
941 DeleteArgs();
942 pFuncDesc = NULL;
943 pParaWin->ClearAll();
944 aWndResult.SetValue(String());
945 aFtFuncName.SetText(String());
946 FuncSelHdl(NULL);
948 if(pFuncPage->IsVisible())
950 aFtEditName.Hide();
951 pParaWin->Hide();
953 aBtnForward.Enable(TRUE); //@new
954 aFtHeadLine.Show();
955 aFtFuncName.Show();
956 aFtFuncDesc.Show();
959 String FormulaDlg_Impl::RepairFormula(const String& aFormula)
961 String aResult('=');
964 UpdateTokenArray(aFormula);
966 if ( m_aTokenList.getLength() )
968 const table::CellAddress aRefPos(m_pHelper->getReferencePosition());
969 const String sFormula(m_pHelper->getFormulaParser()->printFormula(m_aTokenList, aRefPos));
970 if ( !sFormula.Len() || sFormula.GetChar(0) != '=' )
971 aResult += sFormula;
972 else
973 aResult = sFormula;
977 catch(const uno::Exception& )
979 DBG_ERROR("Exception caught!");
981 return aResult;
984 void FormulaDlg_Impl::DoEnter(BOOL bOk)
986 // Eingabe ins Dokument uebernehmen oder abbrechen
987 if ( bOk)
989 // ggf. Dummy-Argumente entfernen
990 String aInputFormula = m_pHelper->getCurrentFormula();
991 String aString = RepairFormula(pMEdit->GetText());
992 m_pHelper->setSelection(0, aInputFormula.Len());
993 m_pHelper->setCurrentFormula(aString);
996 m_pHelper->switchBack();
998 m_pHelper->dispatch(bOk,aBtnMatrix.IsChecked());
999 // Daten loeschen
1000 m_pHelper->deleteFormData();
1002 // Dialog schliessen
1003 m_pHelper->doClose(bOk);
1005 // -----------------------------------------------------------------------------
1007 IMPL_LINK( FormulaDlg_Impl, BtnHdl, PushButton*, pBtn )
1009 if ( pBtn == &aBtnCancel )
1011 DoEnter(FALSE); // schliesst den Dialog
1013 else if ( pBtn == &aBtnEnd )
1015 DoEnter(TRUE); // schliesst den Dialog
1017 else if ( pBtn == &aBtnForward )
1019 //@pMEdit->GrabFocus(); // Damit die Selektion auch angezeigt wird.
1020 const IFunctionDescription* pDesc =pFuncPage->GetFuncDesc( pFuncPage->GetFunction() );
1022 if(pDesc==pFuncDesc || !pFuncPage->IsVisible())
1023 EditNextFunc( TRUE );
1024 else
1026 DblClkHdl(pFuncPage); //new
1027 aBtnForward.Enable(FALSE); //new
1029 //@EditNextFunc( TRUE );
1031 else if ( pBtn == &aBtnBackward )
1033 bEditFlag=FALSE;
1034 aBtnForward.Enable(TRUE);
1035 EditNextFunc( FALSE );
1036 aMEFormula.Invalidate();
1037 aMEFormula.Update();
1039 //...
1041 return 0;
1043 // -----------------------------------------------------------------------------
1046 // --------------------------------------------------------------------------
1047 // Funktionen fuer 1. Seite
1048 // --------------------------------------------------------------------------
1050 void FormulaDlg_Impl::ResizeArgArr( const IFunctionDescription* pNewFunc )
1052 if ( pFuncDesc != pNewFunc )
1054 DeleteArgs();
1056 if ( pNewFunc )
1057 nArgs = pNewFunc->getSuppressedArgumentCount();
1059 pFuncDesc = pNewFunc;
1062 // -----------------------------------------------------------------------------
1064 void FormulaDlg_Impl::UpdateFunctionDesc()
1066 FormEditData* pData = m_pHelper->getFormEditData();
1067 if (!pData)
1068 return;
1069 USHORT nCat = pFuncPage->GetCategory();
1070 if ( nCat == LISTBOX_ENTRY_NOTFOUND )
1071 nCat = 0;
1072 pData->SetCatSel( nCat );
1073 USHORT nFunc = pFuncPage->GetFunction();
1074 if ( nFunc == LISTBOX_ENTRY_NOTFOUND )
1075 nFunc = 0;
1076 pData->SetFuncSel( nFunc );
1078 if ( (pFuncPage->GetFunctionEntryCount() > 0)
1079 && (pFuncPage->GetFunction() != LISTBOX_ENTRY_NOTFOUND) )
1081 const IFunctionDescription* pDesc = pFuncPage->GetFuncDesc(pFuncPage->GetFunction() );
1082 if (pDesc)
1084 pDesc->initArgumentInfo(); // full argument info is needed
1086 String aSig = pDesc->getSignature();
1088 aFtFuncName.SetText( aSig );
1089 aFtFuncDesc.SetText( pDesc->getDescription() );
1090 ResizeArgArr( pDesc );
1092 if ( !m_aArguments.empty() ) // noch Argumente da?
1093 aSig = pDesc->getFormula( m_aArguments ); // fuer Eingabezeile
1094 //@ m_pHelper->setCurrentFormula( aSig );
1097 else
1099 aFtFuncName.SetText( String() );
1100 aFtFuncDesc.SetText( String() );
1102 //ResizeArgArr( NULL );
1103 m_pHelper->setCurrentFormula( String() );
1106 // -----------------------------------------------------------------------------
1108 // Handler fuer Listboxen
1110 IMPL_LINK( FormulaDlg_Impl, DblClkHdl, FuncPage*, EMPTYARG )
1112 USHORT nFunc = pFuncPage->GetFunction();
1114 // ex-UpdateLRUList
1115 const IFunctionDescription* pDesc = pFuncPage->GetFuncDesc(nFunc);
1116 m_pHelper->insertEntryToLRUList(pDesc);
1118 String aFuncName = pFuncPage->GetSelFunctionName();
1119 aFuncName.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "()" ));
1120 m_pHelper->setCurrentFormula(aFuncName);
1121 pMEdit->ReplaceSelected(aFuncName);
1123 Selection aSel=pMEdit->GetSelection();
1124 aSel.Max()=aSel.Max()-1;
1125 pMEdit->SetSelection(aSel);
1127 FormulaHdl(pMEdit);
1129 aSel.Min()=aSel.Max();
1130 pMEdit->SetSelection(aSel);
1132 if(nArgs==0)
1134 BtnHdl(&aBtnBackward);
1137 pParaWin->SetEdFocus(0);
1138 aBtnForward.Enable(FALSE); //@New
1140 return 0;
1142 // -----------------------------------------------------------------------------
1144 // --------------------------------------------------------------------------
1145 // Funktionen fuer rechte Seite
1146 // --------------------------------------------------------------------------
1147 void FormulaDlg_Impl::SetData(xub_StrLen nFStart,xub_StrLen nNextFStart,xub_StrLen nNextFEnd,xub_StrLen& PrivStart,xub_StrLen& PrivEnd)
1149 xub_StrLen nFEnd;
1151 // Selektion merken und neue setzen
1152 m_pHelper->getSelection( nFStart, nFEnd );
1153 m_pHelper->setSelection( nNextFStart, nNextFEnd );
1154 if(!bEditFlag)
1155 pMEdit->SetText(m_pHelper->getCurrentFormula());
1158 m_pHelper->getSelection( PrivStart, PrivEnd);
1159 if(!bEditFlag)
1161 pMEdit->SetSelection( Selection(PrivStart, PrivEnd));
1162 aMEFormula.UpdateOldSel();
1165 FormEditData* pData = m_pHelper->getFormEditData();
1166 pData->SetFStart( nNextFStart );
1167 pData->SetOffset( 0 );
1168 pData->SetEdFocus( 0 );
1170 FillDialog();
1172 // -----------------------------------------------------------------------------
1173 void FormulaDlg_Impl::EditThisFunc(xub_StrLen nFStart)
1175 FormEditData* pData = m_pHelper->getFormEditData();
1176 if (!pData) return;
1178 String aFormula = m_pHelper->getCurrentFormula();
1180 if(nFStart==NOT_FOUND)
1182 nFStart = pData->GetFStart();
1184 else
1186 pData->SetFStart(nFStart);
1189 xub_StrLen nNextFStart = nFStart;
1190 xub_StrLen nNextFEnd = 0;
1192 BOOL bFound;
1194 //@bFound = m_pHelper->getNextFunction( aFormula, FALSE, nNextFStart, &nNextFEnd, &pFuncDesc );
1196 bFound = m_aFormulaHelper.GetNextFunc( aFormula, FALSE, nNextFStart, &nNextFEnd);
1197 if ( bFound )
1199 xub_StrLen PrivStart, PrivEnd;
1200 SetData(nFStart,nNextFStart,nNextFEnd,PrivStart, PrivEnd);
1201 m_pHelper->showReference(aFormula.Copy(PrivStart, PrivEnd-PrivStart));
1203 else
1205 ClearAllParas();
1209 void FormulaDlg_Impl::EditNextFunc( BOOL bForward, xub_StrLen nFStart )
1211 FormEditData* pData = m_pHelper->getFormEditData();
1212 if (!pData)
1213 return;
1215 String aFormula = m_pHelper->getCurrentFormula();
1217 if(nFStart==NOT_FOUND)
1219 nFStart = pData->GetFStart();
1221 else
1223 pData->SetFStart(nFStart);
1226 xub_StrLen nNextFStart = 0;
1227 xub_StrLen nNextFEnd = 0;
1229 BOOL bFound;
1230 if ( bForward )
1232 nNextFStart = m_aFormulaHelper.GetArgStart( aFormula, nFStart, 0 );
1233 //@bFound = m_pHelper->getNextFunction( aFormula, FALSE, nNextFStart, &nNextFEnd, &pFuncDesc );
1234 bFound = m_aFormulaHelper.GetNextFunc( aFormula, FALSE, nNextFStart, &nNextFEnd);
1236 else
1238 nNextFStart = nFStart;
1239 //@bFound = m_pHelper->getNextFunction( aFormula, TRUE, nNextFStart, &nNextFEnd, &pFuncDesc );
1240 bFound = m_aFormulaHelper.GetNextFunc( aFormula, TRUE, nNextFStart, &nNextFEnd);
1243 if ( bFound )
1245 xub_StrLen PrivStart, PrivEnd;
1246 SetData(nFStart,nNextFStart,nNextFEnd,PrivStart, PrivEnd);
1250 void FormulaDlg_Impl::EditFuncParas(xub_StrLen nEditPos)
1252 if(pFuncDesc!=NULL)
1254 FormEditData* pData = m_pHelper->getFormEditData();
1255 if (!pData) return;
1257 String aFormula = m_pHelper->getCurrentFormula();
1258 aFormula +=')';
1259 xub_StrLen nFStart = pData->GetFStart();
1261 DeleteArgs();
1263 nArgs = pFuncDesc->getSuppressedArgumentCount();
1265 sal_Int32 nArgPos=m_aFormulaHelper.GetArgStart( aFormula, nFStart, 0 );
1266 m_aFormulaHelper.GetArgStrings(m_aArguments,aFormula, nFStart, nArgs );
1267 // m_aArguments = ScFormulaUtil::GetArgStrings( aFormula, nFStart, nArgs );
1269 USHORT nActiv=pParaWin->GetSliderPos();
1270 BOOL bFlag=FALSE;
1271 ::std::vector< ::rtl::OUString >::iterator aIter = m_aArguments.begin();
1272 ::std::vector< ::rtl::OUString >::iterator aEnd = m_aArguments.end();
1273 for(USHORT i=0;aIter != aEnd;i++,++aIter)
1275 sal_Int32 nLength=(*aIter).getLength();
1276 pParaWin->SetArgument(i,(*aIter));
1277 if(nArgPos<=nEditPos && nEditPos<nArgPos+nLength)
1279 nActiv=i;
1280 bFlag=TRUE;
1282 nArgPos+=nLength+1;
1285 if(bFlag)
1287 pParaWin->SetSliderPos(nActiv);
1290 pParaWin->UpdateParas();
1291 UpdateValues();
1296 void FormulaDlg_Impl::SaveArg( USHORT nEd )
1298 if (nEd<nArgs)
1300 USHORT i;
1301 for(i=0;i<=nEd;i++)
1303 if ( m_aArguments[i].getLength() == 0 )
1304 m_aArguments[i] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" "));
1306 if(pParaWin->GetArgument(nEd).Len()!=0)
1307 m_aArguments[nEd] = pParaWin->GetArgument(nEd);
1309 USHORT nClearPos=nEd+1;
1310 for(i=nEd+1;i<nArgs;i++)
1312 if(pParaWin->GetArgument(i).Len()!=0)
1314 nClearPos=i+1;
1318 for(i=nClearPos;i<nArgs;i++)
1320 m_aArguments[i] = ::rtl::OUString();
1325 IMPL_LINK( FormulaDlg_Impl, FxHdl, ParaWin*, pPtr )
1327 if(pPtr==pParaWin)
1329 aBtnForward.Enable(TRUE); //@ Damit eine neue Fkt eingegeben werden kann.
1330 aTabCtrl.SetCurPageId(TP_FUNCTION);
1332 String aUndoStr = m_pHelper->getCurrentFormula(); // bevor unten ein ";" eingefuegt wird
1333 FormEditData* pData = m_pHelper->getFormEditData();
1334 if (!pData) return 0;
1336 USHORT nArgNo = pParaWin->GetActiveLine();
1337 nEdFocus=nArgNo;
1339 SaveArg(nArgNo);
1340 UpdateSelection();
1342 xub_StrLen nFormulaStrPos = pData->GetFStart();
1344 String aFormula = m_pHelper->getCurrentFormula();
1345 xub_StrLen n1 = m_aFormulaHelper.GetArgStart( aFormula, nFormulaStrPos, nEdFocus+pData->GetOffset() );
1347 pData->SetEdFocus( nEdFocus );
1348 pData->SaveValues();
1349 pData->SetMode( (USHORT) FORMULA_FORMDLG_FORMULA );
1350 pData->SetFStart( n1 );
1351 pData->SetUndoStr( aUndoStr );
1352 ClearAllParas();
1354 FillDialog(FALSE);
1355 pFuncPage->SetFocus(); //Da Parawin nicht mehr sichtbar
1357 return 0;
1360 IMPL_LINK( FormulaDlg_Impl, ModifyHdl, ParaWin*, pPtr )
1362 if(pPtr==pParaWin)
1364 SaveArg(pParaWin->GetActiveLine());
1365 UpdateValues();
1367 UpdateSelection();
1368 CalcStruct(pMEdit->GetText());
1370 return 0;
1373 IMPL_LINK( FormulaDlg_Impl, FormulaHdl, MultiLineEdit*, EMPTYARG )
1376 FormEditData* pData = m_pHelper->getFormEditData();
1377 if (!pData) return 0;
1379 bEditFlag=TRUE;
1380 String aInputFormula=m_pHelper->getCurrentFormula();
1381 String aString=pMEdit->GetText();
1383 Selection aSel =pMEdit->GetSelection();
1384 xub_StrLen nTest=0;
1386 if(aString.Len()==0) //falls alles geloescht wurde
1388 aString +='=';
1389 pMEdit->SetText(aString);
1390 aSel .Min()=1;
1391 aSel .Max()=1;
1392 pMEdit->SetSelection(aSel);
1394 else if(aString.GetChar(nTest)!='=') //falls ersetzt wurde;
1396 aString.Insert( (sal_Unicode)'=', 0 );
1397 pMEdit->SetText(aString);
1398 aSel .Min()+=1;
1399 aSel .Max()+=1;
1400 pMEdit->SetSelection(aSel);
1404 m_pHelper->setSelection(0, aInputFormula.Len());
1405 m_pHelper->setCurrentFormula(aString);
1406 m_pHelper->setSelection((xub_StrLen)aSel.Min(),(xub_StrLen)aSel.Max());
1408 xub_StrLen nPos=(xub_StrLen)aSel.Min()-1;
1410 String aStrResult;
1412 if ( CalcValue(m_pHelper->getCurrentFormula(), aStrResult ) )
1413 aWndFormResult.SetValue( aStrResult );
1414 else
1416 aStrResult.Erase();
1417 aWndFormResult.SetValue( aStrResult );
1419 CalcStruct(aString);
1421 nPos=GetFunctionPos(nPos);
1423 if(nPos<aSel.Min()-1)
1425 xub_StrLen nPos1=aString.Search('(',nPos);
1426 EditNextFunc( FALSE, nPos1);
1428 else
1430 ClearAllParas();
1433 m_pHelper->setSelection((xub_StrLen)aSel.Min(),(xub_StrLen)aSel.Max());
1434 bEditFlag=FALSE;
1435 return 0;
1438 IMPL_LINK( FormulaDlg_Impl, FormulaCursorHdl, EditBox*, EMPTYARG )
1440 FormEditData* pData = m_pHelper->getFormEditData();
1441 if (!pData) return 0;
1442 xub_StrLen nFStart = pData->GetFStart();
1444 bEditFlag=TRUE;
1446 String aInputFormula=m_pHelper->getCurrentFormula();
1447 String aString=pMEdit->GetText();
1449 Selection aSel =pMEdit->GetSelection();
1450 m_pHelper->setSelection((xub_StrLen)aSel.Min(),(xub_StrLen)aSel.Max());
1452 if(aSel.Min()==0)
1454 aSel.Min()=1;
1455 pMEdit->SetSelection(aSel);
1458 if(aSel.Min()!=aString.Len())
1460 xub_StrLen nPos=(xub_StrLen)aSel.Min();
1462 nFStart=GetFunctionPos(nPos - 1);
1464 if(nFStart<nPos)
1466 xub_StrLen nPos1=m_aFormulaHelper.GetFunctionEnd(aString,nFStart);
1468 if(nPos1>nPos || nPos1==STRING_NOTFOUND)
1470 EditThisFunc(nFStart);
1472 else
1474 xub_StrLen n=nPos;
1475 short nCount=1;
1476 while(n>0)
1478 if(aString.GetChar(n)==')')
1479 nCount++;
1480 else if(aString.GetChar(n)=='(')
1481 nCount--;
1482 if(nCount==0) break;
1483 n--;
1485 if(nCount==0)
1487 nFStart=m_aFormulaHelper.GetFunctionStart(aString,n,TRUE);
1488 EditThisFunc(nFStart);
1490 else
1492 ClearAllParas();
1496 else
1498 ClearAllParas();
1501 m_pHelper->setSelection((xub_StrLen)aSel.Min(),(xub_StrLen)aSel.Max());
1503 bEditFlag=FALSE;
1504 return 0;
1507 void FormulaDlg_Impl::UpdateSelection()
1509 m_pHelper->setSelection((xub_StrLen)aFuncSel.Min(),(xub_StrLen)aFuncSel.Max());
1510 m_pHelper->setCurrentFormula( pFuncDesc->getFormula( m_aArguments ) );
1511 pMEdit->SetText(m_pHelper->getCurrentFormula());
1512 xub_StrLen PrivStart, PrivEnd;
1513 m_pHelper->getSelection( PrivStart, PrivEnd);
1514 aFuncSel.Min()=PrivStart;
1515 aFuncSel.Max()=PrivEnd;
1517 nArgs = pFuncDesc->getSuppressedArgumentCount();
1519 String aFormula=pMEdit->GetText();
1520 sal_Int32 nArgPos=m_aFormulaHelper.GetArgStart( aFormula,PrivStart,0);
1522 USHORT nPos=pParaWin->GetActiveLine();
1524 for(USHORT i=0;i<nPos;i++)
1526 nArgPos += (m_aArguments[i].getLength() + 1);
1528 sal_Int32 nLength= m_aArguments[nPos].getLength();
1530 Selection aSel(nArgPos,nArgPos+nLength);
1531 m_pHelper->setSelection((USHORT)nArgPos,(USHORT)(nArgPos+nLength));
1532 pMEdit->SetSelection(aSel);
1533 aMEFormula.UpdateOldSel();
1535 ::std::pair<RefButton*,RefEdit*> FormulaDlg_Impl::RefInputStartBefore( RefEdit* pEdit, RefButton* pButton )
1537 aEdRef.Show();
1538 pTheRefEdit = pEdit;
1539 pTheRefButton = pButton;
1541 if( pTheRefEdit )
1543 aEdRef.SetRefString( pTheRefEdit->GetText() );
1544 aEdRef.SetSelection( pTheRefEdit->GetSelection() );
1545 aEdRef.SetHelpId( pTheRefEdit->GetHelpId() );
1546 aEdRef.SetUniqueId( pTheRefEdit->GetUniqueId() );
1549 aRefBtn.Show( pButton != NULL );
1551 //m_pHelper->RefInputStart( &aEdRef, pButton ? &aRefBtn : NULL );
1552 ::std::pair<RefButton*,RefEdit*> aPair;
1553 aPair.first = pButton ? &aRefBtn : NULL;
1554 aPair.second = &aEdRef;
1555 return aPair;
1557 void FormulaDlg_Impl::RefInputStartAfter( RefEdit* /*pEdit*/, RefButton* /*pButton*/ )
1559 aRefBtn.SetEndImage();
1561 if( pTheRefEdit )
1563 String aStr = aTitle2;
1564 aStr += ' ';
1565 aStr += aFtEditName.GetText();
1566 aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "( " ) );
1567 if( pParaWin->GetActiveLine() > 0 )
1568 aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "...; " ) );
1569 aStr += pParaWin->GetActiveArgName();
1570 if( pParaWin->GetActiveLine() + 1 < nArgs )
1571 aStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "; ..." ));
1572 aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " )" ) );
1574 m_pParent->SetText( MnemonicGenerator::EraseAllMnemonicChars( aStr ) );
1577 void FormulaDlg_Impl::RefInputDoneAfter( BOOL bForced )
1579 aRefBtn.SetStartImage();
1580 if( bForced || !aRefBtn.IsVisible() )
1582 aEdRef.Hide();
1583 aRefBtn.Hide();
1584 if( pTheRefEdit )
1586 pTheRefEdit->SetRefString( aEdRef.GetText() );
1587 pTheRefEdit->GrabFocus();
1589 if( pTheRefButton )
1590 pTheRefButton->SetStartImage();
1592 USHORT nPrivActiv = pParaWin->GetActiveLine();
1593 pParaWin->SetArgument( nPrivActiv, aEdRef.GetText() );
1594 ModifyHdl( pParaWin );
1595 pTheRefEdit = NULL;
1597 m_pParent->SetText( aTitle1 );
1600 RefEdit* FormulaDlg_Impl::GetCurrRefEdit()
1602 return aEdRef.IsVisible() ? &aEdRef : pParaWin->GetActiveEdit();
1604 void FormulaDlg_Impl::Update()
1606 FormEditData* pData = m_pHelper->getFormEditData();
1607 const String sExpression = pMEdit->GetText();
1608 aOldFormula = String();
1609 UpdateTokenArray(sExpression);
1610 FormulaCursorHdl(&aMEFormula);
1611 CalcStruct(sExpression);
1612 if(pData->GetMode() == FORMULA_FORMDLG_FORMULA)
1613 aTabCtrl.SetCurPageId(TP_FUNCTION);
1614 else
1615 aTabCtrl.SetCurPageId(TP_STRUCT);
1616 aBtnMatrix.Check(pData->GetMatrixFlag());
1617 /*aTimer.SetTimeout(200);
1618 aTimer.SetTimeoutHdl(LINK( this, FormulaDlg_Impl, UpdateFocusHdl));
1619 aTimer.Start();*/
1621 void FormulaDlg_Impl::Update(const String& _sExp)
1623 CalcStruct(_sExp);
1624 FillDialog();
1625 //aBtnForward.Enable(TRUE); //@New
1626 FuncSelHdl(NULL);
1628 void FormulaDlg_Impl::SetMeText(const String& _sText)
1630 FormEditData* pData = m_pHelper->getFormEditData();
1631 pMEdit->SetText(_sText);
1632 pMEdit->SetSelection( pData->GetSelection());
1633 aMEFormula.UpdateOldSel();
1635 FormulaDlgMode FormulaDlg_Impl::SetMeText(const String& _sText,xub_StrLen PrivStart, xub_StrLen PrivEnd,BOOL bMatrix,BOOL _bSelect,BOOL _bUpdate)
1637 FormulaDlgMode eMode = FORMULA_FORMDLG_FORMULA;
1638 if(!bEditFlag)
1639 pMEdit->SetText(_sText);
1641 if ( _bSelect || !bEditFlag )
1642 pMEdit->SetSelection( Selection(PrivStart, PrivEnd));
1643 if ( _bUpdate )
1645 aMEFormula.UpdateOldSel();
1646 pMEdit->Invalidate();
1647 m_pHelper->showReference(pMEdit->GetSelected());
1648 eMode = FORMULA_FORMDLG_EDIT;
1650 aBtnMatrix.Check( bMatrix );
1651 } // if ( _bUpdate )
1652 return eMode;
1654 BOOL FormulaDlg_Impl::CheckMatrix(String& aFormula)
1656 pMEdit->GrabFocus();
1657 xub_StrLen nLen = aFormula.Len();
1658 BOOL bMatrix = nLen > 3 // Matrix-Formel ?
1659 && aFormula.GetChar(0) == '{'
1660 && aFormula.GetChar(1) == '='
1661 && aFormula.GetChar(nLen-1) == '}';
1662 if ( bMatrix )
1664 aFormula.Erase( 0, 1 );
1665 aFormula.Erase( aFormula.Len()-1, 1);
1666 aBtnMatrix.Check( bMatrix );
1667 aBtnMatrix.Disable();
1668 } // if ( bMatrix )
1670 aTabCtrl.SetCurPageId(TP_STRUCT);
1671 return bMatrix;
1673 IMPL_LINK( FormulaDlg_Impl, StructSelHdl, StructPage*, pStruP )
1675 bStructUpdate=FALSE;
1676 if(pStructPage->IsVisible()) aBtnForward.Enable(FALSE); //@New
1678 if(pStructPage==pStruP)
1680 /// TODO
1681 //ScToken* pSelToken = pStructPage->GetSelectedToken();
1682 // ScToken* pOrigToken = ((pSelToken && pSelToken->GetType() == svFAP) ?
1683 // pSelToken->GetFAPOrigToken() : pSelToken);
1684 //xub_StrLen nTokPos=1;
1686 //if(pScTokA!=NULL)
1688 // ScToken* pToken = pScTokA->First();
1690 // while(pToken!=NULL)
1691 // {
1692 // String aString;
1693 // if ( pToken == pOrigToken )
1694 // break;
1695 // pComp->CreateStringFromToken( aString,pToken);
1696 // nTokPos = sal::static_int_cast<xub_StrLen>( nTokPos + aString.Len() );
1697 // pToken=pScTokA->Next();
1698 // }
1699 // EditThisFunc(nTokPos);
1702 //if( pOrigToken )
1704 // String aStr;
1705 // pComp->CreateStringFromToken( aStr, pOrigToken );
1706 // String aEntryTxt=pStructPage->GetSelectedEntryText();
1708 // if(aEntryTxt!=aStr)
1709 // ShowReference(aEntryTxt);
1713 bStructUpdate=TRUE;
1714 return 0;
1716 IMPL_LINK( FormulaDlg_Impl, MatrixHdl, CheckBox *, EMPTYARG )
1718 bUserMatrixFlag=TRUE;
1719 return 0;
1722 IMPL_LINK( FormulaDlg_Impl, FuncSelHdl, FuncPage*, EMPTYARG )
1724 USHORT nCat = pFuncPage->GetCategory();
1725 if ( nCat == LISTBOX_ENTRY_NOTFOUND ) nCat = 0;
1726 USHORT nFunc = pFuncPage->GetFunction();
1727 if ( nFunc == LISTBOX_ENTRY_NOTFOUND ) nFunc = 0;
1729 if ( (pFuncPage->GetFunctionEntryCount() > 0)
1730 && (pFuncPage->GetFunction() != LISTBOX_ENTRY_NOTFOUND) )
1732 const IFunctionDescription* pDesc =pFuncPage->GetFuncDesc( pFuncPage->GetFunction() );
1734 if(pDesc!=pFuncDesc) aBtnForward.Enable(TRUE); //new
1736 if (pDesc)
1738 pDesc->initArgumentInfo(); // full argument info is needed
1740 String aSig = pDesc->getSignature();
1741 aFtHeadLine.SetText( pDesc->getFunctionName() );
1742 aFtFuncName.SetText( aSig );
1743 aFtFuncDesc.SetText( pDesc->getDescription() );
1746 else
1748 aFtHeadLine.SetText( String() );
1749 aFtFuncName.SetText( String() );
1750 aFtFuncDesc.SetText( String() );
1752 return 0;
1755 void FormulaDlg_Impl::UpdateParaWin(const Selection& _rSelection,const String& _sRefStr)
1757 Selection theSel = _rSelection;
1758 aEdRef.ReplaceSelected( _sRefStr );
1759 theSel.Max() = theSel.Min() + _sRefStr.Len();
1760 aEdRef.SetSelection( theSel );
1762 //-------------------------------------
1763 // Manuelles Update der Ergebnisfelder:
1764 //-------------------------------------
1765 USHORT nPrivActiv = pParaWin->GetActiveLine();
1766 pParaWin->SetArgument(nPrivActiv,aEdRef.GetText());
1767 pParaWin->UpdateParas();
1769 Edit* pEd = GetCurrRefEdit();
1770 if( pEd != NULL )
1771 pEd->SetSelection( theSel );
1773 pParaWin->SetRefMode(FALSE);
1775 BOOL FormulaDlg_Impl::UpdateParaWin(Selection& _rSelection)
1777 pParaWin->SetRefMode(TRUE);
1779 String aStrEd;
1780 Edit* pEd = GetCurrRefEdit();
1781 if(pEd!=NULL && pTheRefEdit==NULL)
1783 _rSelection=pEd->GetSelection();
1784 _rSelection.Justify();
1785 aStrEd=pEd->GetText();
1786 aEdRef.SetRefString(aStrEd);
1787 aEdRef.SetSelection( _rSelection );
1789 else
1791 _rSelection=aEdRef.GetSelection();
1792 _rSelection.Justify();
1793 aStrEd= aEdRef.GetText();
1795 return pTheRefEdit == NULL;
1797 ULONG FormulaDlg_Impl::FindFocusWin(Window *pWin)
1799 ULONG nUniqueId=0;
1800 if(pWin->HasFocus())
1802 nUniqueId=pWin->GetUniqueId();
1803 if(nUniqueId==0)
1805 Window* pParent=pWin->GetParent();
1806 while(pParent!=NULL)
1808 nUniqueId=pParent->GetUniqueId();
1810 if(nUniqueId!=0) break;
1812 pParent=pParent->GetParent();
1816 else
1818 USHORT nCount=pWin->GetChildCount();
1820 for(USHORT i=0;i<nCount;i++)
1822 Window* pChild=pWin->GetChild(i);
1823 nUniqueId=FindFocusWin(pChild);
1824 if(nUniqueId>0) break;
1827 return nUniqueId;
1830 void FormulaDlg_Impl::SetEdSelection()
1832 Edit* pEd = GetCurrRefEdit()/*aScParaWin.GetActiveEdit()*/;
1833 if( pEd )
1835 Selection theSel = aEdRef.GetSelection();
1836 // Edit may have the focus -> call ModifyHdl in addition
1837 // to what's happening in GetFocus
1838 pEd->GetModifyHdl().Call(pEd);
1839 pEd->GrabFocus();
1840 pEd->SetSelection(theSel);
1841 } // if( pEd )
1843 // -----------------------------------------------------------------------------
1844 const FormulaHelper& FormulaDlg_Impl::GetFormulaHelper() const
1846 return m_aFormulaHelper;
1848 //============================================================================
1849 FormulaModalDialog::FormulaModalDialog( Window* pParent
1850 , bool _bSupportFunctionResult
1851 , bool _bSupportResult
1852 , bool _bSupportMatrix
1853 , IFormulaEditorHelper* _pHelper
1854 , IFunctionManager* _pFunctionMgr
1855 , IControlReferenceHandler* _pDlg ) :
1856 ModalDialog( pParent, ModuleRes(RID_FORMULADLG_FORMULA_MODAL) ),
1857 m_pImpl( new FormulaDlg_Impl(this,_bSupportFunctionResult
1858 , _bSupportResult
1859 , _bSupportMatrix
1860 ,_pHelper,_pFunctionMgr,_pDlg))
1862 FreeResource();
1863 SetText(m_pImpl->aTitle1);
1865 FormulaModalDialog::~FormulaModalDialog()
1868 // -----------------------------------------------------------------------------
1869 void FormulaModalDialog::Update(const String& _sExp)
1871 m_pImpl->Update(_sExp);
1874 // -----------------------------------------------------------------------------
1875 void FormulaModalDialog::SetMeText(const String& _sText)
1877 m_pImpl->SetMeText(_sText);
1880 // -----------------------------------------------------------------------------
1881 FormulaDlgMode FormulaModalDialog::SetMeText(const String& _sText,xub_StrLen PrivStart, xub_StrLen PrivEnd,BOOL bMatrix,BOOL _bSelect,BOOL _bUpdate)
1883 return m_pImpl->SetMeText(_sText,PrivStart, PrivEnd,bMatrix,_bSelect,_bUpdate);
1885 // -----------------------------------------------------------------------------
1886 void FormulaModalDialog::CheckMatrix()
1888 m_pImpl->aBtnMatrix.Check();
1890 // -----------------------------------------------------------------------------
1891 BOOL FormulaModalDialog::CheckMatrix(String& aFormula)
1893 return m_pImpl->CheckMatrix(aFormula);
1895 // -----------------------------------------------------------------------------
1896 String FormulaModalDialog::GetMeText() const
1898 return m_pImpl->pMEdit->GetText();
1900 // -----------------------------------------------------------------------------
1901 void FormulaModalDialog::Update()
1903 m_pImpl->Update();
1905 // -----------------------------------------------------------------------------
1906 const FormulaHelper& FormulaModalDialog::GetFormulaHelper() const
1908 return m_pImpl->GetFormulaHelper();
1910 // -----------------------------------------------------------------------------
1911 BOOL FormulaModalDialog::isUserMatrix() const
1913 return m_pImpl->bUserMatrixFlag;
1915 void FormulaModalDialog::DoEnter(BOOL _bOk)
1917 m_pImpl->DoEnter(_bOk);
1919 ::std::pair<RefButton*,RefEdit*> FormulaModalDialog::RefInputStartBefore( RefEdit* pEdit, RefButton* pButton )
1921 return m_pImpl->RefInputStartBefore( pEdit, pButton );
1923 void FormulaModalDialog::RefInputStartAfter( RefEdit* pEdit, RefButton* pButton )
1925 m_pImpl->RefInputStartAfter( pEdit, pButton );
1927 void FormulaModalDialog::RefInputDoneAfter( BOOL bForced )
1929 m_pImpl->RefInputDoneAfter( bForced );
1932 ULONG FormulaModalDialog::FindFocusWin(Window *pWin)
1934 return m_pImpl->FindFocusWin( pWin );
1937 void FormulaModalDialog::SetFocusWin(Window *pWin,ULONG nUniqueId)
1939 if(pWin->GetUniqueId()==nUniqueId)
1941 pWin->GrabFocus();
1943 else
1945 USHORT nCount=pWin->GetChildCount();
1947 for(USHORT i=0;i<nCount;i++)
1949 Window* pChild=pWin->GetChild(i);
1950 SetFocusWin(pChild,nUniqueId);
1956 long FormulaModalDialog::PreNotify( NotifyEvent& rNEvt )
1958 m_pImpl->PreNotify( rNEvt );
1960 return ModalDialog::PreNotify(rNEvt);
1963 void FormulaModalDialog::HighlightFunctionParas(const String& aFormula)
1965 m_pImpl->m_pHelper->showReference(aFormula);
1968 void FormulaModalDialog::disableOk()
1970 m_pImpl->aBtnEnd.Disable();
1972 // -----------------------------------------------------------------------------
1973 const IFunctionDescription* FormulaModalDialog::getCurrentFunctionDescription() const
1975 OSL_VERIFY(!m_pImpl->pFuncDesc || m_pImpl->pFuncDesc->getSuppressedArgumentCount() == m_pImpl->nArgs);
1976 return m_pImpl->pFuncDesc;
1978 // -----------------------------------------------------------------------------
1979 void FormulaModalDialog::UpdateParaWin(const Selection& _rSelection,const String& _sRefStr)
1981 m_pImpl->UpdateParaWin(_rSelection,_sRefStr);
1983 BOOL FormulaModalDialog::UpdateParaWin(Selection& _rSelection)
1985 return m_pImpl->UpdateParaWin(_rSelection);
1987 // -----------------------------------------------------------------------------
1988 RefEdit* FormulaModalDialog::GetActiveEdit()
1990 return m_pImpl->pParaWin->GetActiveEdit();
1992 // -----------------------------------------------------------------------------
1993 void FormulaModalDialog::SetEdSelection()
1995 m_pImpl->SetEdSelection();
1998 // --------------------------------------------------------------------------
1999 // Initialisierung / gemeinsaME Funktionen fuer Dialog
2000 // --------------------------------------------------------------------------
2001 FormulaDlg::FormulaDlg( SfxBindings* pB, SfxChildWindow* pCW,
2002 Window* pParent
2003 , bool _bSupportFunctionResult
2004 , bool _bSupportResult
2005 , bool _bSupportMatrix
2006 , IFormulaEditorHelper* _pHelper,IFunctionManager* _pFunctionMgr,IControlReferenceHandler* _pDlg ) :
2007 SfxModelessDialog( pB, pCW, pParent, ModuleRes(RID_FORMULADLG_FORMULA) ),
2008 m_pImpl( new FormulaDlg_Impl(this, _bSupportFunctionResult
2009 , _bSupportResult
2010 , _bSupportMatrix
2011 ,_pHelper,_pFunctionMgr,_pDlg))
2013 FreeResource();
2014 if(GetHelpId()==0) //Hack, da im SfxModelessDialog die HelpId
2015 SetHelpId(GetUniqueId()); //fuer einen ModelessDialog entfernt und
2016 //in eine UniqueId gewandelt wird, machen
2017 //wir das an dieser Stelle rueckgaengig.
2018 SetText(m_pImpl->aTitle1);
2021 FormulaDlg::~FormulaDlg()
2024 // -----------------------------------------------------------------------------
2025 void FormulaDlg::Update(const String& _sExp)
2027 m_pImpl->Update(_sExp);
2030 // -----------------------------------------------------------------------------
2031 void FormulaDlg::SetMeText(const String& _sText)
2033 m_pImpl->SetMeText(_sText);
2036 // -----------------------------------------------------------------------------
2037 FormulaDlgMode FormulaDlg::SetMeText(const String& _sText,xub_StrLen PrivStart, xub_StrLen PrivEnd,BOOL bMatrix,BOOL _bSelect,BOOL _bUpdate)
2039 return m_pImpl->SetMeText(_sText,PrivStart, PrivEnd,bMatrix,_bSelect,_bUpdate);
2041 // -----------------------------------------------------------------------------
2042 void FormulaDlg::CheckMatrix()
2044 m_pImpl->aBtnMatrix.Check();
2046 // -----------------------------------------------------------------------------
2047 BOOL FormulaDlg::CheckMatrix(String& aFormula)
2049 return m_pImpl->CheckMatrix(aFormula);
2051 // -----------------------------------------------------------------------------
2052 String FormulaDlg::GetMeText() const
2054 return m_pImpl->pMEdit->GetText();
2056 // -----------------------------------------------------------------------------
2057 void FormulaDlg::Update()
2059 m_pImpl->Update();
2060 m_pImpl->aTimer.SetTimeout(200);
2061 m_pImpl->aTimer.SetTimeoutHdl(LINK( this, FormulaDlg, UpdateFocusHdl));
2062 m_pImpl->aTimer.Start();
2065 // -----------------------------------------------------------------------------
2066 BOOL FormulaDlg::isUserMatrix() const
2068 return m_pImpl->bUserMatrixFlag;
2070 void FormulaDlg::DoEnter(BOOL _bOk)
2072 m_pImpl->DoEnter(_bOk);
2074 ::std::pair<RefButton*,RefEdit*> FormulaDlg::RefInputStartBefore( RefEdit* pEdit, RefButton* pButton )
2076 return m_pImpl->RefInputStartBefore( pEdit, pButton );
2078 void FormulaDlg::RefInputStartAfter( RefEdit* pEdit, RefButton* pButton )
2080 m_pImpl->RefInputStartAfter( pEdit, pButton );
2082 void FormulaDlg::RefInputDoneAfter( BOOL bForced )
2084 m_pImpl->RefInputDoneAfter( bForced );
2087 ULONG FormulaDlg::FindFocusWin(Window *pWin)
2089 return m_pImpl->FindFocusWin( pWin );
2092 void FormulaDlg::SetFocusWin(Window *pWin,ULONG nUniqueId)
2094 if(pWin->GetUniqueId()==nUniqueId)
2096 pWin->GrabFocus();
2098 else
2100 USHORT nCount=pWin->GetChildCount();
2102 for(USHORT i=0;i<nCount;i++)
2104 Window* pChild=pWin->GetChild(i);
2105 SetFocusWin(pChild,nUniqueId);
2111 long FormulaDlg::PreNotify( NotifyEvent& rNEvt )
2113 m_pImpl->PreNotify( rNEvt );
2114 return SfxModelessDialog::PreNotify(rNEvt);
2117 void FormulaDlg::HighlightFunctionParas(const String& aFormula)
2119 m_pImpl->m_pHelper->showReference(aFormula);
2122 void FormulaDlg::disableOk()
2124 m_pImpl->aBtnEnd.Disable();
2126 // -----------------------------------------------------------------------------
2127 const IFunctionDescription* FormulaDlg::getCurrentFunctionDescription() const
2129 OSL_VERIFY(!m_pImpl->pFuncDesc || m_pImpl->pFuncDesc->getSuppressedArgumentCount() == m_pImpl->nArgs);
2130 return m_pImpl->pFuncDesc;
2132 // -----------------------------------------------------------------------------
2133 void FormulaDlg::UpdateParaWin(const Selection& _rSelection,const String& _sRefStr)
2135 m_pImpl->UpdateParaWin(_rSelection,_sRefStr);
2137 BOOL FormulaDlg::UpdateParaWin(Selection& _rSelection)
2139 return m_pImpl->UpdateParaWin(_rSelection);
2141 // -----------------------------------------------------------------------------
2142 RefEdit* FormulaDlg::GetActiveEdit()
2144 return m_pImpl->pParaWin->GetActiveEdit();
2146 // -----------------------------------------------------------------------------
2147 const FormulaHelper& FormulaDlg::GetFormulaHelper() const
2149 return m_pImpl->GetFormulaHelper();
2151 // -----------------------------------------------------------------------------
2152 void FormulaDlg::SetEdSelection()
2154 m_pImpl->SetEdSelection();
2156 IMPL_LINK( FormulaDlg, UpdateFocusHdl, Timer*, EMPTYARG )
2158 FormEditData* pData = m_pImpl->m_pHelper->getFormEditData();
2160 if (pData) // wird nicht ueber Close zerstoert;
2162 m_pImpl->m_pHelper->setReferenceInput(pData);
2163 ULONG nUniqueId=pData->GetUniqueId();
2164 SetFocusWin(this,nUniqueId);
2166 return 0;
2169 // -----------------------------------------------------------------------------
2170 // -----------------------------------------------------------------------------
2171 void FormEditData::SaveValues()
2173 FormEditData* pTemp = new FormEditData(*this);
2175 Reset();
2176 pParent = pTemp;
2178 // -----------------------------------------------------------------------------
2179 void FormEditData::Reset()
2181 pParent = NULL;
2182 nMode = 0;
2183 nFStart = 0;
2184 nCatSel = 1; //! oder 0 (zuletzt benutzte)
2185 nFuncSel = 0;
2186 nOffset = 0;
2187 nEdFocus = 0;
2188 bMatrix =FALSE;
2189 nUniqueId=0;
2190 aSelection.Min()=0;
2191 aSelection.Max()=0;
2192 aUndoStr.Erase();
2194 // -----------------------------------------------------------------------------
2195 void FormEditData::RestoreValues()
2197 FormEditData* pTemp = pParent;
2198 DBG_ASSERT(pTemp,"RestoreValues ohne Parent");
2199 if (pTemp)
2201 *this = *pTemp;
2202 pTemp->pParent = NULL; // sonst wird der auch geloescht!
2203 delete pTemp;
2206 // -----------------------------------------------------------------------------
2207 const FormEditData& FormEditData::operator=( const FormEditData& r )
2209 pParent = r.pParent;
2210 nMode = r.nMode;
2211 nFStart = r.nFStart;
2212 nCatSel = r.nCatSel;
2213 nFuncSel = r.nFuncSel;
2214 nOffset = r.nOffset;
2215 nEdFocus = r.nEdFocus;
2216 aUndoStr = r.aUndoStr;
2217 bMatrix = r.bMatrix ;
2218 nUniqueId = r.nUniqueId;
2219 aSelection = r.aSelection;
2220 return *this;
2222 // -----------------------------------------------------------------------------
2223 FormEditData::FormEditData()
2225 Reset();
2228 FormEditData::~FormEditData()
2230 delete pParent;
2233 FormEditData::FormEditData( const FormEditData& r )
2235 *this = r;
2238 // -----------------------------------------------------------------------------
2239 } // formula
2240 // -----------------------------------------------------------------------------