1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <errobject.hxx>
21
22 #include <cppuhelper/implbase.hxx>
23 #include <com/sun/star/script/XDefaultProperty.hpp>
24 #include <sbintern.hxx>
25 #include <runtime.hxx>
26
27 using namespace ::com::sun::star;
28 using namespace ::ooo;
29
30 class ErrObject : public ::cppu::WeakImplHelper< vba::XErrObject,
31 script::XDefaultProperty >
32 {
33 OUString m_sHelpFile;
34 OUString m_sSource;
35 OUString m_sDescription;
36 sal_Int32 m_nNumber;
37 sal_Int32 m_nHelpContext;
38
39 public:
40 ErrObject();
41
42 // Attributes
43 virtual ::sal_Int32 SAL_CALL getNumber() override;
44 virtual void SAL_CALL setNumber( ::sal_Int32 _number ) override;
45 virtual ::sal_Int32 SAL_CALL getHelpContext() override;
46 virtual void SAL_CALL setHelpContext( ::sal_Int32 _helpcontext ) override;
47 virtual OUString SAL_CALL getHelpFile() override;
48 virtual void SAL_CALL setHelpFile( const OUString& _helpfile ) override;
49 virtual OUString SAL_CALL getDescription() override;
50 virtual void SAL_CALL setDescription( const OUString& _description ) override;
51 virtual OUString SAL_CALL getSource() override;
52 virtual void SAL_CALL setSource( const OUString& _source ) override;
53
54 // Methods
55 virtual void SAL_CALL Clear( ) override;
56 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 ) override;
57 // XDefaultProperty
58 virtual OUString SAL_CALL getDefaultPropertyName( ) override;
59
60 // Helper method
61 /// @throws css::uno::RuntimeException
62 void setData( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description,
63 const uno::Any& HelpFile, const uno::Any& HelpContext );
64 };
65
ErrObject()66 ErrObject::ErrObject() : m_nNumber(0), m_nHelpContext(0)
67 {
68 }
69
70 sal_Int32 SAL_CALL
getNumber()71 ErrObject::getNumber()
72 {
73 return m_nNumber;
74 }
75
76 void SAL_CALL
setNumber(::sal_Int32 _number)77 ErrObject::setNumber( ::sal_Int32 _number )
78 {
79 GetSbData()->pInst->setErrorVB( _number );
80 OUString _description = GetSbData()->pInst->GetErrorMsg();
81 setData( uno::Any( _number ), uno::Any(), uno::Any( _description ), uno::Any(), uno::Any() );
82 }
83
84 ::sal_Int32 SAL_CALL
getHelpContext()85 ErrObject::getHelpContext()
86 {
87 return m_nHelpContext;
88 }
89 void SAL_CALL
setHelpContext(::sal_Int32 _helpcontext)90 ErrObject::setHelpContext( ::sal_Int32 _helpcontext )
91 {
92 m_nHelpContext = _helpcontext;
93 }
94
95 OUString SAL_CALL
getHelpFile()96 ErrObject::getHelpFile()
97 {
98 return m_sHelpFile;
99 }
100
101 void SAL_CALL
setHelpFile(const OUString & _helpfile)102 ErrObject::setHelpFile( const OUString& _helpfile )
103 {
104 m_sHelpFile = _helpfile;
105 }
106
107 OUString SAL_CALL
getDescription()108 ErrObject::getDescription()
109 {
110 return m_sDescription;
111 }
112
113 void SAL_CALL
setDescription(const OUString & _description)114 ErrObject::setDescription( const OUString& _description )
115 {
116 m_sDescription = _description;
117 }
118
119 OUString SAL_CALL
getSource()120 ErrObject::getSource()
121 {
122 return m_sSource;
123 }
124
125 void SAL_CALL
setSource(const OUString & _source)126 ErrObject::setSource( const OUString& _source )
127 {
128 m_sSource = _source;
129 }
130
131 // Methods
132 void SAL_CALL
Clear()133 ErrObject::Clear( )
134 {
135 m_sHelpFile.clear();
136 m_sSource = m_sHelpFile;
137 m_sDescription = m_sSource;
138 m_nNumber = 0;
139 m_nHelpContext = 0;
140 }
141
142 void SAL_CALL
Raise(const uno::Any & Number,const uno::Any & Source,const uno::Any & Description,const uno::Any & HelpFile,const uno::Any & HelpContext)143 ErrObject::Raise( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, const uno::Any& HelpFile, const uno::Any& HelpContext )
144 {
145 setData( Number, Source, Description, HelpFile, HelpContext );
146 if ( m_nNumber )
147 GetSbData()->pInst->ErrorVB( m_nNumber, m_sDescription );
148 }
149
150 // XDefaultProperty
151 OUString SAL_CALL
getDefaultPropertyName()152 ErrObject::getDefaultPropertyName( )
153 {
154 return "Number";
155 }
156
setData(const uno::Any & Number,const uno::Any & Source,const uno::Any & Description,const uno::Any & HelpFile,const uno::Any & HelpContext)157 void ErrObject::setData( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, const uno::Any& HelpFile, const uno::Any& HelpContext )
158 {
159 if ( !Number.hasValue() )
160 throw uno::RuntimeException("Missing Required Parameter" );
161 Number >>= m_nNumber;
162 Description >>= m_sDescription;
163 Source >>= m_sSource;
164 HelpFile >>= m_sHelpFile;
165 HelpContext >>= m_nHelpContext;
166 }
167
168 // SbxErrObject
SbxErrObject(const OUString & rName,const uno::Any & rUnoObj)169 SbxErrObject::SbxErrObject( const OUString& rName, const uno::Any& rUnoObj )
170 : SbUnoObject( rName, rUnoObj )
171 , m_pErrObject( nullptr )
172 {
173 rUnoObj >>= m_xErr;
174 if ( m_xErr.is() )
175 {
176 SetDfltProperty( uno::Reference< script::XDefaultProperty >( m_xErr, uno::UNO_QUERY_THROW )->getDefaultPropertyName() ) ;
177 m_pErrObject = static_cast< ErrObject* >( m_xErr.get() );
178 }
179 }
180
~SbxErrObject()181 SbxErrObject::~SbxErrObject()
182 {
183 }
184
185 uno::Reference< vba::XErrObject > const &
getUnoErrObject()186 SbxErrObject::getUnoErrObject()
187 {
188 SbxErrObject* pGlobErr = static_cast< SbxErrObject* >( getErrObject().get() );
189 return pGlobErr->m_xErr;
190 }
191
192 SbxVariableRef const &
getErrObject()193 SbxErrObject::getErrObject()
194 {
195 static SbxVariableRef pGlobErr = new SbxErrObject( "Err", uno::Any( uno::Reference< vba::XErrObject >( new ErrObject() ) ) );
196 return pGlobErr;
197 }
198
setNumberAndDescription(::sal_Int32 _number,const OUString & _description)199 void SbxErrObject::setNumberAndDescription( ::sal_Int32 _number, const OUString& _description )
200 {
201 if( m_pErrObject != nullptr )
202 {
203 m_pErrObject->setData( uno::Any( _number ), uno::Any(), uno::Any( _description ), uno::Any(), uno::Any() );
204 }
205 }
206
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
208