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