merge the formfield patch from ooo-build
[ooovba.git] / basic / source / classes / errobject.cxx
blob4005d852d32f8870368c3f37c427d4992e546e1f
1 // MARKER(update_precomp.py): autogen include statement, do not remove
2 #include "precompiled_basic.hxx"
3 #include "errobject.hxx"
5 #include <cppuhelper/implbase2.hxx>
6 #include <com/sun/star/script/XDefaultProperty.hpp>
7 #include "sbintern.hxx"
8 #include "runtime.hxx"
10 using namespace ::com::sun::star;
11 using namespace ::ooo;
13 typedef ::cppu::WeakImplHelper2< vba::XErrObject, script::XDefaultProperty > ErrObjectImpl_BASE;
15 class ErrObject : public ErrObjectImpl_BASE
17 rtl::OUString m_sHelpFile;
18 rtl::OUString m_sSource;
19 rtl::OUString m_sDescription;
20 sal_Int32 m_nNumber;
21 sal_Int32 m_nHelpContext;
23 public:
24 ErrObject();
25 ~ErrObject();
26 // Attributes
27 virtual ::sal_Int32 SAL_CALL getNumber() throw (uno::RuntimeException);
28 virtual void SAL_CALL setNumber( ::sal_Int32 _number ) throw (uno::RuntimeException);
29 virtual ::sal_Int32 SAL_CALL getHelpContext() throw (uno::RuntimeException);
30 virtual void SAL_CALL setHelpContext( ::sal_Int32 _helpcontext ) throw (uno::RuntimeException);
31 virtual ::rtl::OUString SAL_CALL getHelpFile() throw (uno::RuntimeException);
32 virtual void SAL_CALL setHelpFile( const ::rtl::OUString& _helpfile ) throw (uno::RuntimeException);
33 virtual ::rtl::OUString SAL_CALL getDescription() throw (uno::RuntimeException);
34 virtual void SAL_CALL setDescription( const ::rtl::OUString& _description ) throw (uno::RuntimeException);
35 virtual ::rtl::OUString SAL_CALL getSource() throw (uno::RuntimeException);
36 virtual void SAL_CALL setSource( const ::rtl::OUString& _source ) throw (uno::RuntimeException);
38 // Methods
39 virtual void SAL_CALL Clear( ) throw (uno::RuntimeException);
40 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);
41 // XDefaultProperty
42 virtual ::rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (uno::RuntimeException);
46 ErrObject::~ErrObject()
50 ErrObject::ErrObject() : m_nNumber(0), m_nHelpContext(0)
54 sal_Int32 SAL_CALL
55 ErrObject::getNumber() throw (uno::RuntimeException)
57 return m_nNumber;
60 void SAL_CALL
61 ErrObject::setNumber( ::sal_Int32 _number ) throw (uno::RuntimeException)
63 m_nNumber = _number;
68 ::sal_Int32 SAL_CALL
69 ErrObject::getHelpContext() throw (uno::RuntimeException)
71 return m_nHelpContext;
73 void SAL_CALL
74 ErrObject::setHelpContext( ::sal_Int32 _helpcontext ) throw (uno::RuntimeException)
76 m_nHelpContext = _helpcontext;
79 ::rtl::OUString SAL_CALL
80 ErrObject::getHelpFile() throw (uno::RuntimeException)
82 return m_sHelpFile;
85 void SAL_CALL
86 ErrObject::setHelpFile( const ::rtl::OUString& _helpfile ) throw (uno::RuntimeException)
88 m_sHelpFile = _helpfile;
91 ::rtl::OUString SAL_CALL
92 ErrObject::getDescription() throw (uno::RuntimeException)
94 return m_sDescription;
97 void SAL_CALL
98 ErrObject::setDescription( const ::rtl::OUString& _description ) throw (uno::RuntimeException)
100 m_sDescription = _description;
103 ::rtl::OUString SAL_CALL
104 ErrObject::getSource() throw (uno::RuntimeException)
106 return m_sSource;
109 void SAL_CALL
110 ErrObject::setSource( const ::rtl::OUString& _source ) throw (uno::RuntimeException)
112 m_sSource = _source;
115 // Methods
116 void SAL_CALL
117 ErrObject::Clear( ) throw (uno::RuntimeException)
119 m_sHelpFile = rtl::OUString();
120 m_sSource = m_sHelpFile;
121 m_sDescription = m_sSource;
122 m_nNumber = 0;
123 m_nHelpContext = 0;
126 void SAL_CALL
127 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)
129 if ( !Number.hasValue() )
130 throw uno::RuntimeException( rtl::OUString::createFromAscii("Missing Required Paramater"), uno::Reference< uno::XInterface >() );
131 Description >>= m_sDescription;
132 Source >>= m_sSource;
133 HelpFile >>= m_sHelpFile;
134 HelpContext >>= m_nHelpContext;
135 Number >>= m_nNumber;
136 if ( m_nNumber )
138 SbError n = StarBASIC::GetSfxFromVBError( m_nNumber );
139 if ( !n )
140 n = m_nNumber; // force orig number, probably should have a specific table of vb ( localized ) errors
141 pINST->Error( n, m_sDescription );
145 // XDefaultProperty
146 ::rtl::OUString SAL_CALL
147 ErrObject::getDefaultPropertyName( ) throw (uno::RuntimeException)
149 static rtl::OUString sDfltPropName( RTL_CONSTASCII_USTRINGPARAM("Number") );
150 return sDfltPropName;
153 // SbxErrObject
154 SbxErrObject::SbxErrObject( const String& rName, const Any& rUnoObj ): SbUnoObject( rName, rUnoObj )
156 OSL_TRACE("SbxErrObject::SbxErrObject ctor");
157 rUnoObj >>= m_xErr;
158 if ( m_xErr.is() )
159 SetDfltProperty( uno::Reference< script::XDefaultProperty >( m_xErr, uno::UNO_QUERY_THROW )->getDefaultPropertyName() ) ;
162 SbxErrObject::~SbxErrObject()
164 OSL_TRACE("SbxErrObject::~SbxErrObject dtor");
167 uno::Reference< vba::XErrObject >
168 SbxErrObject::getUnoErrObject()
170 SbxVariable* pVar = getErrObject();
171 SbxErrObject* pGlobErr = static_cast< SbxErrObject* >( pVar );
172 return pGlobErr->m_xErr;
175 SbxVariableRef
176 SbxErrObject::getErrObject()
178 static SbxVariableRef pGlobErr = new SbxErrObject( String( RTL_CONSTASCII_USTRINGPARAM("Err")), uno::makeAny( uno::Reference< vba::XErrObject >( new ErrObject() ) ) );
179 return pGlobErr;