Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / appl / appbaslib.cxx
blobf05afecdd20db63cf7392c4cbf15672e5d6a9c6c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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)
44 return;
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;
59 #else
60 // Note: we do not delete the old BasicManager. BasicManager instances are
61 // nowadays obtained from the BasicManagerRepository, and the ownership is with
62 // the repository.
63 // @see basic::BasicManagerRepository::getApplicationBasicManager
64 // @see basic::BasicManagerRepository::getDocumentBasicManager
65 mpBasicManager = _pBasicManager;
67 if ( !mpBasicManager )
68 return;
70 StartListening(*mpBasicManager);
71 try
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");
80 #endif
83 void SfxBasicManagerHolder::storeAllLibraries()
85 #if HAVE_FEATURE_SCRIPTING
86 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" );
87 try
89 if ( mxBasicContainer.is() )
90 mxBasicContainer->storeLibraries();
91 if ( mxDialogContainer.is() )
92 mxDialogContainer->storeLibraries();
94 catch( const Exception& )
96 DBG_UNHANDLED_EXCEPTION("sfx.appl");
98 #endif
101 void SfxBasicManagerHolder::setStorage( const Reference< XStorage >& _rxStorage )
103 #if !HAVE_FEATURE_SCRIPTING
104 (void) _rxStorage;
105 #else
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");
117 #endif
120 void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference< XStorage >& _rxStorage )
122 #if !HAVE_FEATURE_SCRIPTING
123 (void) _rxStorage;
124 #else
125 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" );
127 if ( mxBasicContainer.is() )
128 mxBasicContainer->storeLibrariesToStorage( _rxStorage );
129 if ( mxDialogContainer.is() )
130 mxDialogContainer->storeLibrariesToStorage( _rxStorage );
131 #endif
134 XLibraryContainer * SfxBasicManagerHolder::getLibraryContainer( ContainerType _eType )
136 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" );
138 switch ( _eType )
140 case SCRIPTS: return mxBasicContainer.get();
141 case DIALOGS: return mxDialogContainer.get();
143 OSL_FAIL( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" );
144 return nullptr;
147 void SfxBasicManagerHolder::impl_releaseContainers()
149 mxBasicContainer.clear();
150 mxDialogContainer.clear();
153 bool SfxBasicManagerHolder::LegacyPsswdBinaryLimitExceeded( std::vector< OUString >& sModules )
155 #if !HAVE_FEATURE_SCRIPTING
156 (void) sModules;
157 #else
158 if ( mpBasicManager )
159 return mpBasicManager->LegacyPsswdBinaryLimitExceeded( sModules );
160 #endif
161 return true;
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();
172 pRet->acquire();
173 return pRet;
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();
184 pRet->acquire();
185 return pRet;
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */