Update ooo320-m1
[ooovba.git] / sfx2 / source / view / frmload.cxx
blobcab710173119c9b5dd7694d861b1e4f3648edd25
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: frmload.cxx,v $
10 * $Revision: 1.90 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include "frmload.hxx"
36 #include <framework/interaction.hxx>
37 #include <com/sun/star/frame/XLoadable.hpp>
38 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
39 #include <com/sun/star/container/XContainerQuery.hpp>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <com/sun/star/frame/XFrame.hpp>
42 #include <com/sun/star/frame/XModel.hpp>
43 #include <com/sun/star/awt/XWindow.hpp>
44 #include <com/sun/star/lang/XUnoTunnel.hpp>
45 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
46 #include <comphelper/processfactory.hxx>
47 #endif
48 #include <com/sun/star/beans/PropertyValue.hpp>
49 #include <com/sun/star/container/XNameAccess.hpp>
50 #include <com/sun/star/io/XInputStream.hpp>
51 #include <com/sun/star/task/XInteractionHandler.hpp>
52 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
53 #include <com/sun/star/ucb/CommandAbortedException.hpp>
54 #include <com/sun/star/ucb/InteractiveAppException.hpp>
55 #include <com/sun/star/document/XTypeDetection.hpp>
56 #include <framework/interaction.hxx>
58 #ifndef _TOOLKIT_UNOHLP_HXX
59 #include <toolkit/helper/vclunohelper.hxx>
60 #endif
61 #include <ucbhelper/simpleinteractionrequest.hxx>
63 #include <rtl/ustring.h>
64 #include <rtl/logfile.hxx>
65 #include <svtools/itemset.hxx>
66 #include <vcl/window.hxx>
67 #include <svtools/eitem.hxx>
68 #include <svtools/stritem.hxx>
69 #include <tools/urlobj.hxx>
70 #include <vos/mutex.hxx>
71 #include <svtools/sfxecode.hxx>
72 #include <svtools/ehdl.hxx>
73 #include <sot/storinfo.hxx>
74 #include <comphelper/sequenceashashmap.hxx>
75 #include <comphelper/mediadescriptor.hxx>
76 #include <svtools/moduleoptions.hxx>
78 #ifndef css
79 namespace css = ::com::sun::star;
80 #endif
82 #include <sfx2/doctempl.hxx>
83 #include <sfx2/app.hxx>
84 #include <sfx2/request.hxx>
85 #include <sfx2/sfxsids.hrc>
86 #include <sfx2/dispatch.hxx>
87 #include <sfx2/sfxuno.hxx>
88 #include <sfx2/viewfrm.hxx>
89 #include <sfx2/topfrm.hxx>
90 #include <sfx2/frame.hxx>
91 #include <sfx2/docfac.hxx>
92 #include <sfx2/fcontnr.hxx>
93 #include <sfx2/docfile.hxx>
94 #include <sfx2/docfilt.hxx>
95 #include "brokenpackageint.hxx"
96 #include "objshimp.hxx"
98 SfxFrameLoader_Impl::SfxFrameLoader_Impl( const css::uno::Reference< css::lang::XMultiServiceFactory >& /*xFactory*/ )
102 SfxFrameLoader_Impl::~SfxFrameLoader_Impl()
106 const SfxFilter* impl_detectFilterForURL(const ::rtl::OUString& sURL ,
107 const css::uno::Sequence< css::beans::PropertyValue >& rArgs ,
108 const SfxFilterMatcher& rMatcher)
110 static ::rtl::OUString SERVICENAME_TYPEDETECTION = ::rtl::OUString::createFromAscii("com.sun.star.document.TypeDetection");
112 ::rtl::OUString sFilter;
115 if (!sURL.getLength())
116 return 0;
118 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory();
119 if (!xSMGR.is())
120 return 0;
122 css::uno::Reference< css::document::XTypeDetection > xDetect(
123 xSMGR->createInstance(SERVICENAME_TYPEDETECTION),
124 css::uno::UNO_QUERY_THROW);
126 ::comphelper::MediaDescriptor lOrgArgs(rArgs);
127 css::uno::Reference< css::task::XInteractionHandler > xInteraction = lOrgArgs.getUnpackedValueOrDefault(
128 ::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER(),
129 css::uno::Reference< css::task::XInteractionHandler >());
130 css::uno::Reference< css::task::XStatusIndicator > xProgress = lOrgArgs.getUnpackedValueOrDefault(
131 ::comphelper::MediaDescriptor::PROP_STATUSINDICATOR(),
132 css::uno::Reference< css::task::XStatusIndicator >());
134 ::comphelper::SequenceAsHashMap lNewArgs;
135 lNewArgs[::comphelper::MediaDescriptor::PROP_URL()] <<= sURL;
136 if (xInteraction.is())
137 lNewArgs[::comphelper::MediaDescriptor::PROP_INTERACTIONHANDLER()] <<= xInteraction;
138 if (xProgress.is())
139 lNewArgs[::comphelper::MediaDescriptor::PROP_STATUSINDICATOR()] <<= xProgress;
141 css::uno::Sequence< css::beans::PropertyValue > lDescr = lNewArgs.getAsConstPropertyValueList();
142 ::rtl::OUString sType = xDetect->queryTypeByDescriptor(lDescr, sal_True);
143 if (sType.getLength())
145 const SfxFilter* pFilter = rMatcher.GetFilter4EA(sType);
146 if (pFilter)
147 sFilter = pFilter->GetName();
150 catch(const css::uno::RuntimeException& exRun)
151 { throw exRun; }
152 catch(const css::uno::Exception&)
153 { sFilter = ::rtl::OUString(); }
155 const SfxFilter* pFilter = 0;
156 if (sFilter.getLength())
157 pFilter = rMatcher.GetFilter4FilterName(sFilter);
158 return pFilter;
161 sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const css::uno::Sequence< css::beans::PropertyValue >& rArgs ,
162 const css::uno::Reference< css::frame::XFrame >& rFrame )
163 throw( css::uno::RuntimeException )
165 static ::rtl::OUString PROP_URL = ::rtl::OUString::createFromAscii("URL" );
166 static ::rtl::OUString PROP_FILENAME = ::rtl::OUString::createFromAscii("FileName" );
167 static ::rtl::OUString PROP_TYPENAME = ::rtl::OUString::createFromAscii("TypeName" );
168 static ::rtl::OUString PROP_FILTERNAME = ::rtl::OUString::createFromAscii("FilterName" );
169 static ::rtl::OUString PROP_MODEL = ::rtl::OUString::createFromAscii("Model" );
170 static ::rtl::OUString PROP_DOCUMENTSERVICE = ::rtl::OUString::createFromAscii("DocumentService" );
171 static ::rtl::OUString PROP_READONLY = ::rtl::OUString::createFromAscii("ReadOnly" );
172 static ::rtl::OUString PROP_ASTEMPLATE = ::rtl::OUString::createFromAscii("AsTemplate" );
173 static ::rtl::OUString PROP_INTERACTIONHANDLER = ::rtl::OUString::createFromAscii("InteractionHandler");
175 sal_Bool bLoadState = sal_False;
177 // this methods assumes that the filter is detected before, usually by calling the detect() method below
178 ::vos::OGuard aGuard( Application::GetSolarMutex() );
180 RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxFrameLoader::load" );
182 if ( !rFrame.is() )
183 return sal_False;
185 ::comphelper::SequenceAsHashMap lDescriptor(rArgs);
186 String rURL = lDescriptor.getUnpackedValueOrDefault(PROP_URL , ::rtl::OUString() );
187 String aTypeName = lDescriptor.getUnpackedValueOrDefault(PROP_TYPENAME , ::rtl::OUString() );
188 aFilterName = lDescriptor.getUnpackedValueOrDefault(PROP_FILTERNAME , ::rtl::OUString() );
189 String aServiceName = lDescriptor.getUnpackedValueOrDefault(PROP_DOCUMENTSERVICE , ::rtl::OUString() );
190 css::uno::Reference< css::task::XInteractionHandler > xInteraction = lDescriptor.getUnpackedValueOrDefault(PROP_INTERACTIONHANDLER, css::uno::Reference< css::task::XInteractionHandler >());
191 css::uno::Reference< css::frame::XModel > xModel = lDescriptor.getUnpackedValueOrDefault(PROP_MODEL , css::uno::Reference< css::frame::XModel >() );
193 const SfxFilter* pFilter = NULL;
194 const SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher();
196 /* special mode: use already loaded model ...
197 In such case no filter name will be selected and no URL will be given!
198 Such informations are not neccessary. We have to create a new view only
199 and call setComponent() at the corresponding frame. */
200 if( !xModel.is() )
203 // get filter by its name directly ...
204 if( aFilterName.Len() )
205 pFilter = rMatcher.GetFilter4FilterName( aFilterName );
207 // or search the preferred filter for the detected type ...
208 if( !pFilter && aTypeName.Len() )
209 pFilter = rMatcher.GetFilter4EA(aTypeName);
211 // or use given document service for detection too!
212 if (!pFilter && aServiceName.Len())
214 ::comphelper::SequenceAsHashMap lQuery;
216 if (aServiceName.Len())
217 lQuery[::rtl::OUString::createFromAscii("DocumentService")] <<= ::rtl::OUString(aServiceName);
219 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
220 ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerQuery > xQuery ( xServiceManager->createInstance( DEFINE_CONST_UNICODE( "com.sun.star.document.FilterFactory" ) ), ::com::sun::star::uno::UNO_QUERY );
222 SfxFilterFlags nMust = SFX_FILTER_IMPORT;
223 SfxFilterFlags nDont = SFX_FILTER_NOTINSTALLED;
225 ::com::sun::star::uno::Reference < com::sun::star::container::XEnumeration > xEnum = xQuery->createSubSetEnumerationByProperties(lQuery.getAsConstNamedValueList());
226 while ( xEnum->hasMoreElements() )
228 ::comphelper::SequenceAsHashMap aType( xEnum->nextElement() );
229 aFilterName = aType.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("Name"), ::rtl::OUString());
230 if (!aFilterName.Len())
231 continue;
232 pFilter = rMatcher.GetFilter4FilterName(aFilterName);
233 if (!pFilter)
234 continue;
235 SfxFilterFlags nFlags = pFilter->GetFilterFlags();
236 if (
237 ((nFlags & nMust) == nMust) &&
238 (!(nFlags & nDont ))
241 break;
243 pFilter = 0; //! in case we reach end of enumeration we must have a valid value ...
247 // or use interaction to ask user for right filter.
248 if ( !pFilter && xInteraction.is() && rURL.Len() )
250 ::framework::RequestFilterSelect* pRequest = new ::framework::RequestFilterSelect( rURL );
251 css::uno::Reference< css::task::XInteractionRequest > xRequest ( pRequest );
252 xInteraction->handle( xRequest );
253 if( !pRequest->isAbort() )
255 aFilterName = pRequest->getFilter();
256 pFilter = rMatcher.GetFilter4FilterName( aFilterName );
260 if( !pFilter )
261 return sal_False;
263 aTypeName = pFilter->GetTypeName();
264 // use filter names without prefix
265 aFilterName = pFilter->GetFilterName();
267 // If detected filter indicates using of an own template format
268 // add property "AsTemplate" to descriptor. But supress this step
269 // if such property already exists.
270 if( pFilter->IsOwnTemplateFormat())
272 ::comphelper::SequenceAsHashMap::iterator pIt = lDescriptor.find(PROP_ASTEMPLATE);
273 if (pIt == lDescriptor.end())
274 lDescriptor[PROP_ASTEMPLATE] <<= sal_True;
278 xFrame = rFrame;
280 // Achtung: beim Abraeumen der Objekte kann die SfxApp destruiert werden, vorher noch Deinitialize_Impl rufen
281 SfxApplication* pApp = SFX_APP();
283 // Attention! Because lDescriptor is a copy of rArgs
284 // and was might by changed (e.g. for AsTemplate)
285 // move all changes there back!
286 SfxAllItemSet aSet( pApp->GetPool() );
287 TransformParameters( SID_OPENDOC, lDescriptor.getAsConstPropertyValueList(), aSet );
289 SFX_ITEMSET_ARG( &aSet, pRefererItem, SfxStringItem, SID_REFERER, FALSE );
290 if ( !pRefererItem )
291 aSet.Put( SfxStringItem( SID_REFERER, String() ) );
293 SfxFrame* pFrame=0;
294 for ( pFrame = SfxFrame::GetFirst(); pFrame; pFrame = SfxFrame::GetNext( *pFrame ) )
296 if ( pFrame->GetFrameInterface() == xFrame )
297 break;
300 BOOL bFrameCreated = FALSE;
301 if ( !pFrame )
303 pFrame = SfxTopFrame::Create( rFrame );
304 bFrameCreated = TRUE;
307 if ( xModel.is() )
309 // !TODO: replace by ViewFactory
310 if ( pFrame->GetFrameInterface()->getController().is() )
312 // remove old component
313 // if a frame was created already, it can't be an SfxComponent!
314 pFrame->GetFrameInterface()->setComponent( 0, 0 );
315 if ( !bFrameCreated )
316 pFrame = SfxTopFrame::Create( rFrame );
319 aSet.Put( SfxFrameItem( SID_DOCFRAME, pFrame ) );
321 for ( SfxObjectShell* pDoc = SfxObjectShell::GetFirst( NULL, FALSE ); pDoc; pDoc = SfxObjectShell::GetNext( *pDoc, NULL, FALSE ) )
323 if ( xModel == pDoc->GetModel() )
325 pFrame->SetItemSet_Impl( &aSet );
326 ::comphelper::SequenceAsHashMap lUpdateDescr( lDescriptor );
327 lUpdateDescr.erase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Model" ) ) );
328 lUpdateDescr.erase( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) ) );
330 xModel->attachResource( rURL, lUpdateDescr.getAsConstPropertyValueList() );
331 return pFrame->InsertDocument( pDoc );
335 DBG_ERROR("Model is not based on SfxObjectShell - wrong frame loader use!");
336 return sal_False;
339 // check for the URL pattern of our factory URLs
340 SfxFrameWeak wFrame = pFrame;
341 String aPrefix = String::CreateFromAscii( "private:factory/" );
342 String aFact( rURL );
343 if ( aPrefix.Len() == aFact.Match( aPrefix ) )
345 if ( !aServiceName.Len() )
346 aServiceName = SfxObjectShell::GetServiceNameFromFactory( rURL );
348 // it's a factory URL
349 aFact.Erase( 0, aPrefix.Len() );
351 // look for parameters
352 String aParam;
353 USHORT nPos = aFact.Search( '?' );
354 if ( nPos != STRING_NOTFOUND )
356 // currently only the "slot" parameter is supported
357 USHORT nParamPos = aFact.Search( String::CreateFromAscii("slot="), nPos );
358 if ( nParamPos != STRING_NOTFOUND )
359 aParam = aFact.Copy( nParamPos+5, aFact.Len() );
360 aFact.Erase( nPos, aFact.Len() );
363 WildCard aSearchedFac( aFact.EraseAllChars('4').ToUpperAscii() );
364 SFX_ITEMSET_ARG( &aSet, pDocumentTitleItem, SfxStringItem, SID_DOCINFO_TITLE, FALSE );
365 INetURLObject aObj( rURL );
367 if ( aParam.Len() )
369 sal_uInt16 nSlotId = (sal_uInt16) aParam.ToInt32();
370 SfxRequest aReq( nSlotId, SFX_CALLMODE_SYNCHRON, pApp->GetPool() );
371 aReq.AppendItem( SfxFrameItem ( SID_DOCFRAME, pFrame ) );
372 const SfxPoolItem* pRet = pApp->ExecuteSlot( aReq );
373 if ( pRet )
375 // default must be set to true, because some return values
376 // cant be checked ... but indicates "success"!
377 bLoadState = sal_True;
379 // On the other side some special slots return a boolean state,
380 // which can be set to FALSE.
381 SfxBoolItem *pItem = PTR_CAST( SfxBoolItem, pRet );
382 if (pItem)
383 bLoadState = pItem->GetValue();
385 else
386 bLoadState = sal_False;
388 if ( !bLoadState && bFrameCreated && wFrame && !wFrame->GetCurrentDocument() )
390 css::uno::Reference< css::frame::XFrame > axFrame;
391 wFrame->SetFrameInterface_Impl( axFrame );
392 wFrame->DoClose();
395 xFrame.clear();
396 xListener.clear();
397 return bLoadState;
400 String sTemplateURL;
401 SFX_ITEMSET_ARG( &aSet, pTemplateRegionItem, SfxStringItem, SID_TEMPLATE_REGIONNAME, FALSE );
402 SFX_ITEMSET_ARG( &aSet, pTemplateNameItem, SfxStringItem, SID_TEMPLATE_NAME, FALSE );
403 if ( pTemplateRegionItem && pTemplateNameItem )
405 SfxDocumentTemplates aTmpFac;
406 aTmpFac.GetFull( pTemplateRegionItem->GetValue(), pTemplateNameItem->GetValue(), sTemplateURL );
408 else
410 sTemplateURL = SfxObjectFactory::GetStandardTemplate( aServiceName );
413 BOOL bUseTemplate = (sTemplateURL.Len()>0);
414 if( bUseTemplate )
416 // #i21583#
417 // Forget the filter, which was detected for the corresponding "private:factory/xxx" URL.
418 // We must use the right filter, matching to this document ... not to the private URL!
419 const SfxFilter* pTemplateFilter = impl_detectFilterForURL(sTemplateURL, rArgs, rMatcher);
420 if (pTemplateFilter)
422 pFilter = pTemplateFilter;
423 aFilterName = pTemplateFilter->GetName();
424 // standard template set -> load it "AsTemplate"
425 aSet.Put( SfxStringItem ( SID_FILE_NAME, sTemplateURL ) );
426 aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) );
429 // #119268#
430 // something is wrong with the set default template (e.g. unknown format, missing file etcpp)
431 // The we have to jump into the following special code, where "private:factory/ URL's are handled.
432 // We cant "load" such private/factory URL's!
433 else
434 bUseTemplate = FALSE;
437 if ( !bUseTemplate )
439 // execute "NewDocument" request
440 /* Attention!
441 #107913#
442 Pointers can't be used to check if two objects are equals!
443 E.g. the memory manager can reuse freed memory ...
444 and then the holded copy of a pointer will point to another
445 (and different!) object - may using the same type then before.
446 In such case we compare one object with itself ...
448 SfxRequest aReq( SID_NEWDOCDIRECT, SFX_CALLMODE_SYNCHRON, aSet );
449 aReq.AppendItem( SfxFrameItem( SID_DOCFRAME, pFrame ) );
450 aReq.AppendItem( SfxStringItem( SID_NEWDOCDIRECT, aFact ) );
452 if ( pDocumentTitleItem )
453 aReq.AppendItem( *pDocumentTitleItem );
455 const SfxPoolItem* pRet = pApp->NewDocDirectExec_ImplOld(aReq);
456 if (pRet)
458 // default must be set to true, because some return values
459 // cant be checked ... but indicates "success"!
460 bLoadState = sal_True;
462 // On the other side some special slots return a boolean state,
463 // which can be set to FALSE.
464 SfxBoolItem *pItem = PTR_CAST( SfxBoolItem, pRet );
465 if (pItem)
466 bLoadState = pItem->GetValue();
468 else
469 bLoadState = sal_False;
471 if ( !bLoadState && bFrameCreated && wFrame && !wFrame->GetCurrentDocument() )
473 css::uno::Reference< css::frame::XFrame > axFrame;
474 wFrame->SetFrameInterface_Impl( axFrame );
475 wFrame->DoClose();
478 xFrame.clear();
479 xListener.clear();
480 return bLoadState;
483 else
485 // load the desired file
486 aSet.Put( SfxStringItem ( SID_FILE_NAME, rURL ) );
489 aSet.Put( SfxFrameItem( SID_DOCFRAME, pFrame ) );
490 aSet.Put( SfxUnoAnyItem( SID_FILLFRAME, css::uno::makeAny(xFrame) ) );
491 aSet.Put( SfxStringItem( SID_FILTER_NAME, aFilterName ) );
493 // !TODO: replace by direct construction of model (needs view factory)
494 DBG_ASSERT( pFilter, "No filter set!" );
495 if ( !pFilter )
496 return sal_False;
498 sal_Bool bDisaster = sal_False;
499 SfxObjectShell* pDoc = SfxObjectShell::CreateObject( pFilter->GetServiceName() );
500 if ( pDoc )
502 css::uno::Reference< css::frame::XLoadable > xLoadable = css::uno::Reference< css::frame::XLoadable >( pDoc->GetModel(), css::uno::UNO_QUERY );
503 css::uno::Sequence < css::beans::PropertyValue > aLoadArgs;
504 TransformItems( SID_OPENDOC, aSet, aLoadArgs );
507 xLoadable->load( aLoadArgs );
509 SfxMedium* pDocMedium = pDoc->GetMedium();
510 BOOL bHidden = FALSE;
511 SFX_ITEMSET_ARG( pDocMedium->GetItemSet(), pHidItem, SfxBoolItem, SID_HIDDEN, sal_False);
512 if ( pHidItem )
513 bHidden = pHidItem->GetValue();
515 // !TODO: will be done by Framework!
516 pDocMedium->SetUpdatePickList( !bHidden );
519 #121119#
520 We dont know why pFrame can be corrupt here.
521 But if it was deleted it shouldnt exists inside our global list.
522 May be we can use the damaged pointer to detect if it was removed from
523 this global list.
525 SfxFrame* pTmp=0;
526 for ( pTmp = SfxFrame::GetFirst(); pTmp; pTmp = SfxFrame::GetNext( *pTmp ) )
528 if ( pFrame == pTmp )
529 break;
532 if ( pTmp == pFrame )
534 // !TODO: replace by ViewFactory
535 if ( pFrame->GetFrameInterface()->getController().is() )
537 // remove old component
538 // if a frame was created already, it can't be an SfxComponent!
539 // pFrame->GetFrameInterface()->setComponent( 0, 0 );
540 if ( !bFrameCreated )
541 pFrame = SfxTopFrame::Create( rFrame );
544 wFrame = pFrame;
545 aSet.Put( SfxFrameItem( SID_DOCFRAME, pFrame ) );
546 if( pFrame->InsertDocument( pDoc ) )
548 pFrame->GetCurrentViewFrame()->UpdateDocument_Impl();
549 String aURL = pDoc->GetMedium()->GetName();
550 SFX_APP()->Broadcast( SfxStringHint( SID_OPENURL, aURL ) );
551 bLoadState = sal_True;
553 else
554 bDisaster = sal_True;
556 else
558 DBG_ERROR("#121119# You found the reason for a stacktrace! Frame destroyed while loading document.");
559 bLoadState = sal_False;
562 catch ( css::uno::Exception& )
564 bDisaster = sal_True;
567 if ( bDisaster )
569 if ( wFrame && !wFrame->GetCurrentDocument() )
571 // document loading was not successful; close SfxFrame (but not XFrame!)
572 css::uno::Reference< css::frame::XFrame > axFrame;
573 wFrame->SetFrameInterface_Impl( axFrame );
574 wFrame->DoClose();
575 aSet.ClearItem( SID_DOCFRAME );
578 css::uno::Reference< css::util::XCloseable > xCloseable( xLoadable, css::uno::UNO_QUERY );
579 if ( xCloseable.is() )
581 try {
582 xCloseable->close( sal_True );
583 } catch ( css::uno::Exception& )
589 xFrame.clear();
590 xListener.clear();
591 return bLoadState;
594 void SfxFrameLoader_Impl::cancel() throw( RUNTIME_EXCEPTION )
598 SFX_IMPL_SINGLEFACTORY( SfxFrameLoader_Impl )
600 /* XServiceInfo */
601 UNOOUSTRING SAL_CALL SfxFrameLoader_Impl::getImplementationName() throw( UNORUNTIMEEXCEPTION )
603 return impl_getStaticImplementationName();
606 /* XServiceInfo */
607 sal_Bool SAL_CALL SfxFrameLoader_Impl::supportsService( const UNOOUSTRING& sServiceName ) throw( UNORUNTIMEEXCEPTION )
609 UNOSEQUENCE< UNOOUSTRING > seqServiceNames = getSupportedServiceNames();
610 const UNOOUSTRING* pArray = seqServiceNames.getConstArray();
611 for ( sal_Int32 nCounter=0; nCounter<seqServiceNames.getLength(); nCounter++ )
613 if ( pArray[nCounter] == sServiceName )
615 return sal_True ;
618 return sal_False ;
621 /* XServiceInfo */
622 UNOSEQUENCE< UNOOUSTRING > SAL_CALL SfxFrameLoader_Impl::getSupportedServiceNames() throw( UNORUNTIMEEXCEPTION )
624 return impl_getStaticSupportedServiceNames();
627 /* Helper for XServiceInfo */
628 UNOSEQUENCE< UNOOUSTRING > SfxFrameLoader_Impl::impl_getStaticSupportedServiceNames()
630 UNOMUTEXGUARD aGuard( UNOMUTEX::getGlobalMutex() );
631 UNOSEQUENCE< UNOOUSTRING > seqServiceNames( 1 );
632 seqServiceNames.getArray() [0] = UNOOUSTRING::createFromAscii( "com.sun.star.frame.SynchronousFrameLoader" );
633 return seqServiceNames ;
636 /* Helper for XServiceInfo */
637 UNOOUSTRING SfxFrameLoader_Impl::impl_getStaticImplementationName()
639 return UNOOUSTRING::createFromAscii( "com.sun.star.comp.office.FrameLoader" );
642 /* Helper for registry */
643 UNOREFERENCE< UNOXINTERFACE > SAL_CALL SfxFrameLoader_Impl::impl_createInstance( const UNOREFERENCE< UNOXMULTISERVICEFACTORY >& xServiceManager ) throw( UNOEXCEPTION )
645 return UNOREFERENCE< UNOXINTERFACE >( *new SfxFrameLoader_Impl( xServiceManager ) );