Line data Source code
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/sfxuno.hxx>
25 : #include "sfxtypes.hxx"
26 : #include <sfx2/app.hxx>
27 :
28 : #include <basic/basmgr.hxx>
29 : #include <tools/diagnose_ex.h>
30 : #include <comphelper/processfactory.hxx>
31 : #include <cppuhelper/weak.hxx>
32 :
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;
38 : using ::osl::Mutex;
39 :
40 :
41 5149 : SfxBasicManagerHolder::SfxBasicManagerHolder()
42 5149 : :mpBasicManager( NULL )
43 : {
44 5149 : }
45 :
46 4096 : void SfxBasicManagerHolder::Notify(SfxBroadcaster& rBC, SfxHint const& rHint)
47 : {
48 4096 : if (!mpBasicManager || &rBC != mpBasicManager)
49 6144 : return;
50 2048 : SfxSimpleHint const*const pSimpleHint(dynamic_cast<SfxSimpleHint const*>(&rHint));
51 2048 : if (pSimpleHint && SFX_HINT_DYING == pSimpleHint->GetId())
52 : {
53 2048 : mpBasicManager = nullptr;
54 2048 : mxBasicContainer.clear();
55 2048 : mxDialogContainer.clear();
56 : }
57 : }
58 :
59 7160 : void SfxBasicManagerHolder::reset( BasicManager* _pBasicManager )
60 : {
61 7160 : impl_releaseContainers();
62 :
63 : #if !HAVE_FEATURE_SCRIPTING
64 : (void) _pBasicManager;
65 : #else
66 : // Note: we do not delete the old BasicManager. BasicManager instances are
67 : // nowadays obtained from the BasicManagerRepository, and the ownership is with
68 : // the repository.
69 : // @see basic::BasicManagerRepository::getApplicationBasicManager
70 : // @see basic::BasicManagerRepository::getDocumentBasicManager
71 7160 : mpBasicManager = _pBasicManager;
72 :
73 7160 : if ( mpBasicManager )
74 : {
75 2113 : StartListening(*mpBasicManager);
76 : try
77 : {
78 2113 : mxBasicContainer.set( mpBasicManager->GetScriptLibraryContainer(), UNO_QUERY_THROW );
79 2113 : mxDialogContainer.set( mpBasicManager->GetDialogLibraryContainer(), UNO_QUERY_THROW );
80 : }
81 0 : catch( const Exception& )
82 : {
83 : DBG_UNHANDLED_EXCEPTION();
84 : }
85 : }
86 : #endif
87 7160 : }
88 :
89 46 : void SfxBasicManagerHolder::storeAllLibraries()
90 : {
91 : #if HAVE_FEATURE_SCRIPTING
92 : OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeAllLibraries: not initialized!" );
93 : try
94 : {
95 46 : if ( mxBasicContainer.is() )
96 46 : mxBasicContainer->storeLibraries();
97 46 : if ( mxDialogContainer.is() )
98 46 : mxDialogContainer->storeLibraries();
99 : }
100 0 : catch( const Exception& )
101 : {
102 : DBG_UNHANDLED_EXCEPTION();
103 : }
104 : #endif
105 46 : }
106 :
107 609 : void SfxBasicManagerHolder::setStorage( const Reference< XStorage >& _rxStorage )
108 : {
109 : #if !HAVE_FEATURE_SCRIPTING
110 : (void) _rxStorage;
111 : #else
112 : try
113 : {
114 609 : if ( mxBasicContainer.is() )
115 604 : mxBasicContainer->setRootStorage( _rxStorage );
116 609 : if ( mxDialogContainer.is() )
117 604 : mxDialogContainer->setRootStorage( _rxStorage );
118 : }
119 0 : catch( const Exception& )
120 : {
121 : DBG_UNHANDLED_EXCEPTION();
122 : }
123 : #endif
124 609 : }
125 :
126 653 : void SfxBasicManagerHolder::storeLibrariesToStorage( const Reference< XStorage >& _rxStorage )
127 : {
128 : #if !HAVE_FEATURE_SCRIPTING
129 : (void) _rxStorage;
130 : #else
131 : OSL_PRECOND( isValid(), "SfxBasicManagerHolder::storeLibrariesToStorage: not initialized!" );
132 :
133 653 : if ( mxBasicContainer.is() )
134 653 : mxBasicContainer->storeLibrariesToStorage( _rxStorage );
135 653 : if ( mxDialogContainer.is() )
136 653 : mxDialogContainer->storeLibrariesToStorage( _rxStorage );
137 : #endif
138 653 : }
139 :
140 50 : XLibraryContainer * SfxBasicManagerHolder::getLibraryContainer( ContainerType _eType )
141 : {
142 : OSL_PRECOND( isValid(), "SfxBasicManagerHolder::getLibraryContainer: not initialized!" );
143 :
144 50 : switch ( _eType )
145 : {
146 50 : case SCRIPTS: return mxBasicContainer.get();
147 0 : case DIALOGS: return mxDialogContainer.get();
148 : }
149 : OSL_FAIL( "SfxBasicManagerHolder::getLibraryContainer: illegal container type!" );
150 0 : return NULL;
151 : }
152 :
153 7160 : void SfxBasicManagerHolder::impl_releaseContainers()
154 : {
155 7160 : mxBasicContainer.clear();
156 7160 : mxDialogContainer.clear();
157 7160 : }
158 :
159 52 : bool SfxBasicManagerHolder::LegacyPsswdBinaryLimitExceeded( Sequence< OUString >& sModules )
160 : {
161 : #if !HAVE_FEATURE_SCRIPTING
162 : (void) sModules;
163 : #else
164 52 : if ( mpBasicManager )
165 52 : return mpBasicManager->LegacyPsswdBinaryLimitExceeded( sModules );
166 : #endif
167 0 : return true;
168 : }
169 :
170 : // Service for application library container
171 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
172 0 : com_sun_star_comp_sfx2_ApplicationDialogLibraryContainer_get_implementation(
173 : css::uno::XComponentContext *,
174 : css::uno::Sequence<css::uno::Any> const &)
175 : {
176 0 : SfxApplication::GetBasicManager();
177 0 : css::uno::XInterface* pRet = SfxGetpApp()->GetDialogContainer();
178 0 : pRet->acquire();
179 0 : return pRet;
180 : }
181 :
182 : // Service for application library container
183 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
184 0 : com_sun_star_comp_sfx2_ApplicationScriptLibraryContainer_get_implementation(
185 : css::uno::XComponentContext *,
186 : css::uno::Sequence<css::uno::Any> const &)
187 : {
188 0 : SfxApplication::GetBasicManager();
189 0 : css::uno::XInterface* pRet = SfxGetpApp()->GetBasicContainer();
190 0 : pRet->acquire();
191 0 : return pRet;
192 : }
193 :
194 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|