1*2c696243SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2c696243SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2c696243SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2c696243SAndrew Rist  * distributed with this work for additional information
6*2c696243SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2c696243SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2c696243SAndrew Rist  * "License"); you may not use this file except in compliance
9*2c696243SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2c696243SAndrew Rist  *
11*2c696243SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2c696243SAndrew Rist  *
13*2c696243SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2c696243SAndrew Rist  * software distributed under the License is distributed on an
15*2c696243SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2c696243SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2c696243SAndrew Rist  * specific language governing permissions and limitations
18*2c696243SAndrew Rist  * under the License.
19*2c696243SAndrew Rist  *
20*2c696243SAndrew Rist  *************************************************************/
21*2c696243SAndrew Rist 
22*2c696243SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_scripting.hxx"
26cdf0e10cSrcweir #include "basmodnode.hxx"
27cdf0e10cSrcweir #include "basmethnode.hxx"
28cdf0e10cSrcweir #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
29cdf0e10cSrcweir #include <vos/mutex.hxx>
30cdf0e10cSrcweir #include <vcl/svapp.hxx>
31cdf0e10cSrcweir #include <basic/sbx.hxx>
32cdf0e10cSrcweir #include <basic/sbstar.hxx>
33cdf0e10cSrcweir #include <basic/sbmod.hxx>
34cdf0e10cSrcweir #include <basic/sbmeth.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace ::com::sun::star;
38cdf0e10cSrcweir using namespace ::com::sun::star::lang;
39cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir using namespace ::com::sun::star::script;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //.........................................................................
44cdf0e10cSrcweir namespace basprov
45cdf0e10cSrcweir {
46cdf0e10cSrcweir //.........................................................................
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     // =============================================================================
49cdf0e10cSrcweir     // BasicModuleNodeImpl
50cdf0e10cSrcweir     // =============================================================================
51cdf0e10cSrcweir 
BasicModuleNodeImpl(const Reference<XComponentContext> & rxContext,const::rtl::OUString & sScriptingContext,SbModule * pModule,bool isAppScript)52cdf0e10cSrcweir     BasicModuleNodeImpl::BasicModuleNodeImpl( const Reference< XComponentContext >& rxContext,
53cdf0e10cSrcweir         const ::rtl::OUString& sScriptingContext, SbModule* pModule, bool isAppScript )
54cdf0e10cSrcweir         :m_xContext( rxContext )
55cdf0e10cSrcweir         ,m_sScriptingContext( sScriptingContext )
56cdf0e10cSrcweir         ,m_pModule( pModule )
57cdf0e10cSrcweir         ,m_bIsAppScript( isAppScript )
58cdf0e10cSrcweir     {
59cdf0e10cSrcweir     }
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     // -----------------------------------------------------------------------------
62cdf0e10cSrcweir 
~BasicModuleNodeImpl()63cdf0e10cSrcweir     BasicModuleNodeImpl::~BasicModuleNodeImpl()
64cdf0e10cSrcweir     {
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     // -----------------------------------------------------------------------------
68cdf0e10cSrcweir     // XBrowseNode
69cdf0e10cSrcweir     // -----------------------------------------------------------------------------
70cdf0e10cSrcweir 
getName()71cdf0e10cSrcweir     ::rtl::OUString BasicModuleNodeImpl::getName(  ) throw (RuntimeException)
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         ::rtl::OUString sModuleName;
76cdf0e10cSrcweir         if ( m_pModule )
77cdf0e10cSrcweir             sModuleName = m_pModule->GetName();
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         return sModuleName;
80cdf0e10cSrcweir     }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir     // -----------------------------------------------------------------------------
83cdf0e10cSrcweir 
getChildNodes()84cdf0e10cSrcweir     Sequence< Reference< browse::XBrowseNode > > BasicModuleNodeImpl::getChildNodes(  ) throw (RuntimeException)
85cdf0e10cSrcweir     {
86cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         Sequence< Reference< browse::XBrowseNode > > aChildNodes;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         if ( m_pModule )
91cdf0e10cSrcweir         {
92cdf0e10cSrcweir             SbxArray* pMethods = m_pModule->GetMethods();
93cdf0e10cSrcweir             if ( pMethods )
94cdf0e10cSrcweir             {
95cdf0e10cSrcweir                 sal_Int32 nCount = pMethods->Count();
96cdf0e10cSrcweir                 sal_Int32 nRealCount = 0;
97cdf0e10cSrcweir                 for ( sal_Int32 i = 0; i < nCount; ++i )
98cdf0e10cSrcweir                 {
99cdf0e10cSrcweir 					SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Get( static_cast< sal_uInt16 >( i ) ) );
100cdf0e10cSrcweir                     if ( pMethod && !pMethod->IsHidden() )
101cdf0e10cSrcweir 						++nRealCount;
102cdf0e10cSrcweir 				}
103cdf0e10cSrcweir                 aChildNodes.realloc( nRealCount );
104cdf0e10cSrcweir                 Reference< browse::XBrowseNode >* pChildNodes = aChildNodes.getArray();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 				sal_Int32 iTarget = 0;
107cdf0e10cSrcweir                 for ( sal_Int32 i = 0; i < nCount; ++i )
108cdf0e10cSrcweir                 {
109cdf0e10cSrcweir 					SbMethod* pMethod = static_cast< SbMethod* >( pMethods->Get( static_cast< sal_uInt16 >( i ) ) );
110cdf0e10cSrcweir                     if ( pMethod && !pMethod->IsHidden() )
111cdf0e10cSrcweir                         pChildNodes[iTarget++] = static_cast< browse::XBrowseNode* >( new BasicMethodNodeImpl( m_xContext, m_sScriptingContext, pMethod, m_bIsAppScript ) );
112cdf0e10cSrcweir                 }
113cdf0e10cSrcweir             }
114cdf0e10cSrcweir         }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir         return aChildNodes;
117cdf0e10cSrcweir     }
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     // -----------------------------------------------------------------------------
120cdf0e10cSrcweir 
hasChildNodes()121cdf0e10cSrcweir     sal_Bool BasicModuleNodeImpl::hasChildNodes(  ) throw (RuntimeException)
122cdf0e10cSrcweir     {
123cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         sal_Bool bReturn = sal_False;
126cdf0e10cSrcweir         if ( m_pModule )
127cdf0e10cSrcweir         {
128cdf0e10cSrcweir             SbxArray* pMethods = m_pModule->GetMethods();
129cdf0e10cSrcweir             if ( pMethods && pMethods->Count() > 0 )
130cdf0e10cSrcweir                 bReturn = sal_True;
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         return bReturn;
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     // -----------------------------------------------------------------------------
137cdf0e10cSrcweir 
getType()138cdf0e10cSrcweir     sal_Int16 BasicModuleNodeImpl::getType(  ) throw (RuntimeException)
139cdf0e10cSrcweir     {
140cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         return browse::BrowseNodeTypes::CONTAINER;
143cdf0e10cSrcweir     }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     // -----------------------------------------------------------------------------
146cdf0e10cSrcweir 
147cdf0e10cSrcweir //.........................................................................
148cdf0e10cSrcweir }	// namespace basprov
149cdf0e10cSrcweir //.........................................................................
150