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