1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_reportdesign.hxx" 26 27 28 //---------------------------------------------------------------------------- 29 30 #include <vcl/svapp.hxx> 31 #include <vcl/mnemonic.hxx> 32 #include <vcl/msgbox.hxx> 33 #include <unotools/charclass.hxx> 34 #include <unotools/viewoptions.hxx> 35 #include <tools/urlobj.hxx> 36 #include <formula/formdata.hxx> 37 #include <formula/funcutl.hxx> 38 #include <formula/tokenarray.hxx> 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 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,this,_pFunctionMgr.get(),this) 60 ,m_aFunctionManager(_pFunctionMgr) 61 ,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 ,m_nEnd(1) 68 { 69 if ( _sFormula.getLength() > 0 ) 70 { 71 if ( _sFormula.getStr()[0] != '=' ) 72 m_sFormula += String(_sFormula); 73 else 74 m_sFormula = _sFormula; 75 } 76 m_xParser.set(_xServiceFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.report.pentaho.SOFormulaParser"))),uno::UNO_QUERY); 77 if ( m_xParser.is() ) 78 m_xOpCodeMapper = m_xParser->getFormulaOpCodeMapper(); 79 fill(); 80 } 81 82 void FormulaDialog::notifyChange() 83 { 84 } 85 // ----------------------------------------------------------------------------- 86 void FormulaDialog::fill() 87 { 88 SetMeText(m_sFormula); 89 Update(m_sFormula); 90 CheckMatrix(m_sFormula); 91 Update(); 92 } 93 94 FormulaDialog::~FormulaDialog() 95 { 96 if ( m_pAddField ) 97 { 98 SvtViewOptions aDlgOpt( E_WINDOW, String::CreateFromAscii( HID_RPT_FIELD_SEL_WIN ) ); 99 aDlgOpt.SetWindowState( ::rtl::OUString::createFromAscii( m_pAddField->GetWindowState((WINDOWSTATE_MASK_X | WINDOWSTATE_MASK_Y | WINDOWSTATE_MASK_STATE | WINDOWSTATE_MASK_MINIMIZED)).GetBuffer() ) ); 100 101 ::std::auto_ptr<Window> aTemp2(m_pAddField); 102 m_pAddField = NULL; 103 } 104 } 105 106 // -------------------------------------------------------------------------- 107 // Funktionen fuer rechte Seite 108 // -------------------------------------------------------------------------- 109 bool FormulaDialog::calculateValue( const String& rStrExp, String& rStrResult ) 110 { 111 rStrResult = rStrExp; 112 return false; 113 } 114 void FormulaDialog::doClose(sal_Bool _bOk) 115 { 116 EndDialog(_bOk ? RET_OK : RET_CANCEL); 117 } 118 void FormulaDialog::insertEntryToLRUList(const IFunctionDescription* /*_pDesc*/) 119 { 120 } 121 void FormulaDialog::showReference(const String& /*_sFormula*/) 122 { 123 } 124 void FormulaDialog::dispatch(sal_Bool /*_bOK*/,sal_Bool /*_bMartixChecked*/) 125 { 126 } 127 void FormulaDialog::setDispatcherLock( sal_Bool /*bLock*/ ) 128 { 129 } 130 void FormulaDialog::setReferenceInput(const FormEditData* /*_pData*/) 131 { 132 } 133 void FormulaDialog::deleteFormData() 134 { 135 } 136 void FormulaDialog::clear() 137 { 138 } 139 void FormulaDialog::switchBack() 140 { 141 } 142 FormEditData* FormulaDialog::getFormEditData() const 143 { 144 return m_pFormulaData; 145 } 146 void FormulaDialog::setCurrentFormula(const String& _sReplacement) 147 { 148 const xub_StrLen nOldLen = m_nEnd - m_nStart; 149 const xub_StrLen nNewLen = _sReplacement.Len(); 150 if (nOldLen) 151 m_sFormula.Erase( m_nStart, nOldLen ); 152 if (nNewLen) 153 m_sFormula.Insert( _sReplacement, m_nStart ); 154 m_nEnd = m_nStart + nNewLen; 155 } 156 void FormulaDialog::setSelection(xub_StrLen _nStart,xub_StrLen _nEnd) 157 { 158 if ( _nStart <= _nEnd ) 159 { 160 m_nStart = _nStart; 161 m_nEnd = _nEnd; 162 } 163 else 164 { 165 m_nEnd = _nStart; 166 m_nStart = _nEnd; 167 } 168 } 169 void FormulaDialog::getSelection(xub_StrLen& _nStart,xub_StrLen& _nEnd) const 170 { 171 _nStart = m_nStart; 172 _nEnd = m_nEnd; 173 } 174 String FormulaDialog::getCurrentFormula() const 175 { 176 return m_sFormula; 177 } 178 IFunctionManager* FormulaDialog::getFunctionManager() 179 { 180 return m_aFunctionManager.get(); 181 } 182 // ----------------------------------------------------------------------------- 183 void FormulaDialog::ShowReference(const String& /*_sRef*/) 184 { 185 } 186 // ----------------------------------------------------------------------------- 187 void FormulaDialog::HideReference( sal_Bool /*bDoneRefMode*/) 188 { 189 } 190 // ----------------------------------------------------------------------------- 191 void FormulaDialog::ReleaseFocus( RefEdit* /*pEdit*/, RefButton* /*pButton*/) 192 { 193 } 194 // ----------------------------------------------------------------------------- 195 void FormulaDialog::ToggleCollapsed( RefEdit* _pEdit, RefButton* _pButton) 196 { 197 ::std::pair<RefButton*,RefEdit*> aPair = RefInputStartBefore( _pEdit, _pButton ); 198 m_pEdit = aPair.second; 199 if ( m_pEdit ) 200 m_pEdit->Hide(); 201 if ( aPair.first ) 202 aPair.first->Hide(); 203 204 if ( !m_pAddField ) 205 { 206 m_pAddField = new OAddFieldWindow(this,m_xRowSet); 207 m_pAddField->SetCreateHdl(LINK( this, FormulaDialog, OnClickHdl ) ); 208 SvtViewOptions aDlgOpt( E_WINDOW, String::CreateFromAscii( HID_RPT_FIELD_SEL_WIN ) ); 209 if ( aDlgOpt.Exists() ) 210 { 211 m_pAddField->SetWindowState( ByteString( aDlgOpt.GetWindowState().getStr(), RTL_TEXTENCODING_ASCII_US ) ); 212 213 } 214 215 m_pAddField->Update(); 216 } // if ( !m_pAddField ) 217 RefInputStartAfter( aPair.second, aPair.first ); 218 m_pAddField->Show(); 219 220 } 221 // ----------------------------------------------------------------------------- 222 IMPL_LINK( FormulaDialog, OnClickHdl, OAddFieldWindow* ,_pAddFieldDlg) 223 { 224 const uno::Sequence< beans::PropertyValue > aArgs = _pAddFieldDlg->getSelectedFieldDescriptors(); 225 // we use this way to create undo actions 226 if ( m_pEdit && aArgs.getLength() == 1) 227 { 228 uno::Sequence< beans::PropertyValue > aValue; 229 aArgs[0].Value >>= aValue; 230 ::svx::ODataAccessDescriptor aDescriptor(aValue); 231 ::rtl::OUString sName; 232 aDescriptor[ ::svx::daColumnName ] >>= sName; 233 if ( sName.getLength() ) 234 { 235 sName = ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("[")) + sName + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("]")); 236 m_pEdit->SetText(sName); 237 } 238 } // if ( m_pEdit && aArgs.getLength() ) 239 m_pEdit = NULL; 240 _pAddFieldDlg->Hide(); 241 RefInputDoneAfter( sal_True ); 242 243 return 0L; 244 } 245 // ----------------------------------------------------------------------------- 246 uno::Reference< sheet::XFormulaParser> FormulaDialog::getFormulaParser() const 247 { 248 return m_xParser.get(); 249 } 250 // ----------------------------------------------------------------------------- 251 uno::Reference< sheet::XFormulaOpCodeMapper> FormulaDialog::getFormulaOpCodeMapper() const 252 { 253 return m_xOpCodeMapper; 254 } 255 // ----------------------------------------------------------------------------- 256 table::CellAddress FormulaDialog::getReferencePosition() const 257 { 258 return table::CellAddress(); 259 } 260 // ----------------------------------------------------------------------------- 261 ::std::auto_ptr<formula::FormulaTokenArray> FormulaDialog::convertToTokenArray(const uno::Sequence< sheet::FormulaToken >& _aTokenList) 262 { 263 ::std::auto_ptr<formula::FormulaTokenArray> pArray(new FormulaTokenArray()); 264 pArray->Fill(_aTokenList, NULL); 265 return pArray; 266 } 267 // ============================================================================= 268 } // rptui 269 // ============================================================================= 270