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>
64 #include <svtools/eventcfg.hxx>
66 #include <sfx2/objsh.hxx>
67 #include <sfx2/signaturestate.hxx>
69 #ifndef _BASIC_SBUNO_HXX
70 #include <basic/sbuno.hxx>
72 #include <svtools/sfxecode.hxx>
73 #include <svtools/ehdl.hxx>
74 #include <svtools/printwarningoptions.hxx>
75 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
76 #include <comphelper/processfactory.hxx>
79 #include <com/sun/star/document/XStorageBasedDocument.hpp>
80 #include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
81 #include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
82 #include <com/sun/star/document/XEmbeddedScripts.hpp>
83 #include <com/sun/star/document/XScriptInvocationContext.hpp>
85 #include <svtools/urihelper.hxx>
86 #include <svtools/pathoptions.hxx>
87 #include <svtools/sharecontrolfile.hxx>
88 #include <unotools/localfilehelper.hxx>
89 #include <unotools/ucbhelper.hxx>
90 #include <svtools/asynclink.hxx>
91 #include <tools/diagnose_ex.h>
92 #include <sot/clsids.hxx>
94 #include <sfx2/app.hxx>
95 #include <sfx2/docfac.hxx>
96 #include <sfx2/docfile.hxx>
97 #include <sfx2/event.hxx>
98 #include <sfx2/dispatch.hxx>
99 #include <sfx2/viewsh.hxx>
100 #include <sfx2/viewfrm.hxx>
101 #include "sfxresid.hxx"
102 #include "objshimp.hxx"
103 #include "appbas.hxx"
104 #include "sfxtypes.hxx"
105 #include <sfx2/evntconf.hxx>
106 #include <sfx2/request.hxx>
108 #include "sfxlocal.hrc"
109 #include "appdata.hxx"
110 #include <sfx2/appuno.hxx>
111 #include <sfx2/sfxsids.hrc>
112 #include "basmgr.hxx"
113 #include "QuerySaveDocument.hxx"
114 #include "helpid.hrc"
115 #include <sfx2/msg.hxx>
116 #include "appbaslib.hxx"
117 #include <sfx2/sfxbasemodel.hxx>
119 #include <basic/basicmanagerrepository.hxx>
121 using namespace ::com::sun::star
;
122 using namespace ::com::sun::star::uno
;
123 using namespace ::com::sun::star::script
;
124 using namespace ::com::sun::star::frame
;
125 using namespace ::com::sun::star::document
;
127 using ::basic::BasicManagerRepository
;
128 #include <uno/mapping.hxx>
130 //====================================================================
132 DBG_NAME(SfxObjectShell
)
135 #include "sfxslots.hxx"
137 extern svtools::AsynchronLink
* pPendingCloser
;
138 static WeakReference
< XInterface
> s_xCurrentComponent
;
140 void lcl_UpdateAppBasicDocVars( const Reference
< XInterface
>& _rxComponent
, bool bClear
= false )
142 BasicManager
* pAppMgr
= SFX_APP()->GetBasicManager();
145 uno::Reference
< beans::XPropertySet
> xProps( _rxComponent
, uno::UNO_QUERY
);
150 beans::PropertyValue aProp
;
151 xProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ThisVBADocObj") ) ) >>= aProp
;
152 rtl::OString
sTmp( rtl::OUStringToOString( aProp
.Name
, RTL_TEXTENCODING_UTF8
) );
153 const char* pAscii
= sTmp
.getStr();
155 pAppMgr
->SetGlobalUNOConstant( pAscii
, uno::makeAny( uno::Reference
< uno::XInterface
>() ) );
157 pAppMgr
->SetGlobalUNOConstant( pAscii
, aProp
.Value
);
160 catch( uno::Exception
& e
)
167 //=========================================================================
170 //=========================================================================
172 class SfxModelListener_Impl
: public ::cppu::WeakImplHelper1
< ::com::sun::star::util::XCloseListener
>
174 SfxObjectShell
* mpDoc
;
176 SfxModelListener_Impl( SfxObjectShell
* pDoc
) : mpDoc(pDoc
) {};
177 virtual void SAL_CALL
queryClosing( const com::sun::star::lang::EventObject
& aEvent
, sal_Bool bDeliverOwnership
)
178 throw ( com::sun::star::uno::RuntimeException
, com::sun::star::util::CloseVetoException
) ;
179 virtual void SAL_CALL
notifyClosing( const com::sun::star::lang::EventObject
& aEvent
) throw ( com::sun::star::uno::RuntimeException
) ;
180 virtual void SAL_CALL
disposing( const com::sun::star::lang::EventObject
& aEvent
) throw ( com::sun::star::uno::RuntimeException
) ;
184 void SAL_CALL
SfxModelListener_Impl::queryClosing( const com::sun::star::lang::EventObject
& , sal_Bool
)
185 throw ( com::sun::star::uno::RuntimeException
, com::sun::star::util::CloseVetoException
)
189 void SAL_CALL
SfxModelListener_Impl::notifyClosing( const com::sun::star::lang::EventObject
& ) throw ( com::sun::star::uno::RuntimeException
)
191 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
192 mpDoc
->Broadcast( SfxSimpleHint(SFX_HINT_DEINITIALIZING
) );
195 void SAL_CALL
SfxModelListener_Impl::disposing( const com::sun::star::lang::EventObject
& _rEvent
) throw ( com::sun::star::uno::RuntimeException
)
197 // am I ThisComponent in AppBasic?
198 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
199 if ( SfxObjectShell::GetCurrentComponent() == _rEvent
.Source
)
201 lcl_UpdateAppBasicDocVars( SfxObjectShell::GetCurrentComponent(), true );
202 // remove ThisComponent reference from AppBasic
203 SfxObjectShell::SetCurrentComponent( Reference
< XInterface
>() );
206 if ( mpDoc
->Get_Impl()->bHiddenLockedByAPI
)
208 mpDoc
->Get_Impl()->bHiddenLockedByAPI
= FALSE
;
209 mpDoc
->OwnerLock(FALSE
);
211 else if ( !mpDoc
->Get_Impl()->bClosing
)
212 // GCC stuerzt ab, wenn schon im dtor, also vorher Flag abfragen
216 TYPEINIT1(SfxObjectShell
, SfxShell
);
218 //--------------------------------------------------------------------
219 SfxObjectShell_Impl::SfxObjectShell_Impl( SfxObjectShell
& _rDocShell
)
220 :mpObjectContainer(0)
223 ,pBasicManager( new SfxBasicManagerHolder
)
224 ,rDocShell( _rDocShell
)
228 ,nVisualDocumentNumber( USHRT_MAX
)
229 ,nDocumentSignatureState( SIGNATURESTATE_UNKNOWN
)
230 ,nScriptingSignatureState( SIGNATURESTATE_UNKNOWN
)
231 ,bTemplateConfig( sal_False
)
233 ,bClosing( sal_False
)
234 ,bSetInPlaceObj( sal_False
)
235 ,bIsSaving( sal_False
)
238 ,bIsNamedVisible( sal_False
)
239 ,bIsTemplate(sal_False
)
240 ,bIsAbortingImport ( sal_False
)
241 ,bImportDone ( sal_False
)
242 ,bInPrepareClose( sal_False
)
243 ,bPreparedForClose( sal_False
)
244 ,bWaitingForPicklist( sal_False
)
245 ,bModuleSearched( sal_False
)
246 ,bIsHelpObjSh( sal_False
)
247 ,bForbidCaching( sal_False
)
248 ,bForbidReload( sal_False
)
249 ,bSupportsEventMacros( sal_True
)
250 ,bLoadingWindows( sal_False
)
251 ,bBasicInitialized( sal_False
)
252 // ,bHidden( sal_False )
253 ,bIsPrintJobCancelable( sal_True
)
254 ,bOwnsStorage( sal_True
)
255 ,bNoBaseURL( sal_False
)
256 ,bInitialized( sal_False
)
257 ,bSignatureErrorIsShown( sal_False
)
258 ,bModelInitialized( sal_False
)
259 ,bPreserveVersions( sal_True
)
260 ,m_bMacroSignBroken( sal_False
)
261 ,m_bNoBasicCapabilities( sal_False
)
262 ,bQueryLoadTemplate( sal_True
)
263 ,bLoadReadonly( sal_False
)
264 ,bUseUserData( sal_True
)
265 ,bSaveVersionOnClose( sal_False
)
266 ,m_bSharedXMLFlag( sal_False
)
267 ,m_bAllowShareControlFileClean( sal_True
)
270 ,bDoNotTouchDocInfo( sal_False
)
273 ,nLoadedFlags ( SFX_LOADED_MAINDOCUMENT
)
274 ,nFlagsInProgress( 0 )
275 ,bInFrame( sal_False
)
276 ,bModalMode( sal_False
)
277 ,bRunningMacro( sal_False
)
278 ,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
)
296 ,m_bIncomplEncrWarnShown( sal_False
)
300 //--------------------------------------------------------------------
302 SfxObjectShell_Impl::~SfxObjectShell_Impl()
304 if ( pPendingCloser
== pCloser
)
307 delete pBasicManager
;
310 // initializes a document from a file-description
312 SfxObjectShell::SfxObjectShell
314 SfxObjectCreateMode eMode
/* Zweck, zu dem die SfxObjectShell
317 SFX_CREATE_MODE_EMBEDDED (default)
318 als SO-Server aus einem anderen
321 SFX_CREATE_MODE_STANDARD,
322 als normales, selbst"aendig ge"offnetes
325 SFX_CREATE_MODE_PREVIEW
326 um ein Preview durchzuf"uhren,
327 ggf. werden weniger Daten ben"otigt
329 SFX_CREATE_MODE_ORGANIZER
330 um im Organizer dargestellt zu
331 werden, hier werden keine Inhalte
337 Konstruktor der Klasse SfxObjectShell.
340 : pImp( new SfxObjectShell_Impl( *this ) ),
345 DBG_CTOR(SfxObjectShell
, 0);
347 bHasName
= sal_False
;
350 pImp
->bWaitingForPicklist
= sal_True
;
352 // Aggregation InPlaceObject+Automation
353 //(mba) AddInterface( SvDispatch::ClassFactory() );
355 SfxObjectShell
*pThis
= this;
356 SfxObjectShellArr_Impl
&rArr
= SFX_APP()->GetObjectShells_Impl();
357 rArr
.C40_INSERT( SfxObjectShell
, pThis
, rArr
.Count() );
358 pImp
->bInList
= sal_True
;
359 pImp
->nLoadedFlags
= SFX_LOADED_ALL
;
360 //REMOVE SetObjectShell( TRUE );
363 //--------------------------------------------------------------------
365 // virtual dtor of typical base-class SfxObjectShell
367 SfxObjectShell::~SfxObjectShell()
369 DBG_DTOR(SfxObjectShell
, 0);
371 if ( IsEnableSetModified() )
372 EnableSetModified( sal_False
);
374 // Niemals GetInPlaceObject() aufrufen, der Zugriff auf den
375 // Ableitungszweig SfxInternObject ist wegen eines Compiler Bugs nicht
377 SfxObjectShell::Close();
380 // DELETEX(pImp->pEventConfig);
381 // DELETEX(pImp->pTbxConfig);
382 // DELETEX(pImp->pAccMgr);
383 // DELETEX(pImp->pCfgMgr);
384 DELETEX(pImp
->pReloadTimer
);
386 SfxApplication
*pSfxApp
= SFX_APP();
387 if ( USHRT_MAX
!= pImp
->nVisualDocumentNumber
)
388 pSfxApp
->ReleaseIndex(pImp
->nVisualDocumentNumber
);
390 // Basic-Manager zerst"oren
391 pImp
->pBasicManager
->reset( NULL
);
393 if ( pSfxApp
->GetDdeService() )
394 pSfxApp
->RemoveDdeTopic( this );
396 if ( pImp
->xModel
.is() )
397 pImp
->xModel
= ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> ();
399 // don't call GetStorage() here, in case of Load Failure it's possible that a storage was never assigned!
400 if ( pMedium
&& pMedium
->HasStorage_Impl() && pMedium
->GetStorage( sal_False
) == pImp
->m_xDocStorage
)
401 pMedium
->CanDisposeStorage_Impl( sal_False
);
403 if ( pImp
->mpObjectContainer
)
405 pImp
->mpObjectContainer
->CloseEmbeddedObjects();
406 delete pImp
->mpObjectContainer
;
409 if ( pImp
->bOwnsStorage
&& pImp
->m_xDocStorage
.is() )
413 pImp
->m_xDocStorage
->dispose();
423 pMedium
->CloseAndReleaseStreams_Impl();
431 // The removing of the temporary file must be done as the latest step in the document destruction
432 if ( pImp
->aTempName
.Len() )
435 ::utl::LocalFileHelper::ConvertPhysicalNameToURL( pImp
->aTempName
, aTmp
);
436 ::utl::UCBContentHelper::Kill( aTmp
);
442 //--------------------------------------------------------------------
444 void SfxObjectShell::Stamp_SetPrintCancelState(sal_Bool bState
)
446 pImp
->bIsPrintJobCancelable
= bState
;
449 //--------------------------------------------------------------------
451 sal_Bool
SfxObjectShell::Stamp_GetPrintCancelState() const
453 return pImp
->bIsPrintJobCancelable
;
456 //--------------------------------------------------------------------
458 void SfxObjectShell::ViewAssigned()
462 Diese Methode wird gerufen, wenn eine View zugewiesen wird.
468 //--------------------------------------------------------------------
469 // closes the Object and all its views
471 sal_Bool
SfxObjectShell::Close()
473 {DBG_CHKTHIS(SfxObjectShell
, 0);}
474 SfxObjectShellRef
aRef(this);
475 if ( !pImp
->bClosing
)
477 // falls noch ein Progress l"auft, nicht schlie\sen
478 if ( !pImp
->bDisposing
&& GetProgress() )
481 pImp
->bClosing
= sal_True
;
482 Reference
< util::XCloseable
> xCloseable( GetBaseModel(), UNO_QUERY
);
484 if ( xCloseable
.is() )
488 xCloseable
->close( sal_True
);
492 pImp
->bClosing
= sal_False
;
496 if ( pImp
->bClosing
)
498 // aus Document-Liste austragen
499 SfxApplication
*pSfxApp
= SFX_APP();
500 SfxObjectShellArr_Impl
&rDocs
= pSfxApp
->GetObjectShells_Impl();
501 const SfxObjectShell
*pThis
= this;
502 sal_uInt16 nPos
= rDocs
.GetPos(pThis
);
503 if ( nPos
< rDocs
.Count() )
504 rDocs
.Remove( nPos
);
505 pImp
->bInList
= sal_False
;
512 //--------------------------------------------------------------------
514 // returns a pointer the first SfxDocument of specified type
516 SfxObjectShell
* SfxObjectShell::GetFirst
518 const TypeId
* pType
,
519 sal_Bool bOnlyVisible
522 SfxObjectShellArr_Impl
&rDocs
= SFX_APP()->GetObjectShells_Impl();
524 // seach for a SfxDocument of the specified type
525 for ( sal_uInt16 nPos
= 0; nPos
< rDocs
.Count(); ++nPos
)
527 SfxObjectShell
* pSh
= rDocs
.GetObject( nPos
);
528 if ( bOnlyVisible
&& pSh
->IsPreview() && pSh
->IsReadOnly() )
531 if ( ( !pType
|| pSh
->IsA(*pType
) ) &&
532 ( !bOnlyVisible
|| SfxViewFrame::GetFirst( pSh
, 0, sal_True
)))
538 //--------------------------------------------------------------------
540 // returns a pointer to the next SfxDocument of specified type behind *pDoc
542 SfxObjectShell
* SfxObjectShell::GetNext
544 const SfxObjectShell
& rPrev
,
546 sal_Bool bOnlyVisible
549 SfxObjectShellArr_Impl
&rDocs
= SFX_APP()->GetObjectShells_Impl();
551 // refind the specified predecessor
553 for ( nPos
= 0; nPos
< rDocs
.Count(); ++nPos
)
554 if ( rDocs
.GetObject(nPos
) == &rPrev
)
557 // search for the next SfxDocument of the specified type
558 for ( ++nPos
; nPos
< rDocs
.Count(); ++nPos
)
560 SfxObjectShell
* pSh
= rDocs
.GetObject( nPos
);
561 if ( bOnlyVisible
&& pSh
->IsPreview() && pSh
->IsReadOnly() )
564 if ( ( !pType
|| pSh
->IsA(*pType
) ) &&
565 ( !bOnlyVisible
|| SfxViewFrame::GetFirst( pSh
, 0, sal_True
)))
571 //--------------------------------------------------------------------
573 SfxObjectShell
* SfxObjectShell::Current()
575 SfxViewFrame
*pFrame
= SfxViewFrame::Current();
576 return pFrame
? pFrame
->GetObjectShell() : 0;
579 //-------------------------------------------------------------------------
581 sal_Bool
SfxObjectShell::IsInPrepareClose() const
583 return pImp
->bInPrepareClose
;
586 //------------------------------------------------------------------------
590 SfxObjectShell_Impl
* pImp
;
591 BoolEnv_Impl( SfxObjectShell_Impl
* pImpP
) : pImp( pImpP
)
592 { pImpP
->bInPrepareClose
= sal_True
; }
593 ~BoolEnv_Impl() { pImp
->bInPrepareClose
= sal_False
; }
597 sal_uInt16
SfxObjectShell::PrepareClose
599 sal_Bool bUI
, // sal_True: Dialoge etc. erlaubt, sal_False: silent-mode
600 sal_Bool bForBrowsing
603 if( pImp
->bInPrepareClose
|| pImp
->bPreparedForClose
)
605 BoolEnv_Impl
aBoolEnv( pImp
);
608 if ( IsInModalMode() )
611 SfxViewFrame
* pFirst
= SfxViewFrame::GetFirst( this );
612 if( pFirst
&& !pFirst
->GetFrame()->PrepareClose_Impl( bUI
, bForBrowsing
) )
615 // prepare views for closing
616 for ( SfxViewFrame
* pFrm
= SfxViewFrame::GetFirst(
617 this, TYPE(SfxViewFrame
));
618 pFrm
; pFrm
= SfxViewFrame::GetNext( *pFrm
, this ) )
620 DBG_ASSERT(pFrm
->GetViewShell(),"KeineShell");
621 if ( pFrm
->GetViewShell() )
623 sal_uInt16 nRet
= pFrm
->GetViewShell()->PrepareClose( bUI
, bForBrowsing
);
624 if ( nRet
!= sal_True
)
629 SfxApplication
*pSfxApp
= SFX_APP();
630 pSfxApp
->NotifyEvent( SfxEventHint(SFX_EVENT_PREPARECLOSEDOC
, GlobalEventConfig::GetEventName(STR_EVENT_PREPARECLOSEDOC
), this) );
632 if( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED
)
634 pImp
->bPreparedForClose
= sal_True
;
638 // ggf. nachfragen, ob gespeichert werden soll
639 // nur fuer in sichtbaren Fenstern dargestellte Dokumente fragen
640 SfxViewFrame
*pFrame
= SfxObjectShell::Current() == this
641 ? SfxViewFrame::Current() : SfxViewFrame::GetFirst( this );
642 while ( pFrame
&& (pFrame
->GetFrameType() & SFXFRAME_SERVER
) )
643 pFrame
= SfxViewFrame::GetNext( *pFrame
, this );
645 sal_Bool bClose
= sal_False
;
646 if ( bUI
&& IsModified() )
650 // minimierte restoren
651 SfxFrame
* pTop
= pFrame
->GetTopFrame();
652 SfxViewFrame::SetViewFrame( pTop
->GetCurrentViewFrame() );
653 pFrame
->GetFrame()->Appear();
655 // fragen, ob gespeichert werden soll
656 short nRet
= RET_YES
;
658 //brauchen wir UI=2 noch?
659 //if( SfxApplication::IsPlugin() == sal_False || bUI == 2 )
661 //initiate help agent to inform about "print modifies the document"
662 SvtPrintWarningOptions aPrintOptions
;
663 if (aPrintOptions
.IsModifyDocumentOnPrintingAllowed() &&
664 HasName() && getDocProperties()->getPrintDate().Month
> 0)
666 SfxHelp::OpenHelpAgent(pFirst
->GetFrame(), HID_CLOSE_WARNING
);
668 const Reference
< XTitle
> xTitle(pImp
->xModel
, UNO_QUERY_THROW
);
669 const ::rtl::OUString sTitle
= xTitle
->getTitle ();
670 nRet
= ExecuteQuerySaveDocument(&pFrame
->GetWindow(),sTitle
);
672 /*HACK for plugin::destroy()*/
674 if ( RET_YES
== nRet
)
676 // per Dispatcher speichern
677 const SfxPoolItem
*pPoolItem
;
678 if ( IsSaveVersionOnClose() )
680 SfxStringItem
aItem( SID_DOCINFO_COMMENTS
, String( SfxResId( STR_AUTOMATICVERSION
) ) );
681 SfxBoolItem
aWarnItem( SID_FAIL_ON_WARNING
, bUI
);
682 const SfxPoolItem
* ppArgs
[] = { &aItem
, &aWarnItem
, 0 };
683 pPoolItem
= pFrame
->GetBindings().ExecuteSynchron( SID_SAVEDOC
, ppArgs
);
687 SfxBoolItem
aWarnItem( SID_FAIL_ON_WARNING
, bUI
);
688 const SfxPoolItem
* ppArgs
[] = { &aWarnItem
, 0 };
689 pPoolItem
= pFrame
->GetBindings().ExecuteSynchron( SID_SAVEDOC
, ppArgs
);
692 if ( !pPoolItem
|| pPoolItem
->ISA(SfxVoidItem
) || ( pPoolItem
->ISA(SfxBoolItem
) && !( (const SfxBoolItem
*) pPoolItem
)->GetValue() ) )
697 else if ( RET_CANCEL
== nRet
)
700 else if ( RET_NEWTASK
== nRet
)
706 // Bei Nein nicht noch Informationlost
712 // ggf. hinweisen, da\s unter Fremdformat gespeichert
715 SFX_ITEMSET_ARG( pMedium
->GetItemSet(), pIgnoreInformationLost
,
716 SfxBoolItem
, SID_DOC_IGNOREINFORMATIONLOST
, sal_False
);
717 if( pIgnoreInformationLost
&& pIgnoreInformationLost
->GetValue() )
721 pImp
->bPreparedForClose
= sal_True
;
725 //--------------------------------------------------------------------
728 static BasicManager
* lcl_getBasicManagerForDocument( const SfxObjectShell
& _rDocument
)
730 if ( !_rDocument
.Get_Impl()->m_bNoBasicCapabilities
)
732 if ( !_rDocument
.Get_Impl()->bBasicInitialized
)
733 const_cast< SfxObjectShell
& >( _rDocument
).InitBasicManager_Impl();
734 return _rDocument
.Get_Impl()->pBasicManager
->get();
737 // assume we do not have Basic ourself, but we can refer to another
738 // document which does (by our model's XScriptInvocationContext::getScriptContainer).
739 // In this case, we return the BasicManager of this other document.
741 OSL_ENSURE( !Reference
< XEmbeddedScripts
>( _rDocument
.GetModel(), UNO_QUERY
).is(),
742 "lcl_getBasicManagerForDocument: inconsistency: no Basic, but an XEmbeddedScripts?" );
743 Reference
< XModel
> xForeignDocument
;
744 Reference
< XScriptInvocationContext
> xContext( _rDocument
.GetModel(), UNO_QUERY
);
747 xForeignDocument
.set( xContext
->getScriptContainer(), UNO_QUERY
);
748 OSL_ENSURE( xForeignDocument
.is() && xForeignDocument
!= _rDocument
.GetModel(),
749 "lcl_getBasicManagerForDocument: no Basic, but providing ourself as script container?" );
752 BasicManager
* pBasMgr
= NULL
;
753 if ( xForeignDocument
.is() )
754 pBasMgr
= ::basic::BasicManagerRepository::getDocumentBasicManager( xForeignDocument
);
760 //--------------------------------------------------------------------
762 BasicManager
* SfxObjectShell::GetBasicManager() const
764 BasicManager
* pBasMgr
= lcl_getBasicManagerForDocument( *this );
766 pBasMgr
= SFX_APP()->GetBasicManager();
770 //--------------------------------------------------------------------
772 void SfxObjectShell::SetHasNoBasic()
774 pImp
->m_bNoBasicCapabilities
= sal_True
;
777 //--------------------------------------------------------------------
779 sal_Bool
SfxObjectShell::HasBasic() const
781 if ( pImp
->m_bNoBasicCapabilities
)
784 if ( !pImp
->bBasicInitialized
)
785 const_cast< SfxObjectShell
* >( this )->InitBasicManager_Impl();
787 return pImp
->pBasicManager
->isValid();
790 //--------------------------------------------------------------------
793 const Reference
< XLibraryContainer
>&
794 lcl_getOrCreateLibraryContainer( bool _bScript
, Reference
< XLibraryContainer
>& _rxContainer
,
795 const Reference
< XModel
>& _rxDocument
)
797 if ( !_rxContainer
.is() )
801 Reference
< XStorageBasedDocument
> xStorageDoc( _rxDocument
, UNO_QUERY
);
802 const Reference
< XComponentContext
> xContext(
803 ::comphelper::getProcessComponentContext() );
804 _rxContainer
.set ( _bScript
805 ? DocumentScriptLibraryContainer::create(
806 xContext
, xStorageDoc
)
807 : DocumentDialogLibraryContainer::create(
808 xContext
, xStorageDoc
)
811 catch( const Exception
& )
813 DBG_UNHANDLED_EXCEPTION();
820 //--------------------------------------------------------------------
822 Reference
< XLibraryContainer
> SfxObjectShell::GetDialogContainer()
824 if ( !pImp
->m_bNoBasicCapabilities
)
825 return lcl_getOrCreateLibraryContainer( false, pImp
->xDialogLibraries
, GetModel() );
827 BasicManager
* pBasMgr
= lcl_getBasicManagerForDocument( *this );
829 return pBasMgr
->GetDialogLibraryContainer().get();
831 OSL_ENSURE( false, "SfxObjectShell::GetDialogContainer: falling back to the application - is this really expected here?" );
832 return SFX_APP()->GetDialogContainer();
835 //--------------------------------------------------------------------
837 Reference
< XLibraryContainer
> SfxObjectShell::GetBasicContainer()
839 if ( !pImp
->m_bNoBasicCapabilities
)
840 return lcl_getOrCreateLibraryContainer( true, pImp
->xBasicLibraries
, GetModel() );
842 BasicManager
* pBasMgr
= lcl_getBasicManagerForDocument( *this );
844 return pBasMgr
->GetScriptLibraryContainer().get();
846 OSL_ENSURE( false, "SfxObjectShell::GetBasicContainer: falling back to the application - is this really expected here?" );
847 return SFX_APP()->GetBasicContainer();
850 //--------------------------------------------------------------------
852 StarBASIC
* SfxObjectShell::GetBasic() const
854 return GetBasicManager()->GetLib(0);
857 //--------------------------------------------------------------------
859 void SfxObjectShell::InitBasicManager_Impl()
862 creates a document's BasicManager and loads it, if we are already based on
867 Diese Methode mu"s aus den "Uberladungen von <SvPersist::Load()> (mit
868 dem pStor aus dem Parameter von Load()) sowie aus der "Uberladung
869 von <SvPersist::InitNew()> (mit pStor = 0) gerufen werden.
873 DBG_ASSERT( !pImp
->bBasicInitialized
&& !pImp
->pBasicManager
->isValid(), "Lokaler BasicManager bereits vorhanden");
874 pImp
->bBasicInitialized
= TRUE
;
876 pImp
->pBasicManager
->reset( BasicManagerRepository::getDocumentBasicManager( GetModel() ) );
877 DBG_ASSERT( pImp
->pBasicManager
->isValid(), "SfxObjectShell::InitBasicManager_Impl: did not get a BasicManager!" );
880 //--------------------------------------------------------------------
882 SotObjectRef
SfxObjectShell::CreateAggObj( const SotFactory
* pFact
)
885 SotFactory
* pDispFact
= SvDispatch::ClassFactory();
886 if( pFact
== pDispFact
)
887 return( (SfxShellObject
*)GetSbxObject() );
889 // sonst unbekannte Aggregation
890 DBG_ERROR("unkekannte Factory");
891 SotObjectRef aSvObjectRef
;
896 //--------------------------------------------------------------------
898 sal_uInt16
SfxObjectShell::Count()
900 return SFX_APP()->GetObjectShells_Impl().Count();
903 //--------------------------------------------------------------------
905 sal_Bool
SfxObjectShell::DoClose()
910 //--------------------------------------------------------------------
912 void SfxObjectShell::SetLastMark_Impl( const String
&rMark
)
917 //--------------------------------------------------------------------
919 const String
& SfxObjectShell::GetLastMark_Impl() const
924 //--------------------------------------------------------------------
926 SfxObjectShell
* SfxObjectShell::GetObjectShell()
931 //--------------------------------------------------------------------
933 SEQUENCE
< OUSTRING
> SfxObjectShell::GetEventNames()
935 static uno::Sequence
< ::rtl::OUString
>* pEventNameContainer
= NULL
;
937 if ( !pEventNameContainer
)
939 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
940 if ( !pEventNameContainer
)
942 static uno::Sequence
< ::rtl::OUString
> aEventNameContainer
= GlobalEventConfig().getElementNames();
943 pEventNameContainer
= &aEventNameContainer
;
947 return *pEventNameContainer
;
950 SEQUENCE
< OUSTRING
> SfxObjectShell::GetEventNames_Impl()
952 if (!pImp
->xEventNames
.getLength())
953 pImp
->xEventNames
= GetEventNames();
954 return pImp
->xEventNames
;
957 //--------------------------------------------------------------------
959 void SfxObjectShell::SetModel( SfxBaseModel
* pModel
)
961 OSL_ENSURE( !pImp
->xModel
.is() || pModel
== NULL
, "Model already set!" );
962 pImp
->xModel
= pModel
;
964 pModel
->addCloseListener( new SfxModelListener_Impl(this) );
965 //pImp->m_xDocInfoListener = new SfxDocInfoListener_Impl(*this);
966 //uno::Reference<util::XModifyBroadcaster> xMB(
967 // pModel->getDocumentProperties(), uno::UNO_QUERY_THROW);
968 //xMB->addModifyListener(pImp->m_xDocInfoListener);
972 //--------------------------------------------------------------------
974 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
>& SfxObjectShell::GetModel() const
979 void SfxObjectShell::SetBaseModel( SfxBaseModel
* pModel
)
984 //--------------------------------------------------------------------
986 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> SfxObjectShell::GetBaseModel()
990 /* -----------------------------10.09.2001 15:56------------------------------
992 ---------------------------------------------------------------------------*/
993 void SfxObjectShell::SetAutoStyleFilterIndex(sal_uInt16 nSet
)
995 pImp
->nStyleFilter
= nSet
;
998 sal_uInt16
SfxObjectShell::GetAutoStyleFilterIndex()
1000 return pImp
->nStyleFilter
;
1004 void SfxObjectShell::SetCurrentComponent( const Reference
< XInterface
>& _rxComponent
)
1006 Reference
< XInterface
> xTest(s_xCurrentComponent
);
1007 if ( _rxComponent
== xTest
)
1010 // note that "_rxComponent.get() == s_xCurrentComponent.get().get()" is /sufficient/, but not
1011 // /required/ for "_rxComponent == s_xCurrentComponent.get()".
1012 // In other words, it's still possible that we here do something which is not necessary,
1013 // but we should have filtered quite some unnecessary calls already.
1015 BasicManager
* pAppMgr
= SFX_APP()->GetBasicManager();
1016 s_xCurrentComponent
= _rxComponent
;
1019 lcl_UpdateAppBasicDocVars( _rxComponent
);
1020 pAppMgr
->SetGlobalUNOConstant( "ThisComponent", makeAny( _rxComponent
) );
1023 #if OSL_DEBUG_LEVEL > 0
1024 const char* pComponentImplName
= _rxComponent
.get() ? typeid( *_rxComponent
.get() ).name() : "void";
1025 OSL_TRACE( "current component is a %s\n", pComponentImplName
);
1029 Reference
< XInterface
> SfxObjectShell::GetCurrentComponent()
1031 return s_xCurrentComponent
;
1035 String
SfxObjectShell::GetServiceNameFromFactory( const String
& rFact
)
1037 //! Remove everything behind name!
1038 String
aFact( rFact
);
1039 String aPrefix
= String::CreateFromAscii( "private:factory/" );
1040 if ( aPrefix
.Len() == aFact
.Match( aPrefix
) )
1041 aFact
.Erase( 0, aPrefix
.Len() );
1042 USHORT nPos
= aFact
.Search( '?' );
1044 if ( nPos
!= STRING_NOTFOUND
)
1046 aParam
= aFact
.Copy( nPos
, aFact
.Len() );
1047 aFact
.Erase( nPos
, aFact
.Len() );
1050 aFact
.EraseAllChars('4').ToLowerAscii();
1052 // HACK: sometimes a real document service name is given here instead of
1053 // a factory short name. Set return value directly to this service name as fallback
1054 // in case next lines of code does nothing ...
1055 // use rFact instead of normed aFact value !
1056 ::rtl::OUString aServiceName
= rFact
;
1058 if ( aFact
.EqualsAscii("swriter") )
1060 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.text.TextDocument");
1062 else if ( aFact
.EqualsAscii("sweb") || aFact
.EqualsAscii("swriter/web") )
1064 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.text.WebDocument");
1066 else if ( aFact
.EqualsAscii("sglobal") || aFact
.EqualsAscii("swriter/globaldocument") )
1068 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.text.GlobalDocument");
1070 else if ( aFact
.EqualsAscii("scalc") )
1072 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.sheet.SpreadsheetDocument");
1074 else if ( aFact
.EqualsAscii("sdraw") )
1076 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.drawing.DrawingDocument");
1078 else if ( aFact
.EqualsAscii("simpress") )
1080 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.presentation.PresentationDocument");
1082 else if ( aFact
.EqualsAscii("schart") )
1084 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.chart.ChartDocument");
1086 else if ( aFact
.EqualsAscii("smath") )
1088 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.formula.FormulaProperties");
1090 else if ( aFact
.EqualsAscii("sbasic") )
1092 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.script.BasicIDE");
1094 else if ( aFact
.EqualsAscii("sdatabase") )
1096 aServiceName
= ::rtl::OUString::createFromAscii("com.sun.star.sdb.OfficeDatabaseDocument");
1099 return aServiceName
;
1102 SfxObjectShell
* SfxObjectShell::CreateObjectByFactoryName( const String
& rFact
, SfxObjectCreateMode eMode
)
1104 return CreateObject( GetServiceNameFromFactory( rFact
), eMode
);
1108 SfxObjectShell
* SfxObjectShell::CreateObject( const String
& rServiceName
, SfxObjectCreateMode eCreateMode
)
1110 if ( rServiceName
.Len() )
1112 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModel
> xDoc(
1113 ::comphelper::getProcessServiceFactory()->createInstance( rServiceName
), UNO_QUERY
);
1116 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XUnoTunnel
> xObj( xDoc
, UNO_QUERY
);
1117 ::com::sun::star::uno::Sequence
< sal_Int8
> aSeq( SvGlobalName( SFX_GLOBAL_CLASSID
).GetByteSequence() );
1118 sal_Int64 nHandle
= xObj
->getSomething( aSeq
);
1121 SfxObjectShell
* pRet
= reinterpret_cast< SfxObjectShell
* >( sal::static_int_cast
< sal_IntPtr
>( nHandle
));
1122 pRet
->SetCreateMode_Impl( eCreateMode
);
1131 SfxObjectShell
* SfxObjectShell::CreateAndLoadObject( const SfxItemSet
& rSet
, SfxFrame
* pFrame
)
1133 uno::Sequence
< beans::PropertyValue
> aProps
;
1134 TransformItems( SID_OPENDOC
, rSet
, aProps
);
1135 SFX_ITEMSET_ARG(&rSet
, pFileNameItem
, SfxStringItem
, SID_FILE_NAME
, FALSE
);
1136 SFX_ITEMSET_ARG(&rSet
, pTargetItem
, SfxStringItem
, SID_TARGETNAME
, FALSE
);
1137 ::rtl::OUString aURL
;
1138 ::rtl::OUString aTarget
= rtl::OUString::createFromAscii("_blank");
1139 if ( pFileNameItem
)
1140 aURL
= pFileNameItem
->GetValue();
1142 aTarget
= pTargetItem
->GetValue();
1144 uno::Reference
< frame::XComponentLoader
> xLoader
;
1147 xLoader
= uno::Reference
< frame::XComponentLoader
>( pFrame
->GetFrameInterface(), uno::UNO_QUERY
);
1150 xLoader
= uno::Reference
< frame::XComponentLoader
>( comphelper::getProcessServiceFactory()->createInstance(
1151 ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop") ), uno::UNO_QUERY
);
1153 uno::Reference
< lang::XUnoTunnel
> xObj
;
1156 xObj
= uno::Reference
< lang::XUnoTunnel
>( xLoader
->loadComponentFromURL( aURL
, aTarget
, 0, aProps
), uno::UNO_QUERY
);
1158 catch( uno::Exception
& )
1163 ::com::sun::star::uno::Sequence
< sal_Int8
> aSeq( SvGlobalName( SFX_GLOBAL_CLASSID
).GetByteSequence() );
1164 sal_Int64 nHandle
= xObj
->getSomething( aSeq
);
1166 return reinterpret_cast< SfxObjectShell
* >(sal::static_int_cast
< sal_IntPtr
>( nHandle
));