Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / appl / appbaslib.cxx
blobfc823061e59384f7fbfeebb5c657af139ce3a97d
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;
46 using ::osl::Mutex;
48 //============================================================================
49 SfxBasicManagerHolder::SfxBasicManagerHolder()
50 :mpBasicManager( NULL )
54 void SfxBasicManagerHolder::reset( BasicManager* _pBasicManager )
56 impl_releaseContainers();
58 #ifdef DISABLE_SCRIPTING
59 (void) _pBasicManager;
60 #else
61 // Note: we do not delete the old BasicManager. BasicManager instances are
62 // nowadays obtained from the BasicManagerRepository, and the ownership is with
63 // the repository.
64 // @see basic::BasicManagerRepository::getApplicationBasicManager
65 // @see basic::BasicManagerRepository::getDocumentBasicManager
66 mpBasicManager = _pBasicManager;
68 if ( mpBasicManager )
70 try
72 mxBasicContainer.set( mpBasicManager->GetScriptLibraryContainer(), UNO_QUERY_THROW );
73 mxDialogContainer.set( mpBasicManager->GetDialogLibraryContainer(), UNO_QUERY_THROW );
75 catch( const Exception& )
77 DBG_UNHANDLED_EXCEPTION();
80 #endif
83 void SfxBasicManagerHolder::storeAllLibraries()
85 #ifndef DISABLE_SCRIPTING
86 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" );
87 try
89 if ( mxBasicContainer.is() )
90 mxBasicContainer->storeLibraries();
91 if ( mxDialogContainer.is() )
92 mxDialogContainer->storeLibraries();
94 catch( const Exception& )
96 DBG_UNHANDLED_EXCEPTION();
98 #endif
101 void SfxBasicManagerHolder::setStorage( const Reference< XStorage >& _rxStorage )
103 #ifdef DISABLE_SCRIPTING
104 (void) _rxStorage;
105 #else
108 if ( mxBasicContainer.is() )
109 mxBasicContainer->setRootStorage( _rxStorage );
110 if ( mxDialogContainer.is() )
111 mxDialogContainer->setRootStorage( _rxStorage );
113 catch( const Exception& )
115 DBG_UNHANDLED_EXCEPTION();
117 #endif
120 void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference< XStorage >& _rxStorage )
122 #ifdef DISABLE_SCRIPTING
123 (void) _rxStorage;
124 #else
125 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" );
127 if ( mxBasicContainer.is() )
128 mxBasicContainer->storeLibrariesToStorage( _rxStorage );
129 if ( mxDialogContainer.is() )
130 mxDialogContainer->storeLibrariesToStorage( _rxStorage );
131 #endif
134 Reference< XLibraryContainer > SfxBasicManagerHolder::getLibraryContainer( ContainerType _eType )
136 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" );
138 switch ( _eType )
140 case SCRIPTS: return mxBasicContainer.get();
141 case DIALOGS: return mxDialogContainer.get();
143 OSL_FAIL( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" );
144 return NULL;
147 void SfxBasicManagerHolder::impl_releaseContainers()
149 mxBasicContainer.clear();
150 mxDialogContainer.clear();
153 sal_Bool
154 SfxBasicManagerHolder::LegacyPsswdBinaryLimitExceeded( Sequence< rtl::OUString >& sModules )
156 #ifdef DISABLE_SCRIPTING
157 (void) sModules;
158 #else
159 if ( mpBasicManager )
160 return mpBasicManager->LegacyPsswdBinaryLimitExceeded( sModules );
161 #endif
162 return sal_True;
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() );
175 if( bNeedsInit )
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 >& )
191 throw( Exception )
193 SFX_APP()->GetBasicManager();
194 Reference< XInterface > xRet =
195 Reference< XInterface >( SFX_APP()->GetDialogContainer(), UNO_QUERY );
196 return xRet;
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() );
209 if( bNeedsInit )
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() );
224 if( bNeedsInit )
226 aImplName = OUString("com.sun.star.comp.sfx2.ApplicationScriptLibraryContainer");
227 bNeedsInit = sal_False;
229 return aImplName;
232 Reference< XInterface > SAL_CALL SfxApplicationScriptLibraryContainer::impl_createInstance
233 ( const Reference< XMultiServiceFactory >& )
234 throw( Exception )
236 SFX_APP()->GetBasicManager();
237 Reference< XInterface > xRet =
238 Reference< XInterface >( SFX_APP()->GetBasicContainer(), UNO_QUERY );
239 return xRet;
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */