/src/libreoffice/sfx2/source/doc/objxtor.cxx
Line | Count | Source |
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 | | #include <config_fuzzers.h> |
22 | | |
23 | | #include <map> |
24 | | |
25 | | #include <cppuhelper/implbase.hxx> |
26 | | #include <cppuhelper/weakref.hxx> |
27 | | |
28 | | #include <com/sun/star/util/XCloseable.hpp> |
29 | | #include <com/sun/star/frame/XComponentLoader.hpp> |
30 | | #include <com/sun/star/frame/Desktop.hpp> |
31 | | #include <com/sun/star/util/CloseVetoException.hpp> |
32 | | #include <com/sun/star/util/XCloseListener.hpp> |
33 | | #include <com/sun/star/beans/XPropertySet.hpp> |
34 | | #include <com/sun/star/frame/XTitle.hpp> |
35 | | #include <osl/file.hxx> |
36 | | #include <sal/log.hxx> |
37 | | #include <vcl/weld.hxx> |
38 | | #include <vcl/svapp.hxx> |
39 | | #include <svl/eitem.hxx> |
40 | | #include <basic/sbstar.hxx> |
41 | | #include <svl/stritem.hxx> |
42 | | #include <unotools/configmgr.hxx> |
43 | | #include <unotools/eventcfg.hxx> |
44 | | |
45 | | #include <sfx2/objsh.hxx> |
46 | | #include <sfx2/signaturestate.hxx> |
47 | | #include <sfx2/sfxmodelfactory.hxx> |
48 | | |
49 | | #include <comphelper/configuration.hxx> |
50 | | #include <comphelper/processfactory.hxx> |
51 | | #include <comphelper/servicehelper.hxx> |
52 | | |
53 | | #include <com/sun/star/document/XStorageBasedDocument.hpp> |
54 | | #include <com/sun/star/script/DocumentDialogLibraryContainer.hpp> |
55 | | #include <com/sun/star/script/DocumentScriptLibraryContainer.hpp> |
56 | | #include <com/sun/star/document/XEmbeddedScripts.hpp> |
57 | | #include <com/sun/star/document/XScriptInvocationContext.hpp> |
58 | | #include <com/sun/star/ucb/ContentCreationException.hpp> |
59 | | #include <com/sun/star/lang/XMultiServiceFactory.hpp> |
60 | | |
61 | | #include <unotools/ucbhelper.hxx> |
62 | | #include <comphelper/diagnose_ex.hxx> |
63 | | #include <tools/globname.hxx> |
64 | | #include <tools/debug.hxx> |
65 | | |
66 | | #include <sfx2/app.hxx> |
67 | | #include <sfx2/bindings.hxx> |
68 | | #include <sfx2/docfile.hxx> |
69 | | #include <sfx2/event.hxx> |
70 | | #include <sfx2/viewsh.hxx> |
71 | | #include <sfx2/viewfrm.hxx> |
72 | | #include <sfx2/sfxresid.hxx> |
73 | | #include <objshimp.hxx> |
74 | | #include <sfx2/strings.hrc> |
75 | | #include <sfx2/sfxsids.hrc> |
76 | | #include <basic/basmgr.hxx> |
77 | | #include <sfx2/QuerySaveDocument.hxx> |
78 | | #include <appbaslib.hxx> |
79 | | #include <sfx2/sfxbasemodel.hxx> |
80 | | #include <sfx2/sfxuno.hxx> |
81 | | #include <sfx2/notebookbar/SfxNotebookBar.hxx> |
82 | | #include <sfx2/infobar.hxx> |
83 | | #include <svtools/svparser.hxx> |
84 | | |
85 | | #include <basic/basicmanagerrepository.hxx> |
86 | | |
87 | | using namespace ::com::sun::star; |
88 | | using namespace ::com::sun::star::uno; |
89 | | using namespace ::com::sun::star::script; |
90 | | using namespace ::com::sun::star::frame; |
91 | | using namespace ::com::sun::star::document; |
92 | | |
93 | | using ::basic::BasicManagerRepository; |
94 | | |
95 | | namespace { |
96 | | |
97 | | WeakReference< XInterface > theCurrentComponent; |
98 | | |
99 | | #if HAVE_FEATURE_SCRIPTING |
100 | | |
101 | | // remember all registered components for VBA compatibility, to be able to remove them on disposing the model |
102 | | typedef ::std::map< XInterface*, OUString > VBAConstantNameMap; |
103 | | VBAConstantNameMap s_aRegisteredVBAConstants; |
104 | | |
105 | | OUString lclGetVBAGlobalConstName( const Reference< XInterface >& rxComponent ) |
106 | | { |
107 | | OSL_ENSURE( rxComponent.is(), "lclGetVBAGlobalConstName - missing component" ); |
108 | | |
109 | | VBAConstantNameMap::iterator aIt = s_aRegisteredVBAConstants.find( rxComponent.get() ); |
110 | | if( aIt != s_aRegisteredVBAConstants.end() ) |
111 | | return aIt->second; |
112 | | |
113 | | uno::Reference< beans::XPropertySet > xProps( rxComponent, uno::UNO_QUERY ); |
114 | | if( xProps.is() ) try |
115 | | { |
116 | | OUString aConstName; |
117 | | xProps->getPropertyValue(u"VBAGlobalConstantName"_ustr) >>= aConstName; |
118 | | return aConstName; |
119 | | } |
120 | | catch (const uno::Exception&) // not supported |
121 | | { |
122 | | } |
123 | | return OUString(); |
124 | | } |
125 | | |
126 | | #endif |
127 | | |
128 | | class SfxModelListener_Impl : public ::cppu::WeakImplHelper< css::util::XCloseListener > |
129 | | { |
130 | | SfxObjectShell* mpDoc; |
131 | | public: |
132 | 197k | explicit SfxModelListener_Impl( SfxObjectShell* pDoc ) : mpDoc(pDoc) {}; |
133 | | virtual void SAL_CALL queryClosing( const css::lang::EventObject& aEvent, sal_Bool bDeliverOwnership ) override ; |
134 | | virtual void SAL_CALL notifyClosing( const css::lang::EventObject& aEvent ) override ; |
135 | | virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent ) override ; |
136 | | |
137 | | }; |
138 | | |
139 | | } // namespace |
140 | | |
141 | | void SAL_CALL SfxModelListener_Impl::queryClosing( const css::lang::EventObject& , sal_Bool bDeliverOwnership) |
142 | 197k | { |
143 | 197k | if (mpDoc->Get_Impl()->m_nClosingLockLevel) |
144 | 0 | { |
145 | 0 | if (bDeliverOwnership) |
146 | 0 | mpDoc->Get_Impl()->m_bCloseModelScheduled = true; |
147 | 0 | throw util::CloseVetoException(u"Closing document is blocked"_ustr, getXWeak()); |
148 | 0 | } |
149 | 197k | } |
150 | | |
151 | | void SAL_CALL SfxModelListener_Impl::notifyClosing( const css::lang::EventObject& ) |
152 | 197k | { |
153 | 197k | SolarMutexGuard aSolarGuard; |
154 | 197k | mpDoc->Broadcast( SfxHint(SfxHintId::Deinitializing) ); |
155 | 197k | } |
156 | | |
157 | | void SAL_CALL SfxModelListener_Impl::disposing( const css::lang::EventObject& _rEvent ) |
158 | 197k | { |
159 | | // am I ThisComponent in AppBasic? |
160 | 197k | SolarMutexGuard aSolarGuard; |
161 | 197k | if ( SfxObjectShell::GetCurrentComponent() == _rEvent.Source ) |
162 | 0 | { |
163 | | // remove ThisComponent reference from AppBasic |
164 | 0 | SfxObjectShell::SetCurrentComponent( Reference< XInterface >() ); |
165 | 0 | } |
166 | | |
167 | | #if HAVE_FEATURE_SCRIPTING |
168 | | /* Remove VBA component from AppBasic. As every application registers its |
169 | | own current component, the disposed component may not be the "current |
170 | | component" of the SfxObjectShell. */ |
171 | | if ( _rEvent.Source.is() ) |
172 | | { |
173 | | VBAConstantNameMap::iterator aIt = s_aRegisteredVBAConstants.find( _rEvent.Source.get() ); |
174 | | if ( aIt != s_aRegisteredVBAConstants.end() ) |
175 | | { |
176 | | if ( BasicManager* pAppMgr = SfxApplication::GetBasicManager() ) |
177 | | pAppMgr->SetGlobalUNOConstant( aIt->second, Any( Reference< XInterface >() ) ); |
178 | | s_aRegisteredVBAConstants.erase( aIt ); |
179 | | } |
180 | | } |
181 | | #endif |
182 | | |
183 | 197k | if ( !mpDoc->Get_Impl()->bClosing ) |
184 | | // GCC crashes when already in the destructor, so first query the Flag |
185 | 3.56k | mpDoc->DoClose(); |
186 | 197k | } |
187 | | |
188 | | |
189 | | SfxObjectShell_Impl::SfxObjectShell_Impl( SfxObjectShell& _rDocShell ) |
190 | 197k | :rDocShell( _rDocShell ) |
191 | 197k | ,aMacroMode( *this ) |
192 | 197k | ,pProgress( nullptr) |
193 | 197k | ,nTime( DateTime::SYSTEM ) |
194 | 197k | ,nVisualDocumentNumber( USHRT_MAX) |
195 | 197k | ,nDocumentSignatureState( SignatureState::UNKNOWN ) |
196 | 197k | ,nScriptingSignatureState( SignatureState::UNKNOWN ) |
197 | 197k | ,bClosing( false) |
198 | 197k | ,bIsSaving( false) |
199 | 197k | ,bIsNamedVisible( false) |
200 | 197k | ,bIsAbortingImport ( false) |
201 | 197k | ,bInPrepareClose( false ) |
202 | 197k | ,bPreparedForClose( false ) |
203 | 197k | ,bForbidReload( false ) |
204 | 197k | ,bBasicInitialized( false ) |
205 | 197k | ,bIsPrintJobCancelable( true ) |
206 | 197k | ,bOwnsStorage( true ) |
207 | 197k | ,bInitialized( false ) |
208 | 197k | ,bModelInitialized( false ) |
209 | 197k | ,bPreserveVersions( true ) |
210 | 197k | ,m_bMacroSignBroken( false ) |
211 | 197k | ,m_bNoBasicCapabilities( false ) |
212 | 197k | ,m_bDocRecoverySupport( true ) |
213 | 197k | ,bQueryLoadTemplate( true ) |
214 | 197k | ,bLoadReadonly( false ) |
215 | 197k | ,bUseUserData( true ) |
216 | 197k | ,bUseThumbnailSave( true ) |
217 | 197k | ,bSaveVersionOnClose( false ) |
218 | 197k | ,m_bSharedXMLFlag( false ) |
219 | 197k | ,m_bAllowShareControlFileClean( true ) |
220 | 197k | ,m_bConfigOptionsChecked( false ) |
221 | 197k | ,m_bMacroCallsSeenWhileLoading( false ) |
222 | 197k | ,m_bHadCheckedMacrosOnLoad( false ) |
223 | 197k | ,lErr(ERRCODE_NONE) |
224 | 197k | ,nEventId ( SfxEventHintId::NONE ) |
225 | 197k | ,nLoadedFlags ( SfxLoadedFlags::ALL ) |
226 | 197k | ,nFlagsInProgress( SfxLoadedFlags::NONE ) |
227 | 197k | ,bModalMode( false ) |
228 | 197k | ,bRunningMacro( false ) |
229 | 197k | ,bReadOnlyUI( false ) |
230 | 197k | ,nStyleFilter( 0 ) |
231 | 197k | ,m_bEnableSetModified( true ) |
232 | 197k | ,m_bIsModified( false ) |
233 | 197k | ,m_nMapUnit( MapUnit::Map100thMM ) |
234 | 197k | ,m_bCreateTempStor( false ) |
235 | 197k | ,m_bIsInit( false ) |
236 | 197k | ,m_bIncomplEncrWarnShown( false ) |
237 | 197k | ,m_nModifyPasswordHash( 0 ) |
238 | 197k | ,m_bModifyPasswordEntered( false ) |
239 | 197k | ,m_bSavingForSigning( false ) |
240 | 197k | ,m_bAllowModifiedBackAfterSigning( false ) |
241 | 197k | { |
242 | 197k | SfxObjectShell* pDoc = &_rDocShell; |
243 | 197k | std::vector<SfxObjectShell*> &rArr = SfxGetpApp()->GetObjectShells_Impl(); |
244 | 197k | rArr.push_back( pDoc ); |
245 | 197k | } |
246 | | |
247 | | |
248 | | SfxObjectShell_Impl::~SfxObjectShell_Impl() |
249 | 197k | { |
250 | 197k | } |
251 | | |
252 | | |
253 | | SfxObjectShell::SfxObjectShell( const SfxModelFlags i_nCreationFlags ) |
254 | 90.1k | : pImpl(new SfxObjectShell_Impl(*this)) |
255 | 90.1k | , pMedium(nullptr) |
256 | 90.1k | , eCreateMode(SfxObjectCreateMode::STANDARD) |
257 | 90.1k | , bHasName(false) |
258 | 90.1k | , bIsInGenerateThumbnail (false) |
259 | 90.1k | , mbAvoidRecentDocs(false) |
260 | 90.1k | , bRememberSignature(false) |
261 | 90.1k | { |
262 | 90.1k | if (i_nCreationFlags & SfxModelFlags::EMBEDDED_OBJECT) |
263 | 82.9k | eCreateMode = SfxObjectCreateMode::EMBEDDED; |
264 | 7.25k | else if (i_nCreationFlags & SfxModelFlags::EXTERNAL_LINK) |
265 | 0 | eCreateMode = SfxObjectCreateMode::INTERNAL; |
266 | | |
267 | 90.1k | const bool bScriptSupport = ( i_nCreationFlags & SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS ) == SfxModelFlags::NONE; |
268 | 90.1k | if ( !bScriptSupport ) |
269 | 25.4k | pImpl->m_bNoBasicCapabilities = true; |
270 | | |
271 | 90.1k | const bool bDocRecovery = ( i_nCreationFlags & SfxModelFlags::DISABLE_DOCUMENT_RECOVERY ) == SfxModelFlags::NONE; |
272 | 90.1k | if ( !bDocRecovery ) |
273 | 25.4k | pImpl->m_bDocRecoverySupport = false; |
274 | 90.1k | } |
275 | | |
276 | | /** Constructor of the class SfxObjectShell. |
277 | | |
278 | | @param eMode Purpose, to which the SfxObjectShell is created: |
279 | | SfxObjectCreateMode::EMBEDDED (default) as SO-Server from within another Document |
280 | | SfxObjectCreateMode::STANDARD, as a normal Document open stand-alone |
281 | | SfxObjectCreateMode::ORGANIZER to be displayed in the Organizer, here nothing of the contents is used |
282 | | */ |
283 | | SfxObjectShell::SfxObjectShell(SfxObjectCreateMode eMode) |
284 | 107k | : pImpl(new SfxObjectShell_Impl(*this)) |
285 | 107k | , pMedium(nullptr) |
286 | 107k | , eCreateMode(eMode) |
287 | 107k | , bHasName(false) |
288 | 107k | , bIsInGenerateThumbnail(false) |
289 | 107k | , mbAvoidRecentDocs(false) |
290 | 107k | , bRememberSignature(false) |
291 | 107k | { |
292 | 107k | } |
293 | | |
294 | | SfxObjectShell::~SfxObjectShell() |
295 | 197k | { |
296 | | |
297 | 197k | if ( IsEnableSetModified() ) |
298 | 113k | EnableSetModified( false ); |
299 | | |
300 | 197k | SfxObjectShell::CloseInternal(); |
301 | 197k | pImpl->pBaseModel.clear(); |
302 | | |
303 | 197k | pImpl->pReloadTimer.reset(); |
304 | | |
305 | 197k | SfxApplication *pSfxApp = SfxGetpApp(); |
306 | 197k | if ( USHRT_MAX != pImpl->nVisualDocumentNumber && pSfxApp ) |
307 | 3.67k | pSfxApp->ReleaseIndex(pImpl->nVisualDocumentNumber); |
308 | | |
309 | | // Destroy Basic-Manager |
310 | 197k | pImpl->aBasicManager.reset(nullptr); |
311 | | |
312 | 197k | if ( pSfxApp && pSfxApp->GetDdeService() ) |
313 | 0 | pSfxApp->RemoveDdeTopic( this ); |
314 | | |
315 | 197k | InternalCloseAndRemoveFiles(); |
316 | 197k | } |
317 | | |
318 | | void SfxObjectShell::InternalCloseAndRemoveFiles() |
319 | 197k | { |
320 | | // don't call GetStorage() here, in case of Load Failure it's possible that a storage was never assigned! |
321 | 197k | if ( pMedium && pMedium->HasStorage_Impl() && pMedium->GetStorage( false ) == pImpl->m_xDocStorage ) |
322 | 0 | pMedium->CanDisposeStorage_Impl( false ); |
323 | | |
324 | 197k | if ( pImpl->mxObjectContainer ) |
325 | 53.3k | { |
326 | 53.3k | pImpl->mxObjectContainer->CloseEmbeddedObjects(); |
327 | 53.3k | pImpl->mxObjectContainer.reset(); |
328 | 53.3k | } |
329 | | |
330 | 197k | if ( pImpl->bOwnsStorage && pImpl->m_xDocStorage.is() ) |
331 | 115k | pImpl->m_xDocStorage->dispose(); |
332 | | |
333 | 197k | if ( pMedium ) |
334 | 182k | { |
335 | 182k | pMedium->CloseAndReleaseStreams_Impl(); |
336 | | |
337 | | #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT |
338 | | if (IsDocShared()) |
339 | | FreeSharedFile( pMedium->GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE ) ); |
340 | | #endif |
341 | 182k | delete pMedium; |
342 | 182k | pMedium = nullptr; |
343 | 182k | } |
344 | | |
345 | | // The removing of the temporary file must be done as the latest step in the document destruction |
346 | 197k | if ( !pImpl->aTempName.isEmpty() ) |
347 | 0 | { |
348 | 0 | OUString aTmp; |
349 | 0 | osl::FileBase::getFileURLFromSystemPath( pImpl->aTempName, aTmp ); |
350 | 0 | ::utl::UCBContentHelper::Kill( aTmp ); |
351 | 0 | } |
352 | 197k | } |
353 | | |
354 | | SfxCloseVetoLock::SfxCloseVetoLock(const SfxObjectShell* pDocShell) |
355 | 796 | : mpDocShell(pDocShell) |
356 | 796 | { |
357 | 796 | if (mpDocShell) |
358 | 796 | osl_atomic_increment(&mpDocShell->Get_Impl()->m_nClosingLockLevel); |
359 | 796 | } |
360 | | |
361 | | SfxCloseVetoLock::~SfxCloseVetoLock() |
362 | 796 | { |
363 | 796 | if (mpDocShell && osl_atomic_decrement(&mpDocShell->Get_Impl()->m_nClosingLockLevel) == 0) |
364 | 796 | { |
365 | 796 | if (mpDocShell->Get_Impl()->m_bCloseModelScheduled) |
366 | 0 | { |
367 | 0 | mpDocShell->Get_Impl()->m_bCloseModelScheduled = false; // pass ownership |
368 | 0 | if (rtl::Reference model = static_cast<SfxBaseModel*>(mpDocShell->GetBaseModel().get())) |
369 | 0 | { |
370 | 0 | try |
371 | 0 | { |
372 | 0 | model->close(true); |
373 | 0 | } |
374 | 0 | catch (const util::CloseVetoException&) |
375 | 0 | { |
376 | 0 | DBG_UNHANDLED_EXCEPTION("sfx.doc"); |
377 | 0 | } |
378 | 0 | } |
379 | 0 | } |
380 | 796 | } |
381 | 796 | } |
382 | | |
383 | | void SfxObjectShell::Stamp_SetPrintCancelState(bool bState) |
384 | 1.21k | { |
385 | 1.21k | pImpl->bIsPrintJobCancelable = bState; |
386 | 1.21k | } |
387 | | |
388 | | |
389 | | bool SfxObjectShell::Stamp_GetPrintCancelState() const |
390 | 0 | { |
391 | 0 | return pImpl->bIsPrintJobCancelable; |
392 | 0 | } |
393 | | |
394 | | |
395 | | // closes the Object and all its views |
396 | | |
397 | | bool SfxObjectShell::Close() |
398 | 281k | { |
399 | 281k | SfxObjectShellRef xKeepAlive(this); |
400 | 281k | return CloseInternal(); |
401 | 281k | } |
402 | | |
403 | | // variant that does not take a reference to itself, so we can call it during object destruction |
404 | | bool SfxObjectShell::CloseInternal() |
405 | 479k | { |
406 | 479k | if ( !pImpl->bClosing ) |
407 | 197k | { |
408 | | // Do not close if a progress is still running |
409 | 197k | if ( GetProgress() ) |
410 | 0 | return false; |
411 | | |
412 | 197k | pImpl->bClosing = true; |
413 | 197k | Reference< util::XCloseable > xCloseable( GetBaseModel(), UNO_QUERY ); |
414 | | |
415 | 197k | if ( xCloseable.is() ) |
416 | 197k | { |
417 | 197k | try |
418 | 197k | { |
419 | 197k | xCloseable->close( true ); |
420 | 197k | } |
421 | 197k | catch (const Exception&) |
422 | 197k | { |
423 | 0 | pImpl->bClosing = false; |
424 | 0 | } |
425 | 197k | } |
426 | | |
427 | 197k | if ( pImpl->bClosing ) |
428 | 197k | { |
429 | | // remove from Document list |
430 | | // If there is no App, there is no document to remove |
431 | | // no need to call GetOrCreate here |
432 | 197k | SfxApplication *pSfxApp = SfxApplication::Get(); |
433 | 197k | if(pSfxApp) |
434 | 197k | { |
435 | 197k | std::vector<SfxObjectShell*> &rDocs = pSfxApp->GetObjectShells_Impl(); |
436 | 197k | auto it = std::find( rDocs.begin(), rDocs.end(), this ); |
437 | 197k | if ( it != rDocs.end() ) |
438 | 197k | rDocs.erase( it ); |
439 | 197k | } |
440 | 197k | } |
441 | 197k | } |
442 | | |
443 | 479k | return true; |
444 | 479k | } |
445 | | |
446 | | OUString SfxObjectShell::CreateShellID( const SfxObjectShell* pShell ) |
447 | 14.9k | { |
448 | 14.9k | if (!pShell) |
449 | 0 | return OUString(); |
450 | | |
451 | 14.9k | OUString aShellID; |
452 | | |
453 | 14.9k | SfxMedium* pMedium = pShell->GetMedium(); |
454 | 14.9k | if (pMedium) |
455 | 14.9k | aShellID = pMedium->GetBaseURL(); |
456 | | |
457 | 14.9k | if (!aShellID.isEmpty()) |
458 | 0 | return aShellID; |
459 | | |
460 | 14.9k | sal_Int64 nShellID = reinterpret_cast<sal_Int64>(pShell); |
461 | 14.9k | aShellID = "0x" + OUString::number(nShellID, 16); |
462 | 14.9k | return aShellID; |
463 | 14.9k | } |
464 | | |
465 | | // returns a pointer the first SfxDocument of specified type |
466 | | |
467 | | SfxObjectShell* SfxObjectShell::GetFirst |
468 | | ( |
469 | | const std::function<bool ( const SfxObjectShell* )>& isObjectShell, |
470 | | bool bOnlyVisible |
471 | | ) |
472 | 276k | { |
473 | 276k | std::vector<SfxObjectShell*> &rDocs = SfxGetpApp()->GetObjectShells_Impl(); |
474 | | |
475 | | // search for a SfxDocument of the specified type |
476 | 276k | for (SfxObjectShell* pSh : rDocs) |
477 | 68.4k | { |
478 | 68.4k | if ( bOnlyVisible && pSh->IsPreview() && pSh->IsReadOnly() ) |
479 | 0 | continue; |
480 | | |
481 | 68.4k | if ( (!isObjectShell || isObjectShell( pSh)) && |
482 | 68.4k | ( !bOnlyVisible || SfxViewFrame::GetFirst( pSh ))) |
483 | 66.4k | return pSh; |
484 | 68.4k | } |
485 | | |
486 | 209k | return nullptr; |
487 | 276k | } |
488 | | |
489 | | |
490 | | // returns a pointer to the next SfxDocument of specified type behind *pDoc |
491 | | |
492 | | SfxObjectShell* SfxObjectShell::GetNext |
493 | | ( |
494 | | const SfxObjectShell& rPrev, |
495 | | const std::function<bool ( const SfxObjectShell* )>& isObjectShell, |
496 | | bool bOnlyVisible |
497 | | ) |
498 | 65.2k | { |
499 | 65.2k | std::vector<SfxObjectShell*> &rDocs = SfxGetpApp()->GetObjectShells_Impl(); |
500 | | |
501 | | // refind the specified predecessor |
502 | 65.2k | size_t nPos; |
503 | 65.2k | for ( nPos = 0; nPos < rDocs.size(); ++nPos ) |
504 | 65.2k | if ( rDocs[nPos] == &rPrev ) |
505 | 65.2k | break; |
506 | | |
507 | | // search for the next SfxDocument of the specified type |
508 | 65.2k | for ( ++nPos; nPos < rDocs.size(); ++nPos ) |
509 | 0 | { |
510 | 0 | SfxObjectShell* pSh = rDocs[ nPos ]; |
511 | 0 | if ( bOnlyVisible && pSh->IsPreview() && pSh->IsReadOnly() ) |
512 | 0 | continue; |
513 | | |
514 | 0 | if ( (!isObjectShell || isObjectShell( pSh)) && |
515 | 0 | ( !bOnlyVisible || SfxViewFrame::GetFirst( pSh ))) |
516 | 0 | return pSh; |
517 | 0 | } |
518 | 65.2k | return nullptr; |
519 | 65.2k | } |
520 | | |
521 | | SfxObjectShell* SfxObjectShell::Current() |
522 | 504k | { |
523 | 504k | SfxViewFrame *pFrame = SfxViewFrame::Current(); |
524 | 504k | return pFrame ? pFrame->GetObjectShell() : nullptr; |
525 | 504k | } |
526 | | |
527 | | bool SfxObjectShell::IsInPrepareClose() const |
528 | 0 | { |
529 | 0 | return pImpl->bInPrepareClose; |
530 | 0 | } |
531 | | |
532 | | namespace { |
533 | | |
534 | | struct BoolEnv_Impl |
535 | | { |
536 | | SfxObjectShell_Impl& rImpl; |
537 | 0 | explicit BoolEnv_Impl( SfxObjectShell_Impl& rImplP) : rImpl( rImplP ) |
538 | 0 | { rImplP.bInPrepareClose = true; } |
539 | 0 | ~BoolEnv_Impl() { rImpl.bInPrepareClose = false; } |
540 | | }; |
541 | | |
542 | | } |
543 | | |
544 | | bool SfxObjectShell::PrepareClose |
545 | | ( |
546 | | bool bUI // true: Dialog and so on is allowed |
547 | | // false: silent-mode |
548 | | ) |
549 | 0 | { |
550 | 0 | if( pImpl->bInPrepareClose || pImpl->bPreparedForClose ) |
551 | 0 | return true; |
552 | 0 | BoolEnv_Impl aBoolEnv( *pImpl ); |
553 | | |
554 | | // DocModalDialog? |
555 | 0 | if ( IsInModalMode() ) |
556 | 0 | return false; |
557 | | |
558 | 0 | SfxViewFrame* pFirst = SfxViewFrame::GetFirst( this ); |
559 | 0 | if( pFirst && !pFirst->GetFrame().PrepareClose_Impl( bUI ) ) |
560 | 0 | return false; |
561 | | |
562 | | // prepare views for closing |
563 | 0 | for ( SfxViewFrame* pFrm = SfxViewFrame::GetFirst( this ); |
564 | 0 | pFrm; pFrm = SfxViewFrame::GetNext( *pFrm, this ) ) |
565 | 0 | { |
566 | 0 | DBG_ASSERT(pFrm->GetViewShell(),"No Shell"); |
567 | 0 | if ( pFrm->GetViewShell() ) |
568 | 0 | { |
569 | 0 | bool bRet = pFrm->GetViewShell()->PrepareClose( bUI ); |
570 | 0 | if ( !bRet ) |
571 | 0 | return bRet; |
572 | 0 | } |
573 | 0 | } |
574 | | |
575 | 0 | SfxApplication *pSfxApp = SfxGetpApp(); |
576 | 0 | pSfxApp->NotifyEvent( SfxEventHint(SfxEventHintId::PrepareCloseDoc, GlobalEventConfig::GetEventName(GlobalEventId::PREPARECLOSEDOC), this) ); |
577 | |
|
578 | 0 | if( GetCreateMode() == SfxObjectCreateMode::EMBEDDED ) |
579 | 0 | { |
580 | 0 | pImpl->bPreparedForClose = true; |
581 | 0 | return true; |
582 | 0 | } |
583 | | |
584 | | // Ask if possible if it should be saved |
585 | | // only ask for the Document in the visible window |
586 | 0 | SfxViewFrame *pFrame = SfxObjectShell::Current() == this |
587 | 0 | ? SfxViewFrame::Current() : SfxViewFrame::GetFirst( this ); |
588 | |
|
589 | 0 | if ( bUI && IsModified() && pFrame ) |
590 | 0 | { |
591 | | // restore minimized |
592 | 0 | SfxFrame& rTop = pFrame->GetFrame(); |
593 | 0 | SfxViewFrame::SetViewFrame( rTop.GetCurrentViewFrame() ); |
594 | 0 | pFrame->GetFrame().Appear(); |
595 | | |
596 | | // Ask if to save |
597 | 0 | short nRet = RET_YES; |
598 | 0 | { |
599 | 0 | const Reference<XTitle> xTitle(*pImpl->pBaseModel, UNO_QUERY_THROW); |
600 | 0 | const OUString sTitle = xTitle->getTitle (); |
601 | 0 | nRet = ExecuteQuerySaveDocument(pFrame->GetFrameWeld(), sTitle); |
602 | 0 | } |
603 | | /*HACK for plugin::destroy()*/ |
604 | |
|
605 | 0 | if ( RET_YES == nRet ) |
606 | 0 | { |
607 | | // Save by each Dispatcher |
608 | 0 | SfxPoolItemHolder aPoolItem; |
609 | 0 | if (IsReadOnly()) |
610 | 0 | { |
611 | 0 | SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI ); |
612 | 0 | const SfxPoolItem* ppArgs[] = { &aWarnItem, nullptr }; |
613 | 0 | aPoolItem = pFrame->GetBindings().ExecuteSynchron(SID_SAVEASDOC, ppArgs); |
614 | 0 | } |
615 | 0 | else if (IsSaveVersionOnClose()) |
616 | 0 | { |
617 | 0 | SfxStringItem aItem( SID_DOCINFO_COMMENTS, SfxResId(STR_AUTOMATICVERSION) ); |
618 | 0 | SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI ); |
619 | 0 | const SfxPoolItem* ppArgs[] = { &aItem, &aWarnItem, nullptr }; |
620 | 0 | aPoolItem = pFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, ppArgs ); |
621 | 0 | } |
622 | 0 | else |
623 | 0 | { |
624 | 0 | SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI ); |
625 | 0 | const SfxPoolItem* ppArgs[] = { &aWarnItem, nullptr }; |
626 | 0 | aPoolItem = pFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, ppArgs ); |
627 | 0 | } |
628 | |
|
629 | 0 | if (!aPoolItem || IsDisabledItem(aPoolItem.getItem()) ) |
630 | 0 | return false; |
631 | 0 | if ( auto pBoolItem = dynamic_cast< const SfxBoolItem *>( aPoolItem.getItem() ) ) |
632 | 0 | if ( !pBoolItem->GetValue() ) |
633 | 0 | return false; |
634 | 0 | } |
635 | 0 | else if ( RET_CANCEL == nRet ) |
636 | | // Cancelled |
637 | 0 | return false; |
638 | 0 | } |
639 | | |
640 | 0 | if ( pFrame ) |
641 | 0 | sfx2::SfxNotebookBar::CloseMethod(pFrame->GetBindings()); |
642 | 0 | pImpl->bPreparedForClose = true; |
643 | 0 | return true; |
644 | 0 | } |
645 | | |
646 | | |
647 | | #if HAVE_FEATURE_SCRIPTING |
648 | | namespace |
649 | | { |
650 | | BasicManager* lcl_getBasicManagerForDocument( const SfxObjectShell& _rDocument ) |
651 | | { |
652 | | if ( !_rDocument.Get_Impl()->m_bNoBasicCapabilities ) |
653 | | { |
654 | | if ( !_rDocument.Get_Impl()->bBasicInitialized ) |
655 | | const_cast< SfxObjectShell& >( _rDocument ).InitBasicManager_Impl(); |
656 | | return _rDocument.Get_Impl()->aBasicManager.get(); |
657 | | } |
658 | | |
659 | | // assume we do not have Basic ourself, but we can refer to another |
660 | | // document which does (by our model's XScriptInvocationContext::getScriptContainer). |
661 | | // In this case, we return the BasicManager of this other document. |
662 | | |
663 | | OSL_ENSURE( !Reference< XEmbeddedScripts >( _rDocument.GetModel(), UNO_QUERY ).is(), |
664 | | "lcl_getBasicManagerForDocument: inconsistency: no Basic, but an XEmbeddedScripts?" ); |
665 | | Reference< XModel > xForeignDocument; |
666 | | Reference< XScriptInvocationContext > xContext( _rDocument.GetModel(), UNO_QUERY ); |
667 | | if ( xContext.is() ) |
668 | | { |
669 | | xForeignDocument.set( xContext->getScriptContainer(), UNO_QUERY ); |
670 | | OSL_ENSURE( xForeignDocument.is() && xForeignDocument != _rDocument.GetModel(), |
671 | | "lcl_getBasicManagerForDocument: no Basic, but providing ourself as script container?" ); |
672 | | } |
673 | | |
674 | | BasicManager* pBasMgr = nullptr; |
675 | | if ( xForeignDocument.is() ) |
676 | | pBasMgr = ::basic::BasicManagerRepository::getDocumentBasicManager( xForeignDocument ); |
677 | | |
678 | | return pBasMgr; |
679 | | } |
680 | | } |
681 | | #endif |
682 | | |
683 | | BasicManager* SfxObjectShell::GetBasicManager() const |
684 | 0 | { |
685 | 0 | BasicManager* pBasMgr = nullptr; |
686 | | #if HAVE_FEATURE_SCRIPTING |
687 | | try |
688 | | { |
689 | | pBasMgr = lcl_getBasicManagerForDocument( *this ); |
690 | | if ( !pBasMgr ) |
691 | | pBasMgr = SfxApplication::GetBasicManager(); |
692 | | } |
693 | | catch (const css::ucb::ContentCreationException&) |
694 | | { |
695 | | TOOLS_WARN_EXCEPTION("sfx.doc", ""); |
696 | | } |
697 | | #endif |
698 | 0 | return pBasMgr; |
699 | 0 | } |
700 | | |
701 | | bool SfxObjectShell::HasBasic() const |
702 | 0 | { |
703 | 0 | #if !HAVE_FEATURE_SCRIPTING |
704 | 0 | return false; |
705 | | #else |
706 | | if ( pImpl->m_bNoBasicCapabilities ) |
707 | | return false; |
708 | | |
709 | | if ( !pImpl->bBasicInitialized ) |
710 | | const_cast< SfxObjectShell* >( this )->InitBasicManager_Impl(); |
711 | | |
712 | | return pImpl->aBasicManager.isValid(); |
713 | | #endif |
714 | 0 | } |
715 | | |
716 | | |
717 | | #if HAVE_FEATURE_SCRIPTING |
718 | | namespace |
719 | | { |
720 | | const Reference< XStorageBasedLibraryContainer >& |
721 | | lcl_getOrCreateLibraryContainer( bool _bScript, Reference< XStorageBasedLibraryContainer >& _rxContainer, |
722 | | const Reference< XModel >& _rxDocument ) |
723 | | { |
724 | | if ( !_rxContainer.is() ) |
725 | | { |
726 | | try |
727 | | { |
728 | | Reference< XStorageBasedDocument > xStorageDoc( _rxDocument, UNO_QUERY ); |
729 | | const Reference< XComponentContext >& xContext( |
730 | | ::comphelper::getProcessComponentContext() ); |
731 | | _rxContainer.set ( _bScript |
732 | | ? DocumentScriptLibraryContainer::create( |
733 | | xContext, xStorageDoc ) |
734 | | : DocumentDialogLibraryContainer::create( |
735 | | xContext, xStorageDoc )); |
736 | | } |
737 | | catch (const Exception&) |
738 | | { |
739 | | DBG_UNHANDLED_EXCEPTION("sfx.doc"); |
740 | | } |
741 | | } |
742 | | return _rxContainer; |
743 | | } |
744 | | } |
745 | | #endif |
746 | | |
747 | | Reference< XStorageBasedLibraryContainer > SfxObjectShell::GetDialogContainer() |
748 | 0 | { |
749 | | #if HAVE_FEATURE_SCRIPTING |
750 | | try |
751 | | { |
752 | | if ( !pImpl->m_bNoBasicCapabilities ) |
753 | | return lcl_getOrCreateLibraryContainer( false, pImpl->xDialogLibraries, GetModel() ); |
754 | | |
755 | | BasicManager* pBasMgr = lcl_getBasicManagerForDocument( *this ); |
756 | | if ( pBasMgr ) |
757 | | return pBasMgr->GetDialogLibraryContainer(); |
758 | | } |
759 | | catch (const css::ucb::ContentCreationException&) |
760 | | { |
761 | | TOOLS_WARN_EXCEPTION("sfx.doc", ""); |
762 | | } |
763 | | |
764 | | SAL_WARN("sfx.doc", "SfxObjectShell::GetDialogContainer: falling back to the application - is this really expected here?"); |
765 | | #endif |
766 | 0 | return SfxGetpApp()->GetDialogContainer(); |
767 | 0 | } |
768 | | |
769 | | Reference< XStorageBasedLibraryContainer > SfxObjectShell::GetBasicContainer() |
770 | 27.2k | { |
771 | | #if HAVE_FEATURE_SCRIPTING |
772 | | if (!comphelper::IsFuzzing()) |
773 | | { |
774 | | try |
775 | | { |
776 | | if ( !pImpl->m_bNoBasicCapabilities ) |
777 | | return lcl_getOrCreateLibraryContainer( true, pImpl->xBasicLibraries, GetModel() ); |
778 | | |
779 | | BasicManager* pBasMgr = lcl_getBasicManagerForDocument( *this ); |
780 | | if ( pBasMgr ) |
781 | | return pBasMgr->GetScriptLibraryContainer(); |
782 | | } |
783 | | catch (const css::ucb::ContentCreationException&) |
784 | | { |
785 | | TOOLS_WARN_EXCEPTION("sfx.doc", ""); |
786 | | } |
787 | | } |
788 | | SAL_WARN("sfx.doc", "SfxObjectShell::GetBasicContainer: falling back to the application - is this really expected here?"); |
789 | | #endif |
790 | 27.2k | return SfxGetpApp()->GetBasicContainer(); |
791 | 27.2k | } |
792 | | |
793 | | StarBASIC* SfxObjectShell::GetBasic() const |
794 | 0 | { |
795 | 0 | #if !HAVE_FEATURE_SCRIPTING |
796 | 0 | return nullptr; |
797 | | #else |
798 | | BasicManager * pMan = GetBasicManager(); |
799 | | return pMan ? pMan->GetLib(0) : nullptr; |
800 | | #endif |
801 | 0 | } |
802 | | |
803 | | void SfxObjectShell::InitBasicManager_Impl() |
804 | | /* [Description] |
805 | | |
806 | | Creates a document's BasicManager and loads it, if we are already based on |
807 | | a storage. |
808 | | |
809 | | [Note] |
810 | | |
811 | | This method has to be called by implementations of <SvPersist::Load()> |
812 | | (with its pStor parameter) and by implementations of <SvPersist::InitNew()> |
813 | | (with pStor = 0). |
814 | | */ |
815 | | |
816 | 0 | { |
817 | | /* #163556# (DR) - Handling of recursive calls while creating the Basic |
818 | | manager. |
819 | | |
820 | | It is possible that (while creating the Basic manager) the code that |
821 | | imports the Basic storage wants to access the Basic manager again. |
822 | | Especially in VBA compatibility mode, there is code that wants to |
823 | | access the "VBA Globals" object which is stored as global UNO constant |
824 | | in the Basic manager. |
825 | | |
826 | | To achieve correct handling of the recursive calls of this function |
827 | | from lcl_getBasicManagerForDocument(), the implementation of the |
828 | | function BasicManagerRepository::getDocumentBasicManager() has been |
829 | | changed to return the Basic manager currently under construction, when |
830 | | called repeatedly. |
831 | | |
832 | | The variable pImpl->bBasicInitialized will be set to sal_True after |
833 | | construction now, to ensure that the recursive call of the function |
834 | | lcl_getBasicManagerForDocument() will be routed into this function too. |
835 | | |
836 | | Calling BasicManagerHolder::reset() twice is not a big problem, as it |
837 | | does not take ownership but stores only the raw pointer. Owner of all |
838 | | Basic managers is the global BasicManagerRepository instance. |
839 | | */ |
840 | | #if HAVE_FEATURE_SCRIPTING |
841 | | DBG_ASSERT( !pImpl->bBasicInitialized && !pImpl->aBasicManager.isValid(), "Local BasicManager already exists"); |
842 | | try |
843 | | { |
844 | | pImpl->aBasicManager.reset( BasicManagerRepository::getDocumentBasicManager( GetModel() ) ); |
845 | | } |
846 | | catch (const css::ucb::ContentCreationException&) |
847 | | { |
848 | | TOOLS_WARN_EXCEPTION("sfx.doc", ""); |
849 | | } |
850 | | DBG_ASSERT( pImpl->aBasicManager.isValid(), "SfxObjectShell::InitBasicManager_Impl: did not get a BasicManager!" ); |
851 | | pImpl->bBasicInitialized = true; |
852 | | #endif |
853 | 0 | } |
854 | | |
855 | | |
856 | | bool SfxObjectShell::DoClose() |
857 | 152k | { |
858 | 152k | return Close(); |
859 | 152k | } |
860 | | |
861 | | |
862 | | SfxObjectShell* SfxObjectShell::GetObjectShell() |
863 | 3.67k | { |
864 | 3.67k | return this; |
865 | 3.67k | } |
866 | | |
867 | | |
868 | | uno::Sequence< OUString > SfxObjectShell::GetEventNames() |
869 | 97 | { |
870 | 97 | static uno::Sequence< OUString > s_EventNameContainer(rtl::Reference<GlobalEventConfig>(new GlobalEventConfig)->getElementNames()); |
871 | | |
872 | 97 | return s_EventNameContainer; |
873 | 97 | } |
874 | | |
875 | | |
876 | | css::uno::Reference< css::frame::XModel3 > SfxObjectShell::GetModel() const |
877 | 1.23M | { |
878 | 1.23M | return GetBaseModel(); |
879 | 1.23M | } |
880 | | |
881 | | void SfxObjectShell::SetBaseModel( SfxBaseModel* pModel ) |
882 | 197k | { |
883 | 197k | OSL_ENSURE( !pImpl->pBaseModel.is() || pModel == nullptr, "Model already set!" ); |
884 | 197k | pImpl->pBaseModel.set( pModel ); |
885 | 197k | if ( pImpl->pBaseModel.is() ) |
886 | 197k | { |
887 | 197k | pImpl->pBaseModel->addCloseListener( new SfxModelListener_Impl(this) ); |
888 | 197k | } |
889 | 197k | } |
890 | | |
891 | | |
892 | | css::uno::Reference< css::frame::XModel3 > SfxObjectShell::GetBaseModel() const |
893 | 1.75M | { |
894 | 1.75M | return pImpl->pBaseModel; |
895 | 1.75M | } |
896 | | |
897 | | void SfxObjectShell::SetAutoStyleFilterIndex(sal_uInt16 nSet) |
898 | 75.3k | { |
899 | 75.3k | pImpl->nStyleFilter = nSet; |
900 | 75.3k | } |
901 | | |
902 | | sal_uInt16 SfxObjectShell::GetAutoStyleFilterIndex() const |
903 | 0 | { |
904 | 0 | return pImpl->nStyleFilter; |
905 | 0 | } |
906 | | |
907 | | |
908 | | void SfxObjectShell::SetCurrentComponent( const Reference< XInterface >& _rxComponent ) |
909 | 7.35k | { |
910 | 7.35k | WeakReference< XInterface >& rTheCurrentComponent = theCurrentComponent; |
911 | | |
912 | 7.35k | Reference< XInterface > xOldCurrentComp(rTheCurrentComponent); |
913 | 7.35k | if ( _rxComponent == xOldCurrentComp ) |
914 | | // nothing to do |
915 | 0 | return; |
916 | | // note that "_rxComponent.get() == s_xCurrentComponent.get().get()" is /sufficient/, but not |
917 | | // /required/ for "_rxComponent == s_xCurrentComponent.get()". |
918 | | // In other words, it's still possible that we here do something which is not necessary, |
919 | | // but we should have filtered quite some unnecessary calls already. |
920 | | |
921 | | #if HAVE_FEATURE_SCRIPTING |
922 | | BasicManager* pAppMgr = SfxApplication::GetBasicManager(); |
923 | | rTheCurrentComponent = _rxComponent; |
924 | | if ( !pAppMgr ) |
925 | | return; |
926 | | |
927 | | // set "ThisComponent" for Basic |
928 | | pAppMgr->SetGlobalUNOConstant( u"ThisComponent"_ustr, Any( _rxComponent ) ); |
929 | | |
930 | | // set new current component for VBA compatibility |
931 | | if ( _rxComponent.is() ) |
932 | | { |
933 | | OUString aVBAConstName = lclGetVBAGlobalConstName( _rxComponent ); |
934 | | if ( !aVBAConstName.isEmpty() ) |
935 | | { |
936 | | pAppMgr->SetGlobalUNOConstant( aVBAConstName, Any( _rxComponent ) ); |
937 | | s_aRegisteredVBAConstants[ _rxComponent.get() ] = aVBAConstName; |
938 | | } |
939 | | } |
940 | | // no new component passed -> remove last registered VBA component |
941 | | else if ( xOldCurrentComp.is() ) |
942 | | { |
943 | | OUString aVBAConstName = lclGetVBAGlobalConstName( xOldCurrentComp ); |
944 | | if ( !aVBAConstName.isEmpty() ) |
945 | | { |
946 | | pAppMgr->SetGlobalUNOConstant( aVBAConstName, Any( Reference< XInterface >() ) ); |
947 | | s_aRegisteredVBAConstants.erase( xOldCurrentComp.get() ); |
948 | | } |
949 | | } |
950 | | #endif |
951 | 7.35k | } |
952 | | |
953 | | Reference< XInterface > SfxObjectShell::GetCurrentComponent() |
954 | 197k | { |
955 | 197k | return theCurrentComponent; |
956 | 197k | } |
957 | | |
958 | | |
959 | | OUString SfxObjectShell::GetServiceNameFromFactory( const OUString& rFact ) |
960 | 0 | { |
961 | | //! Remove everything behind name! |
962 | 0 | OUString aFact( rFact ); |
963 | 0 | OUString aPrefix(u"private:factory/"_ustr); |
964 | 0 | if ( aFact.startsWith( aPrefix ) ) |
965 | 0 | aFact = aFact.copy( aPrefix.getLength() ); |
966 | 0 | sal_Int32 nPos = aFact.indexOf( '?' ); |
967 | 0 | if ( nPos != -1 ) |
968 | 0 | { |
969 | 0 | aFact = aFact.copy( 0, nPos ); |
970 | 0 | } |
971 | 0 | aFact = aFact.replaceAll("4", ""); |
972 | 0 | aFact = aFact.toAsciiLowerCase(); |
973 | | |
974 | | // HACK: sometimes a real document service name is given here instead of |
975 | | // a factory short name. Set return value directly to this service name as fallback |
976 | | // in case next lines of code does nothing ... |
977 | | // use rFact instead of normed aFact value ! |
978 | 0 | OUString aServiceName = rFact; |
979 | |
|
980 | 0 | if ( aFact == "swriter" ) |
981 | 0 | { |
982 | 0 | aServiceName = "com.sun.star.text.TextDocument"; |
983 | 0 | } |
984 | 0 | else if ( aFact == "sweb" || aFact == "swriter/web" ) |
985 | 0 | { |
986 | 0 | aServiceName = "com.sun.star.text.WebDocument"; |
987 | 0 | } |
988 | 0 | else if ( aFact == "sglobal" || aFact == "swriter/globaldocument" ) |
989 | 0 | { |
990 | 0 | aServiceName = "com.sun.star.text.GlobalDocument"; |
991 | 0 | } |
992 | 0 | else if ( aFact == "scalc" ) |
993 | 0 | { |
994 | 0 | aServiceName = "com.sun.star.sheet.SpreadsheetDocument"; |
995 | 0 | } |
996 | 0 | else if ( aFact == "sdraw" ) |
997 | 0 | { |
998 | 0 | aServiceName = "com.sun.star.drawing.DrawingDocument"; |
999 | 0 | } |
1000 | 0 | else if ( aFact == "simpress" ) |
1001 | 0 | { |
1002 | 0 | aServiceName = "com.sun.star.presentation.PresentationDocument"; |
1003 | 0 | } |
1004 | 0 | else if ( aFact == "schart" ) |
1005 | 0 | { |
1006 | 0 | aServiceName = "com.sun.star.chart.ChartDocument"; |
1007 | 0 | } |
1008 | 0 | else if ( aFact == "smath" ) |
1009 | 0 | { |
1010 | 0 | aServiceName = "com.sun.star.formula.FormulaProperties"; |
1011 | 0 | } |
1012 | | #if HAVE_FEATURE_SCRIPTING |
1013 | | else if ( aFact == "sbasic" ) |
1014 | | { |
1015 | | aServiceName = "com.sun.star.script.BasicIDE"; |
1016 | | } |
1017 | | #endif |
1018 | | #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS |
1019 | | else if ( aFact == "sdatabase" ) |
1020 | | { |
1021 | | aServiceName = "com.sun.star.sdb.OfficeDatabaseDocument"; |
1022 | | } |
1023 | | #endif |
1024 | |
|
1025 | 0 | return aServiceName; |
1026 | 0 | } |
1027 | | |
1028 | | SfxObjectShell* SfxObjectShell::CreateObjectByFactoryName( const OUString& rFact, SfxObjectCreateMode eMode ) |
1029 | 0 | { |
1030 | 0 | return CreateObject( GetServiceNameFromFactory( rFact ), eMode ); |
1031 | 0 | } |
1032 | | |
1033 | | |
1034 | | SfxObjectShell* SfxObjectShell::CreateObject( const OUString& rServiceName, SfxObjectCreateMode eCreateMode ) |
1035 | 0 | { |
1036 | 0 | if ( !rServiceName.isEmpty() ) |
1037 | 0 | { |
1038 | 0 | uno::Reference < frame::XModel > xDoc( ::comphelper::getProcessServiceFactory()->createInstance( rServiceName ), UNO_QUERY ); |
1039 | 0 | if (SfxObjectShell* pRet = SfxObjectShell::GetShellFromComponent(xDoc)) |
1040 | 0 | { |
1041 | 0 | pRet->SetCreateMode_Impl(eCreateMode); |
1042 | 0 | return pRet; |
1043 | 0 | } |
1044 | 0 | } |
1045 | | |
1046 | 0 | return nullptr; |
1047 | 0 | } |
1048 | | |
1049 | | Reference<lang::XComponent> SfxObjectShell::CreateAndLoadComponent( const SfxItemSet& rSet ) |
1050 | 0 | { |
1051 | 0 | uno::Sequence < beans::PropertyValue > aProps; |
1052 | 0 | TransformItems( SID_OPENDOC, rSet, aProps ); |
1053 | 0 | const SfxStringItem* pFileNameItem = rSet.GetItem<SfxStringItem>(SID_FILE_NAME, false); |
1054 | 0 | const SfxStringItem* pTargetItem = rSet.GetItem<SfxStringItem>(SID_TARGETNAME, false); |
1055 | 0 | OUString aURL; |
1056 | 0 | OUString aTarget(u"_blank"_ustr); |
1057 | 0 | if ( pFileNameItem ) |
1058 | 0 | aURL = pFileNameItem->GetValue(); |
1059 | 0 | if ( pTargetItem ) |
1060 | 0 | aTarget = pTargetItem->GetValue(); |
1061 | |
|
1062 | 0 | uno::Reference < frame::XComponentLoader > xLoader = |
1063 | 0 | frame::Desktop::create(comphelper::getProcessComponentContext()); |
1064 | |
|
1065 | 0 | Reference <lang::XComponent> xComp; |
1066 | 0 | try |
1067 | 0 | { |
1068 | 0 | xComp = xLoader->loadComponentFromURL(aURL, aTarget, 0, aProps); |
1069 | 0 | } |
1070 | 0 | catch (const uno::Exception&) |
1071 | 0 | { |
1072 | 0 | } |
1073 | |
|
1074 | 0 | return xComp; |
1075 | 0 | } |
1076 | | |
1077 | | SfxObjectShell* SfxObjectShell::GetShellFromComponent(const Reference<uno::XInterface>& xComp) |
1078 | 11.7k | { |
1079 | 11.7k | try |
1080 | 11.7k | { |
1081 | 11.7k | Reference<lang::XUnoTunnel> xTunnel(xComp, UNO_QUERY); |
1082 | 11.7k | if (!xTunnel) |
1083 | 10.4k | return nullptr; |
1084 | 1.22k | static const Sequence <sal_Int8> aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() ); |
1085 | 1.22k | return comphelper::getSomething_cast<SfxObjectShell>(xTunnel->getSomething(aSeq)); |
1086 | 11.7k | } |
1087 | 11.7k | catch (const Exception&) |
1088 | 11.7k | { |
1089 | 0 | } |
1090 | | |
1091 | 0 | return nullptr; |
1092 | 11.7k | } |
1093 | | |
1094 | | SfxObjectShell* SfxObjectShell::GetParentShell(const css::uno::Reference<css::uno::XInterface>& xChild) |
1095 | 10.4k | { |
1096 | 10.4k | SfxObjectShell* pResult = nullptr; |
1097 | | |
1098 | 10.4k | try |
1099 | 10.4k | { |
1100 | 10.4k | if (css::uno::Reference<css::container::XChild> xChildModel{ xChild, css::uno::UNO_QUERY }) |
1101 | 10.4k | pResult = GetShellFromComponent(xChildModel->getParent()); |
1102 | 10.4k | } |
1103 | 10.4k | catch (const Exception&) |
1104 | 10.4k | { |
1105 | 0 | } |
1106 | | |
1107 | 10.4k | return pResult; |
1108 | 10.4k | } |
1109 | | |
1110 | | void SfxObjectShell::SetInitialized_Impl( const bool i_fromInitNew ) |
1111 | 182k | { |
1112 | 182k | pImpl->bInitialized = true; |
1113 | 182k | if (comphelper::IsFuzzing()) |
1114 | 182k | return; |
1115 | 0 | if ( i_fromInitNew ) |
1116 | 0 | { |
1117 | 0 | SetActivateEvent_Impl( SfxEventHintId::CreateDoc ); |
1118 | 0 | SfxGetpApp()->NotifyEvent( SfxEventHint( SfxEventHintId::DocCreated, GlobalEventConfig::GetEventName(GlobalEventId::DOCCREATED), this ) ); |
1119 | 0 | } |
1120 | 0 | else |
1121 | 0 | { |
1122 | 0 | SfxGetpApp()->NotifyEvent( SfxEventHint( SfxEventHintId::LoadFinished, GlobalEventConfig::GetEventName(GlobalEventId::LOADFINISHED), this ) ); |
1123 | 0 | } |
1124 | 0 | } |
1125 | | |
1126 | | |
1127 | | bool SfxObjectShell::IsChangeRecording(SfxViewShell* /*pViewShell*/, bool /*bRecordAllViews*/) const |
1128 | 0 | { |
1129 | | // currently this function needs to be overwritten by Writer and Calc only |
1130 | 0 | SAL_WARN( "sfx.doc", "function not implemented" ); |
1131 | 0 | return false; |
1132 | 0 | } |
1133 | | |
1134 | | |
1135 | | bool SfxObjectShell::HasChangeRecordProtection() const |
1136 | 0 | { |
1137 | | // currently this function needs to be overwritten by Writer and Calc only |
1138 | 0 | SAL_WARN( "sfx.doc", "function not implemented" ); |
1139 | 0 | return false; |
1140 | 0 | } |
1141 | | |
1142 | | |
1143 | | void SfxObjectShell::SetChangeRecording( bool /*bActivate*/, bool /*bLockAllViews*/, SfxRedlineRecordingMode /*eRedlineRecordingMode*/) |
1144 | 0 | { |
1145 | | // currently this function needs to be overwritten by Writer and Calc only |
1146 | 0 | SAL_WARN( "sfx.doc", "function not implemented" ); |
1147 | 0 | } |
1148 | | |
1149 | | |
1150 | | void SfxObjectShell::SetProtectionPassword( const OUString & /*rPassword*/ ) |
1151 | 0 | { |
1152 | | // currently this function needs to be overwritten by Writer and Calc only |
1153 | 0 | SAL_WARN( "sfx.doc", "function not implemented" ); |
1154 | 0 | } |
1155 | | |
1156 | | |
1157 | | bool SfxObjectShell::GetProtectionHash( /*out*/ css::uno::Sequence< sal_Int8 > & /*rPasswordHash*/ ) |
1158 | 0 | { |
1159 | | // currently this function needs to be overwritten by Writer and Calc only |
1160 | 0 | SAL_WARN( "sfx.doc", "function not implemented" ); |
1161 | 0 | return false; |
1162 | 0 | } |
1163 | | |
1164 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |