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/app.hxx>
26 #include <basic/basmgr.hxx>
27 #include <tools/diagnose_ex.h>
28 #include <com/sun/star/uno/XComponentContext.hpp>
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::lang
;
32 using namespace ::com::sun::star::script
;
33 using namespace ::com::sun::star::embed
;
36 SfxBasicManagerHolder::SfxBasicManagerHolder()
37 :mpBasicManager( nullptr )
41 void SfxBasicManagerHolder::Notify(SfxBroadcaster
& rBC
, SfxHint
const& rHint
)
43 if (!mpBasicManager
|| &rBC
!= mpBasicManager
)
45 if (SfxHintId::Dying
== rHint
.GetId())
47 mpBasicManager
= nullptr;
48 mxBasicContainer
.clear();
49 mxDialogContainer
.clear();
53 void SfxBasicManagerHolder::reset( BasicManager
* _pBasicManager
)
55 impl_releaseContainers();
57 #if !HAVE_FEATURE_SCRIPTING
58 (void) _pBasicManager
;
60 // Note: we do not delete the old BasicManager. BasicManager instances are
61 // nowadays obtained from the BasicManagerRepository, and the ownership is with
63 // @see basic::BasicManagerRepository::getApplicationBasicManager
64 // @see basic::BasicManagerRepository::getDocumentBasicManager
65 mpBasicManager
= _pBasicManager
;
67 if ( !mpBasicManager
)
70 StartListening(*mpBasicManager
);
73 mxBasicContainer
.set( mpBasicManager
->GetScriptLibraryContainer(), UNO_QUERY_THROW
);
74 mxDialogContainer
.set( mpBasicManager
->GetDialogLibraryContainer(), UNO_QUERY_THROW
);
76 catch( const Exception
& )
78 DBG_UNHANDLED_EXCEPTION("sfx.appl");
83 void SfxBasicManagerHolder::storeAllLibraries()
85 #if HAVE_FEATURE_SCRIPTING
86 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" );
89 if ( mxBasicContainer
.is() )
90 mxBasicContainer
->storeLibraries();
91 if ( mxDialogContainer
.is() )
92 mxDialogContainer
->storeLibraries();
94 catch( const Exception
& )
96 DBG_UNHANDLED_EXCEPTION("sfx.appl");
101 void SfxBasicManagerHolder::setStorage( const Reference
< XStorage
>& _rxStorage
)
103 #if !HAVE_FEATURE_SCRIPTING
108 if ( mxBasicContainer
.is() )
109 mxBasicContainer
->setRootStorage( _rxStorage
);
110 if ( mxDialogContainer
.is() )
111 mxDialogContainer
->setRootStorage( _rxStorage
);
113 catch( const Exception
& )
115 DBG_UNHANDLED_EXCEPTION("sfx.appl");
120 void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference
< XStorage
>& _rxStorage
)
122 #if !HAVE_FEATURE_SCRIPTING
125 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" );
127 if ( mxBasicContainer
.is() )
128 mxBasicContainer
->storeLibrariesToStorage( _rxStorage
);
129 if ( mxDialogContainer
.is() )
130 mxDialogContainer
->storeLibrariesToStorage( _rxStorage
);
134 XLibraryContainer
* SfxBasicManagerHolder::getLibraryContainer( ContainerType _eType
)
136 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" );
140 case SCRIPTS
: return mxBasicContainer
.get();
141 case DIALOGS
: return mxDialogContainer
.get();
143 OSL_FAIL( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" );
147 void SfxBasicManagerHolder::impl_releaseContainers()
149 mxBasicContainer
.clear();
150 mxDialogContainer
.clear();
153 bool SfxBasicManagerHolder::LegacyPsswdBinaryLimitExceeded( std::vector
< OUString
>& sModules
)
155 #if !HAVE_FEATURE_SCRIPTING
158 if ( mpBasicManager
)
159 return mpBasicManager
->LegacyPsswdBinaryLimitExceeded( sModules
);
164 // Service for application library container
165 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
166 com_sun_star_comp_sfx2_ApplicationDialogLibraryContainer_get_implementation(
167 css::uno::XComponentContext
*,
168 css::uno::Sequence
<css::uno::Any
> const &)
170 SfxApplication::GetBasicManager();
171 css::uno::XInterface
* pRet
= SfxGetpApp()->GetDialogContainer();
176 // Service for application library container
177 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
178 com_sun_star_comp_sfx2_ApplicationScriptLibraryContainer_get_implementation(
179 css::uno::XComponentContext
*,
180 css::uno::Sequence
<css::uno::Any
> const &)
182 SfxApplication::GetBasicManager();
183 css::uno::XInterface
* pRet
= SfxGetpApp()->GetBasicContainer();
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */