1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "appbaslib.hxx"
23 #include <sfx2/sfxuno.hxx>
24 #include "sfxtypes.hxx"
25 #include <sfx2/app.hxx>
27 #include <basic/basmgr.hxx>
28 #include <tools/diagnose_ex.h>
29 #include <comphelper/processfactory.hxx>
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::lang
;
33 using namespace ::com::sun::star::script
;
34 using namespace ::com::sun::star::embed
;
35 using ::osl::MutexGuard
;
38 //============================================================================
39 SfxBasicManagerHolder::SfxBasicManagerHolder()
40 :mpBasicManager( NULL
)
44 void SfxBasicManagerHolder::reset( BasicManager
* _pBasicManager
)
46 impl_releaseContainers();
48 #ifdef DISABLE_SCRIPTING
49 (void) _pBasicManager
;
51 // Note: we do not delete the old BasicManager. BasicManager instances are
52 // nowadays obtained from the BasicManagerRepository, and the ownership is with
54 // @see basic::BasicManagerRepository::getApplicationBasicManager
55 // @see basic::BasicManagerRepository::getDocumentBasicManager
56 mpBasicManager
= _pBasicManager
;
62 mxBasicContainer
.set( mpBasicManager
->GetScriptLibraryContainer(), UNO_QUERY_THROW
);
63 mxDialogContainer
.set( mpBasicManager
->GetDialogLibraryContainer(), UNO_QUERY_THROW
);
65 catch( const Exception
& )
67 DBG_UNHANDLED_EXCEPTION();
73 void SfxBasicManagerHolder::storeAllLibraries()
75 #ifndef DISABLE_SCRIPTING
76 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" );
79 if ( mxBasicContainer
.is() )
80 mxBasicContainer
->storeLibraries();
81 if ( mxDialogContainer
.is() )
82 mxDialogContainer
->storeLibraries();
84 catch( const Exception
& )
86 DBG_UNHANDLED_EXCEPTION();
91 void SfxBasicManagerHolder::setStorage( const Reference
< XStorage
>& _rxStorage
)
93 #ifdef DISABLE_SCRIPTING
98 if ( mxBasicContainer
.is() )
99 mxBasicContainer
->setRootStorage( _rxStorage
);
100 if ( mxDialogContainer
.is() )
101 mxDialogContainer
->setRootStorage( _rxStorage
);
103 catch( const Exception
& )
105 DBG_UNHANDLED_EXCEPTION();
110 void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference
< XStorage
>& _rxStorage
)
112 #ifdef DISABLE_SCRIPTING
115 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" );
117 if ( mxBasicContainer
.is() )
118 mxBasicContainer
->storeLibrariesToStorage( _rxStorage
);
119 if ( mxDialogContainer
.is() )
120 mxDialogContainer
->storeLibrariesToStorage( _rxStorage
);
124 Reference
< XLibraryContainer
> SfxBasicManagerHolder::getLibraryContainer( ContainerType _eType
)
126 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" );
130 case SCRIPTS
: return mxBasicContainer
.get();
131 case DIALOGS
: return mxDialogContainer
.get();
133 OSL_FAIL( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" );
137 void SfxBasicManagerHolder::impl_releaseContainers()
139 mxBasicContainer
.clear();
140 mxDialogContainer
.clear();
144 SfxBasicManagerHolder::LegacyPsswdBinaryLimitExceeded( Sequence
< OUString
>& sModules
)
146 #ifdef DISABLE_SCRIPTING
149 if ( mpBasicManager
)
150 return mpBasicManager
->LegacyPsswdBinaryLimitExceeded( sModules
);
155 //============================================================================
156 // Service for application library container
157 SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationDialogLibraryContainer
)
159 Sequence
< OUString
> SfxApplicationDialogLibraryContainer::impl_getStaticSupportedServiceNames()
161 static Sequence
< OUString
> seqServiceNames( 1 );
162 static sal_Bool bNeedsInit
= sal_True
;
164 MutexGuard
aGuard( Mutex::getGlobalMutex() );
167 OUString
* pSeq
= seqServiceNames
.getArray();
168 pSeq
[0] = "com.sun.star.script.ApplicationDialogLibraryContainer";
169 bNeedsInit
= sal_False
;
171 return seqServiceNames
;
174 OUString
SfxApplicationDialogLibraryContainer::impl_getStaticImplementationName()
176 return OUString("com.sun.star.comp.sfx2.ApplicationDialogLibraryContainer");
179 Reference
< XInterface
> SAL_CALL
SfxApplicationDialogLibraryContainer::impl_createInstance
180 ( const Reference
< XMultiServiceFactory
>& )
183 SFX_APP()->GetBasicManager();
184 Reference
< XInterface
> xRet
=
185 Reference
< XInterface
>( SFX_APP()->GetDialogContainer(), UNO_QUERY
);
189 //============================================================================
190 // Service for application library container
191 SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationScriptLibraryContainer
)
193 Sequence
< OUString
> SfxApplicationScriptLibraryContainer::impl_getStaticSupportedServiceNames()
195 Sequence
< OUString
> seqServiceNames( 1 );
196 OUString
* pSeq
= seqServiceNames
.getArray();
197 pSeq
[0] = "com.sun.star.script.ApplicationScriptLibraryContainer";
198 return seqServiceNames
;
201 OUString
SfxApplicationScriptLibraryContainer::impl_getStaticImplementationName()
203 return OUString("com.sun.star.comp.sfx2.ApplicationScriptLibraryContainer");
206 Reference
< XInterface
> SAL_CALL
SfxApplicationScriptLibraryContainer::impl_createInstance
207 ( const Reference
< XMultiServiceFactory
>& )
210 SFX_APP()->GetBasicManager();
211 Reference
< XInterface
> xRet
=
212 Reference
< XInterface
>( SFX_APP()->GetBasicContainer(), UNO_QUERY
);
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */