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_basic.hxx" 30*cdf0e10cSrcweir #include "errobject.hxx" 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 33*cdf0e10cSrcweir #include <com/sun/star/script/XDefaultProperty.hpp> 34*cdf0e10cSrcweir #include "sbintern.hxx" 35*cdf0e10cSrcweir #include "runtime.hxx" 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir using namespace ::com::sun::star; 38*cdf0e10cSrcweir using namespace ::ooo; 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir typedef ::cppu::WeakImplHelper2< vba::XErrObject, script::XDefaultProperty > ErrObjectImpl_BASE; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir class ErrObject : public ErrObjectImpl_BASE 43*cdf0e10cSrcweir { 44*cdf0e10cSrcweir rtl::OUString m_sHelpFile; 45*cdf0e10cSrcweir rtl::OUString m_sSource; 46*cdf0e10cSrcweir rtl::OUString m_sDescription; 47*cdf0e10cSrcweir sal_Int32 m_nNumber; 48*cdf0e10cSrcweir sal_Int32 m_nHelpContext; 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir public: 51*cdf0e10cSrcweir ErrObject(); 52*cdf0e10cSrcweir ~ErrObject(); 53*cdf0e10cSrcweir // Attributes 54*cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getNumber() throw (uno::RuntimeException); 55*cdf0e10cSrcweir virtual void SAL_CALL setNumber( ::sal_Int32 _number ) throw (uno::RuntimeException); 56*cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getHelpContext() throw (uno::RuntimeException); 57*cdf0e10cSrcweir virtual void SAL_CALL setHelpContext( ::sal_Int32 _helpcontext ) throw (uno::RuntimeException); 58*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getHelpFile() throw (uno::RuntimeException); 59*cdf0e10cSrcweir virtual void SAL_CALL setHelpFile( const ::rtl::OUString& _helpfile ) throw (uno::RuntimeException); 60*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getDescription() throw (uno::RuntimeException); 61*cdf0e10cSrcweir virtual void SAL_CALL setDescription( const ::rtl::OUString& _description ) throw (uno::RuntimeException); 62*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getSource() throw (uno::RuntimeException); 63*cdf0e10cSrcweir virtual void SAL_CALL setSource( const ::rtl::OUString& _source ) throw (uno::RuntimeException); 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir // Methods 66*cdf0e10cSrcweir virtual void SAL_CALL Clear( ) throw (uno::RuntimeException); 67*cdf0e10cSrcweir virtual void SAL_CALL Raise( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, const uno::Any& HelpFile, const uno::Any& HelpContext ) throw (uno::RuntimeException); 68*cdf0e10cSrcweir // XDefaultProperty 69*cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (uno::RuntimeException); 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // Helper method 72*cdf0e10cSrcweir void setData( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, 73*cdf0e10cSrcweir const uno::Any& HelpFile, const uno::Any& HelpContext ) throw (uno::RuntimeException); 74*cdf0e10cSrcweir }; 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir ErrObject::~ErrObject() 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir ErrObject::ErrObject() : m_nNumber(0), m_nHelpContext(0) 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir sal_Int32 SAL_CALL 86*cdf0e10cSrcweir ErrObject::getNumber() throw (uno::RuntimeException) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir return m_nNumber; 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir void SAL_CALL 92*cdf0e10cSrcweir ErrObject::setNumber( ::sal_Int32 _number ) throw (uno::RuntimeException) 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir pINST->setErrorVB( _number, String() ); 95*cdf0e10cSrcweir ::rtl::OUString _description = pINST->GetErrorMsg(); 96*cdf0e10cSrcweir setData( uno::makeAny( _number ), uno::Any(), uno::makeAny( _description ), uno::Any(), uno::Any() ); 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir ::sal_Int32 SAL_CALL 100*cdf0e10cSrcweir ErrObject::getHelpContext() throw (uno::RuntimeException) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir return m_nHelpContext; 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir void SAL_CALL 105*cdf0e10cSrcweir ErrObject::setHelpContext( ::sal_Int32 _helpcontext ) throw (uno::RuntimeException) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir m_nHelpContext = _helpcontext; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir ::rtl::OUString SAL_CALL 111*cdf0e10cSrcweir ErrObject::getHelpFile() throw (uno::RuntimeException) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir return m_sHelpFile; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir void SAL_CALL 117*cdf0e10cSrcweir ErrObject::setHelpFile( const ::rtl::OUString& _helpfile ) throw (uno::RuntimeException) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir m_sHelpFile = _helpfile; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir ::rtl::OUString SAL_CALL 123*cdf0e10cSrcweir ErrObject::getDescription() throw (uno::RuntimeException) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir return m_sDescription; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir void SAL_CALL 129*cdf0e10cSrcweir ErrObject::setDescription( const ::rtl::OUString& _description ) throw (uno::RuntimeException) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir m_sDescription = _description; 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir ::rtl::OUString SAL_CALL 135*cdf0e10cSrcweir ErrObject::getSource() throw (uno::RuntimeException) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir return m_sSource; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir void SAL_CALL 141*cdf0e10cSrcweir ErrObject::setSource( const ::rtl::OUString& _source ) throw (uno::RuntimeException) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir m_sSource = _source; 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir // Methods 147*cdf0e10cSrcweir void SAL_CALL 148*cdf0e10cSrcweir ErrObject::Clear( ) throw (uno::RuntimeException) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir m_sHelpFile = rtl::OUString(); 151*cdf0e10cSrcweir m_sSource = m_sHelpFile; 152*cdf0e10cSrcweir m_sDescription = m_sSource; 153*cdf0e10cSrcweir m_nNumber = 0; 154*cdf0e10cSrcweir m_nHelpContext = 0; 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir void SAL_CALL 158*cdf0e10cSrcweir ErrObject::Raise( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, const uno::Any& HelpFile, const uno::Any& HelpContext ) throw (uno::RuntimeException) 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir setData( Number, Source, Description, HelpFile, HelpContext ); 161*cdf0e10cSrcweir if ( m_nNumber ) 162*cdf0e10cSrcweir pINST->ErrorVB( m_nNumber, m_sDescription ); 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir // XDefaultProperty 166*cdf0e10cSrcweir ::rtl::OUString SAL_CALL 167*cdf0e10cSrcweir ErrObject::getDefaultPropertyName( ) throw (uno::RuntimeException) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir static rtl::OUString sDfltPropName( RTL_CONSTASCII_USTRINGPARAM("Number") ); 170*cdf0e10cSrcweir return sDfltPropName; 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir void ErrObject::setData( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, const uno::Any& HelpFile, const uno::Any& HelpContext ) 174*cdf0e10cSrcweir throw (uno::RuntimeException) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir if ( !Number.hasValue() ) 177*cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString::createFromAscii("Missing Required Paramater"), uno::Reference< uno::XInterface >() ); 178*cdf0e10cSrcweir Number >>= m_nNumber; 179*cdf0e10cSrcweir Description >>= m_sDescription; 180*cdf0e10cSrcweir Source >>= m_sSource; 181*cdf0e10cSrcweir HelpFile >>= m_sHelpFile; 182*cdf0e10cSrcweir HelpContext >>= m_nHelpContext; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir // SbxErrObject 186*cdf0e10cSrcweir SbxErrObject::SbxErrObject( const String& rName, const Any& rUnoObj ) 187*cdf0e10cSrcweir : SbUnoObject( rName, rUnoObj ) 188*cdf0e10cSrcweir , m_pErrObject( NULL ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir OSL_TRACE("SbxErrObject::SbxErrObject ctor"); 191*cdf0e10cSrcweir rUnoObj >>= m_xErr; 192*cdf0e10cSrcweir if ( m_xErr.is() ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir SetDfltProperty( uno::Reference< script::XDefaultProperty >( m_xErr, uno::UNO_QUERY_THROW )->getDefaultPropertyName() ) ; 195*cdf0e10cSrcweir m_pErrObject = static_cast< ErrObject* >( m_xErr.get() ); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir SbxErrObject::~SbxErrObject() 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir OSL_TRACE("SbxErrObject::~SbxErrObject dtor"); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir uno::Reference< vba::XErrObject > 205*cdf0e10cSrcweir SbxErrObject::getUnoErrObject() 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir SbxVariable* pVar = getErrObject(); 208*cdf0e10cSrcweir SbxErrObject* pGlobErr = static_cast< SbxErrObject* >( pVar ); 209*cdf0e10cSrcweir return pGlobErr->m_xErr; 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir SbxVariableRef 213*cdf0e10cSrcweir SbxErrObject::getErrObject() 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir static SbxVariableRef pGlobErr = new SbxErrObject( String( RTL_CONSTASCII_USTRINGPARAM("Err")), uno::makeAny( uno::Reference< vba::XErrObject >( new ErrObject() ) ) ); 216*cdf0e10cSrcweir return pGlobErr; 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir void SbxErrObject::setNumberAndDescription( ::sal_Int32 _number, const ::rtl::OUString& _description ) 220*cdf0e10cSrcweir throw (uno::RuntimeException) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir if( m_pErrObject != NULL ) 223*cdf0e10cSrcweir m_pErrObject->setData( uno::makeAny( _number ), uno::Any(), uno::makeAny( _description ), uno::Any(), uno::Any() ); 224*cdf0e10cSrcweir } 225*cdf0e10cSrcweir 226