1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: formula.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_reportdesign.hxx"
35 //----------------------------------------------------------------------------
37 #include <vcl/svapp.hxx>
38 #include <vcl/mnemonic.hxx>
39 #include <vcl/msgbox.hxx>
40 #include <unotools/charclass.hxx>
41 #include <svtools/viewoptions.hxx>
42 #include <tools/urlobj.hxx>
43 #include <formula/formdata.hxx>
44 #include <formula/funcutl.hxx>
45 #include <formula/tokenarray.hxx>
47 #include "Formula.hxx"
48 #include "AddField.hxx"
49 #include "helpids.hrc"
51 //============================================================================
54 using namespace formula
;
55 using namespace ::com::sun::star
;
57 // --------------------------------------------------------------------------
58 // Initialisierung / gemeinsame Funktionen fuer Dialog
59 // --------------------------------------------------------------------------
61 FormulaDialog::FormulaDialog(Window
* pParent
62 , const uno::Reference
<lang::XMultiServiceFactory
>& _xServiceFactory
63 , const ::boost::shared_ptr
< IFunctionManager
>& _pFunctionMgr
64 , const ::rtl::OUString
& _sFormula
65 , const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
>& _xRowSet
)
66 : FormulaModalDialog( pParent
, false,false,false,this,_pFunctionMgr
.get(),this)
67 ,m_aFunctionManager(_pFunctionMgr
)
68 ,m_pFormulaData(new FormEditData())
72 ,m_sFormula(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("=")))
76 if ( _sFormula
.getLength() > 0 )
78 if ( _sFormula
.getStr()[0] != '=' )
79 m_sFormula
+= String(_sFormula
);
81 m_sFormula
= _sFormula
;
83 m_xParser
.set(_xServiceFactory
->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.pentaho.SOFormulaParser"))),uno::UNO_QUERY
);
85 m_xOpCodeMapper
= m_xParser
->getFormulaOpCodeMapper();
89 void FormulaDialog::notifyChange()
92 // -----------------------------------------------------------------------------
93 void FormulaDialog::fill()
95 SetMeText(m_sFormula
);
97 CheckMatrix(m_sFormula
);
101 FormulaDialog::~FormulaDialog()
105 SvtViewOptions
aDlgOpt( E_WINDOW
, String::CreateFromInt32( HID_RPT_FIELD_SEL_WIN
) );
106 aDlgOpt
.SetWindowState( ::rtl::OUString::createFromAscii( m_pAddField
->GetWindowState((WINDOWSTATE_MASK_X
| WINDOWSTATE_MASK_Y
| WINDOWSTATE_MASK_STATE
| WINDOWSTATE_MASK_MINIMIZED
)).GetBuffer() ) );
108 ::std::auto_ptr
<Window
> aTemp2(m_pAddField
);
113 // --------------------------------------------------------------------------
114 // Funktionen fuer rechte Seite
115 // --------------------------------------------------------------------------
116 bool FormulaDialog::calculateValue( const String
& rStrExp
, String
& rStrResult
)
118 rStrResult
= rStrExp
;
121 void FormulaDialog::doClose(BOOL _bOk
)
123 EndDialog(_bOk
? RET_OK
: RET_CANCEL
);
125 void FormulaDialog::insertEntryToLRUList(const IFunctionDescription
* /*_pDesc*/)
128 void FormulaDialog::showReference(const String
& /*_sFormula*/)
131 void FormulaDialog::dispatch(BOOL
/*_bOK*/,BOOL
/*_bMartixChecked*/)
134 void FormulaDialog::setDispatcherLock( BOOL
/*bLock*/ )
137 void FormulaDialog::setReferenceInput(const FormEditData
* /*_pData*/)
140 void FormulaDialog::deleteFormData()
143 void FormulaDialog::clear()
146 void FormulaDialog::switchBack()
149 FormEditData
* FormulaDialog::getFormEditData() const
151 return m_pFormulaData
;
153 void FormulaDialog::setCurrentFormula(const String
& _sReplacement
)
155 const xub_StrLen nOldLen
= m_nEnd
- m_nStart
;
156 const xub_StrLen nNewLen
= _sReplacement
.Len();
158 m_sFormula
.Erase( m_nStart
, nOldLen
);
160 m_sFormula
.Insert( _sReplacement
, m_nStart
);
161 m_nEnd
= m_nStart
+ nNewLen
;
163 void FormulaDialog::setSelection(xub_StrLen _nStart
,xub_StrLen _nEnd
)
165 if ( _nStart
<= _nEnd
)
176 void FormulaDialog::getSelection(xub_StrLen
& _nStart
,xub_StrLen
& _nEnd
) const
181 String
FormulaDialog::getCurrentFormula() const
185 IFunctionManager
* FormulaDialog::getFunctionManager()
187 return m_aFunctionManager
.get();
189 // -----------------------------------------------------------------------------
190 void FormulaDialog::ShowReference(const String
& /*_sRef*/)
193 // -----------------------------------------------------------------------------
194 void FormulaDialog::HideReference( BOOL
/*bDoneRefMode*/)
197 // -----------------------------------------------------------------------------
198 void FormulaDialog::ReleaseFocus( RefEdit
* /*pEdit*/, RefButton
* /*pButton*/)
201 // -----------------------------------------------------------------------------
202 void FormulaDialog::ToggleCollapsed( RefEdit
* _pEdit
, RefButton
* _pButton
)
204 ::std::pair
<RefButton
*,RefEdit
*> aPair
= RefInputStartBefore( _pEdit
, _pButton
);
205 m_pEdit
= aPair
.second
;
213 m_pAddField
= new OAddFieldWindow(this,m_xRowSet
);
214 m_pAddField
->SetCreateHdl(LINK( this, FormulaDialog
, OnClickHdl
) );
215 SvtViewOptions
aDlgOpt( E_WINDOW
, String::CreateFromInt32( HID_RPT_FIELD_SEL_WIN
) );
216 if ( aDlgOpt
.Exists() )
218 m_pAddField
->SetWindowState( ByteString( aDlgOpt
.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US
) );
222 m_pAddField
->Update();
223 } // if ( !m_pAddField )
224 RefInputStartAfter( aPair
.second
, aPair
.first
);
228 // -----------------------------------------------------------------------------
229 IMPL_LINK( FormulaDialog
, OnClickHdl
, OAddFieldWindow
* ,_pAddFieldDlg
)
231 const uno::Sequence
< beans::PropertyValue
> aArgs
= _pAddFieldDlg
->getSelectedFieldDescriptors();
232 // we use this way to create undo actions
233 if ( m_pEdit
&& aArgs
.getLength() == 1)
235 uno::Sequence
< beans::PropertyValue
> aValue
;
236 aArgs
[0].Value
>>= aValue
;
237 ::svx::ODataAccessDescriptor
aDescriptor(aValue
);
238 ::rtl::OUString sName
;
239 aDescriptor
[ ::svx::daColumnName
] >>= sName
;
240 if ( sName
.getLength() )
242 sName
= ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("[")) + sName
+ ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("]"));
243 m_pEdit
->SetText(sName
);
245 } // if ( m_pEdit && aArgs.getLength() )
247 _pAddFieldDlg
->Hide();
248 RefInputDoneAfter( TRUE
);
252 // -----------------------------------------------------------------------------
253 uno::Reference
< sheet::XFormulaParser
> FormulaDialog::getFormulaParser() const
255 return m_xParser
.get();
257 // -----------------------------------------------------------------------------
258 uno::Reference
< sheet::XFormulaOpCodeMapper
> FormulaDialog::getFormulaOpCodeMapper() const
260 return m_xOpCodeMapper
;
262 // -----------------------------------------------------------------------------
263 table::CellAddress
FormulaDialog::getReferencePosition() const
265 return table::CellAddress();
267 // -----------------------------------------------------------------------------
268 ::std::auto_ptr
<formula::FormulaTokenArray
> FormulaDialog::convertToTokenArray(const uno::Sequence
< sheet::FormulaToken
>& _aTokenList
)
270 ::std::auto_ptr
<formula::FormulaTokenArray
> pArray(new FormulaTokenArray());
271 pArray
->Fill(_aTokenList
, NULL
);
274 // =============================================================================
276 // =============================================================================