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