1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef RPTUI_FORMULA_HXX
29 #define RPTUI_FORMULA_HXX
30 
31 #include <formula/formula.hxx>
32 #include <formula/IFunctionDescription.hxx>
33 #include <formula/IControlReferenceHandler.hxx>
34 #include <boost/shared_ptr.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/report/meta/XFormulaParser.hpp>
37 
38 class SvLBoxEntry;
39 //============================================================================
40 namespace rptui
41 {
42 //============================================================================
43 class FunctionManager;
44 class OAddFieldWindow;
45 
46 //============================================================================
47 class FormulaDialog : public formula::FormulaModalDialog,
48                       public formula::IFormulaEditorHelper,
49                       public formula::IControlReferenceHandler
50 {
51     ::boost::shared_ptr< formula::IFunctionManager > m_aFunctionManager;
52     formula::FormEditData*      m_pFormulaData;
53     OAddFieldWindow*		    m_pAddField;
54     ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet >          m_xRowSet;
55     ::com::sun::star::uno::Reference< ::com::sun::star::report::meta::XFormulaParser>   m_xParser;
56     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XFormulaOpCodeMapper>    m_xOpCodeMapper;
57     formula::RefEdit*           m_pEdit;
58     String                      m_sFormula;
59     xub_StrLen                  m_nStart;
60     xub_StrLen                  m_nEnd;
61 
62     DECL_LINK( OnClickHdl, OAddFieldWindow*);
63 public:
64 	FormulaDialog( Window* pParent
65         , const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _xServiceFactory
66         , const ::boost::shared_ptr< formula::IFunctionManager >& _pFunctionMgr
67         , const ::rtl::OUString& _sFormula
68         , const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet >& _xRowSet);
69 	virtual ~FormulaDialog();
70 
71     // IFormulaEditorHelper
72     virtual void notifyChange();
73     virtual void fill();
74     virtual bool calculateValue(const String& _sExpression,String& _rResult);
75     virtual void doClose(sal_Bool _bOk);
76     virtual void insertEntryToLRUList(const formula::IFunctionDescription*	pDesc);
77     virtual void showReference(const String& _sFormula);
78     virtual void dispatch(sal_Bool _bOK,sal_Bool _bMartixChecked);
79     virtual void setDispatcherLock( sal_Bool bLock );
80     virtual void setReferenceInput(const formula::FormEditData* _pData);
81     virtual void deleteFormData();
82     virtual void clear();
83     virtual void switchBack();
84     virtual formula::FormEditData* getFormEditData() const;
85     virtual void setCurrentFormula(const String& _sReplacement);
86     virtual void setSelection(xub_StrLen _nStart,xub_StrLen _nEnd);
87     virtual void getSelection(xub_StrLen& _nStart,xub_StrLen& _nEnd) const;
88     virtual String getCurrentFormula() const;
89 
90     virtual formula::IFunctionManager* getFunctionManager();
91     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XFormulaParser> getFormulaParser() const;
92     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XFormulaOpCodeMapper> getFormulaOpCodeMapper() const;
93     virtual ::com::sun::star::table::CellAddress getReferencePosition() const;
94 
95     virtual ::std::auto_ptr<formula::FormulaTokenArray> convertToTokenArray(const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken >& _aTokenList);
96 
97     // IControlReferenceHandler
98     virtual void ShowReference(const String& _sRef);
99     virtual void HideReference( sal_Bool bDoneRefMode = sal_True );
100     virtual void ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
101     virtual void ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
102 
103 protected:
104 	void		 HighlightFunctionParas(const String& aFormula);
105 };
106 
107 // =============================================================================
108 } // rptui
109 // =============================================================================
110 
111 #endif // RPTUI_FORMULA_HXX
112 
113