diff options
author | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2009-11-25 09:33:27 +0100 |
---|---|---|
committer | Frank Schoenheit [fs] <frank.schoenheit@sun.com> | 2009-11-25 09:33:27 +0100 |
commit | 4f36183eb9be25a723afee4b4e2b4555591ee903 (patch) | |
tree | 6868399ae97a3aa29793ee3ac97fac4ec1099072 /sfx2 | |
parent | 49e67cf6135582501b38e483765bb213068c46f4 (diff) |
broke down ::load into smaller pieces
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/inc/frmload.hxx | 45 | ||||
-rw-r--r-- | sfx2/source/view/frmload.cxx | 379 |
2 files changed, 240 insertions, 184 deletions
diff --git a/sfx2/inc/frmload.hxx b/sfx2/inc/frmload.hxx index 5053f6a2a8f8..4d6207bcb22f 100644 --- a/sfx2/inc/frmload.hxx +++ b/sfx2/inc/frmload.hxx @@ -52,6 +52,7 @@ #include <tools/link.hxx> #include <tools/string.hxx> #include <comphelper/componentcontext.hxx> +#include <comphelper/namedvaluecollection.hxx> class SfxFilter; class SfxFilterMatcher; @@ -59,13 +60,14 @@ class SfxFrame; #include <sfx2/sfxuno.hxx> +class SfxFrameWeak; + class SfxFrameLoader_Impl : public ::cppu::WeakImplHelper2< ::com::sun::star::frame::XSynchronousFrameLoader, ::com::sun::star::lang::XServiceInfo > { ::comphelper::ComponentContext m_aContext; public: SfxFrameLoader_Impl( const ::com::sun::star::uno::Reference < ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory ); - virtual ~SfxFrameLoader_Impl(); SFX_DECL_XSERVICEINFO @@ -75,6 +77,9 @@ public: virtual sal_Bool SAL_CALL load( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgs, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _rxFrame ) throw( ::com::sun::star::uno::RuntimeException ); virtual void SAL_CALL cancel() throw( ::com::sun::star::uno::RuntimeException ); +protected: + virtual ~SfxFrameLoader_Impl(); + private: const SfxFilter* impl_getFilterFromServiceName_nothrow( const ::rtl::OUString& _rServiceName ) const; ::rtl::OUString impl_askForFilter_nothrow( @@ -84,22 +89,50 @@ private: const SfxFilter* impl_detectFilterForURL( const ::rtl::OUString& _rURL, - const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& _rArgs, + const ::comphelper::NamedValueCollection& i_rDescriptor, const SfxFilterMatcher& rMatcher ) const; sal_Bool impl_createNewDocWithSlotParam( - const sal_uInt16 _nSlotID, - SfxFrame* _pFrame + const USHORT _nSlotID, + SfxFrame& i_rFrame ); sal_Bool impl_createNewDoc( - const SfxItemSet& _rSet, - SfxFrame* _pFrame, + const ::comphelper::NamedValueCollection& i_rDescriptor, + SfxFrame& i_rFrame, const ::rtl::OUString& _rFactoryURL ); void impl_ensureValidFrame_throw( const SfxFrame* _pFrame ); + + const SfxFilter* impl_determineFilter( + ::comphelper::NamedValueCollection& io_rDescriptor, + const SfxFilterMatcher& rMatcher + ); + + SfxAllItemSet impl_getInitialItemSet( + const ::comphelper::NamedValueCollection& i_rDescriptor + ) const; + + sal_Bool impl_loadExistingDocument( + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& i_rxDocument, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rxTargetFrame, + const ::comphelper::NamedValueCollection& i_rDescriptor + ); + + sal_Bool impl_cleanUp( + const sal_Bool i_bSuccess, + const SfxFrameWeak& i_wFrame + ); + + const SfxFilter* impl_determineTemplateDocument( + ::comphelper::NamedValueCollection& io_rDescriptor + ) const; + + USHORT impl_findSlotParam( + ::rtl::OUString& io_rFactoryURL + ); }; #endif diff --git a/sfx2/source/view/frmload.cxx b/sfx2/source/view/frmload.cxx index cab90ed821c4..bc566793e786 100644 --- a/sfx2/source/view/frmload.cxx +++ b/sfx2/source/view/frmload.cxx @@ -113,7 +113,7 @@ SfxFrameLoader_Impl::~SfxFrameLoader_Impl() // -------------------------------------------------------------------------------------------------------------------- const SfxFilter* SfxFrameLoader_Impl::impl_detectFilterForURL( const ::rtl::OUString& sURL, - const Sequence< PropertyValue >& rArgs, const SfxFilterMatcher& rMatcher ) const + const ::comphelper::NamedValueCollection& i_rDescriptor, const SfxFilterMatcher& rMatcher ) const { ::rtl::OUString sFilter; try @@ -128,11 +128,10 @@ const SfxFilter* SfxFrameLoader_Impl::impl_detectFilterForURL( const ::rtl::OUSt ::comphelper::NamedValueCollection aNewArgs; aNewArgs.put( "URL", sURL ); - ::comphelper::NamedValueCollection aOrgArgs( rArgs ); - if ( aOrgArgs.has( "InteractionHandler" ) ) - aNewArgs.put( "InteractionHandler", aOrgArgs.get( "InteractionHandler" ) ); - if ( aOrgArgs.has( "StatusIndicator" ) ) - aNewArgs.put( "StatusIndicator", aOrgArgs.get( "StatusIndicator" ) ); + if ( i_rDescriptor.has( "InteractionHandler" ) ) + aNewArgs.put( "InteractionHandler", i_rDescriptor.get( "InteractionHandler" ) ); + if ( i_rDescriptor.has( "StatusIndicator" ) ) + aNewArgs.put( "StatusIndicator", i_rDescriptor.get( "StatusIndicator" ) ); Sequence< PropertyValue > aQueryArgs( aNewArgs.getPropertyValues() ); ::rtl::OUString sType = xDetect->queryTypeByDescriptor( aQueryArgs, sal_True ); @@ -250,241 +249,270 @@ namespace } // -------------------------------------------------------------------------------------------------------------------- -sal_Bool SfxFrameLoader_Impl::impl_createNewDocWithSlotParam( const sal_uInt16 _nSlotID, SfxFrame* _pFrame ) +sal_Bool SfxFrameLoader_Impl::impl_createNewDocWithSlotParam( const USHORT _nSlotID, SfxFrame& i_rFrame ) { SfxApplication* pApp = SFX_APP(); SfxRequest aRequest( _nSlotID, SFX_CALLMODE_SYNCHRON, pApp->GetPool() ); - aRequest.AppendItem( SfxFrameItem ( SID_DOCFRAME, _pFrame ) ); + aRequest.AppendItem( SfxFrameItem ( SID_DOCFRAME, &i_rFrame ) ); return lcl_getDispatchResult( pApp->ExecuteSlot( aRequest ) ); } // -------------------------------------------------------------------------------------------------------------------- -sal_Bool SfxFrameLoader_Impl::impl_createNewDoc( const SfxItemSet& _rSet, SfxFrame* _pFrame, const ::rtl::OUString& _rFactoryURL ) +sal_Bool SfxFrameLoader_Impl::impl_createNewDoc( const ::comphelper::NamedValueCollection& i_rDescriptor, SfxFrame& i_rFrame, + const ::rtl::OUString& _rFactoryURL ) { - SfxApplication* pApp = SFX_APP(); + SfxAllItemSet aSet( impl_getInitialItemSet( i_rDescriptor ) ); - SfxRequest aRequest( SID_NEWDOCDIRECT, SFX_CALLMODE_SYNCHRON, _rSet ); - aRequest.AppendItem( SfxFrameItem( SID_DOCFRAME, _pFrame ) ); + SfxRequest aRequest( SID_NEWDOCDIRECT, SFX_CALLMODE_SYNCHRON, aSet ); + aRequest.AppendItem( SfxFrameItem( SID_DOCFRAME, &i_rFrame ) ); aRequest.AppendItem( SfxStringItem( SID_NEWDOCDIRECT, _rFactoryURL ) ); - SFX_ITEMSET_ARG( &_rSet, pDocumentTitleItem, SfxStringItem, SID_DOCINFO_TITLE, FALSE ); + SFX_ITEMSET_ARG( &aSet, pDocumentTitleItem, SfxStringItem, SID_DOCINFO_TITLE, FALSE ); if ( pDocumentTitleItem ) aRequest.AppendItem( *pDocumentTitleItem ); - return lcl_getDispatchResult( pApp->NewDocDirectExec_ImplOld( aRequest ) ); + return lcl_getDispatchResult( SFX_APP()->NewDocDirectExec_ImplOld( aRequest ) ); } // -------------------------------------------------------------------------------------------------------------------- -sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const css::uno::Sequence< PropertyValue >& rArgs, - const Reference< css::frame::XFrame >& _rTargetFrame ) - throw( css::uno::RuntimeException ) +const SfxFilter* SfxFrameLoader_Impl::impl_determineFilter( ::comphelper::NamedValueCollection& io_rDescriptor, const SfxFilterMatcher& rMatcher ) { - ENSURE_OR_THROW( _rTargetFrame.is(), "illegal NULL frame" ); + const ::rtl::OUString sURL = io_rDescriptor.getOrDefault( "URL", ::rtl::OUString() ); + const ::rtl::OUString sTypeName = io_rDescriptor.getOrDefault( "TypeName", ::rtl::OUString() ); + const ::rtl::OUString sFilterName = io_rDescriptor.getOrDefault( "FilterName", ::rtl::OUString() ); + const ::rtl::OUString sServiceName = io_rDescriptor.getOrDefault( "DocumentService", ::rtl::OUString() ); + const Reference< XInteractionHandler > + xInteraction = io_rDescriptor.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ); - // this methods assumes that the filter is detected before, usually by calling the detect() method below - ::vos::OGuard aGuard( Application::GetSolarMutex() ); + const SfxFilter* pFilter = NULL; - RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxFrameLoader::load" ); + // get filter by its name directly ... + if ( sFilterName.getLength() ) + pFilter = rMatcher.GetFilter4FilterName( sFilterName ); - ::comphelper::NamedValueCollection aDescriptor( rArgs ); - const ::rtl::OUString sURL = aDescriptor.getOrDefault( "URL", ::rtl::OUString() ); - const ::rtl::OUString sTypeName = aDescriptor.getOrDefault( "TypeName", ::rtl::OUString() ); - ::rtl::OUString sFilterName = aDescriptor.getOrDefault( "FilterName", ::rtl::OUString() ); - const ::rtl::OUString sServiceName = aDescriptor.getOrDefault( "DocumentService", ::rtl::OUString() ); - const Reference< XModel > xModel = aDescriptor.getOrDefault( "Model", Reference< XModel >() ); - const Reference< XInteractionHandler > - xInteraction = aDescriptor.getOrDefault( "InteractionHandler", Reference< XInteractionHandler >() ); + // or search the preferred filter for the detected type ... + if ( !pFilter && sTypeName.getLength() ) + pFilter = rMatcher.GetFilter4EA( sTypeName ); - const SfxFilter* pFilter = NULL; - const SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher(); + // or use given document service for detection too! + if ( !pFilter && sServiceName.getLength() ) + pFilter = impl_getFilterFromServiceName_nothrow( sServiceName ); - /* special mode: use already loaded model ... - In such case no filter name will be selected and no URL will be given! - Such informations are not neccessary. We have to create a new view only - and call setComponent() at the corresponding frame. */ - if( !xModel.is() ) + // or use interaction to ask user for right filter. + if ( !pFilter && xInteraction.is() && sURL.getLength() ) { + ::rtl::OUString sSelectedFilter = impl_askForFilter_nothrow( xInteraction, sURL ); + if ( sSelectedFilter.getLength() ) + pFilter = rMatcher.GetFilter4FilterName( sSelectedFilter ); + } - // get filter by its name directly ... - if ( sFilterName.getLength() ) - pFilter = rMatcher.GetFilter4FilterName( sFilterName ); + if ( pFilter ) + io_rDescriptor.put( "FilterName", ::rtl::OUString( pFilter->GetFilterName() ) ); - // or search the preferred filter for the detected type ... - if ( !pFilter && sTypeName.getLength() ) - pFilter = rMatcher.GetFilter4EA( sTypeName ); + return pFilter; +} - // or use given document service for detection too! - if ( !pFilter && sServiceName.getLength() ) - pFilter = impl_getFilterFromServiceName_nothrow( sServiceName ); +// -------------------------------------------------------------------------------------------------------------------- +SfxAllItemSet SfxFrameLoader_Impl::impl_getInitialItemSet( const ::comphelper::NamedValueCollection& i_rDescriptor ) const +{ + SfxAllItemSet aSet( SFX_APP()->GetPool() ); + TransformParameters( SID_OPENDOC, i_rDescriptor.getPropertyValues(), aSet ); - // or use interaction to ask user for right filter. - if ( !pFilter && xInteraction.is() && sURL.getLength() ) - { - ::rtl::OUString sSelectedFilter = impl_askForFilter_nothrow( xInteraction, sURL ); - if ( sSelectedFilter.getLength() ) - pFilter = rMatcher.GetFilter4FilterName( sSelectedFilter ); - } + SFX_ITEMSET_ARG( &aSet, pRefererItem, SfxStringItem, SID_REFERER, FALSE ); + if ( !pRefererItem ) + aSet.Put( SfxStringItem( SID_REFERER, String() ) ); - if( !pFilter ) - return sal_False; + return aSet; +} + +// -------------------------------------------------------------------------------------------------------------------- +sal_Bool SfxFrameLoader_Impl::impl_loadExistingDocument( const Reference< XModel >& i_rxDocument, + const Reference< XFrame >& i_rxTargetFrame, + const ::comphelper::NamedValueCollection& i_rDescriptor ) +{ + ENSURE_OR_THROW( i_rxDocument.is() && i_rxTargetFrame.is(), "invallid model/frame" ); - // use filter names without prefix - sFilterName = pFilter->GetFilterName(); + SfxAllItemSet aSet( impl_getInitialItemSet( i_rDescriptor ) ); - // If detected filter indicates using of an own template format - // add property "AsTemplate" to descriptor. But suppress this step - // if such property already exists. - if ( pFilter->IsOwnTemplateFormat() && !aDescriptor.has( "AsTemplate" ) ) + SfxTopFrame* pTargetFrame = SfxTopFrame::Create( i_rxTargetFrame ); + aSet.Put( SfxFrameItem( SID_DOCFRAME, pTargetFrame ) ); + + for ( SfxObjectShell* pDoc = SfxObjectShell::GetFirst( NULL, FALSE ); pDoc; pDoc = SfxObjectShell::GetNext( *pDoc, NULL, FALSE ) ) + { + if ( i_rxDocument == pDoc->GetModel() ) { - aDescriptor.put( "AsTemplate", sal_Bool( sal_True ) ); + i_rxDocument->attachResource( i_rDescriptor.getOrDefault( "URL", ::rtl::OUString() ), i_rDescriptor.getPropertyValues() ); + + pTargetFrame->SetItemSet_Impl( &aSet ); + return pTargetFrame->InsertDocument_Impl( *pDoc ); } } - // Achtung: beim Abraeumen der Objekte kann die SfxApp destruiert werden, vorher noch Deinitialize_Impl rufen - SfxApplication* pApp = SFX_APP(); + DBG_ERROR("Model is not based on SfxObjectShell - wrong frame loader use!"); + return sal_False; +} - // attention: Don't use rArgs, but instead aDescriptor, which is rArgs plus some - // changes - SfxAllItemSet aSet( pApp->GetPool() ); - TransformParameters( SID_OPENDOC, aDescriptor.getPropertyValues(), aSet ); +// -------------------------------------------------------------------------------------------------------------------- +sal_Bool SfxFrameLoader_Impl::impl_cleanUp( const sal_Bool i_bSuccess, const SfxFrameWeak& i_wFrame ) +{ + if ( !i_bSuccess && i_wFrame && !i_wFrame->GetCurrentDocument() ) + { + i_wFrame->SetFrameInterface_Impl( NULL ); + i_wFrame->DoClose(); + } - SFX_ITEMSET_ARG( &aSet, pRefererItem, SfxStringItem, SID_REFERER, FALSE ); - if ( !pRefererItem ) - aSet.Put( SfxStringItem( SID_REFERER, String() ) ); + return i_bSuccess; +} - SfxTopFrame* pTargetFrame = SfxTopFrame::Create( _rTargetFrame ); - if ( xModel.is() ) +// -------------------------------------------------------------------------------------------------------------------- +const SfxFilter* SfxFrameLoader_Impl::impl_determineTemplateDocument( ::comphelper::NamedValueCollection& io_rDescriptor ) const +{ + const ::rtl::OUString sTemplateRegioName = io_rDescriptor.getOrDefault( "TemplateRegionName", ::rtl::OUString() ); + const ::rtl::OUString sTemplateName = io_rDescriptor.getOrDefault( "TemplateName", ::rtl::OUString() ); + const ::rtl::OUString sServiceName = io_rDescriptor.getOrDefault( "DocumentService", ::rtl::OUString() ); + const ::rtl::OUString sURL = io_rDescriptor.getOrDefault( "URL", ::rtl::OUString() ); + + // determine the full URL of the template to use, if any + String sTemplateURL; + if ( sTemplateRegioName.getLength() && sTemplateName.getLength() ) { - aSet.Put( SfxFrameItem( SID_DOCFRAME, pTargetFrame ) ); + SfxDocumentTemplates aTmpFac; + aTmpFac.GetFull( sTemplateRegioName, sTemplateName, sTemplateURL ); + } + else + { + if ( sServiceName.getLength() ) + sTemplateURL = SfxObjectFactory::GetStandardTemplate( sServiceName ); + else + sTemplateURL = SfxObjectFactory::GetStandardTemplate( SfxObjectShell::GetServiceNameFromFactory( sURL ) ); + } - for ( SfxObjectShell* pDoc = SfxObjectShell::GetFirst( NULL, FALSE ); pDoc; pDoc = SfxObjectShell::GetNext( *pDoc, NULL, FALSE ) ) + if ( sTemplateURL.Len() > 0 ) + { + // detect the filter for the template. Might still be NULL (if the template is broken, or does not + // exist, or some such), but this is handled by our caller the same way as if no template/URL was present. + const SfxFilter* pTemplateFilter = impl_detectFilterForURL( sTemplateURL, io_rDescriptor, SFX_APP()->GetFilterMatcher() ); + if ( pTemplateFilter ) { - if ( xModel == pDoc->GetModel() ) - { - pTargetFrame->SetItemSet_Impl( &aSet ); + // load the template document, but, well, "as template" + io_rDescriptor.put( "FilterName", ::rtl::OUString( pTemplateFilter->GetName() ) ); + io_rDescriptor.put( "FileName", ::rtl::OUString( sTemplateURL ) ); + io_rDescriptor.put( "AsTemplate", sal_True ); + } + return pTemplateFilter; + } - aDescriptor.remove( "Model" ); - aDescriptor.remove( "URL" ); + return NULL; +} - xModel->attachResource( sURL, aDescriptor.getPropertyValues() ); +// -------------------------------------------------------------------------------------------------------------------- +USHORT SfxFrameLoader_Impl::impl_findSlotParam( ::rtl::OUString& io_rFactoryURL ) +{ + ::rtl::OUString sSlotParam; + const sal_Int32 nParamPos = io_rFactoryURL.indexOf( '?' ); + if ( nParamPos >= 0 ) + { + // currently only the "slot" parameter is supported + const sal_Int32 nSlotPos = io_rFactoryURL.indexOfAsciiL( RTL_CONSTASCII_STRINGPARAM( "slot=" ), nParamPos ); + if ( nSlotPos > 0 ) + sSlotParam = io_rFactoryURL.copy( nSlotPos + 5 ); + io_rFactoryURL = io_rFactoryURL.copy( 0, nParamPos ); + } - // TODO: replace by ViewFactory - return pTargetFrame->InsertDocument_Impl( *pDoc ); - } - } + if ( sSlotParam.getLength() ) + return USHORT( sSlotParam.toInt32() ); - DBG_ERROR("Model is not based on SfxObjectShell - wrong frame loader use!"); + return 0; +} + +// -------------------------------------------------------------------------------------------------------------------- +sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const css::uno::Sequence< PropertyValue >& rArgs, + const Reference< css::frame::XFrame >& _rTargetFrame ) + throw( css::uno::RuntimeException ) +{ + ENSURE_OR_THROW( _rTargetFrame.is(), "illegal NULL frame" ); + + // this methods assumes that the filter is detected before, usually by calling the detect() method below + ::vos::OGuard aGuard( Application::GetSolarMutex() ); + + RTL_LOGFILE_CONTEXT( aLog, "sfx2 (mb93783) ::SfxFrameLoader::load" ); + + ::comphelper::NamedValueCollection aDescriptor( rArgs ); + const Reference< XModel > xModel = aDescriptor.getOrDefault( "Model", Reference< XModel >() ); + + const SfxFilter* pDocumentFilter = NULL; + const SfxFilterMatcher& rMatcher = SFX_APP()->GetFilterMatcher(); + + // if a model is given, just load this into a newly created frame + if ( xModel.is() ) + return impl_loadExistingDocument( xModel, _rTargetFrame, aDescriptor ); + + // determine the filter to use + pDocumentFilter = impl_determineFilter( aDescriptor, rMatcher ); + if ( !pDocumentFilter ) return sal_False; - } + + // If detected filter indicates using of an own template format + // add property "AsTemplate" to descriptor. But suppress this step + // if such property already exists. + if ( pDocumentFilter->IsOwnTemplateFormat() && !aDescriptor.has( "AsTemplate" ) ) + aDescriptor.put( "AsTemplate", sal_Bool( sal_True ) ); // check for the URL pattern of our factory URLs + SfxTopFrame* pTargetFrame = SfxTopFrame::Create( _rTargetFrame ); + ENSURE_OR_THROW( pTargetFrame, "could not create an SfxFrame" ); SfxFrameWeak wFrame = pTargetFrame; - String aPrefix = String::CreateFromAscii( "private:factory/" ); - String aFact( sURL ); - if ( aPrefix.Len() == aFact.Match( aPrefix ) ) - { - // it's a factory URL - aFact.Erase( 0, aPrefix.Len() ); - - // look for parameters - String aParam; - USHORT nPos = aFact.Search( '?' ); - if ( nPos != STRING_NOTFOUND ) - { - // currently only the "slot" parameter is supported - USHORT nParamPos = aFact.Search( String::CreateFromAscii("slot="), nPos ); - if ( nParamPos != STRING_NOTFOUND ) - aParam = aFact.Copy( nParamPos+5, aFact.Len() ); - aFact.Erase( nPos, aFact.Len() ); - } - - if ( aParam.Len() ) - { - sal_Bool bSuccess = impl_createNewDocWithSlotParam( (sal_uInt16)aParam.ToInt32(), pTargetFrame ); - if ( !bSuccess && wFrame && !wFrame->GetCurrentDocument() ) - { - wFrame->SetFrameInterface_Impl( NULL ); - wFrame->DoClose(); - } - return bSuccess; - } + const ::rtl::OUString sURL = aDescriptor.getOrDefault( "URL", ::rtl::OUString() ); + if ( sURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "private:factory/" ) ) == 0 ) + { + ::rtl::OUString sFactory( sURL.copy( sizeof( "private:factory/" ) -1 ) ); - String sTemplateURL; - SFX_ITEMSET_ARG( &aSet, pTemplateRegionItem, SfxStringItem, SID_TEMPLATE_REGIONNAME, FALSE ); - SFX_ITEMSET_ARG( &aSet, pTemplateNameItem, SfxStringItem, SID_TEMPLATE_NAME, FALSE ); - if ( pTemplateRegionItem && pTemplateNameItem ) - { - SfxDocumentTemplates aTmpFac; - aTmpFac.GetFull( pTemplateRegionItem->GetValue(), pTemplateNameItem->GetValue(), sTemplateURL ); - } - else + USHORT nSlotParam = impl_findSlotParam( sFactory ); + if ( nSlotParam != 0 ) { - if ( sServiceName.getLength() ) - sTemplateURL = SfxObjectFactory::GetStandardTemplate( sServiceName ); - else - sTemplateURL = SfxObjectFactory::GetStandardTemplate( SfxObjectShell::GetServiceNameFromFactory( sURL ) ); + sal_Bool bSuccess = impl_createNewDocWithSlotParam( nSlotParam, *pTargetFrame ); + return impl_cleanUp( bSuccess, wFrame ); } - BOOL bUseTemplate = (sTemplateURL.Len()>0); - if( bUseTemplate ) + const SfxFilter* pTemplateFilter = impl_determineTemplateDocument( aDescriptor ); + if ( !pTemplateFilter ) { - // #i21583# - // Forget the filter, which was detected for the corresponding "private:factory/xxx" URL. - // We must use the right filter, matching to this document ... not to the private URL! - const SfxFilter* pTemplateFilter = impl_detectFilterForURL(sTemplateURL, rArgs, rMatcher); - if (pTemplateFilter) - { - pFilter = pTemplateFilter; - sFilterName = pTemplateFilter->GetName(); - // standard template set -> load it "AsTemplate" - aSet.Put( SfxStringItem ( SID_FILE_NAME, sTemplateURL ) ); - aSet.Put( SfxBoolItem( SID_TEMPLATE, sal_True ) ); - } - - // #119268# - // something is wrong with the set default template (e.g. unknown format, missing file etcpp) - // The we have to jump into the following special code, where "private:factory/ URL's are handled. - // We cant "load" such private/factory URL's! - else - bUseTemplate = FALSE; + // no or no valid template found => just create a default doc of the desired type, without any template + sal_Bool bSuccess = impl_createNewDoc( aDescriptor, *pTargetFrame, sFactory ); + return impl_cleanUp( bSuccess, wFrame ); } - if ( !bUseTemplate ) - { - // execute "NewDocument" request - sal_Bool bSuccess = impl_createNewDoc( aSet, pTargetFrame, aFact ); - if ( !bSuccess && wFrame && !wFrame->GetCurrentDocument() ) - { - wFrame->SetFrameInterface_Impl( NULL ); - wFrame->DoClose(); - } - return bSuccess; - } + // #i21583# + // ignore/forget the filter which was detected for the corresponding "private:factory/xxx" URL. + pDocumentFilter = pTemplateFilter; } else { - // load the desired file - aSet.Put( SfxStringItem ( SID_FILE_NAME, sURL ) ); + aDescriptor.put( "FileName", sURL ); } - DBG_ASSERT( pFilter, "SfxFrameLoader_Impl::load: could not determine a filter!" ); - if ( !pFilter ) + const ::rtl::OUString sFilterName = aDescriptor.getOrDefault( "FilterName", ::rtl::OUString() ); + + // at this point, we need a filter + DBG_ASSERT( pDocumentFilter, "SfxFrameLoader_Impl::load: could not determine a filter!" ); + if ( !pDocumentFilter ) return sal_False; - // !TODO: replace by direct construction of model (needs view factory) - sal_Bool bDisaster = sal_False; - SfxObjectShell* pDoc = SfxObjectShell::CreateObject( pFilter->GetServiceName() ); + SfxObjectShell* pDoc = SfxObjectShell::CreateObject( pDocumentFilter->GetServiceName() ); if ( !pDoc ) return sal_False; + aDescriptor.put( "Frame", _rTargetFrame ); + SfxAllItemSet aSet( impl_getInitialItemSet( aDescriptor ) ); + aSet.Put( SfxFrameItem( SID_DOCFRAME, pTargetFrame ) ); - aSet.Put( SfxUnoAnyItem( SID_FILLFRAME, makeAny( _rTargetFrame ) ) ); aSet.Put( SfxStringItem( SID_FILTER_NAME, sFilterName ) ); sal_Bool bLoadSuccess = sal_False; + sal_Bool bDisaster = sal_False; try { Reference< XLoadable > xLoadable( pDoc->GetModel(), UNO_QUERY ); @@ -504,7 +532,7 @@ sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const css::uno::Sequence< PropertyV /* #121119# - We dont know why _pFrame can be corrupt here. + We dont know why pTargetFrame can be corrupt here. But if it was deleted it shouldnt exists inside our global list. May be we can use the damaged pointer to detect if it was removed from this global list. @@ -513,7 +541,6 @@ sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const css::uno::Sequence< PropertyV aSet.Put( SfxFrameItem( SID_DOCFRAME, pTargetFrame ) ); - // !TODO: replace by ViewFactory pTargetFrame->SetItemSet_Impl( &aSet ); if ( pTargetFrame->InsertDocument_Impl( *pDoc ) ) { @@ -525,19 +552,15 @@ sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const css::uno::Sequence< PropertyV else bDisaster = sal_True; } - catch ( css::uno::Exception& ) + catch ( Exception& ) { bDisaster = sal_True; } if ( bDisaster ) { - if ( wFrame && !wFrame->GetCurrentDocument() ) - { - // document loading was not successful; close SfxFrame (but not XFrame!) - wFrame->SetFrameInterface_Impl( NULL ); - wFrame->DoClose(); - } + // document loading was not successful; close SfxFrame (but not XFrame!) and document + impl_cleanUp( false, wFrame ); Reference< XCloseable > xCloseable( pDoc->GetModel(), UNO_QUERY ); if ( xCloseable.is() ) @@ -546,7 +569,7 @@ sal_Bool SAL_CALL SfxFrameLoader_Impl::load( const css::uno::Sequence< PropertyV { xCloseable->close( sal_True ); } - catch ( css::uno::Exception& ) + catch ( Exception& ) { DBG_UNHANDLED_EXCEPTION(); } |