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 "baslibnode.hxx"
27cdf0e10cSrcweir #include "basmodnode.hxx"
28cdf0e10cSrcweir #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
29cdf0e10cSrcweir #include <vos/mutex.hxx>
30cdf0e10cSrcweir #include <vcl/svapp.hxx>
31cdf0e10cSrcweir #include <basic/basmgr.hxx>
32cdf0e10cSrcweir #include <basic/sbstar.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using namespace ::com::sun::star;
36cdf0e10cSrcweir using namespace ::com::sun::star::lang;
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir using namespace ::com::sun::star::script;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 
41cdf0e10cSrcweir //.........................................................................
42cdf0e10cSrcweir namespace basprov
43cdf0e10cSrcweir {
44cdf0e10cSrcweir //.........................................................................
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     // =============================================================================
47cdf0e10cSrcweir     // BasicLibraryNodeImpl
48cdf0e10cSrcweir     // =============================================================================
49cdf0e10cSrcweir 
BasicLibraryNodeImpl(const Reference<XComponentContext> & rxContext,const::rtl::OUString & sScriptingContext,BasicManager * pBasicManager,const Reference<script::XLibraryContainer> & xLibContainer,const::rtl::OUString & sLibName,bool isAppScript)50cdf0e10cSrcweir     BasicLibraryNodeImpl::BasicLibraryNodeImpl( const Reference< XComponentContext >& rxContext,
51cdf0e10cSrcweir          const ::rtl::OUString& sScriptingContext, BasicManager* pBasicManager,
52cdf0e10cSrcweir         const Reference< script::XLibraryContainer >& xLibContainer, const ::rtl::OUString& sLibName, bool isAppScript )
53cdf0e10cSrcweir         :m_xContext( rxContext )
54cdf0e10cSrcweir 	,m_sScriptingContext( sScriptingContext )
55cdf0e10cSrcweir         ,m_pBasicManager( pBasicManager )
56cdf0e10cSrcweir         ,m_xLibContainer( xLibContainer )
57cdf0e10cSrcweir         ,m_sLibName( sLibName )
58cdf0e10cSrcweir         ,m_bIsAppScript( isAppScript )
59cdf0e10cSrcweir     {
60cdf0e10cSrcweir         if ( m_xLibContainer.is() )
61cdf0e10cSrcweir         {
62cdf0e10cSrcweir             Any aElement = m_xLibContainer->getByName( m_sLibName );
63cdf0e10cSrcweir             aElement >>= m_xLibrary;
64cdf0e10cSrcweir         }
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     // -----------------------------------------------------------------------------
68cdf0e10cSrcweir 
~BasicLibraryNodeImpl()69cdf0e10cSrcweir     BasicLibraryNodeImpl::~BasicLibraryNodeImpl()
70cdf0e10cSrcweir     {
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     // -----------------------------------------------------------------------------
74cdf0e10cSrcweir     // XBrowseNode
75cdf0e10cSrcweir     // -----------------------------------------------------------------------------
76cdf0e10cSrcweir 
getName()77cdf0e10cSrcweir     ::rtl::OUString BasicLibraryNodeImpl::getName(  ) throw (RuntimeException)
78cdf0e10cSrcweir     {
79cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir         return m_sLibName;
82cdf0e10cSrcweir     }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir     // -----------------------------------------------------------------------------
85cdf0e10cSrcweir 
getChildNodes()86cdf0e10cSrcweir     Sequence< Reference< browse::XBrowseNode > > BasicLibraryNodeImpl::getChildNodes(  ) throw (RuntimeException)
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         Sequence< Reference< browse::XBrowseNode > > aChildNodes;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         if ( m_xLibContainer.is() && m_xLibContainer->hasByName( m_sLibName ) && !m_xLibContainer->isLibraryLoaded( m_sLibName ) )
93cdf0e10cSrcweir             m_xLibContainer->loadLibrary( m_sLibName );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir         if ( m_pBasicManager )
96cdf0e10cSrcweir         {
97cdf0e10cSrcweir             StarBASIC* pBasic = m_pBasicManager->GetLib( m_sLibName );
98cdf0e10cSrcweir             if ( pBasic && m_xLibrary.is() )
99cdf0e10cSrcweir             {
100cdf0e10cSrcweir                 Sequence< ::rtl::OUString > aNames = m_xLibrary->getElementNames();
101cdf0e10cSrcweir                 sal_Int32 nCount = aNames.getLength();
102cdf0e10cSrcweir                 const ::rtl::OUString* pNames = aNames.getConstArray();
103cdf0e10cSrcweir                 aChildNodes.realloc( nCount );
104cdf0e10cSrcweir                 Reference< browse::XBrowseNode >* pChildNodes = aChildNodes.getArray();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir                 for ( sal_Int32 i = 0 ; i < nCount ; ++i )
107cdf0e10cSrcweir                 {
108cdf0e10cSrcweir                     SbModule* pModule = pBasic->FindModule( pNames[i] );
109cdf0e10cSrcweir                     if ( pModule )
110cdf0e10cSrcweir                         pChildNodes[i] = static_cast< browse::XBrowseNode* >( new BasicModuleNodeImpl( m_xContext, m_sScriptingContext, pModule, m_bIsAppScript ) );
111cdf0e10cSrcweir                 }
112cdf0e10cSrcweir             }
113cdf0e10cSrcweir         }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         return aChildNodes;
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     // -----------------------------------------------------------------------------
119cdf0e10cSrcweir 
hasChildNodes()120cdf0e10cSrcweir     sal_Bool BasicLibraryNodeImpl::hasChildNodes(  ) throw (RuntimeException)
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         sal_Bool bReturn = sal_False;
125cdf0e10cSrcweir         if ( m_xLibrary.is() )
126cdf0e10cSrcweir             bReturn = m_xLibrary->hasElements();
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         return bReturn;
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     // -----------------------------------------------------------------------------
132cdf0e10cSrcweir 
getType()133cdf0e10cSrcweir     sal_Int16 BasicLibraryNodeImpl::getType(  ) throw (RuntimeException)
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir         return browse::BrowseNodeTypes::CONTAINER;
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     // -----------------------------------------------------------------------------
141cdf0e10cSrcweir 
142cdf0e10cSrcweir //.........................................................................
143cdf0e10cSrcweir }	// namespace basprov
144cdf0e10cSrcweir //.........................................................................
145