fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svtools / source / filter / SvFilterOptionsDialog.cxx
blobe2734837a79364375a1fa0a904cca5ace99ac5ba
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <vcl/FilterConfigItem.hxx>
22 #include <vcl/graphicfilter.hxx>
23 #include <vcl/svapp.hxx>
24 #include <osl/file.hxx>
25 #include <osl/module.hxx>
26 #include <rtl/ref.hxx>
27 #include <svl/solar.hrc>
28 #include <vcl/fltcall.hxx>
29 #include <vcl/settings.hxx>
30 #include "exportdialog.hxx"
31 #include <uno/mapping.hxx>
32 #include <tools/fldunit.hxx>
33 #include <com/sun/star/frame/XModel.hpp>
34 #include <com/sun/star/beans/XPropertyAccess.hpp>
35 #include <com/sun/star/document/XExporter.hpp>
36 #include <com/sun/star/document/XViewDataSupplier.hpp>
37 #include <com/sun/star/container/XIndexAccess.hpp>
38 #include <com/sun/star/lang/XInitialization.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/uno/Sequence.h>
41 #include <com/sun/star/uno/Any.h>
42 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
43 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
44 #include <com/sun/star/uno/XComponentContext.hpp>
45 #include <unotools/syslocale.hxx>
46 #include <comphelper/processfactory.hxx>
47 #include <cppuhelper/implbase5.hxx>
48 #include <cppuhelper/supportsservice.hxx>
49 #include <boost/scoped_ptr.hpp>
51 using namespace ::com::sun::star;
53 namespace {
55 class SvFilterOptionsDialog : public cppu::WeakImplHelper5
57 document::XExporter,
58 ui::dialogs::XExecutableDialog,
59 beans::XPropertyAccess,
60 lang::XInitialization,
61 lang::XServiceInfo
64 const uno::Reference< uno::XComponentContext >
65 mxContext;
66 uno::Sequence< beans::PropertyValue >
67 maMediaDescriptor;
68 uno::Sequence< beans::PropertyValue >
69 maFilterDataSequence;
70 uno::Reference< lang::XComponent >
71 mxSourceDocument;
73 OUString maDialogTitle;
74 FieldUnit meFieldUnit;
75 bool mbExportSelection;
77 public:
79 SvFilterOptionsDialog( const uno::Reference< uno::XComponentContext >& _rxORB );
80 virtual ~SvFilterOptionsDialog();
82 // XInterface
83 virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
84 virtual void SAL_CALL release() throw() SAL_OVERRIDE;
86 // XInitialization
87 virtual void SAL_CALL initialize( const uno::Sequence< uno::Any > & aArguments )
88 throw ( uno::Exception, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
90 // XServiceInfo
91 virtual OUString SAL_CALL getImplementationName()
92 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
93 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName )
94 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
95 virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
96 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
98 // XPropertyAccess
99 virtual uno::Sequence< beans::PropertyValue > SAL_CALL getPropertyValues()
100 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
101 virtual void SAL_CALL setPropertyValues( const uno::Sequence< beans::PropertyValue > & aProps )
102 throw ( beans::UnknownPropertyException, beans::PropertyVetoException,
103 lang::IllegalArgumentException, lang::WrappedTargetException,
104 uno::RuntimeException, std::exception ) SAL_OVERRIDE;
106 // XExecuteDialog
107 virtual sal_Int16 SAL_CALL execute()
108 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
109 virtual void SAL_CALL setTitle( const OUString& aTitle )
110 throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
112 // XExporter
113 virtual void SAL_CALL setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
114 throw ( lang::IllegalArgumentException, uno::RuntimeException, std::exception ) SAL_OVERRIDE;
118 SvFilterOptionsDialog::SvFilterOptionsDialog( const uno::Reference< uno::XComponentContext >& rxContext ) :
119 mxContext ( rxContext ),
120 meFieldUnit ( FUNIT_CM ),
121 mbExportSelection ( false )
127 SvFilterOptionsDialog::~SvFilterOptionsDialog()
133 void SAL_CALL SvFilterOptionsDialog::acquire() throw()
135 OWeakObject::acquire();
140 void SAL_CALL SvFilterOptionsDialog::release() throw()
142 OWeakObject::release();
145 // XInitialization
146 void SAL_CALL SvFilterOptionsDialog::initialize( const uno::Sequence< uno::Any > & )
147 throw ( uno::Exception, uno::RuntimeException, std::exception )
151 // XServiceInfo
152 OUString SAL_CALL SvFilterOptionsDialog::getImplementationName()
153 throw( uno::RuntimeException, std::exception )
155 return OUString( "com.sun.star.svtools.SvFilterOptionsDialog" );
157 sal_Bool SAL_CALL SvFilterOptionsDialog::supportsService( const OUString& rServiceName )
158 throw( uno::RuntimeException, std::exception )
160 return cppu::supportsService(this, rServiceName);
162 uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog::getSupportedServiceNames()
163 throw ( uno::RuntimeException, std::exception )
165 uno::Sequence< OUString > aRet(1);
166 OUString* pArray = aRet.getArray();
167 pArray[0] = "com.sun.star.ui.dialogs.FilterOptionsDialog";
168 return aRet;
171 // XPropertyAccess
172 uno::Sequence< beans::PropertyValue > SvFilterOptionsDialog::getPropertyValues()
173 throw ( uno::RuntimeException, std::exception )
175 sal_Int32 i, nCount;
176 for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
178 if ( maMediaDescriptor[ i ].Name == "FilterData" )
179 break;
181 if ( i == nCount )
182 maMediaDescriptor.realloc( ++nCount );
184 // the "FilterData" Property is an Any that will contain our PropertySequence of Values
185 maMediaDescriptor[ i ].Name = "FilterData";
186 maMediaDescriptor[ i ].Value <<= maFilterDataSequence;
187 return maMediaDescriptor;
190 void SvFilterOptionsDialog::setPropertyValues( const uno::Sequence< beans::PropertyValue > & aProps )
191 throw ( beans::UnknownPropertyException, beans::PropertyVetoException,
192 lang::IllegalArgumentException, lang::WrappedTargetException,
193 uno::RuntimeException, std::exception )
195 maMediaDescriptor = aProps;
197 sal_Int32 i, nCount;
198 for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
200 if ( maMediaDescriptor[ i ].Name == "FilterData" )
202 maMediaDescriptor[ i ].Value >>= maFilterDataSequence;
204 else if ( maMediaDescriptor[ i ].Name == "SelectionOnly" )
206 maMediaDescriptor[ i ].Value >>= mbExportSelection;
211 // XExecutableDialog
212 void SvFilterOptionsDialog::setTitle( const OUString& aTitle )
213 throw ( uno::RuntimeException, std::exception )
215 maDialogTitle = aTitle;
218 sal_Int16 SvFilterOptionsDialog::execute()
219 throw ( uno::RuntimeException, std::exception )
221 sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
223 OUString aFilterNameStr( "FilterName" );
224 OUString aInternalFilterName;
225 sal_Int32 j, nCount = maMediaDescriptor.getLength();
226 for ( j = 0; j < nCount; j++ )
228 if ( maMediaDescriptor[ j ].Name.equals( aFilterNameStr ) )
230 OUString aStr;
231 maMediaDescriptor[ j ].Value >>= aStr;
232 aInternalFilterName = aStr;
233 aInternalFilterName = aInternalFilterName.replaceAll( "draw_", "" );
234 aInternalFilterName = aInternalFilterName.replaceAll( "impress_", "" );
235 break;
238 if ( !aInternalFilterName.isEmpty() )
240 GraphicFilter aGraphicFilter( true );
242 sal_uInt16 nFormat, nFilterCount = aGraphicFilter.GetExportFormatCount();
243 for ( nFormat = 0; nFormat < nFilterCount; nFormat++ )
245 if ( aGraphicFilter.GetExportInternalFilterName( nFormat ) == aInternalFilterName )
246 break;
248 if ( nFormat < nFilterCount )
250 FltCallDialogParameter aFltCallDlgPara( Application::GetDefDialogParent(), NULL, meFieldUnit );
251 aFltCallDlgPara.aFilterData = maFilterDataSequence;
253 boost::scoped_ptr<ResMgr> pResMgr(ResMgr::CreateResMgr( "svt", Application::GetSettings().GetUILanguageTag() ));
254 aFltCallDlgPara.pResMgr = pResMgr.get();
256 aFltCallDlgPara.aFilterExt = aGraphicFilter.GetExportFormatShortName( nFormat );
257 bool bIsPixelFormat( aGraphicFilter.IsExportPixelFormat( nFormat ) );
258 if ( ScopedVclPtrInstance<ExportDialog>::Create( aFltCallDlgPara, mxContext, mxSourceDocument, mbExportSelection, bIsPixelFormat )->Execute() == RET_OK )
259 nRet = ui::dialogs::ExecutableDialogResults::OK;
261 pResMgr.reset();
263 // taking the out parameter from the dialog
264 maFilterDataSequence = aFltCallDlgPara.aFilterData;
267 return nRet;
270 // XEmporter
271 void SvFilterOptionsDialog::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
272 throw ( lang::IllegalArgumentException, uno::RuntimeException, std::exception )
274 mxSourceDocument = xDoc;
276 // try to set the corresponding metric unit
277 OUString aConfigPath;
278 uno::Reference< lang::XServiceInfo > xServiceInfo
279 ( xDoc, uno::UNO_QUERY );
280 if ( xServiceInfo.is() )
282 if ( xServiceInfo->supportsService("com.sun.star.presentation.PresentationDocument") )
283 aConfigPath = "Office.Impress/Layout/Other/MeasureUnit";
284 else if ( xServiceInfo->supportsService("com.sun.star.drawing.DrawingDocument") )
285 aConfigPath = "Office.Draw/Layout/Other/MeasureUnit";
286 if ( !aConfigPath.isEmpty() )
288 FilterConfigItem aConfigItem( aConfigPath );
289 OUString aPropertyName;
290 SvtSysLocale aSysLocale;
291 if ( aSysLocale.GetLocaleDataPtr()->getMeasurementSystemEnum() == MEASURE_METRIC )
292 aPropertyName = "Metric";
293 else
294 aPropertyName = "NonMetric";
295 meFieldUnit = (FieldUnit)aConfigItem.ReadInt32( aPropertyName, FUNIT_CM );
302 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
303 com_sun_star_svtools_SvFilterOptionsDialog_get_implementation(
304 css::uno::XComponentContext * context,
305 css::uno::Sequence<css::uno::Any> const &)
307 return cppu::acquire(new SvFilterOptionsDialog(context));
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */