xref: /trunk/main/sfx2/source/doc/objxtor.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5d119d52dSAndrew Rist  * distributed with this work for additional information
6d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17d119d52dSAndrew Rist  * specific language governing permissions and limitations
18d119d52dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20d119d52dSAndrew Rist  *************************************************************/
21d119d52dSAndrew Rist 
22d119d52dSAndrew 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
208*f750960cSPeter Kovacs         // check flag before entering dtor in order to avoid crash of GCC
209cdf0e10cSrcweir         mpDoc->DoClose();
210cdf0e10cSrcweir }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir TYPEINIT1(SfxObjectShell, SfxShell);
213cdf0e10cSrcweir 
214cdf0e10cSrcweir //--------------------------------------------------------------------
SfxObjectShell_Impl(SfxObjectShell & _rDocShell)215cdf0e10cSrcweir SfxObjectShell_Impl::SfxObjectShell_Impl( SfxObjectShell& _rDocShell )
216cdf0e10cSrcweir     :mpObjectContainer(0)
217cdf0e10cSrcweir     ,pBasicManager( new SfxBasicManagerHolder )
218cdf0e10cSrcweir     ,rDocShell( _rDocShell )
219cdf0e10cSrcweir     ,aMacroMode( *this )
220cdf0e10cSrcweir     ,pProgress( 0)
221cdf0e10cSrcweir     ,nTime()
222cdf0e10cSrcweir     ,nVisualDocumentNumber( USHRT_MAX)
223cdf0e10cSrcweir     ,nDocumentSignatureState( SIGNATURESTATE_UNKNOWN )
224cdf0e10cSrcweir     ,nScriptingSignatureState( SIGNATURESTATE_UNKNOWN )
225cdf0e10cSrcweir     ,bInList( sal_False)
226cdf0e10cSrcweir     ,bClosing( sal_False)
227cdf0e10cSrcweir     ,bIsSaving( sal_False)
228cdf0e10cSrcweir     ,bPasswd( sal_False)
229cdf0e10cSrcweir     ,bIsTmp( sal_False)
230cdf0e10cSrcweir     ,bIsNamedVisible( sal_False)
231cdf0e10cSrcweir     ,bIsTemplate(sal_False)
232cdf0e10cSrcweir     ,bIsAbortingImport ( sal_False)
233cdf0e10cSrcweir     ,bImportDone ( sal_False)
234cdf0e10cSrcweir     ,bInPrepareClose( sal_False )
235cdf0e10cSrcweir     ,bPreparedForClose( sal_False )
236cdf0e10cSrcweir     ,bWaitingForPicklist( sal_True )
237cdf0e10cSrcweir     ,bForbidReload( sal_False )
238cdf0e10cSrcweir     ,bBasicInitialized( sal_False )
239cdf0e10cSrcweir     ,bIsPrintJobCancelable( sal_True )
240cdf0e10cSrcweir     ,bOwnsStorage( sal_True )
241cdf0e10cSrcweir     ,bNoBaseURL( sal_False )
242cdf0e10cSrcweir     ,bInitialized( sal_False )
243cdf0e10cSrcweir     ,bSignatureErrorIsShown( sal_False )
244cdf0e10cSrcweir     ,bModelInitialized( sal_False )
245cdf0e10cSrcweir     ,bPreserveVersions( sal_True )
246cdf0e10cSrcweir     ,m_bMacroSignBroken( sal_False )
247cdf0e10cSrcweir     ,m_bNoBasicCapabilities( sal_False )
248cdf0e10cSrcweir     ,m_bDocRecoverySupport( sal_True )
249cdf0e10cSrcweir     ,bQueryLoadTemplate( sal_True )
250cdf0e10cSrcweir     ,bLoadReadonly( sal_False )
251cdf0e10cSrcweir     ,bUseUserData( sal_True )
252cdf0e10cSrcweir     ,bSaveVersionOnClose( sal_False )
253cdf0e10cSrcweir     ,m_bSharedXMLFlag( sal_False )
254cdf0e10cSrcweir     ,m_bAllowShareControlFileClean( sal_True )
255cdf0e10cSrcweir     ,lErr(ERRCODE_NONE)
256cdf0e10cSrcweir     ,nEventId ( 0)
257cdf0e10cSrcweir     ,pReloadTimer ( 0)
258cdf0e10cSrcweir     ,pMarkData( 0 )
259cdf0e10cSrcweir     ,nLoadedFlags ( SFX_LOADED_ALL )
260cdf0e10cSrcweir     ,nFlagsInProgress( 0 )
261cdf0e10cSrcweir     ,bModalMode( sal_False )
262cdf0e10cSrcweir     ,bRunningMacro( sal_False )
263cdf0e10cSrcweir     ,bReloadAvailable( sal_False )
264cdf0e10cSrcweir     ,nAutoLoadLocks( 0 )
265cdf0e10cSrcweir     ,pModule( 0 )
266cdf0e10cSrcweir     ,eFlags( SFXOBJECTSHELL_UNDEFINED )
267cdf0e10cSrcweir     ,bReadOnlyUI( sal_False )
268cdf0e10cSrcweir     ,bHiddenLockedByAPI( sal_False )
269cdf0e10cSrcweir     ,nStyleFilter( 0 )
270cdf0e10cSrcweir     ,bDisposing( sal_False )
271cdf0e10cSrcweir     ,m_bEnableSetModified( sal_True )
272cdf0e10cSrcweir     ,m_bIsModified( sal_False )
273cdf0e10cSrcweir     ,m_nMapUnit( MAP_100TH_MM )
274cdf0e10cSrcweir     ,m_bCreateTempStor( sal_False )
275cdf0e10cSrcweir     ,m_bIsInit( sal_False )
276cdf0e10cSrcweir     ,m_bIncomplEncrWarnShown( sal_False )
277cdf0e10cSrcweir     ,m_nModifyPasswordHash( 0 )
278cdf0e10cSrcweir     ,m_bModifyPasswordEntered( sal_False )
279cdf0e10cSrcweir {
280cdf0e10cSrcweir     SfxObjectShell* pDoc = &_rDocShell;
281cdf0e10cSrcweir     SfxObjectShellArr_Impl &rArr = SFX_APP()->GetObjectShells_Impl();
282cdf0e10cSrcweir     rArr.C40_INSERT( SfxObjectShell, pDoc, rArr.Count() );
283cdf0e10cSrcweir     bInList = sal_True;
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir //--------------------------------------------------------------------
287cdf0e10cSrcweir 
~SfxObjectShell_Impl()288cdf0e10cSrcweir SfxObjectShell_Impl::~SfxObjectShell_Impl()
289cdf0e10cSrcweir {
290cdf0e10cSrcweir     delete pBasicManager;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir //--------------------------------------------------------------------
294cdf0e10cSrcweir 
SfxObjectShell(const sal_uInt64 i_nCreationFlags)295cdf0e10cSrcweir SfxObjectShell::SfxObjectShell( const sal_uInt64 i_nCreationFlags )
296cdf0e10cSrcweir     :   pImp( new SfxObjectShell_Impl( *this ) )
297cdf0e10cSrcweir     ,   pMedium(0)
298cdf0e10cSrcweir     ,   pStyleSheetPool(0)
299cdf0e10cSrcweir     ,   eCreateMode( ( i_nCreationFlags & SFXMODEL_EMBEDDED_OBJECT ) ? SFX_CREATE_MODE_EMBEDDED : SFX_CREATE_MODE_STANDARD )
300cdf0e10cSrcweir     ,   bHasName( sal_False )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir     DBG_CTOR(SfxObjectShell, 0);
303cdf0e10cSrcweir 
304cdf0e10cSrcweir     const bool bScriptSupport = ( i_nCreationFlags & SFXMODEL_DISABLE_EMBEDDED_SCRIPTS ) == 0;
305cdf0e10cSrcweir     if ( !bScriptSupport )
306cdf0e10cSrcweir         SetHasNoBasic();
307cdf0e10cSrcweir 
308cdf0e10cSrcweir     const bool bDocRecovery = ( i_nCreationFlags & SFXMODEL_DISABLE_DOCUMENT_RECOVERY ) == 0;
309cdf0e10cSrcweir     if ( !bDocRecovery )
310cdf0e10cSrcweir         pImp->m_bDocRecoverySupport = sal_False;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir //--------------------------------------------------------------------
314cdf0e10cSrcweir 
315cdf0e10cSrcweir // initializes a document from a file-description
316cdf0e10cSrcweir 
SfxObjectShell(SfxObjectCreateMode eMode)317cdf0e10cSrcweir SfxObjectShell::SfxObjectShell
318cdf0e10cSrcweir (
319*f750960cSPeter Kovacs     SfxObjectCreateMode eMode   /*  purpose to generate SfxObjectShel:
320cdf0e10cSrcweir 
321cdf0e10cSrcweir                                     SFX_CREATE_MODE_EMBEDDED (default)
322*f750960cSPeter Kovacs                                         as SO-Server from a different document
323cdf0e10cSrcweir 
324cdf0e10cSrcweir                                     SFX_CREATE_MODE_STANDARD,
325*f750960cSPeter Kovacs                                         as normal, self opening document
326cdf0e10cSrcweir 
327cdf0e10cSrcweir                                     SFX_CREATE_MODE_PREVIEW
328*f750960cSPeter Kovacs                                         in order to create a preview, possible
329*f750960cSPeter Kovacs                                         less data is needed
330cdf0e10cSrcweir 
331cdf0e10cSrcweir                                     SFX_CREATE_MODE_ORGANIZER
332*f750960cSPeter Kovacs                                         as a representation in an Organiser
333*f750960cSPeter Kovacs                                         no data needed
334*f750960cSPeter Kovacs                                */
335cdf0e10cSrcweir )
336cdf0e10cSrcweir 
33756b045d0SMatthias Seidel /*  [Description]
338cdf0e10cSrcweir 
339*f750960cSPeter Kovacs     class constructor SfxObjectShell.
340cdf0e10cSrcweir */
341cdf0e10cSrcweir 
342cdf0e10cSrcweir :   pImp( new SfxObjectShell_Impl( *this ) ),
343cdf0e10cSrcweir     pMedium(0),
344cdf0e10cSrcweir     pStyleSheetPool(0),
345cdf0e10cSrcweir     eCreateMode(eMode),
346cdf0e10cSrcweir     bHasName( sal_False )
347cdf0e10cSrcweir {
348cdf0e10cSrcweir     DBG_CTOR(SfxObjectShell, 0);
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir //--------------------------------------------------------------------
352cdf0e10cSrcweir 
353cdf0e10cSrcweir // virtual dtor of typical base-class SfxObjectShell
354cdf0e10cSrcweir 
~SfxObjectShell()355cdf0e10cSrcweir SfxObjectShell::~SfxObjectShell()
356cdf0e10cSrcweir {
357cdf0e10cSrcweir     DBG_DTOR(SfxObjectShell, 0);
358cdf0e10cSrcweir 
359cdf0e10cSrcweir     if ( IsEnableSetModified() )
360cdf0e10cSrcweir         EnableSetModified( sal_False );
361cdf0e10cSrcweir 
362*f750960cSPeter Kovacs     // do not call GetInPlaceObject(). Access to the inheritage path of SfxInternObject
363*f750960cSPeter Kovacs     // is not allowed because of a bug in the compiler
364cdf0e10cSrcweir     SfxObjectShell::Close();
365cdf0e10cSrcweir     pImp->pBaseModel.set( NULL );
366cdf0e10cSrcweir 
367cdf0e10cSrcweir     DELETEX(pImp->pReloadTimer );
368cdf0e10cSrcweir 
369cdf0e10cSrcweir     SfxApplication *pSfxApp = SFX_APP();
370cdf0e10cSrcweir     if ( USHRT_MAX != pImp->nVisualDocumentNumber )
371cdf0e10cSrcweir         pSfxApp->ReleaseIndex(pImp->nVisualDocumentNumber);
372cdf0e10cSrcweir 
37356b045d0SMatthias Seidel     // destroy BasicManager
374cdf0e10cSrcweir     pImp->pBasicManager->reset( NULL );
375cdf0e10cSrcweir 
376cdf0e10cSrcweir     if ( pSfxApp->GetDdeService() )
377cdf0e10cSrcweir         pSfxApp->RemoveDdeTopic( this );
378cdf0e10cSrcweir 
379cdf0e10cSrcweir     pImp->pBaseModel.set( NULL );
380cdf0e10cSrcweir 
381cdf0e10cSrcweir     // don't call GetStorage() here, in case of Load Failure it's possible that a storage was never assigned!
382cdf0e10cSrcweir     if ( pMedium && pMedium->HasStorage_Impl() && pMedium->GetStorage( sal_False ) == pImp->m_xDocStorage )
383cdf0e10cSrcweir         pMedium->CanDisposeStorage_Impl( sal_False );
384cdf0e10cSrcweir 
385cdf0e10cSrcweir     if ( pImp->mpObjectContainer )
386cdf0e10cSrcweir     {
387cdf0e10cSrcweir         pImp->mpObjectContainer->CloseEmbeddedObjects();
388cdf0e10cSrcweir         delete pImp->mpObjectContainer;
389cdf0e10cSrcweir     }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir     if ( pImp->bOwnsStorage && pImp->m_xDocStorage.is() )
392cdf0e10cSrcweir         pImp->m_xDocStorage->dispose();
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     if ( pMedium )
395cdf0e10cSrcweir     {
396cdf0e10cSrcweir         pMedium->CloseAndReleaseStreams_Impl();
397cdf0e10cSrcweir 
398cdf0e10cSrcweir         if ( IsDocShared() )
399cdf0e10cSrcweir             FreeSharedFile();
400cdf0e10cSrcweir 
401cdf0e10cSrcweir         DELETEX( pMedium );
402cdf0e10cSrcweir     }
403cdf0e10cSrcweir 
404cdf0e10cSrcweir     // The removing of the temporary file must be done as the latest step in the document destruction
405cdf0e10cSrcweir     if ( pImp->aTempName.Len() )
406cdf0e10cSrcweir     {
407cdf0e10cSrcweir         String aTmp;
408cdf0e10cSrcweir         ::utl::LocalFileHelper::ConvertPhysicalNameToURL( pImp->aTempName, aTmp );
409cdf0e10cSrcweir         ::utl::UCBContentHelper::Kill( aTmp );
410cdf0e10cSrcweir     }
411cdf0e10cSrcweir 
412cdf0e10cSrcweir     delete pImp;
413cdf0e10cSrcweir }
414cdf0e10cSrcweir 
415cdf0e10cSrcweir //--------------------------------------------------------------------
416cdf0e10cSrcweir 
Stamp_SetPrintCancelState(sal_Bool bState)417cdf0e10cSrcweir void SfxObjectShell::Stamp_SetPrintCancelState(sal_Bool bState)
418cdf0e10cSrcweir {
419cdf0e10cSrcweir     pImp->bIsPrintJobCancelable = bState;
420cdf0e10cSrcweir }
421cdf0e10cSrcweir 
422cdf0e10cSrcweir //--------------------------------------------------------------------
423cdf0e10cSrcweir 
Stamp_GetPrintCancelState() const424cdf0e10cSrcweir sal_Bool SfxObjectShell::Stamp_GetPrintCancelState() const
425cdf0e10cSrcweir {
426cdf0e10cSrcweir     return pImp->bIsPrintJobCancelable;
427cdf0e10cSrcweir }
428cdf0e10cSrcweir 
429cdf0e10cSrcweir //--------------------------------------------------------------------
430cdf0e10cSrcweir 
ViewAssigned()431cdf0e10cSrcweir void SfxObjectShell::ViewAssigned()
432cdf0e10cSrcweir 
43356b045d0SMatthias Seidel /*  [Description]
434cdf0e10cSrcweir 
435*f750960cSPeter Kovacs     This module is called, when a view is assigned
436cdf0e10cSrcweir */
437cdf0e10cSrcweir 
438cdf0e10cSrcweir {
439cdf0e10cSrcweir }
440cdf0e10cSrcweir 
441cdf0e10cSrcweir //--------------------------------------------------------------------
442cdf0e10cSrcweir // closes the Object and all its views
443cdf0e10cSrcweir 
Close()444cdf0e10cSrcweir sal_Bool SfxObjectShell::Close()
445cdf0e10cSrcweir {
446cdf0e10cSrcweir     {DBG_CHKTHIS(SfxObjectShell, 0);}
447cdf0e10cSrcweir     SfxObjectShellRef aRef(this);
448cdf0e10cSrcweir     if ( !pImp->bClosing )
449cdf0e10cSrcweir     {
450*f750960cSPeter Kovacs         // if a process is still running -> dont close
451cdf0e10cSrcweir         if ( !pImp->bDisposing && GetProgress() )
452cdf0e10cSrcweir             return sal_False;
453cdf0e10cSrcweir 
454cdf0e10cSrcweir         pImp->bClosing = sal_True;
455cdf0e10cSrcweir         Reference< util::XCloseable > xCloseable( GetBaseModel(), UNO_QUERY );
456cdf0e10cSrcweir 
457cdf0e10cSrcweir         if ( xCloseable.is() )
458cdf0e10cSrcweir         {
459cdf0e10cSrcweir             try
460cdf0e10cSrcweir             {
461cdf0e10cSrcweir                 xCloseable->close( sal_True );
462cdf0e10cSrcweir             }
463cdf0e10cSrcweir             catch( Exception& )
464cdf0e10cSrcweir             {
465cdf0e10cSrcweir                 pImp->bClosing = sal_False;
466cdf0e10cSrcweir             }
467cdf0e10cSrcweir         }
468cdf0e10cSrcweir 
469cdf0e10cSrcweir         if ( pImp->bClosing )
470cdf0e10cSrcweir         {
471*f750960cSPeter Kovacs             // remove from Document-List
472cdf0e10cSrcweir             SfxApplication *pSfxApp = SFX_APP();
473cdf0e10cSrcweir             SfxObjectShellArr_Impl &rDocs = pSfxApp->GetObjectShells_Impl();
474cdf0e10cSrcweir             const SfxObjectShell *pThis = this;
475cdf0e10cSrcweir             sal_uInt16 nPos = rDocs.GetPos(pThis);
476cdf0e10cSrcweir             if ( nPos < rDocs.Count() )
477cdf0e10cSrcweir                 rDocs.Remove( nPos );
478cdf0e10cSrcweir             pImp->bInList = sal_False;
479cdf0e10cSrcweir         }
480cdf0e10cSrcweir     }
481cdf0e10cSrcweir 
482cdf0e10cSrcweir     return sal_True;
483cdf0e10cSrcweir }
484cdf0e10cSrcweir 
485cdf0e10cSrcweir //--------------------------------------------------------------------
486cdf0e10cSrcweir 
487cdf0e10cSrcweir // returns a pointer the first SfxDocument of specified type
488cdf0e10cSrcweir 
GetFirst(const TypeId * pType,sal_Bool bOnlyVisible)489cdf0e10cSrcweir SfxObjectShell* SfxObjectShell::GetFirst
490cdf0e10cSrcweir (
491cdf0e10cSrcweir     const TypeId* pType ,
492cdf0e10cSrcweir     sal_Bool            bOnlyVisible
493cdf0e10cSrcweir )
494cdf0e10cSrcweir {
495cdf0e10cSrcweir     SfxObjectShellArr_Impl &rDocs = SFX_APP()->GetObjectShells_Impl();
496cdf0e10cSrcweir 
49786e1cf34SPedro Giffuni     // search for a SfxDocument of the specified type
498cdf0e10cSrcweir     for ( sal_uInt16 nPos = 0; nPos < rDocs.Count(); ++nPos )
499cdf0e10cSrcweir     {
500cdf0e10cSrcweir         SfxObjectShell* pSh = rDocs.GetObject( nPos );
501cdf0e10cSrcweir         if ( bOnlyVisible && pSh->IsPreview() && pSh->IsReadOnly() )
502cdf0e10cSrcweir             continue;
503cdf0e10cSrcweir 
504cdf0e10cSrcweir         if ( ( !pType || pSh->IsA(*pType) ) &&
505cdf0e10cSrcweir              ( !bOnlyVisible || SfxViewFrame::GetFirst( pSh, sal_True )))
506cdf0e10cSrcweir             return pSh;
507cdf0e10cSrcweir     }
508cdf0e10cSrcweir 
509cdf0e10cSrcweir     return 0;
510cdf0e10cSrcweir }
511cdf0e10cSrcweir //--------------------------------------------------------------------
512cdf0e10cSrcweir 
513cdf0e10cSrcweir // returns a pointer to the next SfxDocument of specified type behind *pDoc
514cdf0e10cSrcweir 
GetNext(const SfxObjectShell & rPrev,const TypeId * pType,sal_Bool bOnlyVisible)515cdf0e10cSrcweir SfxObjectShell* SfxObjectShell::GetNext
516cdf0e10cSrcweir (
517cdf0e10cSrcweir     const SfxObjectShell&   rPrev,
518cdf0e10cSrcweir     const TypeId*           pType,
519cdf0e10cSrcweir     sal_Bool                    bOnlyVisible
520cdf0e10cSrcweir )
521cdf0e10cSrcweir {
522cdf0e10cSrcweir     SfxObjectShellArr_Impl &rDocs = SFX_APP()->GetObjectShells_Impl();
523cdf0e10cSrcweir 
524cdf0e10cSrcweir     // refind the specified predecessor
525cdf0e10cSrcweir     sal_uInt16 nPos;
526cdf0e10cSrcweir     for ( nPos = 0; nPos < rDocs.Count(); ++nPos )
527cdf0e10cSrcweir         if ( rDocs.GetObject(nPos) == &rPrev )
528cdf0e10cSrcweir             break;
529cdf0e10cSrcweir 
530cdf0e10cSrcweir     // search for the next SfxDocument of the specified type
531cdf0e10cSrcweir     for ( ++nPos; nPos < rDocs.Count(); ++nPos )
532cdf0e10cSrcweir     {
533cdf0e10cSrcweir         SfxObjectShell* pSh = rDocs.GetObject( nPos );
534cdf0e10cSrcweir         if ( bOnlyVisible && pSh->IsPreview() && pSh->IsReadOnly() )
535cdf0e10cSrcweir             continue;
536cdf0e10cSrcweir 
537cdf0e10cSrcweir         if ( ( !pType || pSh->IsA(*pType) ) &&
538cdf0e10cSrcweir              ( !bOnlyVisible || SfxViewFrame::GetFirst( pSh, sal_True )))
539cdf0e10cSrcweir             return pSh;
540cdf0e10cSrcweir     }
541cdf0e10cSrcweir     return 0;
542cdf0e10cSrcweir }
543cdf0e10cSrcweir 
544cdf0e10cSrcweir //--------------------------------------------------------------------
545cdf0e10cSrcweir 
Current()546cdf0e10cSrcweir SfxObjectShell* SfxObjectShell::Current()
547cdf0e10cSrcweir {
548cdf0e10cSrcweir     SfxViewFrame *pFrame = SfxViewFrame::Current();
549cdf0e10cSrcweir     return pFrame ? pFrame->GetObjectShell() : 0;
550cdf0e10cSrcweir }
551cdf0e10cSrcweir 
552cdf0e10cSrcweir //-------------------------------------------------------------------------
553cdf0e10cSrcweir 
IsInPrepareClose() const554cdf0e10cSrcweir sal_Bool SfxObjectShell::IsInPrepareClose() const
555cdf0e10cSrcweir {
556cdf0e10cSrcweir     return pImp->bInPrepareClose;
557cdf0e10cSrcweir }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir //------------------------------------------------------------------------
560cdf0e10cSrcweir 
561cdf0e10cSrcweir struct BoolEnv_Impl
562cdf0e10cSrcweir {
563cdf0e10cSrcweir     SfxObjectShell_Impl* pImp;
BoolEnv_ImplBoolEnv_Impl564cdf0e10cSrcweir     BoolEnv_Impl( SfxObjectShell_Impl* pImpP) : pImp( pImpP )
565cdf0e10cSrcweir     { pImpP->bInPrepareClose = sal_True; }
~BoolEnv_ImplBoolEnv_Impl566cdf0e10cSrcweir     ~BoolEnv_Impl() { pImp->bInPrepareClose = sal_False; }
567cdf0e10cSrcweir };
568cdf0e10cSrcweir 
569cdf0e10cSrcweir 
PrepareClose(sal_Bool bUI,sal_Bool bForBrowsing)570cdf0e10cSrcweir sal_uInt16 SfxObjectShell::PrepareClose
571cdf0e10cSrcweir (
572cdf0e10cSrcweir     sal_Bool    bUI,        // sal_True: Dialoge etc. erlaubt, sal_False: silent-mode
573cdf0e10cSrcweir     sal_Bool    bForBrowsing
574cdf0e10cSrcweir )
575cdf0e10cSrcweir {
576cdf0e10cSrcweir     if( pImp->bInPrepareClose || pImp->bPreparedForClose )
577cdf0e10cSrcweir         return sal_True;
578cdf0e10cSrcweir     BoolEnv_Impl aBoolEnv( pImp );
579cdf0e10cSrcweir 
580cdf0e10cSrcweir     // DocModalDialog?
581cdf0e10cSrcweir     if ( IsInModalMode() )
582cdf0e10cSrcweir         return sal_False;
583cdf0e10cSrcweir 
584cdf0e10cSrcweir     SfxViewFrame* pFirst = SfxViewFrame::GetFirst( this );
585cdf0e10cSrcweir     if( pFirst && !pFirst->GetFrame().PrepareClose_Impl( bUI, bForBrowsing ) )
586cdf0e10cSrcweir         return sal_False;
587cdf0e10cSrcweir 
588cdf0e10cSrcweir     // prepare views for closing
589cdf0e10cSrcweir     for ( SfxViewFrame* pFrm = SfxViewFrame::GetFirst( this );
590cdf0e10cSrcweir           pFrm; pFrm = SfxViewFrame::GetNext( *pFrm, this ) )
591cdf0e10cSrcweir     {
592cdf0e10cSrcweir         DBG_ASSERT(pFrm->GetViewShell(),"KeineShell");
593cdf0e10cSrcweir         if ( pFrm->GetViewShell() )
594cdf0e10cSrcweir         {
595cdf0e10cSrcweir             sal_uInt16 nRet = pFrm->GetViewShell()->PrepareClose( bUI, bForBrowsing );
596cdf0e10cSrcweir             if ( nRet != sal_True )
597cdf0e10cSrcweir                 return nRet;
598cdf0e10cSrcweir         }
599cdf0e10cSrcweir     }
600cdf0e10cSrcweir 
601cdf0e10cSrcweir     SfxApplication *pSfxApp = SFX_APP();
602cdf0e10cSrcweir     pSfxApp->NotifyEvent( SfxEventHint(SFX_EVENT_PREPARECLOSEDOC, GlobalEventConfig::GetEventName(STR_EVENT_PREPARECLOSEDOC), this) );
603cdf0e10cSrcweir 
604cdf0e10cSrcweir     if( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
605cdf0e10cSrcweir     {
606cdf0e10cSrcweir         pImp->bPreparedForClose = sal_True;
607cdf0e10cSrcweir         return sal_True;
608cdf0e10cSrcweir     }
609cdf0e10cSrcweir 
610*f750960cSPeter Kovacs     // if applicable ask if save should be executed
611*f750960cSPeter Kovacs     // ask only for visible documents
612cdf0e10cSrcweir     SfxViewFrame *pFrame = SfxObjectShell::Current() == this
613cdf0e10cSrcweir         ? SfxViewFrame::Current() : SfxViewFrame::GetFirst( this );
614cdf0e10cSrcweir 
615cdf0e10cSrcweir     sal_Bool bClose = sal_False;
616cdf0e10cSrcweir     if ( bUI && IsModified() && pFrame )
617cdf0e10cSrcweir     {
618*f750960cSPeter Kovacs         //restore minimized
619cdf0e10cSrcweir         SfxFrame& rTop = pFrame->GetTopFrame();
620cdf0e10cSrcweir         SfxViewFrame::SetViewFrame( rTop.GetCurrentViewFrame() );
621cdf0e10cSrcweir         pFrame->GetFrame().Appear();
622cdf0e10cSrcweir 
623*f750960cSPeter Kovacs         // ask for save
624cdf0e10cSrcweir         short nRet = RET_YES;
625cdf0e10cSrcweir         //TODO/CLEANUP
62656b045d0SMatthias Seidel         //do we still need UI=2 ?
627cdf0e10cSrcweir         //if( SfxApplication::IsPlugin() == sal_False || bUI == 2 )
628cdf0e10cSrcweir         {
629cdf0e10cSrcweir             //initiate help agent to inform about "print modifies the document"
630cdf0e10cSrcweir             SvtPrintWarningOptions aPrintOptions;
631cdf0e10cSrcweir             if (aPrintOptions.IsModifyDocumentOnPrintingAllowed() &&
632cdf0e10cSrcweir                 HasName() && getDocProperties()->getPrintDate().Month > 0)
633cdf0e10cSrcweir             {
634cdf0e10cSrcweir                 SfxHelp::OpenHelpAgent( &pFirst->GetFrame(), HID_CLOSE_WARNING );
635cdf0e10cSrcweir             }
636cdf0e10cSrcweir             const Reference< XTitle > xTitle( *pImp->pBaseModel.get(), UNO_QUERY_THROW );
637cdf0e10cSrcweir             const ::rtl::OUString     sTitle = xTitle->getTitle ();
638cdf0e10cSrcweir             nRet = ExecuteQuerySaveDocument(&pFrame->GetWindow(),sTitle);
639cdf0e10cSrcweir         }
640cdf0e10cSrcweir         /*HACK for plugin::destroy()*/
641cdf0e10cSrcweir 
642cdf0e10cSrcweir         if ( RET_YES == nRet )
643cdf0e10cSrcweir         {
644*f750960cSPeter Kovacs             // save by Dispatcher
645cdf0e10cSrcweir             const SfxPoolItem *pPoolItem;
646cdf0e10cSrcweir             if ( IsSaveVersionOnClose() )
647cdf0e10cSrcweir             {
648cdf0e10cSrcweir                 SfxStringItem aItem( SID_DOCINFO_COMMENTS, String( SfxResId( STR_AUTOMATICVERSION ) ) );
649cdf0e10cSrcweir                 SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI );
650cdf0e10cSrcweir                 const SfxPoolItem* ppArgs[] = { &aItem, &aWarnItem, 0 };
651cdf0e10cSrcweir                 pPoolItem = pFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, ppArgs );
652cdf0e10cSrcweir             }
653cdf0e10cSrcweir             else
654cdf0e10cSrcweir             {
655cdf0e10cSrcweir                 SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI );
656cdf0e10cSrcweir                 const SfxPoolItem* ppArgs[] = { &aWarnItem, 0 };
657cdf0e10cSrcweir                 pPoolItem = pFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, ppArgs );
658cdf0e10cSrcweir             }
659cdf0e10cSrcweir 
660cdf0e10cSrcweir             if ( !pPoolItem || pPoolItem->ISA(SfxVoidItem) || ( pPoolItem->ISA(SfxBoolItem) && !( (const SfxBoolItem*) pPoolItem )->GetValue() ) )
661cdf0e10cSrcweir                 return sal_False;
662cdf0e10cSrcweir             else
663cdf0e10cSrcweir                 bClose = sal_True;
664cdf0e10cSrcweir         }
665cdf0e10cSrcweir         else if ( RET_CANCEL == nRet )
66656b045d0SMatthias Seidel             // canceled
667cdf0e10cSrcweir             return sal_False;
668cdf0e10cSrcweir         else if ( RET_NEWTASK == nRet )
669cdf0e10cSrcweir         {
670cdf0e10cSrcweir             return RET_NEWTASK;
671cdf0e10cSrcweir         }
672cdf0e10cSrcweir         else
673cdf0e10cSrcweir         {
674*f750960cSPeter Kovacs             // At No selection don't loose information
675cdf0e10cSrcweir             bClose = sal_True;
676cdf0e10cSrcweir         }
677cdf0e10cSrcweir     }
678cdf0e10cSrcweir 
679cdf0e10cSrcweir     pImp->bPreparedForClose = sal_True;
680cdf0e10cSrcweir     return sal_True;
681cdf0e10cSrcweir }
682cdf0e10cSrcweir 
683cdf0e10cSrcweir //--------------------------------------------------------------------
684cdf0e10cSrcweir namespace
685cdf0e10cSrcweir {
lcl_getBasicManagerForDocument(const SfxObjectShell & _rDocument)686cdf0e10cSrcweir     static BasicManager* lcl_getBasicManagerForDocument( const SfxObjectShell& _rDocument )
687cdf0e10cSrcweir     {
688cdf0e10cSrcweir         if ( !_rDocument.Get_Impl()->m_bNoBasicCapabilities )
689cdf0e10cSrcweir         {
690cdf0e10cSrcweir             if ( !_rDocument.Get_Impl()->bBasicInitialized )
691cdf0e10cSrcweir                 const_cast< SfxObjectShell& >( _rDocument ).InitBasicManager_Impl();
692cdf0e10cSrcweir             return _rDocument.Get_Impl()->pBasicManager->get();
693cdf0e10cSrcweir         }
694cdf0e10cSrcweir 
695cdf0e10cSrcweir         // assume we do not have Basic ourself, but we can refer to another
696cdf0e10cSrcweir         // document which does (by our model's XScriptInvocationContext::getScriptContainer).
697cdf0e10cSrcweir         // In this case, we return the BasicManager of this other document.
698cdf0e10cSrcweir 
699cdf0e10cSrcweir         OSL_ENSURE( !Reference< XEmbeddedScripts >( _rDocument.GetModel(), UNO_QUERY ).is(),
700cdf0e10cSrcweir             "lcl_getBasicManagerForDocument: inconsistency: no Basic, but an XEmbeddedScripts?" );
701cdf0e10cSrcweir         Reference< XModel > xForeignDocument;
702cdf0e10cSrcweir         Reference< XScriptInvocationContext > xContext( _rDocument.GetModel(), UNO_QUERY );
703cdf0e10cSrcweir         if ( xContext.is() )
704cdf0e10cSrcweir         {
705cdf0e10cSrcweir             xForeignDocument.set( xContext->getScriptContainer(), UNO_QUERY );
706cdf0e10cSrcweir             OSL_ENSURE( xForeignDocument.is() && xForeignDocument != _rDocument.GetModel(),
707cdf0e10cSrcweir                 "lcl_getBasicManagerForDocument: no Basic, but providing ourself as script container?" );
708cdf0e10cSrcweir         }
709cdf0e10cSrcweir 
710cdf0e10cSrcweir         BasicManager* pBasMgr = NULL;
711cdf0e10cSrcweir         if ( xForeignDocument.is() )
712cdf0e10cSrcweir             pBasMgr = ::basic::BasicManagerRepository::getDocumentBasicManager( xForeignDocument );
713cdf0e10cSrcweir 
714cdf0e10cSrcweir         return pBasMgr;
715cdf0e10cSrcweir     }
716cdf0e10cSrcweir }
717cdf0e10cSrcweir 
718cdf0e10cSrcweir //--------------------------------------------------------------------
719cdf0e10cSrcweir 
GetBasicManager() const720cdf0e10cSrcweir BasicManager* SfxObjectShell::GetBasicManager() const
721cdf0e10cSrcweir {
722cdf0e10cSrcweir     BasicManager* pBasMgr = lcl_getBasicManagerForDocument( *this );
723cdf0e10cSrcweir     if ( !pBasMgr )
724cdf0e10cSrcweir         pBasMgr = SFX_APP()->GetBasicManager();
725cdf0e10cSrcweir     return pBasMgr;
726cdf0e10cSrcweir }
727cdf0e10cSrcweir 
728cdf0e10cSrcweir //--------------------------------------------------------------------
729cdf0e10cSrcweir 
SetHasNoBasic()730cdf0e10cSrcweir void SfxObjectShell::SetHasNoBasic()
731cdf0e10cSrcweir {
732cdf0e10cSrcweir     pImp->m_bNoBasicCapabilities = sal_True;
733cdf0e10cSrcweir }
734cdf0e10cSrcweir 
735cdf0e10cSrcweir //--------------------------------------------------------------------
736cdf0e10cSrcweir 
HasBasic() const737cdf0e10cSrcweir sal_Bool SfxObjectShell::HasBasic() const
738cdf0e10cSrcweir {
739cdf0e10cSrcweir     if ( pImp->m_bNoBasicCapabilities )
740cdf0e10cSrcweir         return sal_False;
741cdf0e10cSrcweir 
742cdf0e10cSrcweir     if ( !pImp->bBasicInitialized )
743cdf0e10cSrcweir         const_cast< SfxObjectShell* >( this )->InitBasicManager_Impl();
744cdf0e10cSrcweir 
745cdf0e10cSrcweir     return pImp->pBasicManager->isValid();
746cdf0e10cSrcweir }
747cdf0e10cSrcweir 
748cdf0e10cSrcweir //--------------------------------------------------------------------
749cdf0e10cSrcweir namespace
750cdf0e10cSrcweir {
751cdf0e10cSrcweir     const Reference< XLibraryContainer >&
lcl_getOrCreateLibraryContainer(bool _bScript,Reference<XLibraryContainer> & _rxContainer,const Reference<XModel> & _rxDocument)752cdf0e10cSrcweir     lcl_getOrCreateLibraryContainer( bool _bScript, Reference< XLibraryContainer >& _rxContainer,
753cdf0e10cSrcweir         const Reference< XModel >& _rxDocument )
754cdf0e10cSrcweir     {
755cdf0e10cSrcweir         if ( !_rxContainer.is() )
756cdf0e10cSrcweir         {
757cdf0e10cSrcweir             try
758cdf0e10cSrcweir             {
759cdf0e10cSrcweir                 Reference< XStorageBasedDocument > xStorageDoc( _rxDocument, UNO_QUERY );
760cdf0e10cSrcweir                 const Reference< XComponentContext > xContext(
761cdf0e10cSrcweir                     ::comphelper::getProcessComponentContext() );
762cdf0e10cSrcweir                 _rxContainer.set (   _bScript
763cdf0e10cSrcweir                                 ?   DocumentScriptLibraryContainer::create(
764cdf0e10cSrcweir                                         xContext, xStorageDoc )
765cdf0e10cSrcweir                                 :   DocumentDialogLibraryContainer::create(
766cdf0e10cSrcweir                                         xContext, xStorageDoc )
767cdf0e10cSrcweir                                 ,   UNO_QUERY_THROW );
768cdf0e10cSrcweir             }
769cdf0e10cSrcweir             catch( const Exception& )
770cdf0e10cSrcweir             {
771cdf0e10cSrcweir                 DBG_UNHANDLED_EXCEPTION();
772cdf0e10cSrcweir             }
773cdf0e10cSrcweir         }
774cdf0e10cSrcweir         return _rxContainer;
775cdf0e10cSrcweir     }
776cdf0e10cSrcweir }
777cdf0e10cSrcweir 
778cdf0e10cSrcweir //--------------------------------------------------------------------
779cdf0e10cSrcweir 
GetDialogContainer()780cdf0e10cSrcweir Reference< XLibraryContainer > SfxObjectShell::GetDialogContainer()
781cdf0e10cSrcweir {
782cdf0e10cSrcweir     if ( !pImp->m_bNoBasicCapabilities )
783cdf0e10cSrcweir         return lcl_getOrCreateLibraryContainer( false, pImp->xDialogLibraries, GetModel() );
784cdf0e10cSrcweir 
785cdf0e10cSrcweir     BasicManager* pBasMgr = lcl_getBasicManagerForDocument( *this );
786cdf0e10cSrcweir     if ( pBasMgr )
787cdf0e10cSrcweir         return pBasMgr->GetDialogLibraryContainer().get();
788cdf0e10cSrcweir 
789cdf0e10cSrcweir     OSL_ENSURE( false, "SfxObjectShell::GetDialogContainer: falling back to the application - is this really expected here?" );
790cdf0e10cSrcweir     return SFX_APP()->GetDialogContainer();
791cdf0e10cSrcweir }
792cdf0e10cSrcweir 
793cdf0e10cSrcweir //--------------------------------------------------------------------
794cdf0e10cSrcweir 
GetBasicContainer()795cdf0e10cSrcweir Reference< XLibraryContainer > SfxObjectShell::GetBasicContainer()
796cdf0e10cSrcweir {
797cdf0e10cSrcweir     if ( !pImp->m_bNoBasicCapabilities )
798cdf0e10cSrcweir         return lcl_getOrCreateLibraryContainer( true, pImp->xBasicLibraries, GetModel() );
799cdf0e10cSrcweir 
800cdf0e10cSrcweir     BasicManager* pBasMgr = lcl_getBasicManagerForDocument( *this );
801cdf0e10cSrcweir     if ( pBasMgr )
802cdf0e10cSrcweir         return pBasMgr->GetScriptLibraryContainer().get();
803cdf0e10cSrcweir 
804cdf0e10cSrcweir     OSL_ENSURE( false, "SfxObjectShell::GetBasicContainer: falling back to the application - is this really expected here?" );
805cdf0e10cSrcweir     return SFX_APP()->GetBasicContainer();
806cdf0e10cSrcweir }
807cdf0e10cSrcweir 
808cdf0e10cSrcweir //--------------------------------------------------------------------
809cdf0e10cSrcweir 
GetBasic() const810cdf0e10cSrcweir StarBASIC* SfxObjectShell::GetBasic() const
811cdf0e10cSrcweir {
812cdf0e10cSrcweir     return GetBasicManager()->GetLib(0);
813cdf0e10cSrcweir }
814cdf0e10cSrcweir 
815cdf0e10cSrcweir //--------------------------------------------------------------------
816cdf0e10cSrcweir 
InitBasicManager_Impl()817cdf0e10cSrcweir void SfxObjectShell::InitBasicManager_Impl()
81856b045d0SMatthias Seidel /*  [Description]
819cdf0e10cSrcweir 
820cdf0e10cSrcweir     creates a document's BasicManager and loads it, if we are already based on
821cdf0e10cSrcweir     a storage.
822cdf0e10cSrcweir 
82356b045d0SMatthias Seidel     [Note]
824cdf0e10cSrcweir 
825*f750960cSPeter Kovacs     This method must be called with overloaded
826*f750960cSPeter Kovacs         <SvPersist::Load()>    (with pStor from Parameter from Load())
827*f750960cSPeter Kovacs     and <SvPersist::InitNew()> (with pStor = 0)
828cdf0e10cSrcweir */
829cdf0e10cSrcweir 
830cdf0e10cSrcweir {
831*f750960cSPeter Kovacs     /*  #163556# (DR) - Handling of recursive calls while creating the Bacic (shouldn't that be Basic?)
832cdf0e10cSrcweir         manager.
833cdf0e10cSrcweir 
834cdf0e10cSrcweir         It is possible that (while creating the Basic manager) the code that
835cdf0e10cSrcweir         imports the Basic storage wants to access the Basic manager again.
836cdf0e10cSrcweir         Especially in VBA compatibility mode, there is code that wants to
837cdf0e10cSrcweir         access the "VBA Globals" object which is stored as global UNO constant
838cdf0e10cSrcweir         in the Basic manager.
839cdf0e10cSrcweir 
840cdf0e10cSrcweir         To achieve correct handling of the recursive calls of this function
841cdf0e10cSrcweir         from lcl_getBasicManagerForDocument(), the implementation of the
842cdf0e10cSrcweir         function BasicManagerRepository::getDocumentBasicManager() has been
843cdf0e10cSrcweir         changed to return the Basic manager currently under construction, when
844cdf0e10cSrcweir         called repeatedly.
845cdf0e10cSrcweir 
846cdf0e10cSrcweir         The variable pImp->bBasicInitialized will be set to sal_True after
847cdf0e10cSrcweir         construction now, to ensure that the recursive call of the function
848cdf0e10cSrcweir         lcl_getBasicManagerForDocument() will be routed into this function too.
849cdf0e10cSrcweir 
850cdf0e10cSrcweir         Calling BasicManagerHolder::reset() twice is not a big problem, as it
851cdf0e10cSrcweir         does not take ownership but stores only the raw pointer. Owner of all
852cdf0e10cSrcweir         Basic managers is the global BasicManagerRepository instance.
853cdf0e10cSrcweir      */
854cdf0e10cSrcweir     DBG_ASSERT( !pImp->bBasicInitialized && !pImp->pBasicManager->isValid(), "Lokaler BasicManager bereits vorhanden");
855cdf0e10cSrcweir     pImp->pBasicManager->reset( BasicManagerRepository::getDocumentBasicManager( GetModel() ) );
856cdf0e10cSrcweir     DBG_ASSERT( pImp->pBasicManager->isValid(), "SfxObjectShell::InitBasicManager_Impl: did not get a BasicManager!" );
857cdf0e10cSrcweir     pImp->bBasicInitialized = sal_True;
858cdf0e10cSrcweir }
859cdf0e10cSrcweir 
860cdf0e10cSrcweir //--------------------------------------------------------------------
861cdf0e10cSrcweir 
Count()862cdf0e10cSrcweir sal_uInt16 SfxObjectShell::Count()
863cdf0e10cSrcweir {
864cdf0e10cSrcweir     return SFX_APP()->GetObjectShells_Impl().Count();
865cdf0e10cSrcweir }
866cdf0e10cSrcweir 
867cdf0e10cSrcweir //--------------------------------------------------------------------
868cdf0e10cSrcweir 
DoClose()869cdf0e10cSrcweir sal_Bool SfxObjectShell::DoClose()
870cdf0e10cSrcweir {
871cdf0e10cSrcweir     return Close();
872cdf0e10cSrcweir }
873cdf0e10cSrcweir 
874cdf0e10cSrcweir //--------------------------------------------------------------------
875cdf0e10cSrcweir 
GetObjectShell()876cdf0e10cSrcweir SfxObjectShell* SfxObjectShell::GetObjectShell()
877cdf0e10cSrcweir {
878cdf0e10cSrcweir     return this;
879cdf0e10cSrcweir }
880cdf0e10cSrcweir 
881cdf0e10cSrcweir //--------------------------------------------------------------------
882cdf0e10cSrcweir 
GetEventNames()883cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SfxObjectShell::GetEventNames()
884cdf0e10cSrcweir {
885cdf0e10cSrcweir     static uno::Sequence< ::rtl::OUString >* pEventNameContainer = NULL;
886cdf0e10cSrcweir 
887cdf0e10cSrcweir     if ( !pEventNameContainer )
888cdf0e10cSrcweir     {
889cdf0e10cSrcweir         ::vos::OGuard aGuard( Application::GetSolarMutex() );
890cdf0e10cSrcweir         if ( !pEventNameContainer )
891cdf0e10cSrcweir         {
892cdf0e10cSrcweir             static uno::Sequence< ::rtl::OUString > aEventNameContainer = GlobalEventConfig().getElementNames();
893cdf0e10cSrcweir             pEventNameContainer = &aEventNameContainer;
894cdf0e10cSrcweir         }
895cdf0e10cSrcweir     }
896cdf0e10cSrcweir 
897cdf0e10cSrcweir     return *pEventNameContainer;
898cdf0e10cSrcweir }
899cdf0e10cSrcweir 
900cdf0e10cSrcweir //--------------------------------------------------------------------
901cdf0e10cSrcweir 
GetModel() const902cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SfxObjectShell::GetModel() const
903cdf0e10cSrcweir {
904cdf0e10cSrcweir     return GetBaseModel();
905cdf0e10cSrcweir }
906cdf0e10cSrcweir 
SetBaseModel(SfxBaseModel * pModel)907cdf0e10cSrcweir void SfxObjectShell::SetBaseModel( SfxBaseModel* pModel )
908cdf0e10cSrcweir {
909cdf0e10cSrcweir     OSL_ENSURE( !pImp->pBaseModel.is() || pModel == NULL, "Model already set!" );
910cdf0e10cSrcweir     pImp->pBaseModel.set( pModel );
911cdf0e10cSrcweir     if ( pImp->pBaseModel.is() )
912cdf0e10cSrcweir     {
913cdf0e10cSrcweir         pImp->pBaseModel->addCloseListener( new SfxModelListener_Impl(this) );
914cdf0e10cSrcweir     }
915cdf0e10cSrcweir }
916cdf0e10cSrcweir 
917cdf0e10cSrcweir //--------------------------------------------------------------------
918cdf0e10cSrcweir 
GetBaseModel() const919cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > SfxObjectShell::GetBaseModel() const
920cdf0e10cSrcweir {
921cdf0e10cSrcweir     return pImp->pBaseModel.get();
922cdf0e10cSrcweir }
923cdf0e10cSrcweir /* -----------------------------10.09.2001 15:56------------------------------
924cdf0e10cSrcweir 
925cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
SetAutoStyleFilterIndex(sal_uInt16 nSet)926cdf0e10cSrcweir void SfxObjectShell::SetAutoStyleFilterIndex(sal_uInt16 nSet)
927cdf0e10cSrcweir {
928cdf0e10cSrcweir     pImp->nStyleFilter = nSet;
929cdf0e10cSrcweir }
930cdf0e10cSrcweir 
GetAutoStyleFilterIndex()931cdf0e10cSrcweir sal_uInt16 SfxObjectShell::GetAutoStyleFilterIndex()
932cdf0e10cSrcweir {
933cdf0e10cSrcweir     return pImp->nStyleFilter;
934cdf0e10cSrcweir }
935cdf0e10cSrcweir 
936cdf0e10cSrcweir 
SetCurrentComponent(const Reference<XInterface> & _rxComponent)937cdf0e10cSrcweir void SfxObjectShell::SetCurrentComponent( const Reference< XInterface >& _rxComponent )
938cdf0e10cSrcweir {
939cdf0e10cSrcweir     Reference< XInterface > xOldCurrentComp(s_xCurrentComponent);
940cdf0e10cSrcweir     if ( _rxComponent == xOldCurrentComp )
941cdf0e10cSrcweir         // nothing to do
942cdf0e10cSrcweir         return;
943cdf0e10cSrcweir     // note that "_rxComponent.get() == s_xCurrentComponent.get().get()" is /sufficient/, but not
944cdf0e10cSrcweir     // /required/ for "_rxComponent == s_xCurrentComponent.get()".
945cdf0e10cSrcweir     // In other words, it's still possible that we here do something which is not necessary,
946cdf0e10cSrcweir     // but we should have filtered quite some unnecessary calls already.
947cdf0e10cSrcweir 
948cdf0e10cSrcweir     BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
949cdf0e10cSrcweir     s_xCurrentComponent = _rxComponent;
950cdf0e10cSrcweir     if ( pAppMgr )
951cdf0e10cSrcweir     {
952cdf0e10cSrcweir         // set "ThisComponent" for Basic
953cdf0e10cSrcweir         pAppMgr->SetGlobalUNOConstant( "ThisComponent", Any( _rxComponent ) );
954cdf0e10cSrcweir 
955cdf0e10cSrcweir         // set new current component for VBA compatibility
956cdf0e10cSrcweir         if ( _rxComponent.is() )
957cdf0e10cSrcweir         {
958cdf0e10cSrcweir             ::rtl::OString aVBAConstName = lclGetVBAGlobalConstName( _rxComponent );
959cdf0e10cSrcweir             if ( aVBAConstName.getLength() > 0 )
960cdf0e10cSrcweir             {
961cdf0e10cSrcweir                 pAppMgr->SetGlobalUNOConstant( aVBAConstName.getStr(), Any( _rxComponent ) );
962cdf0e10cSrcweir                 s_aRegisteredVBAConstants[ _rxComponent.get() ] = aVBAConstName;
963cdf0e10cSrcweir             }
964cdf0e10cSrcweir         }
965cdf0e10cSrcweir         // no new component passed -> remove last registered VBA component
966cdf0e10cSrcweir         else if ( xOldCurrentComp.is() )
967cdf0e10cSrcweir         {
968cdf0e10cSrcweir             ::rtl::OString aVBAConstName = lclGetVBAGlobalConstName( xOldCurrentComp );
969cdf0e10cSrcweir             if ( aVBAConstName.getLength() > 0 )
970cdf0e10cSrcweir             {
971cdf0e10cSrcweir                 pAppMgr->SetGlobalUNOConstant( aVBAConstName.getStr(), Any( Reference< XInterface >() ) );
972cdf0e10cSrcweir                 s_aRegisteredVBAConstants.erase( xOldCurrentComp.get() );
973cdf0e10cSrcweir             }
974cdf0e10cSrcweir         }
975cdf0e10cSrcweir     }
976cdf0e10cSrcweir }
977cdf0e10cSrcweir 
GetCurrentComponent()978cdf0e10cSrcweir Reference< XInterface > SfxObjectShell::GetCurrentComponent()
979cdf0e10cSrcweir {
980cdf0e10cSrcweir     return s_xCurrentComponent;
981cdf0e10cSrcweir }
982cdf0e10cSrcweir 
983cdf0e10cSrcweir 
GetServiceNameFromFactory(const String & rFact)984cdf0e10cSrcweir String SfxObjectShell::GetServiceNameFromFactory( const String& rFact )
985cdf0e10cSrcweir {
986cdf0e10cSrcweir     //! Remove everything behind name!
987cdf0e10cSrcweir     String aFact( rFact );
988cdf0e10cSrcweir     String aPrefix = String::CreateFromAscii( "private:factory/" );
989cdf0e10cSrcweir     if ( aPrefix.Len() == aFact.Match( aPrefix ) )
990cdf0e10cSrcweir         aFact.Erase( 0, aPrefix.Len() );
991cdf0e10cSrcweir     sal_uInt16 nPos = aFact.Search( '?' );
992cdf0e10cSrcweir     String aParam;
993cdf0e10cSrcweir     if ( nPos != STRING_NOTFOUND )
994cdf0e10cSrcweir     {
995cdf0e10cSrcweir         aParam = aFact.Copy( nPos, aFact.Len() );
996cdf0e10cSrcweir         aFact.Erase( nPos, aFact.Len() );
997cdf0e10cSrcweir         aParam.Erase(0,1);
998cdf0e10cSrcweir     }
999cdf0e10cSrcweir     aFact.EraseAllChars('4').ToLowerAscii();
1000cdf0e10cSrcweir 
1001cdf0e10cSrcweir     // HACK: sometimes a real document service name is given here instead of
1002cdf0e10cSrcweir     // a factory short name. Set return value directly to this service name as fallback
1003cdf0e10cSrcweir     // in case next lines of code does nothing ...
1004cdf0e10cSrcweir     // use rFact instead of normed aFact value !
1005cdf0e10cSrcweir     ::rtl::OUString aServiceName = rFact;
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir     if ( aFact.EqualsAscii("swriter") )
1008cdf0e10cSrcweir     {
1009cdf0e10cSrcweir         aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.text.TextDocument");
1010cdf0e10cSrcweir     }
1011cdf0e10cSrcweir     else if ( aFact.EqualsAscii("sweb") || aFact.EqualsAscii("swriter/web") )
1012cdf0e10cSrcweir     {
1013cdf0e10cSrcweir         aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.text.WebDocument");
1014cdf0e10cSrcweir     }
1015cdf0e10cSrcweir     else if ( aFact.EqualsAscii("sglobal") || aFact.EqualsAscii("swriter/globaldocument") )
1016cdf0e10cSrcweir     {
1017cdf0e10cSrcweir         aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.text.GlobalDocument");
1018cdf0e10cSrcweir     }
1019cdf0e10cSrcweir     else if ( aFact.EqualsAscii("scalc") )
1020cdf0e10cSrcweir     {
1021cdf0e10cSrcweir         aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.sheet.SpreadsheetDocument");
1022cdf0e10cSrcweir     }
1023cdf0e10cSrcweir     else if ( aFact.EqualsAscii("sdraw") )
1024cdf0e10cSrcweir     {
1025cdf0e10cSrcweir         aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.drawing.DrawingDocument");
1026cdf0e10cSrcweir     }
1027cdf0e10cSrcweir     else if ( aFact.EqualsAscii("simpress") )
1028cdf0e10cSrcweir     {
1029cdf0e10cSrcweir         aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.presentation.PresentationDocument");
1030cdf0e10cSrcweir     }
1031cdf0e10cSrcweir     else if ( aFact.EqualsAscii("schart") )
1032cdf0e10cSrcweir     {
1033cdf0e10cSrcweir         aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.chart.ChartDocument");
1034cdf0e10cSrcweir     }
1035cdf0e10cSrcweir     else if ( aFact.EqualsAscii("smath") )
1036cdf0e10cSrcweir     {
1037cdf0e10cSrcweir         aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.formula.FormulaProperties");
1038cdf0e10cSrcweir     }
1039cdf0e10cSrcweir     else if ( aFact.EqualsAscii("sbasic") )
1040cdf0e10cSrcweir     {
1041cdf0e10cSrcweir         aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.script.BasicIDE");
1042cdf0e10cSrcweir     }
1043cdf0e10cSrcweir     else if ( aFact.EqualsAscii("sdatabase") )
1044cdf0e10cSrcweir     {
1045cdf0e10cSrcweir         aServiceName = ::rtl::OUString::createFromAscii("com.sun.star.sdb.OfficeDatabaseDocument");
1046cdf0e10cSrcweir     }
1047cdf0e10cSrcweir 
1048cdf0e10cSrcweir     return aServiceName;
1049cdf0e10cSrcweir }
1050cdf0e10cSrcweir 
CreateObjectByFactoryName(const String & rFact,SfxObjectCreateMode eMode)1051cdf0e10cSrcweir SfxObjectShell* SfxObjectShell::CreateObjectByFactoryName( const String& rFact, SfxObjectCreateMode eMode )
1052cdf0e10cSrcweir {
1053cdf0e10cSrcweir     return CreateObject( GetServiceNameFromFactory( rFact ), eMode );
1054cdf0e10cSrcweir }
1055cdf0e10cSrcweir 
1056cdf0e10cSrcweir 
CreateObject(const String & rServiceName,SfxObjectCreateMode eCreateMode)1057cdf0e10cSrcweir SfxObjectShell* SfxObjectShell::CreateObject( const String& rServiceName, SfxObjectCreateMode eCreateMode )
1058cdf0e10cSrcweir {
1059cdf0e10cSrcweir     if ( rServiceName.Len() )
1060cdf0e10cSrcweir     {
1061cdf0e10cSrcweir         ::com::sun::star::uno::Reference < ::com::sun::star::frame::XModel > xDoc(
1062cdf0e10cSrcweir         ::comphelper::getProcessServiceFactory()->createInstance( rServiceName ), UNO_QUERY );
1063cdf0e10cSrcweir         if ( xDoc.is() )
1064cdf0e10cSrcweir         {
1065cdf0e10cSrcweir             ::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xObj( xDoc, UNO_QUERY );
1066cdf0e10cSrcweir             ::com::sun::star::uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
1067cdf0e10cSrcweir             sal_Int64 nHandle = xObj->getSomething( aSeq );
1068cdf0e10cSrcweir             if ( nHandle )
1069cdf0e10cSrcweir             {
1070cdf0e10cSrcweir                 SfxObjectShell* pRet = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
1071cdf0e10cSrcweir                 pRet->SetCreateMode_Impl( eCreateMode );
1072cdf0e10cSrcweir                 return pRet;
1073cdf0e10cSrcweir             }
1074cdf0e10cSrcweir         }
1075cdf0e10cSrcweir     }
1076cdf0e10cSrcweir 
1077cdf0e10cSrcweir     return 0;
1078cdf0e10cSrcweir }
1079cdf0e10cSrcweir 
CreateAndLoadObject(const SfxItemSet & rSet,SfxFrame * pFrame)1080cdf0e10cSrcweir SfxObjectShell* SfxObjectShell::CreateAndLoadObject( const SfxItemSet& rSet, SfxFrame* pFrame )
1081cdf0e10cSrcweir {
1082cdf0e10cSrcweir     uno::Sequence < beans::PropertyValue > aProps;
1083cdf0e10cSrcweir     TransformItems( SID_OPENDOC, rSet, aProps );
1084cdf0e10cSrcweir     SFX_ITEMSET_ARG(&rSet, pFileNameItem, SfxStringItem, SID_FILE_NAME, sal_False);
1085cdf0e10cSrcweir     SFX_ITEMSET_ARG(&rSet, pTargetItem, SfxStringItem, SID_TARGETNAME, sal_False);
1086cdf0e10cSrcweir     ::rtl::OUString aURL;
1087cdf0e10cSrcweir     ::rtl::OUString aTarget = rtl::OUString::createFromAscii("_blank");
1088cdf0e10cSrcweir     if ( pFileNameItem )
1089cdf0e10cSrcweir         aURL = pFileNameItem->GetValue();
1090cdf0e10cSrcweir     if ( pTargetItem )
1091cdf0e10cSrcweir         aTarget = pTargetItem->GetValue();
1092cdf0e10cSrcweir 
1093cdf0e10cSrcweir     uno::Reference < frame::XComponentLoader > xLoader;
1094cdf0e10cSrcweir     if ( pFrame )
1095cdf0e10cSrcweir     {
1096cdf0e10cSrcweir         xLoader = uno::Reference < frame::XComponentLoader >( pFrame->GetFrameInterface(), uno::UNO_QUERY );
1097cdf0e10cSrcweir     }
1098cdf0e10cSrcweir     else
1099cdf0e10cSrcweir         xLoader = uno::Reference < frame::XComponentLoader >( comphelper::getProcessServiceFactory()->createInstance(
1100cdf0e10cSrcweir             ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop") ), uno::UNO_QUERY );
1101cdf0e10cSrcweir 
1102cdf0e10cSrcweir     uno::Reference < lang::XUnoTunnel > xObj;
1103cdf0e10cSrcweir     try
1104cdf0e10cSrcweir     {
1105cdf0e10cSrcweir         xObj = uno::Reference< lang::XUnoTunnel >( xLoader->loadComponentFromURL( aURL, aTarget, 0, aProps ), uno::UNO_QUERY );
1106cdf0e10cSrcweir     }
1107cdf0e10cSrcweir     catch( uno::Exception& )
1108cdf0e10cSrcweir     {}
1109cdf0e10cSrcweir 
1110cdf0e10cSrcweir     if ( xObj.is() )
1111cdf0e10cSrcweir     {
1112cdf0e10cSrcweir         ::com::sun::star::uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
1113cdf0e10cSrcweir         sal_Int64 nHandle = xObj->getSomething( aSeq );
1114cdf0e10cSrcweir         if ( nHandle )
1115cdf0e10cSrcweir             return reinterpret_cast< SfxObjectShell* >(sal::static_int_cast< sal_IntPtr >(  nHandle ));
1116cdf0e10cSrcweir     }
1117cdf0e10cSrcweir 
1118cdf0e10cSrcweir     return NULL;
1119cdf0e10cSrcweir }
1120cdf0e10cSrcweir 
SetInitialized_Impl(const bool i_fromInitNew)1121cdf0e10cSrcweir void SfxObjectShell::SetInitialized_Impl( const bool i_fromInitNew )
1122cdf0e10cSrcweir {
1123cdf0e10cSrcweir     pImp->bInitialized = sal_True;
1124cdf0e10cSrcweir     if ( i_fromInitNew )
1125cdf0e10cSrcweir     {
1126cdf0e10cSrcweir         SetActivateEvent_Impl( SFX_EVENT_CREATEDOC );
1127cdf0e10cSrcweir         SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_DOCCREATED, GlobalEventConfig::GetEventName(STR_EVENT_DOCCREATED), this ) );
1128cdf0e10cSrcweir     }
1129cdf0e10cSrcweir     else
1130cdf0e10cSrcweir     {
1131cdf0e10cSrcweir         SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_LOADFINISHED, GlobalEventConfig::GetEventName(STR_EVENT_LOADFINISHED), this ) );
1132cdf0e10cSrcweir     }
1133cdf0e10cSrcweir }
1134cdf0e10cSrcweir 
1135cdf0e10cSrcweir 
IsChangeRecording() const1136cdf0e10cSrcweir bool SfxObjectShell::IsChangeRecording() const
1137cdf0e10cSrcweir {
1138cdf0e10cSrcweir     // currently this function needs to be overwritten by Writer and Calc only
1139cdf0e10cSrcweir     DBG_ASSERT( 0, "function not implemented" );
1140cdf0e10cSrcweir     return false;
1141cdf0e10cSrcweir }
1142cdf0e10cSrcweir 
1143cdf0e10cSrcweir 
HasChangeRecordProtection() const1144cdf0e10cSrcweir bool SfxObjectShell::HasChangeRecordProtection() const
1145cdf0e10cSrcweir {
1146cdf0e10cSrcweir     // currently this function needs to be overwritten by Writer and Calc only
1147cdf0e10cSrcweir     DBG_ASSERT( 0, "function not implemented" );
1148cdf0e10cSrcweir     return false;
1149cdf0e10cSrcweir }
1150cdf0e10cSrcweir 
1151cdf0e10cSrcweir 
SetChangeRecording(bool)1152cdf0e10cSrcweir void SfxObjectShell::SetChangeRecording( bool /*bActivate*/ )
1153cdf0e10cSrcweir {
1154cdf0e10cSrcweir     // currently this function needs to be overwritten by Writer and Calc only
1155cdf0e10cSrcweir     DBG_ASSERT( 0, "function not implemented" );
1156cdf0e10cSrcweir }
1157cdf0e10cSrcweir 
1158cdf0e10cSrcweir 
SetProtectionPassword(const String &)1159cdf0e10cSrcweir bool SfxObjectShell::SetProtectionPassword( const String & /*rPassword*/ )
1160cdf0e10cSrcweir {
1161cdf0e10cSrcweir     // currently this function needs to be overwritten by Writer and Calc only
1162cdf0e10cSrcweir     DBG_ASSERT( 0, "function not implemented" );
1163cdf0e10cSrcweir     return false;
1164cdf0e10cSrcweir }
1165cdf0e10cSrcweir 
1166cdf0e10cSrcweir 
GetProtectionHash(::com::sun::star::uno::Sequence<sal_Int8> &)1167cdf0e10cSrcweir bool SfxObjectShell::GetProtectionHash( /*out*/ ::com::sun::star::uno::Sequence< sal_Int8 > & /*rPasswordHash*/ )
1168cdf0e10cSrcweir {
1169cdf0e10cSrcweir     // currently this function needs to be overwritten by Writer and Calc only
1170cdf0e10cSrcweir     DBG_ASSERT( 0, "function not implemented" );
1171cdf0e10cSrcweir     return false;
1172cdf0e10cSrcweir }
1173