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