1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SvFilterOptionsDialog.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #include "SvFilterOptionsDialog.hxx"
35 #include <svtools/FilterConfigItem.hxx>
36 #include <svtools/filter.hxx>
37 #include "FilterConfigCache.hxx"
38 #include <osl/file.hxx>
39 #include <osl/module.hxx>
40 #include <svtools/solar.hrc>
41 #include <svtools/fltcall.hxx>
42 #include "dlgexpor.hxx"
43 #include "dlgejpg.hxx"
44 #include "dlgepng.hxx"
45 #include <uno/mapping.hxx>
46 #include <com/sun/star/frame/XModel.hpp>
47 #include <com/sun/star/document/XViewDataSupplier.hpp>
48 #include <com/sun/star/container/XIndexAccess.hpp>
49 #include <com/sun/star/lang/XServiceInfo.hpp>
50 #include <com/sun/star/uno/Sequence.h>
51 #include <com/sun/star/uno/Any.h>
52 #include <svtools/syslocale.hxx>
53 #include "vcl/svapp.hxx"
55 #if defined WIN || (defined OS2 && !defined ICC)
56 #define EXPDLG_FUNCTION_NAME "_DoExportDialog"
58 #define EXPDLG_FUNCTION_NAME "DoExportDialog"
61 using namespace ::rtl
;
62 using namespace ::com::sun::star
;
64 // -------------------------
65 // - SvFilterOptionsDialog -
66 // -------------------------
68 uno::Reference
< uno::XInterface
>
69 SAL_CALL
SvFilterOptionsDialog_CreateInstance(
70 const uno::Reference
< lang::XMultiServiceFactory
> & _rxFactory
)
72 return static_cast< ::cppu::OWeakObject
* > ( new SvFilterOptionsDialog( _rxFactory
) );
75 OUString
SvFilterOptionsDialog_getImplementationName()
76 throw( uno::RuntimeException
)
78 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.SvFilterOptionsDialog" ) );
80 #define SERVICE_NAME "com.sun.star.ui.dialog.FilterOptionsDialog"
81 sal_Bool SAL_CALL
SvFilterOptionsDialog_supportsService( const OUString
& ServiceName
)
82 throw( uno::RuntimeException
)
84 return ServiceName
.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME
) );
87 uno::Sequence
< OUString
> SAL_CALL
SvFilterOptionsDialog_getSupportedServiceNames()
88 throw( uno::RuntimeException
)
90 uno::Sequence
< OUString
> aRet(1);
91 OUString
* pArray
= aRet
.getArray();
92 pArray
[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME
) );
97 // -----------------------------------------------------------------------------
99 SvFilterOptionsDialog::SvFilterOptionsDialog( const uno::Reference
< lang::XMultiServiceFactory
> & xMgr
) :
101 eFieldUnit ( FUNIT_CM
)
105 // -----------------------------------------------------------------------------
107 SvFilterOptionsDialog::~SvFilterOptionsDialog()
111 // -----------------------------------------------------------------------------
113 void SAL_CALL
SvFilterOptionsDialog::acquire() throw()
115 OWeakObject::acquire();
118 // -----------------------------------------------------------------------------
120 void SAL_CALL
SvFilterOptionsDialog::release() throw()
122 OWeakObject::release();
126 void SAL_CALL
SvFilterOptionsDialog::initialize( const uno::Sequence
< uno::Any
> & )
127 throw ( uno::Exception
, uno::RuntimeException
)
132 OUString SAL_CALL
SvFilterOptionsDialog::getImplementationName()
133 throw( uno::RuntimeException
)
135 return SvFilterOptionsDialog_getImplementationName();
137 sal_Bool SAL_CALL
SvFilterOptionsDialog::supportsService( const OUString
& rServiceName
)
138 throw( uno::RuntimeException
)
140 return SvFilterOptionsDialog_supportsService( rServiceName
);
142 uno::Sequence
< OUString
> SAL_CALL
SvFilterOptionsDialog::getSupportedServiceNames()
143 throw ( uno::RuntimeException
)
145 return SvFilterOptionsDialog_getSupportedServiceNames();
150 uno::Sequence
< beans::PropertyValue
> SvFilterOptionsDialog::getPropertyValues()
151 throw ( uno::RuntimeException
)
154 for ( i
= 0, nCount
= aMediaDescriptor
.getLength(); i
< nCount
; i
++ )
156 if ( aMediaDescriptor
[ i
].Name
.equalsAscii( "FilterData" ) )
160 aMediaDescriptor
.realloc( ++nCount
);
162 // the "FilterData" Property is an Any that will contain our PropertySequence of Values
163 aMediaDescriptor
[ i
].Name
= String( RTL_CONSTASCII_USTRINGPARAM( "FilterData" ) );
164 aMediaDescriptor
[ i
].Value
<<= aFilterDataSequence
;
165 return aMediaDescriptor
;
168 void SvFilterOptionsDialog::setPropertyValues( const uno::Sequence
< beans::PropertyValue
> & aProps
)
169 throw ( beans::UnknownPropertyException
, beans::PropertyVetoException
,
170 lang::IllegalArgumentException
, lang::WrappedTargetException
,
171 uno::RuntimeException
)
173 aMediaDescriptor
= aProps
;
176 for ( i
= 0, nCount
= aMediaDescriptor
.getLength(); i
< nCount
; i
++ )
178 if ( aMediaDescriptor
[ i
].Name
.equalsAscii( "FilterData" ) )
180 aMediaDescriptor
[ i
].Value
>>= aFilterDataSequence
;
187 void SvFilterOptionsDialog::setTitle( const OUString
& aTitle
)
188 throw ( uno::RuntimeException
)
190 aDialogTitle
= aTitle
;
193 sal_Int16
SvFilterOptionsDialog::execute()
194 throw ( uno::RuntimeException
)
196 sal_Int16 nRet
= ui::dialogs::ExecutableDialogResults::CANCEL
;
198 String
aFilterNameStr( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
199 String aInternalFilterName
;
200 sal_Int32 j
, nCount
= aMediaDescriptor
.getLength();
201 for ( j
= 0; j
< nCount
; j
++ )
203 if ( aMediaDescriptor
[ j
].Name
.equals( aFilterNameStr
) )
206 aMediaDescriptor
[ j
].Value
>>= aStr
;
207 aInternalFilterName
= aStr
;
208 aInternalFilterName
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "draw_" ) ), String(), 0 );
209 aInternalFilterName
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "impress_" ) ), String(), 0 );
213 if ( aInternalFilterName
.Len() )
215 GraphicFilter
aGraphicFilter( sal_True
);
217 sal_uInt16 nFormat
, nFilterCount
= aGraphicFilter
.pConfig
->GetExportFormatCount();
218 for ( nFormat
= 0; nFormat
< nFilterCount
; nFormat
++ )
220 if ( aGraphicFilter
.pConfig
->GetExportInternalFilterName( nFormat
) == aInternalFilterName
)
223 if ( nFormat
< nFilterCount
)
225 FltCallDialogParameter
aFltCallDlgPara( Application::GetDefDialogParent(), NULL
, eFieldUnit
);
226 aFltCallDlgPara
.aFilterData
= aFilterDataSequence
;
228 String
aFilterName( aGraphicFilter
.pConfig
->GetExportFilterName( nFormat
) );
229 if ( aGraphicFilter
.pConfig
->IsExportInternalFilter( nFormat
) )
231 // Export-Dialog fuer Bitmap's, SVM's und WMF's
232 if( ( aFilterName
.EqualsIgnoreCaseAscii( EXP_BMP
) ) ||
233 ( aFilterName
.EqualsIgnoreCaseAscii( EXP_SVMETAFILE
) ) ||
234 ( aFilterName
.EqualsIgnoreCaseAscii( EXP_WMF
) ) ||
235 ( aFilterName
.EqualsIgnoreCaseAscii( EXP_EMF
) ) ||
236 ( aFilterName
.EqualsIgnoreCaseAscii( EXP_JPEG
) )||
237 ( aFilterName
.EqualsIgnoreCaseAscii( EXP_PNG
) ) )
239 ByteString
aResMgrName( "svt", 3 );
242 pResMgr
= ResMgr::CreateResMgr( aResMgrName
.GetBuffer(), Application::GetSettings().GetUILocale() );
243 aFltCallDlgPara
.pResMgr
= pResMgr
;
245 if( aFilterName
.EqualsIgnoreCaseAscii( EXP_JPEG
) )
247 if ( DlgExportEJPG( aFltCallDlgPara
).Execute() == RET_OK
)
248 nRet
= ui::dialogs::ExecutableDialogResults::OK
;
250 else if ( aFilterName
.EqualsIgnoreCaseAscii( EXP_PNG
) )
252 if ( DlgExportEPNG( aFltCallDlgPara
).Execute() == RET_OK
)
253 nRet
= ui::dialogs::ExecutableDialogResults::OK
;
255 else if( aFilterName
.EqualsIgnoreCaseAscii( EXP_BMP
) )
257 // Fuer Vektorformate nehmen wir den Vektor-Dialog
258 aFltCallDlgPara
.aFilterExt
= aGraphicFilter
.pConfig
->GetExportFormatShortName( nFormat
);
259 if ( DlgExportPix( aFltCallDlgPara
).Execute() == RET_OK
)
260 nRet
= ui::dialogs::ExecutableDialogResults::OK
;
264 aFltCallDlgPara
.aFilterExt
= aGraphicFilter
.pConfig
->GetExportFormatShortName( nFormat
);
265 if ( DlgExportVec( aFltCallDlgPara
).Execute() == RET_OK
)
266 nRet
= ui::dialogs::ExecutableDialogResults::OK
;
271 else // ladbare Filter
273 xub_StrLen i
, nTokenCount
= aGraphicFilter
.aFilterPath
.GetTokenCount( ';' );
274 for ( i
= 0; i
< nTokenCount
; i
++ )
279 ::osl::FileBase::getFileURLFromSystemPath( aGraphicFilter
.aFilterPath
.GetToken( i
), aPathURL
);
280 aPathURL
+= String( '/' );
282 OUString aSystemPath
;
283 ::osl::FileBase::getSystemPathFromFileURL( aPathURL
, aSystemPath
);
284 aSystemPath
+= OUString( aFilterName
);
286 osl::Module
aLibrary( aSystemPath
);
287 PFilterDlgCall pFunc
= (PFilterDlgCall
) aLibrary
.getFunctionSymbol( UniString::CreateFromAscii( EXPDLG_FUNCTION_NAME
) );
288 // Dialog in DLL ausfuehren
291 if ( (*pFunc
)( aFltCallDlgPara
) )
292 nRet
= ui::dialogs::ExecutableDialogResults::OK
;
296 // taking the out parameter from the dialog
297 aFilterDataSequence
= aFltCallDlgPara
.aFilterData
;
304 void SvFilterOptionsDialog::setSourceDocument( const uno::Reference
< lang::XComponent
>& xDoc
)
305 throw ( lang::IllegalArgumentException
, uno::RuntimeException
)
307 // try to set the corresponding metric unit
309 uno::Reference
< lang::XServiceInfo
> xServiceInfo
310 ( xDoc
, uno::UNO_QUERY
);
311 if ( xServiceInfo
.is() )
313 if ( xServiceInfo
->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ) )
314 aConfigPath
= String( RTL_CONSTASCII_USTRINGPARAM( "Office.Impress/Layout/Other/MeasureUnit" ) );
315 else if ( xServiceInfo
->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ) )
316 aConfigPath
= String( RTL_CONSTASCII_USTRINGPARAM( "Office.Draw/Layout/Other/MeasureUnit" ) );
317 if ( aConfigPath
.Len() )
319 FilterConfigItem
aConfigItem( aConfigPath
);
320 String aPropertyName
;
321 SvtSysLocale aSysLocale
;
322 if ( aSysLocale
.GetLocaleDataPtr()->getMeasurementSystemEnum() == MEASURE_METRIC
)
323 aPropertyName
= String( RTL_CONSTASCII_USTRINGPARAM( "Metric" ) );
325 aPropertyName
= String( RTL_CONSTASCII_USTRINGPARAM( "NonMetric" ) );
326 eFieldUnit
= (FieldUnit
)aConfigItem
.ReadInt32( aPropertyName
, FUNIT_CM
);