diff options
author | Tomaž Vajngerl <quikee@gmail.com> | 2012-06-30 23:46:33 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2012-07-01 17:47:49 +0200 |
commit | 8c1aafe8c20b6de8e13b4ce0eb34bb1b1f04fc0f (patch) | |
tree | 2bf76a9286af6df9323230e0b07fe8579c27ecf3 /sd/source | |
parent | b876538a6d90926b9771fb014432ccfb8c8125be (diff) |
Change "Save graphic" and "Save picture as" to common code.
Change-Id: Id860b3220bde3d43eec7c74711e6938e68d01d56
Diffstat (limited to 'sd/source')
-rw-r--r-- | sd/source/filter/grf/sdgrffilter.cxx | 176 | ||||
-rw-r--r-- | sd/source/ui/view/drviews2.cxx | 12 |
2 files changed, 7 insertions, 181 deletions
diff --git a/sd/source/filter/grf/sdgrffilter.cxx b/sd/source/filter/grf/sdgrffilter.cxx index 2ad8a7abafdb..67307a5fdf28 100644 --- a/sd/source/filter/grf/sdgrffilter.cxx +++ b/sd/source/filter/grf/sdgrffilter.cxx @@ -59,11 +59,7 @@ // -- #include <comphelper/processfactory.hxx> #include <unotools/pathoptions.hxx> -#include <com/sun/star/ui/dialogs/XFilePicker.hpp> -#include <com/sun/star/ui/dialogs/XFilterManager.hpp> -#include <com/sun/star/ui/dialogs/TemplateDescription.hpp> #include <sfx2/filedlghelper.hxx> -#include <tools/urlobj.hxx> #include <svtools/filter.hxx> #include <svx/xoutbmp.hxx> @@ -379,176 +375,4 @@ sal_Bool SdGRFFilter::Export() return bRet; } -void SdGRFFilter::SaveGraphic( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape ) -{ - try - { - Reference< XComponentContext > xContext = ::comphelper::getProcessComponentContext(); - - Reference< XGraphicProvider > xProvider( GraphicProvider::create(xContext) ); - Reference< XPropertySet > xShapeSet( xShape, UNO_QUERY_THROW ); - - // detect mime type of graphic - OUString aMimeType; - OUString sGraphicURL; - - // first try to detect from graphic object - Reference< XPropertySet > xGraphicSet( xShapeSet->getPropertyValue( "Graphic" ), UNO_QUERY_THROW ); - xShapeSet->getPropertyValue( "GraphicURL" ) >>= sGraphicURL; - - bool bIsLinked = !sGraphicURL.isEmpty() && sGraphicURL.equals("vnd.sun.star.GraphicObject:"); - - if( !bIsLinked ) - xGraphicSet->getPropertyValue( "MimeType" ) >>= aMimeType; - - if( bIsLinked || aMimeType == "image/x-vclgraphic" || aMimeType.isEmpty() ) - { - // this failed, try to detect it from graphic stream and URL - OUString aURL( sGraphicURL ); - - if( aURL.isEmpty() ) - xShapeSet->getPropertyValue( "GraphicStreamURL" ) >>= aURL; - - { - Reference< XInputStream > xGraphStream( xShapeSet->getPropertyValue( "GraphicStream" ), UNO_QUERY ); - PropertyValues aDesc(2); - aDesc[0].Name = "URL"; - aDesc[0].Value <<= aURL; - aDesc[1].Name = "InputStream"; - aDesc[1].Value <<= xGraphStream; - - Reference< XPropertySet > xDescSet( xProvider->queryGraphicDescriptor( aDesc ), UNO_QUERY_THROW ); - - xDescSet->getPropertyValue( "MimeType" ) >>= aMimeType; - } - } - - if( aMimeType == "image/x-vclgraphic" || aMimeType.isEmpty() ) - { - // this also failed, now set a mimetype that fits graphic best - - // gif for animated pixel - // png for non animated pixel - // svm for vector format - sal_Int8 nGraphicType = 0; - xGraphicSet->getPropertyValue( "GraphicType" ) >>= nGraphicType; - switch( nGraphicType ) - { - case ::com::sun::star::graphic::GraphicType::VECTOR: - aMimeType = "image/x-svm"; - break; - - case ::com::sun::star::graphic::GraphicType::PIXEL: - { - sal_Bool bAnimated = sal_False; - xGraphicSet->getPropertyValue( "Animated" ) >>= bAnimated; - - if( bAnimated ) - { - aMimeType = "image/gif"; - break; - } - } - default: - aMimeType = "image/png"; - break; - } - } - - // init dialog - SvtPathOptions aPathOpt; - String sGrfPath( aPathOpt.GetGraphicPath() ); - - FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION, 0 ); - Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker(); - - String aTitle( SdResId( STR_TITLE_SAVE_AS_PICTURE ) ); - aDlgHelper.SetTitle( aTitle ); - - INetURLObject aPath; - aPath.SetSmartURL( sGrfPath); - xFP->setDisplayDirectory( aPath.GetMainURL(INetURLObject::DECODE_TO_IURI) ); - - // populate filter dialog filter list and select default filter to match graphic mime type - - GraphicFilter& rGF = GraphicFilter::GetGraphicFilter(); - Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY); - OUString aDefaultFormatName; - sal_uInt16 nCount = rGF.GetExportFormatCount(); - - std::map< OUString, OUString > aMimeTypeMap; - - for ( sal_uInt16 i = 0; i < nCount; i++ ) - { - const OUString aExportFormatName( rGF.GetExportFormatName( i ) ); - const OUString aFilterMimeType( rGF.GetExportFormatMediaType( i ) ); - xFltMgr->appendFilter( aExportFormatName, rGF.GetExportWildcard( i ) ); - aMimeTypeMap[ aExportFormatName ] = aFilterMimeType; - if( aMimeType == aFilterMimeType ) - aDefaultFormatName = aExportFormatName; - } - - if( aDefaultFormatName.isEmpty() ) - { - nCount = rGF.GetImportFormatCount(); - for( sal_uInt16 i = 0; i < nCount; i++ ) - { - const OUString aFilterMimeType( rGF.GetImportFormatMediaType( i ) ); - if( aMimeType == aFilterMimeType ) - { - aDefaultFormatName = rGF.GetImportFormatName( i ); - xFltMgr->appendFilter( aDefaultFormatName, rGF.GetImportWildcard( i ) ); - aMimeTypeMap[ aDefaultFormatName ] = aFilterMimeType; - break; - } - } - } - - if( aDefaultFormatName.isEmpty() ) - aDefaultFormatName = "PNG - Portable Network Graphic"; - - xFltMgr->setCurrentFilter( aDefaultFormatName ); - - // execute dialog - - if( aDlgHelper.Execute() == ERRCODE_NONE ) - { - OUString sPath( xFP->getFiles().getConstArray()[0] ); - aPath.SetSmartURL( sPath); - sGrfPath = aPath.GetPath(); - - OUString aExportMimeType( aMimeTypeMap[xFltMgr->getCurrentFilter()] ); - - Reference< XInputStream > xGraphStream; - if( aMimeType == aExportMimeType ) - xShapeSet->getPropertyValue( "GraphicStream" ) >>= xGraphStream; - - if( xGraphStream.is() ) - { - Reference< XSimpleFileAccess2 > xFileAccess( SimpleFileAccess::create(xContext) ); - xFileAccess->writeFile( sPath, xGraphStream ); - } - else - { - PropertyValues aDesc(2); - aDesc[0].Name = "URL"; - aDesc[0].Value <<= sPath; - aDesc[1].Name = "MimeType"; - aDesc[1].Value <<= aExportMimeType; - Reference< XGraphic > xGraphic( xShapeSet->getPropertyValue( "Graphic" ), UNO_QUERY_THROW ); - xProvider->storeGraphic( xGraphic, aDesc ); - } - } - } - catch( Exception& ) - { - OSL_FAIL( - (rtl::OString("SdGRFFilter::SaveGraphic(), " - "exception caught: ") + - rtl::OUStringToOString( - comphelper::anyToString( cppu::getCaughtException() ), - RTL_TEXTENCODING_UTF8 )).getStr() ); - } -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/view/drviews2.cxx b/sd/source/ui/view/drviews2.cxx index 5f20f724ce87..c9f49e6e554e 100644 --- a/sd/source/ui/view/drviews2.cxx +++ b/sd/source/ui/view/drviews2.cxx @@ -47,7 +47,7 @@ #include <basic/sbstar.hxx> #include <editeng/flditem.hxx> #include <svx/xlineit0.hxx> - +#include <svx/graphichelper.hxx> #include <svx/svdoutl.hxx> #include <svx/xlnwtit.hxx> #include <svx/svdoattr.hxx> @@ -936,11 +936,13 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq) const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList(); if( rMarkList.GetMarkCount() == 1 ) { - SdrGrafObj *pGrafObj = dynamic_cast< SdrGrafObj* >( rMarkList.GetMark( 0 )->GetMarkedSdrObj() ); - if(pGrafObj ) + SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj(); + if( pObj && pObj->ISA( SdrGrafObj ) && ( (SdrGrafObj*) pObj )->GetGraphicType() == GRAPHIC_BITMAP ) { - ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape( pGrafObj->getUnoShape(), com::sun::star::uno::UNO_QUERY ); - SdGRFFilter::SaveGraphic( xShape ); + GraphicObject aGraphicObject( ( (SdrGrafObj*) pObj )->GetGraphicObject() ); + { + GraphicHelper::ExportGraphic( aGraphicObject.GetGraphic(), String("") ); + } } } Cancel(); |