1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: objxtor.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include "arrdecl.hxx"
36 #include <cppuhelper/implbase1.hxx>
38 #include <com/sun/star/util/XCloseable.hpp>
39 #include <com/sun/star/frame/XComponentLoader.hpp>
40 #include <com/sun/star/util/XCloseBroadcaster.hpp>
41 #include <com/sun/star/util/XCloseListener.hpp>
42 #include <com/sun/star/util/XModifyBroadcaster.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <com/sun/star/frame/XTitle.hpp>
45 #include <vos/mutex.hxx>
47 #ifndef _SV_RESARY_HXX
48 #include <tools/resary.hxx>
50 #ifndef _MSGBOX_HXX //autogen
51 #include <vcl/msgbox.hxx>
53 #ifndef _WRKWIN_HXX //autogen
54 #include <vcl/wrkwin.hxx>
56 #include <vcl/svapp.hxx>
57 #include <svtools/eitem.hxx>
58 #include <tools/rtti.hxx>
59 #include <svtools/lstner.hxx>
60 #include <sfxhelp.hxx>
61 #include <basic/sbstar.hxx>
62 #include <svtools/stritem.hxx>
63 #include <basic/sbx.hxx>
65 #include <sfx2/objsh.hxx>
66 #include <sfx2/signaturestate.hxx>
68 #ifndef _BASIC_SBUNO_HXX
69 #include <basic/sbuno.hxx>
71 #include <svtools/sfxecode.hxx>
72 #include <svtools/ehdl.hxx>
73 #include <svtools/printwarningoptions.hxx>
74 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
75 #include <comphelper/processfactory.hxx>
78 #include <com/sun/star/document/XStorageBasedDocument.hpp>
79 #include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
80 #include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
81 #include <com/sun/star/document/XEmbeddedScripts.hpp>
82 #include <com/sun/star/document/XScriptInvocationContext.hpp>
84 #include <svtools/urihelper.hxx>
85 #include <svtools/pathoptions.hxx>
86 #include <svtools/sharecontrolfile.hxx>
87 #include <unotools/localfilehelper.hxx>
88 #include <unotools/ucbhelper.hxx>
89 #include <svtools/asynclink.hxx>
90 #include <tools/diagnose_ex.h>
91 #include <sot/clsids.hxx>
93 #include <sfx2/app.hxx>
94 #include <sfx2/docfac.hxx>
95 #include <sfx2/docfile.hxx>
96 #include <sfx2/event.hxx>
97 #include <sfx2/dispatch.hxx>
98 #include <sfx2/viewsh.hxx>
99 #include <sfx2/viewfrm.hxx>
100 #include "sfxresid.hxx"
101 #include "objshimp.hxx"
102 #include "appbas.hxx"
103 #include "sfxtypes.hxx"
104 #include <sfx2/evntconf.hxx>
105 #include <sfx2/request.hxx>
107 #include "sfxlocal.hrc"
108 #include "appdata.hxx"
109 #include <sfx2/appuno.hxx>
110 #include <sfx2/sfxsids.hrc>
111 #include "basmgr.hxx"
112 #include "QuerySaveDocument.hxx"
113 #include "helpid.hrc"
114 #include <sfx2/msg.hxx>
115 #include "appbaslib.hxx"
116 #include <sfx2/sfxbasemodel.hxx>
118 #include <basic/basicmanagerrepository.hxx>
120 using namespace ::com::sun::star
;
121 using namespace ::com::sun::star::uno
;
122 using namespace ::com::sun::star::script
;
123 using namespace ::com::sun::star::frame
;
124 using namespace ::com::sun::star::document
;
126 using ::basic::BasicManagerRepository
;
127 #include <uno/mapping.hxx>
129 //====================================================================
131 DBG_NAME(SfxObjectShell
)
134 #include "sfxslots.hxx"
136 extern svtools::AsynchronLink
* pPendingCloser
;
137 static WeakReference
< XInterface
> s_xCurrentComponent
;
139 void lcl_UpdateAppBasicDocVars( const Reference
< XInterface
>& _rxComponent
, bool bClear
= false )
141 BasicManager
* pAppMgr
= SFX_APP()->GetBasicManager();
144 uno::Reference
< beans::XPropertySet
> xProps( _rxComponent
, uno::UNO_QUERY
);
149 beans::PropertyValue aProp
;
150 xProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ThisVBADocObj") ) ) >>= aProp
;
151 rtl::OString
sTmp( rtl::OUStringToOString( aProp
.Name
, RTL_TEXTENCODING_UTF8
) );
152 const char* pAscii
= sTmp
.getStr();
154 pAppMgr
->SetGlobalUNOConstant( pAscii
, uno::makeAny( uno::Reference
< uno::XInterface
>() ) );
156 pAppMgr
->SetGlobalUNOConstant( pAscii
, aProp
.Value
);
159 catch( uno::Exception
& e
)
166 //=========================================================================
169 //=========================================================================
171 class SfxModelListener_Impl
: public ::cppu::WeakImplHelper1
< ::com::sun::star::util::XCloseListener
>
173 SfxObjectShell
* mpDoc
;
175 SfxModelListener_Impl( SfxObjectShell
* pDoc
) : mpDoc(pDoc
) {};
176 virtual void SAL_CALL
queryClosing( const com::sun::star::lang::EventObject
& aEvent
, sal_Bool bDeliverOwnership
)
177 throw ( com::sun::star::uno::RuntimeException
, com::sun::star::util::CloseVetoException
) ;
178 virtual void SAL_CALL
notifyClosing( const com::sun::star::lang::EventObject
& aEvent
) throw ( com::sun::star::uno::RuntimeException
) ;
179 virtual void SAL_CALL
disposing( const com::sun::star::lang::EventObject
& aEvent
) throw ( com::sun::star::uno::RuntimeException
) ;
183 void SAL_CALL
SfxModelListener_Impl::queryClosing( const com::sun::star::lang::EventObject
& , sal_Bool
)
184 throw ( com::sun::star::uno::RuntimeException
, com::sun::star::util::CloseVetoException
)
188 void SAL_CALL
SfxModelListener_Impl::notifyClosing( const com::sun::star::lang::EventObject
& ) throw ( com::sun::star::uno::RuntimeException
)
190 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
191 mpDoc
->Broadcast( SfxSimpleHint(SFX_HINT_DEINITIALIZING
) );
194 void SAL_CALL
SfxModelListener_Impl::disposing( const com::sun::star::lang::EventObject
& _rEvent
) throw ( com::sun::star::uno::RuntimeException
)
196 // am I ThisComponent in AppBasic?
197 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
198 if ( SfxObjectShell::GetCurrentComponent() == _rEvent
.Source
)
200 lcl_UpdateAppBasicDocVars( SfxObjectShell::GetCurrentComponent(), true );
201 // remove ThisComponent reference from AppBasic
202 SfxObjectShell::SetCurrentComponent( Reference
< XInterface
>() );
205 if ( mpDoc
->Get_Impl()->bHiddenLockedByAPI
)
207 mpDoc
->Get_Impl()->bHiddenLockedByAPI
= FALSE
;
208 mpDoc
->OwnerLock(FALSE
);
210 else if ( !mpDoc
->Get_Impl()->bClosing
)
211 // GCC stuerzt ab, wenn schon im dtor, also vorher Flag abfragen
215 TYPEINIT1(SfxObjectShell
, SfxShell
);
217 //--------------------------------------------------------------------
218 SfxObjectShell_Impl::SfxObjectShell_Impl( SfxObjectShell
& _rDocShell
)
219 :mpObjectContainer(0)
222 ,pBasicManager( new SfxBasicManagerHolder
)
223 ,rDocShell( _rDocShell
)
227 ,nVisualDocumentNumber( USHRT_MAX
)
228 ,nDocumentSignatureState( SIGNATURESTATE_UNKNOWN
)
229 ,nScriptingSignatureState( SIGNATURESTATE_UNKNOWN
)
230 ,bTemplateConfig( sal_False
)
232 ,bClosing( sal_False
)
233 ,bSetInPlaceObj( sal_False
)
234 ,bIsSaving( sal_False
)
237 ,bIsNamedVisible( sal_False
)
238 ,bIsTemplate(sal_False
)
239 ,bIsAbortingImport ( sal_False
)
240 ,bImportDone ( sal_False
)
241 ,bInPrepareClose( sal_False
)
242 ,bPreparedForClose( sal_False
)
243 ,bWaitingForPicklist( sal_False
)
244 ,bModuleSearched( sal_False
)
245 ,bIsHelpObjSh( sal_False
)
246 ,bForbidCaching( sal_False
)
247 ,bForbidReload( sal_False
)
248 ,bSupportsEventMacros( sal_True
)
249 ,bLoadingWindows( sal_False
)
250 ,bBasicInitialized( sal_False
)
251 // ,bHidden( sal_False )
252 ,bIsPrintJobCancelable( sal_True
)
253 ,bOwnsStorage( sal_True
)
254 ,bNoBaseURL( sal_False
)
255 ,bInitialized( sal_False
)
256 ,bSignatureErrorIsShown( sal_False
)
257 ,bModelInitialized( sal_False
)
258 ,bPreserveVersions( sal_True
)
259 ,m_bMacroSignBroken( sal_False
)
260 ,m_bNoBasicCapabilities( sal_False
)
261 ,bQueryLoadTemplate( sal_True
)
262 ,bLoadReadonly( sal_False
)
263 ,bUseUserData( sal_True
)
264 ,bSaveVersionOnClose( sal_False
)
265 ,m_bSharedXMLFlag( sal_False
)
266 ,m_bAllowShareControlFileClean( sal_True
)
269 ,bDoNotTouchDocInfo( sal_False
)
272 ,nLoadedFlags ( SFX_LOADED_MAINDOCUMENT
)
273 ,nFlagsInProgress( 0 )
274 ,bInFrame( sal_False
)
275 ,bModalMode( sal_False
)
276 ,bRunningMacro( sal_False
)
277 ,bReloadAvailable( sal_False
)
283 ,eFlags( SFXOBJECTSHELL_UNDEFINED
)
285 ,bReadOnlyUI( sal_False
)
286 ,bHiddenLockedByAPI( sal_False
)
287 ,bInCloseEvent( sal_False
)
289 ,bDisposing( sal_False
)
290 ,m_bEnableSetModified( sal_True
)
291 ,m_bIsModified( sal_False
)
292 ,m_nMapUnit( MAP_100TH_MM
)
293 ,m_bCreateTempStor( sal_False
)
294 ,m_xDocInfoListener()
295 ,m_bIsInit( sal_False
)
299 //--------------------------------------------------------------------
301 SfxObjectShell_Impl::~SfxObjectShell_Impl()
303 if ( pPendingCloser
== pCloser
)
306 delete pBasicManager
;
309 // initializes a document from a file-description
311 SfxObjectShell::SfxObjectShell
313 SfxObjectCreateMode eMode
/* Zweck, zu dem die SfxObjectShell
316 SFX_CREATE_MODE_EMBEDDED (default)
317 als SO-Server aus einem anderen
320 SFX_CREATE_MODE_STANDARD,
321 als normales, selbst"aendig ge"offnetes
324 SFX_CREATE_MODE_PREVIEW
325 um ein Preview durchzuf"uhren,
326 ggf. werden weniger Daten ben"otigt
328 SFX_CREATE_MODE_ORGANIZER
329 um im Organizer dargestellt zu
330 werden, hier werden keine Inhalte
336 Konstruktor der Klasse SfxObjectShell.
339 : pImp( new SfxObjectShell_Impl( *this ) ),
344 DBG_CTOR(SfxObjectShell
, 0);
346 bHasName
= sal_False
;
349 pImp
->bWaitingForPicklist
= sal_True
;
351 // Aggregation InPlaceObject+Automation
352 //(mba) AddInterface( SvDispatch::ClassFactory() );
354 SfxObjectShell
*pThis
= this;
355 SfxObjectShellArr_Impl
&rArr
= SFX_APP()->GetObjectShells_Impl();
356 rArr
.C40_INSERT( SfxObjectShell
, pThis
, rArr
.Count() );
357 pImp
->bInList
= sal_True
;
358 pImp
->nLoadedFlags
= SFX_LOADED_ALL
;
359 //REMOVE SetObjectShell( TRUE );
362 //--------------------------------------------------------------------
364 // virtual dtor of typical base-class SfxObjectShell
366 SfxObjectShell::~SfxObjectShell()
368 DBG_DTOR(SfxObjectShell
, 0);
370 if ( IsEnableSetModified() )
371 EnableSetModified( sal_False
);
373 // Niemals GetInPlaceObject() aufrufen, der Zugriff auf den
374 // Ableitungszweig SfxInternObject ist wegen eines Compiler Bugs nicht
376 SfxObjectShell::Close();
379 // DELETEX(pImp->pEventConfig);
380 // DELETEX(pImp->pTbxConfig);
381 // DELETEX(pImp->pAccMgr);
382 // DELETEX(pImp->pCfgMgr);
383 DELETEX(pImp
->pReloadTimer
);
385 SfxApplication
*pSfxApp
= SFX_APP();
386 if ( USHRT_MAX
!= pImp
->nVisualDocumentNumber
)
387 pSfxApp
->ReleaseIndex(pImp
->nVisualDocumentNumber
);
389 // Basic-Manager zerst"oren
390 pImp
->pBasicManager
->reset( NULL
);
392 if ( pSfxApp
->GetDdeService() )
393 pSfxApp
->RemoveDdeTopic( this );
395 if ( pImp
->xModel
.is() )
396 pImp
->xModel
= ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> ();
398 // don't call GetStorage() here, in case of Load Failure it's possible that a storage was never assigned!
399 if ( pMedium
&& pMedium
->HasStorage_Impl() && pMedium
->GetStorage() == pImp
->m_xDocStorage
)
400 pMedium
->CanDisposeStorage_Impl( sal_False
);
402 if ( pImp
->mpObjectContainer
)
404 pImp
->mpObjectContainer
->CloseEmbeddedObjects();
405 delete pImp
->mpObjectContainer
;
408 if ( pImp
->bOwnsStorage
&& pImp
->m_xDocStorage
.is() )
412 pImp
->m_xDocStorage
->dispose();
422 pMedium
->CloseAndReleaseStreams_Impl();
430 // The removing of the temporary file must be done as the latest step in the document destruction
431 if ( pImp
->aTempName
.Len() )
434 ::utl::LocalFileHelper::ConvertPhysicalNameToURL( pImp
->aTempName
, aTmp
);
435 ::utl::UCBContentHelper::Kill( aTmp
);
441 //--------------------------------------------------------------------
443 void SfxObjectShell::Stamp_SetPrintCancelState(sal_Bool bState
)
445 pImp
->bIsPrintJobCancelable
= bState
;
448 //--------------------------------------------------------------------
450 sal_Bool
SfxObjectShell::Stamp_GetPrintCancelState() const
452 return pImp
->bIsPrintJobCancelable
;
455 //--------------------------------------------------------------------
457 void SfxObjectShell::ViewAssigned()
461 Diese Methode wird gerufen, wenn eine View zugewiesen wird.
467 //--------------------------------------------------------------------
468 // closes the Object and all its views
470 sal_Bool
SfxObjectShell::Close()
472 {DBG_CHKTHIS(SfxObjectShell
, 0);}
473 SfxObjectShellRef
aRef(this);
474 if ( !pImp
->bClosing
)
476 // falls noch ein Progress l"auft, nicht schlie\sen
477 if ( !pImp
->bDisposing
&& GetProgress() )
480 pImp
->bClosing
= sal_True
;
481 Reference
< util::XCloseable
> xCloseable( GetBaseModel(), UNO_QUERY
);
483 if ( xCloseable
.is() )
487 xCloseable
->close( sal_True
);
491 pImp
->bClosing
= sal_False
;
495 if ( pImp
->bClosing
)
497 // aus Document-Liste austragen
498 SfxApplication
*pSfxApp
= SFX_APP();
499 SfxObjectShellArr_Impl
&rDocs
= pSfxApp
->GetObjectShells_Impl();
500 const SfxObjectShell
*pThis
= this;
501 sal_uInt16 nPos
= rDocs
.GetPos(pThis
);
502 if ( nPos
< rDocs
.Count() )
503 rDocs
.Remove( nPos
);
504 pImp
->bInList
= sal_False
;
511 //--------------------------------------------------------------------
513 // returns a pointer the first SfxDocument of specified type
515 SfxObjectShell
* SfxObjectShell::GetFirst
517 const TypeId
* pType
,
518 sal_Bool bOnlyVisible
521 SfxObjectShellArr_Impl
&rDocs
= SFX_APP()->GetObjectShells_Impl();
523 // seach for a SfxDocument of the specified type
524 for ( sal_uInt16 nPos
= 0; nPos
< rDocs
.Count(); ++nPos
)
526 SfxObjectShell
* pSh
= rDocs
.GetObject( nPos
);
527 if ( bOnlyVisible
&& pSh
->IsPreview() && pSh
->IsReadOnly() )
530 if ( ( !pType
|| pSh
->IsA(*pType
) ) &&
531 ( !bOnlyVisible
|| SfxViewFrame::GetFirst( pSh
, 0, sal_True
)))
537 //--------------------------------------------------------------------
539 // returns a pointer to the next SfxDocument of specified type behind *pDoc
541 SfxObjectShell
* SfxObjectShell::GetNext
543 const SfxObjectShell
& rPrev
,
545 sal_Bool bOnlyVisible
548 SfxObjectShellArr_Impl
&rDocs
= SFX_APP()->GetObjectShells_Impl();
550 // refind the specified predecessor
552 for ( nPos
= 0; nPos
< rDocs
.Count(); ++nPos
)
553 if ( rDocs
.GetObject(nPos
) == &rPrev
)
556 // search for the next SfxDocument of the specified type
557 for ( ++nPos
; nPos
< rDocs
.Count(); ++nPos
)
559 SfxObjectShell
* pSh
= rDocs
.GetObject( nPos
);
560 if ( bOnlyVisible
&& pSh
->IsPreview() && pSh
->IsReadOnly() )
563 if ( ( !pType
|| pSh
->IsA(*pType
) ) &&
564 ( !bOnlyVisible
|| SfxViewFrame::GetFirst( pSh
, 0, sal_True
)))
570 //--------------------------------------------------------------------
572 SfxObjectShell
* SfxObjectShell::Current()
574 SfxViewFrame
*pFrame
= SfxViewFrame::Current();
575 return pFrame
? pFrame
->GetObjectShell() : 0;
578 //-------------------------------------------------------------------------
580 sal_Bool
SfxObjectShell::IsInPrepareClose() const
582 return pImp
->bInPrepareClose
;
585 //------------------------------------------------------------------------
589 SfxObjectShell_Impl
* pImp
;
590 BoolEnv_Impl( SfxObjectShell_Impl
* pImpP
) : pImp( pImpP
)
591 { pImpP
->bInPrepareClose
= sal_True
; }
592 ~BoolEnv_Impl() { pImp
->bInPrepareClose
= sal_False
; }
596 sal_uInt16
SfxObjectShell::PrepareClose
598 sal_Bool bUI
, // sal_True: Dialoge etc. erlaubt, sal_False: silent-mode
599 sal_Bool bForBrowsing
602 if( pImp
->bInPrepareClose
|| pImp
->bPreparedForClose
)
604 BoolEnv_Impl
aBoolEnv( pImp
);
607 if ( IsInModalMode() )
610 SfxViewFrame
* pFirst
= SfxViewFrame::GetFirst( this );
611 if( pFirst
&& !pFirst
->GetFrame()->PrepareClose_Impl( bUI
, bForBrowsing
) )
614 // prepare views for closing
615 for ( SfxViewFrame
* pFrm
= SfxViewFrame::GetFirst(
616 this, TYPE(SfxViewFrame
));
617 pFrm
; pFrm
= SfxViewFrame::GetNext( *pFrm
, this ) )
619 DBG_ASSERT(pFrm
->GetViewShell(),"KeineShell");
620 if ( pFrm
->GetViewShell() )
622 sal_uInt16 nRet
= pFrm
->GetViewShell()->PrepareClose( bUI
, bForBrowsing
);
623 if ( nRet
!= sal_True
)
628 SFX_APP()->NotifyEvent( SfxEventHint(SFX_EVENT_PREPARECLOSEDOC
, this) );
630 if( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED
)
632 pImp
->bPreparedForClose
= sal_True
;
636 // ggf. nachfragen, ob gespeichert werden soll
637 // nur fuer in sichtbaren Fenstern dargestellte Dokumente fragen
638 SfxViewFrame
*pFrame
= SfxObjectShell::Current() == this
639 ? SfxViewFrame::Current() : SfxViewFrame::GetFirst( this );
640 while ( pFrame
&& (pFrame
->GetFrameType() & SFXFRAME_SERVER
) )
641 pFrame
= SfxViewFrame::GetNext( *pFrame
, this );
643 sal_Bool bClose
= sal_False
;
644 if ( bUI
&& IsModified() )
648 // minimierte restoren
649 SfxFrame
* pTop
= pFrame
->GetTopFrame();
650 SfxViewFrame::SetViewFrame( pTop
->GetCurrentViewFrame() );
651 pFrame
->GetFrame()->Appear();
653 // fragen, ob gespeichert werden soll
654 short nRet
= RET_YES
;
656 //brauchen wir UI=2 noch?
657 //if( SfxApplication::IsPlugin() == sal_False || bUI == 2 )
659 //initiate help agent to inform about "print modifies the document"
660 SvtPrintWarningOptions aPrintOptions
;
661 if (aPrintOptions
.IsModifyDocumentOnPrintingAllowed() &&
662 HasName() && getDocProperties()->getPrintDate().Month
> 0)
664 SfxHelp::OpenHelpAgent(pFirst
->GetFrame(), HID_CLOSE_WARNING
);
666 const Reference
< XTitle
> xTitle(pImp
->xModel
, UNO_QUERY_THROW
);
667 const ::rtl::OUString sTitle
= xTitle
->getTitle ();
668 nRet
= ExecuteQuerySaveDocument(&pFrame
->GetWindow(),sTitle
);
670 /*HACK for plugin::destroy()*/
672 if ( RET_YES
== nRet
)
674 // per Dispatcher speichern
675 const SfxPoolItem
*pPoolItem
;
676 if ( IsSaveVersionOnClose() )
678 SfxStringItem
aItem( SID_DOCINFO_COMMENTS
, String( SfxResId( STR_AUTOMATICVERSION
) ) );
679 SfxBoolItem
aWarnItem( SID_FAIL_ON_WARNING
, bUI
);
680 const SfxPoolItem
* ppArgs
[] = { &aItem
, &aWarnItem
, 0 };
681 pPoolItem
= pFrame
->GetBindings().ExecuteSynchron( SID_SAVEDOC
, ppArgs
);
685 SfxBoolItem
aWarnItem( SID_FAIL_ON_WARNING
, bUI
);
686 const SfxPoolItem
* ppArgs
[] = { &aWarnItem
, 0 };
687 pPoolItem
= pFrame
->GetBindings().ExecuteSynchron( SID_SAVEDOC
, ppArgs
);
690 if ( !pPoolItem
|| pPoolItem
->ISA(SfxVoidItem
) || ( pPoolItem
->ISA(SfxBoolItem
) && !( (const SfxBoolItem
*) pPoolItem
)->GetValue() ) )
695 else if ( RET_CANCEL
== nRet
)
698 else if ( RET_NEWTASK
== nRet
)
704 // Bei Nein nicht noch Informationlost
710 // ggf. hinweisen, da\s unter Fremdformat gespeichert
713 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pIgnoreInformationLost
,
714 SfxBoolItem
, SID_DOC_IGNOREINFORMATIONLOST
, sal_False
);
715 if( pIgnoreInformationLost
&& pIgnoreInformationLost
->GetValue() )
719 pImp
->bPreparedForClose
= sal_True
;
723 //--------------------------------------------------------------------
726 static BasicManager
* lcl_getBasicManagerForDocument( const SfxObjectShell
& _rDocument
)
728 if ( !_rDocument
.Get_Impl()->m_bNoBasicCapabilities
)
730 if ( !_rDocument
.Get_Impl()->bBasicInitialized
)
731 const_cast< SfxObjectShell
& >( _rDocument
).InitBasicManager_Impl();
732 return _rDocument
.Get_Impl()->pBasicManager
->get();
735 // assume we do not have Basic ourself, but we can refer to another
736 // document which does (by our model's XScriptInvocationContext::getScriptContainer).
737 // In this case, we return the BasicManager of this other document.
739 OSL_ENSURE( !Reference
< XEmbeddedScripts
>( _rDocument
.GetModel(), UNO_QUERY
).is(),
740 "lcl_getBasicManagerForDocument: inconsistency: no Basic, but an XEmbeddedScripts?" );
741 Reference
< XModel
> xForeignDocument
;
742 Reference
< XScriptInvocationContext
> xContext( _rDocument
.GetModel(), UNO_QUERY
);
745 xForeignDocument
.set( xContext
->getScriptContainer(), UNO_QUERY
);
746 OSL_ENSURE( xForeignDocument
.is() && xForeignDocument
!= _rDocument
.GetModel(),
747 "lcl_getBasicManagerForDocument: no Basic, but providing ourself as script container?" );
750 BasicManager
* pBasMgr
= NULL
;
751 if ( xForeignDocument
.is() )
752 pBasMgr
= ::basic::BasicManagerRepository::getDocumentBasicManager( xForeignDocument
);
758 //--------------------------------------------------------------------
760 BasicManager
* SfxObjectShell::GetBasicManager() const
762 BasicManager
* pBasMgr
= lcl_getBasicManagerForDocument( *this );
764 pBasMgr
= SFX_APP()->GetBasicManager();
768 //--------------------------------------------------------------------
770 void SfxObjectShell::SetHasNoBasic()
772 pImp
->m_bNoBasicCapabilities
= sal_True
;
775 //--------------------------------------------------------------------
777 sal_Bool
SfxObjectShell::HasBasic() const
779 if ( pImp
->m_bNoBasicCapabilities
)
782 if ( !pImp
->bBasicInitialized
)
783 const_cast< SfxObjectShell
* >( this )->InitBasicManager_Impl();
785 return pImp
->pBasicManager
->isValid();
788 //--------------------------------------------------------------------
791 const Reference
< XLibraryContainer
>&
792 lcl_getOrCreateLibraryContainer( bool _bScript
, Reference
< XLibraryContainer
>& _rxContainer
,
793 const Reference
< XModel
>& _rxDocument
)
795 if ( !_rxContainer
.is() )
799 Reference
< XStorageBasedDocument
> xStorageDoc( _rxDocument
, UNO_QUERY
);
800 const Reference
< XComponentContext
> xContext(
801 ::comphelper::getProcessComponentContext() );
802 _rxContainer
.set ( _bScript
803 ? DocumentScriptLibraryContainer::create(
804 xContext
, xStorageDoc
)
805 : DocumentDialogLibraryContainer::create(
806 xContext
, xStorageDoc
)
809 catch( const Exception
& )
811 DBG_UNHANDLED_EXCEPTION();
818 //--------------------------------------------------------------------
820 Reference
< XLibraryContainer
> SfxObjectShell::GetDialogContainer()
822 if ( !pImp
->m_bNoBasicCapabilities
)
823 return lcl_getOrCreateLibraryContainer( false, pImp
->xDialogLibraries
, GetModel() );
825 BasicManager
* pBasMgr
= lcl_getBasicManagerForDocument( *this );
827 return pBasMgr
->GetDialogLibraryContainer().get();
829 OSL_ENSURE( false, "SfxObjectShell::GetDialogContainer: falling back to the application - is this really expected here?" );
830 return SFX_APP()->GetDialogContainer();
833 //--------------------------------------------------------------------
835 Reference
< XLibraryContainer
> SfxObjectShell::GetBasicContainer()
837 if ( !pImp
->m_bNoBasicCapabilities
)
838 return lcl_getOrCreateLibraryContainer( true, pImp
->xBasicLibraries
, GetModel() );
840 BasicManager
* pBasMgr
= lcl_getBasicManagerForDocument( *this );
842 return pBasMgr
->GetScriptLibraryContainer().get();
844 OSL_ENSURE( false, "SfxObjectShell::GetBasicContainer: falling back to the application - is this really expected here?" );
845 return SFX_APP()->GetBasicContainer();
848 //--------------------------------------------------------------------
850 StarBASIC
* SfxObjectShell::GetBasic() const
852 return GetBasicManager()->GetLib(0);
855 //--------------------------------------------------------------------
857 void SfxObjectShell::InitBasicManager_Impl()
860 creates a document's BasicManager and loads it, if we are already based on
865 Diese Methode mu"s aus den "Uberladungen von <SvPersist::Load()> (mit
866 dem pStor aus dem Parameter von Load()) sowie aus der "Uberladung
867 von <SvPersist::InitNew()> (mit pStor = 0) gerufen werden.
871 DBG_ASSERT( !pImp
->bBasicInitialized
&& !pImp
->pBasicManager
->isValid(), "Lokaler BasicManager bereits vorhanden");
872 pImp
->bBasicInitialized
= TRUE
;
874 pImp
->pBasicManager
->reset( BasicManagerRepository::getDocumentBasicManager( GetModel() ) );
875 DBG_ASSERT( pImp
->pBasicManager
->isValid(), "SfxObjectShell::InitBasicManager_Impl: did not get a BasicManager!" );
878 //--------------------------------------------------------------------
880 SotObjectRef
SfxObjectShell::CreateAggObj( const SotFactory
* pFact
)
883 SotFactory
* pDispFact
= SvDispatch::ClassFactory();
884 if( pFact
== pDispFact
)
885 return( (SfxShellObject
*)GetSbxObject() );
887 // sonst unbekannte Aggregation
888 DBG_ERROR("unkekannte Factory");
889 SotObjectRef aSvObjectRef
;
894 //--------------------------------------------------------------------
896 sal_uInt16
SfxObjectShell::Count()
898 return SFX_APP()->GetObjectShells_Impl().Count();
901 //--------------------------------------------------------------------
903 sal_Bool
SfxObjectShell::DoClose()
908 //--------------------------------------------------------------------
910 void SfxObjectShell::SetLastMark_Impl( const String
&rMark
)
915 //--------------------------------------------------------------------
917 const String
& SfxObjectShell::GetLastMark_Impl() const
922 //--------------------------------------------------------------------
924 SfxObjectShell
* SfxObjectShell::GetObjectShell()
929 //--------------------------------------------------------------------
931 SEQUENCE
< OUSTRING
> SfxObjectShell::GetEventNames()
933 return GetEventNames_Impl();
936 SEQUENCE
< OUSTRING
> SfxObjectShell::GetEventNames_Impl()
938 static uno::Sequence
< ::rtl::OUString
>* pEventNameContainer
= NULL
;
940 if ( !pEventNameContainer
)
942 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
943 if ( !pEventNameContainer
)
945 static uno::Sequence
< ::rtl::OUString
> aEventNameContainer( 27 );
946 // SFX_EVENT_STARTAPP
947 aEventNameContainer
[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnStartApp" ) );
949 // SFX_EVENT_CLOSEAPP
950 aEventNameContainer
[1] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnCloseApp" ) );
952 // SFX_EVENT_CREATEDOC
953 aEventNameContainer
[2] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnNew" ) );
956 aEventNameContainer
[3] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnLoad" ) );
958 // SFX_EVENT_SAVEASDOC
959 aEventNameContainer
[4] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnSaveAs" ) );
961 // SFX_EVENT_SAVEASDOCDONE
962 aEventNameContainer
[5] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnSaveAsDone" ) );
965 aEventNameContainer
[6] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnSave" ) );
967 // SFX_EVENT_SAVEDOCDONE
968 aEventNameContainer
[7] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnSaveDone" ) );
970 // SFX_EVENT_PREPARECLOSEDOC
971 aEventNameContainer
[8] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnPrepareUnload" ) );
973 // SFX_EVENT_CLOSEDOC
974 aEventNameContainer
[9] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnUnload" ) );
976 // SFX_EVENT_ACTIVATEDOC
977 aEventNameContainer
[10] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnFocus" ) );
979 // SFX_EVENT_DEACTIVATEDOC
980 aEventNameContainer
[11] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnUnfocus" ) );
982 // SFX_EVENT_PRINTDOC
983 aEventNameContainer
[12] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnPrint" ) );
985 // SFX_EVENT_MODIFYCHANGED
986 aEventNameContainer
[13] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnModifyChanged" ) );
988 // SFX_EVENT_SAVETODOC
989 aEventNameContainer
[14] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnCopyTo" ) );
991 // SFX_EVENT_SAVETODOCDONE
992 aEventNameContainer
[15] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnCopyToDone" ) );
994 // SFX_EVENT_VIEWCREATED
995 aEventNameContainer
[16] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnViewCreated" ) );
997 // SFX_EVENT_PREPARECLOSEVIEW
998 aEventNameContainer
[17] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnPrepareViewClosing" ) );
1000 // SFX_EVENT_CLOSEVIEW
1001 aEventNameContainer
[18] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnViewClosed" ) );
1003 // SFX_EVENT_VISAREACHANGED
1004 aEventNameContainer
[19] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnVisAreaChanged" ) );
1006 // SFX_EVENT_DOCCREATED
1007 aEventNameContainer
[20] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnCreate" ) );
1009 // SFX_EVENT_LOADFINISHED
1010 aEventNameContainer
[21] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnLoadFinished" ) );
1012 // SFX_EVENT_SAVEASDOCFAILED
1013 aEventNameContainer
[22] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnSaveAsFailed" ) );
1015 // SFX_EVENT_SAVEDOCFAILED
1016 aEventNameContainer
[23] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnSaveFailed" ) );
1018 // SFX_EVENT_SAVETODOCFAILED
1019 aEventNameContainer
[24] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnCopyToFailed" ) );
1021 // SFX_HINT_TITLECHANGED
1022 aEventNameContainer
[25] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnTitleChanged" ) );
1024 // SFX_HINT_MODECHANGED
1025 aEventNameContainer
[26] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OnModeChanged" ) );
1027 pEventNameContainer
= &aEventNameContainer
;
1031 return *pEventNameContainer
;
1034 //--------------------------------------------------------------------
1036 void SfxObjectShell::SetModel( SfxBaseModel
* pModel
)
1038 OSL_ENSURE( !pImp
->xModel
.is() || pModel
== NULL
, "Model already set!" );
1039 pImp
->xModel
= pModel
;
1041 pModel
->addCloseListener( new SfxModelListener_Impl(this) );
1042 //pImp->m_xDocInfoListener = new SfxDocInfoListener_Impl(*this);
1043 //uno::Reference<util::XModifyBroadcaster> xMB(
1044 // pModel->getDocumentProperties(), uno::UNO_QUERY_THROW);
1045 //xMB->addModifyListener(pImp->m_xDocInfoListener);
1049 //--------------------------------------------------------------------
1051 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& SfxObjectShell::GetModel() const
1053 return pImp
->xModel
;
1056 void SfxObjectShell::SetBaseModel( SfxBaseModel
* pModel
)
1061 //--------------------------------------------------------------------
1063 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> SfxObjectShell::GetBaseModel()
1065 return pImp
->xModel
;
1067 /* -----------------------------10.09.2001 15:56------------------------------
1069 ---------------------------------------------------------------------------*/
1070 void SfxObjectShell::SetAutoStyleFilterIndex(sal_uInt16 nSet
)
1072 pImp
->nStyleFilter
= nSet
;
1075 sal_uInt16
SfxObjectShell::GetAutoStyleFilterIndex()
1077 return pImp
->nStyleFilter
;
1081 void SfxObjectShell::SetCurrentComponent( const Reference
< XInterface
>& _rxComponent
)
1083 Reference
< XInterface
> xTest(s_xCurrentComponent
);
1084 if ( _rxComponent
== xTest
)
1087 // note that "_rxComponent.get() == s_xCurrentComponent.get().get()" is /sufficient/, but not
1088 // /required/ for "_rxComponent == s_xCurrentComponent.get()".
1089 // In other words, it's still possible that we here do something which is not necessary,
1090 // but we should have filtered quite some unnecessary calls already.
1092 BasicManager
* pAppMgr
= SFX_APP()->GetBasicManager();
1093 s_xCurrentComponent
= _rxComponent
;
1096 lcl_UpdateAppBasicDocVars( _rxComponent
);
1097 pAppMgr
->SetGlobalUNOConstant( "ThisComponent", makeAny( _rxComponent
) );
1100 #if OSL_DEBUG_LEVEL > 0
1101 const char* pComponentImplName
= _rxComponent
.get() ? typeid( *_rxComponent
.get() ).name() : "void";
1102 OSL_TRACE( "current component is a %s\n", pComponentImplName
);
1106 Reference
< XInterface
> SfxObjectShell::GetCurrentComponent()
1108 return s_xCurrentComponent
;
1112 String
SfxObjectShell::GetServiceNameFromFactory( const String
& rFact
)
1114 //! Remove everything behind name!
1115 String
aFact( rFact
);
1116 String aPrefix
= String::CreateFromAscii( "private:factory/" );
1117 if ( aPrefix
.Len() == aFact
.Match( aPrefix
) )
1118 aFact
.Erase( 0, aPrefix
.Len() );
1119 USHORT nPos
= aFact
.Search( '?' );
1121 if ( nPos
!= STRING_NOTFOUND
)
1123 aParam
= aFact
.Copy( nPos
, aFact
.Len() );
1124 aFact
.Erase( nPos
, aFact
.Len() );
1127 aFact
.EraseAllChars('4').ToLowerAscii();
1129 // HACK: sometimes a real document service name is given here instead of
1130 // a factory short name. Set return value directly to this service name as fallback
1131 // in case next lines of code does nothing ...
1132 // use rFact instead of normed aFact value !
1133 ::rtl::OUString aServiceName
= rFact
;
1135 if ( aFact
.EqualsAscii("swriter") )
1137 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.text.TextDocument");
1139 else if ( aFact
.EqualsAscii("sweb") || aFact
.EqualsAscii("swriter/web") )
1141 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.text.WebDocument");
1143 else if ( aFact
.EqualsAscii("sglobal") || aFact
.EqualsAscii("swriter/globaldocument") )
1145 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.text.GlobalDocument");
1147 else if ( aFact
.EqualsAscii("scalc") )
1149 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.sheet.SpreadsheetDocument");
1151 else if ( aFact
.EqualsAscii("sdraw") )
1153 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.drawing.DrawingDocument");
1155 else if ( aFact
.EqualsAscii("simpress") )
1157 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.presentation.PresentationDocument");
1159 else if ( aFact
.EqualsAscii("schart") )
1161 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.chart.ChartDocument");
1163 else if ( aFact
.EqualsAscii("smath") )
1165 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.formula.FormulaProperties");
1167 else if ( aFact
.EqualsAscii("sbasic") )
1169 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.script.BasicIDE");
1171 else if ( aFact
.EqualsAscii("sdatabase") )
1173 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.sdb.OfficeDatabaseDocument");
1176 return aServiceName
;
1179 SfxObjectShell
* SfxObjectShell::CreateObjectByFactoryName( const String
& rFact
, SfxObjectCreateMode eMode
)
1181 return CreateObject( GetServiceNameFromFactory( rFact
), eMode
);
1185 SfxObjectShell
* SfxObjectShell::CreateObject( const String
& rServiceName
, SfxObjectCreateMode eCreateMode
)
1187 if ( rServiceName
.Len() )
1189 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> xDoc(
1190 ::comphelper::getProcessServiceFactory()->createInstance( rServiceName
), UNO_QUERY
);
1193 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XUnoTunnel
> xObj( xDoc
, UNO_QUERY
);
1194 ::com::sun::star::uno::Sequence
< sal_Int8
> aSeq( SvGlobalName( SFX_GLOBAL_CLASSID
).GetByteSequence() );
1195 sal_Int64 nHandle
= xObj
->getSomething( aSeq
);
1198 SfxObjectShell
* pRet
= reinterpret_cast< SfxObjectShell
* >( sal::static_int_cast
< sal_IntPtr
>( nHandle
));
1199 pRet
->SetCreateMode_Impl( eCreateMode
);
1208 SfxObjectShell
* SfxObjectShell::CreateAndLoadObject( const SfxItemSet
& rSet
, SfxFrame
* pFrame
)
1210 uno::Sequence
< beans::PropertyValue
> aProps
;
1211 TransformItems( SID_OPENDOC
, rSet
, aProps
);
1212 SFX_ITEMSET_ARG(&rSet
, pFileNameItem
, SfxStringItem
, SID_FILE_NAME
, FALSE
);
1213 SFX_ITEMSET_ARG(&rSet
, pTargetItem
, SfxStringItem
, SID_TARGETNAME
, FALSE
);
1214 ::rtl::OUString aURL
;
1215 ::rtl::OUString aTarget
= rtl::OUString::createFromAscii("_blank");
1216 if ( pFileNameItem
)
1217 aURL
= pFileNameItem
->GetValue();
1219 aTarget
= pTargetItem
->GetValue();
1221 uno::Reference
< frame::XComponentLoader
> xLoader
;
1224 xLoader
= uno::Reference
< frame::XComponentLoader
>( pFrame
->GetFrameInterface(), uno::UNO_QUERY
);
1227 xLoader
= uno::Reference
< frame::XComponentLoader
>( comphelper::getProcessServiceFactory()->createInstance(
1228 ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop") ), uno::UNO_QUERY
);
1230 uno::Reference
< lang::XUnoTunnel
> xObj
;
1233 xObj
= uno::Reference
< lang::XUnoTunnel
>( xLoader
->loadComponentFromURL( aURL
, aTarget
, 0, aProps
), uno::UNO_QUERY
);
1235 catch( uno::Exception
& )
1240 ::com::sun::star::uno::Sequence
< sal_Int8
> aSeq( SvGlobalName( SFX_GLOBAL_CLASSID
).GetByteSequence() );
1241 sal_Int64 nHandle
= xObj
->getSomething( aSeq
);
1243 return reinterpret_cast< SfxObjectShell
* >(sal::static_int_cast
< sal_IntPtr
>( nHandle
));