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