1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "errobject.hxx"
22 #include <cppuhelper/implbase2.hxx>
23 #include <com/sun/star/script/XDefaultProperty.hpp>
24 #include "sbintern.hxx"
25 #include "runtime.hxx"
27 using namespace ::com::sun::star
;
28 using namespace ::ooo
;
30 typedef ::cppu::WeakImplHelper2
< vba::XErrObject
, script::XDefaultProperty
> ErrObjectImpl_BASE
;
32 class ErrObject
: public ErrObjectImpl_BASE
36 OUString m_sDescription
;
38 sal_Int32 m_nHelpContext
;
44 virtual ::sal_Int32 SAL_CALL
getNumber() throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
45 virtual void SAL_CALL
setNumber( ::sal_Int32 _number
) throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
46 virtual ::sal_Int32 SAL_CALL
getHelpContext() throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
47 virtual void SAL_CALL
setHelpContext( ::sal_Int32 _helpcontext
) throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
48 virtual OUString SAL_CALL
getHelpFile() throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
49 virtual void SAL_CALL
setHelpFile( const OUString
& _helpfile
) throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
50 virtual OUString SAL_CALL
getDescription() throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
51 virtual void SAL_CALL
setDescription( const OUString
& _description
) throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
52 virtual OUString SAL_CALL
getSource() throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
53 virtual void SAL_CALL
setSource( const OUString
& _source
) throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
56 virtual void SAL_CALL
Clear( ) throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
57 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
, std::exception
) SAL_OVERRIDE
;
59 virtual OUString SAL_CALL
getDefaultPropertyName( ) throw (uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
62 void setData( const uno::Any
& Number
, const uno::Any
& Source
, const uno::Any
& Description
,
63 const uno::Any
& HelpFile
, const uno::Any
& HelpContext
) throw (uno::RuntimeException
);
67 ErrObject::~ErrObject()
71 ErrObject::ErrObject() : m_nNumber(0), m_nHelpContext(0)
76 ErrObject::getNumber() throw (uno::RuntimeException
, std::exception
)
82 ErrObject::setNumber( ::sal_Int32 _number
) throw (uno::RuntimeException
, std::exception
)
84 GetSbData()->pInst
->setErrorVB( _number
, OUString() );
85 OUString _description
= GetSbData()->pInst
->GetErrorMsg();
86 setData( uno::makeAny( _number
), uno::Any(), uno::makeAny( _description
), uno::Any(), uno::Any() );
90 ErrObject::getHelpContext() throw (uno::RuntimeException
, std::exception
)
92 return m_nHelpContext
;
95 ErrObject::setHelpContext( ::sal_Int32 _helpcontext
) throw (uno::RuntimeException
, std::exception
)
97 m_nHelpContext
= _helpcontext
;
101 ErrObject::getHelpFile() throw (uno::RuntimeException
, std::exception
)
107 ErrObject::setHelpFile( const OUString
& _helpfile
) throw (uno::RuntimeException
, std::exception
)
109 m_sHelpFile
= _helpfile
;
113 ErrObject::getDescription() throw (uno::RuntimeException
, std::exception
)
115 return m_sDescription
;
119 ErrObject::setDescription( const OUString
& _description
) throw (uno::RuntimeException
, std::exception
)
121 m_sDescription
= _description
;
125 ErrObject::getSource() throw (uno::RuntimeException
, std::exception
)
131 ErrObject::setSource( const OUString
& _source
) throw (uno::RuntimeException
, std::exception
)
138 ErrObject::Clear( ) throw (uno::RuntimeException
, std::exception
)
141 m_sSource
= m_sHelpFile
;
142 m_sDescription
= m_sSource
;
148 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
, std::exception
)
150 setData( Number
, Source
, Description
, HelpFile
, HelpContext
);
152 GetSbData()->pInst
->ErrorVB( m_nNumber
, m_sDescription
);
157 ErrObject::getDefaultPropertyName( ) throw (uno::RuntimeException
, std::exception
)
159 return OUString( "Number" );
162 void ErrObject::setData( const uno::Any
& Number
, const uno::Any
& Source
, const uno::Any
& Description
, const uno::Any
& HelpFile
, const uno::Any
& HelpContext
)
163 throw (uno::RuntimeException
)
165 if ( !Number
.hasValue() )
166 throw uno::RuntimeException("Missing Required Parameter" );
167 Number
>>= m_nNumber
;
168 Description
>>= m_sDescription
;
169 Source
>>= m_sSource
;
170 HelpFile
>>= m_sHelpFile
;
171 HelpContext
>>= m_nHelpContext
;
175 SbxErrObject::SbxErrObject( const OUString
& rName
, const uno::Any
& rUnoObj
)
176 : SbUnoObject( rName
, rUnoObj
)
177 , m_pErrObject( NULL
)
179 OSL_TRACE("SbxErrObject::SbxErrObject ctor");
183 SetDfltProperty( uno::Reference
< script::XDefaultProperty
>( m_xErr
, uno::UNO_QUERY_THROW
)->getDefaultPropertyName() ) ;
184 m_pErrObject
= static_cast< ErrObject
* >( m_xErr
.get() );
188 SbxErrObject::~SbxErrObject()
190 OSL_TRACE("SbxErrObject::~SbxErrObject dtor");
193 uno::Reference
< vba::XErrObject
>
194 SbxErrObject::getUnoErrObject()
196 SbxVariable
* pVar
= getErrObject();
197 SbxErrObject
* pGlobErr
= static_cast< SbxErrObject
* >( pVar
);
198 return pGlobErr
->m_xErr
;
202 SbxErrObject::getErrObject()
204 static SbxVariableRef pGlobErr
= new SbxErrObject( OUString("Err"), uno::makeAny( uno::Reference
< vba::XErrObject
>( new ErrObject() ) ) );
208 void SbxErrObject::setNumberAndDescription( ::sal_Int32 _number
, const OUString
& _description
)
209 throw (uno::RuntimeException
)
211 if( m_pErrObject
!= NULL
)
213 m_pErrObject
->setData( uno::makeAny( _number
), uno::Any(), uno::makeAny( _description
), uno::Any(), uno::Any() );
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */