update emoji autocorrect entries from po-files
[LibreOffice.git] / reportdesign / source / ui / dlg / Formula.cxx
blob819fabb1d5972675350a055df5643a1f882c9ffa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/svapp.hxx>
21 #include <vcl/mnemonic.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <unotools/charclass.hxx>
24 #include <unotools/viewoptions.hxx>
25 #include <formula/formdata.hxx>
26 #include <formula/funcutl.hxx>
27 #include <formula/tokenarray.hxx>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30 #include <boost/scoped_ptr.hpp>
32 #include "Formula.hxx"
33 #include "AddField.hxx"
34 #include "helpids.hrc"
37 namespace rptui
39 using namespace formula;
40 using namespace ::com::sun::star;
43 // Initialisierung / gemeinsame Funktionen fuer Dialog
46 FormulaDialog::FormulaDialog(vcl::Window* pParent
47 , const uno::Reference<lang::XMultiServiceFactory>& _xServiceFactory
48 , const ::boost::shared_ptr< IFunctionManager >& _pFunctionMgr
49 , const OUString& _sFormula
50 , const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet >& _xRowSet
51 , svl::SharedStringPool& rStrPool )
52 : FormulaModalDialog( pParent, false,false,false,_pFunctionMgr.get(),this)
53 ,m_aFunctionManager(_pFunctionMgr)
54 ,m_pFormulaData(new FormEditData())
55 ,m_pAddField(NULL)
56 ,m_xRowSet(_xRowSet)
57 ,m_pEdit(NULL)
58 ,m_sFormula("=")
59 ,m_nStart(0)
60 ,m_nEnd(1)
61 ,mrStringPool(rStrPool)
63 if ( !_sFormula.isEmpty() )
65 if ( _sFormula[0] != '=' )
66 m_sFormula += _sFormula;
67 else
68 m_sFormula = _sFormula;
70 m_xParser.set(_xServiceFactory->createInstance("org.libreoffice.report.pentaho.SOFormulaParser"),uno::UNO_QUERY);
71 if ( m_xParser.is() )
72 m_xOpCodeMapper = m_xParser->getFormulaOpCodeMapper();
73 fill();
76 void FormulaDialog::notifyChange()
80 void FormulaDialog::fill()
82 SetMeText(m_sFormula);
83 Update(m_sFormula);
84 CheckMatrix(m_sFormula);
85 Update();
88 FormulaDialog::~FormulaDialog()
90 disposeOnce();
93 void FormulaDialog::dispose()
95 if ( m_pAddField )
97 SvtViewOptions aDlgOpt( E_WINDOW, OUString( HID_RPT_FIELD_SEL_WIN ) );
98 aDlgOpt.SetWindowState(OStringToOUString(m_pAddField->GetWindowState((WINDOWSTATE_MASK_X | WINDOWSTATE_MASK_Y | WINDOWSTATE_MASK_STATE | WINDOWSTATE_MASK_MINIMIZED)), RTL_TEXTENCODING_ASCII_US));
101 StoreFormEditData( m_pFormulaData );
102 m_pEdit.clear();
103 m_pAddField.clear();
104 formula::FormulaModalDialog::dispose();
108 // Funktionen fuer rechte Seite
110 bool FormulaDialog::calculateValue( const OUString& rStrExp, OUString& rStrResult )
112 rStrResult = rStrExp;
113 return false;
115 void FormulaDialog::doClose(bool _bOk)
117 EndDialog(_bOk ? RET_OK : RET_CANCEL);
119 void FormulaDialog::insertEntryToLRUList(const IFunctionDescription* /*_pDesc*/)
122 void FormulaDialog::showReference(const OUString& /*_sFormula*/)
125 void FormulaDialog::dispatch(bool /*_bOK*/, bool /*_bMatrixChecked*/)
128 void FormulaDialog::setDispatcherLock( bool /*bLock*/ )
131 void FormulaDialog::setReferenceInput(const FormEditData* /*_pData*/)
134 void FormulaDialog::deleteFormData()
137 void FormulaDialog::clear()
140 void FormulaDialog::switchBack()
143 FormEditData* FormulaDialog::getFormEditData() const
145 return m_pFormulaData;
147 void FormulaDialog::setCurrentFormula(const OUString& _sReplacement)
149 const sal_Int32 nOldLen = m_nEnd - m_nStart;
150 const sal_Int32 nNewLen = _sReplacement.getLength();
151 if (nOldLen)
152 m_sFormula = m_sFormula.replaceAt( m_nStart, nOldLen, "" );
153 if (nNewLen)
154 m_sFormula = m_sFormula.replaceAt( m_nStart, 0, _sReplacement );
155 m_nEnd = m_nStart + nNewLen;
157 void FormulaDialog::setSelection(sal_Int32 _nStart, sal_Int32 _nEnd)
159 if ( _nStart <= _nEnd )
161 m_nStart = _nStart;
162 m_nEnd = _nEnd;
164 else
166 m_nEnd = _nStart;
167 m_nStart = _nEnd;
170 void FormulaDialog::getSelection(sal_Int32& _nStart, sal_Int32& _nEnd) const
172 _nStart = m_nStart;
173 _nEnd = m_nEnd;
175 OUString FormulaDialog::getCurrentFormula() const
177 return m_sFormula;
179 IFunctionManager* FormulaDialog::getFunctionManager()
181 return m_aFunctionManager.get();
184 void FormulaDialog::ShowReference(const OUString& /*_sRef*/)
188 void FormulaDialog::HideReference( bool /*bDoneRefMode*/)
192 void FormulaDialog::ReleaseFocus( RefEdit* /*pEdit*/, RefButton* /*pButton*/)
196 void FormulaDialog::ToggleCollapsed( RefEdit* _pEdit, RefButton* _pButton)
198 ::std::pair<RefButton*,RefEdit*> aPair = RefInputStartBefore( _pEdit, _pButton );
199 m_pEdit = aPair.second;
200 if ( m_pEdit )
201 m_pEdit->Hide();
202 if ( aPair.first )
203 aPair.first->Hide();
205 if ( !m_pAddField )
207 m_pAddField = VclPtr<OAddFieldWindow>::Create(this,m_xRowSet);
208 m_pAddField->SetCreateHdl(LINK( this, FormulaDialog, OnClickHdl ) );
209 SvtViewOptions aDlgOpt( E_WINDOW, OUString( HID_RPT_FIELD_SEL_WIN ) );
210 if ( aDlgOpt.Exists() )
212 m_pAddField->SetWindowState(OUStringToOString(aDlgOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US));
216 m_pAddField->Update();
218 RefInputStartAfter( aPair.second, aPair.first );
219 m_pAddField->Show();
223 IMPL_LINK( FormulaDialog, OnClickHdl, OAddFieldWindow* ,_pAddFieldDlg)
225 const uno::Sequence< beans::PropertyValue > aArgs = _pAddFieldDlg->getSelectedFieldDescriptors();
226 // we use this way to create undo actions
227 if ( m_pEdit && aArgs.getLength() == 1)
229 uno::Sequence< beans::PropertyValue > aValue;
230 aArgs[0].Value >>= aValue;
231 svx::ODataAccessDescriptor aDescriptor(aValue);
232 OUString sName;
233 aDescriptor[ svx::daColumnName ] >>= sName;
234 if ( !sName.isEmpty() )
236 sName = "[" + sName + "]";
237 m_pEdit->SetText(sName);
240 m_pEdit = NULL;
241 _pAddFieldDlg->Hide();
242 RefInputDoneAfter( true );
244 return 0L;
247 uno::Reference< sheet::XFormulaParser> FormulaDialog::getFormulaParser() const
249 return m_xParser.get();
252 uno::Reference< sheet::XFormulaOpCodeMapper> FormulaDialog::getFormulaOpCodeMapper() const
254 return m_xOpCodeMapper;
257 table::CellAddress FormulaDialog::getReferencePosition() const
259 return table::CellAddress();
262 ::std::unique_ptr<formula::FormulaTokenArray> FormulaDialog::convertToTokenArray(const uno::Sequence< sheet::FormulaToken >& _aTokenList)
264 ::std::unique_ptr<formula::FormulaTokenArray> pArray(new FormulaTokenArray());
265 pArray->Fill(_aTokenList, mrStringPool, NULL);
266 return pArray;
269 } // rptui
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */