1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: baslibnode.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_scripting.hxx"
33 #include "baslibnode.hxx"
34 #include "basmodnode.hxx"
35 #include <com/sun/star/script/browse/BrowseNodeTypes.hpp>
36 #include <vos/mutex.hxx>
37 #include <vcl/svapp.hxx>
38 #include <basic/basmgr.hxx>
39 #include <basic/sbstar.hxx>
42 using namespace ::com::sun::star
;
43 using namespace ::com::sun::star::lang
;
44 using namespace ::com::sun::star::uno
;
45 using namespace ::com::sun::star::script
;
48 //.........................................................................
51 //.........................................................................
53 // =============================================================================
54 // BasicLibraryNodeImpl
55 // =============================================================================
57 BasicLibraryNodeImpl::BasicLibraryNodeImpl( const Reference
< XComponentContext
>& rxContext
,
58 const ::rtl::OUString
& sScriptingContext
, BasicManager
* pBasicManager
,
59 const Reference
< script::XLibraryContainer
>& xLibContainer
, const ::rtl::OUString
& sLibName
, bool isAppScript
)
60 :m_xContext( rxContext
)
61 ,m_sScriptingContext( sScriptingContext
)
62 ,m_pBasicManager( pBasicManager
)
63 ,m_xLibContainer( xLibContainer
)
64 ,m_sLibName( sLibName
)
65 ,m_bIsAppScript( isAppScript
)
67 if ( m_xLibContainer
.is() )
69 Any aElement
= m_xLibContainer
->getByName( m_sLibName
);
70 aElement
>>= m_xLibrary
;
74 // -----------------------------------------------------------------------------
76 BasicLibraryNodeImpl::~BasicLibraryNodeImpl()
80 // -----------------------------------------------------------------------------
82 // -----------------------------------------------------------------------------
84 ::rtl::OUString
BasicLibraryNodeImpl::getName( ) throw (RuntimeException
)
86 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
91 // -----------------------------------------------------------------------------
93 Sequence
< Reference
< browse::XBrowseNode
> > BasicLibraryNodeImpl::getChildNodes( ) throw (RuntimeException
)
95 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
97 Sequence
< Reference
< browse::XBrowseNode
> > aChildNodes
;
99 if ( m_xLibContainer
.is() && m_xLibContainer
->hasByName( m_sLibName
) && !m_xLibContainer
->isLibraryLoaded( m_sLibName
) )
100 m_xLibContainer
->loadLibrary( m_sLibName
);
102 if ( m_pBasicManager
)
104 StarBASIC
* pBasic
= m_pBasicManager
->GetLib( m_sLibName
);
105 if ( pBasic
&& m_xLibrary
.is() )
107 Sequence
< ::rtl::OUString
> aNames
= m_xLibrary
->getElementNames();
108 sal_Int32 nCount
= aNames
.getLength();
109 const ::rtl::OUString
* pNames
= aNames
.getConstArray();
110 aChildNodes
.realloc( nCount
);
111 Reference
< browse::XBrowseNode
>* pChildNodes
= aChildNodes
.getArray();
113 for ( sal_Int32 i
= 0 ; i
< nCount
; ++i
)
115 SbModule
* pModule
= pBasic
->FindModule( pNames
[i
] );
117 pChildNodes
[i
] = static_cast< browse::XBrowseNode
* >( new BasicModuleNodeImpl( m_xContext
, m_sScriptingContext
, pModule
, m_bIsAppScript
) );
125 // -----------------------------------------------------------------------------
127 sal_Bool
BasicLibraryNodeImpl::hasChildNodes( ) throw (RuntimeException
)
129 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
131 sal_Bool bReturn
= sal_False
;
132 if ( m_xLibrary
.is() )
133 bReturn
= m_xLibrary
->hasElements();
138 // -----------------------------------------------------------------------------
140 sal_Int16
BasicLibraryNodeImpl::getType( ) throw (RuntimeException
)
142 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
144 return browse::BrowseNodeTypes::CONTAINER
;
147 // -----------------------------------------------------------------------------
149 //.........................................................................
150 } // namespace basprov
151 //.........................................................................