LibreOffice Module reportdesign (master) 1
Formula.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <formula/formdata.hxx>
22#include <formula/funcutl.hxx>
25#include <com/sun/star/lang/XMultiServiceFactory.hpp>
26#include <com/sun/star/beans/PropertyValue.hpp>
27
28#include <memory>
29
30#include <Formula.hxx>
31#include <AddField.hxx>
32#include <utility>
33#include <helpids.h>
34
35
36namespace rptui
37{
38 using namespace formula;
39 using namespace ::com::sun::star;
40
41
42// initialization / shared functions for the dialog
43
44
46 , const uno::Reference<lang::XMultiServiceFactory>& _xServiceFactory
47 , const std::shared_ptr< IFunctionManager >& _pFunctionMgr
48 , const OUString& _sFormula
49 , css::uno::Reference < css::beans::XPropertySet > _xRowSet
50 , svl::SharedStringPool& rStrPool )
51 : FormulaModalDialog( pParent, _pFunctionMgr.get(),this)
52 ,m_aFunctionManager(_pFunctionMgr)
53 ,m_xFormulaData(new FormEditData())
54 ,m_xRowSet(std::move(_xRowSet))
55 ,m_pEdit(nullptr)
56 ,m_sFormula("=")
57 ,m_nStart(0)
58 ,m_nEnd(1)
59 ,mrStringPool(rStrPool)
60{
61 if ( !_sFormula.isEmpty() )
62 {
63 if ( _sFormula[0] != '=' )
64 m_sFormula += _sFormula;
65 else
66 m_sFormula = _sFormula;
67 }
68 m_xParser.set(_xServiceFactory->createInstance("org.libreoffice.report.pentaho.SOFormulaParser"),uno::UNO_QUERY);
69 if ( m_xParser.is() )
70 m_xOpCodeMapper = m_xParser->getFormulaOpCodeMapper();
71 fill();
72}
73
75{
76}
77
79{
83 Update();
84}
85
87{
88 if ( m_xAddField )
89 {
90 SvtViewOptions aDlgOpt( EViewType::Window, HID_RPT_FIELD_SEL_WIN );
92
93 if (m_xAddField->getDialog()->get_visible())
94 m_xAddField->response(RET_CANCEL);
95
96 m_xAddField.reset();
97 }
98
100 m_pEdit = nullptr;
101}
102
103// functions for right side
104
105bool FormulaDialog::calculateValue( const OUString& rStrExp, OUString& rStrResult, bool /*bMatrixFormula*/ )
106{
107 rStrResult = rStrExp;
108 return false;
109}
110
111std::shared_ptr<formula::FormulaCompiler> FormulaDialog::getCompiler() const
112{
113 return nullptr;
114}
115
116std::unique_ptr<formula::FormulaCompiler> FormulaDialog::createCompiler( formula::FormulaTokenArray& rArray ) const
117{
118 return std::unique_ptr<formula::FormulaCompiler>(new FormulaCompiler(rArray));
119}
120
122{
123 response(_bOk ? RET_OK : RET_CANCEL);
124}
125
127{
128}
129void FormulaDialog::showReference(const OUString& /*_sFormula*/)
130{
131}
132void FormulaDialog::dispatch(bool /*_bOK*/, bool /*_bMatrixChecked*/)
133{
134}
136{
137}
139{
140}
142{
143}
145{
146}
148{
149 return m_xFormulaData.get();
150}
151void FormulaDialog::setCurrentFormula(const OUString& _sReplacement)
152{
153 const sal_Int32 nOldLen = m_nEnd - m_nStart;
154 const sal_Int32 nNewLen = _sReplacement.getLength();
155 if (nOldLen)
156 m_sFormula = m_sFormula.replaceAt( m_nStart, nOldLen, u"" );
157 if (nNewLen)
158 m_sFormula = m_sFormula.replaceAt( m_nStart, 0, _sReplacement );
159 m_nEnd = m_nStart + nNewLen;
160}
161void FormulaDialog::setSelection(sal_Int32 _nStart, sal_Int32 _nEnd)
162{
163 if ( _nStart <= _nEnd )
164 {
165 m_nStart = _nStart;
166 m_nEnd = _nEnd;
167 }
168 else
169 {
170 m_nEnd = _nStart;
171 m_nStart = _nEnd;
172 }
173}
174void FormulaDialog::getSelection(sal_Int32& _nStart, sal_Int32& _nEnd) const
175{
176 _nStart = m_nStart;
177 _nEnd = m_nEnd;
178}
180{
181 return m_sFormula;
182}
184{
185 return m_aFunctionManager.get();
186}
187
188void FormulaDialog::ShowReference(const OUString& /*_sRef*/)
189{
190}
191
192void FormulaDialog::HideReference( bool /*bDoneRefMode*/)
193{
194}
195
197{
198}
199
201{
202 ::std::pair<RefButton*,RefEdit*> aPair = RefInputStartBefore( _pEdit, _pButton );
203 m_pEdit = aPair.second;
204 if ( m_pEdit )
205 m_pEdit->GetWidget()->hide();
206 if ( aPair.first )
207 aPair.first->GetWidget()->hide();
208
209 if (!m_xAddField)
210 {
211 m_xAddField = std::make_shared<OAddFieldWindow>(m_xDialog.get(), m_xRowSet);
212 m_xAddField->SetCreateHdl(LINK( this, FormulaDialog, OnClickHdl ) );
213 SvtViewOptions aDlgOpt( EViewType::Window, HID_RPT_FIELD_SEL_WIN );
214 if ( aDlgOpt.Exists() )
215 {
216 m_xAddField->getDialog()->set_window_state(aDlgOpt.GetWindowState());
217
218 }
219
220 m_xAddField->Update();
221 }
223
224 if (!m_xAddField->getDialog()->get_visible())
225 weld::DialogController::runAsync(m_xAddField, [this](sal_Int32 /*nResult*/) { m_xAddField.reset(); });
226}
227
228IMPL_LINK( FormulaDialog, OnClickHdl, OAddFieldWindow& ,_rAddFieldDlg, void)
229{
230 const uno::Sequence< beans::PropertyValue > aArgs = _rAddFieldDlg.getSelectedFieldDescriptors();
231 // we use this way to create undo actions
232 if ( m_pEdit && aArgs.getLength() == 1)
233 {
234 uno::Sequence< beans::PropertyValue > aValue;
235 aArgs[0].Value >>= aValue;
236 svx::ODataAccessDescriptor aDescriptor(aValue);
237 OUString sName;
239 if ( !sName.isEmpty() )
240 {
241 sName = "[" + sName + "]";
242 m_pEdit->SetText(sName);
243 }
244 }
245 m_pEdit = nullptr;
246 if (_rAddFieldDlg.getDialog()->get_visible())
247 _rAddFieldDlg.response(RET_CANCEL);
248 RefInputDoneAfter();
249}
250
251uno::Reference< sheet::XFormulaParser> FormulaDialog::getFormulaParser() const
252{
253 return m_xParser;
254}
255
256uno::Reference< sheet::XFormulaOpCodeMapper> FormulaDialog::getFormulaOpCodeMapper() const
257{
258 return m_xOpCodeMapper;
259}
260
261table::CellAddress FormulaDialog::getReferencePosition() const
262{
263 return table::CellAddress();
264}
265
266::std::unique_ptr<formula::FormulaTokenArray> FormulaDialog::convertToTokenArray(const uno::Sequence< sheet::FormulaToken >& _aTokenList)
267{
268 ::std::unique_ptr<formula::FormulaTokenArray> pArray(new FormulaTokenArray());
269 pArray->Fill(_aTokenList, mrStringPool, nullptr);
270 return pArray;
271}
272
273} // rptui
274
275/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
void SetWindowState(const OUString &sState)
OUString GetWindowState() const
bool Exists() const
void StoreFormEditData(FormEditData *pData)
void SetMeText(const OUString &_sText)
::std::pair< RefButton *, RefEdit * > RefInputStartBefore(RefEdit *pEdit, RefButton *pButton)
void CheckMatrix(OUString &aFormula)
weld::Entry * GetWidget() const
virtual void notifyChange() override
Definition: Formula.cxx:74
virtual css::table::CellAddress getReferencePosition() const override
Definition: Formula.cxx:261
virtual void getSelection(sal_Int32 &_nStart, sal_Int32 &_nEnd) const override
Definition: Formula.cxx:174
virtual void insertEntryToLRUList(const formula::IFunctionDescription *pDesc) override
Definition: Formula.cxx:126
virtual void setSelection(sal_Int32 _nStart, sal_Int32 _nEnd) override
Definition: Formula.cxx:161
css::uno::Reference< css::report::meta::XFormulaParser > m_xParser
Definition: Formula.hxx:52
virtual void ReleaseFocus(formula::RefEdit *pEdit) override
Definition: Formula.cxx:196
css::uno::Reference< css::beans::XPropertySet > m_xRowSet
Definition: Formula.hxx:51
FormulaDialog(weld::Window *pParent, const css::uno::Reference< css::lang::XMultiServiceFactory > &_xServiceFactory, const std::shared_ptr< formula::IFunctionManager > &_pFunctionMgr, const OUString &_sFormula, css::uno::Reference< css::beans::XPropertySet > _xRowSet, svl::SharedStringPool &rStrPool)
Definition: Formula.cxx:45
std::shared_ptr< OAddFieldWindow > m_xAddField
Definition: Formula.hxx:50
virtual OUString getCurrentFormula() const override
Definition: Formula.cxx:179
virtual void HideReference(bool bDoneRefMode=true) override
Definition: Formula.cxx:192
virtual formula::FormEditData * getFormEditData() const override
Definition: Formula.cxx:147
std::unique_ptr< formula::FormEditData > m_xFormulaData
Definition: Formula.hxx:49
virtual css::uno::Reference< css::sheet::XFormulaOpCodeMapper > getFormulaOpCodeMapper() const override
Definition: Formula.cxx:256
css::uno::Reference< css::sheet::XFormulaOpCodeMapper > m_xOpCodeMapper
Definition: Formula.hxx:53
OUString m_sFormula
Definition: Formula.hxx:55
virtual void deleteFormData() override
Definition: Formula.cxx:138
virtual std::shared_ptr< formula::FormulaCompiler > getCompiler() const override
Definition: Formula.cxx:111
virtual void switchBack() override
Definition: Formula.cxx:144
formula::RefEdit * m_pEdit
Definition: Formula.hxx:54
virtual void dispatch(bool _bOK, bool _bMatrixChecked) override
Definition: Formula.cxx:132
virtual void fill() override
Definition: Formula.cxx:78
sal_Int32 m_nEnd
Definition: Formula.hxx:57
virtual css::uno::Reference< css::sheet::XFormulaParser > getFormulaParser() const override
Definition: Formula.cxx:251
virtual ::std::unique_ptr< formula::FormulaTokenArray > convertToTokenArray(const css::uno::Sequence< css::sheet::FormulaToken > &_aTokenList) override
Definition: Formula.cxx:266
virtual bool calculateValue(const OUString &_sExpression, OUString &_rResult, bool bMatrixFormula) override
Definition: Formula.cxx:105
virtual std::unique_ptr< formula::FormulaCompiler > createCompiler(formula::FormulaTokenArray &rArray) const override
Definition: Formula.cxx:116
virtual void doClose(bool _bOk) override
Definition: Formula.cxx:121
std::shared_ptr< formula::IFunctionManager > m_aFunctionManager
Definition: Formula.hxx:48
virtual void setDispatcherLock(bool bLock) override
Definition: Formula.cxx:135
virtual void setCurrentFormula(const OUString &_sReplacement) override
Definition: Formula.cxx:151
virtual void ToggleCollapsed(formula::RefEdit *pEdit, formula::RefButton *pButton) override
Definition: Formula.cxx:200
svl::SharedStringPool & mrStringPool
Definition: Formula.hxx:59
virtual formula::IFunctionManager * getFunctionManager() override
Definition: Formula.cxx:183
virtual ~FormulaDialog() override
Definition: Formula.cxx:86
virtual void showReference(const OUString &_sFormula) override
Definition: Formula.cxx:129
virtual void clear() override
Definition: Formula.cxx:141
sal_Int32 m_nStart
Definition: Formula.hxx:56
virtual void ShowReference(const OUString &_sRef) override
Definition: Formula.cxx:188
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
virtual void hide()=0
float u
OUString sName
#define HID_RPT_FIELD_SEL_WIN
Definition: helpids.h:34
IMPL_LINK(OAddFieldWindow, DragBeginHdl, bool &, rUnsetDragIcon, bool)
Definition: AddField.cxx:50
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
RET_OK
RET_CANCEL