Avoid potential negative array index access to cached text.
[LibreOffice.git] / scripting / source / basprov / basmodnode.cxx
blob0ed8e91a9f97269f409fa739dd9a499969672cd9
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 "basmodnode.hxx"
21 #include "basmethnode.hxx"
22 #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
23 #include <utility>
24 #include <vcl/svapp.hxx>
25 #include <basic/sbx.hxx>
26 #include <basic/sbmod.hxx>
27 #include <basic/sbmeth.hxx>
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::lang;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::script;
36 namespace basprov
40 // BasicModuleNodeImpl
43 BasicModuleNodeImpl::BasicModuleNodeImpl( const Reference< XComponentContext >& rxContext,
44 OUString sScriptingContext, SbModule* pModule, bool isAppScript )
45 :m_xContext( rxContext )
46 ,m_sScriptingContext(std::move( sScriptingContext ))
47 ,m_pModule( pModule )
48 ,m_bIsAppScript( isAppScript )
53 BasicModuleNodeImpl::~BasicModuleNodeImpl()
58 // XBrowseNode
61 OUString BasicModuleNodeImpl::getName( )
63 SolarMutexGuard aGuard;
65 OUString sModuleName;
66 if ( m_pModule )
67 sModuleName = m_pModule->GetName();
69 return sModuleName;
73 Sequence< Reference< browse::XBrowseNode > > BasicModuleNodeImpl::getChildNodes( )
75 SolarMutexGuard aGuard;
77 Sequence< Reference< browse::XBrowseNode > > aChildNodes;
79 if ( m_pModule )
81 SbxArray* pMethods = m_pModule->GetMethods().get();
82 if ( pMethods )
84 sal_uInt32 nCount = pMethods->Count();
85 sal_Int32 nRealCount = 0;
86 for ( sal_uInt32 i = 0; i < nCount; ++i )
88 SbMethod* pMethod = static_cast<SbMethod*>(pMethods->Get(i));
89 if ( pMethod && !pMethod->IsHidden() )
90 ++nRealCount;
92 aChildNodes.realloc( nRealCount );
93 Reference< browse::XBrowseNode >* pChildNodes = aChildNodes.getArray();
95 sal_Int32 iTarget = 0;
96 for ( sal_uInt32 i = 0; i < nCount; ++i )
98 SbMethod* pMethod = static_cast<SbMethod*>(pMethods->Get(i));
99 if ( pMethod && !pMethod->IsHidden() )
100 pChildNodes[iTarget++] = new BasicMethodNodeImpl(
101 m_xContext, m_sScriptingContext, pMethod, m_bIsAppScript);
106 return aChildNodes;
110 sal_Bool BasicModuleNodeImpl::hasChildNodes( )
112 SolarMutexGuard aGuard;
114 bool bReturn = false;
115 if ( m_pModule )
117 SbxArray* pMethods = m_pModule->GetMethods().get();
118 if (pMethods && pMethods->Count() > 0)
119 bReturn = true;
122 return bReturn;
126 sal_Int16 BasicModuleNodeImpl::getType( )
128 return browse::BrowseNodeTypes::CONTAINER;
132 } // namespace basprov
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */