1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_features.h>
22 #include "appbaslib.hxx"
24 #include <sfx2/sfxuno.hxx>
25 #include "sfxtypes.hxx"
26 #include <sfx2/app.hxx>
28 #include <basic/basmgr.hxx>
29 #include <tools/diagnose_ex.h>
30 #include <comphelper/processfactory.hxx>
31 #include <cppuhelper/weak.hxx>
33 using namespace ::com::sun::star::uno
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::com::sun::star::script
;
36 using namespace ::com::sun::star::embed
;
37 using ::osl::MutexGuard
;
41 SfxBasicManagerHolder::SfxBasicManagerHolder()
42 :mpBasicManager( NULL
)
46 void SfxBasicManagerHolder::Notify(SfxBroadcaster
& rBC
, SfxHint
const& rHint
)
48 if (!mpBasicManager
|| &rBC
!= mpBasicManager
)
50 SfxSimpleHint
const*const pSimpleHint(dynamic_cast<SfxSimpleHint
const*>(&rHint
));
51 if (pSimpleHint
&& SFX_HINT_DYING
== pSimpleHint
->GetId())
53 mpBasicManager
= nullptr;
54 mxBasicContainer
.clear();
55 mxDialogContainer
.clear();
59 void SfxBasicManagerHolder::reset( BasicManager
* _pBasicManager
)
61 impl_releaseContainers();
63 #if !HAVE_FEATURE_SCRIPTING
64 (void) _pBasicManager
;
66 // Note: we do not delete the old BasicManager. BasicManager instances are
67 // nowadays obtained from the BasicManagerRepository, and the ownership is with
69 // @see basic::BasicManagerRepository::getApplicationBasicManager
70 // @see basic::BasicManagerRepository::getDocumentBasicManager
71 mpBasicManager
= _pBasicManager
;
75 StartListening(*mpBasicManager
);
78 mxBasicContainer
.set( mpBasicManager
->GetScriptLibraryContainer(), UNO_QUERY_THROW
);
79 mxDialogContainer
.set( mpBasicManager
->GetDialogLibraryContainer(), UNO_QUERY_THROW
);
81 catch( const Exception
& )
83 DBG_UNHANDLED_EXCEPTION();
89 void SfxBasicManagerHolder::storeAllLibraries()
91 #if HAVE_FEATURE_SCRIPTING
92 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" );
95 if ( mxBasicContainer
.is() )
96 mxBasicContainer
->storeLibraries();
97 if ( mxDialogContainer
.is() )
98 mxDialogContainer
->storeLibraries();
100 catch( const Exception
& )
102 DBG_UNHANDLED_EXCEPTION();
107 void SfxBasicManagerHolder::setStorage( const Reference
< XStorage
>& _rxStorage
)
109 #if !HAVE_FEATURE_SCRIPTING
114 if ( mxBasicContainer
.is() )
115 mxBasicContainer
->setRootStorage( _rxStorage
);
116 if ( mxDialogContainer
.is() )
117 mxDialogContainer
->setRootStorage( _rxStorage
);
119 catch( const Exception
& )
121 DBG_UNHANDLED_EXCEPTION();
126 void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference
< XStorage
>& _rxStorage
)
128 #if !HAVE_FEATURE_SCRIPTING
131 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" );
133 if ( mxBasicContainer
.is() )
134 mxBasicContainer
->storeLibrariesToStorage( _rxStorage
);
135 if ( mxDialogContainer
.is() )
136 mxDialogContainer
->storeLibrariesToStorage( _rxStorage
);
140 XLibraryContainer
* SfxBasicManagerHolder::getLibraryContainer( ContainerType _eType
)
142 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" );
146 case SCRIPTS
: return mxBasicContainer
.get();
147 case DIALOGS
: return mxDialogContainer
.get();
149 OSL_FAIL( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" );
153 void SfxBasicManagerHolder::impl_releaseContainers()
155 mxBasicContainer
.clear();
156 mxDialogContainer
.clear();
159 bool SfxBasicManagerHolder::LegacyPsswdBinaryLimitExceeded( Sequence
< OUString
>& sModules
)
161 #if !HAVE_FEATURE_SCRIPTING
164 if ( mpBasicManager
)
165 return mpBasicManager
->LegacyPsswdBinaryLimitExceeded( sModules
);
170 // Service for application library container
171 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
172 com_sun_star_comp_sfx2_ApplicationDialogLibraryContainer_get_implementation(
173 css::uno::XComponentContext
*,
174 css::uno::Sequence
<css::uno::Any
> const &)
176 SfxApplication::GetBasicManager();
177 css::uno::XInterface
* pRet
= SfxGetpApp()->GetDialogContainer();
182 // Service for application library container
183 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
184 com_sun_star_comp_sfx2_ApplicationScriptLibraryContainer_get_implementation(
185 css::uno::XComponentContext
*,
186 css::uno::Sequence
<css::uno::Any
> const &)
188 SfxApplication::GetBasicManager();
189 css::uno::XInterface
* pRet
= SfxGetpApp()->GetBasicContainer();
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */