1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "appbaslib.hxx"
32 #include <sfx2/sfxuno.hxx>
33 #include "sfxtypes.hxx"
34 #include <sfx2/app.hxx>
36 #include <basic/basmgr.hxx>
37 #include <tools/diagnose_ex.h>
38 #include <comphelper/processfactory.hxx>
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star::script
;
43 using namespace ::com::sun::star::embed
;
44 using ::rtl::OUString
;
45 using ::osl::MutexGuard
;
48 //============================================================================
49 SfxBasicManagerHolder::SfxBasicManagerHolder()
50 :mpBasicManager( NULL
)
54 void SfxBasicManagerHolder::reset( BasicManager
* _pBasicManager
)
56 impl_releaseContainers();
58 #ifdef DISABLE_SCRIPTING
59 (void) _pBasicManager
;
61 // Note: we do not delete the old BasicManager. BasicManager instances are
62 // nowadays obtained from the BasicManagerRepository, and the ownership is with
64 // @see basic::BasicManagerRepository::getApplicationBasicManager
65 // @see basic::BasicManagerRepository::getDocumentBasicManager
66 mpBasicManager
= _pBasicManager
;
72 mxBasicContainer
.set( mpBasicManager
->GetScriptLibraryContainer(), UNO_QUERY_THROW
);
73 mxDialogContainer
.set( mpBasicManager
->GetDialogLibraryContainer(), UNO_QUERY_THROW
);
75 catch( const Exception
& )
77 DBG_UNHANDLED_EXCEPTION();
83 void SfxBasicManagerHolder::storeAllLibraries()
85 #ifndef DISABLE_SCRIPTING
86 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" );
89 if ( mxBasicContainer
.is() )
90 mxBasicContainer
->storeLibraries();
91 if ( mxDialogContainer
.is() )
92 mxDialogContainer
->storeLibraries();
94 catch( const Exception
& )
96 DBG_UNHANDLED_EXCEPTION();
101 void SfxBasicManagerHolder::setStorage( const Reference
< XStorage
>& _rxStorage
)
103 #ifdef DISABLE_SCRIPTING
108 if ( mxBasicContainer
.is() )
109 mxBasicContainer
->setRootStorage( _rxStorage
);
110 if ( mxDialogContainer
.is() )
111 mxDialogContainer
->setRootStorage( _rxStorage
);
113 catch( const Exception
& )
115 DBG_UNHANDLED_EXCEPTION();
120 void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference
< XStorage
>& _rxStorage
)
122 #ifdef DISABLE_SCRIPTING
125 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" );
127 if ( mxBasicContainer
.is() )
128 mxBasicContainer
->storeLibrariesToStorage( _rxStorage
);
129 if ( mxDialogContainer
.is() )
130 mxDialogContainer
->storeLibrariesToStorage( _rxStorage
);
134 Reference
< XLibraryContainer
> SfxBasicManagerHolder::getLibraryContainer( ContainerType _eType
)
136 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" );
140 case SCRIPTS
: return mxBasicContainer
.get();
141 case DIALOGS
: return mxDialogContainer
.get();
143 OSL_FAIL( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" );
147 void SfxBasicManagerHolder::impl_releaseContainers()
149 mxBasicContainer
.clear();
150 mxDialogContainer
.clear();
154 SfxBasicManagerHolder::LegacyPsswdBinaryLimitExceeded( Sequence
< rtl::OUString
>& sModules
)
156 #ifdef DISABLE_SCRIPTING
159 if ( mpBasicManager
)
160 return mpBasicManager
->LegacyPsswdBinaryLimitExceeded( sModules
);
165 //============================================================================
166 // Service for application library container
167 SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationDialogLibraryContainer
)
169 Sequence
< OUString
> SfxApplicationDialogLibraryContainer::impl_getStaticSupportedServiceNames()
171 static Sequence
< OUString
> seqServiceNames( 1 );
172 static sal_Bool bNeedsInit
= sal_True
;
174 MutexGuard
aGuard( Mutex::getGlobalMutex() );
177 OUString
* pSeq
= seqServiceNames
.getArray();
178 pSeq
[0] = OUString("com.sun.star.script.ApplicationDialogLibraryContainer");
179 bNeedsInit
= sal_False
;
181 return seqServiceNames
;
184 OUString
SfxApplicationDialogLibraryContainer::impl_getStaticImplementationName()
186 return OUString("com.sun.star.comp.sfx2.ApplicationDialogLibraryContainer");
189 Reference
< XInterface
> SAL_CALL
SfxApplicationDialogLibraryContainer::impl_createInstance
190 ( const Reference
< XMultiServiceFactory
>& )
193 SFX_APP()->GetBasicManager();
194 Reference
< XInterface
> xRet
=
195 Reference
< XInterface
>( SFX_APP()->GetDialogContainer(), UNO_QUERY
);
199 //============================================================================
200 // Service for application library container
201 SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationScriptLibraryContainer
)
203 Sequence
< OUString
> SfxApplicationScriptLibraryContainer::impl_getStaticSupportedServiceNames()
205 static Sequence
< OUString
> seqServiceNames( 1 );
206 static sal_Bool bNeedsInit
= sal_True
;
208 MutexGuard
aGuard( Mutex::getGlobalMutex() );
211 OUString
* pSeq
= seqServiceNames
.getArray();
212 pSeq
[0] = OUString("com.sun.star.script.ApplicationScriptLibraryContainer");
213 bNeedsInit
= sal_False
;
215 return seqServiceNames
;
218 OUString
SfxApplicationScriptLibraryContainer::impl_getStaticImplementationName()
220 static OUString aImplName
;
221 static sal_Bool bNeedsInit
= sal_True
;
223 MutexGuard
aGuard( Mutex::getGlobalMutex() );
226 aImplName
= OUString("com.sun.star.comp.sfx2.ApplicationScriptLibraryContainer");
227 bNeedsInit
= sal_False
;
232 Reference
< XInterface
> SAL_CALL
SfxApplicationScriptLibraryContainer::impl_createInstance
233 ( const Reference
< XMultiServiceFactory
>& )
236 SFX_APP()->GetBasicManager();
237 Reference
< XInterface
> xRet
=
238 Reference
< XInterface
>( SFX_APP()->GetBasicContainer(), UNO_QUERY
);
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */