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();
51 virtual void SAL_CALL setNumber( ::sal_Int32 _number );
52 virtual ::sal_Int32 SAL_CALL getHelpContext();
53 virtual void SAL_CALL setHelpContext( ::sal_Int32 _helpcontext );
54 virtual ::rtl::OUString SAL_CALL getHelpFile();
55 virtual void SAL_CALL setHelpFile( const ::rtl::OUString& _helpfile );
56 virtual ::rtl::OUString SAL_CALL getDescription();
57 virtual void SAL_CALL setDescription( const ::rtl::OUString& _description );
58 virtual ::rtl::OUString SAL_CALL getSource();
59 virtual void SAL_CALL setSource( const ::rtl::OUString& _source );
60
61 // Methods
62 virtual void SAL_CALL Clear( );
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 );
64 // XDefaultProperty
65 virtual ::rtl::OUString SAL_CALL getDefaultPropertyName( );
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 );
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()
83 {
84 return m_nNumber;
85 }
86
87 void SAL_CALL
setNumber(::sal_Int32 _number)88 ErrObject::setNumber( ::sal_Int32 _number )
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()
97 {
98 return m_nHelpContext;
99 }
100 void SAL_CALL
setHelpContext(::sal_Int32 _helpcontext)101 ErrObject::setHelpContext( ::sal_Int32 _helpcontext )
102 {
103 m_nHelpContext = _helpcontext;
104 }
105
106 ::rtl::OUString SAL_CALL
getHelpFile()107 ErrObject::getHelpFile()
108 {
109 return m_sHelpFile;
110 }
111
112 void SAL_CALL
setHelpFile(const::rtl::OUString & _helpfile)113 ErrObject::setHelpFile( const ::rtl::OUString& _helpfile )
114 {
115 m_sHelpFile = _helpfile;
116 }
117
118 ::rtl::OUString SAL_CALL
getDescription()119 ErrObject::getDescription()
120 {
121 return m_sDescription;
122 }
123
124 void SAL_CALL
setDescription(const::rtl::OUString & _description)125 ErrObject::setDescription( const ::rtl::OUString& _description )
126 {
127 m_sDescription = _description;
128 }
129
130 ::rtl::OUString SAL_CALL
getSource()131 ErrObject::getSource()
132 {
133 return m_sSource;
134 }
135
136 void SAL_CALL
setSource(const::rtl::OUString & _source)137 ErrObject::setSource( const ::rtl::OUString& _source )
138 {
139 m_sSource = _source;
140 }
141
142 // Methods
143 void SAL_CALL
Clear()144 ErrObject::Clear( )
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 )
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( )
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 {
171 if ( !Number.hasValue() )
172 throw uno::RuntimeException( rtl::OUString::createFromAscii("Missing Required Parameter"), uno::Reference< uno::XInterface >() );
173 Number >>= m_nNumber;
174 Description >>= m_sDescription;
175 Source >>= m_sSource;
176 HelpFile >>= m_sHelpFile;
177 HelpContext >>= m_nHelpContext;
178 }
179
180 // SbxErrObject
SbxErrObject(const String & rName,const Any & rUnoObj)181 SbxErrObject::SbxErrObject( const String& rName, const Any& rUnoObj )
182 : SbUnoObject( rName, rUnoObj )
183 , m_pErrObject( NULL )
184 {
185 OSL_TRACE("SbxErrObject::SbxErrObject ctor");
186 rUnoObj >>= m_xErr;
187 if ( m_xErr.is() )
188 {
189 SetDfltProperty( uno::Reference< script::XDefaultProperty >( m_xErr, uno::UNO_QUERY_THROW )->getDefaultPropertyName() ) ;
190 m_pErrObject = static_cast< ErrObject* >( m_xErr.get() );
191 }
192 }
193
~SbxErrObject()194 SbxErrObject::~SbxErrObject()
195 {
196 OSL_TRACE("SbxErrObject::~SbxErrObject dtor");
197 }
198
199 uno::Reference< vba::XErrObject >
getUnoErrObject()200 SbxErrObject::getUnoErrObject()
201 {
202 SbxVariable* pVar = getErrObject();
203 SbxErrObject* pGlobErr = static_cast< SbxErrObject* >( pVar );
204 return pGlobErr->m_xErr;
205 }
206
207 SbxVariableRef
getErrObject()208 SbxErrObject::getErrObject()
209 {
210 static SbxVariableRef pGlobErr = new SbxErrObject( String( RTL_CONSTASCII_USTRINGPARAM("Err")), uno::makeAny( uno::Reference< vba::XErrObject >( new ErrObject() ) ) );
211 return pGlobErr;
212 }
213
setNumberAndDescription(::sal_Int32 _number,const::rtl::OUString & _description)214 void SbxErrObject::setNumberAndDescription( ::sal_Int32 _number, const ::rtl::OUString& _description )
215 {
216 if( m_pErrObject != NULL )
217 m_pErrObject->setData( uno::makeAny( _number ), uno::Any(), uno::makeAny( _description ), uno::Any(), uno::Any() );
218 }
219
220 /* vim: set noet sw=4 ts=4: */
221