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