Change "Save graphic" and "Save picture as" to common code.
Change-Id: Id860b3220bde3d43eec7c74711e6938e68d01d56
This commit is contained in:
@@ -173,7 +173,6 @@ void ScGraphicShell::GetExternalEditState( SfxItemSet& rSet )
|
|||||||
ScDrawView* pView = GetViewData()->GetScDrawView();
|
ScDrawView* pView = GetViewData()->GetScDrawView();
|
||||||
const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
|
const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
|
||||||
bool bEnable = false;
|
bool bEnable = false;
|
||||||
printf("ZO!\n");
|
|
||||||
if( rMarkList.GetMarkCount() == 1 )
|
if( rMarkList.GetMarkCount() == 1 )
|
||||||
{
|
{
|
||||||
SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
|
SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
|
||||||
|
@@ -39,7 +39,6 @@ public:
|
|||||||
sal_Bool Import();
|
sal_Bool Import();
|
||||||
sal_Bool Export();
|
sal_Bool Export();
|
||||||
|
|
||||||
static void SaveGraphic( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape );
|
|
||||||
static void HandleGraphicFilterError( sal_uInt16 nFilterError, sal_uLong nStreamError = ERRCODE_NONE );
|
static void HandleGraphicFilterError( sal_uInt16 nFilterError, sal_uLong nStreamError = ERRCODE_NONE );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -59,11 +59,7 @@
|
|||||||
// --
|
// --
|
||||||
#include <comphelper/processfactory.hxx>
|
#include <comphelper/processfactory.hxx>
|
||||||
#include <unotools/pathoptions.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 <sfx2/filedlghelper.hxx>
|
||||||
#include <tools/urlobj.hxx>
|
|
||||||
#include <svtools/filter.hxx>
|
#include <svtools/filter.hxx>
|
||||||
#include <svx/xoutbmp.hxx>
|
#include <svx/xoutbmp.hxx>
|
||||||
|
|
||||||
@@ -379,176 +375,4 @@ sal_Bool SdGRFFilter::Export()
|
|||||||
return bRet;
|
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: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -47,7 +47,7 @@
|
|||||||
#include <basic/sbstar.hxx>
|
#include <basic/sbstar.hxx>
|
||||||
#include <editeng/flditem.hxx>
|
#include <editeng/flditem.hxx>
|
||||||
#include <svx/xlineit0.hxx>
|
#include <svx/xlineit0.hxx>
|
||||||
|
#include <svx/graphichelper.hxx>
|
||||||
#include <svx/svdoutl.hxx>
|
#include <svx/svdoutl.hxx>
|
||||||
#include <svx/xlnwtit.hxx>
|
#include <svx/xlnwtit.hxx>
|
||||||
#include <svx/svdoattr.hxx>
|
#include <svx/svdoattr.hxx>
|
||||||
@@ -936,11 +936,13 @@ void DrawViewShell::FuTemporary(SfxRequest& rReq)
|
|||||||
const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
|
const SdrMarkList& rMarkList = mpDrawView->GetMarkedObjectList();
|
||||||
if( rMarkList.GetMarkCount() == 1 )
|
if( rMarkList.GetMarkCount() == 1 )
|
||||||
{
|
{
|
||||||
SdrGrafObj *pGrafObj = dynamic_cast< SdrGrafObj* >( rMarkList.GetMark( 0 )->GetMarkedSdrObj() );
|
SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
|
||||||
if(pGrafObj )
|
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 );
|
GraphicObject aGraphicObject( ( (SdrGrafObj*) pObj )->GetGraphicObject() );
|
||||||
SdGRFFilter::SaveGraphic( xShape );
|
{
|
||||||
|
GraphicHelper::ExportGraphic( aGraphicObject.GetGraphic(), String("") );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Cancel();
|
Cancel();
|
||||||
|
@@ -93,6 +93,7 @@ $(eval $(call gb_Library_use_external,svxcore,icuuc))
|
|||||||
$(eval $(call gb_Library_add_exception_objects,svxcore,\
|
$(eval $(call gb_Library_add_exception_objects,svxcore,\
|
||||||
svx/source/core/coreservices \
|
svx/source/core/coreservices \
|
||||||
svx/source/core/extedit \
|
svx/source/core/extedit \
|
||||||
|
svx/source/core/graphichelper \
|
||||||
svx/source/customshapes/EnhancedCustomShape2d \
|
svx/source/customshapes/EnhancedCustomShape2d \
|
||||||
svx/source/customshapes/EnhancedCustomShapeGeometry \
|
svx/source/customshapes/EnhancedCustomShapeGeometry \
|
||||||
svx/source/customshapes/EnhancedCustomShapeTypeNames \
|
svx/source/customshapes/EnhancedCustomShapeTypeNames \
|
||||||
|
@@ -554,5 +554,6 @@ $(eval $(call gb_Package_add_file,svx_inc,inc/svx/colrctrl.hxx,svx/colrctrl.hxx)
|
|||||||
$(eval $(call gb_Package_add_file,svx_inc,inc/svx/fmdpage.hxx,svx/fmdpage.hxx))
|
$(eval $(call gb_Package_add_file,svx_inc,inc/svx/fmdpage.hxx,svx/fmdpage.hxx))
|
||||||
$(eval $(call gb_Package_add_file,svx_inc,inc/svx/sxmtpitm.hxx,svx/sxmtpitm.hxx))
|
$(eval $(call gb_Package_add_file,svx_inc,inc/svx/sxmtpitm.hxx,svx/sxmtpitm.hxx))
|
||||||
$(eval $(call gb_Package_add_file,svx_inc,inc/svx/extedit.hxx,svx/extedit.hxx))
|
$(eval $(call gb_Package_add_file,svx_inc,inc/svx/extedit.hxx,svx/extedit.hxx))
|
||||||
|
$(eval $(call gb_Package_add_file,svx_inc,inc/svx/graphichelper.hxx,svx/graphichelper.hxx))
|
||||||
|
|
||||||
# vim: set noet sw=4 ts=4:
|
# vim: set noet sw=4 ts=4:
|
||||||
|
@@ -29,7 +29,7 @@
|
|||||||
#include <vcl/graph.hxx>
|
#include <vcl/graph.hxx>
|
||||||
#include <svtools/grfmgr.hxx>
|
#include <svtools/grfmgr.hxx>
|
||||||
#include <vcl/timer.hxx>
|
#include <vcl/timer.hxx>
|
||||||
#include "svx/svxdllapi.h"
|
#include <svx/svxdllapi.h>
|
||||||
|
|
||||||
class SVX_DLLPUBLIC ExternalToolEdit
|
class SVX_DLLPUBLIC ExternalToolEdit
|
||||||
{
|
{
|
||||||
|
45
svx/inc/svx/graphichelper.hxx
Normal file
45
svx/inc/svx/graphichelper.hxx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/* -*- 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.
|
||||||
|
*
|
||||||
|
************************************************************************/
|
||||||
|
#ifndef _GRAPHICHELPER_HXX
|
||||||
|
#define _GRAPHICHELPER_HXX
|
||||||
|
|
||||||
|
#include <vcl/graph.hxx>
|
||||||
|
#include <svx/svxdllapi.h>
|
||||||
|
|
||||||
|
class SVX_DLLPUBLIC GraphicHelper
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
static void GetPreferedExtension( String &rExt, const Graphic &rGrf );
|
||||||
|
static String ExportGraphic( const Graphic &rGraphic, const String &rGrfName );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
@@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <svx/extedit.hxx>
|
#include <svx/extedit.hxx>
|
||||||
|
#include <svx/graphichelper.hxx>
|
||||||
#include <sfx2/viewfrm.hxx>
|
#include <sfx2/viewfrm.hxx>
|
||||||
#include <sfx2/bindings.hxx>
|
#include <sfx2/bindings.hxx>
|
||||||
#include <osl/file.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 );
|
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 )
|
void ExternalToolEdit::Edit( GraphicObject* pGraphicObject )
|
||||||
{
|
{
|
||||||
//Get the graphic from the GraphicObject
|
//Get the graphic from the GraphicObject
|
||||||
@@ -135,7 +105,7 @@ void ExternalToolEdit::Edit( GraphicObject* pGraphicObject )
|
|||||||
|
|
||||||
//get the Preferred File Extension for this graphic
|
//get the Preferred File Extension for this graphic
|
||||||
String fExtension;
|
String fExtension;
|
||||||
GetPreferedExtension(fExtension, aGraphic);
|
GraphicHelper::GetPreferedExtension(fExtension, aGraphic);
|
||||||
|
|
||||||
//Create the temp File
|
//Create the temp File
|
||||||
rtl::OUString tempFileBase, tempFileName;
|
rtl::OUString tempFileBase, tempFileName;
|
||||||
|
178
svx/source/core/graphichelper.cxx
Normal file
178
svx/source/core/graphichelper.cxx
Normal file
@@ -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: */
|
@@ -28,25 +28,17 @@
|
|||||||
|
|
||||||
#include <hintids.hxx>
|
#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/eitem.hxx>
|
||||||
#include <svl/stritem.hxx>
|
#include <svl/stritem.hxx>
|
||||||
#include <unotools/pathoptions.hxx>
|
|
||||||
#include <svtools/filter.hxx>
|
|
||||||
#include <svtools/imap.hxx>
|
#include <svtools/imap.hxx>
|
||||||
#include <svtools/inetimg.hxx>
|
#include <svtools/inetimg.hxx>
|
||||||
#include <svtools/transfer.hxx>
|
#include <svtools/transfer.hxx>
|
||||||
#include <sfx2/docfile.hxx>
|
#include <sfx2/docfile.hxx>
|
||||||
#include <sfx2/dispatch.hxx>
|
#include <sfx2/dispatch.hxx>
|
||||||
#include <svx/xoutbmp.hxx>
|
|
||||||
#include <svx/gallery.hxx>
|
#include <svx/gallery.hxx>
|
||||||
|
#include <svx/graphichelper.hxx>
|
||||||
#include <editeng/brshitem.hxx>
|
#include <editeng/brshitem.hxx>
|
||||||
|
|
||||||
|
|
||||||
#include <frmatr.hxx>
|
#include <frmatr.hxx>
|
||||||
#include <fmturl.hxx>
|
#include <fmturl.hxx>
|
||||||
#include <fmtinfmt.hxx>
|
#include <fmtinfmt.hxx>
|
||||||
@@ -62,34 +54,12 @@
|
|||||||
#include <cmdid.h>
|
#include <cmdid.h>
|
||||||
#include <helpid.h>
|
#include <helpid.h>
|
||||||
#include <docvw.hrc>
|
#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::lang;
|
||||||
using namespace ::com::sun::star::uno;
|
using namespace ::com::sun::star::uno;
|
||||||
using namespace ::com::sun::star;
|
using namespace ::com::sun::star;
|
||||||
using namespace ::com::sun::star::ui::dialogs;
|
|
||||||
using namespace ::sfx2;
|
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()
|
SwReadOnlyPopup::~SwReadOnlyPopup()
|
||||||
{
|
{
|
||||||
delete pImageMap;
|
delete pImageMap;
|
||||||
@@ -403,104 +373,7 @@ String SwReadOnlyPopup::SaveGraphic( sal_uInt16 nId )
|
|||||||
else
|
else
|
||||||
return aEmptyStr;
|
return aEmptyStr;
|
||||||
}
|
}
|
||||||
return ExportGraphic( aGraphic, sGrfName );
|
return GraphicHelper::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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -71,6 +71,7 @@
|
|||||||
#include <shells.hrc>
|
#include <shells.hrc>
|
||||||
#include <popup.hrc>
|
#include <popup.hrc>
|
||||||
#include <svx/extedit.hxx>
|
#include <svx/extedit.hxx>
|
||||||
|
#include <svx/graphichelper.hxx>
|
||||||
#define SwGrfShell
|
#define SwGrfShell
|
||||||
#include <sfx2/msg.hxx>
|
#include <sfx2/msg.hxx>
|
||||||
#include "swslots.hxx"
|
#include "swslots.hxx"
|
||||||
@@ -119,7 +120,7 @@ void SwGrfShell::Execute(SfxRequest &rReq)
|
|||||||
{
|
{
|
||||||
String sGrfNm, sFilterNm;
|
String sGrfNm, sFilterNm;
|
||||||
rSh.GetGrfNms( &sGrfNm, &sFilterNm );
|
rSh.GetGrfNms( &sGrfNm, &sFilterNm );
|
||||||
ExportGraphic( *pGraphic, sGrfNm );
|
GraphicHelper::ExportGraphic( *pGraphic, sGrfNm );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user