Update ooo320-m1
[ooovba.git] / reportdesign / source / ui / dlg / Formula.cxx
blob935ec4c31e4dc0a8fe8a87a3037902e1d0743217
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: formula.cxx,v $
10 * $Revision: 1.19 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_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 //============================================================================
52 namespace rptui
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())
69 ,m_pAddField(NULL)
70 ,m_xRowSet(_xRowSet)
71 ,m_pEdit(NULL)
72 ,m_sFormula(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("=")))
73 ,m_nStart(0)
74 ,m_nEnd(1)
76 if ( _sFormula.getLength() > 0 )
78 if ( _sFormula.getStr()[0] != '=' )
79 m_sFormula += String(_sFormula);
80 else
81 m_sFormula = _sFormula;
83 m_xParser.set(_xServiceFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.pentaho.SOFormulaParser"))),uno::UNO_QUERY);
84 if ( m_xParser.is() )
85 m_xOpCodeMapper = m_xParser->getFormulaOpCodeMapper();
86 fill();
89 void FormulaDialog::notifyChange()
92 // -----------------------------------------------------------------------------
93 void FormulaDialog::fill()
95 SetMeText(m_sFormula);
96 Update(m_sFormula);
97 CheckMatrix(m_sFormula);
98 Update();
101 FormulaDialog::~FormulaDialog()
103 if ( m_pAddField )
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);
109 m_pAddField = NULL;
113 // --------------------------------------------------------------------------
114 // Funktionen fuer rechte Seite
115 // --------------------------------------------------------------------------
116 bool FormulaDialog::calculateValue( const String& rStrExp, String& rStrResult )
118 rStrResult = rStrExp;
119 return false;
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();
157 if (nOldLen)
158 m_sFormula.Erase( m_nStart, nOldLen );
159 if (nNewLen)
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 )
167 m_nStart = _nStart;
168 m_nEnd = _nEnd;
170 else
172 m_nEnd = _nStart;
173 m_nStart = _nEnd;
176 void FormulaDialog::getSelection(xub_StrLen& _nStart,xub_StrLen& _nEnd) const
178 _nStart = m_nStart;
179 _nEnd = m_nEnd;
181 String FormulaDialog::getCurrentFormula() const
183 return m_sFormula;
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;
206 if ( m_pEdit )
207 m_pEdit->Hide();
208 if ( aPair.first )
209 aPair.first->Hide();
211 if ( !m_pAddField )
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 );
225 m_pAddField->Show();
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() )
246 m_pEdit = NULL;
247 _pAddFieldDlg->Hide();
248 RefInputDoneAfter( TRUE );
250 return 0L;
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);
272 return pArray;
274 // =============================================================================
275 } // rptui
276 // =============================================================================