1*e1f63238SAndrew Rist /************************************************************** 2*e1f63238SAndrew Rist * 3*e1f63238SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*e1f63238SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*e1f63238SAndrew Rist * distributed with this work for additional information 6*e1f63238SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*e1f63238SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*e1f63238SAndrew Rist * "License"); you may not use this file except in compliance 9*e1f63238SAndrew Rist * with the License. You may obtain a copy of the License at 10*e1f63238SAndrew Rist * 11*e1f63238SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*e1f63238SAndrew Rist * 13*e1f63238SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*e1f63238SAndrew Rist * software distributed under the License is distributed on an 15*e1f63238SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*e1f63238SAndrew Rist * KIND, either express or implied. See the License for the 17*e1f63238SAndrew Rist * specific language governing permissions and limitations 18*e1f63238SAndrew Rist * under the License. 19*e1f63238SAndrew Rist * 20*e1f63238SAndrew Rist *************************************************************/ 21*e1f63238SAndrew Rist 22*e1f63238SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_basic.hxx" 26cdf0e10cSrcweir #include "errobject.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 29cdf0e10cSrcweir #include <com/sun/star/script/XDefaultProperty.hpp> 30cdf0e10cSrcweir #include "sbintern.hxx" 31cdf0e10cSrcweir #include "runtime.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir using namespace ::com::sun::star; 34cdf0e10cSrcweir using namespace ::ooo; 35cdf0e10cSrcweir 36cdf0e10cSrcweir typedef ::cppu::WeakImplHelper2< vba::XErrObject, script::XDefaultProperty > ErrObjectImpl_BASE; 37cdf0e10cSrcweir 38cdf0e10cSrcweir class ErrObject : public ErrObjectImpl_BASE 39cdf0e10cSrcweir { 40cdf0e10cSrcweir rtl::OUString m_sHelpFile; 41cdf0e10cSrcweir rtl::OUString m_sSource; 42cdf0e10cSrcweir rtl::OUString m_sDescription; 43cdf0e10cSrcweir sal_Int32 m_nNumber; 44cdf0e10cSrcweir sal_Int32 m_nHelpContext; 45cdf0e10cSrcweir 46cdf0e10cSrcweir public: 47cdf0e10cSrcweir ErrObject(); 48cdf0e10cSrcweir ~ErrObject(); 49cdf0e10cSrcweir // Attributes 50cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getNumber() throw (uno::RuntimeException); 51cdf0e10cSrcweir virtual void SAL_CALL setNumber( ::sal_Int32 _number ) throw (uno::RuntimeException); 52cdf0e10cSrcweir virtual ::sal_Int32 SAL_CALL getHelpContext() throw (uno::RuntimeException); 53cdf0e10cSrcweir virtual void SAL_CALL setHelpContext( ::sal_Int32 _helpcontext ) throw (uno::RuntimeException); 54cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getHelpFile() throw (uno::RuntimeException); 55cdf0e10cSrcweir virtual void SAL_CALL setHelpFile( const ::rtl::OUString& _helpfile ) throw (uno::RuntimeException); 56cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getDescription() throw (uno::RuntimeException); 57cdf0e10cSrcweir virtual void SAL_CALL setDescription( const ::rtl::OUString& _description ) throw (uno::RuntimeException); 58cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getSource() throw (uno::RuntimeException); 59cdf0e10cSrcweir virtual void SAL_CALL setSource( const ::rtl::OUString& _source ) throw (uno::RuntimeException); 60cdf0e10cSrcweir 61cdf0e10cSrcweir // Methods 62cdf0e10cSrcweir virtual void SAL_CALL Clear( ) throw (uno::RuntimeException); 63cdf0e10cSrcweir 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); 64cdf0e10cSrcweir // XDefaultProperty 65cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (uno::RuntimeException); 66cdf0e10cSrcweir 67cdf0e10cSrcweir // Helper method 68cdf0e10cSrcweir void setData( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, 69cdf0e10cSrcweir const uno::Any& HelpFile, const uno::Any& HelpContext ) throw (uno::RuntimeException); 70cdf0e10cSrcweir }; 71cdf0e10cSrcweir 72cdf0e10cSrcweir 73cdf0e10cSrcweir ErrObject::~ErrObject() 74cdf0e10cSrcweir { 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir ErrObject::ErrObject() : m_nNumber(0), m_nHelpContext(0) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir sal_Int32 SAL_CALL 82cdf0e10cSrcweir ErrObject::getNumber() throw (uno::RuntimeException) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir return m_nNumber; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir void SAL_CALL 88cdf0e10cSrcweir ErrObject::setNumber( ::sal_Int32 _number ) throw (uno::RuntimeException) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir pINST->setErrorVB( _number, String() ); 91cdf0e10cSrcweir ::rtl::OUString _description = pINST->GetErrorMsg(); 92cdf0e10cSrcweir setData( uno::makeAny( _number ), uno::Any(), uno::makeAny( _description ), uno::Any(), uno::Any() ); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir ::sal_Int32 SAL_CALL 96cdf0e10cSrcweir ErrObject::getHelpContext() throw (uno::RuntimeException) 97cdf0e10cSrcweir { 98cdf0e10cSrcweir return m_nHelpContext; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir void SAL_CALL 101cdf0e10cSrcweir ErrObject::setHelpContext( ::sal_Int32 _helpcontext ) throw (uno::RuntimeException) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir m_nHelpContext = _helpcontext; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir ::rtl::OUString SAL_CALL 107cdf0e10cSrcweir ErrObject::getHelpFile() throw (uno::RuntimeException) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir return m_sHelpFile; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir void SAL_CALL 113cdf0e10cSrcweir ErrObject::setHelpFile( const ::rtl::OUString& _helpfile ) throw (uno::RuntimeException) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir m_sHelpFile = _helpfile; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir ::rtl::OUString SAL_CALL 119cdf0e10cSrcweir ErrObject::getDescription() throw (uno::RuntimeException) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir return m_sDescription; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir void SAL_CALL 125cdf0e10cSrcweir ErrObject::setDescription( const ::rtl::OUString& _description ) throw (uno::RuntimeException) 126cdf0e10cSrcweir { 127cdf0e10cSrcweir m_sDescription = _description; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir ::rtl::OUString SAL_CALL 131cdf0e10cSrcweir ErrObject::getSource() throw (uno::RuntimeException) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir return m_sSource; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir void SAL_CALL 137cdf0e10cSrcweir ErrObject::setSource( const ::rtl::OUString& _source ) throw (uno::RuntimeException) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir m_sSource = _source; 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir // Methods 143cdf0e10cSrcweir void SAL_CALL 144cdf0e10cSrcweir ErrObject::Clear( ) throw (uno::RuntimeException) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir m_sHelpFile = rtl::OUString(); 147cdf0e10cSrcweir m_sSource = m_sHelpFile; 148cdf0e10cSrcweir m_sDescription = m_sSource; 149cdf0e10cSrcweir m_nNumber = 0; 150cdf0e10cSrcweir m_nHelpContext = 0; 151cdf0e10cSrcweir } 152cdf0e10cSrcweir 153cdf0e10cSrcweir void SAL_CALL 154cdf0e10cSrcweir 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) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir setData( Number, Source, Description, HelpFile, HelpContext ); 157cdf0e10cSrcweir if ( m_nNumber ) 158cdf0e10cSrcweir pINST->ErrorVB( m_nNumber, m_sDescription ); 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir // XDefaultProperty 162cdf0e10cSrcweir ::rtl::OUString SAL_CALL 163cdf0e10cSrcweir ErrObject::getDefaultPropertyName( ) throw (uno::RuntimeException) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir static rtl::OUString sDfltPropName( RTL_CONSTASCII_USTRINGPARAM("Number") ); 166cdf0e10cSrcweir return sDfltPropName; 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir void ErrObject::setData( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, const uno::Any& HelpFile, const uno::Any& HelpContext ) 170cdf0e10cSrcweir throw (uno::RuntimeException) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir if ( !Number.hasValue() ) 173cdf0e10cSrcweir throw uno::RuntimeException( rtl::OUString::createFromAscii("Missing Required Paramater"), uno::Reference< uno::XInterface >() ); 174cdf0e10cSrcweir Number >>= m_nNumber; 175cdf0e10cSrcweir Description >>= m_sDescription; 176cdf0e10cSrcweir Source >>= m_sSource; 177cdf0e10cSrcweir HelpFile >>= m_sHelpFile; 178cdf0e10cSrcweir HelpContext >>= m_nHelpContext; 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir // SbxErrObject 182cdf0e10cSrcweir SbxErrObject::SbxErrObject( const String& rName, const Any& rUnoObj ) 183cdf0e10cSrcweir : SbUnoObject( rName, rUnoObj ) 184cdf0e10cSrcweir , m_pErrObject( NULL ) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir OSL_TRACE("SbxErrObject::SbxErrObject ctor"); 187cdf0e10cSrcweir rUnoObj >>= m_xErr; 188cdf0e10cSrcweir if ( m_xErr.is() ) 189cdf0e10cSrcweir { 190cdf0e10cSrcweir SetDfltProperty( uno::Reference< script::XDefaultProperty >( m_xErr, uno::UNO_QUERY_THROW )->getDefaultPropertyName() ) ; 191cdf0e10cSrcweir m_pErrObject = static_cast< ErrObject* >( m_xErr.get() ); 192cdf0e10cSrcweir } 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir SbxErrObject::~SbxErrObject() 196cdf0e10cSrcweir { 197cdf0e10cSrcweir OSL_TRACE("SbxErrObject::~SbxErrObject dtor"); 198cdf0e10cSrcweir } 199cdf0e10cSrcweir 200cdf0e10cSrcweir uno::Reference< vba::XErrObject > 201cdf0e10cSrcweir SbxErrObject::getUnoErrObject() 202cdf0e10cSrcweir { 203cdf0e10cSrcweir SbxVariable* pVar = getErrObject(); 204cdf0e10cSrcweir SbxErrObject* pGlobErr = static_cast< SbxErrObject* >( pVar ); 205cdf0e10cSrcweir return pGlobErr->m_xErr; 206cdf0e10cSrcweir } 207cdf0e10cSrcweir 208cdf0e10cSrcweir SbxVariableRef 209cdf0e10cSrcweir SbxErrObject::getErrObject() 210cdf0e10cSrcweir { 211cdf0e10cSrcweir static SbxVariableRef pGlobErr = new SbxErrObject( String( RTL_CONSTASCII_USTRINGPARAM("Err")), uno::makeAny( uno::Reference< vba::XErrObject >( new ErrObject() ) ) ); 212cdf0e10cSrcweir return pGlobErr; 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir void SbxErrObject::setNumberAndDescription( ::sal_Int32 _number, const ::rtl::OUString& _description ) 216cdf0e10cSrcweir throw (uno::RuntimeException) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir if( m_pErrObject != NULL ) 219cdf0e10cSrcweir m_pErrObject->setData( uno::makeAny( _number ), uno::Any(), uno::makeAny( _description ), uno::Any(), uno::Any() ); 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222