sync master with lastest vba changes
[ooovba.git] / formula / source / ui / dlg / formula.cxx
blob3226298bd9c093c0d50d17c59306432c1c47c67b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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();
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());
501 const sheet::FormulaToken* pIter = m_aTokenList.getConstArray();
502 const sheet::FormulaToken* pEnd = pIter + m_aTokenList.getLength();
503 //if ( pIter != pEnd && aFormString.GetChar(0) == '=' )
504 // ++pIter;
507 while ( pIter != pEnd )
509 const sal_Int32 eOp = pIter->OpCode;
510 uno::Sequence<sheet::FormulaToken> aArgs(1);
511 aArgs[0] = *pIter;
512 const String aString = xParser->printFormula(aArgs);
513 const sheet::FormulaToken* pNextToken = pIter + 1;
515 if(!bUserMatrixFlag && FormulaCompiler::IsMatrixFunction((OpCode)eOp) )
517 aBtnMatrix.Check();
520 if ( eOp == m_aSpecialOpCodes[sheet::FormulaMapGroupSpecialOffset::PUSH].Token.OpCode || eOp == m_aSpecialOpCodes[sheet::FormulaMapGroupSpecialOffset::SPACES].Token.OpCode )
522 const xub_StrLen n1=aFormString.Search(sep, nTokPos);
523 const xub_StrLen n2=aFormString.Search(')',nTokPos);
524 xub_StrLen nXXX=nTokPos;
525 if(n1<n2)
527 nTokPos=n1;
529 else
531 nTokPos=n2;
533 if ( pNextToken != pEnd )
535 aArgs[0] = *pNextToken;
536 const String a2String = xParser->printFormula(aArgs);
537 const xub_StrLen n3 = aFormString.Search(a2String,nXXX);
538 if ( n3 < nTokPos )
539 nTokPos = n3;
542 else
544 nTokPos = sal::static_int_cast<xub_StrLen>( nTokPos + aString.Len() );
547 if ( eOp == m_aSeparatorsOpCodes[TOKEN_OPEN].OpCode )
549 nBracketCount++;
550 bFlag=TRUE;
552 else if ( eOp == m_aSeparatorsOpCodes[TOKEN_CLOSE].OpCode )
554 nBracketCount--;
555 bFlag=FALSE;
556 nFuncPos=nPrevFuncPos;
558 bool bIsFunction = ::std::find_if(m_aFunctionOpCodes.getConstArray(),m_pFunctionOpCodesEnd,::std::bind2nd(OpCodeCompare(),boost::cref(eOp))) != m_pFunctionOpCodesEnd;
560 if ( bIsFunction && m_aSpecialOpCodes[sheet::FormulaMapGroupSpecialOffset::SPACES].Token.OpCode != eOp )
562 nPrevFuncPos = nFuncPos;
563 nFuncPos = nOldTokPos;
566 if ( nOldTokPos <= nPos && nPos < nTokPos )
568 if ( !bIsFunction )
570 if ( nBracketCount < 1 )
572 nFuncPos= pMEdit->GetText().Len();
574 else if ( !bFlag )
576 nFuncPos=nPrevFuncPos;
579 break;
582 pIter = pNextToken;
583 nOldTokPos = nTokPos;
584 } // while ( pIter != pEnd )
586 catch(const uno::Exception& )
588 DBG_ERROR("Exception caught!");
592 return nFuncPos;
594 // -----------------------------------------------------------------------------
595 BOOL FormulaDlg_Impl::CalcValue( const String& rStrExp, String& rStrResult )
597 BOOL bResult = TRUE;
599 if ( rStrExp.Len() > 0 )
601 // nur, wenn keine Tastatureingabe mehr anliegt, den Wert berechnen:
603 if ( !Application::AnyInput( INPUT_KEYBOARD ) )
605 bResult = m_pHelper->calculateValue(rStrExp,rStrResult);
607 else
608 bResult = FALSE;
611 return bResult;
614 void FormulaDlg_Impl::UpdateValues()
616 String aStrResult;
618 if ( CalcValue( pFuncDesc->getFormula( m_aArguments ), aStrResult ) )
619 aWndResult.SetValue( aStrResult );
621 aStrResult.Erase();
622 if ( CalcValue(m_pHelper->getCurrentFormula(), aStrResult ) )
623 aWndFormResult.SetValue( aStrResult );
624 else
626 aStrResult.Erase();
627 aWndFormResult.SetValue( aStrResult );
629 CalcStruct(pMEdit->GetText());
632 BOOL FormulaDlg_Impl::CalcStruct( const String& rStrExp)
634 BOOL bResult = TRUE;
635 xub_StrLen nLength=rStrExp.Len();
637 if ( rStrExp.Len() > 0 && aOldFormula!=rStrExp && bStructUpdate)
639 // nur, wenn keine Tastatureingabe mehr anliegt, den Wert berechnen:
641 if ( !Application::AnyInput( INPUT_KEYBOARD ) )
643 pStructPage->ClearStruct();
645 String aString=rStrExp;
646 if(rStrExp.GetChar(nLength-1)=='(')
648 aString.Erase((xub_StrLen)(nLength-1));
651 aString.EraseAllChars('\n');
652 String aStrResult;
654 if ( CalcValue(aString, aStrResult ) )
655 aWndFormResult.SetValue( aStrResult );
657 UpdateTokenArray(aString);
658 fillTree(pStructPage);
660 aOldFormula=rStrExp;
661 if(rStrExp.GetChar(nLength-1)=='(')
662 UpdateTokenArray(rStrExp);
664 else
665 bResult = FALSE;
667 return bResult;
670 // -----------------------------------------------------------------------------
671 void FormulaDlg_Impl::MakeTree(IStructHelper* _pTree,SvLBoxEntry* pParent,FormulaToken* _pToken,long Count)
673 if( _pToken != NULL && Count > 0 )
675 long nParas = _pToken->GetParamCount();
676 OpCode eOp = _pToken->GetOpCode();
678 uno::Sequence<sheet::FormulaToken> aArgs(1);
679 aArgs[0] = m_aTokenMap.find(_pToken)->second;
682 const String aResult = m_pHelper->getFormulaParser()->printFormula(aArgs);
684 if ( nParas > 0 )
686 SvLBoxEntry* pEntry;
688 String aTest=_pTree->GetEntryText(pParent);
690 if(aTest==aResult &&
691 (eOp==ocAdd || eOp==ocMul ||
692 eOp==ocAmpersand))
694 pEntry=pParent;
696 else
698 if(eOp==ocBad)
700 pEntry=_pTree->InsertEntry(aResult,pParent,STRUCT_ERROR,0,_pToken);
702 else
704 pEntry=_pTree->InsertEntry(aResult,pParent,STRUCT_FOLDER,0,_pToken);
708 MakeTree(_pTree,pEntry,m_pTokenArray->PrevRPN(),nParas);
709 --Count;
710 m_pTokenArray->NextRPN();
711 MakeTree(_pTree,pParent,m_pTokenArray->PrevRPN(),Count);
713 else
715 if(eOp==ocBad)
717 _pTree->InsertEntry(aResult,pParent,STRUCT_ERROR,0,_pToken);
719 else
721 _pTree->InsertEntry(aResult,pParent,STRUCT_END,0,_pToken);
723 --Count;
724 MakeTree(_pTree,pParent,m_pTokenArray->PrevRPN(),Count);
727 catch(uno::Exception&)
729 DBG_UNHANDLED_EXCEPTION();
734 void FormulaDlg_Impl::fillTree(IStructHelper* _pTree)
736 GetFormulaOpCodeMapper();
737 FormulaToken* pToken = m_pTokenArray->LastRPN();
739 if( pToken != NULL)
741 MakeTree(_pTree,NULL,pToken,1);
744 void FormulaDlg_Impl::UpdateTokenArray( const String& rStrExp)
746 m_aTokenMap.clear();
747 m_aTokenList.realloc(0);
750 m_aTokenList = m_pHelper->getFormulaParser()->parseFormula(rStrExp);
752 catch(const uno::Exception&)
754 DBG_UNHANDLED_EXCEPTION();
756 GetFormulaOpCodeMapper(); // just to get it initialized
757 m_pTokenArray = m_pHelper->convertToTokenArray(m_aTokenList);
758 const sal_Int32 nLen = static_cast<sal_Int32>(m_pTokenArray->GetLen());
759 FormulaToken** pTokens = m_pTokenArray->GetArray();
760 if ( pTokens && nLen == m_aTokenList.getLength() )
762 for (sal_Int32 nPos=0; nPos<nLen; nPos++)
764 m_aTokenMap.insert(::std::map<FormulaToken*,sheet::FormulaToken>::value_type(pTokens[nPos],m_aTokenList[nPos]));
766 } // if ( pTokens && nLen == m_aTokenList.getLength() )
768 FormulaCompiler aCompiler(*m_pTokenArray.get());
769 aCompiler.CompileTokenArray();
772 void FormulaDlg_Impl::FillDialog(BOOL nFlag)
774 if ( nFlag )
775 FillControls();
776 FillListboxes();
778 String aStrResult;
780 if ( CalcValue(m_pHelper->getCurrentFormula(), aStrResult ) )
781 aWndFormResult.SetValue( aStrResult );
782 else
784 aStrResult.Erase();
785 aWndFormResult.SetValue( aStrResult );
789 // -----------------------------------------------------------------------------
790 void FormulaDlg_Impl::FillListboxes()
792 // Umschalten zwischen den "Seiten"
793 FormEditData* pData = m_pHelper->getFormEditData();
794 String aNewTitle;
795 // 1. Seite: Funktion auswaehlen
796 if ( pFuncDesc && pFuncDesc->getCategory() )
798 if( pFuncPage->GetCategory() != pFuncDesc->getCategory()->getNumber() + 1 )
799 pFuncPage->SetCategory(static_cast<USHORT>(pFuncDesc->getCategory()->getNumber() + 1));
801 USHORT nPos=pFuncPage->GetFuncPos(pFuncDesc);
803 pFuncPage->SetFunction(nPos);
805 else if ( pData )
807 pFuncPage->SetCategory( pData->GetCatSel() );
808 pFuncPage->SetFunction( pData->GetFuncSel() );
810 FuncSelHdl(NULL);
812 // ResizeArgArr jetzt schon in UpdateFunctionDesc
815 m_pHelper->setDispatcherLock( TRUE);// Modal-Modus einschalten
817 aNewTitle = aTitle1;
819 // HelpId fuer 1. Seite ist die aus der Resource
820 m_pParent->SetHelpId( nOldHelp );
821 m_pParent->SetUniqueId( nOldUnique );
823 // -----------------------------------------------------------------------------
824 void FormulaDlg_Impl::FillControls()
826 // Umschalten zwischen den "Seiten"
827 FormEditData* pData = m_pHelper->getFormEditData();
828 if (!pData )
829 return;
831 String aNewTitle;
832 // 2. Seite oder Editieren: ausgewaehlte Funktion anzeigen
834 xub_StrLen nFStart = pData->GetFStart();
835 String aFormula = m_pHelper->getCurrentFormula();
836 xub_StrLen nNextFStart = nFStart;
837 xub_StrLen nNextFEnd = 0;
839 aFormula.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " )" ));
840 DeleteArgs();
841 const IFunctionDescription* pOldFuncDesc = pFuncDesc;
842 BOOL bTestFlag = FALSE;
844 if ( m_aFormulaHelper.GetNextFunc( aFormula, FALSE,
845 nNextFStart, &nNextFEnd, &pFuncDesc, &m_aArguments ) )
847 bTestFlag = (pOldFuncDesc != pFuncDesc);
848 if(bTestFlag)
850 aFtHeadLine.Hide();
851 aFtFuncName.Hide();
852 aFtFuncDesc.Hide();
853 pParaWin->SetFunctionDesc(pFuncDesc);
854 aFtEditName.SetText( pFuncDesc->getFunctionName() );
855 aFtEditName.Show();
856 pParaWin->Show();
857 const long nHelpId = pFuncDesc->getHelpId();
858 if ( nHelpId )
859 pMEdit->SetSmartHelpId(SmartId(nHelpId));
862 xub_StrLen nOldStart, nOldEnd;
863 m_pHelper->getSelection( nOldStart, nOldEnd );
864 if ( nOldStart != nNextFStart || nOldEnd != nNextFEnd )
866 m_pHelper->setSelection( nNextFStart, nNextFEnd );
868 aFuncSel.Min() = nNextFStart;
869 aFuncSel.Max() = nNextFEnd;
871 if(!bEditFlag)
872 pMEdit->SetText(m_pHelper->getCurrentFormula());
873 xub_StrLen PrivStart, PrivEnd;
874 m_pHelper->getSelection( PrivStart, PrivEnd);
875 if(!bEditFlag)
876 pMEdit->SetSelection( Selection(PrivStart, PrivEnd));
878 nArgs = pFuncDesc->getSuppressedArgumentCount();
879 USHORT nOffset = pData->GetOffset();
880 nEdFocus = pData->GetEdFocus();
882 // Verkettung der Edit's fuer Focus-Kontrolle
884 if(bTestFlag)
885 pParaWin->SetArgumentOffset(nOffset);
886 USHORT nActiv=0;
887 xub_StrLen nArgPos= m_aFormulaHelper.GetArgStart( aFormula, nFStart, 0 );
888 xub_StrLen nEditPos=(xub_StrLen) pMEdit->GetSelection().Min();
889 BOOL bFlag=FALSE;
891 for(USHORT i=0;i<nArgs;i++)
893 sal_Int32 nLength = m_aArguments[i].getLength()+1;
894 pParaWin->SetArgument(i,m_aArguments[i]);
895 if(nArgPos<=nEditPos && nEditPos<nArgPos+nLength)
897 nActiv=i;
898 bFlag=TRUE;
900 nArgPos = sal::static_int_cast<xub_StrLen>( nArgPos + nLength );
902 pParaWin->UpdateParas();
904 if(bFlag)
906 pParaWin->SetActiveLine(nActiv);
909 //pParaWin->SetEdFocus( nEdFocus );
910 UpdateValues();
912 else
914 aFtEditName.SetText(String());
915 pMEdit->SetSmartHelpId(m_aSmartEditHelpId);
917 // Test, ob vorne/hinten noch mehr Funktionen sind
919 xub_StrLen nTempStart = m_aFormulaHelper.GetArgStart( aFormula, nFStart, 0 );
920 BOOL bNext = m_aFormulaHelper.GetNextFunc( aFormula, FALSE, nTempStart );
921 nTempStart=(xub_StrLen)pMEdit->GetSelection().Min();
922 pData->SetFStart(nTempStart);
923 BOOL bPrev = m_aFormulaHelper.GetNextFunc( aFormula, TRUE, nTempStart );
924 aBtnBackward.Enable(bPrev);
925 aBtnForward.Enable(bNext);
927 // -----------------------------------------------------------------------------
929 void FormulaDlg_Impl::ClearAllParas()
931 DeleteArgs();
932 pFuncDesc = NULL;
933 pParaWin->ClearAll();
934 aWndResult.SetValue(String());
935 aFtFuncName.SetText(String());
936 FuncSelHdl(NULL);
938 if(pFuncPage->IsVisible())
940 aFtEditName.Hide();
941 pParaWin->Hide();
943 aBtnForward.Enable(TRUE); //@new
944 aFtHeadLine.Show();
945 aFtFuncName.Show();
946 aFtFuncDesc.Show();
949 String FormulaDlg_Impl::RepairFormula(const String& aFormula)
951 String aResult('=');
954 UpdateTokenArray(aFormula);
956 if ( m_aTokenList.getLength() )
958 const String sFormula(m_pHelper->getFormulaParser()->printFormula(m_aTokenList));
959 if ( !sFormula.Len() || sFormula.GetChar(0) != '=' )
960 aResult += sFormula;
961 else
962 aResult = sFormula;
966 catch(const uno::Exception& )
968 DBG_ERROR("Exception caught!");
970 return aResult;
973 void FormulaDlg_Impl::DoEnter(BOOL bOk)
975 // Eingabe ins Dokument uebernehmen oder abbrechen
976 if ( bOk)
978 // ggf. Dummy-Argumente entfernen
979 String aInputFormula = m_pHelper->getCurrentFormula();
980 String aString = RepairFormula(pMEdit->GetText());
981 m_pHelper->setSelection(0, aInputFormula.Len());
982 m_pHelper->setCurrentFormula(aString);
985 m_pHelper->switchBack();
987 m_pHelper->dispatch(bOk,aBtnMatrix.IsChecked());
988 // Daten loeschen
989 m_pHelper->deleteFormData();
991 // Dialog schliessen
992 m_pHelper->doClose(bOk);
994 // -----------------------------------------------------------------------------
996 IMPL_LINK( FormulaDlg_Impl, BtnHdl, PushButton*, pBtn )
998 if ( pBtn == &aBtnCancel )
1000 DoEnter(FALSE); // schliesst den Dialog
1002 else if ( pBtn == &aBtnEnd )
1004 DoEnter(TRUE); // schliesst den Dialog
1006 else if ( pBtn == &aBtnForward )
1008 //@pMEdit->GrabFocus(); // Damit die Selektion auch angezeigt wird.
1009 const IFunctionDescription* pDesc =pFuncPage->GetFuncDesc( pFuncPage->GetFunction() );
1011 if(pDesc==pFuncDesc || !pFuncPage->IsVisible())
1012 EditNextFunc( TRUE );
1013 else
1015 DblClkHdl(pFuncPage); //new
1016 aBtnForward.Enable(FALSE); //new
1018 //@EditNextFunc( TRUE );
1020 else if ( pBtn == &aBtnBackward )
1022 bEditFlag=FALSE;
1023 aBtnForward.Enable(TRUE);
1024 EditNextFunc( FALSE );
1025 aMEFormula.Invalidate();
1026 aMEFormula.Update();
1028 //...
1030 return 0;
1032 // -----------------------------------------------------------------------------
1035 // --------------------------------------------------------------------------
1036 // Funktionen fuer 1. Seite
1037 // --------------------------------------------------------------------------
1039 void FormulaDlg_Impl::ResizeArgArr( const IFunctionDescription* pNewFunc )
1041 if ( pFuncDesc != pNewFunc )
1043 DeleteArgs();
1045 if ( pNewFunc )
1046 nArgs = pNewFunc->getSuppressedArgumentCount();
1048 pFuncDesc = pNewFunc;
1051 // -----------------------------------------------------------------------------
1053 void FormulaDlg_Impl::UpdateFunctionDesc()
1055 FormEditData* pData = m_pHelper->getFormEditData();
1056 if (!pData)
1057 return;
1058 USHORT nCat = pFuncPage->GetCategory();
1059 if ( nCat == LISTBOX_ENTRY_NOTFOUND )
1060 nCat = 0;
1061 pData->SetCatSel( nCat );
1062 USHORT nFunc = pFuncPage->GetFunction();
1063 if ( nFunc == LISTBOX_ENTRY_NOTFOUND )
1064 nFunc = 0;
1065 pData->SetFuncSel( nFunc );
1067 if ( (pFuncPage->GetFunctionEntryCount() > 0)
1068 && (pFuncPage->GetFunction() != LISTBOX_ENTRY_NOTFOUND) )
1070 const IFunctionDescription* pDesc = pFuncPage->GetFuncDesc(pFuncPage->GetFunction() );
1071 if (pDesc)
1073 pDesc->initArgumentInfo(); // full argument info is needed
1075 String aSig = pDesc->getSignature();
1077 aFtFuncName.SetText( aSig );
1078 aFtFuncDesc.SetText( pDesc->getDescription() );
1079 ResizeArgArr( pDesc );
1081 if ( !m_aArguments.empty() ) // noch Argumente da?
1082 aSig = pDesc->getFormula( m_aArguments ); // fuer Eingabezeile
1083 //@ m_pHelper->setCurrentFormula( aSig );
1086 else
1088 aFtFuncName.SetText( String() );
1089 aFtFuncDesc.SetText( String() );
1091 //ResizeArgArr( NULL );
1092 m_pHelper->setCurrentFormula( String() );
1095 // -----------------------------------------------------------------------------
1097 // Handler fuer Listboxen
1099 IMPL_LINK( FormulaDlg_Impl, DblClkHdl, FuncPage*, EMPTYARG )
1101 USHORT nFunc = pFuncPage->GetFunction();
1103 // ex-UpdateLRUList
1104 const IFunctionDescription* pDesc = pFuncPage->GetFuncDesc(nFunc);
1105 m_pHelper->insertEntryToLRUList(pDesc);
1107 String aFuncName = pFuncPage->GetSelFunctionName();
1108 aFuncName.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "()" ));
1109 m_pHelper->setCurrentFormula(aFuncName);
1110 pMEdit->ReplaceSelected(aFuncName);
1112 Selection aSel=pMEdit->GetSelection();
1113 aSel.Max()=aSel.Max()-1;
1114 pMEdit->SetSelection(aSel);
1116 FormulaHdl(pMEdit);
1118 aSel.Min()=aSel.Max();
1119 pMEdit->SetSelection(aSel);
1121 if(nArgs==0)
1123 BtnHdl(&aBtnBackward);
1126 pParaWin->SetEdFocus(0);
1127 aBtnForward.Enable(FALSE); //@New
1129 return 0;
1131 // -----------------------------------------------------------------------------
1133 // --------------------------------------------------------------------------
1134 // Funktionen fuer rechte Seite
1135 // --------------------------------------------------------------------------
1136 void FormulaDlg_Impl::SetData(xub_StrLen nFStart,xub_StrLen nNextFStart,xub_StrLen nNextFEnd,xub_StrLen& PrivStart,xub_StrLen& PrivEnd)
1138 xub_StrLen nFEnd;
1140 // Selektion merken und neue setzen
1141 m_pHelper->getSelection( nFStart, nFEnd );
1142 m_pHelper->setSelection( nNextFStart, nNextFEnd );
1143 if(!bEditFlag)
1144 pMEdit->SetText(m_pHelper->getCurrentFormula());
1147 m_pHelper->getSelection( PrivStart, PrivEnd);
1148 if(!bEditFlag)
1150 pMEdit->SetSelection( Selection(PrivStart, PrivEnd));
1151 aMEFormula.UpdateOldSel();
1154 FormEditData* pData = m_pHelper->getFormEditData();
1155 pData->SetFStart( nNextFStart );
1156 pData->SetOffset( 0 );
1157 pData->SetEdFocus( 0 );
1159 FillDialog();
1161 // -----------------------------------------------------------------------------
1162 void FormulaDlg_Impl::EditThisFunc(xub_StrLen nFStart)
1164 FormEditData* pData = m_pHelper->getFormEditData();
1165 if (!pData) return;
1167 String aFormula = m_pHelper->getCurrentFormula();
1169 if(nFStart==NOT_FOUND)
1171 nFStart = pData->GetFStart();
1173 else
1175 pData->SetFStart(nFStart);
1178 xub_StrLen nNextFStart = nFStart;
1179 xub_StrLen nNextFEnd = 0;
1181 BOOL bFound;
1183 //@bFound = m_pHelper->getNextFunction( aFormula, FALSE, nNextFStart, &nNextFEnd, &pFuncDesc );
1185 bFound = m_aFormulaHelper.GetNextFunc( aFormula, FALSE, nNextFStart, &nNextFEnd);
1186 if ( bFound )
1188 xub_StrLen PrivStart, PrivEnd;
1189 SetData(nFStart,nNextFStart,nNextFEnd,PrivStart, PrivEnd);
1190 m_pHelper->showReference(aFormula.Copy(PrivStart, PrivEnd-PrivStart));
1192 else
1194 ClearAllParas();
1198 void FormulaDlg_Impl::EditNextFunc( BOOL bForward, xub_StrLen nFStart )
1200 FormEditData* pData = m_pHelper->getFormEditData();
1201 if (!pData)
1202 return;
1204 String aFormula = m_pHelper->getCurrentFormula();
1206 if(nFStart==NOT_FOUND)
1208 nFStart = pData->GetFStart();
1210 else
1212 pData->SetFStart(nFStart);
1215 xub_StrLen nNextFStart = 0;
1216 xub_StrLen nNextFEnd = 0;
1218 BOOL bFound;
1219 if ( bForward )
1221 nNextFStart = m_aFormulaHelper.GetArgStart( aFormula, nFStart, 0 );
1222 //@bFound = m_pHelper->getNextFunction( aFormula, FALSE, nNextFStart, &nNextFEnd, &pFuncDesc );
1223 bFound = m_aFormulaHelper.GetNextFunc( aFormula, FALSE, nNextFStart, &nNextFEnd);
1225 else
1227 nNextFStart = nFStart;
1228 //@bFound = m_pHelper->getNextFunction( aFormula, TRUE, nNextFStart, &nNextFEnd, &pFuncDesc );
1229 bFound = m_aFormulaHelper.GetNextFunc( aFormula, TRUE, nNextFStart, &nNextFEnd);
1232 if ( bFound )
1234 xub_StrLen PrivStart, PrivEnd;
1235 SetData(nFStart,nNextFStart,nNextFEnd,PrivStart, PrivEnd);
1239 void FormulaDlg_Impl::EditFuncParas(xub_StrLen nEditPos)
1241 if(pFuncDesc!=NULL)
1243 FormEditData* pData = m_pHelper->getFormEditData();
1244 if (!pData) return;
1246 String aFormula = m_pHelper->getCurrentFormula();
1247 aFormula +=')';
1248 xub_StrLen nFStart = pData->GetFStart();
1250 DeleteArgs();
1252 nArgs = pFuncDesc->getSuppressedArgumentCount();
1254 sal_Int32 nArgPos=m_aFormulaHelper.GetArgStart( aFormula, nFStart, 0 );
1255 m_aFormulaHelper.GetArgStrings(m_aArguments,aFormula, nFStart, nArgs );
1256 // m_aArguments = ScFormulaUtil::GetArgStrings( aFormula, nFStart, nArgs );
1258 USHORT nActiv=pParaWin->GetSliderPos();
1259 BOOL bFlag=FALSE;
1260 ::std::vector< ::rtl::OUString >::iterator aIter = m_aArguments.begin();
1261 ::std::vector< ::rtl::OUString >::iterator aEnd = m_aArguments.end();
1262 for(USHORT i=0;aIter != aEnd;i++,++aIter)
1264 sal_Int32 nLength=(*aIter).getLength();
1265 pParaWin->SetArgument(i,(*aIter));
1266 if(nArgPos<=nEditPos && nEditPos<nArgPos+nLength)
1268 nActiv=i;
1269 bFlag=TRUE;
1271 nArgPos+=nLength+1;
1274 if(bFlag)
1276 pParaWin->SetSliderPos(nActiv);
1279 pParaWin->UpdateParas();
1280 UpdateValues();
1285 void FormulaDlg_Impl::SaveArg( USHORT nEd )
1287 if (nEd<nArgs)
1289 USHORT i;
1290 for(i=0;i<=nEd;i++)
1292 if ( m_aArguments[i].getLength() == 0 )
1293 m_aArguments[i] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" "));
1295 if(pParaWin->GetArgument(nEd).Len()!=0)
1296 m_aArguments[nEd] = pParaWin->GetArgument(nEd);
1298 USHORT nClearPos=nEd+1;
1299 for(i=nEd+1;i<nArgs;i++)
1301 if(pParaWin->GetArgument(i).Len()!=0)
1303 nClearPos=i+1;
1307 for(i=nClearPos;i<nArgs;i++)
1309 m_aArguments[i] = ::rtl::OUString();
1314 IMPL_LINK( FormulaDlg_Impl, FxHdl, ParaWin*, pPtr )
1316 if(pPtr==pParaWin)
1318 aBtnForward.Enable(TRUE); //@ Damit eine neue Fkt eingegeben werden kann.
1319 aTabCtrl.SetCurPageId(TP_FUNCTION);
1321 String aUndoStr = m_pHelper->getCurrentFormula(); // bevor unten ein ";" eingefuegt wird
1322 FormEditData* pData = m_pHelper->getFormEditData();
1323 if (!pData) return 0;
1325 USHORT nArgNo = pParaWin->GetActiveLine();
1326 nEdFocus=nArgNo;
1328 SaveArg(nArgNo);
1329 UpdateSelection();
1331 xub_StrLen nFormulaStrPos = pData->GetFStart();
1333 String aFormula = m_pHelper->getCurrentFormula();
1334 xub_StrLen n1 = m_aFormulaHelper.GetArgStart( aFormula, nFormulaStrPos, nEdFocus+pData->GetOffset() );
1336 pData->SetEdFocus( nEdFocus );
1337 pData->SaveValues();
1338 pData->SetMode( (USHORT) FORMULA_FORMDLG_FORMULA );
1339 pData->SetFStart( n1 );
1340 pData->SetUndoStr( aUndoStr );
1341 ClearAllParas();
1343 FillDialog(FALSE);
1344 pFuncPage->SetFocus(); //Da Parawin nicht mehr sichtbar
1346 return 0;
1349 IMPL_LINK( FormulaDlg_Impl, ModifyHdl, ParaWin*, pPtr )
1351 if(pPtr==pParaWin)
1353 SaveArg(pParaWin->GetActiveLine());
1354 UpdateValues();
1356 UpdateSelection();
1357 CalcStruct(pMEdit->GetText());
1359 return 0;
1362 IMPL_LINK( FormulaDlg_Impl, FormulaHdl, MultiLineEdit*, EMPTYARG )
1365 FormEditData* pData = m_pHelper->getFormEditData();
1366 if (!pData) return 0;
1368 bEditFlag=TRUE;
1369 String aInputFormula=m_pHelper->getCurrentFormula();
1370 String aString=pMEdit->GetText();
1372 Selection aSel =pMEdit->GetSelection();
1373 xub_StrLen nTest=0;
1375 if(aString.Len()==0) //falls alles geloescht wurde
1377 aString +='=';
1378 pMEdit->SetText(aString);
1379 aSel .Min()=1;
1380 aSel .Max()=1;
1381 pMEdit->SetSelection(aSel);
1383 else if(aString.GetChar(nTest)!='=') //falls ersetzt wurde;
1385 aString.Insert( (sal_Unicode)'=', 0 );
1386 pMEdit->SetText(aString);
1387 aSel .Min()+=1;
1388 aSel .Max()+=1;
1389 pMEdit->SetSelection(aSel);
1393 m_pHelper->setSelection(0, aInputFormula.Len());
1394 m_pHelper->setCurrentFormula(aString);
1395 m_pHelper->setSelection((xub_StrLen)aSel.Min(),(xub_StrLen)aSel.Max());
1397 xub_StrLen nPos=(xub_StrLen)aSel.Min()-1;
1399 String aStrResult;
1401 if ( CalcValue(m_pHelper->getCurrentFormula(), aStrResult ) )
1402 aWndFormResult.SetValue( aStrResult );
1403 else
1405 aStrResult.Erase();
1406 aWndFormResult.SetValue( aStrResult );
1408 CalcStruct(aString);
1410 nPos=GetFunctionPos(nPos);
1412 if(nPos<aSel.Min()-1)
1414 xub_StrLen nPos1=aString.Search('(',nPos);
1415 EditNextFunc( FALSE, nPos1);
1417 else
1419 ClearAllParas();
1422 m_pHelper->setSelection((xub_StrLen)aSel.Min(),(xub_StrLen)aSel.Max());
1423 bEditFlag=FALSE;
1424 return 0;
1427 IMPL_LINK( FormulaDlg_Impl, FormulaCursorHdl, EditBox*, EMPTYARG )
1429 FormEditData* pData = m_pHelper->getFormEditData();
1430 if (!pData) return 0;
1431 xub_StrLen nFStart = pData->GetFStart();
1433 bEditFlag=TRUE;
1435 String aInputFormula=m_pHelper->getCurrentFormula();
1436 String aString=pMEdit->GetText();
1438 Selection aSel =pMEdit->GetSelection();
1439 m_pHelper->setSelection((xub_StrLen)aSel.Min(),(xub_StrLen)aSel.Max());
1441 if(aSel.Min()==0)
1443 aSel.Min()=1;
1444 pMEdit->SetSelection(aSel);
1447 if(aSel.Min()!=aString.Len())
1449 xub_StrLen nPos=(xub_StrLen)aSel.Min();
1451 nFStart=GetFunctionPos(nPos - 1);
1453 if(nFStart<nPos)
1455 xub_StrLen nPos1=m_aFormulaHelper.GetFunctionEnd(aString,nFStart);
1457 if(nPos1>nPos || nPos1==STRING_NOTFOUND)
1459 EditThisFunc(nFStart);
1461 else
1463 xub_StrLen n=nPos;
1464 short nCount=1;
1465 while(n>0)
1467 if(aString.GetChar(n)==')')
1468 nCount++;
1469 else if(aString.GetChar(n)=='(')
1470 nCount--;
1471 if(nCount==0) break;
1472 n--;
1474 if(nCount==0)
1476 nFStart=m_aFormulaHelper.GetFunctionStart(aString,n,TRUE);
1477 EditThisFunc(nFStart);
1479 else
1481 ClearAllParas();
1485 else
1487 ClearAllParas();
1490 m_pHelper->setSelection((xub_StrLen)aSel.Min(),(xub_StrLen)aSel.Max());
1492 bEditFlag=FALSE;
1493 return 0;
1496 void FormulaDlg_Impl::UpdateSelection()
1498 m_pHelper->setSelection((xub_StrLen)aFuncSel.Min(),(xub_StrLen)aFuncSel.Max());
1499 m_pHelper->setCurrentFormula( pFuncDesc->getFormula( m_aArguments ) );
1500 pMEdit->SetText(m_pHelper->getCurrentFormula());
1501 xub_StrLen PrivStart, PrivEnd;
1502 m_pHelper->getSelection( PrivStart, PrivEnd);
1503 aFuncSel.Min()=PrivStart;
1504 aFuncSel.Max()=PrivEnd;
1506 nArgs = pFuncDesc->getSuppressedArgumentCount();
1508 String aFormula=pMEdit->GetText();
1509 sal_Int32 nArgPos=m_aFormulaHelper.GetArgStart( aFormula,PrivStart,0);
1511 USHORT nPos=pParaWin->GetActiveLine();
1513 for(USHORT i=0;i<nPos;i++)
1515 nArgPos += (m_aArguments[i].getLength() + 1);
1517 sal_Int32 nLength= m_aArguments[nPos].getLength();
1519 Selection aSel(nArgPos,nArgPos+nLength);
1520 m_pHelper->setSelection((USHORT)nArgPos,(USHORT)(nArgPos+nLength));
1521 pMEdit->SetSelection(aSel);
1522 aMEFormula.UpdateOldSel();
1524 ::std::pair<RefButton*,RefEdit*> FormulaDlg_Impl::RefInputStartBefore( RefEdit* pEdit, RefButton* pButton )
1526 aEdRef.Show();
1527 pTheRefEdit = pEdit;
1528 pTheRefButton = pButton;
1530 if( pTheRefEdit )
1532 aEdRef.SetRefString( pTheRefEdit->GetText() );
1533 aEdRef.SetSelection( pTheRefEdit->GetSelection() );
1534 aEdRef.SetHelpId( pTheRefEdit->GetHelpId() );
1535 aEdRef.SetUniqueId( pTheRefEdit->GetUniqueId() );
1538 aRefBtn.Show( pButton != NULL );
1540 //m_pHelper->RefInputStart( &aEdRef, pButton ? &aRefBtn : NULL );
1541 ::std::pair<RefButton*,RefEdit*> aPair;
1542 aPair.first = pButton ? &aRefBtn : NULL;
1543 aPair.second = &aEdRef;
1544 return aPair;
1546 void FormulaDlg_Impl::RefInputStartAfter( RefEdit* /*pEdit*/, RefButton* /*pButton*/ )
1548 aRefBtn.SetEndImage();
1550 if( pTheRefEdit )
1552 String aStr = aTitle2;
1553 aStr += ' ';
1554 aStr += aFtEditName.GetText();
1555 aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "( " ) );
1556 if( pParaWin->GetActiveLine() > 0 )
1557 aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "...; " ) );
1558 aStr += pParaWin->GetActiveArgName();
1559 if( pParaWin->GetActiveLine() + 1 < nArgs )
1560 aStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "; ..." ));
1561 aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " )" ) );
1563 m_pParent->SetText( MnemonicGenerator::EraseAllMnemonicChars( aStr ) );
1566 void FormulaDlg_Impl::RefInputDoneAfter( BOOL bForced )
1568 aRefBtn.SetStartImage();
1569 if( bForced || !aRefBtn.IsVisible() )
1571 aEdRef.Hide();
1572 aRefBtn.Hide();
1573 if( pTheRefEdit )
1575 pTheRefEdit->SetRefString( aEdRef.GetText() );
1576 pTheRefEdit->GrabFocus();
1578 if( pTheRefButton )
1579 pTheRefButton->SetStartImage();
1581 USHORT nPrivActiv = pParaWin->GetActiveLine();
1582 pParaWin->SetArgument( nPrivActiv, aEdRef.GetText() );
1583 ModifyHdl( pParaWin );
1584 pTheRefEdit = NULL;
1586 m_pParent->SetText( aTitle1 );
1589 RefEdit* FormulaDlg_Impl::GetCurrRefEdit()
1591 return aEdRef.IsVisible() ? &aEdRef : pParaWin->GetActiveEdit();
1593 void FormulaDlg_Impl::Update()
1595 FormEditData* pData = m_pHelper->getFormEditData();
1596 const String sExpression = pMEdit->GetText();
1597 UpdateTokenArray(sExpression);
1598 FormulaCursorHdl(&aMEFormula);
1599 CalcStruct(sExpression);
1600 if(pData->GetMode() == FORMULA_FORMDLG_FORMULA)
1601 aTabCtrl.SetCurPageId(TP_FUNCTION);
1602 else
1603 aTabCtrl.SetCurPageId(TP_STRUCT);
1604 aBtnMatrix.Check(pData->GetMatrixFlag());
1605 /*aTimer.SetTimeout(200);
1606 aTimer.SetTimeoutHdl(LINK( this, FormulaDlg_Impl, UpdateFocusHdl));
1607 aTimer.Start();*/
1609 void FormulaDlg_Impl::Update(const String& _sExp)
1611 CalcStruct(_sExp);
1612 FillDialog();
1613 //aBtnForward.Enable(TRUE); //@New
1614 FuncSelHdl(NULL);
1616 void FormulaDlg_Impl::SetMeText(const String& _sText)
1618 FormEditData* pData = m_pHelper->getFormEditData();
1619 pMEdit->SetText(_sText);
1620 pMEdit->SetSelection( pData->GetSelection());
1621 aMEFormula.UpdateOldSel();
1623 FormulaDlgMode FormulaDlg_Impl::SetMeText(const String& _sText,xub_StrLen PrivStart, xub_StrLen PrivEnd,BOOL bMatrix,BOOL _bSelect,BOOL _bUpdate)
1625 FormulaDlgMode eMode = FORMULA_FORMDLG_FORMULA;
1626 if(!bEditFlag)
1627 pMEdit->SetText(_sText);
1629 if ( _bSelect || !bEditFlag )
1630 pMEdit->SetSelection( Selection(PrivStart, PrivEnd));
1631 if ( _bUpdate )
1633 aMEFormula.UpdateOldSel();
1634 pMEdit->Invalidate();
1635 m_pHelper->showReference(pMEdit->GetSelected());
1636 eMode = FORMULA_FORMDLG_EDIT;
1638 aBtnMatrix.Check( bMatrix );
1639 } // if ( _bUpdate )
1640 return eMode;
1642 BOOL FormulaDlg_Impl::CheckMatrix(String& aFormula)
1644 pMEdit->GrabFocus();
1645 xub_StrLen nLen = aFormula.Len();
1646 BOOL bMatrix = nLen > 3 // Matrix-Formel ?
1647 && aFormula.GetChar(0) == '{'
1648 && aFormula.GetChar(1) == '='
1649 && aFormula.GetChar(nLen-1) == '}';
1650 if ( bMatrix )
1652 aFormula.Erase( 0, 1 );
1653 aFormula.Erase( aFormula.Len()-1, 1);
1654 aBtnMatrix.Check( bMatrix );
1655 aBtnMatrix.Disable();
1656 } // if ( bMatrix )
1658 aTabCtrl.SetCurPageId(TP_STRUCT);
1659 return bMatrix;
1661 IMPL_LINK( FormulaDlg_Impl, StructSelHdl, StructPage*, pStruP )
1663 bStructUpdate=FALSE;
1664 if(pStructPage->IsVisible()) aBtnForward.Enable(FALSE); //@New
1666 if(pStructPage==pStruP)
1668 /// TODO
1669 //ScToken* pSelToken = pStructPage->GetSelectedToken();
1670 // ScToken* pOrigToken = ((pSelToken && pSelToken->GetType() == svFAP) ?
1671 // pSelToken->GetFAPOrigToken() : pSelToken);
1672 //xub_StrLen nTokPos=1;
1674 //if(pScTokA!=NULL)
1676 // ScToken* pToken = pScTokA->First();
1678 // while(pToken!=NULL)
1679 // {
1680 // String aString;
1681 // if ( pToken == pOrigToken )
1682 // break;
1683 // pComp->CreateStringFromToken( aString,pToken);
1684 // nTokPos = sal::static_int_cast<xub_StrLen>( nTokPos + aString.Len() );
1685 // pToken=pScTokA->Next();
1686 // }
1687 // EditThisFunc(nTokPos);
1690 //if( pOrigToken )
1692 // String aStr;
1693 // pComp->CreateStringFromToken( aStr, pOrigToken );
1694 // String aEntryTxt=pStructPage->GetSelectedEntryText();
1696 // if(aEntryTxt!=aStr)
1697 // ShowReference(aEntryTxt);
1701 bStructUpdate=TRUE;
1702 return 0;
1704 IMPL_LINK( FormulaDlg_Impl, MatrixHdl, CheckBox *, EMPTYARG )
1706 bUserMatrixFlag=TRUE;
1707 return 0;
1710 IMPL_LINK( FormulaDlg_Impl, FuncSelHdl, FuncPage*, EMPTYARG )
1712 USHORT nCat = pFuncPage->GetCategory();
1713 if ( nCat == LISTBOX_ENTRY_NOTFOUND ) nCat = 0;
1714 USHORT nFunc = pFuncPage->GetFunction();
1715 if ( nFunc == LISTBOX_ENTRY_NOTFOUND ) nFunc = 0;
1717 if ( (pFuncPage->GetFunctionEntryCount() > 0)
1718 && (pFuncPage->GetFunction() != LISTBOX_ENTRY_NOTFOUND) )
1720 const IFunctionDescription* pDesc =pFuncPage->GetFuncDesc( pFuncPage->GetFunction() );
1722 if(pDesc!=pFuncDesc) aBtnForward.Enable(TRUE); //new
1724 if (pDesc)
1726 pDesc->initArgumentInfo(); // full argument info is needed
1728 String aSig = pDesc->getSignature();
1729 aFtHeadLine.SetText( pDesc->getFunctionName() );
1730 aFtFuncName.SetText( aSig );
1731 aFtFuncDesc.SetText( pDesc->getDescription() );
1734 else
1736 aFtHeadLine.SetText( String() );
1737 aFtFuncName.SetText( String() );
1738 aFtFuncDesc.SetText( String() );
1740 return 0;
1743 void FormulaDlg_Impl::UpdateParaWin(const Selection& _rSelection,const String& _sRefStr)
1745 Selection theSel = _rSelection;
1746 aEdRef.ReplaceSelected( _sRefStr );
1747 theSel.Max() = theSel.Min() + _sRefStr.Len();
1748 aEdRef.SetSelection( theSel );
1750 //-------------------------------------
1751 // Manuelles Update der Ergebnisfelder:
1752 //-------------------------------------
1753 USHORT nPrivActiv = pParaWin->GetActiveLine();
1754 pParaWin->SetArgument(nPrivActiv,aEdRef.GetText());
1755 pParaWin->UpdateParas();
1757 Edit* pEd = GetCurrRefEdit();
1758 if( pEd != NULL )
1759 pEd->SetSelection( theSel );
1761 pParaWin->SetRefMode(FALSE);
1763 BOOL FormulaDlg_Impl::UpdateParaWin(Selection& _rSelection)
1765 pParaWin->SetRefMode(TRUE);
1767 String aStrEd;
1768 Edit* pEd = GetCurrRefEdit();
1769 if(pEd!=NULL && pTheRefEdit==NULL)
1771 _rSelection=pEd->GetSelection();
1772 _rSelection.Justify();
1773 aStrEd=pEd->GetText();
1774 aEdRef.SetRefString(aStrEd);
1775 aEdRef.SetSelection( _rSelection );
1777 else
1779 _rSelection=aEdRef.GetSelection();
1780 _rSelection.Justify();
1781 aStrEd= aEdRef.GetText();
1783 return pTheRefEdit == NULL;
1785 ULONG FormulaDlg_Impl::FindFocusWin(Window *pWin)
1787 ULONG nUniqueId=0;
1788 if(pWin->HasFocus())
1790 nUniqueId=pWin->GetUniqueId();
1791 if(nUniqueId==0)
1793 Window* pParent=pWin->GetParent();
1794 while(pParent!=NULL)
1796 nUniqueId=pParent->GetUniqueId();
1798 if(nUniqueId!=0) break;
1800 pParent=pParent->GetParent();
1804 else
1806 USHORT nCount=pWin->GetChildCount();
1808 for(USHORT i=0;i<nCount;i++)
1810 Window* pChild=pWin->GetChild(i);
1811 nUniqueId=FindFocusWin(pChild);
1812 if(nUniqueId>0) break;
1815 return nUniqueId;
1818 void FormulaDlg_Impl::SetEdSelection()
1820 Edit* pEd = GetCurrRefEdit()/*aScParaWin.GetActiveEdit()*/;
1821 if( pEd )
1823 Selection theSel = aEdRef.GetSelection();
1824 // Edit may have the focus -> call ModifyHdl in addition
1825 // to what's happening in GetFocus
1826 pEd->GetModifyHdl().Call(pEd);
1827 pEd->GrabFocus();
1828 pEd->SetSelection(theSel);
1829 } // if( pEd )
1831 // -----------------------------------------------------------------------------
1832 const FormulaHelper& FormulaDlg_Impl::GetFormulaHelper() const
1834 return m_aFormulaHelper;
1836 //============================================================================
1837 FormulaModalDialog::FormulaModalDialog( Window* pParent
1838 , bool _bSupportFunctionResult
1839 , bool _bSupportResult
1840 , bool _bSupportMatrix
1841 , IFormulaEditorHelper* _pHelper
1842 , IFunctionManager* _pFunctionMgr
1843 , IControlReferenceHandler* _pDlg ) :
1844 ModalDialog( pParent, ModuleRes(RID_FORMULADLG_FORMULA_MODAL) ),
1845 m_pImpl( new FormulaDlg_Impl(this,_bSupportFunctionResult
1846 , _bSupportResult
1847 , _bSupportMatrix
1848 ,_pHelper,_pFunctionMgr,_pDlg))
1850 FreeResource();
1851 SetText(m_pImpl->aTitle1);
1853 FormulaModalDialog::~FormulaModalDialog()
1856 // -----------------------------------------------------------------------------
1857 void FormulaModalDialog::Update(const String& _sExp)
1859 m_pImpl->Update(_sExp);
1862 // -----------------------------------------------------------------------------
1863 void FormulaModalDialog::SetMeText(const String& _sText)
1865 m_pImpl->SetMeText(_sText);
1868 // -----------------------------------------------------------------------------
1869 FormulaDlgMode FormulaModalDialog::SetMeText(const String& _sText,xub_StrLen PrivStart, xub_StrLen PrivEnd,BOOL bMatrix,BOOL _bSelect,BOOL _bUpdate)
1871 return m_pImpl->SetMeText(_sText,PrivStart, PrivEnd,bMatrix,_bSelect,_bUpdate);
1873 // -----------------------------------------------------------------------------
1874 void FormulaModalDialog::CheckMatrix()
1876 m_pImpl->aBtnMatrix.Check();
1878 // -----------------------------------------------------------------------------
1879 BOOL FormulaModalDialog::CheckMatrix(String& aFormula)
1881 return m_pImpl->CheckMatrix(aFormula);
1883 // -----------------------------------------------------------------------------
1884 String FormulaModalDialog::GetMeText() const
1886 return m_pImpl->pMEdit->GetText();
1888 // -----------------------------------------------------------------------------
1889 void FormulaModalDialog::Update()
1891 m_pImpl->Update();
1893 // -----------------------------------------------------------------------------
1894 const FormulaHelper& FormulaModalDialog::GetFormulaHelper() const
1896 return m_pImpl->GetFormulaHelper();
1898 // -----------------------------------------------------------------------------
1899 BOOL FormulaModalDialog::isUserMatrix() const
1901 return m_pImpl->bUserMatrixFlag;
1903 void FormulaModalDialog::DoEnter(BOOL _bOk)
1905 m_pImpl->DoEnter(_bOk);
1907 ::std::pair<RefButton*,RefEdit*> FormulaModalDialog::RefInputStartBefore( RefEdit* pEdit, RefButton* pButton )
1909 return m_pImpl->RefInputStartBefore( pEdit, pButton );
1911 void FormulaModalDialog::RefInputStartAfter( RefEdit* pEdit, RefButton* pButton )
1913 m_pImpl->RefInputStartAfter( pEdit, pButton );
1915 void FormulaModalDialog::RefInputDoneAfter( BOOL bForced )
1917 m_pImpl->RefInputDoneAfter( bForced );
1920 ULONG FormulaModalDialog::FindFocusWin(Window *pWin)
1922 return m_pImpl->FindFocusWin( pWin );
1925 void FormulaModalDialog::SetFocusWin(Window *pWin,ULONG nUniqueId)
1927 if(pWin->GetUniqueId()==nUniqueId)
1929 pWin->GrabFocus();
1931 else
1933 USHORT nCount=pWin->GetChildCount();
1935 for(USHORT i=0;i<nCount;i++)
1937 Window* pChild=pWin->GetChild(i);
1938 SetFocusWin(pChild,nUniqueId);
1944 long FormulaModalDialog::PreNotify( NotifyEvent& rNEvt )
1946 m_pImpl->PreNotify( rNEvt );
1948 return ModalDialog::PreNotify(rNEvt);
1951 void FormulaModalDialog::HighlightFunctionParas(const String& aFormula)
1953 m_pImpl->m_pHelper->showReference(aFormula);
1956 void FormulaModalDialog::disableOk()
1958 m_pImpl->aBtnEnd.Disable();
1960 // -----------------------------------------------------------------------------
1961 const IFunctionDescription* FormulaModalDialog::getCurrentFunctionDescription() const
1963 OSL_VERIFY(!m_pImpl->pFuncDesc || m_pImpl->pFuncDesc->getSuppressedArgumentCount() == m_pImpl->nArgs);
1964 return m_pImpl->pFuncDesc;
1966 // -----------------------------------------------------------------------------
1967 void FormulaModalDialog::UpdateParaWin(const Selection& _rSelection,const String& _sRefStr)
1969 m_pImpl->UpdateParaWin(_rSelection,_sRefStr);
1971 BOOL FormulaModalDialog::UpdateParaWin(Selection& _rSelection)
1973 return m_pImpl->UpdateParaWin(_rSelection);
1975 // -----------------------------------------------------------------------------
1976 RefEdit* FormulaModalDialog::GetActiveEdit()
1978 return m_pImpl->pParaWin->GetActiveEdit();
1980 // -----------------------------------------------------------------------------
1981 void FormulaModalDialog::SetEdSelection()
1983 m_pImpl->SetEdSelection();
1986 // --------------------------------------------------------------------------
1987 // Initialisierung / gemeinsaME Funktionen fuer Dialog
1988 // --------------------------------------------------------------------------
1989 FormulaDlg::FormulaDlg( SfxBindings* pB, SfxChildWindow* pCW,
1990 Window* pParent
1991 , bool _bSupportFunctionResult
1992 , bool _bSupportResult
1993 , bool _bSupportMatrix
1994 , IFormulaEditorHelper* _pHelper,IFunctionManager* _pFunctionMgr,IControlReferenceHandler* _pDlg ) :
1995 SfxModelessDialog( pB, pCW, pParent, ModuleRes(RID_FORMULADLG_FORMULA) ),
1996 m_pImpl( new FormulaDlg_Impl(this, _bSupportFunctionResult
1997 , _bSupportResult
1998 , _bSupportMatrix
1999 ,_pHelper,_pFunctionMgr,_pDlg))
2001 FreeResource();
2002 if(GetHelpId()==0) //Hack, da im SfxModelessDialog die HelpId
2003 SetHelpId(GetUniqueId()); //fuer einen ModelessDialog entfernt und
2004 //in eine UniqueId gewandelt wird, machen
2005 //wir das an dieser Stelle rueckgaengig.
2006 SetText(m_pImpl->aTitle1);
2009 FormulaDlg::~FormulaDlg()
2012 // -----------------------------------------------------------------------------
2013 void FormulaDlg::Update(const String& _sExp)
2015 m_pImpl->Update(_sExp);
2018 // -----------------------------------------------------------------------------
2019 void FormulaDlg::SetMeText(const String& _sText)
2021 m_pImpl->SetMeText(_sText);
2024 // -----------------------------------------------------------------------------
2025 FormulaDlgMode FormulaDlg::SetMeText(const String& _sText,xub_StrLen PrivStart, xub_StrLen PrivEnd,BOOL bMatrix,BOOL _bSelect,BOOL _bUpdate)
2027 return m_pImpl->SetMeText(_sText,PrivStart, PrivEnd,bMatrix,_bSelect,_bUpdate);
2029 // -----------------------------------------------------------------------------
2030 void FormulaDlg::CheckMatrix()
2032 m_pImpl->aBtnMatrix.Check();
2034 // -----------------------------------------------------------------------------
2035 BOOL FormulaDlg::CheckMatrix(String& aFormula)
2037 return m_pImpl->CheckMatrix(aFormula);
2039 // -----------------------------------------------------------------------------
2040 String FormulaDlg::GetMeText() const
2042 return m_pImpl->pMEdit->GetText();
2044 // -----------------------------------------------------------------------------
2045 void FormulaDlg::Update()
2047 m_pImpl->Update();
2048 m_pImpl->aTimer.SetTimeout(200);
2049 m_pImpl->aTimer.SetTimeoutHdl(LINK( this, FormulaDlg, UpdateFocusHdl));
2050 m_pImpl->aTimer.Start();
2053 // -----------------------------------------------------------------------------
2054 BOOL FormulaDlg::isUserMatrix() const
2056 return m_pImpl->bUserMatrixFlag;
2058 void FormulaDlg::DoEnter(BOOL _bOk)
2060 m_pImpl->DoEnter(_bOk);
2062 ::std::pair<RefButton*,RefEdit*> FormulaDlg::RefInputStartBefore( RefEdit* pEdit, RefButton* pButton )
2064 return m_pImpl->RefInputStartBefore( pEdit, pButton );
2066 void FormulaDlg::RefInputStartAfter( RefEdit* pEdit, RefButton* pButton )
2068 m_pImpl->RefInputStartAfter( pEdit, pButton );
2070 void FormulaDlg::RefInputDoneAfter( BOOL bForced )
2072 m_pImpl->RefInputDoneAfter( bForced );
2075 ULONG FormulaDlg::FindFocusWin(Window *pWin)
2077 return m_pImpl->FindFocusWin( pWin );
2080 void FormulaDlg::SetFocusWin(Window *pWin,ULONG nUniqueId)
2082 if(pWin->GetUniqueId()==nUniqueId)
2084 pWin->GrabFocus();
2086 else
2088 USHORT nCount=pWin->GetChildCount();
2090 for(USHORT i=0;i<nCount;i++)
2092 Window* pChild=pWin->GetChild(i);
2093 SetFocusWin(pChild,nUniqueId);
2099 long FormulaDlg::PreNotify( NotifyEvent& rNEvt )
2101 m_pImpl->PreNotify( rNEvt );
2102 return SfxModelessDialog::PreNotify(rNEvt);
2105 void FormulaDlg::HighlightFunctionParas(const String& aFormula)
2107 m_pImpl->m_pHelper->showReference(aFormula);
2110 void FormulaDlg::disableOk()
2112 m_pImpl->aBtnEnd.Disable();
2114 // -----------------------------------------------------------------------------
2115 const IFunctionDescription* FormulaDlg::getCurrentFunctionDescription() const
2117 OSL_VERIFY(!m_pImpl->pFuncDesc || m_pImpl->pFuncDesc->getSuppressedArgumentCount() == m_pImpl->nArgs);
2118 return m_pImpl->pFuncDesc;
2120 // -----------------------------------------------------------------------------
2121 void FormulaDlg::UpdateParaWin(const Selection& _rSelection,const String& _sRefStr)
2123 m_pImpl->UpdateParaWin(_rSelection,_sRefStr);
2125 BOOL FormulaDlg::UpdateParaWin(Selection& _rSelection)
2127 return m_pImpl->UpdateParaWin(_rSelection);
2129 // -----------------------------------------------------------------------------
2130 RefEdit* FormulaDlg::GetActiveEdit()
2132 return m_pImpl->pParaWin->GetActiveEdit();
2134 // -----------------------------------------------------------------------------
2135 const FormulaHelper& FormulaDlg::GetFormulaHelper() const
2137 return m_pImpl->GetFormulaHelper();
2139 // -----------------------------------------------------------------------------
2140 void FormulaDlg::SetEdSelection()
2142 m_pImpl->SetEdSelection();
2144 IMPL_LINK( FormulaDlg, UpdateFocusHdl, Timer*, EMPTYARG )
2146 FormEditData* pData = m_pImpl->m_pHelper->getFormEditData();
2148 if (pData) // wird nicht ueber Close zerstoert;
2150 m_pImpl->m_pHelper->setReferenceInput(pData);
2151 ULONG nUniqueId=pData->GetUniqueId();
2152 SetFocusWin(this,nUniqueId);
2154 return 0;
2157 // -----------------------------------------------------------------------------
2158 // -----------------------------------------------------------------------------
2159 void FormEditData::SaveValues()
2161 FormEditData* pTemp = new FormEditData(*this);
2163 Reset();
2164 pParent = pTemp;
2166 // -----------------------------------------------------------------------------
2167 void FormEditData::Reset()
2169 pParent = NULL;
2170 nMode = 0;
2171 nFStart = 0;
2172 nCatSel = 1; //! oder 0 (zuletzt benutzte)
2173 nFuncSel = 0;
2174 nOffset = 0;
2175 nEdFocus = 0;
2176 bMatrix =FALSE;
2177 nUniqueId=0;
2178 aSelection.Min()=0;
2179 aSelection.Max()=0;
2180 aUndoStr.Erase();
2182 // -----------------------------------------------------------------------------
2183 void FormEditData::RestoreValues()
2185 FormEditData* pTemp = pParent;
2186 DBG_ASSERT(pTemp,"RestoreValues ohne Parent");
2187 if (pTemp)
2189 *this = *pTemp;
2190 pTemp->pParent = NULL; // sonst wird der auch geloescht!
2191 delete pTemp;
2194 // -----------------------------------------------------------------------------
2195 const FormEditData& FormEditData::operator=( const FormEditData& r )
2197 pParent = r.pParent;
2198 nMode = r.nMode;
2199 nFStart = r.nFStart;
2200 nCatSel = r.nCatSel;
2201 nFuncSel = r.nFuncSel;
2202 nOffset = r.nOffset;
2203 nEdFocus = r.nEdFocus;
2204 aUndoStr = r.aUndoStr;
2205 bMatrix = r.bMatrix ;
2206 nUniqueId = r.nUniqueId;
2207 aSelection = r.aSelection;
2208 return *this;
2210 // -----------------------------------------------------------------------------
2211 FormEditData::FormEditData()
2213 Reset();
2216 FormEditData::~FormEditData()
2218 delete pParent;
2221 FormEditData::FormEditData( const FormEditData& r )
2223 *this = r;
2226 // -----------------------------------------------------------------------------
2227 } // formula
2228 // -----------------------------------------------------------------------------