xref: /aoo41x/main/sfx2/source/view/frmload.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 "frmload.hxx"
28cdf0e10cSrcweir #include "objshimp.hxx"
29cdf0e10cSrcweir #include "sfx2/app.hxx"
30cdf0e10cSrcweir #include "sfx2/dispatch.hxx"
31cdf0e10cSrcweir #include "sfx2/docfac.hxx"
32cdf0e10cSrcweir #include "sfx2/docfile.hxx"
33cdf0e10cSrcweir #include "sfx2/docfilt.hxx"
34cdf0e10cSrcweir #include "sfx2/doctempl.hxx"
35cdf0e10cSrcweir #include "sfx2/fcontnr.hxx"
36cdf0e10cSrcweir #include "sfx2/frame.hxx"
37cdf0e10cSrcweir #include "sfx2/request.hxx"
38cdf0e10cSrcweir #include "sfx2/sfx.hrc"
39cdf0e10cSrcweir #include "sfx2/sfxsids.hrc"
40cdf0e10cSrcweir #include "sfx2/sfxuno.hxx"
41cdf0e10cSrcweir #include "sfx2/viewfrm.hxx"
42cdf0e10cSrcweir #include "sfx2/viewsh.hxx"
43cdf0e10cSrcweir #include "sfx2/viewfac.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir /** === begin UNO includes === **/
46cdf0e10cSrcweir #include <com/sun/star/container/XContainerQuery.hpp>
47cdf0e10cSrcweir #include <com/sun/star/document/XTypeDetection.hpp>
48cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp>
49cdf0e10cSrcweir #include <com/sun/star/frame/XLoadable.hpp>
50cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
51cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler2.hpp>
52cdf0e10cSrcweir #include <com/sun/star/document/XViewDataSupplier.hpp>
53cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
54cdf0e10cSrcweir /** === end UNO includes === **/
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #include <comphelper/interaction.hxx>
57cdf0e10cSrcweir #include <comphelper/namedvaluecollection.hxx>
58cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx>
59cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
60cdf0e10cSrcweir #include <framework/interaction.hxx>
61cdf0e10cSrcweir #include <rtl/logfile.hxx>
62cdf0e10cSrcweir #include <rtl/ustring.h>
63cdf0e10cSrcweir #include <sot/storinfo.hxx>
64cdf0e10cSrcweir #include <svtools/ehdl.hxx>
65cdf0e10cSrcweir #include <svl/eitem.hxx>
66cdf0e10cSrcweir #include <svl/itemset.hxx>
67cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
68cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
69cdf0e10cSrcweir #include <svl/stritem.hxx>
70cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
71cdf0e10cSrcweir #include <tools/diagnose_ex.h>
72cdf0e10cSrcweir #include <ucbhelper/simpleinteractionrequest.hxx>
73cdf0e10cSrcweir #include <vos/mutex.hxx>
74cdf0e10cSrcweir 
75cdf0e10cSrcweir /** === begin UNO using === **/
76cdf0e10cSrcweir using ::com::sun::star::beans::PropertyValue;
77cdf0e10cSrcweir using ::com::sun::star::container::XContainerQuery;
78cdf0e10cSrcweir using ::com::sun::star::container::XEnumeration;
79cdf0e10cSrcweir using ::com::sun::star::document::XTypeDetection;
80cdf0e10cSrcweir using ::com::sun::star::frame::XFrame;
81cdf0e10cSrcweir using ::com::sun::star::frame::XLoadable;
82cdf0e10cSrcweir using ::com::sun::star::frame::XModel;
83cdf0e10cSrcweir using ::com::sun::star::lang::XMultiServiceFactory;
84cdf0e10cSrcweir using ::com::sun::star::task::XInteractionHandler;
85cdf0e10cSrcweir using ::com::sun::star::task::XInteractionHandler2;
86cdf0e10cSrcweir using ::com::sun::star::task::XInteractionRequest;
87cdf0e10cSrcweir using ::com::sun::star::task::XStatusIndicator;
88cdf0e10cSrcweir using ::com::sun::star::uno::Any;
89cdf0e10cSrcweir using ::com::sun::star::uno::Exception;
90cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
91cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException;
92cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
93cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY;
94cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW;
95cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW;
96cdf0e10cSrcweir using ::com::sun::star::uno::makeAny;
97cdf0e10cSrcweir using ::com::sun::star::util::XCloseable;
98cdf0e10cSrcweir using ::com::sun::star::document::XViewDataSupplier;
99cdf0e10cSrcweir using ::com::sun::star::container::XIndexAccess;
100cdf0e10cSrcweir using ::com::sun::star::frame::XController2;
101cdf0e10cSrcweir using ::com::sun::star::frame::XController;
102cdf0e10cSrcweir using ::com::sun::star::frame::XModel2;
103cdf0e10cSrcweir /** === end UNO using === **/
104cdf0e10cSrcweir 
SfxFrameLoader_Impl(const Reference<XMultiServiceFactory> & _rxFactory)105cdf0e10cSrcweir SfxFrameLoader_Impl::SfxFrameLoader_Impl( const Reference< XMultiServiceFactory >& _rxFactory )
106cdf0e10cSrcweir     :m_aContext( _rxFactory )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
~SfxFrameLoader_Impl()110cdf0e10cSrcweir SfxFrameLoader_Impl::~SfxFrameLoader_Impl()
111cdf0e10cSrcweir {
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
impl_detectFilterForURL(const::rtl::OUString & sURL,const::comphelper::NamedValueCollection & i_rDescriptor,const SfxFilterMatcher & rMatcher) const115cdf0e10cSrcweir const SfxFilter* SfxFrameLoader_Impl::impl_detectFilterForURL( const ::rtl::OUString& sURL,
116cdf0e10cSrcweir         const ::comphelper::NamedValueCollection& i_rDescriptor, const SfxFilterMatcher& rMatcher ) const
117cdf0e10cSrcweir {
118cdf0e10cSrcweir     ::rtl::OUString sFilter;
119cdf0e10cSrcweir     try
120cdf0e10cSrcweir     {
121cdf0e10cSrcweir         if ( !sURL.getLength() )
122cdf0e10cSrcweir             return 0;
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         Reference< XTypeDetection > xDetect(
125cdf0e10cSrcweir             m_aContext.createComponent( "com.sun.star.document.TypeDetection" ),
126cdf0e10cSrcweir             UNO_QUERY_THROW);
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         ::comphelper::NamedValueCollection aNewArgs;
129cdf0e10cSrcweir         aNewArgs.put( "URL", sURL );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir         if ( i_rDescriptor.has( "InteractionHandler" ) )
132cdf0e10cSrcweir             aNewArgs.put( "InteractionHandler", i_rDescriptor.get( "InteractionHandler" ) );
133cdf0e10cSrcweir         if ( i_rDescriptor.has( "StatusIndicator" ) )
134cdf0e10cSrcweir             aNewArgs.put( "StatusIndicator", i_rDescriptor.get( "StatusIndicator" ) );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir         Sequence< PropertyValue > aQueryArgs( aNewArgs.getPropertyValues() );
137cdf0e10cSrcweir         ::rtl::OUString sType = xDetect->queryTypeByDescriptor( aQueryArgs, sal_True );
138cdf0e10cSrcweir         if ( sType.getLength() )
139cdf0e10cSrcweir         {
140cdf0e10cSrcweir             const SfxFilter* pFilter = rMatcher.GetFilter4EA( sType );
141cdf0e10cSrcweir             if ( pFilter )
142cdf0e10cSrcweir                 sFilter = pFilter->GetName();
143cdf0e10cSrcweir         }
144cdf0e10cSrcweir     }
145cdf0e10cSrcweir     catch ( const RuntimeException& )
146cdf0e10cSrcweir     {
147cdf0e10cSrcweir         throw;
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir     catch( const Exception& )
150cdf0e10cSrcweir     {
151cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
152cdf0e10cSrcweir         sFilter = ::rtl::OUString();
153cdf0e10cSrcweir     }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     const SfxFilter* pFilter = 0;
156cdf0e10cSrcweir     if (sFilter.getLength())
157cdf0e10cSrcweir         pFilter = rMatcher.GetFilter4FilterName(sFilter);
158cdf0e10cSrcweir     return pFilter;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
impl_getFilterFromServiceName_nothrow(const::rtl::OUString & i_rServiceName) const162cdf0e10cSrcweir const SfxFilter* SfxFrameLoader_Impl::impl_getFilterFromServiceName_nothrow( const ::rtl::OUString& i_rServiceName ) const
163cdf0e10cSrcweir {
164cdf0e10cSrcweir     try
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         ::comphelper::NamedValueCollection aQuery;
167cdf0e10cSrcweir         aQuery.put( "DocumentService", i_rServiceName );
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         const Reference< XContainerQuery > xQuery(
170cdf0e10cSrcweir             m_aContext.createComponent( "com.sun.star.document.FilterFactory" ),
171cdf0e10cSrcweir             UNO_QUERY_THROW );
172cdf0e10cSrcweir 
173cdf0e10cSrcweir         const SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
174cdf0e10cSrcweir         const SfxFilterFlags nMust = SFX_FILTER_IMPORT;
175cdf0e10cSrcweir         const SfxFilterFlags nDont = SFX_FILTER_NOTINSTALLED;
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         Reference < XEnumeration > xEnum( xQuery->createSubSetEnumerationByProperties(
178cdf0e10cSrcweir             aQuery.getNamedValues() ), UNO_SET_THROW );
179cdf0e10cSrcweir         while ( xEnum->hasMoreElements() )
180cdf0e10cSrcweir         {
181cdf0e10cSrcweir             ::comphelper::NamedValueCollection aType( xEnum->nextElement() );
182cdf0e10cSrcweir             ::rtl::OUString sFilterName = aType.getOrDefault( "Name", ::rtl::OUString() );
183cdf0e10cSrcweir             if ( !sFilterName.getLength() )
184cdf0e10cSrcweir                 continue;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir             const SfxFilter* pFilter = rMatcher.GetFilter4FilterName( sFilterName );
187cdf0e10cSrcweir             if ( !pFilter )
188cdf0e10cSrcweir                 continue;
189cdf0e10cSrcweir 
190cdf0e10cSrcweir             SfxFilterFlags nFlags = pFilter->GetFilterFlags();
191cdf0e10cSrcweir             if  (   ( ( nFlags & nMust ) == nMust )
192cdf0e10cSrcweir                 &&  ( ( nFlags & nDont ) == 0 )
193cdf0e10cSrcweir                 )
194cdf0e10cSrcweir             {
195cdf0e10cSrcweir                 return pFilter;
196cdf0e10cSrcweir             }
197cdf0e10cSrcweir         }
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir     catch( const Exception& )
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
202cdf0e10cSrcweir     }
203cdf0e10cSrcweir     return NULL;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
impl_askForFilter_nothrow(const Reference<XInteractionHandler> & i_rxHandler,const::rtl::OUString & i_rDocumentURL) const207cdf0e10cSrcweir ::rtl::OUString SfxFrameLoader_Impl::impl_askForFilter_nothrow( const Reference< XInteractionHandler >& i_rxHandler,
208cdf0e10cSrcweir                                                                  const ::rtl::OUString& i_rDocumentURL ) const
209cdf0e10cSrcweir {
210cdf0e10cSrcweir     ENSURE_OR_THROW( i_rxHandler.is(), "invalid interaction handler" );
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     ::rtl::OUString sFilterName;
213cdf0e10cSrcweir     try
214cdf0e10cSrcweir     {
215cdf0e10cSrcweir         ::framework::RequestFilterSelect aRequest( i_rDocumentURL );
216cdf0e10cSrcweir         i_rxHandler->handle( aRequest.GetRequest() );
217cdf0e10cSrcweir         if( !aRequest.isAbort() )
218cdf0e10cSrcweir             sFilterName = aRequest.getFilter();
219cdf0e10cSrcweir     }
220cdf0e10cSrcweir     catch( const Exception& )
221cdf0e10cSrcweir     {
222cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
223cdf0e10cSrcweir     }
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     return sFilterName;
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
229cdf0e10cSrcweir namespace
230cdf0e10cSrcweir {
lcl_getDispatchResult(const SfxPoolItem * _pResult)231cdf0e10cSrcweir     sal_Bool lcl_getDispatchResult( const SfxPoolItem* _pResult )
232cdf0e10cSrcweir     {
233cdf0e10cSrcweir         if ( !_pResult )
234cdf0e10cSrcweir             return sal_False;
235cdf0e10cSrcweir 
236cdf0e10cSrcweir         // default must be set to true, because some return values
237cdf0e10cSrcweir         // cant be checked, but nonetheless indicate "success"!
238cdf0e10cSrcweir 	    sal_Bool bSuccess = sal_True;
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 	    // On the other side some special slots return a boolean state,
241cdf0e10cSrcweir         // which can be set to FALSE.
242cdf0e10cSrcweir         SfxBoolItem *pItem = PTR_CAST( SfxBoolItem, _pResult );
243cdf0e10cSrcweir         if ( pItem )
244cdf0e10cSrcweir             bSuccess = pItem->GetValue();
245cdf0e10cSrcweir 
246cdf0e10cSrcweir         return bSuccess;
247cdf0e10cSrcweir     }
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
impl_createNewDocWithSlotParam(const sal_uInt16 _nSlotID,const Reference<XFrame> & i_rxFrame,const bool i_bHidden)251cdf0e10cSrcweir sal_Bool SfxFrameLoader_Impl::impl_createNewDocWithSlotParam( const sal_uInt16 _nSlotID, const Reference< XFrame >& i_rxFrame,
252cdf0e10cSrcweir                                                               const bool i_bHidden )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir     SfxRequest aRequest( _nSlotID, SFX_CALLMODE_SYNCHRON, SFX_APP()->GetPool() );
255cdf0e10cSrcweir     aRequest.AppendItem( SfxUnoFrameItem( SID_FILLFRAME, i_rxFrame ) );
256cdf0e10cSrcweir     if ( i_bHidden )
257cdf0e10cSrcweir         aRequest.AppendItem( SfxBoolItem( SID_HIDDEN, sal_True ) );
258cdf0e10cSrcweir     return lcl_getDispatchResult( SFX_APP()->ExecuteSlot( aRequest ) );
259cdf0e10cSrcweir }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
impl_determineFilter(::comphelper::NamedValueCollection & io_rDescriptor) const262cdf0e10cSrcweir void SfxFrameLoader_Impl::impl_determineFilter( ::comphelper::NamedValueCollection& io_rDescriptor ) const
263cdf0e10cSrcweir {
264cdf0e10cSrcweir     const ::rtl::OUString     sURL         = io_rDescriptor.getOrDefault( "URL",                ::rtl::OUString() );
265cdf0e10cSrcweir     const ::rtl::OUString     sTypeName    = io_rDescriptor.getOrDefault( "TypeName",           ::rtl::OUString() );
266cdf0e10cSrcweir     const ::rtl::OUString     sFilterName  = io_rDescriptor.getOrDefault( "FilterName",         ::rtl::OUString() );
267cdf0e10cSrcweir     const ::rtl::OUString     sServiceName = io_rDescriptor.getOrDefault( "DocumentService",    ::rtl::OUString() );
268cdf0e10cSrcweir     const Reference< XInteractionHandler >
269cdf0e10cSrcweir                               xInteraction = io_rDescriptor.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() );
270cdf0e10cSrcweir 
271cdf0e10cSrcweir     const SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
272cdf0e10cSrcweir     const SfxFilter* pFilter = NULL;
273cdf0e10cSrcweir 
274cdf0e10cSrcweir     // get filter by its name directly ...
275cdf0e10cSrcweir     if ( sFilterName.getLength() )
276cdf0e10cSrcweir         pFilter = rMatcher.GetFilter4FilterName( sFilterName );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir     // or search the preferred filter for the detected type ...
279cdf0e10cSrcweir     if ( !pFilter && sTypeName.getLength() )
280cdf0e10cSrcweir         pFilter = rMatcher.GetFilter4EA( sTypeName );
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     // or use given document service for detection, too
283cdf0e10cSrcweir     if ( !pFilter && sServiceName.getLength() )
284cdf0e10cSrcweir         pFilter = impl_getFilterFromServiceName_nothrow( sServiceName );
285cdf0e10cSrcweir 
286cdf0e10cSrcweir     // or use interaction to ask user for right filter.
287cdf0e10cSrcweir     if ( !pFilter && xInteraction.is() && sURL.getLength() )
288cdf0e10cSrcweir     {
289cdf0e10cSrcweir         ::rtl::OUString sSelectedFilter = impl_askForFilter_nothrow( xInteraction, sURL );
290cdf0e10cSrcweir         if ( sSelectedFilter.getLength() )
291cdf0e10cSrcweir             pFilter = rMatcher.GetFilter4FilterName( sSelectedFilter );
292cdf0e10cSrcweir     }
293cdf0e10cSrcweir 
294cdf0e10cSrcweir     if ( pFilter )
295cdf0e10cSrcweir     {
296cdf0e10cSrcweir         io_rDescriptor.put( "FilterName", ::rtl::OUString( pFilter->GetFilterName() ) );
297cdf0e10cSrcweir 
298cdf0e10cSrcweir         // If detected filter indicates using of an own template format
299cdf0e10cSrcweir         // add property "AsTemplate" to descriptor. But suppress this step
300cdf0e10cSrcweir         // if such property already exists.
301cdf0e10cSrcweir         if ( pFilter->IsOwnTemplateFormat() && !io_rDescriptor.has( "AsTemplate" ) )
302cdf0e10cSrcweir             io_rDescriptor.put( "AsTemplate", sal_Bool( sal_True ) );
303cdf0e10cSrcweir 
304cdf0e10cSrcweir         // The DocumentService property will finally be used to determine the document type to create, so
305cdf0e10cSrcweir         // override it with the service name as indicated by the found filter.
306cdf0e10cSrcweir         io_rDescriptor.put( "DocumentService", ::rtl::OUString( pFilter->GetServiceName() ) );
307cdf0e10cSrcweir     }
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
impl_findObjectShell(const Reference<XModel2> & i_rxDocument) const311cdf0e10cSrcweir SfxObjectShellRef SfxFrameLoader_Impl::impl_findObjectShell( const Reference< XModel2 >& i_rxDocument ) const
312cdf0e10cSrcweir {
313cdf0e10cSrcweir 	for ( SfxObjectShell* pDoc = SfxObjectShell::GetFirst( NULL, sal_False ); pDoc; pDoc = SfxObjectShell::GetNext( *pDoc, NULL, sal_False ) )
314cdf0e10cSrcweir 	{
315cdf0e10cSrcweir 		if ( i_rxDocument == pDoc->GetModel() )
316cdf0e10cSrcweir         {
317cdf0e10cSrcweir             return pDoc;
318cdf0e10cSrcweir         }
319cdf0e10cSrcweir 	}
320cdf0e10cSrcweir 
321cdf0e10cSrcweir     DBG_ERROR( "SfxFrameLoader_Impl::impl_findObjectShell: model is not based on SfxObjectShell - wrong frame loader usage!" );
322cdf0e10cSrcweir     return NULL;
323cdf0e10cSrcweir }
324cdf0e10cSrcweir 
325cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
impl_determineTemplateDocument(::comphelper::NamedValueCollection & io_rDescriptor) const326cdf0e10cSrcweir bool SfxFrameLoader_Impl::impl_determineTemplateDocument( ::comphelper::NamedValueCollection& io_rDescriptor ) const
327cdf0e10cSrcweir {
328cdf0e10cSrcweir     const ::rtl::OUString sTemplateRegioName = io_rDescriptor.getOrDefault( "TemplateRegionName", ::rtl::OUString() );
329cdf0e10cSrcweir     const ::rtl::OUString sTemplateName      = io_rDescriptor.getOrDefault( "TemplateName",       ::rtl::OUString() );
330cdf0e10cSrcweir     const ::rtl::OUString sServiceName       = io_rDescriptor.getOrDefault( "DocumentService",    ::rtl::OUString() );
331cdf0e10cSrcweir     const ::rtl::OUString sURL               = io_rDescriptor.getOrDefault( "URL",                ::rtl::OUString() );
332cdf0e10cSrcweir 
333cdf0e10cSrcweir     // determine the full URL of the template to use, if any
334cdf0e10cSrcweir     String sTemplateURL;
335cdf0e10cSrcweir 	if ( sTemplateRegioName.getLength() && sTemplateName.getLength() )
336cdf0e10cSrcweir 	{
337cdf0e10cSrcweir 		SfxDocumentTemplates aTmpFac;
338cdf0e10cSrcweir 		aTmpFac.GetFull( sTemplateRegioName, sTemplateName, sTemplateURL );
339cdf0e10cSrcweir 	}
340cdf0e10cSrcweir 	else
341cdf0e10cSrcweir 	{
342cdf0e10cSrcweir 	    if ( sServiceName.getLength() )
343cdf0e10cSrcweir             sTemplateURL = SfxObjectFactory::GetStandardTemplate( sServiceName );
344cdf0e10cSrcweir         else
345cdf0e10cSrcweir             sTemplateURL = SfxObjectFactory::GetStandardTemplate( SfxObjectShell::GetServiceNameFromFactory( sURL ) );
346cdf0e10cSrcweir 	}
347cdf0e10cSrcweir 
348cdf0e10cSrcweir     if ( sTemplateURL.Len() > 0 )
349cdf0e10cSrcweir     {
350cdf0e10cSrcweir         // detect the filter for the template. Might still be NULL (if the template is broken, or does not
351cdf0e10cSrcweir         // exist, or some such), but this is handled by our caller the same way as if no template/URL was present.
352cdf0e10cSrcweir         const SfxFilter* pTemplateFilter = impl_detectFilterForURL( sTemplateURL, io_rDescriptor, SFX_APP()->GetFilterMatcher() );
353cdf0e10cSrcweir         if ( pTemplateFilter )
354cdf0e10cSrcweir         {
355cdf0e10cSrcweir             // load the template document, but, well, "as template"
356cdf0e10cSrcweir             io_rDescriptor.put( "FilterName", ::rtl::OUString( pTemplateFilter->GetName() ) );
357cdf0e10cSrcweir             io_rDescriptor.put( "FileName", ::rtl::OUString( sTemplateURL ) );
358cdf0e10cSrcweir             io_rDescriptor.put( "AsTemplate", sal_True );
359cdf0e10cSrcweir 
360cdf0e10cSrcweir             // #i21583#
361cdf0e10cSrcweir             // the DocumentService property will finally be used to create the document. Thus, override any possibly
362cdf0e10cSrcweir             // present value with the document service of the template.
363cdf0e10cSrcweir             io_rDescriptor.put( "DocumentService", ::rtl::OUString( pTemplateFilter->GetServiceName() ) );
364cdf0e10cSrcweir             return true;
365cdf0e10cSrcweir         }
366cdf0e10cSrcweir     }
367cdf0e10cSrcweir     return false;
368cdf0e10cSrcweir }
369cdf0e10cSrcweir 
370cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
impl_findSlotParam(const::rtl::OUString & i_rFactoryURL) const371cdf0e10cSrcweir sal_uInt16 SfxFrameLoader_Impl::impl_findSlotParam( const ::rtl::OUString& i_rFactoryURL ) const
372cdf0e10cSrcweir {
373cdf0e10cSrcweir     ::rtl::OUString sSlotParam;
374cdf0e10cSrcweir     const sal_Int32 nParamPos = i_rFactoryURL.indexOf( '?' );
375cdf0e10cSrcweir     if ( nParamPos >= 0 )
376cdf0e10cSrcweir     {
377cdf0e10cSrcweir         // currently only the "slot" parameter is supported
378cdf0e10cSrcweir         const sal_Int32 nSlotPos = i_rFactoryURL.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "slot=" ), nParamPos );
379cdf0e10cSrcweir         if ( nSlotPos > 0 )
380cdf0e10cSrcweir             sSlotParam = i_rFactoryURL.copy( nSlotPos + 5 );
381cdf0e10cSrcweir     }
382cdf0e10cSrcweir 
383cdf0e10cSrcweir     if ( sSlotParam.getLength() )
384cdf0e10cSrcweir         return sal_uInt16( sSlotParam.toInt32() );
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     return 0;
387cdf0e10cSrcweir }
388cdf0e10cSrcweir 
389cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
impl_handleCaughtError_nothrow(const Any & i_rCaughtError,const::comphelper::NamedValueCollection & i_rDescriptor) const390cdf0e10cSrcweir void SfxFrameLoader_Impl::impl_handleCaughtError_nothrow( const Any& i_rCaughtError, const ::comphelper::NamedValueCollection& i_rDescriptor ) const
391cdf0e10cSrcweir {
392cdf0e10cSrcweir     try
393cdf0e10cSrcweir     {
394cdf0e10cSrcweir         const Reference< XInteractionHandler > xInteraction =
395cdf0e10cSrcweir             i_rDescriptor.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() );
396cdf0e10cSrcweir         if ( !xInteraction.is() )
397cdf0e10cSrcweir             return;
398cdf0e10cSrcweir         ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( i_rCaughtError ) );
399cdf0e10cSrcweir         ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
400cdf0e10cSrcweir         pRequest->addContinuation( pApprove.get() );
401cdf0e10cSrcweir 
402cdf0e10cSrcweir         const Reference< XInteractionHandler2 > xHandler( xInteraction, UNO_QUERY );
403cdf0e10cSrcweir     #if OSL_DEBUG_LEVEL > 0
404cdf0e10cSrcweir         const sal_Bool bHandled =
405cdf0e10cSrcweir     #endif
406cdf0e10cSrcweir         xHandler.is() && xHandler->handleInteractionRequest( pRequest.get() );
407cdf0e10cSrcweir 
408cdf0e10cSrcweir     #if OSL_DEBUG_LEVEL > 0
409cdf0e10cSrcweir         if ( !bHandled )
410cdf0e10cSrcweir             // the interaction handler couldn't deal with this error
411cdf0e10cSrcweir             // => report it as assertion, at least (done in the DBG_UNHANDLED_EXCEPTION below)
412cdf0e10cSrcweir             ::cppu::throwException( i_rCaughtError );
413cdf0e10cSrcweir     #endif
414cdf0e10cSrcweir     }
415cdf0e10cSrcweir     catch( const Exception& )
416cdf0e10cSrcweir     {
417cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
418cdf0e10cSrcweir     }
419cdf0e10cSrcweir }
420cdf0e10cSrcweir 
421cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
impl_removeLoaderArguments(::comphelper::NamedValueCollection & io_rDescriptor)422cdf0e10cSrcweir void SfxFrameLoader_Impl::impl_removeLoaderArguments( ::comphelper::NamedValueCollection& io_rDescriptor )
423cdf0e10cSrcweir {
424cdf0e10cSrcweir     // remove the arguments which are for the loader only, and not for a call to attachResource
425cdf0e10cSrcweir     io_rDescriptor.remove( "StatusIndicator" );
426cdf0e10cSrcweir     io_rDescriptor.remove( "Model" );
427cdf0e10cSrcweir }
428cdf0e10cSrcweir 
429cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
impl_extractViewCreationArgs(::comphelper::NamedValueCollection & io_rDescriptor)430cdf0e10cSrcweir ::comphelper::NamedValueCollection SfxFrameLoader_Impl::impl_extractViewCreationArgs( ::comphelper::NamedValueCollection& io_rDescriptor )
431cdf0e10cSrcweir {
432cdf0e10cSrcweir     const sal_Char* pKnownViewArgs[] = {
433cdf0e10cSrcweir         "JumpMark"
434cdf0e10cSrcweir     };
435cdf0e10cSrcweir 
436cdf0e10cSrcweir     ::comphelper::NamedValueCollection aViewArgs;
437cdf0e10cSrcweir     for ( size_t i=0; i < sizeof( pKnownViewArgs ) / sizeof( pKnownViewArgs[0] ); ++i )
438cdf0e10cSrcweir     {
439cdf0e10cSrcweir         if ( io_rDescriptor.has( pKnownViewArgs[i] ) )
440cdf0e10cSrcweir         {
441cdf0e10cSrcweir             aViewArgs.put( pKnownViewArgs[i], io_rDescriptor.get( pKnownViewArgs[i] ) );
442cdf0e10cSrcweir             io_rDescriptor.remove( pKnownViewArgs[i] );
443cdf0e10cSrcweir         }
444cdf0e10cSrcweir     }
445cdf0e10cSrcweir     return aViewArgs;
446cdf0e10cSrcweir }
447cdf0e10cSrcweir 
448cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
impl_determineEffectiveViewId_nothrow(const SfxObjectShell & i_rDocument,const::comphelper::NamedValueCollection & i_rDescriptor)449cdf0e10cSrcweir sal_Int16 SfxFrameLoader_Impl::impl_determineEffectiveViewId_nothrow( const SfxObjectShell& i_rDocument, const ::comphelper::NamedValueCollection& i_rDescriptor )
450cdf0e10cSrcweir {
451cdf0e10cSrcweir     sal_Int16 nViewId = i_rDescriptor.getOrDefault( "ViewId", sal_Int16( 0 ) );
452cdf0e10cSrcweir     try
453cdf0e10cSrcweir     {
454cdf0e10cSrcweir         if ( nViewId == 0 ) do
455cdf0e10cSrcweir         {
456cdf0e10cSrcweir             Reference< XViewDataSupplier > xViewDataSupplier( i_rDocument.GetModel(), UNO_QUERY );
457cdf0e10cSrcweir             Reference< XIndexAccess > xViewData;
458cdf0e10cSrcweir             if ( xViewDataSupplier.is() )
459cdf0e10cSrcweir 	            xViewData.set( xViewDataSupplier->getViewData() );
460cdf0e10cSrcweir 
461cdf0e10cSrcweir             if ( !xViewData.is() || ( xViewData->getCount() == 0 ) )
462cdf0e10cSrcweir                 // no view data stored together with the model
463cdf0e10cSrcweir 	            break;
464cdf0e10cSrcweir 
465cdf0e10cSrcweir             // obtain the ViewID from the view data
466cdf0e10cSrcweir             Sequence< PropertyValue > aViewData;
467cdf0e10cSrcweir             if ( !( xViewData->getByIndex( 0 ) >>= aViewData ) )
468cdf0e10cSrcweir                 break;
469cdf0e10cSrcweir 
470cdf0e10cSrcweir             ::comphelper::NamedValueCollection aNamedViewData( aViewData );
471cdf0e10cSrcweir             ::rtl::OUString sViewId = aNamedViewData.getOrDefault( "ViewId", ::rtl::OUString() );
472cdf0e10cSrcweir             if ( !sViewId.getLength() )
473cdf0e10cSrcweir                 break;
474cdf0e10cSrcweir 
475cdf0e10cSrcweir             // somewhat weird convention here ... in the view data, the ViewId is a string, effectively describing
476cdf0e10cSrcweir             // a view name. In the document load descriptor, the ViewId is in fact the numeric ID.
477cdf0e10cSrcweir 
478cdf0e10cSrcweir             SfxViewFactory* pViewFactory = i_rDocument.GetFactory().GetViewFactoryByViewName( sViewId );
479cdf0e10cSrcweir             if ( pViewFactory )
480cdf0e10cSrcweir                 nViewId = sal_Int16( pViewFactory->GetOrdinal() );
481cdf0e10cSrcweir         }
482cdf0e10cSrcweir         while ( false );
483cdf0e10cSrcweir     }
484cdf0e10cSrcweir     catch( const Exception& )
485cdf0e10cSrcweir     {
486cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
487cdf0e10cSrcweir     }
488cdf0e10cSrcweir 
489cdf0e10cSrcweir     if ( nViewId == 0 )
490cdf0e10cSrcweir         nViewId = i_rDocument.GetFactory().GetViewFactory( 0 ).GetOrdinal();
491cdf0e10cSrcweir     return nViewId;
492cdf0e10cSrcweir }
493cdf0e10cSrcweir 
494cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
impl_createDocumentView(const Reference<XModel2> & i_rModel,const Reference<XFrame> & i_rFrame,const::comphelper::NamedValueCollection & i_rViewFactoryArgs,const::rtl::OUString & i_rViewName)495cdf0e10cSrcweir Reference< XController2 > SfxFrameLoader_Impl::impl_createDocumentView( const Reference< XModel2 >& i_rModel,
496cdf0e10cSrcweir         const Reference< XFrame >& i_rFrame, const ::comphelper::NamedValueCollection& i_rViewFactoryArgs,
497cdf0e10cSrcweir         const ::rtl::OUString& i_rViewName )
498cdf0e10cSrcweir {
499cdf0e10cSrcweir     // let the model create a new controller
500cdf0e10cSrcweir     const Reference< XController2 > xController( i_rModel->createViewController(
501cdf0e10cSrcweir         i_rViewName,
502cdf0e10cSrcweir         i_rViewFactoryArgs.getPropertyValues(),
503cdf0e10cSrcweir         i_rFrame
504cdf0e10cSrcweir     ), UNO_SET_THROW );
505cdf0e10cSrcweir 
506cdf0e10cSrcweir     // introduce model/view/controller to each other
507cdf0e10cSrcweir     xController->attachModel( i_rModel.get() );
508cdf0e10cSrcweir     i_rModel->connectController( xController.get() );
509cdf0e10cSrcweir     i_rFrame->setComponent( xController->getComponentWindow(), xController.get() );
510cdf0e10cSrcweir     xController->attachFrame( i_rFrame );
511cdf0e10cSrcweir     i_rModel->setCurrentController( xController.get() );
512cdf0e10cSrcweir 
513cdf0e10cSrcweir     return xController;
514cdf0e10cSrcweir }
515cdf0e10cSrcweir 
516cdf0e10cSrcweir // --------------------------------------------------------------------------------------------------------------------
load(const Sequence<PropertyValue> & rArgs,const Reference<XFrame> & _rTargetFrame)517cdf0e10cSrcweir sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const Sequence< PropertyValue >& rArgs,
518cdf0e10cSrcweir                                              const Reference< XFrame >& _rTargetFrame )
519cdf0e10cSrcweir     throw( RuntimeException )
520cdf0e10cSrcweir {
521cdf0e10cSrcweir     ENSURE_OR_THROW( _rTargetFrame.is(), "illegal NULL frame" );
522cdf0e10cSrcweir 
523cdf0e10cSrcweir     ::vos::OGuard aGuard( Application::GetSolarMutex() );
524cdf0e10cSrcweir 
525cdf0e10cSrcweir 	RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxFrameLoader::load" );
526cdf0e10cSrcweir 
527cdf0e10cSrcweir     ::comphelper::NamedValueCollection aDescriptor( rArgs );
528cdf0e10cSrcweir 
529cdf0e10cSrcweir     // ensure the descriptor contains a referrer
530cdf0e10cSrcweir     if ( !aDescriptor.has( "Referer" ) )
531cdf0e10cSrcweir         aDescriptor.put( "Referer", ::rtl::OUString() );
532cdf0e10cSrcweir 
533cdf0e10cSrcweir     // TODO: is this needed? finally, when loading is successfull, then there should be no need for this item,
534cdf0e10cSrcweir     // as the document can always obtain its frame. In particular, there might be situations where this frame
535cdf0e10cSrcweir     // is accessed, but already disposed: Imagine the user loading a document, opening a second view on it, and
536cdf0e10cSrcweir     // then closing the first view/frame.
537cdf0e10cSrcweir     aDescriptor.put( "Frame", _rTargetFrame );
538cdf0e10cSrcweir 
539cdf0e10cSrcweir     // did the caller already pass a model?
540cdf0e10cSrcweir     Reference< XModel2 > xModel = aDescriptor.getOrDefault( "Model", Reference< XModel2 >() );
541cdf0e10cSrcweir     const bool bExternalModel = xModel.is();
542cdf0e10cSrcweir 
543cdf0e10cSrcweir     // check for factory URLs to create a new doc, instead of loading one
544cdf0e10cSrcweir     const ::rtl::OUString sURL = aDescriptor.getOrDefault( "URL", ::rtl::OUString() );
545cdf0e10cSrcweir     const bool bIsFactoryURL = ( sURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "private:factory/" ) ) == 0 );
546cdf0e10cSrcweir     bool bInitNewModel = bIsFactoryURL;
547cdf0e10cSrcweir     if ( bIsFactoryURL && !bExternalModel )
548cdf0e10cSrcweir     {
549cdf0e10cSrcweir         const ::rtl::OUString sFactory = sURL.copy( sizeof( "private:factory/" ) -1 );
550cdf0e10cSrcweir         // special handling for some weird factory URLs a la private:factory/swriter?slot=21053
551cdf0e10cSrcweir         const sal_uInt16 nSlotParam = impl_findSlotParam( sFactory );
552cdf0e10cSrcweir         if ( nSlotParam != 0 )
553cdf0e10cSrcweir         {
554cdf0e10cSrcweir             return impl_createNewDocWithSlotParam( nSlotParam, _rTargetFrame, aDescriptor.getOrDefault( "Hidden", false ) );
555cdf0e10cSrcweir         }
556cdf0e10cSrcweir 
557cdf0e10cSrcweir         const bool bDescribesValidTemplate = impl_determineTemplateDocument( aDescriptor );
558cdf0e10cSrcweir         if ( bDescribesValidTemplate )
559cdf0e10cSrcweir         {
560cdf0e10cSrcweir             // if the media descriptor allowed us to determine a template document to create the new document
561cdf0e10cSrcweir             // from, then do not init a new document model from scratch (below), but instead load the
562cdf0e10cSrcweir             // template document
563cdf0e10cSrcweir             bInitNewModel = false;
564cdf0e10cSrcweir         }
565cdf0e10cSrcweir         else
566cdf0e10cSrcweir         {
567cdf0e10cSrcweir             const ::rtl::OUString sServiceName = SfxObjectShell::GetServiceNameFromFactory( sFactory );
568cdf0e10cSrcweir             aDescriptor.put( "DocumentService", sServiceName );
569cdf0e10cSrcweir         }
570cdf0e10cSrcweir 	}
571cdf0e10cSrcweir     else
572cdf0e10cSrcweir     {
573cdf0e10cSrcweir         // compatibility
574cdf0e10cSrcweir         aDescriptor.put( "FileName", aDescriptor.get( "URL" ) );
575cdf0e10cSrcweir     }
576cdf0e10cSrcweir 
577cdf0e10cSrcweir     sal_Bool bLoadSuccess = sal_False;
578cdf0e10cSrcweir 	try
579cdf0e10cSrcweir 	{
580cdf0e10cSrcweir         // extract view releant arguments from the loader args
581cdf0e10cSrcweir         ::comphelper::NamedValueCollection aViewCreationArgs( impl_extractViewCreationArgs( aDescriptor ) );
582cdf0e10cSrcweir 
583cdf0e10cSrcweir         // no model passed from outside? => create one from scratch
584cdf0e10cSrcweir 	    if ( !xModel.is() )
585cdf0e10cSrcweir         {
586cdf0e10cSrcweir             // beforehand, determine the filter to use, and update the descriptor with its information
587cdf0e10cSrcweir             if ( !bInitNewModel )
588cdf0e10cSrcweir             {
589cdf0e10cSrcweir                 impl_determineFilter( aDescriptor );
590cdf0e10cSrcweir             }
591cdf0e10cSrcweir 
592cdf0e10cSrcweir             // create the new doc
593cdf0e10cSrcweir             const ::rtl::OUString sServiceName = aDescriptor.getOrDefault( "DocumentService", ::rtl::OUString() );
594cdf0e10cSrcweir             xModel.set( m_aContext.createComponent( sServiceName ), UNO_QUERY_THROW );
595cdf0e10cSrcweir 
596cdf0e10cSrcweir             // load resp. init it
597cdf0e10cSrcweir             const Reference< XLoadable > xLoadable( xModel, UNO_QUERY_THROW );
598cdf0e10cSrcweir             if ( bInitNewModel )
599cdf0e10cSrcweir             {
600cdf0e10cSrcweir 	            xLoadable->initNew();
601cdf0e10cSrcweir 
602cdf0e10cSrcweir                 impl_removeLoaderArguments( aDescriptor );
603cdf0e10cSrcweir                 xModel->attachResource( ::rtl::OUString(), aDescriptor.getPropertyValues() );
604cdf0e10cSrcweir             }
605cdf0e10cSrcweir             else
606cdf0e10cSrcweir             {
607cdf0e10cSrcweir 		        xLoadable->load( aDescriptor.getPropertyValues() );
608cdf0e10cSrcweir             }
609cdf0e10cSrcweir         }
610cdf0e10cSrcweir         else
611cdf0e10cSrcweir         {
612cdf0e10cSrcweir             // tell the doc its (current) load args.
613cdf0e10cSrcweir             impl_removeLoaderArguments( aDescriptor );
614cdf0e10cSrcweir             xModel->attachResource( xModel->getURL(), aDescriptor.getPropertyValues() );
615cdf0e10cSrcweir         }
616cdf0e10cSrcweir 
617cdf0e10cSrcweir         // get the SfxObjectShell (still needed at the moment)
618cdf0e10cSrcweir         // SfxObjectShellRef is used here ( instead of ...Lock ) since the model is closed below if necessary
619cdf0e10cSrcweir         // SfxObjectShellLock would be even dangerous here, since the lifetime control should be done outside in case of success
620cdf0e10cSrcweir         const SfxObjectShellRef xDoc = impl_findObjectShell( xModel );
621cdf0e10cSrcweir         ENSURE_OR_THROW( xDoc.Is(), "no SfxObjectShell for the given model" );
622cdf0e10cSrcweir 
623cdf0e10cSrcweir         // ensure the ID of the to-be-created view is in the descriptor, if possible
624cdf0e10cSrcweir         const sal_Int16 nViewId = impl_determineEffectiveViewId_nothrow( *xDoc, aDescriptor );
625cdf0e10cSrcweir         const sal_Int16 nViewNo = xDoc->GetFactory().GetViewNo_Impl( nViewId, 0 );
626cdf0e10cSrcweir         const ::rtl::OUString sViewName( xDoc->GetFactory().GetViewFactory( nViewNo ).GetAPIViewName() );
627cdf0e10cSrcweir 
628cdf0e10cSrcweir         // plug the document into the frame
629cdf0e10cSrcweir         impl_createDocumentView( xModel, _rTargetFrame, aViewCreationArgs, sViewName );
630cdf0e10cSrcweir 		bLoadSuccess = sal_True;
631cdf0e10cSrcweir 	}
632cdf0e10cSrcweir 	catch ( Exception& )
633cdf0e10cSrcweir 	{
634cdf0e10cSrcweir         const Any aError( ::cppu::getCaughtException() );
635cdf0e10cSrcweir         if ( !aDescriptor.getOrDefault( "Silent", sal_False ) )
636cdf0e10cSrcweir             impl_handleCaughtError_nothrow( aError, aDescriptor );
637cdf0e10cSrcweir 	}
638cdf0e10cSrcweir 
639cdf0e10cSrcweir     // if loading was not successful, close the document
640cdf0e10cSrcweir     if ( !bLoadSuccess && !bExternalModel )
641cdf0e10cSrcweir     {
642cdf0e10cSrcweir 	    try
643cdf0e10cSrcweir         {
644cdf0e10cSrcweir             const Reference< XCloseable > xCloseable( xModel, UNO_QUERY_THROW );
645cdf0e10cSrcweir 		    xCloseable->close( sal_True );
646cdf0e10cSrcweir 	    }
647cdf0e10cSrcweir         catch ( Exception& )
648cdf0e10cSrcweir 	    {
649cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
650cdf0e10cSrcweir         }
651cdf0e10cSrcweir     }
652cdf0e10cSrcweir 
653cdf0e10cSrcweir 	return bLoadSuccess;
654cdf0e10cSrcweir }
655cdf0e10cSrcweir 
cancel()656cdf0e10cSrcweir void SfxFrameLoader_Impl::cancel() throw( RuntimeException )
657cdf0e10cSrcweir {
658cdf0e10cSrcweir }
659cdf0e10cSrcweir 
SFX_IMPL_SINGLEFACTORY(SfxFrameLoader_Impl)660cdf0e10cSrcweir SFX_IMPL_SINGLEFACTORY( SfxFrameLoader_Impl )
661cdf0e10cSrcweir 
662cdf0e10cSrcweir /* XServiceInfo */
663cdf0e10cSrcweir UNOOUSTRING SAL_CALL SfxFrameLoader_Impl::getImplementationName() throw( RuntimeException )
664cdf0e10cSrcweir {
665cdf0e10cSrcweir     return impl_getStaticImplementationName();
666cdf0e10cSrcweir }
667cdf0e10cSrcweir                                                                                                                                 \
668cdf0e10cSrcweir /* XServiceInfo */
supportsService(const UNOOUSTRING & sServiceName)669cdf0e10cSrcweir sal_Bool SAL_CALL SfxFrameLoader_Impl::supportsService( const UNOOUSTRING& sServiceName ) throw( RuntimeException )
670cdf0e10cSrcweir {
671cdf0e10cSrcweir     UNOSEQUENCE< UNOOUSTRING >  seqServiceNames =   getSupportedServiceNames();
672cdf0e10cSrcweir     const UNOOUSTRING*          pArray          =   seqServiceNames.getConstArray();
673cdf0e10cSrcweir     for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ )
674cdf0e10cSrcweir     {
675cdf0e10cSrcweir         if ( pArray[nCounter] == sServiceName )
676cdf0e10cSrcweir         {
677cdf0e10cSrcweir             return sal_True ;
678cdf0e10cSrcweir         }
679cdf0e10cSrcweir     }
680cdf0e10cSrcweir     return sal_False ;
681cdf0e10cSrcweir }
682cdf0e10cSrcweir 
683cdf0e10cSrcweir /* XServiceInfo */
getSupportedServiceNames()684cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > SAL_CALL SfxFrameLoader_Impl::getSupportedServiceNames() throw( RuntimeException )
685cdf0e10cSrcweir {
686cdf0e10cSrcweir     return impl_getStaticSupportedServiceNames();
687cdf0e10cSrcweir }
688cdf0e10cSrcweir 
689cdf0e10cSrcweir /* Helper for XServiceInfo */
impl_getStaticSupportedServiceNames()690cdf0e10cSrcweir UNOSEQUENCE< UNOOUSTRING > SfxFrameLoader_Impl::impl_getStaticSupportedServiceNames()
691cdf0e10cSrcweir {
692cdf0e10cSrcweir     UNOMUTEXGUARD aGuard( UNOMUTEX::getGlobalMutex() );
693cdf0e10cSrcweir     UNOSEQUENCE< UNOOUSTRING > seqServiceNames( 1 );
694cdf0e10cSrcweir     seqServiceNames.getArray() [0] = UNOOUSTRING::createFromAscii( "com.sun.star.frame.SynchronousFrameLoader" );
695cdf0e10cSrcweir     return seqServiceNames ;
696cdf0e10cSrcweir }
697cdf0e10cSrcweir 
698cdf0e10cSrcweir /* Helper for XServiceInfo */
impl_getStaticImplementationName()699cdf0e10cSrcweir UNOOUSTRING SfxFrameLoader_Impl::impl_getStaticImplementationName()
700cdf0e10cSrcweir {
701cdf0e10cSrcweir     return UNOOUSTRING::createFromAscii( "com.sun.star.comp.office.FrameLoader" );
702cdf0e10cSrcweir }
703cdf0e10cSrcweir 
704cdf0e10cSrcweir /* Helper for registry */
impl_createInstance(const UNOREFERENCE<UNOXMULTISERVICEFACTORY> & xServiceManager)705cdf0e10cSrcweir UNOREFERENCE< UNOXINTERFACE > SAL_CALL SfxFrameLoader_Impl::impl_createInstance( const UNOREFERENCE< UNOXMULTISERVICEFACTORY >& xServiceManager ) throw( UNOEXCEPTION )
706cdf0e10cSrcweir {
707cdf0e10cSrcweir     return UNOREFERENCE< UNOXINTERFACE >( *new SfxFrameLoader_Impl( xServiceManager ) );
708cdf0e10cSrcweir }
709cdf0e10cSrcweir 
710