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