nss: upgrade to release 3.73
[LibreOffice.git] / basic / source / classes / errobject.cxx
blobb961e16983f73cebb9fe8abff1e0d281be69ac3f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <errobject.hxx>
21 #include <sbxbase.hxx>
23 #include <cppuhelper/implbase.hxx>
24 #include <com/sun/star/script/XDefaultProperty.hpp>
25 #include <sbintern.hxx>
26 #include <runtime.hxx>
28 using namespace ::com::sun::star;
29 using namespace ::ooo;
31 class ErrObject : public ::cppu::WeakImplHelper< vba::XErrObject,
32 script::XDefaultProperty >
34 OUString m_sHelpFile;
35 OUString m_sSource;
36 OUString m_sDescription;
37 sal_Int32 m_nNumber;
38 sal_Int32 m_nHelpContext;
40 public:
41 ErrObject();
43 // Attributes
44 virtual ::sal_Int32 SAL_CALL getNumber() override;
45 virtual void SAL_CALL setNumber( ::sal_Int32 _number ) override;
46 virtual ::sal_Int32 SAL_CALL getHelpContext() override;
47 virtual void SAL_CALL setHelpContext( ::sal_Int32 _helpcontext ) override;
48 virtual OUString SAL_CALL getHelpFile() override;
49 virtual void SAL_CALL setHelpFile( const OUString& _helpfile ) override;
50 virtual OUString SAL_CALL getDescription() override;
51 virtual void SAL_CALL setDescription( const OUString& _description ) override;
52 virtual OUString SAL_CALL getSource() override;
53 virtual void SAL_CALL setSource( const OUString& _source ) override;
55 // Methods
56 virtual void SAL_CALL Clear( ) override;
57 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;
58 // XDefaultProperty
59 virtual OUString SAL_CALL getDefaultPropertyName( ) override;
61 // Helper method
62 /// @throws css::uno::RuntimeException
63 void setData( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description,
64 const uno::Any& HelpFile, const uno::Any& HelpContext );
67 ErrObject::ErrObject() : m_nNumber(0), m_nHelpContext(0)
71 sal_Int32 SAL_CALL
72 ErrObject::getNumber()
74 return m_nNumber;
77 void SAL_CALL
78 ErrObject::setNumber( ::sal_Int32 _number )
80 GetSbData()->pInst->setErrorVB( _number );
81 OUString _description = GetSbData()->pInst->GetErrorMsg();
82 setData( uno::Any( _number ), uno::Any(), uno::Any( _description ), uno::Any(), uno::Any() );
85 ::sal_Int32 SAL_CALL
86 ErrObject::getHelpContext()
88 return m_nHelpContext;
90 void SAL_CALL
91 ErrObject::setHelpContext( ::sal_Int32 _helpcontext )
93 m_nHelpContext = _helpcontext;
96 OUString SAL_CALL
97 ErrObject::getHelpFile()
99 return m_sHelpFile;
102 void SAL_CALL
103 ErrObject::setHelpFile( const OUString& _helpfile )
105 m_sHelpFile = _helpfile;
108 OUString SAL_CALL
109 ErrObject::getDescription()
111 return m_sDescription;
114 void SAL_CALL
115 ErrObject::setDescription( const OUString& _description )
117 m_sDescription = _description;
120 OUString SAL_CALL
121 ErrObject::getSource()
123 return m_sSource;
126 void SAL_CALL
127 ErrObject::setSource( const OUString& _source )
129 m_sSource = _source;
132 // Methods
133 void SAL_CALL
134 ErrObject::Clear( )
136 m_sHelpFile.clear();
137 m_sSource = m_sHelpFile;
138 m_sDescription = m_sSource;
139 m_nNumber = 0;
140 m_nHelpContext = 0;
143 void SAL_CALL
144 ErrObject::Raise( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, const uno::Any& HelpFile, const uno::Any& HelpContext )
146 setData( Number, Source, Description, HelpFile, HelpContext );
147 if ( m_nNumber )
148 GetSbData()->pInst->ErrorVB( m_nNumber, m_sDescription );
151 // XDefaultProperty
152 OUString SAL_CALL
153 ErrObject::getDefaultPropertyName( )
155 return "Number";
158 void ErrObject::setData( const uno::Any& Number, const uno::Any& Source, const uno::Any& Description, const uno::Any& HelpFile, const uno::Any& HelpContext )
160 if ( !Number.hasValue() )
161 throw uno::RuntimeException("Missing Required Parameter" );
162 Number >>= m_nNumber;
163 Description >>= m_sDescription;
164 Source >>= m_sSource;
165 HelpFile >>= m_sHelpFile;
166 HelpContext >>= m_nHelpContext;
169 // SbxErrObject
170 SbxErrObject::SbxErrObject( const OUString& rName, const uno::Any& rUnoObj )
171 : SbUnoObject( rName, rUnoObj )
172 , m_pErrObject( nullptr )
174 rUnoObj >>= m_xErr;
175 if ( m_xErr.is() )
177 SetDfltProperty( uno::Reference< script::XDefaultProperty >( m_xErr, uno::UNO_QUERY_THROW )->getDefaultPropertyName() ) ;
178 m_pErrObject = static_cast< ErrObject* >( m_xErr.get() );
182 SbxErrObject::~SbxErrObject()
186 uno::Reference< vba::XErrObject > const &
187 SbxErrObject::getUnoErrObject()
189 SbxErrObject* pGlobErr = static_cast< SbxErrObject* >( getErrObject().get() );
190 return pGlobErr->m_xErr;
193 SbxVariableRef const &
194 SbxErrObject::getErrObject()
196 SbxVariableRef& rGlobErr = GetSbxData_Impl().m_aGlobErr;
198 static osl::Mutex aMutex;
199 osl::MutexGuard aGuard(aMutex);
200 if (!rGlobErr)
201 rGlobErr = new SbxErrObject("Err",
202 uno::Any(uno::Reference<vba::XErrObject>(new ErrObject())));
204 return rGlobErr;
207 void SbxErrObject::setNumberAndDescription( ::sal_Int32 _number, const OUString& _description )
209 if( m_pErrObject != nullptr )
211 m_pErrObject->setData( uno::Any( _number ), uno::Any(), uno::Any( _description ), uno::Any(), uno::Any() );
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */