Debian Codegraph @

basic/source/classes/errobject.cxx

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