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 /sw | |
parent | b876538a6d90926b9771fb014432ccfb8c8125be (diff) |
Change "Save graphic" and "Save picture as" to common code.
Change-Id: Id860b3220bde3d43eec7c74711e6938e68d01d56
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/ui/docvw/romenu.cxx | 131 | ||||
-rw-r--r-- | sw/source/ui/shells/grfsh.cxx | 3 |
2 files changed, 4 insertions, 130 deletions
diff --git a/sw/source/ui/docvw/romenu.cxx b/sw/source/ui/docvw/romenu.cxx index 068ec3e36935..607145c93d56 100644 --- a/sw/source/ui/docvw/romenu.cxx +++ b/sw/source/ui/docvw/romenu.cxx @@ -28,25 +28,17 @@ #include <hintids.hxx> - -#include <tools/urlobj.hxx> -#include <vcl/graph.hxx> -#include <vcl/msgbox.hxx> -#include <sot/formats.hxx> #include <svl/eitem.hxx> #include <svl/stritem.hxx> -#include <unotools/pathoptions.hxx> -#include <svtools/filter.hxx> #include <svtools/imap.hxx> #include <svtools/inetimg.hxx> #include <svtools/transfer.hxx> #include <sfx2/docfile.hxx> #include <sfx2/dispatch.hxx> -#include <svx/xoutbmp.hxx> #include <svx/gallery.hxx> +#include <svx/graphichelper.hxx> #include <editeng/brshitem.hxx> - #include <frmatr.hxx> #include <fmturl.hxx> #include <fmtinfmt.hxx> @@ -62,34 +54,12 @@ #include <cmdid.h> #include <helpid.h> #include <docvw.hrc> -#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> using namespace ::com::sun::star::lang; using namespace ::com::sun::star::uno; using namespace ::com::sun::star; -using namespace ::com::sun::star::ui::dialogs; using namespace ::sfx2; -void GetPreferedExtension( String &rExt, const Graphic &rGrf ) -{ - // then propose the "best" filter using the native-info, if applicable - const sal_Char* pExt = "png"; - switch( const_cast<Graphic&>(rGrf).GetLink().GetType() ) - { - case GFX_LINK_TYPE_NATIVE_GIF: pExt = "gif"; break; - case GFX_LINK_TYPE_NATIVE_TIF: pExt = "tif"; break; - case GFX_LINK_TYPE_NATIVE_WMF: pExt = "wmf"; break; - case GFX_LINK_TYPE_NATIVE_MET: pExt = "met"; break; - case GFX_LINK_TYPE_NATIVE_PCT: pExt = "pct"; break; - case GFX_LINK_TYPE_NATIVE_JPG: pExt = "jpg"; break; - default:; //prevent warning - } - rExt.AssignAscii( pExt ); -} - SwReadOnlyPopup::~SwReadOnlyPopup() { delete pImageMap; @@ -403,104 +373,7 @@ String SwReadOnlyPopup::SaveGraphic( sal_uInt16 nId ) else return aEmptyStr; } - return ExportGraphic( aGraphic, sGrfName ); -} - -String ExportGraphic( const Graphic &rGraphic, const String &rGrfName ) -{ - SvtPathOptions aPathOpt; - String sGrfPath( aPathOpt.GetGraphicPath() ); - - FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION, 0 ); - Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker(); - - INetURLObject aPath; - aPath.SetSmartURL( sGrfPath ); - - // fish out the graphic's name - String aName = rGrfName; - - aDlgHelper.SetTitle( SW_RESSTR(STR_EXPORT_GRAFIK_TITLE)); - aDlgHelper.SetDisplayDirectory( aPath.GetMainURL(INetURLObject::DECODE_TO_IURI) ); - INetURLObject aURL; - aURL.SetSmartURL( aName ); - aDlgHelper.SetFileName( aURL.GetName() ); - - GraphicFilter& rGF = GraphicFilter::GetGraphicFilter(); - const sal_uInt16 nCount = rGF.GetExportFormatCount(); - - String aExt( aURL.GetExtension() ); - if( !aExt.Len() ) - GetPreferedExtension( aExt, rGraphic ); - - aExt.ToLowerAscii(); - sal_uInt16 nDfltFilter = USHRT_MAX; - - Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY); - - for ( sal_uInt16 i = 0; i < nCount; i++ ) - { - xFltMgr->appendFilter( rGF.GetExportFormatName( i ), rGF.GetExportWildcard( i ) ); - if ( COMPARE_EQUAL == aExt.CompareIgnoreCaseToAscii(rGF.GetExportFormatShortName( i ).ToLowerAscii() )) - nDfltFilter = i; - } - if ( USHRT_MAX == nDfltFilter ) - { - // "wrong" extension? - GetPreferedExtension( aExt, rGraphic ); - for ( sal_uInt16 i = 0; i < nCount; ++i ) - if ( aExt == rGF.GetExportFormatShortName( i ).ToLowerAscii() ) - { - nDfltFilter = i; - break; - } - } - - if( USHRT_MAX != nDfltFilter ) - { - xFltMgr->setCurrentFilter( rGF.GetExportFormatName( nDfltFilter ) ) ; - - if( aDlgHelper.Execute() == ERRCODE_NONE ) - { - String sPath( xFP->getFiles().getConstArray()[0] ); - // remember used path - please don't optimize away! - aPath.SetSmartURL( sPath); - sGrfPath = aPath.GetPath(); - - if( rGrfName.Len() && - nDfltFilter == rGF.GetExportFormatNumber( xFltMgr->getCurrentFilter())) - { - // try to save the original graphic - SfxMedium aIn( rGrfName, STREAM_READ | STREAM_NOCREATE ); - if( aIn.GetInStream() && !aIn.GetInStream()->GetError() ) - { - SfxMedium aOut( sPath, STREAM_WRITE | STREAM_SHARE_DENYNONE); - if( aOut.GetOutStream() && !aOut.GetOutStream()->GetError()) - { - *aOut.GetOutStream() << *aIn.GetInStream(); - if ( 0 == aIn.GetError() ) - { - aOut.Close(); - aOut.Commit(); - if ( 0 == aOut.GetError() ) - return sPath; - } - } - } - } - - sal_uInt16 nFilter; - if ( !xFltMgr->getCurrentFilter().isEmpty() && rGF.GetExportFormatCount() ) - nFilter = rGF.GetExportFormatNumber( xFltMgr->getCurrentFilter() ); - else - nFilter = GRFILTER_FORMAT_DONTKNOW; - String aFilter( rGF.GetExportFormatShortName( nFilter ) ); - XOutBitmap::WriteGraphic( rGraphic, sPath, aFilter, - XOUTBMP_DONT_EXPAND_FILENAME|XOUTBMP_DONT_ADD_EXTENSION ); - return sPath; - } - } - return aEmptyStr; + return GraphicHelper::ExportGraphic( aGraphic, sGrfName ); } diff --git a/sw/source/ui/shells/grfsh.cxx b/sw/source/ui/shells/grfsh.cxx index f47284124ea0..06caa0632edc 100644 --- a/sw/source/ui/shells/grfsh.cxx +++ b/sw/source/ui/shells/grfsh.cxx @@ -71,6 +71,7 @@ #include <shells.hrc> #include <popup.hrc> #include <svx/extedit.hxx> +#include <svx/graphichelper.hxx> #define SwGrfShell #include <sfx2/msg.hxx> #include "swslots.hxx" @@ -119,7 +120,7 @@ void SwGrfShell::Execute(SfxRequest &rReq) { String sGrfNm, sFilterNm; rSh.GetGrfNms( &sGrfNm, &sFilterNm ); - ExportGraphic( *pGraphic, sGrfNm ); + GraphicHelper::ExportGraphic( *pGraphic, sGrfNm ); } } break; |