merge the formfield patch from ooo-build
[ooovba.git] / sfx2 / source / appl / appbaslib.cxx
blobf6369b1d2a8eef0111d9398f65b99b24720c2ded
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: appbaslib.cxx,v $
10 * $Revision: 1.6 $
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 #include "appbaslib.hxx"
33 #include <sfx2/sfxuno.hxx>
34 #include "sfxtypes.hxx"
35 #include <sfx2/app.hxx>
37 #include <basic/basmgr.hxx>
38 #include <tools/diagnose_ex.h>
39 #include <comphelper/processfactory.hxx>
41 using namespace ::com::sun::star::uno;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::script;
44 using namespace ::com::sun::star::embed;
45 using ::rtl::OUString;
46 using ::osl::MutexGuard;
47 using ::osl::Mutex;
49 //============================================================================
50 SfxBasicManagerHolder::SfxBasicManagerHolder()
51 :mpBasicManager( NULL )
55 void SfxBasicManagerHolder::reset( BasicManager* _pBasicManager )
57 impl_releaseContainers();
59 // Note: we do not delete the old BasicManager. BasicManager instances are
60 // nowadays obtained from the BasicManagerRepository, and the ownership is with
61 // the repository.
62 // @see basic::BasicManagerRepository::getApplicationBasicManager
63 // @see basic::BasicManagerRepository::getDocumentBasicManager
64 mpBasicManager = _pBasicManager;
66 if ( mpBasicManager )
68 try
70 mxBasicContainer.set( mpBasicManager->GetScriptLibraryContainer(), UNO_QUERY_THROW );
71 mxDialogContainer.set( mpBasicManager->GetDialogLibraryContainer(), UNO_QUERY_THROW );
73 catch( const Exception& )
75 DBG_UNHANDLED_EXCEPTION();
80 bool SfxBasicManagerHolder::isAnyContainerModified() const
82 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::isAnyContainerModified: not initialized!" );
84 if ( mxBasicContainer.is() && mxBasicContainer->isModified() )
85 return true;
86 if ( mxDialogContainer.is() && mxDialogContainer->isModified() )
87 return true;
89 return false;
92 void SfxBasicManagerHolder::storeAllLibraries()
94 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" );
95 try
97 if ( mxBasicContainer.is() )
98 mxBasicContainer->storeLibraries();
99 if ( mxDialogContainer.is() )
100 mxDialogContainer->storeLibraries();
102 catch( const Exception& )
104 DBG_UNHANDLED_EXCEPTION();
108 void SfxBasicManagerHolder::setStorage( const Reference< XStorage >& _rxStorage )
112 if ( mxBasicContainer.is() )
113 mxBasicContainer->setRootStorage( _rxStorage );
114 if ( mxDialogContainer.is() )
115 mxDialogContainer->setRootStorage( _rxStorage );
117 catch( const Exception& )
119 DBG_UNHANDLED_EXCEPTION();
123 void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference< XStorage >& _rxStorage )
125 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" );
129 if ( mxBasicContainer.is() )
130 mxBasicContainer->storeLibrariesToStorage( _rxStorage );
131 if ( mxDialogContainer.is() )
132 mxDialogContainer->storeLibrariesToStorage( _rxStorage );
134 catch( const Exception& )
136 DBG_UNHANDLED_EXCEPTION();
140 Reference< XLibraryContainer > SfxBasicManagerHolder::getLibraryContainer( ContainerType _eType )
142 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" );
144 switch ( _eType )
146 case SCRIPTS: return mxBasicContainer.get();
147 case DIALOGS: return mxDialogContainer.get();
149 DBG_ERROR( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" );
150 return NULL;
153 void SfxBasicManagerHolder::impl_releaseContainers()
155 mxBasicContainer.clear();
156 mxDialogContainer.clear();
159 sal_Bool
160 SfxBasicManagerHolder::LegacyPsswdBinaryLimitExceeded( Sequence< rtl::OUString >& sModules )
162 if ( mpBasicManager )
163 return mpBasicManager->LegacyPsswdBinaryLimitExceeded( sModules );
164 return sal_True;
167 //============================================================================
168 // Service for application library container
169 SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationDialogLibraryContainer )
171 Sequence< OUString > SfxApplicationDialogLibraryContainer::impl_getStaticSupportedServiceNames()
173 static Sequence< OUString > seqServiceNames( 1 );
174 static sal_Bool bNeedsInit = sal_True;
176 MutexGuard aGuard( Mutex::getGlobalMutex() );
177 if( bNeedsInit )
179 OUString* pSeq = seqServiceNames.getArray();
180 pSeq[0] = OUString::createFromAscii( "com.sun.star.script.ApplicationDialogLibraryContainer" );
181 bNeedsInit = sal_False;
183 return seqServiceNames;
186 OUString SfxApplicationDialogLibraryContainer::impl_getStaticImplementationName()
188 static OUString aImplName;
189 static sal_Bool bNeedsInit = sal_True;
191 MutexGuard aGuard( Mutex::getGlobalMutex() );
192 if( bNeedsInit )
194 aImplName = OUString::createFromAscii( "com.sun.star.comp.sfx2.ApplicationDialogLibraryContainer" );
195 bNeedsInit = sal_False;
197 return aImplName;
200 Reference< XInterface > SAL_CALL SfxApplicationDialogLibraryContainer::impl_createInstance
201 ( const Reference< XMultiServiceFactory >& )
202 throw( Exception )
204 SFX_APP()->GetBasicManager();
205 Reference< XInterface > xRet =
206 Reference< XInterface >( SFX_APP()->GetDialogContainer(), UNO_QUERY );
207 return xRet;
210 //============================================================================
211 // Service for application library container
212 SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationScriptLibraryContainer )
214 Sequence< OUString > SfxApplicationScriptLibraryContainer::impl_getStaticSupportedServiceNames()
216 static Sequence< OUString > seqServiceNames( 1 );
217 static sal_Bool bNeedsInit = sal_True;
219 MutexGuard aGuard( Mutex::getGlobalMutex() );
220 if( bNeedsInit )
222 OUString* pSeq = seqServiceNames.getArray();
223 pSeq[0] = OUString::createFromAscii( "com.sun.star.script.ApplicationScriptLibraryContainer" );
224 bNeedsInit = sal_False;
226 return seqServiceNames;
229 OUString SfxApplicationScriptLibraryContainer::impl_getStaticImplementationName()
231 static OUString aImplName;
232 static sal_Bool bNeedsInit = sal_True;
234 MutexGuard aGuard( Mutex::getGlobalMutex() );
235 if( bNeedsInit )
237 aImplName = OUString::createFromAscii( "com.sun.star.comp.sfx2.ApplicationScriptLibraryContainer" );
238 bNeedsInit = sal_False;
240 return aImplName;
243 Reference< XInterface > SAL_CALL SfxApplicationScriptLibraryContainer::impl_createInstance
244 ( const Reference< XMultiServiceFactory >& )
245 throw( Exception )
247 SFX_APP()->GetBasicManager();
248 Reference< XInterface > xRet =
249 Reference< XInterface >( SFX_APP()->GetBasicContainer(), UNO_QUERY );
250 return xRet;