From ff98426745b76fef17e78d75f9b18b26ebc69a74 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Fri, 15 Mar 2013 01:22:13 +0100 Subject: initial work on an odc export We can now export a chart to odc when we are in chart edit mode from Calc. I need to add support for it to Writer and Impress as well. We can already open these files but copy&paste from the opened file fails. The next step is then to add a new menu entry Insert->Object->Chart from file Change-Id: I14d1702e79517e7319a1929de2be5501d375885d --- sfx2/inc/sfx2/objsh.hxx | 6 +++-- sfx2/source/doc/guisaveas.cxx | 27 +++++++++++++++++++++ sfx2/source/doc/objstor.cxx | 51 ++++++++++++++++++++++++++++++++++------ sfx2/source/doc/sfxbasemodel.cxx | 2 +- 4 files changed, 76 insertions(+), 10 deletions(-) (limited to 'sfx2') diff --git a/sfx2/inc/sfx2/objsh.hxx b/sfx2/inc/sfx2/objsh.hxx index 73a1934ef015..7e34147fb4b4 100644 --- a/sfx2/inc/sfx2/objsh.hxx +++ b/sfx2/inc/sfx2/objsh.hxx @@ -569,10 +569,12 @@ public: virtual void SetModified( sal_Bool bModified = sal_True ); sal_Bool IsModified(); + /** + * @param bChart true if the file is a chart doc and FillClass should not be called + */ void SetupStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, - sal_Int32 nVersion, - sal_Bool bTemplate ) const; + sal_Int32 nVersion, sal_Bool bTemplate, bool bChart = false ) const; ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > GetStorage(); diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx index 727e8178420e..092bf89bd33f 100644 --- a/sfx2/source/doc/guisaveas.cxx +++ b/sfx2/source/doc/guisaveas.cxx @@ -87,6 +87,10 @@ #include #include "../appl/app.hrc" +#include + +#include + // flags that specify requested operation #define EXPORT_REQUESTED 1 #define PDFEXPORT_REQUESTED 2 @@ -322,6 +326,29 @@ ModelData_Impl::ModelData_Impl( SfxStoringHelper& aOwner, , m_bRecommendReadOnly( sal_False ) { CheckInteractionHandler(); + rtl::OUString sModuleName; + try + { + uno::Reference< lang::XComponent > xCurrentComponent = frame::Desktop::create( comphelper::getProcessComponentContext() )->getCurrentComponent(); + sModuleName = aOwner.GetModuleManager()->identify(xCurrentComponent); + if(sModuleName == "com.sun.star.chart2.ChartDocument") + { + // let us switch the model and set the xStorable and + // XStorable2 to the old model. + // This is an ugly hack because we have no SfxObjectShell for chart2 yet. + // We need SfxObjectShell for the heavy work around ODF document creation + // because chart2 only writes the basic stream out. + // In future in might make sense to implement a full scale object shell in + // chart2 and make chart2 an own program. + m_xModel = uno::Reference< frame::XModel >(xCurrentComponent, uno::UNO_QUERY_THROW ); + m_xStorable = uno::Reference< frame::XStorable >(xModel, uno::UNO_QUERY_THROW ); + m_xStorable2 = uno::Reference< frame::XStorable2 >(xModel, uno::UNO_QUERY_THROW ); + } + } + catch(...) + { + // we don't want to pass on any errors; + } } //------------------------------------------------------------------------- diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index e352b5a9799f..15828e19641b 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -305,10 +305,38 @@ SvGlobalName SfxObjectShell::GetClassName() const return GetFactory().GetClassId(); } +namespace { + +/** + * Chart2 does not have an Object shell, so handle this here for now + * If we ever implement a full scale object shell in chart2 move it there + */ +sal_uInt32 GetChartVersion( sal_Int32 nVersion, bool bTemplate ) +{ + if( nVersion == SOFFICE_FILEFORMAT_60) + { + return SOT_FORMATSTR_ID_STARCHART_60; + } + else if( nVersion == SOFFICE_FILEFORMAT_8) + { + if (bTemplate) + { + SAL_WARN("sfx2", "no chart template support yet"); + return SOT_FORMATSTR_ID_STARCHART_8; + } + else + return SOT_FORMATSTR_ID_STARCHART_8; + } + + SAL_WARN("sfx2", "unsupported version"); + return 0; +} + +} + //------------------------------------------------------------------------- void SfxObjectShell::SetupStorage( const uno::Reference< embed::XStorage >& xStorage, - sal_Int32 nVersion, - sal_Bool bTemplate ) const + sal_Int32 nVersion, sal_Bool bTemplate, bool bChart ) const { uno::Reference< beans::XPropertySet > xProps( xStorage, uno::UNO_QUERY ); @@ -318,7 +346,11 @@ void SfxObjectShell::SetupStorage( const uno::Reference< embed::XStorage >& xSto OUString aFullTypeName, aShortTypeName, aAppName; sal_uInt32 nClipFormat=0; - FillClass( &aName, &nClipFormat, &aAppName, &aFullTypeName, &aShortTypeName, nVersion, bTemplate ); + if(!bChart) + FillClass( &aName, &nClipFormat, &aAppName, &aFullTypeName, &aShortTypeName, nVersion, bTemplate ); + else + nClipFormat = GetChartVersion(nVersion, bTemplate); + if ( nClipFormat ) { // basic doesn't have a ClipFormat @@ -421,7 +453,7 @@ sal_Bool SfxObjectShell::GeneralInit_Impl( const uno::Reference< embed::XStorage return sal_False; } - SetupStorage( xStorage, SOFFICE_FILEFORMAT_CURRENT, sal_False ); + SetupStorage( xStorage, SOFFICE_FILEFORMAT_CURRENT, sal_False, false ); } } catch ( uno::Exception& ) @@ -1874,7 +1906,7 @@ sal_Bool SfxObjectShell::DoSaveObjectAs( SfxMedium& rMedium, sal_Bool bCommit ) if ( !(a>>=aMediaType) || aMediaType.isEmpty() ) { OSL_FAIL( "The mediatype must be set already!\n" ); - SetupStorage( xNewStor, SOFFICE_FILEFORMAT_CURRENT, sal_False ); + SetupStorage( xNewStor, SOFFICE_FILEFORMAT_CURRENT, sal_False, false ); } pImp->bIsSaving = sal_False; @@ -3017,7 +3049,12 @@ sal_Bool SfxObjectShell::SaveAsOwnFormat( SfxMedium& rMedium ) // OASIS templates have own mediatypes ( SO7 also actually, but it is to late to use them here ) sal_Bool bTemplate = ( rMedium.GetFilter()->IsOwnTemplateFormat() && nVersion > SOFFICE_FILEFORMAT_60 ); - SetupStorage( xStorage, nVersion, bTemplate ); + const SfxFilter* pFilter = rMedium.GetFilter(); + bool bChart = false; + if(pFilter->GetName() == OUString("chart8")) + bChart = true; + + SetupStorage( xStorage, nVersion, bTemplate, bChart ); #ifndef DISABLE_SCRIPTING if ( HasBasic() ) { @@ -3043,7 +3080,7 @@ uno::Reference< embed::XStorage > SfxObjectShell::GetStorage() pImp->m_xDocStorage = ::comphelper::OStorageHelper::GetTemporaryStorage(); OSL_ENSURE( pImp->m_xDocStorage.is(), "The method must either return storage or throw an exception!" ); - SetupStorage( pImp->m_xDocStorage, SOFFICE_FILEFORMAT_CURRENT, sal_False ); + SetupStorage( pImp->m_xDocStorage, SOFFICE_FILEFORMAT_CURRENT, sal_False, false ); pImp->m_bCreateTempStor = sal_False; SFX_APP()->NotifyEvent( SfxEventHint( SFX_EVENT_STORAGECHANGED, GlobalEventConfig::GetEventName(STR_EVENT_STORAGECHANGED), this ) ); } diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index 608214dfe8fd..08e9b9fbe802 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -3760,7 +3760,7 @@ void SAL_CALL SfxBaseModel::storeToStorage( const uno::Reference< XSTORAGE >& xS { // TODO/LATER: if the provided storage has some data inside the storing might fail, probably the storage must be truncated // TODO/LATER: is it possible to have a template here? - m_pData->m_pObjectShell->SetupStorage( xStorage, nVersion, sal_False ); + m_pData->m_pObjectShell->SetupStorage( xStorage, nVersion, sal_False, false ); // BaseURL is part of the ItemSet SfxMedium aMedium( xStorage, String(), &aSet ); -- cgit