LibreOffice Module sfx2 (master) 1
appbaslib.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <config_features.h>
21
22#include <appbaslib.hxx>
23
24#include <sfx2/app.hxx>
25
26#include <basic/basmgr.hxx>
28#include <com/sun/star/uno/XComponentContext.hpp>
29
30using namespace ::com::sun::star::uno;
31using namespace ::com::sun::star::lang;
32using namespace ::com::sun::star::script;
33using namespace ::com::sun::star::embed;
34
35
37 :mpBasicManager( nullptr )
38{
39}
40
42{
43 if (!mpBasicManager || &rBC != mpBasicManager)
44 return;
45 if (SfxHintId::Dying == rHint.GetId())
46 {
47 mpBasicManager = nullptr;
48 mxBasicContainer.clear();
49 mxDialogContainer.clear();
50 }
51}
52
54{
56
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;
66
67 if ( !mpBasicManager )
68 return;
69
71 try
72 {
75 }
76 catch( const Exception& )
77 {
78 DBG_UNHANDLED_EXCEPTION("sfx.appl");
79 }
80#endif
81}
82
84{
85#if HAVE_FEATURE_SCRIPTING
86 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" );
87 try
88 {
89 if ( mxBasicContainer.is() )
90 mxBasicContainer->storeLibraries();
91 if ( mxDialogContainer.is() )
92 mxDialogContainer->storeLibraries();
93 }
94 catch( const Exception& )
95 {
96 DBG_UNHANDLED_EXCEPTION("sfx.appl");
97 }
98#endif
99}
100
101void SfxBasicManagerHolder::setStorage( const Reference< XStorage >& _rxStorage )
102{
103#if !HAVE_FEATURE_SCRIPTING
104 (void) _rxStorage;
105#else
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("sfx.appl");
116 }
117#endif
118}
119
120void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference< XStorage >& _rxStorage )
121{
122#if !HAVE_FEATURE_SCRIPTING
123 (void) _rxStorage;
124#else
125 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" );
126
127 if ( mxBasicContainer.is() )
128 mxBasicContainer->storeLibrariesToStorage( _rxStorage );
129 if ( mxDialogContainer.is() )
130 mxDialogContainer->storeLibrariesToStorage( _rxStorage );
131#endif
132}
133
135{
136 OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" );
137
138 switch ( _eType )
139 {
140 case SCRIPTS: return mxBasicContainer.get();
141 case DIALOGS: return mxDialogContainer.get();
142 }
143 OSL_FAIL( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" );
144 return nullptr;
145}
146
148{
149 mxBasicContainer.clear();
150 mxDialogContainer.clear();
151}
152
153bool SfxBasicManagerHolder::ImgVersion12PsswdBinaryLimitExceeded( std::vector< OUString >& sModules )
154{
155#if !HAVE_FEATURE_SCRIPTING
156 (void) sModules;
157#else
158 if ( mpBasicManager )
160#endif
161 return true;
162}
163
164// Service for application library container
165extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
167 css::uno::XComponentContext *,
168 css::uno::Sequence<css::uno::Any> const &)
169{
171 css::uno::XInterface* pRet = SfxGetpApp()->GetDialogContainer();
172 pRet->acquire();
173 return pRet;
174}
175
176// Service for application library container
177extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
179 css::uno::XComponentContext *,
180 css::uno::Sequence<css::uno::Any> const &)
181{
183 css::uno::XInterface* pRet = SfxGetpApp()->GetBasicContainer();
184 pRet->acquire();
185 return pRet;
186}
187
188/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxApplication * SfxGetpApp()
Definition: app.hxx:231
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_sfx2_ApplicationScriptLibraryContainer_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: appbaslib.cxx:178
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_sfx2_ApplicationDialogLibraryContainer_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: appbaslib.cxx:166
const css::uno::Reference< css::script::XPersistentLibraryContainer > & GetScriptLibraryContainer() const
const css::uno::Reference< css::script::XPersistentLibraryContainer > & GetDialogLibraryContainer() const
bool ImgVersion12PsswdBinaryLimitExceeded(std::vector< OUString > &_out_rModuleNames)
css::script::XLibraryContainer * GetBasicContainer()
Definition: appbas.cxx:87
static BasicManager * GetBasicManager()
Definition: appbas.cxx:62
css::script::XLibraryContainer * GetDialogContainer()
Definition: appbas.cxx:73
bool isValid() const
returns <TRUE> if and only if the instance is currently bound to a non-<NULL> BasicManager.
Definition: appbaslib.hxx:54
void storeAllLibraries()
calls the storeLibraries at both our script and basic library container
Definition: appbaslib.cxx:83
void reset(BasicManager *_pBasicManager)
binds the instance to the given BasicManager
Definition: appbaslib.cxx:53
css::uno::Reference< css::script::XStorageBasedLibraryContainer > mxBasicContainer
Definition: appbaslib.hxx:39
void setStorage(const css::uno::Reference< css::embed::XStorage > &_rxStorage)
calls the setStorage at all our XStorageBasedLibraryContainer.
Definition: appbaslib.cxx:101
css::uno::Reference< css::script::XStorageBasedLibraryContainer > mxDialogContainer
Definition: appbaslib.hxx:41
void storeLibrariesToStorage(const css::uno::Reference< css::embed::XStorage > &_rxStorage)
calls the storeLibrariesToStorage at all our XStorageBasedLibraryContainer.
Definition: appbaslib.cxx:120
virtual void Notify(SfxBroadcaster &rBC, SfxHint const &rHint) override
Definition: appbaslib.cxx:41
css::script::XLibraryContainer * getLibraryContainer(ContainerType _eType)
Definition: appbaslib.cxx:134
BasicManager * mpBasicManager
Definition: appbaslib.hxx:37
bool ImgVersion12PsswdBinaryLimitExceeded(std::vector< OUString > &sModules)
checks if any modules in the SfxLibraryContainer exceed the binary limits.
Definition: appbaslib.cxx:153
SfxHintId GetId() const
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
#define DBG_UNHANDLED_EXCEPTION(...)
@ Exception
Implementation of the interface com.sun.star.rdf.XDocumentMetadataAccess.