Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <vcl/svapp.hxx>
30 : : #include <vcl/mnemonic.hxx>
31 : : #include <vcl/msgbox.hxx>
32 : : #include <unotools/charclass.hxx>
33 : : #include <unotools/viewoptions.hxx>
34 : : #include <formula/formdata.hxx>
35 : : #include <formula/funcutl.hxx>
36 : : #include <formula/tokenarray.hxx>
37 : :
38 : : #include <boost/scoped_ptr.hpp>
39 : :
40 : : #include "Formula.hxx"
41 : : #include "AddField.hxx"
42 : : #include "helpids.hrc"
43 : :
44 : : //============================================================================
45 : : namespace rptui
46 : : {
47 : : using namespace formula;
48 : : using namespace ::com::sun::star;
49 : :
50 : : // --------------------------------------------------------------------------
51 : : // Initialisierung / gemeinsame Funktionen fuer Dialog
52 : : // --------------------------------------------------------------------------
53 : :
54 : 0 : FormulaDialog::FormulaDialog(Window* pParent
55 : : , const uno::Reference<lang::XMultiServiceFactory>& _xServiceFactory
56 : : , const ::boost::shared_ptr< IFunctionManager >& _pFunctionMgr
57 : : , const ::rtl::OUString& _sFormula
58 : : , const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet >& _xRowSet)
59 : : : FormulaModalDialog( pParent, false,false,false,_pFunctionMgr.get(),this)
60 : : ,m_aFunctionManager(_pFunctionMgr)
61 : 0 : ,m_pFormulaData(new FormEditData())
62 : : ,m_pAddField(NULL)
63 : : ,m_xRowSet(_xRowSet)
64 : : ,m_pEdit(NULL)
65 : : ,m_sFormula(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("=")))
66 : : ,m_nStart(0)
67 : 0 : ,m_nEnd(1)
68 : : {
69 : 0 : if ( !_sFormula.isEmpty() )
70 : : {
71 : 0 : if ( _sFormula.getStr()[0] != '=' )
72 : 0 : m_sFormula += String(_sFormula);
73 : : else
74 : 0 : m_sFormula = _sFormula;
75 : : }
76 : 0 : m_xParser.set(_xServiceFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.pentaho.SOFormulaParser"))),uno::UNO_QUERY);
77 : 0 : if ( m_xParser.is() )
78 : 0 : m_xOpCodeMapper = m_xParser->getFormulaOpCodeMapper();
79 : 0 : fill();
80 : 0 : }
81 : :
82 : 0 : void FormulaDialog::notifyChange()
83 : : {
84 : 0 : }
85 : : // -----------------------------------------------------------------------------
86 : 0 : void FormulaDialog::fill()
87 : : {
88 : 0 : SetMeText(m_sFormula);
89 : 0 : Update(m_sFormula);
90 : 0 : CheckMatrix(m_sFormula);
91 : 0 : Update();
92 : 0 : }
93 : :
94 : 0 : FormulaDialog::~FormulaDialog()
95 : : {
96 : 0 : if ( m_pAddField )
97 : : {
98 : 0 : SvtViewOptions aDlgOpt( E_WINDOW, rtl::OUString( HID_RPT_FIELD_SEL_WIN ) );
99 : 0 : aDlgOpt.SetWindowState(::rtl::OStringToOUString(m_pAddField->GetWindowState((WINDOWSTATE_MASK_X | WINDOWSTATE_MASK_Y | WINDOWSTATE_MASK_STATE | WINDOWSTATE_MASK_MINIMIZED)), RTL_TEXTENCODING_ASCII_US));
100 : :
101 : 0 : boost::scoped_ptr<Window> aTemp2(m_pAddField);
102 : 0 : m_pAddField = NULL;
103 : : }
104 : :
105 : 0 : StoreFormEditData( m_pFormulaData );
106 : 0 : }
107 : :
108 : : // --------------------------------------------------------------------------
109 : : // Funktionen fuer rechte Seite
110 : : // --------------------------------------------------------------------------
111 : 0 : bool FormulaDialog::calculateValue( const String& rStrExp, String& rStrResult )
112 : : {
113 : 0 : rStrResult = rStrExp;
114 : 0 : return false;
115 : : }
116 : 0 : void FormulaDialog::doClose(sal_Bool _bOk)
117 : : {
118 : 0 : EndDialog(_bOk ? RET_OK : RET_CANCEL);
119 : 0 : }
120 : 0 : void FormulaDialog::insertEntryToLRUList(const IFunctionDescription* /*_pDesc*/)
121 : : {
122 : 0 : }
123 : 0 : void FormulaDialog::showReference(const String& /*_sFormula*/)
124 : : {
125 : 0 : }
126 : 0 : void FormulaDialog::dispatch(sal_Bool /*_bOK*/,sal_Bool /*_bMartixChecked*/)
127 : : {
128 : 0 : }
129 : 0 : void FormulaDialog::setDispatcherLock( sal_Bool /*bLock*/ )
130 : : {
131 : 0 : }
132 : 0 : void FormulaDialog::setReferenceInput(const FormEditData* /*_pData*/)
133 : : {
134 : 0 : }
135 : 0 : void FormulaDialog::deleteFormData()
136 : : {
137 : 0 : }
138 : 0 : void FormulaDialog::clear()
139 : : {
140 : 0 : }
141 : 0 : void FormulaDialog::switchBack()
142 : : {
143 : 0 : }
144 : 0 : FormEditData* FormulaDialog::getFormEditData() const
145 : : {
146 : 0 : return m_pFormulaData;
147 : : }
148 : 0 : void FormulaDialog::setCurrentFormula(const String& _sReplacement)
149 : : {
150 : 0 : const xub_StrLen nOldLen = m_nEnd - m_nStart;
151 : 0 : const xub_StrLen nNewLen = _sReplacement.Len();
152 : 0 : if (nOldLen)
153 : 0 : m_sFormula.Erase( m_nStart, nOldLen );
154 : 0 : if (nNewLen)
155 : 0 : m_sFormula.Insert( _sReplacement, m_nStart );
156 : 0 : m_nEnd = m_nStart + nNewLen;
157 : 0 : }
158 : 0 : void FormulaDialog::setSelection(xub_StrLen _nStart,xub_StrLen _nEnd)
159 : : {
160 : 0 : if ( _nStart <= _nEnd )
161 : : {
162 : 0 : m_nStart = _nStart;
163 : 0 : m_nEnd = _nEnd;
164 : : }
165 : : else
166 : : {
167 : 0 : m_nEnd = _nStart;
168 : 0 : m_nStart = _nEnd;
169 : : }
170 : 0 : }
171 : 0 : void FormulaDialog::getSelection(xub_StrLen& _nStart,xub_StrLen& _nEnd) const
172 : : {
173 : 0 : _nStart = m_nStart;
174 : 0 : _nEnd = m_nEnd;
175 : 0 : }
176 : 0 : String FormulaDialog::getCurrentFormula() const
177 : : {
178 : 0 : return m_sFormula;
179 : : }
180 : 0 : IFunctionManager* FormulaDialog::getFunctionManager()
181 : : {
182 : 0 : return m_aFunctionManager.get();
183 : : }
184 : : // -----------------------------------------------------------------------------
185 : 0 : void FormulaDialog::ShowReference(const String& /*_sRef*/)
186 : : {
187 : 0 : }
188 : : // -----------------------------------------------------------------------------
189 : 0 : void FormulaDialog::HideReference( sal_Bool /*bDoneRefMode*/)
190 : : {
191 : 0 : }
192 : : // -----------------------------------------------------------------------------
193 : 0 : void FormulaDialog::ReleaseFocus( RefEdit* /*pEdit*/, RefButton* /*pButton*/)
194 : : {
195 : 0 : }
196 : : // -----------------------------------------------------------------------------
197 : 0 : void FormulaDialog::ToggleCollapsed( RefEdit* _pEdit, RefButton* _pButton)
198 : : {
199 : 0 : ::std::pair<RefButton*,RefEdit*> aPair = RefInputStartBefore( _pEdit, _pButton );
200 : 0 : m_pEdit = aPair.second;
201 : 0 : if ( m_pEdit )
202 : 0 : m_pEdit->Hide();
203 : 0 : if ( aPair.first )
204 : 0 : aPair.first->Hide();
205 : :
206 : 0 : if ( !m_pAddField )
207 : : {
208 : 0 : m_pAddField = new OAddFieldWindow(this,m_xRowSet);
209 : 0 : m_pAddField->SetCreateHdl(LINK( this, FormulaDialog, OnClickHdl ) );
210 : 0 : SvtViewOptions aDlgOpt( E_WINDOW, rtl::OUString( HID_RPT_FIELD_SEL_WIN ) );
211 : 0 : if ( aDlgOpt.Exists() )
212 : : {
213 : 0 : m_pAddField->SetWindowState(::rtl::OUStringToOString(aDlgOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US));
214 : :
215 : : }
216 : :
217 : 0 : m_pAddField->Update();
218 : : }
219 : 0 : RefInputStartAfter( aPair.second, aPair.first );
220 : 0 : m_pAddField->Show();
221 : :
222 : 0 : }
223 : : // -----------------------------------------------------------------------------
224 : 0 : IMPL_LINK( FormulaDialog, OnClickHdl, OAddFieldWindow* ,_pAddFieldDlg)
225 : : {
226 : 0 : const uno::Sequence< beans::PropertyValue > aArgs = _pAddFieldDlg->getSelectedFieldDescriptors();
227 : : // we use this way to create undo actions
228 : 0 : if ( m_pEdit && aArgs.getLength() == 1)
229 : : {
230 : 0 : uno::Sequence< beans::PropertyValue > aValue;
231 : 0 : aArgs[0].Value >>= aValue;
232 : 0 : ::svx::ODataAccessDescriptor aDescriptor(aValue);
233 : 0 : ::rtl::OUString sName;
234 : 0 : aDescriptor[ ::svx::daColumnName ] >>= sName;
235 : 0 : if ( !sName.isEmpty() )
236 : : {
237 : 0 : sName = ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("[")) + sName + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("]"));
238 : 0 : m_pEdit->SetText(sName);
239 : 0 : }
240 : : }
241 : 0 : m_pEdit = NULL;
242 : 0 : _pAddFieldDlg->Hide();
243 : 0 : RefInputDoneAfter( sal_True );
244 : :
245 : 0 : return 0L;
246 : : }
247 : : // -----------------------------------------------------------------------------
248 : 0 : uno::Reference< sheet::XFormulaParser> FormulaDialog::getFormulaParser() const
249 : : {
250 : 0 : return m_xParser.get();
251 : : }
252 : : // -----------------------------------------------------------------------------
253 : 0 : uno::Reference< sheet::XFormulaOpCodeMapper> FormulaDialog::getFormulaOpCodeMapper() const
254 : : {
255 : 0 : return m_xOpCodeMapper;
256 : : }
257 : : // -----------------------------------------------------------------------------
258 : 0 : table::CellAddress FormulaDialog::getReferencePosition() const
259 : : {
260 : 0 : return table::CellAddress();
261 : : }
262 : : // -----------------------------------------------------------------------------
263 : : SAL_WNODEPRECATED_DECLARATIONS_PUSH
264 : 0 : ::std::auto_ptr<formula::FormulaTokenArray> FormulaDialog::convertToTokenArray(const uno::Sequence< sheet::FormulaToken >& _aTokenList)
265 : : {
266 : 0 : ::std::auto_ptr<formula::FormulaTokenArray> pArray(new FormulaTokenArray());
267 : 0 : pArray->Fill(_aTokenList, NULL);
268 : 0 : return pArray;
269 : : }
270 : : SAL_WNODEPRECATED_DECLARATIONS_POP
271 : : // =============================================================================
272 : : } // rptui
273 : : // =============================================================================
274 : :
275 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|