xref: /aoo42x/main/sfx2/source/appl/appbaslib.cxx (revision d119d52d)
1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d119d52dSAndrew Rist  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d119d52dSAndrew Rist  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19*d119d52dSAndrew Rist  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "appbaslib.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
30cdf0e10cSrcweir #include "sfxtypes.hxx"
31cdf0e10cSrcweir #include <sfx2/app.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <basic/basmgr.hxx>
34cdf0e10cSrcweir #include <tools/diagnose_ex.h>
35cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir using namespace ::com::sun::star::lang;
39cdf0e10cSrcweir using namespace ::com::sun::star::script;
40cdf0e10cSrcweir using namespace ::com::sun::star::embed;
41cdf0e10cSrcweir using ::rtl::OUString;
42cdf0e10cSrcweir using ::osl::MutexGuard;
43cdf0e10cSrcweir using ::osl::Mutex;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //============================================================================
SfxBasicManagerHolder()46cdf0e10cSrcweir SfxBasicManagerHolder::SfxBasicManagerHolder()
47cdf0e10cSrcweir     :mpBasicManager( NULL )
48cdf0e10cSrcweir {
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
reset(BasicManager * _pBasicManager)51cdf0e10cSrcweir void SfxBasicManagerHolder::reset( BasicManager* _pBasicManager )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     impl_releaseContainers();
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     // Note: we do not delete the old BasicManager. BasicManager instances are
56cdf0e10cSrcweir     // nowadays obtained from the BasicManagerRepository, and the ownership is with
57cdf0e10cSrcweir     // the repository.
58cdf0e10cSrcweir     // @see basic::BasicManagerRepository::getApplicationBasicManager
59cdf0e10cSrcweir     // @see basic::BasicManagerRepository::getDocumentBasicManager
60cdf0e10cSrcweir     mpBasicManager = _pBasicManager;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     if ( mpBasicManager )
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir         try
65cdf0e10cSrcweir         {
66cdf0e10cSrcweir             mxBasicContainer.set( mpBasicManager->GetScriptLibraryContainer(), UNO_QUERY_THROW );
67cdf0e10cSrcweir             mxDialogContainer.set( mpBasicManager->GetDialogLibraryContainer(), UNO_QUERY_THROW  );
68cdf0e10cSrcweir         }
69cdf0e10cSrcweir         catch( const Exception& )
70cdf0e10cSrcweir         {
71cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
72cdf0e10cSrcweir         }
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
isAnyContainerModified() const76cdf0e10cSrcweir bool SfxBasicManagerHolder::isAnyContainerModified() const
77cdf0e10cSrcweir {
78cdf0e10cSrcweir     OSL_PRECOND( isValid(), "SfxBasicManagerHolder::isAnyContainerModified: not initialized!" );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     if ( mxBasicContainer.is() && mxBasicContainer->isModified() )
81cdf0e10cSrcweir         return true;
82cdf0e10cSrcweir     if ( mxDialogContainer.is() && mxDialogContainer->isModified() )
83cdf0e10cSrcweir         return true;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     return false;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
storeAllLibraries()88cdf0e10cSrcweir void SfxBasicManagerHolder::storeAllLibraries()
89cdf0e10cSrcweir {
90cdf0e10cSrcweir     OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" );
91cdf0e10cSrcweir     try
92cdf0e10cSrcweir     {
93cdf0e10cSrcweir         if ( mxBasicContainer.is() )
94cdf0e10cSrcweir             mxBasicContainer->storeLibraries();
95cdf0e10cSrcweir         if ( mxDialogContainer.is() )
96cdf0e10cSrcweir             mxDialogContainer->storeLibraries();
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir     catch( const Exception& )
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
setStorage(const Reference<XStorage> & _rxStorage)104cdf0e10cSrcweir void SfxBasicManagerHolder::setStorage( const Reference< XStorage >& _rxStorage )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir     try
107cdf0e10cSrcweir     {
108cdf0e10cSrcweir         if ( mxBasicContainer.is() )
109cdf0e10cSrcweir             mxBasicContainer->setRootStorage( _rxStorage );
110cdf0e10cSrcweir         if ( mxDialogContainer.is() )
111cdf0e10cSrcweir             mxDialogContainer->setRootStorage( _rxStorage );
112cdf0e10cSrcweir     }
113cdf0e10cSrcweir     catch( const Exception& )
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir }
118cdf0e10cSrcweir 
storeLibrariesToStorage(const Reference<XStorage> & _rxStorage)119cdf0e10cSrcweir void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference< XStorage >& _rxStorage )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" );
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     try
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir         if ( mxBasicContainer.is() )
126cdf0e10cSrcweir             mxBasicContainer->storeLibrariesToStorage( _rxStorage );
127cdf0e10cSrcweir         if ( mxDialogContainer.is() )
128cdf0e10cSrcweir             mxDialogContainer->storeLibrariesToStorage( _rxStorage );
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir     catch( const Exception& )
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
133cdf0e10cSrcweir     }
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
getLibraryContainer(ContainerType _eType)136cdf0e10cSrcweir Reference< XLibraryContainer > SfxBasicManagerHolder::getLibraryContainer( ContainerType _eType )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" );
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     switch ( _eType )
141cdf0e10cSrcweir     {
142cdf0e10cSrcweir     case SCRIPTS:   return mxBasicContainer.get();
143cdf0e10cSrcweir     case DIALOGS:   return mxDialogContainer.get();
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir     DBG_ERROR( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" );
146cdf0e10cSrcweir     return NULL;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
impl_releaseContainers()149cdf0e10cSrcweir void SfxBasicManagerHolder::impl_releaseContainers()
150cdf0e10cSrcweir {
151cdf0e10cSrcweir     mxBasicContainer.clear();
152cdf0e10cSrcweir     mxDialogContainer.clear();
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir sal_Bool
LegacyPsswdBinaryLimitExceeded(Sequence<rtl::OUString> & sModules)156cdf0e10cSrcweir SfxBasicManagerHolder::LegacyPsswdBinaryLimitExceeded( Sequence< rtl::OUString >& sModules )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir     if ( mpBasicManager )
159cdf0e10cSrcweir         return mpBasicManager->LegacyPsswdBinaryLimitExceeded( sModules );
160cdf0e10cSrcweir     return sal_True;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir //============================================================================
164cdf0e10cSrcweir // Service for application library container
SFX_IMPL_ONEINSTANCEFACTORY(SfxApplicationDialogLibraryContainer)165cdf0e10cSrcweir SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationDialogLibraryContainer )
166cdf0e10cSrcweir 
167cdf0e10cSrcweir Sequence< OUString > SfxApplicationDialogLibraryContainer::impl_getStaticSupportedServiceNames()
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     static Sequence< OUString > seqServiceNames( 1 );
170cdf0e10cSrcweir     static sal_Bool bNeedsInit = sal_True;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir 	MutexGuard aGuard( Mutex::getGlobalMutex() );
173cdf0e10cSrcweir     if( bNeedsInit )
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         OUString* pSeq = seqServiceNames.getArray();
176cdf0e10cSrcweir         pSeq[0] = OUString::createFromAscii( "com.sun.star.script.ApplicationDialogLibraryContainer" );
177cdf0e10cSrcweir         bNeedsInit = sal_False;
178cdf0e10cSrcweir     }
179cdf0e10cSrcweir     return seqServiceNames;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
impl_getStaticImplementationName()182cdf0e10cSrcweir OUString SfxApplicationDialogLibraryContainer::impl_getStaticImplementationName()
183cdf0e10cSrcweir {
184cdf0e10cSrcweir     static OUString aImplName;
185cdf0e10cSrcweir     static sal_Bool bNeedsInit = sal_True;
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 	MutexGuard aGuard( Mutex::getGlobalMutex() );
188cdf0e10cSrcweir     if( bNeedsInit )
189cdf0e10cSrcweir     {
190cdf0e10cSrcweir         aImplName = OUString::createFromAscii( "com.sun.star.comp.sfx2.ApplicationDialogLibraryContainer" );
191cdf0e10cSrcweir         bNeedsInit = sal_False;
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir     return aImplName;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir 
impl_createInstance(const Reference<XMultiServiceFactory> &)196cdf0e10cSrcweir Reference< XInterface > SAL_CALL SfxApplicationDialogLibraryContainer::impl_createInstance
197cdf0e10cSrcweir     ( const Reference< XMultiServiceFactory >& )
198cdf0e10cSrcweir         throw( Exception )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	SFX_APP()->GetBasicManager();
201cdf0e10cSrcweir     Reference< XInterface > xRet =
202cdf0e10cSrcweir         Reference< XInterface >( SFX_APP()->GetDialogContainer(), UNO_QUERY );
203cdf0e10cSrcweir     return xRet;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir //============================================================================
207cdf0e10cSrcweir // Service for application library container
SFX_IMPL_ONEINSTANCEFACTORY(SfxApplicationScriptLibraryContainer)208cdf0e10cSrcweir SFX_IMPL_ONEINSTANCEFACTORY( SfxApplicationScriptLibraryContainer )
209cdf0e10cSrcweir 
210cdf0e10cSrcweir Sequence< OUString > SfxApplicationScriptLibraryContainer::impl_getStaticSupportedServiceNames()
211cdf0e10cSrcweir {
212cdf0e10cSrcweir     static Sequence< OUString > seqServiceNames( 1 );
213cdf0e10cSrcweir     static sal_Bool bNeedsInit = sal_True;
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 	MutexGuard aGuard( Mutex::getGlobalMutex() );
216cdf0e10cSrcweir     if( bNeedsInit )
217cdf0e10cSrcweir     {
218cdf0e10cSrcweir         OUString* pSeq = seqServiceNames.getArray();
219cdf0e10cSrcweir         pSeq[0] = OUString::createFromAscii( "com.sun.star.script.ApplicationScriptLibraryContainer" );
220cdf0e10cSrcweir         bNeedsInit = sal_False;
221cdf0e10cSrcweir     }
222cdf0e10cSrcweir     return seqServiceNames;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
impl_getStaticImplementationName()225cdf0e10cSrcweir OUString SfxApplicationScriptLibraryContainer::impl_getStaticImplementationName()
226cdf0e10cSrcweir {
227cdf0e10cSrcweir     static OUString aImplName;
228cdf0e10cSrcweir     static sal_Bool bNeedsInit = sal_True;
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 	MutexGuard aGuard( Mutex::getGlobalMutex() );
231cdf0e10cSrcweir     if( bNeedsInit )
232cdf0e10cSrcweir     {
233cdf0e10cSrcweir         aImplName = OUString::createFromAscii( "com.sun.star.comp.sfx2.ApplicationScriptLibraryContainer" );
234cdf0e10cSrcweir         bNeedsInit = sal_False;
235cdf0e10cSrcweir     }
236cdf0e10cSrcweir     return aImplName;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir 
impl_createInstance(const Reference<XMultiServiceFactory> &)239cdf0e10cSrcweir Reference< XInterface > SAL_CALL SfxApplicationScriptLibraryContainer::impl_createInstance
240cdf0e10cSrcweir     ( const Reference< XMultiServiceFactory >& )
241cdf0e10cSrcweir         throw( Exception )
242cdf0e10cSrcweir {
243cdf0e10cSrcweir 	SFX_APP()->GetBasicManager();
244cdf0e10cSrcweir     Reference< XInterface > xRet =
245cdf0e10cSrcweir         Reference< XInterface >( SFX_APP()->GetBasicContainer(), UNO_QUERY );
246cdf0e10cSrcweir     return xRet;
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
249