xref: /AOO41X/main/formula/source/ui/dlg/formula.cxx (revision 4d7c9de063a797b8b4f3d45e3561e82ad1f8ef1f)
1*c25918c1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c25918c1SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c25918c1SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c25918c1SAndrew Rist  * distributed with this work for additional information
6*c25918c1SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c25918c1SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c25918c1SAndrew Rist  * "License"); you may not use this file except in compliance
9*c25918c1SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*c25918c1SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*c25918c1SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c25918c1SAndrew Rist  * software distributed under the License is distributed on an
15*c25918c1SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c25918c1SAndrew Rist  * KIND, either express or implied.  See the License for the
17*c25918c1SAndrew Rist  * specific language governing permissions and limitations
18*c25918c1SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*c25918c1SAndrew Rist  *************************************************************/
21*c25918c1SAndrew Rist 
22*c25918c1SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_formula.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //----------------------------------------------------------------------------
28cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
29cdf0e10cSrcweir #include <sfx2/docfile.hxx>
30cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
31cdf0e10cSrcweir #include <vcl/svapp.hxx>
32cdf0e10cSrcweir #include <vcl/mnemonic.hxx>
33cdf0e10cSrcweir #include <vcl/tabpage.hxx>
34cdf0e10cSrcweir #include <vcl/tabctrl.hxx>
35cdf0e10cSrcweir #include <vcl/lstbox.hxx>
36cdf0e10cSrcweir #include <vcl/group.hxx>
37cdf0e10cSrcweir #include <vcl/wall.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <svtools/stdctrl.hxx>
40cdf0e10cSrcweir #include <svtools/svmedit.hxx>
41cdf0e10cSrcweir #include <svtools/svtreebx.hxx>
42cdf0e10cSrcweir #include <svl/stritem.hxx>
43cdf0e10cSrcweir #include <svl/zforlist.hxx>
44cdf0e10cSrcweir #include <svl/eitem.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include <unotools/charclass.hxx>
47cdf0e10cSrcweir #include <tools/urlobj.hxx>
48cdf0e10cSrcweir #include <tools/diagnose_ex.h>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include "formdlgs.hrc"
51cdf0e10cSrcweir #include "funcpage.hxx"
52cdf0e10cSrcweir #include "formula/formula.hxx"
53cdf0e10cSrcweir #include "formula/IFunctionDescription.hxx"
54cdf0e10cSrcweir #include "formula/FormulaCompiler.hxx"
55cdf0e10cSrcweir #include "formula/token.hxx"
56cdf0e10cSrcweir #include "formula/tokenarray.hxx"
57cdf0e10cSrcweir #include "formula/formdata.hxx"
58cdf0e10cSrcweir #include "formula/formulahelper.hxx"
59cdf0e10cSrcweir #include "structpg.hxx"
60cdf0e10cSrcweir #include "parawin.hxx"
61cdf0e10cSrcweir #include "ModuleHelper.hxx"
62cdf0e10cSrcweir #include "ForResId.hrc"
63cdf0e10cSrcweir #include <com/sun/star/sheet/FormulaToken.hpp>
64cdf0e10cSrcweir #include <com/sun/star/sheet/FormulaLanguage.hpp>
65cdf0e10cSrcweir #include <com/sun/star/sheet/FormulaMapGroup.hpp>
66cdf0e10cSrcweir #include <com/sun/star/sheet/FormulaMapGroupSpecialOffset.hpp>
67cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
68cdf0e10cSrcweir #include <boost/bind.hpp>
69cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
70cdf0e10cSrcweir #include <map>
71cdf0e10cSrcweir 
72cdf0e10cSrcweir #define TOKEN_OPEN  0
73cdf0e10cSrcweir #define TOKEN_CLOSE 1
74cdf0e10cSrcweir #define TOKEN_SEP   2
75cdf0e10cSrcweir namespace formula
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     using namespace ::com::sun::star;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     class OFormulaToken : public IFormulaToken
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         sal_Int32   m_nParaCount;
82cdf0e10cSrcweir         bool        m_bIsFunction;
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     public:
OFormulaToken(bool _bFunction,sal_Int32 _nParaCount)85cdf0e10cSrcweir         OFormulaToken(bool _bFunction,sal_Int32 _nParaCount) : m_nParaCount(_nParaCount),m_bIsFunction(_bFunction){}
86cdf0e10cSrcweir 
isFunction() const87cdf0e10cSrcweir         virtual bool isFunction() const { return m_bIsFunction; }
getArgumentCount() const88cdf0e10cSrcweir         virtual sal_uInt32 getArgumentCount() const { return m_nParaCount; }
89cdf0e10cSrcweir     };
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     class FormulaDlg_Impl
93cdf0e10cSrcweir     {
94cdf0e10cSrcweir     public:
95cdf0e10cSrcweir         ::std::pair<RefButton*,RefEdit*>
96cdf0e10cSrcweir                         RefInputStartBefore( RefEdit* pEdit, RefButton* pButton );
97cdf0e10cSrcweir         void            RefInputStartAfter( RefEdit* pEdit, RefButton* pButton );
98cdf0e10cSrcweir         void            RefInputDoneAfter( sal_Bool bForced );
99cdf0e10cSrcweir         sal_Bool			CalcValue( const String& rStrExp, String& rStrResult );
100cdf0e10cSrcweir         sal_Bool			CalcStruct( const String& rStrExp);
101cdf0e10cSrcweir         void			UpdateValues();
102cdf0e10cSrcweir         void			DeleteArgs();
103cdf0e10cSrcweir         xub_StrLen      GetFunctionPos(xub_StrLen nPos);
104cdf0e10cSrcweir         void			ClearAllParas();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         void            MakeTree(IStructHelper* _pTree,SvLBoxEntry* pParent,FormulaToken* _pToken,long Count);
107cdf0e10cSrcweir         void            fillTree(IStructHelper* _pTree);
108cdf0e10cSrcweir         void            UpdateTokenArray( const String& rStrExp);
109cdf0e10cSrcweir         String          RepairFormula(const String& aFormula);
110cdf0e10cSrcweir 	    void			FillDialog(sal_Bool nFlag=sal_True);
111cdf0e10cSrcweir 	    void			EditNextFunc( sal_Bool bForward, xub_StrLen nFStart=NOT_FOUND );
112cdf0e10cSrcweir 	    void			EditThisFunc(xub_StrLen nFStart);
113cdf0e10cSrcweir 	    void			EditFuncParas(xub_StrLen nEditPos);
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	    void			UpdateArgInput( sal_uInt16 nOffset, sal_uInt16 nInput );
117cdf0e10cSrcweir         void			Update();
118cdf0e10cSrcweir         void            Update(const String& _sExp);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	    void			SaveArg( sal_uInt16 nEd );
122cdf0e10cSrcweir 	    void			UpdateSelection();
123cdf0e10cSrcweir 	    void			DoEnter( sal_Bool bOk );
124cdf0e10cSrcweir 	    void			UpdateFunctionDesc();
125cdf0e10cSrcweir 	    void			ResizeArgArr( const IFunctionDescription* pNewFunc );
126cdf0e10cSrcweir 	    void			FillListboxes();
127cdf0e10cSrcweir 	    void			FillControls(sal_Bool &rbNext, sal_Bool &rbPrev);
128cdf0e10cSrcweir 
129cdf0e10cSrcweir         FormulaDlgMode  SetMeText(const String& _sText,xub_StrLen PrivStart, xub_StrLen PrivEnd,sal_Bool bMatrix,sal_Bool _bSelect,sal_Bool _bUpdate);
130cdf0e10cSrcweir         void            SetMeText(const String& _sText);
131cdf0e10cSrcweir         sal_Bool            CheckMatrix(String& aFormula /*IN/OUT*/);
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         void            SetEdSelection();
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         sal_Bool            UpdateParaWin(Selection& _rSelection);
136cdf0e10cSrcweir         void            UpdateParaWin(const Selection& _rSelection,const String& _sRefStr);
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         void            SetData(xub_StrLen nFStart,xub_StrLen nNextFStart,xub_StrLen nNextFEnd,xub_StrLen& PrivStart,xub_StrLen& PrivEnd);
139cdf0e10cSrcweir         void            PreNotify( NotifyEvent& rNEvt );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         RefEdit*        GetCurrRefEdit();
142cdf0e10cSrcweir         rtl::OString    FindFocusWin(Window *pWin);
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         const FormulaHelper& GetFormulaHelper() const;
145cdf0e10cSrcweir         uno::Reference< sheet::XFormulaOpCodeMapper > GetFormulaOpCodeMapper() const;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 	    DECL_LINK( ModifyHdl, ParaWin* );
148cdf0e10cSrcweir 	    DECL_LINK( FxHdl, ParaWin* );
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 	    DECL_LINK( MatrixHdl, CheckBox *);
151cdf0e10cSrcweir 	    DECL_LINK( FormulaHdl, MultiLineEdit* );
152cdf0e10cSrcweir 	    DECL_LINK( FormulaCursorHdl, EditBox*);
153cdf0e10cSrcweir 	    DECL_LINK( BtnHdl, PushButton* );
154cdf0e10cSrcweir 	    DECL_LINK( GetEdFocusHdl, ArgInput* );
155cdf0e10cSrcweir 	    DECL_LINK( GetFxFocusHdl, ArgInput* );
156cdf0e10cSrcweir 	    DECL_LINK( DblClkHdl, FuncPage* );
157cdf0e10cSrcweir 	    DECL_LINK( FuncSelHdl, FuncPage*);
158cdf0e10cSrcweir 	    DECL_LINK( StructSelHdl, StructPage * );
159cdf0e10cSrcweir     public:
160cdf0e10cSrcweir         OModuleClient                                           m_aModuleClient;
161cdf0e10cSrcweir         mutable uno::Reference< sheet::XFormulaOpCodeMapper>    m_xOpCodeMapper;
162cdf0e10cSrcweir         uno::Sequence< sheet::FormulaToken >                    m_aTokenList;
163cdf0e10cSrcweir         ::std::auto_ptr<FormulaTokenArray>                      m_pTokenArray;
164cdf0e10cSrcweir         mutable uno::Sequence< sheet::FormulaOpCodeMapEntry >   m_aSpecialOpCodes;
165cdf0e10cSrcweir         mutable const sheet::FormulaOpCodeMapEntry*             m_pSpecialOpCodesEnd;
166cdf0e10cSrcweir         mutable uno::Sequence< sheet::FormulaToken >            m_aSeparatorsOpCodes;
167cdf0e10cSrcweir         mutable uno::Sequence< sheet::FormulaOpCodeMapEntry >   m_aFunctionOpCodes;
168cdf0e10cSrcweir         mutable const sheet::FormulaOpCodeMapEntry*             m_pFunctionOpCodesEnd;
169cdf0e10cSrcweir         mutable uno::Sequence< sheet::FormulaOpCodeMapEntry >   m_aUnaryOpCodes;
170cdf0e10cSrcweir         mutable const sheet::FormulaOpCodeMapEntry*             m_pUnaryOpCodesEnd;
171cdf0e10cSrcweir         mutable uno::Sequence< sheet::FormulaOpCodeMapEntry >   m_aBinaryOpCodes;
172cdf0e10cSrcweir         mutable const sheet::FormulaOpCodeMapEntry*             m_pBinaryOpCodesEnd;
173cdf0e10cSrcweir         ::std::vector< ::boost::shared_ptr<OFormulaToken> >     m_aTokens;
174cdf0e10cSrcweir         ::std::map<FormulaToken*,sheet::FormulaToken>           m_aTokenMap;
175cdf0e10cSrcweir         IFormulaEditorHelper*                                   m_pHelper;
176cdf0e10cSrcweir         Dialog*  m_pParent;
177cdf0e10cSrcweir         IControlReferenceHandler*  m_pDlg;
178cdf0e10cSrcweir 	    TabControl		aTabCtrl;
179cdf0e10cSrcweir 	    GroupBox		aGEdit;		//! MUST be placed before pParaWin for initializing
180cdf0e10cSrcweir 	    ParaWin*		pParaWin;
181cdf0e10cSrcweir 	    FixedText		aFtHeadLine;
182cdf0e10cSrcweir 	    FixedInfo		aFtFuncName;
183cdf0e10cSrcweir 	    FixedInfo		aFtFuncDesc;
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 	    FixedText		aFtEditName;
186cdf0e10cSrcweir 	    //FixedInfo		aFtEditDesc;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	    FixedText		aFtResult;
189cdf0e10cSrcweir 	    ValWnd			aWndResult;
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 	    FixedText		aFtFormula;
192cdf0e10cSrcweir 	    EditBox		    aMEFormula;
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 	    CheckBox		aBtnMatrix;
195cdf0e10cSrcweir 	    HelpButton		aBtnHelp;
196cdf0e10cSrcweir 	    CancelButton	aBtnCancel;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	    PushButton		aBtnBackward;
199cdf0e10cSrcweir 	    PushButton		aBtnForward;
200cdf0e10cSrcweir 	    OKButton		aBtnEnd;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 	    RefEdit		aEdRef;
203cdf0e10cSrcweir 	    RefButton	aRefBtn;
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 	    FixedText		aFtFormResult;
206cdf0e10cSrcweir 	    ValWnd			aWndFormResult;
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 	    RefEdit*		pTheRefEdit;
209cdf0e10cSrcweir 	    RefButton*	pTheRefButton;
210cdf0e10cSrcweir 	    FuncPage*	pFuncPage;
211cdf0e10cSrcweir 	    StructPage*	pStructPage;
212cdf0e10cSrcweir 	    String			aOldFormula;
213cdf0e10cSrcweir 	    sal_Bool			bStructUpdate;
214cdf0e10cSrcweir 	    MultiLineEdit*  pMEdit;
215cdf0e10cSrcweir 	    sal_Bool			bUserMatrixFlag;
216cdf0e10cSrcweir 	    Timer			aTimer;
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 	    const String	aTitle1;
219cdf0e10cSrcweir 	    const String	aTitle2;
220cdf0e10cSrcweir 	    const String	aTxtEnd;
221cdf0e10cSrcweir 	    const String	aTxtOk;		// hinter aBtnEnd
222cdf0e10cSrcweir         FormulaHelper
223cdf0e10cSrcweir                         m_aFormulaHelper;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         rtl::OString    m_aEditHelpId;
226cdf0e10cSrcweir 
227cdf0e10cSrcweir         rtl::OString	aOldHelp;
228cdf0e10cSrcweir 	    rtl::OString    aOldUnique;
229cdf0e10cSrcweir 	    rtl::OString    aActivWinId;
230cdf0e10cSrcweir 	    sal_Bool			bIsShutDown;
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 	    Font			aFntBold;
235cdf0e10cSrcweir 	    Font			aFntLight;
236cdf0e10cSrcweir 	    sal_uInt16			nEdFocus;
237cdf0e10cSrcweir     //    Selection       theCurSel;
238cdf0e10cSrcweir 	    sal_Bool			bEditFlag;
239cdf0e10cSrcweir 	    const IFunctionDescription*	pFuncDesc;
240cdf0e10cSrcweir 	    xub_StrLen		nArgs;
241cdf0e10cSrcweir         ::std::vector< ::rtl::OUString > m_aArguments;
242cdf0e10cSrcweir 	    Selection		aFuncSel;
243cdf0e10cSrcweir 
244cdf0e10cSrcweir         FormulaDlg_Impl(Dialog* pParent
245cdf0e10cSrcweir                         , bool _bSupportFunctionResult
246cdf0e10cSrcweir                         , bool _bSupportResult
247cdf0e10cSrcweir                         , bool _bSupportMatrix
248cdf0e10cSrcweir                         ,IFormulaEditorHelper* _pHelper
249cdf0e10cSrcweir                         ,const IFunctionManager* _pFunctionMgr
250cdf0e10cSrcweir                         ,IControlReferenceHandler* _pDlg);
251cdf0e10cSrcweir         ~FormulaDlg_Impl();
252cdf0e10cSrcweir 
253cdf0e10cSrcweir     };
FormulaDlg_Impl(Dialog * pParent,bool _bSupportFunctionResult,bool _bSupportResult,bool _bSupportMatrix,IFormulaEditorHelper * _pHelper,const IFunctionManager * _pFunctionMgr,IControlReferenceHandler * _pDlg)254cdf0e10cSrcweir FormulaDlg_Impl::FormulaDlg_Impl(Dialog* pParent
255cdf0e10cSrcweir                                         , bool _bSupportFunctionResult
256cdf0e10cSrcweir                                         , bool _bSupportResult
257cdf0e10cSrcweir                                         , bool _bSupportMatrix
258cdf0e10cSrcweir                                         ,IFormulaEditorHelper* _pHelper
259cdf0e10cSrcweir                                         ,const IFunctionManager* _pFunctionMgr
260cdf0e10cSrcweir                                         ,IControlReferenceHandler* _pDlg)
261cdf0e10cSrcweir     :
262cdf0e10cSrcweir     m_pHelper       (_pHelper),
263cdf0e10cSrcweir     m_pParent       (pParent),
264cdf0e10cSrcweir     m_pDlg          (_pDlg),
265cdf0e10cSrcweir     aTabCtrl		( pParent, ModuleRes( TC_FUNCTION ) ),
266cdf0e10cSrcweir     aGEdit			( pParent, ModuleRes( GB_EDIT ) ),
267cdf0e10cSrcweir     aFtHeadLine		( pParent, ModuleRes( FT_HEADLINE ) ),
268cdf0e10cSrcweir     aFtFuncName		( pParent, ModuleRes( FT_FUNCNAME ) ),
269cdf0e10cSrcweir     aFtFuncDesc		( pParent, ModuleRes( FT_FUNCDESC ) ),
270cdf0e10cSrcweir     //
271cdf0e10cSrcweir     aFtEditName		( pParent, ModuleRes( FT_EDITNAME ) ),
272cdf0e10cSrcweir     aFtResult		( pParent, ModuleRes( FT_RESULT ) ),
273cdf0e10cSrcweir     aWndResult		( pParent, ModuleRes( WND_RESULT ) ),
274cdf0e10cSrcweir 
275cdf0e10cSrcweir     aFtFormula		( pParent, ModuleRes( FT_FORMULA ) ),
276cdf0e10cSrcweir     aMEFormula		( pParent, ModuleRes( ED_FORMULA ) ),
277cdf0e10cSrcweir     //
278cdf0e10cSrcweir     aBtnMatrix		( pParent, ModuleRes( BTN_MATRIX ) ),
279cdf0e10cSrcweir     aBtnHelp		( pParent, ModuleRes( BTN_HELP ) ),
280cdf0e10cSrcweir     aBtnCancel		( pParent, ModuleRes( BTN_CANCEL ) ),
281cdf0e10cSrcweir     aBtnBackward	( pParent, ModuleRes( BTN_BACKWARD ) ),
282cdf0e10cSrcweir     aBtnForward		( pParent, ModuleRes( BTN_FORWARD ) ),
283cdf0e10cSrcweir     aBtnEnd			( pParent, ModuleRes( BTN_END ) ),
284cdf0e10cSrcweir     aEdRef			( pParent, _pDlg, ModuleRes( ED_REF) ),
285cdf0e10cSrcweir     aRefBtn			( pParent, ModuleRes( RB_REF),&aEdRef,_pDlg ),
286cdf0e10cSrcweir     aFtFormResult	( pParent, ModuleRes( FT_FORMULA_RESULT)),
287cdf0e10cSrcweir     aWndFormResult	( pParent, ModuleRes( WND_FORMULA_RESULT)),
288cdf0e10cSrcweir     //
289cdf0e10cSrcweir     pTheRefEdit		(NULL),
290cdf0e10cSrcweir     pMEdit			(NULL),
291cdf0e10cSrcweir     bUserMatrixFlag	(sal_False),
292cdf0e10cSrcweir     //
293cdf0e10cSrcweir     aTitle1			( ModuleRes( STR_TITLE1 ) ),		// lokale Resource
294cdf0e10cSrcweir     aTitle2			( ModuleRes( STR_TITLE2 ) ),		// lokale Resource
295cdf0e10cSrcweir     aTxtEnd			( ModuleRes( STR_END ) ),		    // lokale Resource
296cdf0e10cSrcweir     aTxtOk			( aBtnEnd.GetText() ),
297cdf0e10cSrcweir     m_aFormulaHelper(_pFunctionMgr),
298cdf0e10cSrcweir     //
299cdf0e10cSrcweir     bIsShutDown		(sal_False),
300cdf0e10cSrcweir     nEdFocus		(0),
301cdf0e10cSrcweir     pFuncDesc		(NULL),
302cdf0e10cSrcweir     nArgs			(0)
303cdf0e10cSrcweir {
304cdf0e10cSrcweir     pParaWin = new ParaWin( pParent,_pDlg, aGEdit.GetPosPixel());
305cdf0e10cSrcweir     aGEdit.Hide();
306cdf0e10cSrcweir     pParaWin->Hide();
307cdf0e10cSrcweir     aFtEditName.Hide();
308cdf0e10cSrcweir     aEdRef.Hide();
309cdf0e10cSrcweir     aRefBtn.Hide();
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     pMEdit = aMEFormula.GetEdit();
312cdf0e10cSrcweir 	aMEFormula.SetAccessibleName(aFtFormula.GetText());
313cdf0e10cSrcweir 	if (pMEdit)
314cdf0e10cSrcweir 		pMEdit->SetAccessibleName(aFtFormula.GetText());
315cdf0e10cSrcweir     m_aEditHelpId = pMEdit->GetHelpId();
316cdf0e10cSrcweir     pMEdit->SetUniqueId( m_aEditHelpId );
317cdf0e10cSrcweir 
318cdf0e10cSrcweir     bEditFlag=sal_False;
319cdf0e10cSrcweir     bStructUpdate=sal_True;
320cdf0e10cSrcweir     Point aPos=aGEdit.GetPosPixel();
321cdf0e10cSrcweir     pParaWin->SetPosPixel(aPos);
322cdf0e10cSrcweir     pParaWin->SetArgModifiedHdl(LINK( this, FormulaDlg_Impl, ModifyHdl ) );
323cdf0e10cSrcweir     pParaWin->SetFxHdl(LINK( this, FormulaDlg_Impl, FxHdl ) );
324cdf0e10cSrcweir 
325cdf0e10cSrcweir     pFuncPage= new FuncPage( &aTabCtrl,_pFunctionMgr);
326cdf0e10cSrcweir     pStructPage= new StructPage( &aTabCtrl);
327cdf0e10cSrcweir     pFuncPage->Hide();
328cdf0e10cSrcweir     pStructPage->Hide();
329cdf0e10cSrcweir     aTabCtrl.SetTabPage( TP_FUNCTION, pFuncPage);
330cdf0e10cSrcweir     aTabCtrl.SetTabPage( TP_STRUCT, pStructPage);
331cdf0e10cSrcweir 
332cdf0e10cSrcweir     aOldHelp = pParent->GetHelpId();				// HelpId aus Resource immer fuer "Seite 1"
333cdf0e10cSrcweir     aOldUnique = pParent->GetUniqueId();
334cdf0e10cSrcweir 
335cdf0e10cSrcweir     aFtResult.Show( _bSupportResult );
336cdf0e10cSrcweir     aWndResult.Show( _bSupportResult );
337cdf0e10cSrcweir 
338cdf0e10cSrcweir     aFtFormResult.Show( _bSupportFunctionResult );
339cdf0e10cSrcweir     aWndFormResult.Show( _bSupportFunctionResult );
340cdf0e10cSrcweir 
341cdf0e10cSrcweir     if ( _bSupportMatrix )
342cdf0e10cSrcweir         aBtnMatrix.SetClickHdl(LINK( this, FormulaDlg_Impl, MatrixHdl ) );
343cdf0e10cSrcweir     else
344cdf0e10cSrcweir         aBtnMatrix.Hide();
345cdf0e10cSrcweir 
346cdf0e10cSrcweir     aBtnCancel	.SetClickHdl( LINK( this, FormulaDlg_Impl, BtnHdl ) );
347cdf0e10cSrcweir     aBtnEnd 	.SetClickHdl( LINK( this, FormulaDlg_Impl, BtnHdl ) );
348cdf0e10cSrcweir     aBtnForward	.SetClickHdl( LINK( this, FormulaDlg_Impl, BtnHdl ) );
349cdf0e10cSrcweir     aBtnBackward.SetClickHdl( LINK( this, FormulaDlg_Impl, BtnHdl ) );
350cdf0e10cSrcweir 
351cdf0e10cSrcweir     pFuncPage->SetDoubleClickHdl( LINK( this, FormulaDlg_Impl, DblClkHdl ) );
352cdf0e10cSrcweir     pFuncPage->SetSelectHdl( LINK( this, FormulaDlg_Impl, FuncSelHdl) );
353cdf0e10cSrcweir     pStructPage->SetSelectionHdl( LINK( this, FormulaDlg_Impl, StructSelHdl ) );
354cdf0e10cSrcweir     pMEdit->SetModifyHdl( LINK( this, FormulaDlg_Impl, FormulaHdl ) );
355cdf0e10cSrcweir     aMEFormula.SetSelChangedHdl( LINK( this, FormulaDlg_Impl, FormulaCursorHdl ) );
356cdf0e10cSrcweir 
357cdf0e10cSrcweir     aFntLight = aFtFormula.GetFont();
358cdf0e10cSrcweir     aFntLight.SetTransparent( sal_True );
359cdf0e10cSrcweir     aFntBold = aFntLight;
360cdf0e10cSrcweir     aFntBold.SetWeight( WEIGHT_BOLD );
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     pParaWin->SetArgumentFonts(aFntBold,aFntLight);
363cdf0e10cSrcweir 
364cdf0e10cSrcweir     //	function description for choosing a function is no longer in a different color
365cdf0e10cSrcweir 
366cdf0e10cSrcweir     aFtHeadLine.SetFont(aFntBold);
367cdf0e10cSrcweir     aFtFuncName.SetFont(aFntLight);
368cdf0e10cSrcweir     aFtFuncDesc.SetFont(aFntLight);
369cdf0e10cSrcweir }
~FormulaDlg_Impl()370cdf0e10cSrcweir FormulaDlg_Impl::~FormulaDlg_Impl()
371cdf0e10cSrcweir {
372cdf0e10cSrcweir     if(aTimer.IsActive())
373cdf0e10cSrcweir 	{
374cdf0e10cSrcweir 		aTimer.SetTimeoutHdl(Link());
375cdf0e10cSrcweir 		aTimer.Stop();
376cdf0e10cSrcweir 	} // if(aTimer.IsActive())
377cdf0e10cSrcweir     bIsShutDown=sal_True;// Setzen, damit PreNotify keinen GetFocus speichert.
378cdf0e10cSrcweir     FormEditData* pData = m_pHelper->getFormEditData();
379cdf0e10cSrcweir     if (pData) // wird nicht ueber Close zerstoert;
380cdf0e10cSrcweir 	{
381cdf0e10cSrcweir 		pData->SetFStart((xub_StrLen)pMEdit->GetSelection().Min());
382cdf0e10cSrcweir 		pData->SetSelection(pMEdit->GetSelection());
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 		if(aTabCtrl.GetCurPageId()==TP_FUNCTION)
385cdf0e10cSrcweir 			pData->SetMode( (sal_uInt16) FORMULA_FORMDLG_FORMULA );
386cdf0e10cSrcweir 		else
387cdf0e10cSrcweir 			pData->SetMode( (sal_uInt16) FORMULA_FORMDLG_EDIT );
388cdf0e10cSrcweir 		pData->SetUndoStr(pMEdit->GetText());
389cdf0e10cSrcweir 		pData->SetMatrixFlag(aBtnMatrix.IsChecked());
390cdf0e10cSrcweir 	}
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 	aTabCtrl.RemovePage(TP_FUNCTION);
393cdf0e10cSrcweir 	aTabCtrl.RemovePage(TP_STRUCT);
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 	delete pStructPage;
396cdf0e10cSrcweir 	delete pFuncPage;
397cdf0e10cSrcweir     delete pParaWin;
398cdf0e10cSrcweir 	DeleteArgs();
399cdf0e10cSrcweir }
400cdf0e10cSrcweir // -----------------------------------------------------------------------------
PreNotify(NotifyEvent & rNEvt)401cdf0e10cSrcweir void FormulaDlg_Impl::PreNotify( NotifyEvent& rNEvt )
402cdf0e10cSrcweir {
403cdf0e10cSrcweir 	sal_uInt16 nSwitch=rNEvt.GetType();
404cdf0e10cSrcweir 	if(nSwitch==EVENT_GETFOCUS && !bIsShutDown)
405cdf0e10cSrcweir 	{
406cdf0e10cSrcweir 		Window* pWin=rNEvt.GetWindow();
407cdf0e10cSrcweir 		if(pWin!=NULL)
408cdf0e10cSrcweir 		{
409cdf0e10cSrcweir 			aActivWinId = pWin->GetUniqueId();
410cdf0e10cSrcweir 			if(aActivWinId.getLength()==0)
411cdf0e10cSrcweir 			{
412cdf0e10cSrcweir 				Window* pParent=pWin->GetParent();
413cdf0e10cSrcweir 				while(pParent!=NULL)
414cdf0e10cSrcweir 				{
415cdf0e10cSrcweir 					aActivWinId=pParent->GetUniqueId();
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 					if(aActivWinId.getLength()!=0) break;
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 					pParent=pParent->GetParent();
420cdf0e10cSrcweir 				}
421cdf0e10cSrcweir 			}
422cdf0e10cSrcweir 			if(aActivWinId.getLength())
423cdf0e10cSrcweir 			{
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 				FormEditData* pData = m_pHelper->getFormEditData();
426cdf0e10cSrcweir 
427cdf0e10cSrcweir 				if (pData && !aTimer.IsActive()) // wird nicht ueber Close zerstoert;
428cdf0e10cSrcweir 				{
429cdf0e10cSrcweir 					pData->SetUniqueId(aActivWinId);
430cdf0e10cSrcweir 				}
431cdf0e10cSrcweir 			}
432cdf0e10cSrcweir 		}
433cdf0e10cSrcweir 	}
434cdf0e10cSrcweir }
GetFormulaOpCodeMapper() const435cdf0e10cSrcweir uno::Reference< sheet::XFormulaOpCodeMapper > FormulaDlg_Impl::GetFormulaOpCodeMapper() const
436cdf0e10cSrcweir {
437cdf0e10cSrcweir     if ( !m_xOpCodeMapper.is() )
438cdf0e10cSrcweir     {
439cdf0e10cSrcweir         m_xOpCodeMapper = m_pHelper->getFormulaOpCodeMapper();
440cdf0e10cSrcweir         m_aFunctionOpCodes = m_xOpCodeMapper->getAvailableMappings(sheet::FormulaLanguage::ODFF,sheet::FormulaMapGroup::FUNCTIONS);
441cdf0e10cSrcweir         m_pFunctionOpCodesEnd = m_aFunctionOpCodes.getConstArray() + m_aFunctionOpCodes.getLength();
442cdf0e10cSrcweir 
443cdf0e10cSrcweir         m_aUnaryOpCodes = m_xOpCodeMapper->getAvailableMappings(sheet::FormulaLanguage::ODFF,sheet::FormulaMapGroup::UNARY_OPERATORS);
444cdf0e10cSrcweir         m_pUnaryOpCodesEnd = m_aUnaryOpCodes.getConstArray() + m_aUnaryOpCodes.getLength();
445cdf0e10cSrcweir 
446cdf0e10cSrcweir         m_aBinaryOpCodes = m_xOpCodeMapper->getAvailableMappings(sheet::FormulaLanguage::ODFF,sheet::FormulaMapGroup::BINARY_OPERATORS);
447cdf0e10cSrcweir         m_pBinaryOpCodesEnd = m_aBinaryOpCodes.getConstArray() + m_aBinaryOpCodes.getLength();
448cdf0e10cSrcweir 
449cdf0e10cSrcweir         uno::Sequence< ::rtl::OUString > aArgs(3);
450cdf0e10cSrcweir         aArgs[TOKEN_OPEN]   = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("("));
451cdf0e10cSrcweir         aArgs[TOKEN_CLOSE]  = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(")"));
452cdf0e10cSrcweir         aArgs[TOKEN_SEP]    = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(";"));
453cdf0e10cSrcweir         m_aSeparatorsOpCodes = m_xOpCodeMapper->getMappings(aArgs,sheet::FormulaLanguage::ODFF);
454cdf0e10cSrcweir 
455cdf0e10cSrcweir         m_aSpecialOpCodes = m_xOpCodeMapper->getAvailableMappings(sheet::FormulaLanguage::ODFF,sheet::FormulaMapGroup::SPECIAL);
456cdf0e10cSrcweir         m_pSpecialOpCodesEnd = m_aSpecialOpCodes.getConstArray() + m_aSpecialOpCodes.getLength();
457cdf0e10cSrcweir     } // if ( !m_xOpCodeMapper.is() )
458cdf0e10cSrcweir     return m_xOpCodeMapper;
459cdf0e10cSrcweir }
460cdf0e10cSrcweir 
DeleteArgs()461cdf0e10cSrcweir void FormulaDlg_Impl::DeleteArgs()
462cdf0e10cSrcweir {
463cdf0e10cSrcweir     ::std::vector< ::rtl::OUString>().swap(m_aArguments);
464cdf0e10cSrcweir     nArgs = 0;
465cdf0e10cSrcweir }
466cdf0e10cSrcweir namespace
467cdf0e10cSrcweir {
468cdf0e10cSrcweir     // comparing two property instances
469cdf0e10cSrcweir     struct OpCodeCompare : public ::std::binary_function< sheet::FormulaOpCodeMapEntry, sal_Int32 , bool >
470cdf0e10cSrcweir     {
operator ()formula::__anon37c2110d0111::OpCodeCompare471cdf0e10cSrcweir 	    bool operator() (const sheet::FormulaOpCodeMapEntry& x, sal_Int32 y) const
472cdf0e10cSrcweir 	    {
473cdf0e10cSrcweir 		    return x.Token.OpCode == y;
474cdf0e10cSrcweir 	    }
475cdf0e10cSrcweir     };
476cdf0e10cSrcweir }
477cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetFunctionPos(xub_StrLen nPos)478cdf0e10cSrcweir xub_StrLen FormulaDlg_Impl::GetFunctionPos(xub_StrLen nPos)
479cdf0e10cSrcweir {
480cdf0e10cSrcweir     const sal_Unicode sep = m_pHelper->getFunctionManager()->getSingleToken(IFunctionManager::eSep);
481cdf0e10cSrcweir 
482cdf0e10cSrcweir 	xub_StrLen nTokPos=1;
483cdf0e10cSrcweir 	xub_StrLen nOldTokPos=1;
484cdf0e10cSrcweir 	xub_StrLen nFuncPos=STRING_NOTFOUND;    //@ Testweise
485cdf0e10cSrcweir 	xub_StrLen nPrevFuncPos=1;
486cdf0e10cSrcweir 	short  nBracketCount=0;
487cdf0e10cSrcweir 	sal_Bool   bFlag=sal_False;
488cdf0e10cSrcweir 	String aFormString = pMEdit->GetText();
489cdf0e10cSrcweir 	m_aFormulaHelper.GetCharClass()->toUpper( aFormString );
490cdf0e10cSrcweir 
491cdf0e10cSrcweir 	if ( m_aTokenList.getLength() )
492cdf0e10cSrcweir 	{
493cdf0e10cSrcweir         const uno::Reference< sheet::XFormulaParser > xParser(m_pHelper->getFormulaParser());
494cdf0e10cSrcweir         const table::CellAddress aRefPos(m_pHelper->getReferencePosition());
495cdf0e10cSrcweir 
496cdf0e10cSrcweir         const sheet::FormulaToken* pIter = m_aTokenList.getConstArray();
497cdf0e10cSrcweir         const sheet::FormulaToken* pEnd = pIter + m_aTokenList.getLength();
498cdf0e10cSrcweir         //if ( pIter != pEnd && aFormString.GetChar(0) == '=' )
499cdf0e10cSrcweir         //    ++pIter;
500cdf0e10cSrcweir         try
501cdf0e10cSrcweir         {
502cdf0e10cSrcweir             while ( pIter != pEnd )
503cdf0e10cSrcweir 		    {
504cdf0e10cSrcweir 			    const sal_Int32 eOp = pIter->OpCode;
505cdf0e10cSrcweir                 uno::Sequence<sheet::FormulaToken> aArgs(1);
506cdf0e10cSrcweir                 aArgs[0] = *pIter;
507cdf0e10cSrcweir                 const String aString = xParser->printFormula(aArgs, aRefPos);
508cdf0e10cSrcweir 			    const sheet::FormulaToken* pNextToken = pIter + 1;
509cdf0e10cSrcweir 
510cdf0e10cSrcweir                 if(!bUserMatrixFlag && FormulaCompiler::IsMatrixFunction((OpCode)eOp) )
511cdf0e10cSrcweir 			    {
512cdf0e10cSrcweir 				    aBtnMatrix.Check();
513cdf0e10cSrcweir 			    }
514cdf0e10cSrcweir 
515cdf0e10cSrcweir                 if ( eOp == m_aSpecialOpCodes[sheet::FormulaMapGroupSpecialOffset::PUSH].Token.OpCode || eOp == m_aSpecialOpCodes[sheet::FormulaMapGroupSpecialOffset::SPACES].Token.OpCode )
516cdf0e10cSrcweir 			    {
517cdf0e10cSrcweir 				    const xub_StrLen n1=aFormString.Search(sep, nTokPos);
518cdf0e10cSrcweir 				    const xub_StrLen n2=aFormString.Search(')',nTokPos);
519cdf0e10cSrcweir 				    xub_StrLen nXXX=nTokPos;
520cdf0e10cSrcweir 				    if(n1<n2)
521cdf0e10cSrcweir 				    {
522cdf0e10cSrcweir 					    nTokPos=n1;
523cdf0e10cSrcweir 				    }
524cdf0e10cSrcweir 				    else
525cdf0e10cSrcweir 				    {
526cdf0e10cSrcweir 					    nTokPos=n2;
527cdf0e10cSrcweir 				    }
528cdf0e10cSrcweir 				    if ( pNextToken != pEnd )
529cdf0e10cSrcweir 				    {
530cdf0e10cSrcweir                         aArgs[0] = *pNextToken;
531cdf0e10cSrcweir                         const String a2String = xParser->printFormula(aArgs, aRefPos);
532cdf0e10cSrcweir 					    const xub_StrLen n3 = aFormString.Search(a2String,nXXX);
533cdf0e10cSrcweir 				        if ( n3 < nTokPos )
534cdf0e10cSrcweir                             nTokPos = n3;
535cdf0e10cSrcweir 				    }
536cdf0e10cSrcweir 			    }
537cdf0e10cSrcweir 			    else
538cdf0e10cSrcweir 			    {
539cdf0e10cSrcweir                     nTokPos = sal::static_int_cast<xub_StrLen>( nTokPos + aString.Len() );
540cdf0e10cSrcweir 			    }
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 			    if ( eOp == m_aSeparatorsOpCodes[TOKEN_OPEN].OpCode )
543cdf0e10cSrcweir 			    {
544cdf0e10cSrcweir 				    nBracketCount++;
545cdf0e10cSrcweir 				    bFlag=sal_True;
546cdf0e10cSrcweir 			    }
547cdf0e10cSrcweir 			    else if ( eOp == m_aSeparatorsOpCodes[TOKEN_CLOSE].OpCode )
548cdf0e10cSrcweir 			    {
549cdf0e10cSrcweir 				    nBracketCount--;
550cdf0e10cSrcweir 				    bFlag=sal_False;
551cdf0e10cSrcweir 				    nFuncPos=nPrevFuncPos;
552cdf0e10cSrcweir 			    }
553cdf0e10cSrcweir                 bool bIsFunction = ::std::find_if(m_aFunctionOpCodes.getConstArray(),m_pFunctionOpCodesEnd,::std::bind2nd(OpCodeCompare(),boost::cref(eOp))) != m_pFunctionOpCodesEnd;
554cdf0e10cSrcweir 
555cdf0e10cSrcweir 			    if ( bIsFunction && m_aSpecialOpCodes[sheet::FormulaMapGroupSpecialOffset::SPACES].Token.OpCode != eOp )
556cdf0e10cSrcweir 			    {
557cdf0e10cSrcweir 				    nPrevFuncPos = nFuncPos;
558cdf0e10cSrcweir 				    nFuncPos = nOldTokPos;
559cdf0e10cSrcweir 			    }
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 			    if ( nOldTokPos <= nPos && nPos < nTokPos )
562cdf0e10cSrcweir 			    {
563cdf0e10cSrcweir 				    if ( !bIsFunction )
564cdf0e10cSrcweir 				    {
565cdf0e10cSrcweir 					    if ( nBracketCount < 1 )
566cdf0e10cSrcweir 					    {
567cdf0e10cSrcweir 						    nFuncPos= pMEdit->GetText().Len();
568cdf0e10cSrcweir 					    }
569cdf0e10cSrcweir 					    else if ( !bFlag )
570cdf0e10cSrcweir 					    {
571cdf0e10cSrcweir 						    nFuncPos=nPrevFuncPos;
572cdf0e10cSrcweir 					    }
573cdf0e10cSrcweir 				    }
574cdf0e10cSrcweir 				    break;
575cdf0e10cSrcweir 			    }
576cdf0e10cSrcweir 
577cdf0e10cSrcweir 			    pIter = pNextToken;
578cdf0e10cSrcweir 			    nOldTokPos = nTokPos;
579cdf0e10cSrcweir 		    } // while ( pIter != pEnd )
580cdf0e10cSrcweir         }
581cdf0e10cSrcweir         catch(const uno::Exception& )
582cdf0e10cSrcweir         {
583cdf0e10cSrcweir             DBG_ERROR("Exception caught!");
584cdf0e10cSrcweir         }
585cdf0e10cSrcweir 	}
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 	return nFuncPos;
588cdf0e10cSrcweir }
589cdf0e10cSrcweir // -----------------------------------------------------------------------------
CalcValue(const String & rStrExp,String & rStrResult)590cdf0e10cSrcweir sal_Bool FormulaDlg_Impl::CalcValue( const String& rStrExp, String& rStrResult )
591cdf0e10cSrcweir {
592cdf0e10cSrcweir 	sal_Bool bResult = sal_True;
593cdf0e10cSrcweir 
594cdf0e10cSrcweir 	if ( rStrExp.Len() > 0 )
595cdf0e10cSrcweir 	{
596cdf0e10cSrcweir 		// nur, wenn keine Tastatureingabe mehr anliegt, den Wert berechnen:
597cdf0e10cSrcweir 
598cdf0e10cSrcweir 		if ( !Application::AnyInput( INPUT_KEYBOARD ) )
599cdf0e10cSrcweir 		{
600cdf0e10cSrcweir 			bResult = m_pHelper->calculateValue(rStrExp,rStrResult);
601cdf0e10cSrcweir 		}
602cdf0e10cSrcweir 		else
603cdf0e10cSrcweir 			bResult = sal_False;
604cdf0e10cSrcweir 	}
605cdf0e10cSrcweir 
606cdf0e10cSrcweir 	return bResult;
607cdf0e10cSrcweir }
608cdf0e10cSrcweir 
UpdateValues()609cdf0e10cSrcweir void FormulaDlg_Impl::UpdateValues()
610cdf0e10cSrcweir {
611cdf0e10cSrcweir 	String aStrResult;
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 	if ( CalcValue( pFuncDesc->getFormula( m_aArguments ), aStrResult ) )
614cdf0e10cSrcweir 		aWndResult.SetValue( aStrResult );
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 	aStrResult.Erase();
617cdf0e10cSrcweir 	if ( CalcValue(m_pHelper->getCurrentFormula(), aStrResult ) )
618cdf0e10cSrcweir 		aWndFormResult.SetValue( aStrResult );
619cdf0e10cSrcweir 	else
620cdf0e10cSrcweir 	{
621cdf0e10cSrcweir 		aStrResult.Erase();
622cdf0e10cSrcweir 		aWndFormResult.SetValue( aStrResult );
623cdf0e10cSrcweir 	}
624cdf0e10cSrcweir 	CalcStruct(pMEdit->GetText());
625cdf0e10cSrcweir }
626cdf0e10cSrcweir 
CalcStruct(const String & rStrExp)627cdf0e10cSrcweir sal_Bool FormulaDlg_Impl::CalcStruct( const String& rStrExp)
628cdf0e10cSrcweir {
629cdf0e10cSrcweir 	sal_Bool bResult = sal_True;
630cdf0e10cSrcweir 	xub_StrLen nLength=rStrExp.Len();
631cdf0e10cSrcweir 
632cdf0e10cSrcweir 	if ( rStrExp.Len() > 0 && aOldFormula!=rStrExp && bStructUpdate)
633cdf0e10cSrcweir 	{
634cdf0e10cSrcweir 		// nur, wenn keine Tastatureingabe mehr anliegt, den Wert berechnen:
635cdf0e10cSrcweir 
636cdf0e10cSrcweir 		if ( !Application::AnyInput( INPUT_KEYBOARD ) )
637cdf0e10cSrcweir 		{
638cdf0e10cSrcweir 			pStructPage->ClearStruct();
639cdf0e10cSrcweir 
640cdf0e10cSrcweir 			String aString=rStrExp;
641cdf0e10cSrcweir 			if(rStrExp.GetChar(nLength-1)=='(')
642cdf0e10cSrcweir 			{
643cdf0e10cSrcweir 				aString.Erase((xub_StrLen)(nLength-1));
644cdf0e10cSrcweir 			}
645cdf0e10cSrcweir 
646cdf0e10cSrcweir 			aString.EraseAllChars('\n');
647cdf0e10cSrcweir 			String aStrResult;
648cdf0e10cSrcweir 
649cdf0e10cSrcweir 			if ( CalcValue(aString, aStrResult ) )
650cdf0e10cSrcweir 				aWndFormResult.SetValue( aStrResult );
651cdf0e10cSrcweir 
652cdf0e10cSrcweir 			UpdateTokenArray(aString);
653cdf0e10cSrcweir             fillTree(pStructPage);
654cdf0e10cSrcweir 
655cdf0e10cSrcweir 			aOldFormula=rStrExp;
656cdf0e10cSrcweir 			if(rStrExp.GetChar(nLength-1)=='(')
657cdf0e10cSrcweir 				UpdateTokenArray(rStrExp);
658cdf0e10cSrcweir 		}
659cdf0e10cSrcweir 		else
660cdf0e10cSrcweir 			bResult = sal_False;
661cdf0e10cSrcweir 	}
662cdf0e10cSrcweir 	return bResult;
663cdf0e10cSrcweir }
664cdf0e10cSrcweir 
665cdf0e10cSrcweir // -----------------------------------------------------------------------------
MakeTree(IStructHelper * _pTree,SvLBoxEntry * pParent,FormulaToken * _pToken,long Count)666cdf0e10cSrcweir void FormulaDlg_Impl::MakeTree(IStructHelper* _pTree,SvLBoxEntry* pParent,FormulaToken* _pToken,long Count)
667cdf0e10cSrcweir {
668cdf0e10cSrcweir 	if( _pToken != NULL && Count > 0 )
669cdf0e10cSrcweir 	{
670cdf0e10cSrcweir 		long nParas = _pToken->GetParamCount();
671cdf0e10cSrcweir 		OpCode eOp = _pToken->GetOpCode();
672cdf0e10cSrcweir 
673cdf0e10cSrcweir         // #i101512# for output, the original token is needed
674cdf0e10cSrcweir         FormulaToken* pOrigToken = (_pToken->GetType() == svFAP) ? _pToken->GetFAPOrigToken() : _pToken;
675cdf0e10cSrcweir         uno::Sequence<sheet::FormulaToken> aArgs(1);
676cdf0e10cSrcweir         aArgs[0] = m_aTokenMap.find(pOrigToken)->second;
677cdf0e10cSrcweir         try
678cdf0e10cSrcweir         {
679cdf0e10cSrcweir             const table::CellAddress aRefPos(m_pHelper->getReferencePosition());
680cdf0e10cSrcweir             const String aResult = m_pHelper->getFormulaParser()->printFormula(aArgs, aRefPos);
681cdf0e10cSrcweir 
682cdf0e10cSrcweir 		    if ( nParas > 0 )
683cdf0e10cSrcweir 		    {
684cdf0e10cSrcweir 			    SvLBoxEntry* pEntry;
685cdf0e10cSrcweir 
686cdf0e10cSrcweir 			    String aTest=_pTree->GetEntryText(pParent);
687cdf0e10cSrcweir 
688cdf0e10cSrcweir 			    if(aTest==aResult &&
689cdf0e10cSrcweir 				    (eOp==ocAdd || eOp==ocMul ||
690cdf0e10cSrcweir 				     eOp==ocAmpersand))
691cdf0e10cSrcweir 			    {
692cdf0e10cSrcweir 				    pEntry=pParent;
693cdf0e10cSrcweir 			    }
694cdf0e10cSrcweir 			    else
695cdf0e10cSrcweir 			    {
696cdf0e10cSrcweir 				    if(eOp==ocBad)
697cdf0e10cSrcweir 				    {
698cdf0e10cSrcweir 					    pEntry=_pTree->InsertEntry(aResult,pParent,STRUCT_ERROR,0,_pToken);
699cdf0e10cSrcweir 				    }
700cdf0e10cSrcweir 				    else
701cdf0e10cSrcweir 				    {
702cdf0e10cSrcweir 					    pEntry=_pTree->InsertEntry(aResult,pParent,STRUCT_FOLDER,0,_pToken);
703cdf0e10cSrcweir 				    }
704cdf0e10cSrcweir 			    }
705cdf0e10cSrcweir 
706cdf0e10cSrcweir 			    MakeTree(_pTree,pEntry,m_pTokenArray->PrevRPN(),nParas);
707cdf0e10cSrcweir 			    --Count;
708cdf0e10cSrcweir 			    m_pTokenArray->NextRPN();
709cdf0e10cSrcweir 			    MakeTree(_pTree,pParent,m_pTokenArray->PrevRPN(),Count);
710cdf0e10cSrcweir 		    }
711cdf0e10cSrcweir 		    else
712cdf0e10cSrcweir 		    {
713cdf0e10cSrcweir 			    if(eOp==ocBad)
714cdf0e10cSrcweir 			    {
715cdf0e10cSrcweir 				    _pTree->InsertEntry(aResult,pParent,STRUCT_ERROR,0,_pToken);
716cdf0e10cSrcweir 			    }
717cdf0e10cSrcweir 			    else
718cdf0e10cSrcweir 			    {
719cdf0e10cSrcweir 				    _pTree->InsertEntry(aResult,pParent,STRUCT_END,0,_pToken);
720cdf0e10cSrcweir 			    }
721cdf0e10cSrcweir 			    --Count;
722cdf0e10cSrcweir 			    MakeTree(_pTree,pParent,m_pTokenArray->PrevRPN(),Count);
723cdf0e10cSrcweir 		    }
724cdf0e10cSrcweir         }
725cdf0e10cSrcweir         catch(uno::Exception&)
726cdf0e10cSrcweir         {
727cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
728cdf0e10cSrcweir         }
729cdf0e10cSrcweir 	}
730cdf0e10cSrcweir }
731cdf0e10cSrcweir 
fillTree(IStructHelper * _pTree)732cdf0e10cSrcweir void FormulaDlg_Impl::fillTree(IStructHelper* _pTree)
733cdf0e10cSrcweir {
734cdf0e10cSrcweir     GetFormulaOpCodeMapper();
735cdf0e10cSrcweir     FormulaToken* pToken = m_pTokenArray->LastRPN();
736cdf0e10cSrcweir 
737cdf0e10cSrcweir 	if( pToken != NULL)
738cdf0e10cSrcweir 	{
739cdf0e10cSrcweir 		MakeTree(_pTree,NULL,pToken,1);
740cdf0e10cSrcweir 	}
741cdf0e10cSrcweir }
UpdateTokenArray(const String & rStrExp)742cdf0e10cSrcweir void FormulaDlg_Impl::UpdateTokenArray( const String& rStrExp)
743cdf0e10cSrcweir {
744cdf0e10cSrcweir     m_aTokenMap.clear();
745cdf0e10cSrcweir     m_aTokenList.realloc(0);
746cdf0e10cSrcweir     try
747cdf0e10cSrcweir     {
748cdf0e10cSrcweir         const table::CellAddress aRefPos(m_pHelper->getReferencePosition());
749cdf0e10cSrcweir         m_aTokenList = m_pHelper->getFormulaParser()->parseFormula(rStrExp, aRefPos);
750cdf0e10cSrcweir     }
751cdf0e10cSrcweir     catch(const uno::Exception&)
752cdf0e10cSrcweir     {
753cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
754cdf0e10cSrcweir     }
755cdf0e10cSrcweir     GetFormulaOpCodeMapper(); // just to get it initialized
756cdf0e10cSrcweir 	m_pTokenArray = m_pHelper->convertToTokenArray(m_aTokenList);
757cdf0e10cSrcweir     const sal_Int32 nLen = static_cast<sal_Int32>(m_pTokenArray->GetLen());
758cdf0e10cSrcweir     FormulaToken** pTokens = m_pTokenArray->GetArray();
759cdf0e10cSrcweir     if ( pTokens && nLen == m_aTokenList.getLength() )
760cdf0e10cSrcweir     {
761cdf0e10cSrcweir         for (sal_Int32 nPos=0; nPos<nLen; nPos++)
762cdf0e10cSrcweir         {
763cdf0e10cSrcweir             m_aTokenMap.insert(::std::map<FormulaToken*,sheet::FormulaToken>::value_type(pTokens[nPos],m_aTokenList[nPos]));
764cdf0e10cSrcweir         }
765cdf0e10cSrcweir     } // if ( pTokens && nLen == m_aTokenList.getLength() )
766cdf0e10cSrcweir 
767cdf0e10cSrcweir     FormulaCompiler aCompiler(*m_pTokenArray.get());
768cdf0e10cSrcweir     aCompiler.SetCompileForFAP(sal_True);   // #i101512# special handling is needed
769cdf0e10cSrcweir     aCompiler.CompileTokenArray();
770cdf0e10cSrcweir }
771cdf0e10cSrcweir 
FillDialog(sal_Bool nFlag)772cdf0e10cSrcweir void FormulaDlg_Impl::FillDialog(sal_Bool nFlag)
773cdf0e10cSrcweir {
774cdf0e10cSrcweir 	sal_Bool bNext=sal_True, bPrev=sal_True;
775cdf0e10cSrcweir 	if(nFlag)
776cdf0e10cSrcweir 		FillControls(bNext, bPrev);
777cdf0e10cSrcweir 	FillListboxes();
778cdf0e10cSrcweir 	if(nFlag)
779cdf0e10cSrcweir 	{
780cdf0e10cSrcweir 		aBtnBackward.Enable(bPrev);
781cdf0e10cSrcweir 		aBtnForward.Enable(bNext);
782cdf0e10cSrcweir 	}
783cdf0e10cSrcweir 
784cdf0e10cSrcweir 	String aStrResult;
785cdf0e10cSrcweir 
786cdf0e10cSrcweir 	if ( CalcValue(m_pHelper->getCurrentFormula(), aStrResult ) )
787cdf0e10cSrcweir 		aWndFormResult.SetValue( aStrResult );
788cdf0e10cSrcweir 	else
789cdf0e10cSrcweir 	{
790cdf0e10cSrcweir 		aStrResult.Erase();
791cdf0e10cSrcweir 		aWndFormResult.SetValue( aStrResult );
792cdf0e10cSrcweir 	}
793cdf0e10cSrcweir }
794cdf0e10cSrcweir 
795cdf0e10cSrcweir // -----------------------------------------------------------------------------
FillListboxes()796cdf0e10cSrcweir void FormulaDlg_Impl::FillListboxes()
797cdf0e10cSrcweir {
798cdf0e10cSrcweir 	//	Umschalten zwischen den "Seiten"
799cdf0e10cSrcweir     FormEditData* pData = m_pHelper->getFormEditData();
800cdf0e10cSrcweir 	String aNewTitle;
801cdf0e10cSrcweir 	//	1. Seite: Funktion auswaehlen
802cdf0e10cSrcweir 	if ( pFuncDesc && pFuncDesc->getCategory() )
803cdf0e10cSrcweir 	{
804cdf0e10cSrcweir 		if( pFuncPage->GetCategory() != pFuncDesc->getCategory()->getNumber() + 1 )
805cdf0e10cSrcweir 			pFuncPage->SetCategory(static_cast<sal_uInt16>(pFuncDesc->getCategory()->getNumber() + 1));
806cdf0e10cSrcweir 
807cdf0e10cSrcweir 		sal_uInt16 nPos=pFuncPage->GetFuncPos(pFuncDesc);
808cdf0e10cSrcweir 
809cdf0e10cSrcweir 		pFuncPage->SetFunction(nPos);
810cdf0e10cSrcweir 	}
811cdf0e10cSrcweir 	else if ( pData )
812cdf0e10cSrcweir 	{
813cdf0e10cSrcweir 		pFuncPage->SetCategory( pData->GetCatSel() );
814cdf0e10cSrcweir 		pFuncPage->SetFunction( pData->GetFuncSel() );
815cdf0e10cSrcweir 	}
816cdf0e10cSrcweir 	FuncSelHdl(NULL);
817cdf0e10cSrcweir 
818cdf0e10cSrcweir 	//	ResizeArgArr jetzt schon in UpdateFunctionDesc
819cdf0e10cSrcweir 
820cdf0e10cSrcweir 
821cdf0e10cSrcweir     m_pHelper->setDispatcherLock( sal_True);// Modal-Modus einschalten
822cdf0e10cSrcweir 
823cdf0e10cSrcweir 	aNewTitle = aTitle1;
824cdf0e10cSrcweir 
825cdf0e10cSrcweir 	//	HelpId fuer 1. Seite ist die aus der Resource
826cdf0e10cSrcweir 	m_pParent->SetHelpId( aOldHelp );
827cdf0e10cSrcweir 	m_pParent->SetUniqueId( aOldUnique );
828cdf0e10cSrcweir }
829cdf0e10cSrcweir // -----------------------------------------------------------------------------
FillControls(sal_Bool & rbNext,sal_Bool & rbPrev)830cdf0e10cSrcweir void FormulaDlg_Impl::FillControls(sal_Bool &rbNext, sal_Bool &rbPrev)
831cdf0e10cSrcweir {
832cdf0e10cSrcweir 	//	Umschalten zwischen den "Seiten"
833cdf0e10cSrcweir     FormEditData* pData = m_pHelper->getFormEditData();
834cdf0e10cSrcweir 	if (!pData )
835cdf0e10cSrcweir         return;
836cdf0e10cSrcweir 
837cdf0e10cSrcweir 	String aNewTitle;
838cdf0e10cSrcweir 	//	2. Seite oder Editieren: ausgewaehlte Funktion anzeigen
839cdf0e10cSrcweir 
840cdf0e10cSrcweir 	xub_StrLen nFStart	   = pData->GetFStart();
841cdf0e10cSrcweir 	String aFormula		   = m_pHelper->getCurrentFormula();
842cdf0e10cSrcweir 	xub_StrLen nNextFStart = nFStart;
843cdf0e10cSrcweir 	xub_StrLen nNextFEnd   = 0;
844cdf0e10cSrcweir 
845cdf0e10cSrcweir 	aFormula.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " )" ));
846cdf0e10cSrcweir 	DeleteArgs();
847cdf0e10cSrcweir 	const IFunctionDescription* pOldFuncDesc = pFuncDesc;
848cdf0e10cSrcweir 	sal_Bool bTestFlag = sal_False;
849cdf0e10cSrcweir 
850cdf0e10cSrcweir 	if ( m_aFormulaHelper.GetNextFunc( aFormula, sal_False,
851cdf0e10cSrcweir 									 nNextFStart, &nNextFEnd, &pFuncDesc, &m_aArguments ) )
852cdf0e10cSrcweir 	{
853cdf0e10cSrcweir 		bTestFlag = (pOldFuncDesc != pFuncDesc);
854cdf0e10cSrcweir 		if(bTestFlag)
855cdf0e10cSrcweir 		{
856cdf0e10cSrcweir 			aFtHeadLine.Hide();
857cdf0e10cSrcweir 			aFtFuncName.Hide();
858cdf0e10cSrcweir 			aFtFuncDesc.Hide();
859cdf0e10cSrcweir 			pParaWin->SetFunctionDesc(pFuncDesc);
860cdf0e10cSrcweir 			aFtEditName.SetText( pFuncDesc->getFunctionName() );
861cdf0e10cSrcweir             aFtEditName.Show();
862cdf0e10cSrcweir             pParaWin->Show();
863cdf0e10cSrcweir             const rtl::OString aHelpId = pFuncDesc->getHelpId();
864cdf0e10cSrcweir             if ( aHelpId.getLength() )
865cdf0e10cSrcweir                 pMEdit->SetHelpId(aHelpId);
866cdf0e10cSrcweir 		}
867cdf0e10cSrcweir 
868cdf0e10cSrcweir 		xub_StrLen nOldStart, nOldEnd;
869cdf0e10cSrcweir 		m_pHelper->getSelection( nOldStart, nOldEnd );
870cdf0e10cSrcweir 		if ( nOldStart != nNextFStart || nOldEnd != nNextFEnd )
871cdf0e10cSrcweir 		{
872cdf0e10cSrcweir 			m_pHelper->setSelection( nNextFStart, nNextFEnd );
873cdf0e10cSrcweir 		}
874cdf0e10cSrcweir 		aFuncSel.Min() = nNextFStart;
875cdf0e10cSrcweir 		aFuncSel.Max() = nNextFEnd;
876cdf0e10cSrcweir 
877cdf0e10cSrcweir 		if(!bEditFlag)
878cdf0e10cSrcweir 			pMEdit->SetText(m_pHelper->getCurrentFormula());
879cdf0e10cSrcweir 		xub_StrLen PrivStart, PrivEnd;
880cdf0e10cSrcweir         m_pHelper->getSelection( PrivStart, PrivEnd);
881cdf0e10cSrcweir 		if(!bEditFlag)
882cdf0e10cSrcweir 			pMEdit->SetSelection( Selection(PrivStart, PrivEnd));
883cdf0e10cSrcweir 
884cdf0e10cSrcweir 		nArgs = pFuncDesc->getSuppressedArgumentCount();
885cdf0e10cSrcweir 		sal_uInt16 nOffset = pData->GetOffset();
886cdf0e10cSrcweir 		nEdFocus = pData->GetEdFocus();
887cdf0e10cSrcweir 
888cdf0e10cSrcweir 		//	Verkettung der Edit's fuer Focus-Kontrolle
889cdf0e10cSrcweir 
890cdf0e10cSrcweir 		if(bTestFlag)
891cdf0e10cSrcweir             pParaWin->SetArgumentOffset(nOffset);
892cdf0e10cSrcweir 		sal_uInt16 nActiv=0;
893cdf0e10cSrcweir 		xub_StrLen nArgPos= m_aFormulaHelper.GetArgStart( aFormula, nFStart, 0 );
894cdf0e10cSrcweir 		xub_StrLen nEditPos=(xub_StrLen) pMEdit->GetSelection().Min();
895cdf0e10cSrcweir 		sal_Bool	bFlag=sal_False;
896cdf0e10cSrcweir 
897cdf0e10cSrcweir 		for(sal_uInt16 i=0;i<nArgs;i++)
898cdf0e10cSrcweir 		{
899cdf0e10cSrcweir 			sal_Int32 nLength = m_aArguments[i].getLength()+1;
900cdf0e10cSrcweir 			pParaWin->SetArgument(i,m_aArguments[i]);
901cdf0e10cSrcweir 			if(nArgPos<=nEditPos && nEditPos<nArgPos+nLength)
902cdf0e10cSrcweir 			{
903cdf0e10cSrcweir 				nActiv=i;
904cdf0e10cSrcweir 				bFlag=sal_True;
905cdf0e10cSrcweir 			}
906cdf0e10cSrcweir             nArgPos = sal::static_int_cast<xub_StrLen>( nArgPos + nLength );
907cdf0e10cSrcweir 		}
908cdf0e10cSrcweir 		pParaWin->UpdateParas();
909cdf0e10cSrcweir 
910cdf0e10cSrcweir 		if(bFlag)
911cdf0e10cSrcweir 		{
912cdf0e10cSrcweir 			pParaWin->SetActiveLine(nActiv);
913cdf0e10cSrcweir 		}
914cdf0e10cSrcweir 
915cdf0e10cSrcweir 		//pParaWin->SetEdFocus( nEdFocus );
916cdf0e10cSrcweir 		UpdateValues();
917cdf0e10cSrcweir 	}
918cdf0e10cSrcweir 	else
919cdf0e10cSrcweir 	{
920cdf0e10cSrcweir 		aFtEditName.SetText(String());
921cdf0e10cSrcweir         pMEdit->SetHelpId( m_aEditHelpId );
922cdf0e10cSrcweir 	}
923cdf0e10cSrcweir 		//	Test, ob vorne/hinten noch mehr Funktionen sind
924cdf0e10cSrcweir 
925cdf0e10cSrcweir 	xub_StrLen nTempStart = m_aFormulaHelper.GetArgStart( aFormula, nFStart, 0 );
926cdf0e10cSrcweir 	rbNext = m_aFormulaHelper.GetNextFunc( aFormula, sal_False, nTempStart );
927cdf0e10cSrcweir 	nTempStart=(xub_StrLen)pMEdit->GetSelection().Min();
928cdf0e10cSrcweir 	pData->SetFStart(nTempStart);
929cdf0e10cSrcweir 	rbPrev = m_aFormulaHelper.GetNextFunc( aFormula, sal_True, nTempStart );
930cdf0e10cSrcweir }
931cdf0e10cSrcweir // -----------------------------------------------------------------------------
932cdf0e10cSrcweir 
ClearAllParas()933cdf0e10cSrcweir void FormulaDlg_Impl::ClearAllParas()
934cdf0e10cSrcweir {
935cdf0e10cSrcweir 	DeleteArgs();
936cdf0e10cSrcweir 	pFuncDesc = NULL;
937cdf0e10cSrcweir 	pParaWin->ClearAll();
938cdf0e10cSrcweir 	aWndResult.SetValue(String());
939cdf0e10cSrcweir 	aFtFuncName.SetText(String());
940cdf0e10cSrcweir 	FuncSelHdl(NULL);
941cdf0e10cSrcweir 
942cdf0e10cSrcweir 	if(pFuncPage->IsVisible())
943cdf0e10cSrcweir 	{
944cdf0e10cSrcweir         aFtEditName.Hide();
945cdf0e10cSrcweir         pParaWin->Hide();
946cdf0e10cSrcweir 
947cdf0e10cSrcweir 		aBtnForward.Enable(sal_True); //@new
948cdf0e10cSrcweir 		aFtHeadLine.Show();
949cdf0e10cSrcweir 		aFtFuncName.Show();
950cdf0e10cSrcweir 		aFtFuncDesc.Show();
951cdf0e10cSrcweir 	}
952cdf0e10cSrcweir }
RepairFormula(const String & aFormula)953cdf0e10cSrcweir String FormulaDlg_Impl::RepairFormula(const String& aFormula)
954cdf0e10cSrcweir {
955cdf0e10cSrcweir 	String aResult('=');
956cdf0e10cSrcweir     try
957cdf0e10cSrcweir     {
958cdf0e10cSrcweir 	    UpdateTokenArray(aFormula);
959cdf0e10cSrcweir 
960cdf0e10cSrcweir         if ( m_aTokenList.getLength() )
961cdf0e10cSrcweir 	    {
962cdf0e10cSrcweir             const table::CellAddress aRefPos(m_pHelper->getReferencePosition());
963cdf0e10cSrcweir             const String sFormula(m_pHelper->getFormulaParser()->printFormula(m_aTokenList, aRefPos));
964cdf0e10cSrcweir             if ( !sFormula.Len() || sFormula.GetChar(0) != '=' )
965cdf0e10cSrcweir                 aResult += sFormula;
966cdf0e10cSrcweir             else
967cdf0e10cSrcweir                 aResult = sFormula;
968cdf0e10cSrcweir 
969cdf0e10cSrcweir 	    }
970cdf0e10cSrcweir     }
971cdf0e10cSrcweir     catch(const uno::Exception& )
972cdf0e10cSrcweir     {
973cdf0e10cSrcweir         DBG_ERROR("Exception caught!");
974cdf0e10cSrcweir     }
975cdf0e10cSrcweir 	return aResult;
976cdf0e10cSrcweir }
977cdf0e10cSrcweir 
DoEnter(sal_Bool bOk)978cdf0e10cSrcweir void FormulaDlg_Impl::DoEnter(sal_Bool bOk)
979cdf0e10cSrcweir {
980cdf0e10cSrcweir 	//	Eingabe ins Dokument uebernehmen oder abbrechen
981cdf0e10cSrcweir 	if ( bOk)
982cdf0e10cSrcweir 	{
983cdf0e10cSrcweir 		//	ggf. Dummy-Argumente entfernen
984cdf0e10cSrcweir 		String	aInputFormula = m_pHelper->getCurrentFormula();
985cdf0e10cSrcweir 		String	aString = RepairFormula(pMEdit->GetText());
986cdf0e10cSrcweir 		m_pHelper->setSelection(0, aInputFormula.Len());
987cdf0e10cSrcweir 		m_pHelper->setCurrentFormula(aString);
988cdf0e10cSrcweir 	}
989cdf0e10cSrcweir 
990cdf0e10cSrcweir 	m_pHelper->switchBack();
991cdf0e10cSrcweir 
992cdf0e10cSrcweir     m_pHelper->dispatch(bOk,aBtnMatrix.IsChecked());
993cdf0e10cSrcweir 	//	Daten loeschen
994cdf0e10cSrcweir     m_pHelper->deleteFormData();
995cdf0e10cSrcweir 
996cdf0e10cSrcweir 	//	Dialog schliessen
997cdf0e10cSrcweir 	m_pHelper->doClose(bOk);
998cdf0e10cSrcweir }
999cdf0e10cSrcweir // -----------------------------------------------------------------------------
1000cdf0e10cSrcweir 
IMPL_LINK(FormulaDlg_Impl,BtnHdl,PushButton *,pBtn)1001cdf0e10cSrcweir IMPL_LINK( FormulaDlg_Impl, BtnHdl, PushButton*, pBtn )
1002cdf0e10cSrcweir {
1003cdf0e10cSrcweir 	if ( pBtn == &aBtnCancel )
1004cdf0e10cSrcweir 	{
1005cdf0e10cSrcweir 		DoEnter(sal_False);					// schliesst den Dialog
1006cdf0e10cSrcweir 	}
1007cdf0e10cSrcweir 	else if ( pBtn == &aBtnEnd )
1008cdf0e10cSrcweir 	{
1009cdf0e10cSrcweir 		DoEnter(sal_True);					// schliesst den Dialog
1010cdf0e10cSrcweir 	}
1011cdf0e10cSrcweir 	else if ( pBtn == &aBtnForward )
1012cdf0e10cSrcweir 	{
1013cdf0e10cSrcweir 		//@pMEdit->GrabFocus();			// Damit die Selektion auch angezeigt wird.
1014cdf0e10cSrcweir 		const IFunctionDescription* pDesc =pFuncPage->GetFuncDesc( pFuncPage->GetFunction() );
1015cdf0e10cSrcweir 
1016cdf0e10cSrcweir 		if(pDesc==pFuncDesc || !pFuncPage->IsVisible())
1017cdf0e10cSrcweir 			EditNextFunc( sal_True );
1018cdf0e10cSrcweir 		else
1019cdf0e10cSrcweir 		{
1020cdf0e10cSrcweir 			DblClkHdl(pFuncPage);	   //new
1021cdf0e10cSrcweir 			aBtnForward.Enable(sal_False); //new
1022cdf0e10cSrcweir 		}
1023cdf0e10cSrcweir 		//@EditNextFunc( sal_True );
1024cdf0e10cSrcweir 	}
1025cdf0e10cSrcweir 	else if ( pBtn == &aBtnBackward )
1026cdf0e10cSrcweir 	{
1027cdf0e10cSrcweir 		bEditFlag=sal_False;
1028cdf0e10cSrcweir 		aBtnForward.Enable(sal_True);
1029cdf0e10cSrcweir 		EditNextFunc( sal_False );
1030cdf0e10cSrcweir 		aMEFormula.Invalidate();
1031cdf0e10cSrcweir 		aMEFormula.Update();
1032cdf0e10cSrcweir 	}
1033cdf0e10cSrcweir 	//...
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir 	return 0;
1036cdf0e10cSrcweir }
1037cdf0e10cSrcweir // -----------------------------------------------------------------------------
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir 
1040cdf0e10cSrcweir //	--------------------------------------------------------------------------
1041cdf0e10cSrcweir //							Funktionen fuer 1. Seite
1042cdf0e10cSrcweir //	--------------------------------------------------------------------------
1043cdf0e10cSrcweir 
ResizeArgArr(const IFunctionDescription * pNewFunc)1044cdf0e10cSrcweir void FormulaDlg_Impl::ResizeArgArr( const IFunctionDescription* pNewFunc )
1045cdf0e10cSrcweir {
1046cdf0e10cSrcweir 	if ( pFuncDesc != pNewFunc )
1047cdf0e10cSrcweir 	{
1048cdf0e10cSrcweir 		DeleteArgs();
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir 		if ( pNewFunc )
1051cdf0e10cSrcweir 			nArgs = pNewFunc->getSuppressedArgumentCount();
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir 		pFuncDesc = pNewFunc;
1054cdf0e10cSrcweir 	}
1055cdf0e10cSrcweir }
1056cdf0e10cSrcweir // -----------------------------------------------------------------------------
1057cdf0e10cSrcweir 
UpdateFunctionDesc()1058cdf0e10cSrcweir void FormulaDlg_Impl::UpdateFunctionDesc()
1059cdf0e10cSrcweir {
1060cdf0e10cSrcweir 	FormEditData* pData = m_pHelper->getFormEditData();
1061cdf0e10cSrcweir 	if (!pData)
1062cdf0e10cSrcweir         return;
1063cdf0e10cSrcweir 	sal_uInt16 nCat = pFuncPage->GetCategory();
1064cdf0e10cSrcweir 	if ( nCat == LISTBOX_ENTRY_NOTFOUND )
1065cdf0e10cSrcweir         nCat = 0;
1066cdf0e10cSrcweir 	pData->SetCatSel( nCat );
1067cdf0e10cSrcweir 	sal_uInt16 nFunc = pFuncPage->GetFunction();
1068cdf0e10cSrcweir 	if ( nFunc == LISTBOX_ENTRY_NOTFOUND )
1069cdf0e10cSrcweir         nFunc = 0;
1070cdf0e10cSrcweir 	pData->SetFuncSel( nFunc );
1071cdf0e10cSrcweir 
1072cdf0e10cSrcweir 	if (   (pFuncPage->GetFunctionEntryCount() > 0)
1073cdf0e10cSrcweir 		&& (pFuncPage->GetFunction() != LISTBOX_ENTRY_NOTFOUND) )
1074cdf0e10cSrcweir 	{
1075cdf0e10cSrcweir 		const IFunctionDescription* pDesc = pFuncPage->GetFuncDesc(pFuncPage->GetFunction() );
1076cdf0e10cSrcweir 		if (pDesc)
1077cdf0e10cSrcweir 		{
1078cdf0e10cSrcweir             pDesc->initArgumentInfo();      // full argument info is needed
1079cdf0e10cSrcweir 
1080cdf0e10cSrcweir 			String aSig = pDesc->getSignature();
1081cdf0e10cSrcweir 
1082cdf0e10cSrcweir 			aFtFuncName.SetText( aSig );
1083cdf0e10cSrcweir 			aFtFuncDesc.SetText( pDesc->getDescription() );
1084cdf0e10cSrcweir 			ResizeArgArr( pDesc );
1085cdf0e10cSrcweir 
1086cdf0e10cSrcweir 			if ( !m_aArguments.empty() )		// noch Argumente da?
1087cdf0e10cSrcweir 				aSig = pDesc->getFormula( m_aArguments );			// fuer Eingabezeile
1088cdf0e10cSrcweir 			//@ m_pHelper->setCurrentFormula( aSig );
1089cdf0e10cSrcweir 		}
1090cdf0e10cSrcweir 	}
1091cdf0e10cSrcweir 	else
1092cdf0e10cSrcweir 	{
1093cdf0e10cSrcweir 		aFtFuncName.SetText( String() );
1094cdf0e10cSrcweir 		aFtFuncDesc.SetText( String() );
1095cdf0e10cSrcweir 
1096cdf0e10cSrcweir 		//ResizeArgArr( NULL );
1097cdf0e10cSrcweir 		m_pHelper->setCurrentFormula( String() );
1098cdf0e10cSrcweir 	}
1099cdf0e10cSrcweir }
1100cdf0e10cSrcweir // -----------------------------------------------------------------------------
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir // Handler fuer Listboxen
1103cdf0e10cSrcweir 
IMPL_LINK(FormulaDlg_Impl,DblClkHdl,FuncPage *,EMPTYARG)1104cdf0e10cSrcweir IMPL_LINK( FormulaDlg_Impl, DblClkHdl, FuncPage*, EMPTYARG )
1105cdf0e10cSrcweir {
1106cdf0e10cSrcweir 	sal_uInt16 nFunc = pFuncPage->GetFunction();
1107cdf0e10cSrcweir 
1108cdf0e10cSrcweir 	//	ex-UpdateLRUList
1109cdf0e10cSrcweir 	const IFunctionDescription*	pDesc = pFuncPage->GetFuncDesc(nFunc);
1110cdf0e10cSrcweir     m_pHelper->insertEntryToLRUList(pDesc);
1111cdf0e10cSrcweir 
1112cdf0e10cSrcweir 	String aFuncName = pFuncPage->GetSelFunctionName();
1113cdf0e10cSrcweir 	aFuncName.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "()" ));
1114cdf0e10cSrcweir 	m_pHelper->setCurrentFormula(aFuncName);
1115cdf0e10cSrcweir 	pMEdit->ReplaceSelected(aFuncName);
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir 	Selection aSel=pMEdit->GetSelection();
1118cdf0e10cSrcweir 	aSel.Max()=aSel.Max()-1;
1119cdf0e10cSrcweir 	pMEdit->SetSelection(aSel);
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir 	FormulaHdl(pMEdit);
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir 	aSel.Min()=aSel.Max();
1124cdf0e10cSrcweir 	pMEdit->SetSelection(aSel);
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir 	if(nArgs==0)
1127cdf0e10cSrcweir 	{
1128cdf0e10cSrcweir 		BtnHdl(&aBtnBackward);
1129cdf0e10cSrcweir 	}
1130cdf0e10cSrcweir 
1131cdf0e10cSrcweir 	pParaWin->SetEdFocus(0);
1132cdf0e10cSrcweir 	aBtnForward.Enable(sal_False); //@New
1133cdf0e10cSrcweir 
1134cdf0e10cSrcweir 	return 0;
1135cdf0e10cSrcweir }
1136cdf0e10cSrcweir // -----------------------------------------------------------------------------
1137cdf0e10cSrcweir 
1138cdf0e10cSrcweir //	--------------------------------------------------------------------------
1139cdf0e10cSrcweir //							Funktionen fuer rechte Seite
1140cdf0e10cSrcweir //	--------------------------------------------------------------------------
SetData(xub_StrLen nFStart,xub_StrLen nNextFStart,xub_StrLen nNextFEnd,xub_StrLen & PrivStart,xub_StrLen & PrivEnd)1141cdf0e10cSrcweir void FormulaDlg_Impl::SetData(xub_StrLen nFStart,xub_StrLen nNextFStart,xub_StrLen nNextFEnd,xub_StrLen& PrivStart,xub_StrLen& PrivEnd)
1142cdf0e10cSrcweir {
1143cdf0e10cSrcweir     xub_StrLen nFEnd;
1144cdf0e10cSrcweir 
1145cdf0e10cSrcweir 	// Selektion merken und neue setzen
1146cdf0e10cSrcweir 	m_pHelper->getSelection( nFStart, nFEnd );
1147cdf0e10cSrcweir 	m_pHelper->setSelection( nNextFStart, nNextFEnd );
1148cdf0e10cSrcweir 	if(!bEditFlag)
1149cdf0e10cSrcweir 		pMEdit->SetText(m_pHelper->getCurrentFormula());
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir 
1152cdf0e10cSrcweir 	m_pHelper->getSelection( PrivStart, PrivEnd);
1153cdf0e10cSrcweir 	if(!bEditFlag)
1154cdf0e10cSrcweir 	{
1155cdf0e10cSrcweir 		pMEdit->SetSelection( Selection(PrivStart, PrivEnd));
1156cdf0e10cSrcweir 		aMEFormula.UpdateOldSel();
1157cdf0e10cSrcweir 	}
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir     FormEditData* pData = m_pHelper->getFormEditData();
1160cdf0e10cSrcweir 	pData->SetFStart( nNextFStart );
1161cdf0e10cSrcweir 	pData->SetOffset( 0 );
1162cdf0e10cSrcweir 	pData->SetEdFocus( 0 );
1163cdf0e10cSrcweir 
1164cdf0e10cSrcweir     FillDialog();
1165cdf0e10cSrcweir }
1166cdf0e10cSrcweir // -----------------------------------------------------------------------------
EditThisFunc(xub_StrLen nFStart)1167cdf0e10cSrcweir void FormulaDlg_Impl::EditThisFunc(xub_StrLen nFStart)
1168cdf0e10cSrcweir {
1169cdf0e10cSrcweir 	FormEditData* pData = m_pHelper->getFormEditData();
1170cdf0e10cSrcweir 	if (!pData) return;
1171cdf0e10cSrcweir 
1172cdf0e10cSrcweir 	String aFormula = m_pHelper->getCurrentFormula();
1173cdf0e10cSrcweir 
1174cdf0e10cSrcweir 	if(nFStart==NOT_FOUND)
1175cdf0e10cSrcweir 	{
1176cdf0e10cSrcweir 		nFStart = pData->GetFStart();
1177cdf0e10cSrcweir 	}
1178cdf0e10cSrcweir 	else
1179cdf0e10cSrcweir 	{
1180cdf0e10cSrcweir 		pData->SetFStart(nFStart);
1181cdf0e10cSrcweir 	}
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir 	xub_StrLen nNextFStart	= nFStart;
1184cdf0e10cSrcweir 	xub_StrLen nNextFEnd	= 0;
1185cdf0e10cSrcweir 
1186cdf0e10cSrcweir 	sal_Bool bFound;
1187cdf0e10cSrcweir 
1188cdf0e10cSrcweir 	//@bFound = m_pHelper->getNextFunction( aFormula, sal_False, nNextFStart, &nNextFEnd, &pFuncDesc );
1189cdf0e10cSrcweir 
1190cdf0e10cSrcweir 	bFound = m_aFormulaHelper.GetNextFunc( aFormula, sal_False, nNextFStart, &nNextFEnd);
1191cdf0e10cSrcweir 	if ( bFound )
1192cdf0e10cSrcweir 	{
1193cdf0e10cSrcweir         xub_StrLen PrivStart, PrivEnd;
1194cdf0e10cSrcweir         SetData(nFStart,nNextFStart,nNextFEnd,PrivStart, PrivEnd);
1195cdf0e10cSrcweir 		m_pHelper->showReference(aFormula.Copy(PrivStart, PrivEnd-PrivStart));
1196cdf0e10cSrcweir 	}
1197cdf0e10cSrcweir 	else
1198cdf0e10cSrcweir 	{
1199cdf0e10cSrcweir 		ClearAllParas();
1200cdf0e10cSrcweir 	}
1201cdf0e10cSrcweir }
1202cdf0e10cSrcweir 
EditNextFunc(sal_Bool bForward,xub_StrLen nFStart)1203cdf0e10cSrcweir void FormulaDlg_Impl::EditNextFunc( sal_Bool bForward, xub_StrLen nFStart )
1204cdf0e10cSrcweir {
1205cdf0e10cSrcweir 	FormEditData* pData = m_pHelper->getFormEditData();
1206cdf0e10cSrcweir 	if (!pData)
1207cdf0e10cSrcweir         return;
1208cdf0e10cSrcweir 
1209cdf0e10cSrcweir 	String aFormula = m_pHelper->getCurrentFormula();
1210cdf0e10cSrcweir 
1211cdf0e10cSrcweir 	if(nFStart==NOT_FOUND)
1212cdf0e10cSrcweir 	{
1213cdf0e10cSrcweir 		nFStart = pData->GetFStart();
1214cdf0e10cSrcweir 	}
1215cdf0e10cSrcweir 	else
1216cdf0e10cSrcweir 	{
1217cdf0e10cSrcweir 		pData->SetFStart(nFStart);
1218cdf0e10cSrcweir 	}
1219cdf0e10cSrcweir 
1220cdf0e10cSrcweir 	xub_StrLen nNextFStart	= 0;
1221cdf0e10cSrcweir 	xub_StrLen nNextFEnd	= 0;
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir 	sal_Bool bFound;
1224cdf0e10cSrcweir 	if ( bForward )
1225cdf0e10cSrcweir 	{
1226cdf0e10cSrcweir 		nNextFStart	= m_aFormulaHelper.GetArgStart( aFormula, nFStart, 0 );
1227cdf0e10cSrcweir 		//@bFound = m_pHelper->getNextFunction( aFormula, sal_False, nNextFStart, &nNextFEnd, &pFuncDesc );
1228cdf0e10cSrcweir 		bFound = m_aFormulaHelper.GetNextFunc( aFormula, sal_False, nNextFStart, &nNextFEnd);
1229cdf0e10cSrcweir 	}
1230cdf0e10cSrcweir 	else
1231cdf0e10cSrcweir 	{
1232cdf0e10cSrcweir 		nNextFStart	= nFStart;
1233cdf0e10cSrcweir 		//@bFound = m_pHelper->getNextFunction( aFormula, sal_True, nNextFStart, &nNextFEnd, &pFuncDesc );
1234cdf0e10cSrcweir 		bFound = m_aFormulaHelper.GetNextFunc( aFormula, sal_True, nNextFStart, &nNextFEnd);
1235cdf0e10cSrcweir 	}
1236cdf0e10cSrcweir 
1237cdf0e10cSrcweir 	if ( bFound )
1238cdf0e10cSrcweir 	{
1239cdf0e10cSrcweir         xub_StrLen PrivStart, PrivEnd;
1240cdf0e10cSrcweir         SetData(nFStart,nNextFStart,nNextFEnd,PrivStart, PrivEnd);
1241cdf0e10cSrcweir 	}
1242cdf0e10cSrcweir }
1243cdf0e10cSrcweir 
EditFuncParas(xub_StrLen nEditPos)1244cdf0e10cSrcweir void FormulaDlg_Impl::EditFuncParas(xub_StrLen nEditPos)
1245cdf0e10cSrcweir {
1246cdf0e10cSrcweir 	if(pFuncDesc!=NULL)
1247cdf0e10cSrcweir 	{
1248cdf0e10cSrcweir 		FormEditData* pData = m_pHelper->getFormEditData();
1249cdf0e10cSrcweir 		if (!pData) return;
1250cdf0e10cSrcweir 
1251cdf0e10cSrcweir 		String aFormula = m_pHelper->getCurrentFormula();
1252cdf0e10cSrcweir 		aFormula +=')';
1253cdf0e10cSrcweir 		xub_StrLen nFStart = pData->GetFStart();
1254cdf0e10cSrcweir 
1255cdf0e10cSrcweir 		DeleteArgs();
1256cdf0e10cSrcweir 
1257cdf0e10cSrcweir 		nArgs = pFuncDesc->getSuppressedArgumentCount();
1258cdf0e10cSrcweir 
1259cdf0e10cSrcweir 		sal_Int32 nArgPos=m_aFormulaHelper.GetArgStart( aFormula, nFStart, 0 );
1260cdf0e10cSrcweir         m_aFormulaHelper.GetArgStrings(m_aArguments,aFormula, nFStart, nArgs );
1261cdf0e10cSrcweir // 		m_aArguments = ScFormulaUtil::GetArgStrings( aFormula, nFStart, nArgs );
1262cdf0e10cSrcweir 
1263cdf0e10cSrcweir 		sal_uInt16 nActiv=pParaWin->GetSliderPos();
1264cdf0e10cSrcweir 		sal_Bool	bFlag=sal_False;
1265cdf0e10cSrcweir         ::std::vector< ::rtl::OUString >::iterator aIter = m_aArguments.begin();
1266cdf0e10cSrcweir         ::std::vector< ::rtl::OUString >::iterator aEnd = m_aArguments.end();
1267cdf0e10cSrcweir 		for(sal_uInt16 i=0;aIter != aEnd;i++,++aIter)
1268cdf0e10cSrcweir 		{
1269cdf0e10cSrcweir 			sal_Int32 nLength=(*aIter).getLength();
1270cdf0e10cSrcweir 			pParaWin->SetArgument(i,(*aIter));
1271cdf0e10cSrcweir 			if(nArgPos<=nEditPos && nEditPos<nArgPos+nLength)
1272cdf0e10cSrcweir 			{
1273cdf0e10cSrcweir 				nActiv=i;
1274cdf0e10cSrcweir 				bFlag=sal_True;
1275cdf0e10cSrcweir 			}
1276cdf0e10cSrcweir 			nArgPos+=nLength+1;
1277cdf0e10cSrcweir 		}
1278cdf0e10cSrcweir 
1279cdf0e10cSrcweir 		if(bFlag)
1280cdf0e10cSrcweir 		{
1281cdf0e10cSrcweir 			pParaWin->SetSliderPos(nActiv);
1282cdf0e10cSrcweir 		}
1283cdf0e10cSrcweir 
1284cdf0e10cSrcweir 		pParaWin->UpdateParas();
1285cdf0e10cSrcweir 		UpdateValues();
1286cdf0e10cSrcweir 	}
1287cdf0e10cSrcweir 
1288cdf0e10cSrcweir }
1289cdf0e10cSrcweir 
SaveArg(sal_uInt16 nEd)1290cdf0e10cSrcweir void FormulaDlg_Impl::SaveArg( sal_uInt16 nEd )
1291cdf0e10cSrcweir {
1292cdf0e10cSrcweir 	if (nEd<nArgs)
1293cdf0e10cSrcweir 	{
1294cdf0e10cSrcweir 		sal_uInt16 i;
1295cdf0e10cSrcweir 		for(i=0;i<=nEd;i++)
1296cdf0e10cSrcweir 		{
1297cdf0e10cSrcweir 			if ( m_aArguments[i].getLength() == 0 )
1298cdf0e10cSrcweir 				m_aArguments[i] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" "));
1299cdf0e10cSrcweir 		}
1300cdf0e10cSrcweir 		if(pParaWin->GetArgument(nEd).Len()!=0)
1301cdf0e10cSrcweir 			m_aArguments[nEd] = pParaWin->GetArgument(nEd);
1302cdf0e10cSrcweir 
1303cdf0e10cSrcweir 		sal_uInt16 nClearPos=nEd+1;
1304cdf0e10cSrcweir 		for(i=nEd+1;i<nArgs;i++)
1305cdf0e10cSrcweir 		{
1306cdf0e10cSrcweir 			if(pParaWin->GetArgument(i).Len()!=0)
1307cdf0e10cSrcweir 			{
1308cdf0e10cSrcweir 				nClearPos=i+1;
1309cdf0e10cSrcweir 			}
1310cdf0e10cSrcweir 		}
1311cdf0e10cSrcweir 
1312cdf0e10cSrcweir 		for(i=nClearPos;i<nArgs;i++)
1313cdf0e10cSrcweir 		{
1314cdf0e10cSrcweir 			m_aArguments[i] = ::rtl::OUString();
1315cdf0e10cSrcweir 		}
1316cdf0e10cSrcweir 	}
1317cdf0e10cSrcweir }
1318cdf0e10cSrcweir 
IMPL_LINK(FormulaDlg_Impl,FxHdl,ParaWin *,pPtr)1319cdf0e10cSrcweir IMPL_LINK( FormulaDlg_Impl, FxHdl, ParaWin*, pPtr )
1320cdf0e10cSrcweir {
1321cdf0e10cSrcweir 	if(pPtr==pParaWin)
1322cdf0e10cSrcweir 	{
1323cdf0e10cSrcweir 		aBtnForward.Enable(sal_True); //@ Damit eine neue Fkt eingegeben werden kann.
1324cdf0e10cSrcweir 		aTabCtrl.SetCurPageId(TP_FUNCTION);
1325cdf0e10cSrcweir 
1326cdf0e10cSrcweir 		String aUndoStr = m_pHelper->getCurrentFormula();		// bevor unten ein ";" eingefuegt wird
1327cdf0e10cSrcweir 		FormEditData* pData = m_pHelper->getFormEditData();
1328cdf0e10cSrcweir 		if (!pData) return 0;
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir 		sal_uInt16 nArgNo = pParaWin->GetActiveLine();
1331cdf0e10cSrcweir 		nEdFocus=nArgNo;
1332cdf0e10cSrcweir 
1333cdf0e10cSrcweir 		SaveArg(nArgNo);
1334cdf0e10cSrcweir 		UpdateSelection();
1335cdf0e10cSrcweir 
1336cdf0e10cSrcweir 		xub_StrLen nFormulaStrPos = pData->GetFStart();
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir 		String aFormula = m_pHelper->getCurrentFormula();
1339cdf0e10cSrcweir 		xub_StrLen n1 = m_aFormulaHelper.GetArgStart( aFormula, nFormulaStrPos, nEdFocus+pData->GetOffset() );
1340cdf0e10cSrcweir 
1341cdf0e10cSrcweir 		pData->SetEdFocus( nEdFocus );
1342cdf0e10cSrcweir 		pData->SaveValues();
1343cdf0e10cSrcweir 		pData->SetMode( (sal_uInt16) FORMULA_FORMDLG_FORMULA );
1344cdf0e10cSrcweir 		pData->SetFStart( n1 );
1345cdf0e10cSrcweir 		pData->SetUndoStr( aUndoStr );
1346cdf0e10cSrcweir 		ClearAllParas();
1347cdf0e10cSrcweir 
1348cdf0e10cSrcweir 		FillDialog(sal_False);
1349cdf0e10cSrcweir 		pFuncPage->SetFocus(); //Da Parawin nicht mehr sichtbar
1350cdf0e10cSrcweir 	}
1351cdf0e10cSrcweir 	return 0;
1352cdf0e10cSrcweir }
1353cdf0e10cSrcweir 
IMPL_LINK(FormulaDlg_Impl,ModifyHdl,ParaWin *,pPtr)1354cdf0e10cSrcweir IMPL_LINK( FormulaDlg_Impl, ModifyHdl, ParaWin*, pPtr )
1355cdf0e10cSrcweir {
1356cdf0e10cSrcweir 	if(pPtr==pParaWin)
1357cdf0e10cSrcweir 	{
1358cdf0e10cSrcweir 		SaveArg(pParaWin->GetActiveLine());
1359cdf0e10cSrcweir 		UpdateValues();
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir 		UpdateSelection();
1362cdf0e10cSrcweir 		CalcStruct(pMEdit->GetText());
1363cdf0e10cSrcweir 	}
1364cdf0e10cSrcweir 	return 0;
1365cdf0e10cSrcweir }
1366cdf0e10cSrcweir 
IMPL_LINK(FormulaDlg_Impl,FormulaHdl,MultiLineEdit *,EMPTYARG)1367cdf0e10cSrcweir IMPL_LINK( FormulaDlg_Impl, FormulaHdl, MultiLineEdit*, EMPTYARG )
1368cdf0e10cSrcweir {
1369cdf0e10cSrcweir 
1370cdf0e10cSrcweir 	FormEditData* pData = m_pHelper->getFormEditData();
1371cdf0e10cSrcweir 	if (!pData) return 0;
1372cdf0e10cSrcweir 
1373cdf0e10cSrcweir 	bEditFlag=sal_True;
1374cdf0e10cSrcweir 	String		aInputFormula=m_pHelper->getCurrentFormula();
1375cdf0e10cSrcweir 	String		aString=pMEdit->GetText();
1376cdf0e10cSrcweir 
1377cdf0e10cSrcweir 	Selection	aSel =pMEdit->GetSelection();
1378cdf0e10cSrcweir 	xub_StrLen nTest=0;
1379cdf0e10cSrcweir 
1380cdf0e10cSrcweir 	if(aString.Len()==0) //falls alles geloescht wurde
1381cdf0e10cSrcweir 	{
1382cdf0e10cSrcweir 		aString +='=';
1383cdf0e10cSrcweir 		pMEdit->SetText(aString);
1384cdf0e10cSrcweir 		aSel .Min()=1;
1385cdf0e10cSrcweir 		aSel .Max()=1;
1386cdf0e10cSrcweir 		pMEdit->SetSelection(aSel);
1387cdf0e10cSrcweir 	}
1388cdf0e10cSrcweir 	else if(aString.GetChar(nTest)!='=') //falls ersetzt wurde;
1389cdf0e10cSrcweir 	{
1390cdf0e10cSrcweir 		aString.Insert( (sal_Unicode)'=', 0 );
1391cdf0e10cSrcweir 		pMEdit->SetText(aString);
1392cdf0e10cSrcweir 		aSel .Min()+=1;
1393cdf0e10cSrcweir 		aSel .Max()+=1;
1394cdf0e10cSrcweir 		pMEdit->SetSelection(aSel);
1395cdf0e10cSrcweir 	}
1396cdf0e10cSrcweir 
1397cdf0e10cSrcweir 
1398cdf0e10cSrcweir 	m_pHelper->setSelection(0, aInputFormula.Len());
1399cdf0e10cSrcweir 	m_pHelper->setCurrentFormula(aString);
1400cdf0e10cSrcweir 	m_pHelper->setSelection((xub_StrLen)aSel.Min(),(xub_StrLen)aSel.Max());
1401cdf0e10cSrcweir 
1402cdf0e10cSrcweir 	xub_StrLen nPos=(xub_StrLen)aSel.Min()-1;
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir 	String aStrResult;
1405cdf0e10cSrcweir 
1406cdf0e10cSrcweir 	if ( CalcValue(m_pHelper->getCurrentFormula(), aStrResult ) )
1407cdf0e10cSrcweir 		aWndFormResult.SetValue( aStrResult );
1408cdf0e10cSrcweir 	else
1409cdf0e10cSrcweir 	{
1410cdf0e10cSrcweir 		aStrResult.Erase();
1411cdf0e10cSrcweir         aWndFormResult.SetValue( aStrResult );
1412cdf0e10cSrcweir 	}
1413cdf0e10cSrcweir 	CalcStruct(aString);
1414cdf0e10cSrcweir 
1415cdf0e10cSrcweir 	nPos=GetFunctionPos(nPos);
1416cdf0e10cSrcweir 
1417cdf0e10cSrcweir 	if(nPos<aSel.Min()-1)
1418cdf0e10cSrcweir 	{
1419cdf0e10cSrcweir 		xub_StrLen nPos1=aString.Search('(',nPos);
1420cdf0e10cSrcweir 		EditNextFunc( sal_False, nPos1);
1421cdf0e10cSrcweir 	}
1422cdf0e10cSrcweir 	else
1423cdf0e10cSrcweir 	{
1424cdf0e10cSrcweir 		ClearAllParas();
1425cdf0e10cSrcweir 	}
1426cdf0e10cSrcweir 
1427cdf0e10cSrcweir 	m_pHelper->setSelection((xub_StrLen)aSel.Min(),(xub_StrLen)aSel.Max());
1428cdf0e10cSrcweir 	bEditFlag=sal_False;
1429cdf0e10cSrcweir 	return 0;
1430cdf0e10cSrcweir }
1431cdf0e10cSrcweir 
IMPL_LINK(FormulaDlg_Impl,FormulaCursorHdl,EditBox *,EMPTYARG)1432cdf0e10cSrcweir IMPL_LINK( FormulaDlg_Impl, FormulaCursorHdl, EditBox*, EMPTYARG )
1433cdf0e10cSrcweir {
1434cdf0e10cSrcweir 	FormEditData* pData = m_pHelper->getFormEditData();
1435cdf0e10cSrcweir 	if (!pData) return 0;
1436cdf0e10cSrcweir 	xub_StrLen nFStart = pData->GetFStart();
1437cdf0e10cSrcweir 
1438cdf0e10cSrcweir 	bEditFlag=sal_True;
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir 	String		aInputFormula=m_pHelper->getCurrentFormula();
1441cdf0e10cSrcweir 	String		aString=pMEdit->GetText();
1442cdf0e10cSrcweir 
1443cdf0e10cSrcweir 	Selection	aSel =pMEdit->GetSelection();
1444cdf0e10cSrcweir 	m_pHelper->setSelection((xub_StrLen)aSel.Min(),(xub_StrLen)aSel.Max());
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir 	if(aSel.Min()==0)
1447cdf0e10cSrcweir 	{
1448cdf0e10cSrcweir 		aSel.Min()=1;
1449cdf0e10cSrcweir 		pMEdit->SetSelection(aSel);
1450cdf0e10cSrcweir 	}
1451cdf0e10cSrcweir 
1452cdf0e10cSrcweir 	if(aSel.Min()!=aString.Len())
1453cdf0e10cSrcweir 	{
1454cdf0e10cSrcweir 		xub_StrLen nPos=(xub_StrLen)aSel.Min();
1455cdf0e10cSrcweir 
1456cdf0e10cSrcweir 		nFStart=GetFunctionPos(nPos - 1);
1457cdf0e10cSrcweir 
1458cdf0e10cSrcweir 		if(nFStart<nPos)
1459cdf0e10cSrcweir 		{
1460cdf0e10cSrcweir 			xub_StrLen nPos1=m_aFormulaHelper.GetFunctionEnd(aString,nFStart);
1461cdf0e10cSrcweir 
1462cdf0e10cSrcweir 			if(nPos1>nPos || nPos1==STRING_NOTFOUND)
1463cdf0e10cSrcweir 			{
1464cdf0e10cSrcweir 				EditThisFunc(nFStart);
1465cdf0e10cSrcweir 			}
1466cdf0e10cSrcweir 			else
1467cdf0e10cSrcweir 			{
1468cdf0e10cSrcweir 				xub_StrLen n=nPos;
1469cdf0e10cSrcweir 				short nCount=1;
1470cdf0e10cSrcweir 				while(n>0)
1471cdf0e10cSrcweir 				{
1472cdf0e10cSrcweir 				   if(aString.GetChar(n)==')')
1473cdf0e10cSrcweir 					   nCount++;
1474cdf0e10cSrcweir 				   else if(aString.GetChar(n)=='(')
1475cdf0e10cSrcweir 					   nCount--;
1476cdf0e10cSrcweir 				   if(nCount==0) break;
1477cdf0e10cSrcweir 				   n--;
1478cdf0e10cSrcweir 				}
1479cdf0e10cSrcweir 				if(nCount==0)
1480cdf0e10cSrcweir 				{
1481cdf0e10cSrcweir 					nFStart=m_aFormulaHelper.GetFunctionStart(aString,n,sal_True);
1482cdf0e10cSrcweir 					EditThisFunc(nFStart);
1483cdf0e10cSrcweir 				}
1484cdf0e10cSrcweir 				else
1485cdf0e10cSrcweir 				{
1486cdf0e10cSrcweir 					ClearAllParas();
1487cdf0e10cSrcweir 				}
1488cdf0e10cSrcweir 			}
1489cdf0e10cSrcweir 		}
1490cdf0e10cSrcweir 		else
1491cdf0e10cSrcweir 		{
1492cdf0e10cSrcweir 			ClearAllParas();
1493cdf0e10cSrcweir 		}
1494cdf0e10cSrcweir 	}
1495cdf0e10cSrcweir 	m_pHelper->setSelection((xub_StrLen)aSel.Min(),(xub_StrLen)aSel.Max());
1496cdf0e10cSrcweir 
1497cdf0e10cSrcweir 	bEditFlag=sal_False;
1498cdf0e10cSrcweir 	return 0;
1499cdf0e10cSrcweir }
1500cdf0e10cSrcweir 
UpdateSelection()1501cdf0e10cSrcweir void FormulaDlg_Impl::UpdateSelection()
1502cdf0e10cSrcweir {
1503cdf0e10cSrcweir 	m_pHelper->setSelection((xub_StrLen)aFuncSel.Min(),(xub_StrLen)aFuncSel.Max());
1504cdf0e10cSrcweir 	m_pHelper->setCurrentFormula( pFuncDesc->getFormula( m_aArguments ) );
1505cdf0e10cSrcweir 	pMEdit->SetText(m_pHelper->getCurrentFormula());
1506cdf0e10cSrcweir 	xub_StrLen PrivStart, PrivEnd;
1507cdf0e10cSrcweir 	m_pHelper->getSelection( PrivStart, PrivEnd);
1508cdf0e10cSrcweir 	aFuncSel.Min()=PrivStart;
1509cdf0e10cSrcweir 	aFuncSel.Max()=PrivEnd;
1510cdf0e10cSrcweir 
1511cdf0e10cSrcweir 	nArgs = pFuncDesc->getSuppressedArgumentCount();
1512cdf0e10cSrcweir 
1513cdf0e10cSrcweir 	String aFormula=pMEdit->GetText();
1514cdf0e10cSrcweir 	sal_Int32 nArgPos=m_aFormulaHelper.GetArgStart( aFormula,PrivStart,0);
1515cdf0e10cSrcweir 
1516cdf0e10cSrcweir 	sal_uInt16 nPos=pParaWin->GetActiveLine();
1517cdf0e10cSrcweir 
1518cdf0e10cSrcweir 	for(sal_uInt16 i=0;i<nPos;i++)
1519cdf0e10cSrcweir 	{
1520cdf0e10cSrcweir 		nArgPos += (m_aArguments[i].getLength() + 1);
1521cdf0e10cSrcweir 	}
1522cdf0e10cSrcweir 	sal_Int32 nLength= m_aArguments[nPos].getLength();
1523cdf0e10cSrcweir 
1524cdf0e10cSrcweir 	Selection aSel(nArgPos,nArgPos+nLength);
1525cdf0e10cSrcweir 	m_pHelper->setSelection((sal_uInt16)nArgPos,(sal_uInt16)(nArgPos+nLength));
1526cdf0e10cSrcweir 	pMEdit->SetSelection(aSel);
1527cdf0e10cSrcweir 	aMEFormula.UpdateOldSel();
1528cdf0e10cSrcweir }
RefInputStartBefore(RefEdit * pEdit,RefButton * pButton)1529cdf0e10cSrcweir ::std::pair<RefButton*,RefEdit*> FormulaDlg_Impl::RefInputStartBefore( RefEdit* pEdit, RefButton* pButton )
1530cdf0e10cSrcweir {
1531cdf0e10cSrcweir     aEdRef.Show();
1532cdf0e10cSrcweir     pTheRefEdit = pEdit;
1533cdf0e10cSrcweir     pTheRefButton = pButton;
1534cdf0e10cSrcweir 
1535cdf0e10cSrcweir     if( pTheRefEdit )
1536cdf0e10cSrcweir     {
1537cdf0e10cSrcweir         aEdRef.SetRefString( pTheRefEdit->GetText() );
1538cdf0e10cSrcweir         aEdRef.SetSelection( pTheRefEdit->GetSelection() );
1539cdf0e10cSrcweir         aEdRef.SetHelpId( pTheRefEdit->GetHelpId() );
1540cdf0e10cSrcweir         aEdRef.SetUniqueId( pTheRefEdit->GetUniqueId() );
1541cdf0e10cSrcweir     }
1542cdf0e10cSrcweir 
1543cdf0e10cSrcweir     aRefBtn.Show( pButton != NULL );
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir     //m_pHelper->RefInputStart( &aEdRef, pButton ? &aRefBtn : NULL );
1546cdf0e10cSrcweir     ::std::pair<RefButton*,RefEdit*> aPair;
1547cdf0e10cSrcweir     aPair.first = pButton ? &aRefBtn : NULL;
1548cdf0e10cSrcweir     aPair.second = &aEdRef;
1549cdf0e10cSrcweir     return aPair;
1550cdf0e10cSrcweir }
RefInputStartAfter(RefEdit *,RefButton *)1551cdf0e10cSrcweir void FormulaDlg_Impl::RefInputStartAfter( RefEdit* /*pEdit*/, RefButton* /*pButton*/ )
1552cdf0e10cSrcweir {
1553cdf0e10cSrcweir     aRefBtn.SetEndImage();
1554cdf0e10cSrcweir 
1555cdf0e10cSrcweir     if( pTheRefEdit )
1556cdf0e10cSrcweir     {
1557cdf0e10cSrcweir         String aStr = aTitle2;
1558cdf0e10cSrcweir         aStr += ' ';
1559cdf0e10cSrcweir         aStr += aFtEditName.GetText();
1560cdf0e10cSrcweir         aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "( " ) );
1561cdf0e10cSrcweir         if( pParaWin->GetActiveLine() > 0 )
1562cdf0e10cSrcweir             aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "...; " ) );
1563cdf0e10cSrcweir         aStr += pParaWin->GetActiveArgName();
1564cdf0e10cSrcweir         if( pParaWin->GetActiveLine() + 1 < nArgs )
1565cdf0e10cSrcweir             aStr.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "; ..." ));
1566cdf0e10cSrcweir         aStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( " )" ) );
1567cdf0e10cSrcweir 
1568cdf0e10cSrcweir         m_pParent->SetText( MnemonicGenerator::EraseAllMnemonicChars( aStr ) );
1569cdf0e10cSrcweir     }
1570cdf0e10cSrcweir }
RefInputDoneAfter(sal_Bool bForced)1571cdf0e10cSrcweir void FormulaDlg_Impl::RefInputDoneAfter( sal_Bool bForced )
1572cdf0e10cSrcweir {
1573cdf0e10cSrcweir     aRefBtn.SetStartImage();
1574cdf0e10cSrcweir     if( bForced || !aRefBtn.IsVisible() )
1575cdf0e10cSrcweir     {
1576cdf0e10cSrcweir         aEdRef.Hide();
1577cdf0e10cSrcweir         aRefBtn.Hide();
1578cdf0e10cSrcweir         if( pTheRefEdit )
1579cdf0e10cSrcweir         {
1580cdf0e10cSrcweir             pTheRefEdit->SetRefString( aEdRef.GetText() );
1581cdf0e10cSrcweir             pTheRefEdit->GrabFocus();
1582cdf0e10cSrcweir 
1583cdf0e10cSrcweir             if( pTheRefButton )
1584cdf0e10cSrcweir                 pTheRefButton->SetStartImage();
1585cdf0e10cSrcweir 
1586cdf0e10cSrcweir             sal_uInt16 nPrivActiv = pParaWin->GetActiveLine();
1587cdf0e10cSrcweir             pParaWin->SetArgument( nPrivActiv, aEdRef.GetText() );
1588cdf0e10cSrcweir             ModifyHdl( pParaWin );
1589cdf0e10cSrcweir             pTheRefEdit = NULL;
1590cdf0e10cSrcweir         }
1591cdf0e10cSrcweir         m_pParent->SetText( aTitle1 );
1592cdf0e10cSrcweir     }
1593cdf0e10cSrcweir }
GetCurrRefEdit()1594cdf0e10cSrcweir RefEdit* FormulaDlg_Impl::GetCurrRefEdit()
1595cdf0e10cSrcweir {
1596cdf0e10cSrcweir     return aEdRef.IsVisible() ? &aEdRef : pParaWin->GetActiveEdit();
1597cdf0e10cSrcweir }
Update()1598cdf0e10cSrcweir void FormulaDlg_Impl::Update()
1599cdf0e10cSrcweir {
1600cdf0e10cSrcweir     FormEditData* pData = m_pHelper->getFormEditData();
1601cdf0e10cSrcweir     const String sExpression = pMEdit->GetText();
1602cdf0e10cSrcweir     aOldFormula = String();
1603cdf0e10cSrcweir     UpdateTokenArray(sExpression);
1604cdf0e10cSrcweir 	FormulaCursorHdl(&aMEFormula);
1605cdf0e10cSrcweir 	CalcStruct(sExpression);
1606cdf0e10cSrcweir 	if(pData->GetMode() == FORMULA_FORMDLG_FORMULA)
1607cdf0e10cSrcweir 		aTabCtrl.SetCurPageId(TP_FUNCTION);
1608cdf0e10cSrcweir 	else
1609cdf0e10cSrcweir 		aTabCtrl.SetCurPageId(TP_STRUCT);
1610cdf0e10cSrcweir 	aBtnMatrix.Check(pData->GetMatrixFlag());
1611cdf0e10cSrcweir 	/*aTimer.SetTimeout(200);
1612cdf0e10cSrcweir 	aTimer.SetTimeoutHdl(LINK( this, FormulaDlg_Impl, UpdateFocusHdl));
1613cdf0e10cSrcweir 	aTimer.Start();*/
1614cdf0e10cSrcweir }
Update(const String & _sExp)1615cdf0e10cSrcweir void FormulaDlg_Impl::Update(const String& _sExp)
1616cdf0e10cSrcweir {
1617cdf0e10cSrcweir     CalcStruct(_sExp);
1618cdf0e10cSrcweir 	FillDialog();
1619cdf0e10cSrcweir 	//aBtnForward.Enable(sal_True); //@New
1620cdf0e10cSrcweir 	FuncSelHdl(NULL);
1621cdf0e10cSrcweir }
SetMeText(const String & _sText)1622cdf0e10cSrcweir void FormulaDlg_Impl::SetMeText(const String& _sText)
1623cdf0e10cSrcweir {
1624cdf0e10cSrcweir     FormEditData* pData = m_pHelper->getFormEditData();
1625cdf0e10cSrcweir     pMEdit->SetText(_sText);
1626cdf0e10cSrcweir 	pMEdit->SetSelection( pData->GetSelection());
1627cdf0e10cSrcweir 	aMEFormula.UpdateOldSel();
1628cdf0e10cSrcweir }
SetMeText(const String & _sText,xub_StrLen PrivStart,xub_StrLen PrivEnd,sal_Bool bMatrix,sal_Bool _bSelect,sal_Bool _bUpdate)1629cdf0e10cSrcweir FormulaDlgMode FormulaDlg_Impl::SetMeText(const String& _sText,xub_StrLen PrivStart, xub_StrLen PrivEnd,sal_Bool bMatrix,sal_Bool _bSelect,sal_Bool _bUpdate)
1630cdf0e10cSrcweir {
1631cdf0e10cSrcweir     FormulaDlgMode eMode = FORMULA_FORMDLG_FORMULA;
1632cdf0e10cSrcweir     if(!bEditFlag)
1633cdf0e10cSrcweir 		pMEdit->SetText(_sText);
1634cdf0e10cSrcweir 
1635cdf0e10cSrcweir 	if ( _bSelect || !bEditFlag )
1636cdf0e10cSrcweir 	    pMEdit->SetSelection( Selection(PrivStart, PrivEnd));
1637cdf0e10cSrcweir     if ( _bUpdate )
1638cdf0e10cSrcweir     {
1639cdf0e10cSrcweir 	    aMEFormula.UpdateOldSel();
1640cdf0e10cSrcweir 	    pMEdit->Invalidate();
1641cdf0e10cSrcweir 	    m_pHelper->showReference(pMEdit->GetSelected());
1642cdf0e10cSrcweir 	    eMode = FORMULA_FORMDLG_EDIT;
1643cdf0e10cSrcweir 
1644cdf0e10cSrcweir 	    aBtnMatrix.Check( bMatrix );
1645cdf0e10cSrcweir     } // if ( _bUpdate )
1646cdf0e10cSrcweir     return eMode;
1647cdf0e10cSrcweir }
CheckMatrix(String & aFormula)1648cdf0e10cSrcweir sal_Bool FormulaDlg_Impl::CheckMatrix(String& aFormula)
1649cdf0e10cSrcweir {
1650cdf0e10cSrcweir     pMEdit->GrabFocus();
1651cdf0e10cSrcweir 	xub_StrLen nLen = aFormula.Len();
1652cdf0e10cSrcweir 	sal_Bool bMatrix =  nLen > 3 					// Matrix-Formel ?
1653cdf0e10cSrcweir 			&& aFormula.GetChar(0) == '{'
1654cdf0e10cSrcweir 			&& aFormula.GetChar(1) == '='
1655cdf0e10cSrcweir 			&& aFormula.GetChar(nLen-1) == '}';
1656cdf0e10cSrcweir 	if ( bMatrix )
1657cdf0e10cSrcweir 	{
1658cdf0e10cSrcweir 		aFormula.Erase( 0, 1 );
1659cdf0e10cSrcweir 		aFormula.Erase( aFormula.Len()-1, 1);
1660cdf0e10cSrcweir 		aBtnMatrix.Check( bMatrix );
1661cdf0e10cSrcweir 		aBtnMatrix.Disable();
1662cdf0e10cSrcweir 	} // if ( bMatrix )
1663cdf0e10cSrcweir 
1664cdf0e10cSrcweir     aTabCtrl.SetCurPageId(TP_STRUCT);
1665cdf0e10cSrcweir     return bMatrix;
1666cdf0e10cSrcweir }
IMPL_LINK(FormulaDlg_Impl,StructSelHdl,StructPage *,pStruP)1667cdf0e10cSrcweir IMPL_LINK( FormulaDlg_Impl, StructSelHdl, StructPage*, pStruP )
1668cdf0e10cSrcweir {
1669cdf0e10cSrcweir 	bStructUpdate=sal_False;
1670cdf0e10cSrcweir 	if(pStructPage->IsVisible())	aBtnForward.Enable(sal_False); //@New
1671cdf0e10cSrcweir 
1672cdf0e10cSrcweir 	if(pStructPage==pStruP)
1673cdf0e10cSrcweir 	{
1674cdf0e10cSrcweir         /// TODO
1675cdf0e10cSrcweir 		//ScToken* pSelToken = pStructPage->GetSelectedToken();
1676cdf0e10cSrcweir   //      ScToken* pOrigToken = ((pSelToken && pSelToken->GetType() == svFAP) ?
1677cdf0e10cSrcweir   //              pSelToken->GetFAPOrigToken() : pSelToken);
1678cdf0e10cSrcweir 		//xub_StrLen nTokPos=1;
1679cdf0e10cSrcweir 
1680cdf0e10cSrcweir 		//if(pScTokA!=NULL)
1681cdf0e10cSrcweir 		//{
1682cdf0e10cSrcweir 		//	ScToken* pToken = pScTokA->First();
1683cdf0e10cSrcweir 
1684cdf0e10cSrcweir 		//	while(pToken!=NULL)
1685cdf0e10cSrcweir 		//	{
1686cdf0e10cSrcweir 		//		String aString;
1687cdf0e10cSrcweir   //              if ( pToken == pOrigToken )
1688cdf0e10cSrcweir   //                  break;
1689cdf0e10cSrcweir 		//		pComp->CreateStringFromToken( aString,pToken);
1690cdf0e10cSrcweir   //              nTokPos = sal::static_int_cast<xub_StrLen>( nTokPos + aString.Len() );
1691cdf0e10cSrcweir 		//		pToken=pScTokA->Next();
1692cdf0e10cSrcweir 		//	}
1693cdf0e10cSrcweir 		//	EditThisFunc(nTokPos);
1694cdf0e10cSrcweir 		//}
1695cdf0e10cSrcweir 
1696cdf0e10cSrcweir 		//if( pOrigToken )
1697cdf0e10cSrcweir 		//{
1698cdf0e10cSrcweir 		//	String aStr;
1699cdf0e10cSrcweir 		//	pComp->CreateStringFromToken( aStr, pOrigToken );
1700cdf0e10cSrcweir 		//	String aEntryTxt=pStructPage->GetSelectedEntryText();
1701cdf0e10cSrcweir 
1702cdf0e10cSrcweir 		//	if(aEntryTxt!=aStr)
1703cdf0e10cSrcweir 		//		ShowReference(aEntryTxt);
1704cdf0e10cSrcweir 		//}
1705cdf0e10cSrcweir 
1706cdf0e10cSrcweir 	}
1707cdf0e10cSrcweir 	bStructUpdate=sal_True;
1708cdf0e10cSrcweir 	return 0;
1709cdf0e10cSrcweir }
IMPL_LINK(FormulaDlg_Impl,MatrixHdl,CheckBox *,EMPTYARG)1710cdf0e10cSrcweir IMPL_LINK( FormulaDlg_Impl, MatrixHdl, CheckBox *, EMPTYARG )
1711cdf0e10cSrcweir {
1712cdf0e10cSrcweir 	bUserMatrixFlag=sal_True;
1713cdf0e10cSrcweir 	return 0;
1714cdf0e10cSrcweir }
1715cdf0e10cSrcweir 
IMPL_LINK(FormulaDlg_Impl,FuncSelHdl,FuncPage *,EMPTYARG)1716cdf0e10cSrcweir IMPL_LINK( FormulaDlg_Impl, FuncSelHdl, FuncPage*, EMPTYARG )
1717cdf0e10cSrcweir {
1718cdf0e10cSrcweir 	sal_uInt16 nCat = pFuncPage->GetCategory();
1719cdf0e10cSrcweir 	if ( nCat == LISTBOX_ENTRY_NOTFOUND ) nCat = 0;
1720cdf0e10cSrcweir 	sal_uInt16 nFunc = pFuncPage->GetFunction();
1721cdf0e10cSrcweir 	if ( nFunc == LISTBOX_ENTRY_NOTFOUND ) nFunc = 0;
1722cdf0e10cSrcweir 
1723cdf0e10cSrcweir 	if (   (pFuncPage->GetFunctionEntryCount() > 0)
1724cdf0e10cSrcweir 		&& (pFuncPage->GetFunction() != LISTBOX_ENTRY_NOTFOUND) )
1725cdf0e10cSrcweir 	{
1726cdf0e10cSrcweir 		const IFunctionDescription* pDesc =pFuncPage->GetFuncDesc( pFuncPage->GetFunction() );
1727cdf0e10cSrcweir 
1728cdf0e10cSrcweir 		if(pDesc!=pFuncDesc) aBtnForward.Enable(sal_True); //new
1729cdf0e10cSrcweir 
1730cdf0e10cSrcweir 		if (pDesc)
1731cdf0e10cSrcweir 		{
1732cdf0e10cSrcweir             pDesc->initArgumentInfo();      // full argument info is needed
1733cdf0e10cSrcweir 
1734cdf0e10cSrcweir 			String aSig = pDesc->getSignature();
1735cdf0e10cSrcweir 			aFtHeadLine.SetText( pDesc->getFunctionName() );
1736cdf0e10cSrcweir 			aFtFuncName.SetText( aSig );
1737cdf0e10cSrcweir 			aFtFuncDesc.SetText( pDesc->getDescription() );
1738cdf0e10cSrcweir 		}
1739cdf0e10cSrcweir 	}
1740cdf0e10cSrcweir 	else
1741cdf0e10cSrcweir 	{
1742cdf0e10cSrcweir 		aFtHeadLine.SetText( String() );
1743cdf0e10cSrcweir 		aFtFuncName.SetText( String() );
1744cdf0e10cSrcweir 		aFtFuncDesc.SetText( String() );
1745cdf0e10cSrcweir 	}
1746cdf0e10cSrcweir 	return 0;
1747cdf0e10cSrcweir }
1748cdf0e10cSrcweir 
UpdateParaWin(const Selection & _rSelection,const String & _sRefStr)1749cdf0e10cSrcweir void FormulaDlg_Impl::UpdateParaWin(const Selection& _rSelection,const String& _sRefStr)
1750cdf0e10cSrcweir {
1751cdf0e10cSrcweir     Selection theSel = _rSelection;
1752cdf0e10cSrcweir     aEdRef.ReplaceSelected( _sRefStr );
1753cdf0e10cSrcweir 	theSel.Max() = theSel.Min() + _sRefStr.Len();
1754cdf0e10cSrcweir 	aEdRef.SetSelection( theSel );
1755cdf0e10cSrcweir 
1756cdf0e10cSrcweir 	//-------------------------------------
1757cdf0e10cSrcweir 	// Manuelles Update der Ergebnisfelder:
1758cdf0e10cSrcweir 	//-------------------------------------
1759cdf0e10cSrcweir 	sal_uInt16 nPrivActiv = pParaWin->GetActiveLine();
1760cdf0e10cSrcweir 	pParaWin->SetArgument(nPrivActiv,aEdRef.GetText());
1761cdf0e10cSrcweir 	pParaWin->UpdateParas();
1762cdf0e10cSrcweir 
1763cdf0e10cSrcweir     Edit* pEd = GetCurrRefEdit();
1764cdf0e10cSrcweir 	if( pEd != NULL )
1765cdf0e10cSrcweir         pEd->SetSelection( theSel );
1766cdf0e10cSrcweir 
1767cdf0e10cSrcweir 	pParaWin->SetRefMode(sal_False);
1768cdf0e10cSrcweir }
UpdateParaWin(Selection & _rSelection)1769cdf0e10cSrcweir sal_Bool FormulaDlg_Impl::UpdateParaWin(Selection& _rSelection)
1770cdf0e10cSrcweir {
1771cdf0e10cSrcweir     pParaWin->SetRefMode(sal_True);
1772cdf0e10cSrcweir 
1773cdf0e10cSrcweir 	String		aStrEd;
1774cdf0e10cSrcweir     Edit* pEd = GetCurrRefEdit();
1775cdf0e10cSrcweir 	if(pEd!=NULL && pTheRefEdit==NULL)
1776cdf0e10cSrcweir 	{
1777cdf0e10cSrcweir 		_rSelection=pEd->GetSelection();
1778cdf0e10cSrcweir         _rSelection.Justify();
1779cdf0e10cSrcweir 		aStrEd=pEd->GetText();
1780cdf0e10cSrcweir 		aEdRef.SetRefString(aStrEd);
1781cdf0e10cSrcweir 		aEdRef.SetSelection( _rSelection );
1782cdf0e10cSrcweir 	}
1783cdf0e10cSrcweir 	else
1784cdf0e10cSrcweir 	{
1785cdf0e10cSrcweir 		_rSelection=aEdRef.GetSelection();
1786cdf0e10cSrcweir         _rSelection.Justify();
1787cdf0e10cSrcweir 		aStrEd= aEdRef.GetText();
1788cdf0e10cSrcweir 	}
1789cdf0e10cSrcweir     return pTheRefEdit == NULL;
1790cdf0e10cSrcweir }
FindFocusWin(Window * pWin)1791cdf0e10cSrcweir rtl::OString FormulaDlg_Impl::FindFocusWin(Window *pWin)
1792cdf0e10cSrcweir {
1793cdf0e10cSrcweir     rtl::OString aUniqueId;
1794cdf0e10cSrcweir 	if(pWin->HasFocus())
1795cdf0e10cSrcweir 	{
1796cdf0e10cSrcweir 		aUniqueId=pWin->GetUniqueId();
1797cdf0e10cSrcweir 		if(aUniqueId.getLength()==0)
1798cdf0e10cSrcweir 		{
1799cdf0e10cSrcweir 			Window* pParent=pWin->GetParent();
1800cdf0e10cSrcweir 			while(pParent!=NULL)
1801cdf0e10cSrcweir 			{
1802cdf0e10cSrcweir 				aUniqueId=pParent->GetUniqueId();
1803cdf0e10cSrcweir 
1804cdf0e10cSrcweir 				if(aUniqueId.getLength()!=0) break;
1805cdf0e10cSrcweir 
1806cdf0e10cSrcweir 				pParent=pParent->GetParent();
1807cdf0e10cSrcweir 			}
1808cdf0e10cSrcweir 		}
1809cdf0e10cSrcweir 	}
1810cdf0e10cSrcweir 	else
1811cdf0e10cSrcweir 	{
1812cdf0e10cSrcweir 		sal_uInt16 nCount=pWin->GetChildCount();
1813cdf0e10cSrcweir 
1814cdf0e10cSrcweir 		for(sal_uInt16 i=0;i<nCount;i++)
1815cdf0e10cSrcweir 		{
1816cdf0e10cSrcweir 			Window* pChild=pWin->GetChild(i);
1817cdf0e10cSrcweir 			aUniqueId=FindFocusWin(pChild);
1818cdf0e10cSrcweir 			if(aUniqueId.getLength()>0) break;
1819cdf0e10cSrcweir 		}
1820cdf0e10cSrcweir 	}
1821cdf0e10cSrcweir 	return aUniqueId;
1822cdf0e10cSrcweir }
1823cdf0e10cSrcweir 
SetEdSelection()1824cdf0e10cSrcweir void FormulaDlg_Impl::SetEdSelection()
1825cdf0e10cSrcweir {
1826cdf0e10cSrcweir     Edit* pEd = GetCurrRefEdit()/*aScParaWin.GetActiveEdit()*/;
1827cdf0e10cSrcweir     if( pEd )
1828cdf0e10cSrcweir 	{
1829cdf0e10cSrcweir 		Selection theSel = aEdRef.GetSelection();
1830cdf0e10cSrcweir 		//	Edit may have the focus -> call ModifyHdl in addition
1831cdf0e10cSrcweir 		//	to what's happening in GetFocus
1832cdf0e10cSrcweir 		pEd->GetModifyHdl().Call(pEd);
1833cdf0e10cSrcweir 		pEd->GrabFocus();
1834cdf0e10cSrcweir 		pEd->SetSelection(theSel);
1835cdf0e10cSrcweir 	} // if( pEd )
1836cdf0e10cSrcweir }
1837cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetFormulaHelper() const1838cdf0e10cSrcweir const FormulaHelper& FormulaDlg_Impl::GetFormulaHelper()  const
1839cdf0e10cSrcweir {
1840cdf0e10cSrcweir     return m_aFormulaHelper;
1841cdf0e10cSrcweir }
1842cdf0e10cSrcweir //============================================================================
FormulaModalDialog(Window * pParent,bool _bSupportFunctionResult,bool _bSupportResult,bool _bSupportMatrix,IFormulaEditorHelper * _pHelper,IFunctionManager * _pFunctionMgr,IControlReferenceHandler * _pDlg)1843cdf0e10cSrcweir FormulaModalDialog::FormulaModalDialog( Window* pParent
1844cdf0e10cSrcweir                                             , bool _bSupportFunctionResult
1845cdf0e10cSrcweir                                             , bool _bSupportResult
1846cdf0e10cSrcweir                                             , bool _bSupportMatrix
1847cdf0e10cSrcweir                                             , IFormulaEditorHelper* _pHelper
1848cdf0e10cSrcweir                                             , IFunctionManager* _pFunctionMgr
1849cdf0e10cSrcweir                                             , IControlReferenceHandler* _pDlg ) :
1850cdf0e10cSrcweir 		ModalDialog( pParent, ModuleRes(RID_FORMULADLG_FORMULA_MODAL) ),
1851cdf0e10cSrcweir         m_pImpl( new FormulaDlg_Impl(this,_bSupportFunctionResult
1852cdf0e10cSrcweir                                             , _bSupportResult
1853cdf0e10cSrcweir                                             , _bSupportMatrix
1854cdf0e10cSrcweir                                             ,_pHelper,_pFunctionMgr,_pDlg))
1855cdf0e10cSrcweir {
1856cdf0e10cSrcweir     FreeResource();
1857cdf0e10cSrcweir 	SetText(m_pImpl->aTitle1);
1858cdf0e10cSrcweir }
~FormulaModalDialog()1859cdf0e10cSrcweir FormulaModalDialog::~FormulaModalDialog()
1860cdf0e10cSrcweir {
1861cdf0e10cSrcweir }
1862cdf0e10cSrcweir // -----------------------------------------------------------------------------
Update(const String & _sExp)1863cdf0e10cSrcweir void FormulaModalDialog::Update(const String& _sExp)
1864cdf0e10cSrcweir {
1865cdf0e10cSrcweir     m_pImpl->Update(_sExp);
1866cdf0e10cSrcweir }
1867cdf0e10cSrcweir 
1868cdf0e10cSrcweir // -----------------------------------------------------------------------------
SetMeText(const String & _sText)1869cdf0e10cSrcweir void FormulaModalDialog::SetMeText(const String& _sText)
1870cdf0e10cSrcweir {
1871cdf0e10cSrcweir     m_pImpl->SetMeText(_sText);
1872cdf0e10cSrcweir }
1873cdf0e10cSrcweir 
1874cdf0e10cSrcweir // -----------------------------------------------------------------------------
SetMeText(const String & _sText,xub_StrLen PrivStart,xub_StrLen PrivEnd,sal_Bool bMatrix,sal_Bool _bSelect,sal_Bool _bUpdate)1875cdf0e10cSrcweir FormulaDlgMode FormulaModalDialog::SetMeText(const String& _sText,xub_StrLen PrivStart, xub_StrLen PrivEnd,sal_Bool bMatrix,sal_Bool _bSelect,sal_Bool _bUpdate)
1876cdf0e10cSrcweir {
1877cdf0e10cSrcweir     return m_pImpl->SetMeText(_sText,PrivStart, PrivEnd,bMatrix,_bSelect,_bUpdate);
1878cdf0e10cSrcweir }
1879cdf0e10cSrcweir // -----------------------------------------------------------------------------
CheckMatrix()1880cdf0e10cSrcweir void FormulaModalDialog::CheckMatrix()
1881cdf0e10cSrcweir {
1882cdf0e10cSrcweir     m_pImpl->aBtnMatrix.Check();
1883cdf0e10cSrcweir }
1884cdf0e10cSrcweir // -----------------------------------------------------------------------------
CheckMatrix(String & aFormula)1885cdf0e10cSrcweir sal_Bool FormulaModalDialog::CheckMatrix(String& aFormula)
1886cdf0e10cSrcweir {
1887cdf0e10cSrcweir     return m_pImpl->CheckMatrix(aFormula);
1888cdf0e10cSrcweir }
1889cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetMeText() const1890cdf0e10cSrcweir String FormulaModalDialog::GetMeText() const
1891cdf0e10cSrcweir {
1892cdf0e10cSrcweir     return m_pImpl->pMEdit->GetText();
1893cdf0e10cSrcweir }
1894cdf0e10cSrcweir // -----------------------------------------------------------------------------
Update()1895cdf0e10cSrcweir void FormulaModalDialog::Update()
1896cdf0e10cSrcweir {
1897cdf0e10cSrcweir     m_pImpl->Update();
1898cdf0e10cSrcweir }
1899cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetFormulaHelper() const1900cdf0e10cSrcweir const FormulaHelper& FormulaModalDialog::GetFormulaHelper() const
1901cdf0e10cSrcweir {
1902cdf0e10cSrcweir     return m_pImpl->GetFormulaHelper();
1903cdf0e10cSrcweir }
1904cdf0e10cSrcweir // -----------------------------------------------------------------------------
isUserMatrix() const1905cdf0e10cSrcweir sal_Bool FormulaModalDialog::isUserMatrix() const
1906cdf0e10cSrcweir {
1907cdf0e10cSrcweir     return m_pImpl->bUserMatrixFlag;
1908cdf0e10cSrcweir }
DoEnter(sal_Bool _bOk)1909cdf0e10cSrcweir void FormulaModalDialog::DoEnter(sal_Bool _bOk)
1910cdf0e10cSrcweir {
1911cdf0e10cSrcweir     m_pImpl->DoEnter(_bOk);
1912cdf0e10cSrcweir }
RefInputStartBefore(RefEdit * pEdit,RefButton * pButton)1913cdf0e10cSrcweir ::std::pair<RefButton*,RefEdit*> FormulaModalDialog::RefInputStartBefore( RefEdit* pEdit, RefButton* pButton )
1914cdf0e10cSrcweir {
1915cdf0e10cSrcweir     return m_pImpl->RefInputStartBefore( pEdit, pButton );
1916cdf0e10cSrcweir }
RefInputStartAfter(RefEdit * pEdit,RefButton * pButton)1917cdf0e10cSrcweir void FormulaModalDialog::RefInputStartAfter( RefEdit* pEdit, RefButton* pButton )
1918cdf0e10cSrcweir {
1919cdf0e10cSrcweir     m_pImpl->RefInputStartAfter( pEdit, pButton );
1920cdf0e10cSrcweir }
RefInputDoneAfter(sal_Bool bForced)1921cdf0e10cSrcweir void FormulaModalDialog::RefInputDoneAfter( sal_Bool bForced )
1922cdf0e10cSrcweir {
1923cdf0e10cSrcweir     m_pImpl->RefInputDoneAfter( bForced );
1924cdf0e10cSrcweir }
1925cdf0e10cSrcweir 
FindFocusWin(Window * pWin)1926cdf0e10cSrcweir rtl::OString FormulaModalDialog::FindFocusWin(Window *pWin)
1927cdf0e10cSrcweir {
1928cdf0e10cSrcweir     return m_pImpl->FindFocusWin( pWin );
1929cdf0e10cSrcweir }
1930cdf0e10cSrcweir 
SetFocusWin(Window * pWin,const rtl::OString & nUniqueId)1931cdf0e10cSrcweir void FormulaModalDialog::SetFocusWin(Window *pWin,const rtl::OString& nUniqueId)
1932cdf0e10cSrcweir {
1933cdf0e10cSrcweir 	if(pWin->GetUniqueId()==nUniqueId)
1934cdf0e10cSrcweir 	{
1935cdf0e10cSrcweir 		pWin->GrabFocus();
1936cdf0e10cSrcweir 	}
1937cdf0e10cSrcweir 	else
1938cdf0e10cSrcweir 	{
1939cdf0e10cSrcweir 		sal_uInt16 nCount=pWin->GetChildCount();
1940cdf0e10cSrcweir 
1941cdf0e10cSrcweir 		for(sal_uInt16 i=0;i<nCount;i++)
1942cdf0e10cSrcweir 		{
1943cdf0e10cSrcweir 			Window* pChild=pWin->GetChild(i);
1944cdf0e10cSrcweir 			SetFocusWin(pChild,nUniqueId);
1945cdf0e10cSrcweir 		}
1946cdf0e10cSrcweir 	}
1947cdf0e10cSrcweir }
1948cdf0e10cSrcweir 
1949cdf0e10cSrcweir 
PreNotify(NotifyEvent & rNEvt)1950cdf0e10cSrcweir long FormulaModalDialog::PreNotify( NotifyEvent& rNEvt )
1951cdf0e10cSrcweir {
1952cdf0e10cSrcweir     m_pImpl->PreNotify( rNEvt );
1953cdf0e10cSrcweir 
1954cdf0e10cSrcweir 	return ModalDialog::PreNotify(rNEvt);
1955cdf0e10cSrcweir }
1956cdf0e10cSrcweir 
HighlightFunctionParas(const String & aFormula)1957cdf0e10cSrcweir void FormulaModalDialog::HighlightFunctionParas(const String& aFormula)
1958cdf0e10cSrcweir {
1959cdf0e10cSrcweir 	m_pImpl->m_pHelper->showReference(aFormula);
1960cdf0e10cSrcweir }
1961cdf0e10cSrcweir 
disableOk()1962cdf0e10cSrcweir void FormulaModalDialog::disableOk()
1963cdf0e10cSrcweir {
1964cdf0e10cSrcweir     m_pImpl->aBtnEnd.Disable();
1965cdf0e10cSrcweir }
1966cdf0e10cSrcweir // -----------------------------------------------------------------------------
getCurrentFunctionDescription() const1967cdf0e10cSrcweir const IFunctionDescription*	FormulaModalDialog::getCurrentFunctionDescription() const
1968cdf0e10cSrcweir {
1969cdf0e10cSrcweir     OSL_VERIFY(!m_pImpl->pFuncDesc || m_pImpl->pFuncDesc->getSuppressedArgumentCount() == m_pImpl->nArgs);
1970cdf0e10cSrcweir     return m_pImpl->pFuncDesc;
1971cdf0e10cSrcweir }
1972cdf0e10cSrcweir // -----------------------------------------------------------------------------
UpdateParaWin(const Selection & _rSelection,const String & _sRefStr)1973cdf0e10cSrcweir void FormulaModalDialog::UpdateParaWin(const Selection& _rSelection,const String& _sRefStr)
1974cdf0e10cSrcweir {
1975cdf0e10cSrcweir     m_pImpl->UpdateParaWin(_rSelection,_sRefStr);
1976cdf0e10cSrcweir }
UpdateParaWin(Selection & _rSelection)1977cdf0e10cSrcweir sal_Bool FormulaModalDialog::UpdateParaWin(Selection& _rSelection)
1978cdf0e10cSrcweir {
1979cdf0e10cSrcweir     return m_pImpl->UpdateParaWin(_rSelection);
1980cdf0e10cSrcweir }
1981cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetActiveEdit()1982cdf0e10cSrcweir RefEdit*	FormulaModalDialog::GetActiveEdit()
1983cdf0e10cSrcweir {
1984cdf0e10cSrcweir     return m_pImpl->pParaWin->GetActiveEdit();
1985cdf0e10cSrcweir }
1986cdf0e10cSrcweir // -----------------------------------------------------------------------------
SetEdSelection()1987cdf0e10cSrcweir void FormulaModalDialog::SetEdSelection()
1988cdf0e10cSrcweir {
1989cdf0e10cSrcweir     m_pImpl->SetEdSelection();
1990cdf0e10cSrcweir }
1991cdf0e10cSrcweir 
1992cdf0e10cSrcweir //	--------------------------------------------------------------------------
1993cdf0e10cSrcweir //		Initialisierung / gemeinsaME Funktionen  fuer Dialog
1994cdf0e10cSrcweir //	--------------------------------------------------------------------------
FormulaDlg(SfxBindings * pB,SfxChildWindow * pCW,Window * pParent,bool _bSupportFunctionResult,bool _bSupportResult,bool _bSupportMatrix,IFormulaEditorHelper * _pHelper,IFunctionManager * _pFunctionMgr,IControlReferenceHandler * _pDlg)1995cdf0e10cSrcweir FormulaDlg::FormulaDlg( SfxBindings* pB, SfxChildWindow* pCW,
1996cdf0e10cSrcweir 							 Window* pParent
1997cdf0e10cSrcweir                             , bool _bSupportFunctionResult
1998cdf0e10cSrcweir                             , bool _bSupportResult
1999cdf0e10cSrcweir                             , bool _bSupportMatrix
2000cdf0e10cSrcweir                             , IFormulaEditorHelper* _pHelper,IFunctionManager* _pFunctionMgr,IControlReferenceHandler* _pDlg ) :
2001cdf0e10cSrcweir 		SfxModelessDialog( pB, pCW, pParent, ModuleRes(RID_FORMULADLG_FORMULA) ),
2002cdf0e10cSrcweir         m_pImpl( new FormulaDlg_Impl(this, _bSupportFunctionResult
2003cdf0e10cSrcweir                                             , _bSupportResult
2004cdf0e10cSrcweir                                             , _bSupportMatrix
2005cdf0e10cSrcweir                                             ,_pHelper,_pFunctionMgr,_pDlg))
2006cdf0e10cSrcweir {
2007cdf0e10cSrcweir     FreeResource();
2008cdf0e10cSrcweir     if(!GetHelpId().getLength())				//Hack, da im SfxModelessDialog die HelpId
2009cdf0e10cSrcweir 		SetHelpId(GetUniqueId());	//fuer einen ModelessDialog entfernt und
2010cdf0e10cSrcweir 									//in eine UniqueId gewandelt wird, machen
2011cdf0e10cSrcweir 									//wir das an dieser Stelle rueckgaengig.
2012cdf0e10cSrcweir 	SetText(m_pImpl->aTitle1);
2013cdf0e10cSrcweir }
2014cdf0e10cSrcweir 
~FormulaDlg()2015cdf0e10cSrcweir FormulaDlg::~FormulaDlg()
2016cdf0e10cSrcweir {
2017cdf0e10cSrcweir }
2018cdf0e10cSrcweir // -----------------------------------------------------------------------------
Update(const String & _sExp)2019cdf0e10cSrcweir void FormulaDlg::Update(const String& _sExp)
2020cdf0e10cSrcweir {
2021cdf0e10cSrcweir     m_pImpl->Update(_sExp);
2022cdf0e10cSrcweir }
2023cdf0e10cSrcweir 
2024cdf0e10cSrcweir // -----------------------------------------------------------------------------
SetMeText(const String & _sText)2025cdf0e10cSrcweir void FormulaDlg::SetMeText(const String& _sText)
2026cdf0e10cSrcweir {
2027cdf0e10cSrcweir     m_pImpl->SetMeText(_sText);
2028cdf0e10cSrcweir }
2029cdf0e10cSrcweir 
2030cdf0e10cSrcweir // -----------------------------------------------------------------------------
SetMeText(const String & _sText,xub_StrLen PrivStart,xub_StrLen PrivEnd,sal_Bool bMatrix,sal_Bool _bSelect,sal_Bool _bUpdate)2031cdf0e10cSrcweir FormulaDlgMode FormulaDlg::SetMeText(const String& _sText,xub_StrLen PrivStart, xub_StrLen PrivEnd,sal_Bool bMatrix,sal_Bool _bSelect,sal_Bool _bUpdate)
2032cdf0e10cSrcweir {
2033cdf0e10cSrcweir     return m_pImpl->SetMeText(_sText,PrivStart, PrivEnd,bMatrix,_bSelect,_bUpdate);
2034cdf0e10cSrcweir }
2035cdf0e10cSrcweir // -----------------------------------------------------------------------------
CheckMatrix()2036cdf0e10cSrcweir void FormulaDlg::CheckMatrix()
2037cdf0e10cSrcweir {
2038cdf0e10cSrcweir     m_pImpl->aBtnMatrix.Check();
2039cdf0e10cSrcweir }
2040cdf0e10cSrcweir // -----------------------------------------------------------------------------
CheckMatrix(String & aFormula)2041cdf0e10cSrcweir sal_Bool FormulaDlg::CheckMatrix(String& aFormula)
2042cdf0e10cSrcweir {
2043cdf0e10cSrcweir     return m_pImpl->CheckMatrix(aFormula);
2044cdf0e10cSrcweir }
2045cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetMeText() const2046cdf0e10cSrcweir String FormulaDlg::GetMeText() const
2047cdf0e10cSrcweir {
2048cdf0e10cSrcweir     return m_pImpl->pMEdit->GetText();
2049cdf0e10cSrcweir }
2050cdf0e10cSrcweir // -----------------------------------------------------------------------------
Update()2051cdf0e10cSrcweir void FormulaDlg::Update()
2052cdf0e10cSrcweir {
2053cdf0e10cSrcweir     m_pImpl->Update();
2054cdf0e10cSrcweir     m_pImpl->aTimer.SetTimeout(200);
2055cdf0e10cSrcweir 	m_pImpl->aTimer.SetTimeoutHdl(LINK( this, FormulaDlg, UpdateFocusHdl));
2056cdf0e10cSrcweir 	m_pImpl->aTimer.Start();
2057cdf0e10cSrcweir }
2058cdf0e10cSrcweir 
2059cdf0e10cSrcweir // -----------------------------------------------------------------------------
isUserMatrix() const2060cdf0e10cSrcweir sal_Bool FormulaDlg::isUserMatrix() const
2061cdf0e10cSrcweir {
2062cdf0e10cSrcweir     return m_pImpl->bUserMatrixFlag;
2063cdf0e10cSrcweir }
DoEnter(sal_Bool _bOk)2064cdf0e10cSrcweir void FormulaDlg::DoEnter(sal_Bool _bOk)
2065cdf0e10cSrcweir {
2066cdf0e10cSrcweir     m_pImpl->DoEnter(_bOk);
2067cdf0e10cSrcweir }
RefInputStartBefore(RefEdit * pEdit,RefButton * pButton)2068cdf0e10cSrcweir ::std::pair<RefButton*,RefEdit*> FormulaDlg::RefInputStartBefore( RefEdit* pEdit, RefButton* pButton )
2069cdf0e10cSrcweir {
2070cdf0e10cSrcweir     return m_pImpl->RefInputStartBefore( pEdit, pButton );
2071cdf0e10cSrcweir }
RefInputStartAfter(RefEdit * pEdit,RefButton * pButton)2072cdf0e10cSrcweir void FormulaDlg::RefInputStartAfter( RefEdit* pEdit, RefButton* pButton )
2073cdf0e10cSrcweir {
2074cdf0e10cSrcweir     m_pImpl->RefInputStartAfter( pEdit, pButton );
2075cdf0e10cSrcweir }
RefInputDoneAfter(sal_Bool bForced)2076cdf0e10cSrcweir void FormulaDlg::RefInputDoneAfter( sal_Bool bForced )
2077cdf0e10cSrcweir {
2078cdf0e10cSrcweir     m_pImpl->RefInputDoneAfter( bForced );
2079cdf0e10cSrcweir }
2080cdf0e10cSrcweir 
FindFocusWin(Window * pWin)2081cdf0e10cSrcweir rtl::OString FormulaDlg::FindFocusWin(Window *pWin)
2082cdf0e10cSrcweir {
2083cdf0e10cSrcweir     return m_pImpl->FindFocusWin( pWin );
2084cdf0e10cSrcweir }
2085cdf0e10cSrcweir 
SetFocusWin(Window * pWin,const rtl::OString & nUniqueId)2086cdf0e10cSrcweir void FormulaDlg::SetFocusWin(Window *pWin,const rtl::OString& nUniqueId)
2087cdf0e10cSrcweir {
2088cdf0e10cSrcweir 	if(pWin->GetUniqueId()==nUniqueId)
2089cdf0e10cSrcweir 	{
2090cdf0e10cSrcweir 		pWin->GrabFocus();
2091cdf0e10cSrcweir 	}
2092cdf0e10cSrcweir 	else
2093cdf0e10cSrcweir 	{
2094cdf0e10cSrcweir 		sal_uInt16 nCount=pWin->GetChildCount();
2095cdf0e10cSrcweir 
2096cdf0e10cSrcweir 		for(sal_uInt16 i=0;i<nCount;i++)
2097cdf0e10cSrcweir 		{
2098cdf0e10cSrcweir 			Window* pChild=pWin->GetChild(i);
2099cdf0e10cSrcweir 			SetFocusWin(pChild,nUniqueId);
2100cdf0e10cSrcweir 		}
2101cdf0e10cSrcweir 	}
2102cdf0e10cSrcweir }
2103cdf0e10cSrcweir 
2104cdf0e10cSrcweir 
PreNotify(NotifyEvent & rNEvt)2105cdf0e10cSrcweir long FormulaDlg::PreNotify( NotifyEvent& rNEvt )
2106cdf0e10cSrcweir {
2107cdf0e10cSrcweir 	m_pImpl->PreNotify( rNEvt );
2108cdf0e10cSrcweir 	return SfxModelessDialog::PreNotify(rNEvt);
2109cdf0e10cSrcweir }
2110cdf0e10cSrcweir 
HighlightFunctionParas(const String & aFormula)2111cdf0e10cSrcweir void FormulaDlg::HighlightFunctionParas(const String& aFormula)
2112cdf0e10cSrcweir {
2113cdf0e10cSrcweir 	m_pImpl->m_pHelper->showReference(aFormula);
2114cdf0e10cSrcweir }
2115cdf0e10cSrcweir 
disableOk()2116cdf0e10cSrcweir void FormulaDlg::disableOk()
2117cdf0e10cSrcweir {
2118cdf0e10cSrcweir     m_pImpl->aBtnEnd.Disable();
2119cdf0e10cSrcweir }
2120cdf0e10cSrcweir // -----------------------------------------------------------------------------
getCurrentFunctionDescription() const2121cdf0e10cSrcweir const IFunctionDescription*	FormulaDlg::getCurrentFunctionDescription() const
2122cdf0e10cSrcweir {
2123cdf0e10cSrcweir     OSL_VERIFY(!m_pImpl->pFuncDesc || m_pImpl->pFuncDesc->getSuppressedArgumentCount() == m_pImpl->nArgs);
2124cdf0e10cSrcweir     return m_pImpl->pFuncDesc;
2125cdf0e10cSrcweir }
2126cdf0e10cSrcweir // -----------------------------------------------------------------------------
UpdateParaWin(const Selection & _rSelection,const String & _sRefStr)2127cdf0e10cSrcweir void FormulaDlg::UpdateParaWin(const Selection& _rSelection,const String& _sRefStr)
2128cdf0e10cSrcweir {
2129cdf0e10cSrcweir     m_pImpl->UpdateParaWin(_rSelection,_sRefStr);
2130cdf0e10cSrcweir }
UpdateParaWin(Selection & _rSelection)2131cdf0e10cSrcweir sal_Bool FormulaDlg::UpdateParaWin(Selection& _rSelection)
2132cdf0e10cSrcweir {
2133cdf0e10cSrcweir     return m_pImpl->UpdateParaWin(_rSelection);
2134cdf0e10cSrcweir }
2135cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetActiveEdit()2136cdf0e10cSrcweir RefEdit*	FormulaDlg::GetActiveEdit()
2137cdf0e10cSrcweir {
2138cdf0e10cSrcweir     return m_pImpl->pParaWin->GetActiveEdit();
2139cdf0e10cSrcweir }
2140cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetFormulaHelper() const2141cdf0e10cSrcweir const FormulaHelper& FormulaDlg::GetFormulaHelper() const
2142cdf0e10cSrcweir {
2143cdf0e10cSrcweir     return m_pImpl->GetFormulaHelper();
2144cdf0e10cSrcweir }
2145cdf0e10cSrcweir // -----------------------------------------------------------------------------
SetEdSelection()2146cdf0e10cSrcweir void FormulaDlg::SetEdSelection()
2147cdf0e10cSrcweir {
2148cdf0e10cSrcweir     m_pImpl->SetEdSelection();
2149cdf0e10cSrcweir }
IMPL_LINK(FormulaDlg,UpdateFocusHdl,Timer *,EMPTYARG)2150cdf0e10cSrcweir IMPL_LINK( FormulaDlg, UpdateFocusHdl, Timer*, EMPTYARG )
2151cdf0e10cSrcweir {
2152cdf0e10cSrcweir 	FormEditData* pData = m_pImpl->m_pHelper->getFormEditData();
2153cdf0e10cSrcweir 
2154cdf0e10cSrcweir 	if (pData) // wird nicht ueber Close zerstoert;
2155cdf0e10cSrcweir 	{
2156cdf0e10cSrcweir         m_pImpl->m_pHelper->setReferenceInput(pData);
2157cdf0e10cSrcweir         rtl::OString nUniqueId(pData->GetUniqueId());
2158cdf0e10cSrcweir 		SetFocusWin(this,nUniqueId);
2159cdf0e10cSrcweir 	}
2160cdf0e10cSrcweir 	return 0;
2161cdf0e10cSrcweir }
2162cdf0e10cSrcweir 
2163cdf0e10cSrcweir // -----------------------------------------------------------------------------
2164cdf0e10cSrcweir // -----------------------------------------------------------------------------
SaveValues()2165cdf0e10cSrcweir void FormEditData::SaveValues()
2166cdf0e10cSrcweir {
2167cdf0e10cSrcweir 	FormEditData* pTemp = new FormEditData(*this);
2168cdf0e10cSrcweir 
2169cdf0e10cSrcweir 	Reset();
2170cdf0e10cSrcweir 	pParent = pTemp;
2171cdf0e10cSrcweir }
2172cdf0e10cSrcweir // -----------------------------------------------------------------------------
Reset()2173cdf0e10cSrcweir void FormEditData::Reset()
2174cdf0e10cSrcweir {
2175cdf0e10cSrcweir 	pParent = NULL;
2176cdf0e10cSrcweir 	nMode = 0;
2177cdf0e10cSrcweir 	nFStart = 0;
2178cdf0e10cSrcweir 	nCatSel = 1;		//!	oder 0 (zuletzt benutzte)
2179cdf0e10cSrcweir 	nFuncSel = 0;
2180cdf0e10cSrcweir 	nOffset = 0;
2181cdf0e10cSrcweir 	nEdFocus = 0;
2182cdf0e10cSrcweir 	bMatrix	=sal_False;
2183cdf0e10cSrcweir 	aUniqueId=rtl::OString();
2184cdf0e10cSrcweir 	aSelection.Min()=0;
2185cdf0e10cSrcweir 	aSelection.Max()=0;
2186cdf0e10cSrcweir 	aUndoStr.Erase();
2187cdf0e10cSrcweir }
2188cdf0e10cSrcweir // -----------------------------------------------------------------------------
RestoreValues()2189cdf0e10cSrcweir void FormEditData::RestoreValues()
2190cdf0e10cSrcweir {
2191cdf0e10cSrcweir 	FormEditData* pTemp = pParent;
2192cdf0e10cSrcweir 	DBG_ASSERT(pTemp,"RestoreValues ohne Parent");
2193cdf0e10cSrcweir 	if (pTemp)
2194cdf0e10cSrcweir 	{
2195cdf0e10cSrcweir 		*this = *pTemp;
2196cdf0e10cSrcweir 		pTemp->pParent = NULL;		// sonst wird der auch geloescht!
2197cdf0e10cSrcweir 		delete pTemp;
2198cdf0e10cSrcweir 	}
2199cdf0e10cSrcweir }
2200cdf0e10cSrcweir // -----------------------------------------------------------------------------
operator =(const FormEditData & r)2201cdf0e10cSrcweir const FormEditData& FormEditData::operator=( const FormEditData& r )
2202cdf0e10cSrcweir {
2203cdf0e10cSrcweir 	pParent			= r.pParent;
2204cdf0e10cSrcweir 	nMode			= r.nMode;
2205cdf0e10cSrcweir 	nFStart			= r.nFStart;
2206cdf0e10cSrcweir 	nCatSel			= r.nCatSel;
2207cdf0e10cSrcweir 	nFuncSel		= r.nFuncSel;
2208cdf0e10cSrcweir 	nOffset			= r.nOffset;
2209cdf0e10cSrcweir 	nEdFocus		= r.nEdFocus;
2210cdf0e10cSrcweir 	aUndoStr		= r.aUndoStr;
2211cdf0e10cSrcweir 	bMatrix			= r.bMatrix	;
2212cdf0e10cSrcweir 	aUniqueId		= r.aUniqueId;
2213cdf0e10cSrcweir 	aSelection		= r.aSelection;
2214cdf0e10cSrcweir 	return *this;
2215cdf0e10cSrcweir }
2216cdf0e10cSrcweir // -----------------------------------------------------------------------------
FormEditData()2217cdf0e10cSrcweir FormEditData::FormEditData()
2218cdf0e10cSrcweir {
2219cdf0e10cSrcweir 	Reset();
2220cdf0e10cSrcweir }
2221cdf0e10cSrcweir 
~FormEditData()2222cdf0e10cSrcweir FormEditData::~FormEditData()
2223cdf0e10cSrcweir {
2224cdf0e10cSrcweir 	delete pParent;
2225cdf0e10cSrcweir }
2226cdf0e10cSrcweir 
FormEditData(const FormEditData & r)2227cdf0e10cSrcweir FormEditData::FormEditData( const FormEditData& r )
2228cdf0e10cSrcweir {
2229cdf0e10cSrcweir 	*this = r;
2230cdf0e10cSrcweir }
2231cdf0e10cSrcweir 
2232cdf0e10cSrcweir // -----------------------------------------------------------------------------
2233cdf0e10cSrcweir } // formula
2234cdf0e10cSrcweir // -----------------------------------------------------------------------------
2235