xref: /trunk/main/basic/source/classes/errobject.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org.  If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basic.hxx"
30 #include "errobject.hxx"
31 
32 #include <cppuhelper/implbase2.hxx>
33 #include <com/sun/star/script/XDefaultProperty.hpp>
34 #include "sbintern.hxx"
35 #include "runtime.hxx"
36 
37 using namespace ::com::sun::star;
38 using namespace ::ooo;
39 
40 typedef ::cppu::WeakImplHelper2< vba::XErrObject, script::XDefaultProperty > ErrObjectImpl_BASE;
41 
42 class ErrObject : public ErrObjectImpl_BASE
43 {
44     rtl::OUString m_sHelpFile;
45     rtl::OUString m_sSource;
46     rtl::OUString m_sDescription;
47     sal_Int32 m_nNumber;
48     sal_Int32 m_nHelpContext;
49 
50 public:
51     ErrObject();
52     ~ErrObject();
53     // Attributes
54     virtual ::sal_Int32 SAL_CALL getNumber() throw (uno::RuntimeException);
55     virtual void SAL_CALL setNumber( ::sal_Int32 _number ) throw (uno::RuntimeException);
56     virtual ::sal_Int32 SAL_CALL getHelpContext() throw (uno::RuntimeException);
57     virtual void SAL_CALL setHelpContext( ::sal_Int32 _helpcontext ) throw (uno::RuntimeException);
58     virtual ::rtl::OUString SAL_CALL getHelpFile() throw (uno::RuntimeException);
59     virtual void SAL_CALL setHelpFile( const ::rtl::OUString& _helpfile ) throw (uno::RuntimeException);
60     virtual ::rtl::OUString SAL_CALL getDescription() throw (uno::RuntimeException);
61     virtual void SAL_CALL setDescription( const ::rtl::OUString& _description ) throw (uno::RuntimeException);
62     virtual ::rtl::OUString SAL_CALL getSource() throw (uno::RuntimeException);
63     virtual void SAL_CALL setSource( const ::rtl::OUString& _source ) throw (uno::RuntimeException);
64 
65     // Methods
66     virtual void SAL_CALL Clear(  ) throw (uno::RuntimeException);
67     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);
68     // XDefaultProperty
69     virtual ::rtl::OUString SAL_CALL getDefaultPropertyName(  ) throw (uno::RuntimeException);
70 
71     // Helper method
72     void setData( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description,
73         const uno::Any& HelpFile, const uno::Any& HelpContext ) throw (uno::RuntimeException);
74 };
75 
76 
77 ErrObject::~ErrObject()
78 {
79 }
80 
81 ErrObject::ErrObject() : m_nNumber(0), m_nHelpContext(0)
82 {
83 }
84 
85 sal_Int32 SAL_CALL
86 ErrObject::getNumber() throw (uno::RuntimeException)
87 {
88     return m_nNumber;
89 }
90 
91 void SAL_CALL
92 ErrObject::setNumber( ::sal_Int32 _number ) throw (uno::RuntimeException)
93 {
94     pINST->setErrorVB( _number, String() );
95     ::rtl::OUString _description = pINST->GetErrorMsg();
96     setData( uno::makeAny( _number ), uno::Any(), uno::makeAny( _description ), uno::Any(), uno::Any() );
97 }
98 
99 ::sal_Int32 SAL_CALL
100 ErrObject::getHelpContext() throw (uno::RuntimeException)
101 {
102     return m_nHelpContext;
103 }
104 void SAL_CALL
105 ErrObject::setHelpContext( ::sal_Int32 _helpcontext ) throw (uno::RuntimeException)
106 {
107     m_nHelpContext = _helpcontext;
108 }
109 
110 ::rtl::OUString SAL_CALL
111 ErrObject::getHelpFile() throw (uno::RuntimeException)
112 {
113     return m_sHelpFile;
114 }
115 
116 void SAL_CALL
117 ErrObject::setHelpFile( const ::rtl::OUString& _helpfile ) throw (uno::RuntimeException)
118 {
119     m_sHelpFile = _helpfile;
120 }
121 
122 ::rtl::OUString SAL_CALL
123 ErrObject::getDescription() throw (uno::RuntimeException)
124 {
125     return m_sDescription;
126 }
127 
128 void SAL_CALL
129 ErrObject::setDescription( const ::rtl::OUString& _description ) throw (uno::RuntimeException)
130 {
131     m_sDescription = _description;
132 }
133 
134 ::rtl::OUString SAL_CALL
135 ErrObject::getSource() throw (uno::RuntimeException)
136 {
137     return m_sSource;
138 }
139 
140 void SAL_CALL
141 ErrObject::setSource( const ::rtl::OUString& _source ) throw (uno::RuntimeException)
142 {
143     m_sSource = _source;
144 }
145 
146 // Methods
147 void SAL_CALL
148 ErrObject::Clear(  ) throw (uno::RuntimeException)
149 {
150     m_sHelpFile = rtl::OUString();
151     m_sSource = m_sHelpFile;
152     m_sDescription = m_sSource;
153     m_nNumber = 0;
154     m_nHelpContext = 0;
155 }
156 
157 void SAL_CALL
158 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)
159 {
160     setData( Number, Source, Description, HelpFile, HelpContext );
161     if ( m_nNumber )
162         pINST->ErrorVB( m_nNumber, m_sDescription );
163 }
164 
165 // XDefaultProperty
166 ::rtl::OUString SAL_CALL
167 ErrObject::getDefaultPropertyName(  ) throw (uno::RuntimeException)
168 {
169     static rtl::OUString sDfltPropName( RTL_CONSTASCII_USTRINGPARAM("Number") );
170     return sDfltPropName;
171 }
172 
173 void ErrObject::setData( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, const uno::Any& HelpFile, const uno::Any& HelpContext )
174     throw (uno::RuntimeException)
175 {
176     if ( !Number.hasValue() )
177         throw uno::RuntimeException( rtl::OUString::createFromAscii("Missing Required Paramater"), uno::Reference< uno::XInterface >() );
178     Number >>= m_nNumber;
179     Description >>= m_sDescription;
180     Source >>= m_sSource;
181     HelpFile >>= m_sHelpFile;
182     HelpContext >>= m_nHelpContext;
183 }
184 
185 // SbxErrObject
186 SbxErrObject::SbxErrObject( const String& rName, const Any& rUnoObj )
187     : SbUnoObject( rName, rUnoObj )
188     , m_pErrObject( NULL )
189 {
190     OSL_TRACE("SbxErrObject::SbxErrObject ctor");
191     rUnoObj >>= m_xErr;
192     if ( m_xErr.is() )
193     {
194         SetDfltProperty( uno::Reference< script::XDefaultProperty >( m_xErr, uno::UNO_QUERY_THROW )->getDefaultPropertyName() ) ;
195         m_pErrObject = static_cast< ErrObject* >( m_xErr.get() );
196     }
197 }
198 
199 SbxErrObject::~SbxErrObject()
200 {
201     OSL_TRACE("SbxErrObject::~SbxErrObject dtor");
202 }
203 
204 uno::Reference< vba::XErrObject >
205 SbxErrObject::getUnoErrObject()
206 {
207     SbxVariable* pVar = getErrObject();
208     SbxErrObject* pGlobErr = static_cast< SbxErrObject* >(  pVar );
209     return pGlobErr->m_xErr;
210 }
211 
212 SbxVariableRef
213 SbxErrObject::getErrObject()
214 {
215     static SbxVariableRef pGlobErr = new SbxErrObject( String(  RTL_CONSTASCII_USTRINGPARAM("Err")), uno::makeAny( uno::Reference< vba::XErrObject >( new ErrObject() ) ) );
216     return pGlobErr;
217 }
218 
219 void SbxErrObject::setNumberAndDescription( ::sal_Int32 _number, const ::rtl::OUString& _description )
220     throw (uno::RuntimeException)
221 {
222     if( m_pErrObject != NULL )
223         m_pErrObject->setData( uno::makeAny( _number ), uno::Any(), uno::makeAny( _description ), uno::Any(), uno::Any() );
224 }
225 
226