summaryrefslogtreecommitdiff
path: root/svx/source
diff options
context:
space:
mode:
authorTomaž Vajngerl <quikee@gmail.com>2012-06-30 23:46:33 +0200
committerTomaž Vajngerl <quikee@gmail.com>2012-07-01 17:47:49 +0200
commit8c1aafe8c20b6de8e13b4ce0eb34bb1b1f04fc0f (patch)
tree2bf76a9286af6df9323230e0b07fe8579c27ecf3 /svx/source
parentb876538a6d90926b9771fb014432ccfb8c8125be (diff)
Change "Save graphic" and "Save picture as" to common code.
Change-Id: Id860b3220bde3d43eec7c74711e6938e68d01d56
Diffstat (limited to 'svx/source')
-rw-r--r--svx/source/core/extedit.cxx34
-rw-r--r--svx/source/core/graphichelper.cxx178
2 files changed, 180 insertions, 32 deletions
diff --git a/svx/source/core/extedit.cxx b/svx/source/core/extedit.cxx
index eddb16acd4b4..c52d0cfc5ab0 100644
--- a/svx/source/core/extedit.cxx
+++ b/svx/source/core/extedit.cxx
@@ -23,6 +23,7 @@
*/
#include <svx/extedit.hxx>
+#include <svx/graphichelper.hxx>
#include <sfx2/viewfrm.hxx>
#include <sfx2/bindings.hxx>
#include <osl/file.hxx>
@@ -96,37 +97,6 @@ void ExternalToolEdit::threadWorker(void* pThreadData)
xSystemShellExecute->execute( pData->m_aFileName, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
}
-
-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:
- break;
- }
- rExt.AssignAscii( pExt );
-}
-
void ExternalToolEdit::Edit( GraphicObject* pGraphicObject )
{
//Get the graphic from the GraphicObject
@@ -135,7 +105,7 @@ void ExternalToolEdit::Edit( GraphicObject* pGraphicObject )
//get the Preferred File Extension for this graphic
String fExtension;
- GetPreferedExtension(fExtension, aGraphic);
+ GraphicHelper::GetPreferedExtension(fExtension, aGraphic);
//Create the temp File
rtl::OUString tempFileBase, tempFileName;
diff --git a/svx/source/core/graphichelper.cxx b/svx/source/core/graphichelper.cxx
new file mode 100644
index 000000000000..faec3b27970d
--- /dev/null
+++ b/svx/source/core/graphichelper.cxx
@@ -0,0 +1,178 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <tools/string.hxx>
+#include <svx/graphichelper.hxx>
+#include <unotools/pathoptions.hxx>
+#include <svtools/filter.hxx>
+#include <sfx2/docfile.hxx>
+#include <svx/xoutbmp.hxx>
+#include <sfx2/filedlghelper.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>
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::ui::dialogs;
+using namespace ::sfx2;
+
+void GraphicHelper::GetPreferedExtension( String &rExtension, const Graphic &rGraphic )
+{
+ // propose the "best" filter using the native-info, if applicable
+ const sal_Char* pExtension = "png";
+ switch( const_cast<Graphic&>( rGraphic ).GetLink().GetType() )
+ {
+ case GFX_LINK_TYPE_NATIVE_GIF:
+ pExtension = "gif";
+ break;
+ case GFX_LINK_TYPE_NATIVE_TIF:
+ pExtension = "tif";
+ break;
+ case GFX_LINK_TYPE_NATIVE_WMF:
+ pExtension = "wmf";
+ break;
+ case GFX_LINK_TYPE_NATIVE_MET:
+ pExtension = "met";
+ break;
+ case GFX_LINK_TYPE_NATIVE_PCT:
+ pExtension = "pct";
+ break;
+ case GFX_LINK_TYPE_NATIVE_JPG:
+ pExtension = "jpg";
+ break;
+ default:
+ break;
+ }
+ rExtension.AssignAscii( pExtension );
+}
+
+String GraphicHelper::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;
+ printf("Name: %s\n", aName.GetBuffer());
+
+ //aDlgHelper.SetTitle( SW_RESSTR(STR_EXPORT_GRAFIK_TITLE));
+ aDlgHelper.SetTitle( String("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|
+ XOUTBMP_USE_NATIVE_IF_POSSIBLE );
+ return sPath;
+ }
+ }
+ return String();
+}
+
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */