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