xref: /aoo42x/main/sd/source/filter/grf/sdgrffilter.cxx (revision 79aad27f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #ifdef _MSC_VER
28 #pragma warning (disable:4190)
29 #endif
30 #include <com/sun/star/graphic/XGraphicProvider.hpp>
31 #include <com/sun/star/graphic/GraphicType.hpp>
32 #include <com/sun/star/ucb/XSimpleFileAccess2.hpp>
33 
34 #include <unotools/localfilehelper.hxx>
35 #include <tools/errinf.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <vcl/metaact.hxx>
38 #include <vcl/virdev.hxx>
39 #include <sfx2/docfile.hxx>
40 #include <sfx2/docfilt.hxx>
41 #include <sfx2/frame.hxx>
42 #include <svx/svdograf.hxx>
43 #include <svx/svdpagv.hxx>
44 
45 #include "../../ui/inc/strings.hrc"
46 #include "../../ui/inc/DrawViewShell.hxx"
47 #include "../../ui/inc/DrawDocShell.hxx"
48 #include "../../ui/inc/ClientView.hxx"
49 #include "../../ui/inc/FrameView.hxx"
50 
51 #include "comphelper/anytostring.hxx"
52 #include "cppuhelper/exc_hlp.hxx"
53 
54 // --
55 #include <comphelper/processfactory.hxx>
56 #include <unotools/pathoptions.hxx>
57 #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
58 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
59 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
60 #include <sfx2/filedlghelper.hxx>
61 #include <tools/urlobj.hxx>
62 #include <svtools/filter.hxx>
63 #include <svx/xoutbmp.hxx>
64 
65 // --
66 
67 #include "sdpage.hxx"
68 #include "drawdoc.hxx"
69 #include "sdresid.hxx"
70 #include "sdgrffilter.hxx"
71 #include "../../ui/inc/ViewShellBase.hxx"
72 #include <com/sun/star/uno/Sequence.h>
73 #include <com/sun/star/beans/PropertyValue.hpp>
74 #include <com/sun/star/beans/PropertyValues.hpp>
75 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
76 #include <com/sun/star/lang/XComponent.hpp>
77 #include <com/sun/star/document/XFilter.hpp>
78 #include <com/sun/star/document/XExporter.hpp>
79 #include <comphelper/processfactory.hxx>
80 #include <com/sun/star/view/XSelectionSupplier.hpp>
81 #include <com/sun/star/drawing/XDrawView.hpp>
82 #include "../../ui/inc/DrawController.hxx"
83 #include <cppuhelper/implbase2.hxx>
84 #include <com/sun/star/drawing/XShape.hpp>
85 #include <com/sun/star/task/XInteractionHandler.hpp>
86 #include <com/sun/star/task/XInteractionRequest.hpp>
87 #include <com/sun/star/drawing/GraphicFilterRequest.hpp>
88 
89 using namespace ::com::sun::star;
90 using namespace ::com::sun::star::uno;
91 using namespace ::com::sun::star::lang;
92 using namespace ::com::sun::star::beans;
93 using namespace ::com::sun::star::graphic;
94 using namespace ::com::sun::star::io;
95 using namespace ::com::sun::star::ucb;
96 using namespace com::sun::star::ui::dialogs;
97 using rtl::OUString;
98 using namespace ::sfx2;
99 
100 
101 // -----------------------------------------------------------------------------
102 
103 class SdGRFFilter_ImplInteractionHdl : public ::cppu::WeakImplHelper1< com::sun::star::task::XInteractionHandler >
104 {
105     com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > m_xInter;
106 	sal_uInt16 nFilterError;
107 
108 	public:
109 
SdGRFFilter_ImplInteractionHdl(com::sun::star::uno::Reference<com::sun::star::task::XInteractionHandler> xInteraction)110     SdGRFFilter_ImplInteractionHdl( com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > xInteraction ) :
111 		m_xInter( xInteraction ),
112 		nFilterError( GRFILTER_OK )
113         {}
114 
115     ~SdGRFFilter_ImplInteractionHdl();
116 
GetErrorCode() const117 	sal_uInt16 GetErrorCode() const { return nFilterError; };
118 
119 	virtual void SAL_CALL	handle( const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& )
120 								throw( com::sun::star::uno::RuntimeException );
121 };
122 
~SdGRFFilter_ImplInteractionHdl()123 SdGRFFilter_ImplInteractionHdl::~SdGRFFilter_ImplInteractionHdl()
124 {
125 }
126 
handle(const com::sun::star::uno::Reference<com::sun::star::task::XInteractionRequest> & xRequest)127 void SdGRFFilter_ImplInteractionHdl::handle( const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& xRequest )
128         throw( com::sun::star::uno::RuntimeException )
129 {
130 	if( !m_xInter.is() )
131 		return;
132 
133 	com::sun::star::drawing::GraphicFilterRequest aErr;
134     if ( xRequest->getRequest() >>= aErr )
135 		nFilterError = (sal_uInt16)aErr.ErrCode;
136 	else
137         m_xInter->handle( xRequest );
138 }
139 
140 
141 // ---------------
142 // - SdPPTFilter -
143 // ---------------
144 
SdGRFFilter(SfxMedium & rMedium,::sd::DrawDocShell & rDocShell)145 SdGRFFilter::SdGRFFilter( SfxMedium& rMedium, ::sd::DrawDocShell& rDocShell ) :
146 	SdFilter( rMedium, rDocShell, sal_True )
147 {
148 }
149 
150 // -----------------------------------------------------------------------------
151 
~SdGRFFilter()152 SdGRFFilter::~SdGRFFilter()
153 {
154 }
155 
156 // -----------------------------------------------------------------------------
157 
HandleGraphicFilterError(sal_uInt16 nFilterError,sal_uLong nStreamError)158 void SdGRFFilter::HandleGraphicFilterError( sal_uInt16 nFilterError, sal_uLong nStreamError )
159 {
160 	sal_uInt16 nId;
161 
162 	switch( nFilterError )
163 	{
164 		case GRFILTER_OPENERROR:
165 			nId = STR_IMPORT_GRFILTER_OPENERROR;
166 			break;
167 		case GRFILTER_IOERROR:
168 			nId = STR_IMPORT_GRFILTER_IOERROR;
169 			break;
170 		case GRFILTER_FORMATERROR:
171 			nId = STR_IMPORT_GRFILTER_FORMATERROR;
172 			break;
173 		case GRFILTER_VERSIONERROR:
174 			nId = STR_IMPORT_GRFILTER_VERSIONERROR;
175 			break;
176 		case GRFILTER_TOOBIG:
177 			nId = STR_IMPORT_GRFILTER_TOOBIG;
178 			break;
179 		case 0 :
180 			nId = 0;
181 			break;
182 
183 		default:
184 		case GRFILTER_FILTERERROR:
185 			nId = STR_IMPORT_GRFILTER_FILTERERROR;
186 			break;
187 	}
188 
189 	if( ERRCODE_NONE != nStreamError )
190 		ErrorHandler::HandleError( nStreamError );
191 	else if( STR_IMPORT_GRFILTER_IOERROR == nId )
192 		ErrorHandler::HandleError( ERRCODE_IO_GENERAL );
193 	else
194 	{
195 		ErrorBox aErrorBox( NULL, WB_OK, String( SdResId( nId ) ) );
196 		aErrorBox.Execute();
197 	}
198 }
199 
200 // -----------------------------------------------------------------------------
201 
Import()202 sal_Bool SdGRFFilter::Import()
203 {
204 	Graphic         aGraphic;
205 	const String    aFileName( mrMedium.GetURLObject().GetMainURL( INetURLObject::NO_DECODE ) );
206 	GraphicFilter*  pGraphicFilter = GraphicFilter::GetGraphicFilter();
207 	const sal_uInt16    nFilter = pGraphicFilter->GetImportFormatNumberForTypeName( mrMedium.GetFilter()->GetTypeName() );
208 	sal_Bool		bRet = sal_False;
209 
210 	// ggf. Filterdialog ausfuehren
211 	if ( !pGraphicFilter->HasImportDialog( nFilter ) || pGraphicFilter->DoImportDialog( NULL, nFilter ) )
212 	{
213 		SvStream*		pIStm = mrMedium.GetInStream();
214 		sal_uInt16			nReturn = pIStm ? pGraphicFilter->ImportGraphic( aGraphic, aFileName, *pIStm, nFilter ) : 1;
215 
216 		if( nReturn )
217 			HandleGraphicFilterError( nReturn, pGraphicFilter->GetLastError().nStreamError );
218 		else
219 		{
220 			if( mrDocument.GetPageCount() == 0L )
221 				mrDocument.CreateFirstPages();
222 
223 			SdPage*		pPage = mrDocument.GetSdPage( 0, PK_STANDARD );
224 			Point		aPos;
225 			Size		aPagSize( pPage->GetSize() );
226 			Size		aGrfSize( OutputDevice::LogicToLogic( aGraphic.GetPrefSize(),
227 								  aGraphic.GetPrefMapMode(), MAP_100TH_MM ) );
228 
229 			aPagSize.Width() -= pPage->GetLftBorder() + pPage->GetRgtBorder();
230 			aPagSize.Height() -= pPage->GetUppBorder() + pPage->GetLwrBorder();
231 
232 			// scale to fit page
233 			if ( ( ( aGrfSize.Height() > aPagSize.Height() ) || ( aGrfSize.Width() > aPagSize.Width() ) ) &&
234 				 aGrfSize.Height() && aPagSize.Height() )
235 			{
236 				double fGrfWH =	(double) aGrfSize.Width() / aGrfSize.Height();
237 				double fWinWH =	(double) aPagSize.Width() / aPagSize.Height();
238 
239 				// Grafik an Pagesize anpassen (skaliert)
240 				if( fGrfWH < fWinWH )
241 				{
242 					aGrfSize.Width() = (long) ( aPagSize.Height() * fGrfWH );
243 					aGrfSize.Height() = aPagSize.Height();
244 				}
245 				else if( fGrfWH > 0.F )
246 				{
247 					aGrfSize.Width() = aPagSize.Width();
248 					aGrfSize.Height()= (long) ( aPagSize.Width() / fGrfWH );
249 				}
250 			}
251 
252 			// Ausgaberechteck fuer Grafik setzen
253 			aPos.X() = ( ( aPagSize.Width() - aGrfSize.Width() ) >> 1 ) + pPage->GetLftBorder();
254 			aPos.Y() = ( ( aPagSize.Height() - aGrfSize.Height() ) >> 1 )  + pPage->GetUppBorder();
255 
256 			pPage->InsertObject( new SdrGrafObj( aGraphic, Rectangle( aPos, aGrfSize ) ) );
257 			bRet = sal_True;
258 		}
259 	}
260 	return bRet;
261 }
262 
263 // -----------------------------------------------------------------------------
264 
Export()265 sal_Bool SdGRFFilter::Export()
266 {
267 	// SJ: todo: error handling, the GraphicExportFilter does not support proper errorhandling
268 
269     sal_Bool bRet = sal_False;
270 
271  	uno::Reference< lang::XMultiServiceFactory >
272         xSMgr( ::comphelper::getProcessServiceFactory() );
273     uno::Reference< uno::XInterface > xComponent
274         ( xSMgr->createInstance( rtl::OUString::createFromAscii( "com.sun.star.drawing.GraphicExportFilter" ) ),
275             uno::UNO_QUERY );
276 	if ( xComponent.is() )
277 	{
278 		uno::Reference< document::XExporter > xExporter
279 			( xComponent, uno::UNO_QUERY );
280 		uno::Reference< document::XFilter > xFilter
281 			( xComponent, uno::UNO_QUERY );
282 		if ( xExporter.is() && xFilter.is() )
283 		{
284 			SdPage*	pPage = NULL;
285 			sd::DrawViewShell*	pDrawViewShell = static_cast< ::sd::DrawViewShell* >
286 				( ( ( mrDocShell.GetViewShell() && mrDocShell.GetViewShell()->ISA(::sd::DrawViewShell ) ) ? mrDocShell.GetViewShell() : NULL ) );
287 
288 			PageKind ePageKind = PK_STANDARD;
289 			if( pDrawViewShell )
290 			{
291 				ePageKind = pDrawViewShell->GetPageKind();
292 				if( PK_HANDOUT == ePageKind )
293 					pPage = mrDocument.GetSdPage( 0, PK_HANDOUT );
294 				else
295 					pPage = pDrawViewShell->GetActualPage();
296 			}
297 			else
298 				pPage = mrDocument.GetSdPage( 0, PK_STANDARD );
299 
300 			if ( pPage )
301 			{
302 				// taking the 'correct' page number, seems that there might exist a better method to archive this
303 				pPage = mrDocument.GetSdPage( pPage->GetPageNum() ? ( pPage->GetPageNum() - 1 ) >> 1 : 0, ePageKind );
304 				if ( pPage )
305 				{
306 					uno::Reference< lang::XComponent > xSource( pPage->getUnoPage(), uno::UNO_QUERY );
307 					SfxItemSet* pSet = mrMedium.GetItemSet();
308                 	GraphicFilter*  pGraphicFilter = GraphicFilter::GetGraphicFilter();
309 					if ( pSet && pGraphicFilter && xSource.is() )
310 					{
311 						const String aTypeName( mrMedium.GetFilter()->GetTypeName() );
312 						const sal_uInt16 nFilter = pGraphicFilter->GetExportFormatNumberForTypeName( aTypeName );
313 						if ( nFilter != GRFILTER_FORMAT_NOTFOUND )
314 						{
315 							uno::Reference< task::XInteractionHandler > mXInteractionHandler;
316 
317 							beans::PropertyValues aArgs;
318 							TransformItems( SID_SAVEASDOC, *pSet, aArgs );
319 
320 							rtl::OUString sInteractionHandler( RTL_CONSTASCII_USTRINGPARAM( "InteractionHandler" ) );
321 							rtl::OUString sFilterName( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
322 							rtl::OUString sShortName( pGraphicFilter->GetExportFormatShortName( nFilter ) );
323 
324 							sal_Bool	bFilterNameFound = sal_False;
325 							sal_Int32	i, nCount;
326 							for ( i = 0, nCount = aArgs.getLength(); i < nCount; i++ )
327 							{
328 								rtl::OUString& rStr = aArgs[ i ].Name;
329 								if ( rStr == sFilterName )
330 								{
331 									bFilterNameFound = sal_True;
332 									aArgs[ i ].Name = sFilterName;
333 									aArgs[ i ].Value <<= sShortName;
334 								}
335 								else if ( rStr == sInteractionHandler )
336 								{
337 									uno::Reference< task::XInteractionHandler > xHdl;
338 									if ( aArgs[ i ].Value >>= xHdl )
339 									{
340 										mXInteractionHandler = new SdGRFFilter_ImplInteractionHdl( xHdl );
341 										aArgs[ i ].Value <<= mXInteractionHandler;
342 									}
343 								}
344 							}
345 							if ( !bFilterNameFound )
346 							{
347 								aArgs.realloc( ++nCount );
348 								aArgs[ i ].Name = sFilterName;
349 								aArgs[ i ].Value <<= sShortName;
350 							}
351 
352 							// take selection if needed
353 							if( ( SFX_ITEM_SET == pSet->GetItemState( SID_SELECTION ) )
354 								&& static_cast< const SfxBoolItem& >( pSet->Get( SID_SELECTION ) ).GetValue()
355 								&& pDrawViewShell )
356 							{
357 								uno::Reference< view::XSelectionSupplier > xSelectionSupplier(
358 									pDrawViewShell->GetViewShellBase().GetController(), uno::UNO_QUERY );
359 								if ( xSelectionSupplier.is() )
360 								{
361 									uno::Any aSelection( xSelectionSupplier->getSelection() );
362 									uno::Reference< lang::XComponent > xSelection;
363 									if ( aSelection >>= xSelection )
364 										xSource = xSelection;
365 								}
366 							}
367 							xExporter->setSourceDocument( xSource );
368 							bRet = xFilter->filter( aArgs );
369 							if ( !bRet && mXInteractionHandler.is() )
370 								SdGRFFilter::HandleGraphicFilterError(
371 									static_cast< SdGRFFilter_ImplInteractionHdl* >( mXInteractionHandler.get() )->GetErrorCode(),
372 													pGraphicFilter->GetLastError().nStreamError );
373 						}
374  					}
375 				}
376 			}
377 		}
378 	}
379     return bRet;
380 }
381 
SaveGraphic(const::com::sun::star::uno::Reference<::com::sun::star::drawing::XShape> & xShape)382 void SdGRFFilter::SaveGraphic( const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& xShape )
383 {
384 	try
385 	{
386 		Reference< XMultiServiceFactory > xSM( ::comphelper::getProcessServiceFactory(), UNO_QUERY_THROW );
387 
388 		Reference< XGraphicProvider > xProvider( xSM->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.GraphicProvider" ) ) ), UNO_QUERY_THROW );
389 		Reference< XPropertySet > xShapeSet( xShape, UNO_QUERY_THROW );
390 
391 		// detect mime type of graphic
392 		OUString aMimeType;
393         OUString sGraphicURL;
394 
395 		// first try to detect from graphic object
396 		Reference< XPropertySet > xGraphicSet( xShapeSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Graphic" ) ) ), UNO_QUERY_THROW );
397         xShapeSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "GraphicURL" ) ) ) >>= sGraphicURL;
398 
399         bool bIsLinked = (sGraphicURL.getLength() != 0) && (sGraphicURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.GraphicObject:") ) != 0);
400 
401         if( !bIsLinked )
402        		xGraphicSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "MimeType" ) ) ) >>= aMimeType;
403 
404 		if( bIsLinked || aMimeType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "image/x-vclgraphic" ) ) || !aMimeType.getLength() )
405 		{
406 			// this failed, try to detect it from graphic stream and URL
407 			OUString aURL( sGraphicURL );
408 
409 			if( aURL.getLength() == 0 )
410 				xShapeSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "GraphicStreamURL" ) ) ) >>= aURL;
411 
412 			{
413 				Reference< XInputStream > xGraphStream( xShapeSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "GraphicStream" ) ) ), UNO_QUERY );
414 				PropertyValues aDesc(2);
415 				aDesc[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
416 				aDesc[0].Value <<= aURL;
417 				aDesc[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "InputStream" ) );
418 				aDesc[1].Value <<= xGraphStream;
419 
420 				Reference< XPropertySet > xDescSet( xProvider->queryGraphicDescriptor( aDesc ), UNO_QUERY_THROW );
421 
422 				xDescSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "MimeType" ) ) ) >>= aMimeType;
423 			}
424 		}
425 
426 		if( aMimeType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "image/x-vclgraphic" ) ) || !aMimeType.getLength() )
427 		{
428 			// this also failed, now set a mimetype that fits graphic best
429 
430 			// gif for animated pixel
431 			// png for non animated pixel
432 			// svm for vector format
433 			sal_Int8 nGraphicType = 0;
434 			xGraphicSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "GraphicType" ) ) ) >>= nGraphicType;
435 			switch( nGraphicType )
436 			{
437 			case ::com::sun::star::graphic::GraphicType::VECTOR:
438 				aMimeType = OUString::createFromAscii( "image/x-svm" );
439 				break;
440 
441 			case ::com::sun::star::graphic::GraphicType::PIXEL:
442 				{
443 					sal_Bool bAnimated = sal_False;
444 					xGraphicSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Animated" ) ) ) >>= bAnimated;
445 
446 					if( bAnimated )
447 					{
448 						aMimeType = OUString::createFromAscii( "image/gif" );
449 						break;
450 					}
451 				}
452 				// Fallthrough!
453 //			case ::com::sun::star::graphic::GraphicType::EMPTY:
454 			default:
455 				aMimeType = OUString::createFromAscii( "image/png" );
456 				break;
457 			}
458 		}
459 
460 		// init dialog
461 		SvtPathOptions aPathOpt;
462 		String sGrfPath( aPathOpt.GetGraphicPath() );
463 
464 		FileDialogHelper aDlgHelper( TemplateDescription::FILESAVE_AUTOEXTENSION, 0 );
465 		Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
466 
467 		String aTitle( SdResId( STR_TITLE_SAVE_AS_PICTURE ) );
468 		aDlgHelper.SetTitle( aTitle );
469 
470 		INetURLObject aPath;
471 		aPath.SetSmartURL( sGrfPath);
472 	    xFP->setDisplayDirectory( aPath.GetMainURL(INetURLObject::DECODE_TO_IURI) );
473 
474 		// populate filter dialog filter list and select default filter to match graphic mime type
475 
476 		GraphicFilter& rGF = *GraphicFilter::GetGraphicFilter();
477 		Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
478 		OUString aDefaultFormatName;
479 		sal_uInt16 nCount = rGF.GetExportFormatCount();
480 
481 		std::map< OUString, OUString > aMimeTypeMap;
482 
483 		for ( sal_uInt16 i = 0; i < nCount; i++ )
484 		{
485 			const OUString aExportFormatName( rGF.GetExportFormatName( i ) );
486 			const OUString aFilterMimeType( rGF.GetExportFormatMediaType( i ) );
487 			xFltMgr->appendFilter( aExportFormatName, rGF.GetExportWildcard( i ) );
488 			aMimeTypeMap[ aExportFormatName ] = aFilterMimeType;
489 			if( aMimeType == aFilterMimeType )
490 				aDefaultFormatName = aExportFormatName;
491 		}
492 
493 		if( aDefaultFormatName.getLength() == 0 )
494 		{
495 			nCount = rGF.GetImportFormatCount();
496 			for( sal_uInt16 i = 0; i < nCount; i++ )
497 			{
498 				const OUString aFilterMimeType( rGF.GetImportFormatMediaType( i ) );
499 				if( aMimeType == aFilterMimeType )
500 				{
501 					aDefaultFormatName = rGF.GetImportFormatName( i );
502 					xFltMgr->appendFilter( aDefaultFormatName,  rGF.GetImportWildcard( i ) );
503 					aMimeTypeMap[ aDefaultFormatName ] = aFilterMimeType;
504 					break;
505 				}
506 			}
507 		}
508 
509 		if( aDefaultFormatName.getLength() == 0 )
510 			aDefaultFormatName = OUString( RTL_CONSTASCII_USTRINGPARAM( "PNG - Portable Network Graphic" ) );
511 
512 		xFltMgr->setCurrentFilter( aDefaultFormatName );
513 
514 		// execute dialog
515 
516 		if( aDlgHelper.Execute() == ERRCODE_NONE )
517 		{
518 			OUString sPath( xFP->getFiles().getConstArray()[0] );
519 			aPath.SetSmartURL( sPath);
520 			sGrfPath = aPath.GetPath();
521 
522 			OUString aExportMimeType( aMimeTypeMap[xFltMgr->getCurrentFilter()] );
523 
524 			Reference< XInputStream > xGraphStream;
525 			if( aMimeType == aExportMimeType )
526 				xShapeSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "GraphicStream" ) ) ) >>= xGraphStream;
527 
528 			if( xGraphStream.is() )
529 			{
530 				Reference< XSimpleFileAccess2 > xFileAccess( xSM->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ), UNO_QUERY_THROW );
531 				xFileAccess->writeFile( sPath, xGraphStream );
532 			}
533 			else
534 			{
535 				PropertyValues aDesc(2);
536 				aDesc[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "URL" ) );
537 				aDesc[0].Value <<= sPath;
538 				aDesc[1].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "MimeType" ) );
539 				aDesc[1].Value <<= aExportMimeType;
540 				Reference< XGraphic > xGraphic( xShapeSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Graphic" ) ) ), UNO_QUERY_THROW );
541 				xProvider->storeGraphic( xGraphic, aDesc );
542 			}
543 		}
544 	}
545 	catch( Exception& )
546 	{
547 		DBG_ERROR(
548 			(rtl::OString("SdGRFFilter::SaveGraphic(), "
549 					"exception caught: ") +
550 			rtl::OUStringToOString(
551 				comphelper::anyToString( cppu::getCaughtException() ),
552 				RTL_TEXTENCODING_UTF8 )).getStr() );
553 	}
554 }
555