1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sfx2.hxx" 30 31 #include "appbaslib.hxx" 32 33 #include <sfx2/sfxuno.hxx> 34 #include "sfxtypes.hxx" 35 #include <sfx2/app.hxx> 36 37 #include <basic/basmgr.hxx> 38 #include <tools/diagnose_ex.h> 39 #include <comphelper/processfactory.hxx> 40 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; 48 49 //============================================================================ 50 SfxBasicManagerHolder::SfxBasicManagerHolder() 51 :mpBasicManager( NULL ) 52 { 53 } 54 55 void SfxBasicManagerHolder::reset( BasicManager* _pBasicManager ) 56 { 57 impl_releaseContainers(); 58 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; 65 66 if ( mpBasicManager ) 67 { 68 try 69 { 70 mxBasicContainer.set( mpBasicManager->GetScriptLibraryContainer(), UNO_QUERY_THROW ); 71 mxDialogContainer.set( mpBasicManager->GetDialogLibraryContainer(), UNO_QUERY_THROW ); 72 } 73 catch( const Exception& ) 74 { 75 DBG_UNHANDLED_EXCEPTION(); 76 } 77 } 78 } 79 80 bool SfxBasicManagerHolder::isAnyContainerModified() const 81 { 82 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::isAnyContainerModified: not initialized!" ); 83 84 if ( mxBasicContainer.is() && mxBasicContainer->isModified() ) 85 return true; 86 if ( mxDialogContainer.is() && mxDialogContainer->isModified() ) 87 return true; 88 89 return false; 90 } 91 92 void SfxBasicManagerHolder::storeAllLibraries() 93 { 94 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" ); 95 try 96 { 97 if ( mxBasicContainer.is() ) 98 mxBasicContainer->storeLibraries(); 99 if ( mxDialogContainer.is() ) 100 mxDialogContainer->storeLibraries(); 101 } 102 catch( const Exception& ) 103 { 104 DBG_UNHANDLED_EXCEPTION(); 105 } 106 } 107 108 void SfxBasicManagerHolder::setStorage( const Reference< XStorage >& _rxStorage ) 109 { 110 try 111 { 112 if ( mxBasicContainer.is() ) 113 mxBasicContainer->setRootStorage( _rxStorage ); 114 if ( mxDialogContainer.is() ) 115 mxDialogContainer->setRootStorage( _rxStorage ); 116 } 117 catch( const Exception& ) 118 { 119 DBG_UNHANDLED_EXCEPTION(); 120 } 121 } 122 123 void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference< XStorage >& _rxStorage ) 124 { 125 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" ); 126 127 try 128 { 129 if ( mxBasicContainer.is() ) 130 mxBasicContainer->storeLibrariesToStorage( _rxStorage ); 131 if ( mxDialogContainer.is() ) 132 mxDialogContainer->storeLibrariesToStorage( _rxStorage ); 133 } 134 catch( const Exception& ) 135 { 136 DBG_UNHANDLED_EXCEPTION(); 137 } 138 } 139 140 Reference< XLibraryContainer > SfxBasicManagerHolder::getLibraryContainer( ContainerType _eType ) 141 { 142 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" ); 143 144 switch ( _eType ) 145 { 146 case SCRIPTS: return mxBasicContainer.get(); 147 case DIALOGS: return mxDialogContainer.get(); 148 } 149 DBG_ERROR( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" ); 150 return NULL; 151 } 152 153 void SfxBasicManagerHolder::impl_releaseContainers() 154 { 155 mxBasicContainer.clear(); 156 mxDialogContainer.clear(); 157 } 158 159 sal_Bool 160 SfxBasicManagerHolder::LegacyPsswdBinaryLimitExceeded( Sequence< rtl::OUString >& sModules ) 161 { 162 if ( mpBasicManager ) 163 return mpBasicManager->LegacyPsswdBinaryLimitExceeded( sModules ); 164 return sal_True; 165 } 166 167 //============================================================================ 168 // Service for application library container 169 SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationDialogLibraryContainer ) 170 171 Sequence< OUString > SfxApplicationDialogLibraryContainer::impl_getStaticSupportedServiceNames() 172 { 173 static Sequence< OUString > seqServiceNames( 1 ); 174 static sal_Bool bNeedsInit = sal_True; 175 176 MutexGuard aGuard( Mutex::getGlobalMutex() ); 177 if( bNeedsInit ) 178 { 179 OUString* pSeq = seqServiceNames.getArray(); 180 pSeq[0] = OUString::createFromAscii( "com.sun.star.script.ApplicationDialogLibraryContainer" ); 181 bNeedsInit = sal_False; 182 } 183 return seqServiceNames; 184 } 185 186 OUString SfxApplicationDialogLibraryContainer::impl_getStaticImplementationName() 187 { 188 static OUString aImplName; 189 static sal_Bool bNeedsInit = sal_True; 190 191 MutexGuard aGuard( Mutex::getGlobalMutex() ); 192 if( bNeedsInit ) 193 { 194 aImplName = OUString::createFromAscii( "com.sun.star.comp.sfx2.ApplicationDialogLibraryContainer" ); 195 bNeedsInit = sal_False; 196 } 197 return aImplName; 198 } 199 200 Reference< XInterface > SAL_CALL SfxApplicationDialogLibraryContainer::impl_createInstance 201 ( const Reference< XMultiServiceFactory >& ) 202 throw( Exception ) 203 { 204 SFX_APP()->GetBasicManager(); 205 Reference< XInterface > xRet = 206 Reference< XInterface >( SFX_APP()->GetDialogContainer(), UNO_QUERY ); 207 return xRet; 208 } 209 210 //============================================================================ 211 // Service for application library container 212 SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationScriptLibraryContainer ) 213 214 Sequence< OUString > SfxApplicationScriptLibraryContainer::impl_getStaticSupportedServiceNames() 215 { 216 static Sequence< OUString > seqServiceNames( 1 ); 217 static sal_Bool bNeedsInit = sal_True; 218 219 MutexGuard aGuard( Mutex::getGlobalMutex() ); 220 if( bNeedsInit ) 221 { 222 OUString* pSeq = seqServiceNames.getArray(); 223 pSeq[0] = OUString::createFromAscii( "com.sun.star.script.ApplicationScriptLibraryContainer" ); 224 bNeedsInit = sal_False; 225 } 226 return seqServiceNames; 227 } 228 229 OUString SfxApplicationScriptLibraryContainer::impl_getStaticImplementationName() 230 { 231 static OUString aImplName; 232 static sal_Bool bNeedsInit = sal_True; 233 234 MutexGuard aGuard( Mutex::getGlobalMutex() ); 235 if( bNeedsInit ) 236 { 237 aImplName = OUString::createFromAscii( "com.sun.star.comp.sfx2.ApplicationScriptLibraryContainer" ); 238 bNeedsInit = sal_False; 239 } 240 return aImplName; 241 } 242 243 Reference< XInterface > SAL_CALL SfxApplicationScriptLibraryContainer::impl_createInstance 244 ( const Reference< XMultiServiceFactory >& ) 245 throw( Exception ) 246 { 247 SFX_APP()->GetBasicManager(); 248 Reference< XInterface > xRet = 249 Reference< XInterface >( SFX_APP()->GetBasicContainer(), UNO_QUERY ); 250 return xRet; 251 } 252 253