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