1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <vcl/FilterConfigItem.hxx>
23 #include <vcl/graphicfilter.hxx>
24 #include <vcl/svapp.hxx>
25 #include <FltCallDialogParameter.hxx>
26 #include "exportdialog.hxx"
27 #include <tools/fldunit.hxx>
28 #include <com/sun/star/awt/XWindow.hpp>
29 #include <com/sun/star/beans/XPropertyAccess.hpp>
30 #include <com/sun/star/document/XExporter.hpp>
31 #include <com/sun/star/graphic/XGraphic.hpp>
32 #include <com/sun/star/lang/XInitialization.hpp>
33 #include <com/sun/star/lang/XServiceInfo.hpp>
34 #include <com/sun/star/uno/Sequence.h>
35 #include <com/sun/star/uno/Any.h>
36 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
37 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
38 #include <com/sun/star/uno/XComponentContext.hpp>
39 #include <unotools/localedatawrapper.hxx>
40 #include <unotools/syslocale.hxx>
41 #include <cppuhelper/implbase.hxx>
42 #include <cppuhelper/supportsservice.hxx>
44 using namespace ::com::sun::star
;
48 class SvFilterOptionsDialog
: public cppu::WeakImplHelper
51 ui::dialogs::XExecutableDialog
,
52 beans::XPropertyAccess
,
53 lang::XInitialization
,
57 const uno::Reference
< uno::XComponentContext
>
59 uno::Sequence
< beans::PropertyValue
>
61 uno::Sequence
< beans::PropertyValue
>
63 uno::Reference
< lang::XComponent
>
66 css::uno::Reference
<css::awt::XWindow
> mxParent
;
67 FieldUnit meFieldUnit
;
68 bool mbExportSelection
;
69 bool mbGraphicsSource
;
73 explicit SvFilterOptionsDialog( uno::Reference
< uno::XComponentContext
> _xORB
);
76 virtual void SAL_CALL
acquire() noexcept override
;
77 virtual void SAL_CALL
release() noexcept override
;
80 virtual void SAL_CALL
initialize( const uno::Sequence
< uno::Any
> & aArguments
) override
;
83 virtual OUString SAL_CALL
getImplementationName() override
;
84 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
85 virtual uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
88 virtual uno::Sequence
< beans::PropertyValue
> SAL_CALL
getPropertyValues() override
;
89 virtual void SAL_CALL
setPropertyValues( const uno::Sequence
< beans::PropertyValue
> & aProps
) override
;
92 virtual sal_Int16 SAL_CALL
execute() override
;
93 virtual void SAL_CALL
setTitle( const OUString
& aTitle
) override
;
96 virtual void SAL_CALL
setSourceDocument( const uno::Reference
< lang::XComponent
>& xDoc
) override
;
100 SvFilterOptionsDialog::SvFilterOptionsDialog( uno::Reference
< uno::XComponentContext
> xContext
) :
101 mxContext (std::move( xContext
)),
102 meFieldUnit ( FieldUnit::CM
),
103 mbExportSelection ( false ),
104 mbGraphicsSource ( true )
108 void SAL_CALL
SvFilterOptionsDialog::acquire() noexcept
110 OWeakObject::acquire();
114 void SAL_CALL
SvFilterOptionsDialog::release() noexcept
116 OWeakObject::release();
120 void SAL_CALL
SvFilterOptionsDialog::initialize(const uno::Sequence
<uno::Any
>& rArguments
)
122 for(const uno::Any
& rArgument
: rArguments
)
124 beans::PropertyValue aProperty
;
125 if (rArgument
>>= aProperty
)
127 if( aProperty
.Name
== "ParentWindow" )
129 aProperty
.Value
>>= mxParent
;
136 OUString SAL_CALL
SvFilterOptionsDialog::getImplementationName()
138 return "com.sun.star.svtools.SvFilterOptionsDialog";
140 sal_Bool SAL_CALL
SvFilterOptionsDialog::supportsService( const OUString
& rServiceName
)
142 return cppu::supportsService(this, rServiceName
);
144 uno::Sequence
< OUString
> SAL_CALL
SvFilterOptionsDialog::getSupportedServiceNames()
146 return { "com.sun.star.ui.dialogs.FilterOptionsDialog" };
150 uno::Sequence
< beans::PropertyValue
> SvFilterOptionsDialog::getPropertyValues()
152 auto pProp
= std::find_if(std::cbegin(maMediaDescriptor
), std::cend(maMediaDescriptor
),
153 [](const beans::PropertyValue
& rProp
) { return rProp
.Name
== "FilterData"; });
154 auto i
= static_cast<sal_Int32
>(std::distance(std::cbegin(maMediaDescriptor
), pProp
));
155 sal_Int32 nCount
= maMediaDescriptor
.getLength();
157 maMediaDescriptor
.realloc( ++nCount
);
159 // the "FilterData" Property is an Any that will contain our PropertySequence of Values
160 auto& item
= maMediaDescriptor
.getArray()[ i
];
161 item
.Name
= "FilterData";
162 item
.Value
<<= maFilterDataSequence
;
163 return maMediaDescriptor
;
166 void SvFilterOptionsDialog::setPropertyValues( const uno::Sequence
< beans::PropertyValue
> & aProps
)
168 maMediaDescriptor
= aProps
;
170 for ( const auto& rProp
: std::as_const(maMediaDescriptor
) )
172 if ( rProp
.Name
== "FilterData" )
174 rProp
.Value
>>= maFilterDataSequence
;
176 else if ( rProp
.Name
== "SelectionOnly" )
178 rProp
.Value
>>= mbExportSelection
;
184 void SvFilterOptionsDialog::setTitle( const OUString
& )
188 sal_Int16
SvFilterOptionsDialog::execute()
190 sal_Int16 nRet
= ui::dialogs::ExecutableDialogResults::CANCEL
;
192 OUString aInternalFilterName
;
193 uno::Reference
<graphic::XGraphic
> xGraphic
;
194 for ( const auto& rProp
: std::as_const(maMediaDescriptor
) )
196 const OUString
& rName
= rProp
.Name
;
197 if ( rName
== "FilterName" )
200 rProp
.Value
>>= aStr
;
201 aInternalFilterName
= aStr
.replaceFirst( "draw_", "" );
202 aInternalFilterName
= aInternalFilterName
.replaceFirst( "impress_", "" );
203 aInternalFilterName
= aInternalFilterName
.replaceFirst( "calc_", "" );
204 aInternalFilterName
= aInternalFilterName
.replaceFirst( "writer_", "" );
207 else if ( rName
== "Graphic" )
209 rProp
.Value
>>= xGraphic
;
212 if ( !aInternalFilterName
.isEmpty() )
214 GraphicFilter
aGraphicFilter( true );
216 sal_uInt16 nFormat
, nFilterCount
= aGraphicFilter
.GetExportFormatCount();
217 for ( nFormat
= 0; nFormat
< nFilterCount
; nFormat
++ )
219 if ( aGraphicFilter
.GetExportInternalFilterName( nFormat
) == aInternalFilterName
)
222 if ( nFormat
< nFilterCount
)
224 FltCallDialogParameter
aFltCallDlgPara(Application::GetFrameWeld(mxParent
), meFieldUnit
);
225 aFltCallDlgPara
.aFilterData
= maFilterDataSequence
;
226 aFltCallDlgPara
.aFilterExt
= aGraphicFilter
.GetExportFormatShortName( nFormat
);
227 bool bIsPixelFormat( aGraphicFilter
.IsExportPixelFormat( nFormat
) );
229 ExportDialog
aDialog(aFltCallDlgPara
, mxContext
, mxSourceDocument
, mbExportSelection
,
230 bIsPixelFormat
, mbGraphicsSource
, xGraphic
);
231 if (aDialog
.run() == RET_OK
)
232 nRet
= ui::dialogs::ExecutableDialogResults::OK
;
234 // taking the out parameter from the dialog
235 maFilterDataSequence
= aFltCallDlgPara
.aFilterData
;
242 void SvFilterOptionsDialog::setSourceDocument( const uno::Reference
< lang::XComponent
>& xDoc
)
244 mxSourceDocument
= xDoc
;
246 mbGraphicsSource
= true; // default Draw and Impress like it was before
248 // try to set the corresponding metric unit
249 OUString aConfigPath
;
250 uno::Reference
< lang::XServiceInfo
> xServiceInfo
251 ( xDoc
, uno::UNO_QUERY
);
252 if ( !xServiceInfo
.is() )
255 if ( xServiceInfo
->supportsService("com.sun.star.presentation.PresentationDocument") )
256 aConfigPath
= "Office.Impress/Layout/Other/MeasureUnit";
257 else if ( xServiceInfo
->supportsService("com.sun.star.drawing.DrawingDocument") )
258 aConfigPath
= "Office.Draw/Layout/Other/MeasureUnit";
261 mbGraphicsSource
= false;
262 if ( xServiceInfo
->supportsService("com.sun.star.sheet.SpreadsheetDocument") )
263 aConfigPath
= "Office.Calc/Layout/Other/MeasureUnit";
264 else if ( xServiceInfo
->supportsService("com.sun.star.text.TextDocument") )
265 aConfigPath
= "Office.Writer/Layout/Other/MeasureUnit";
267 if ( !aConfigPath
.isEmpty() )
269 FilterConfigItem
aConfigItem( aConfigPath
);
270 OUString aPropertyName
;
271 SvtSysLocale aSysLocale
;
272 if ( aSysLocale
.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric
)
273 aPropertyName
= "Metric";
275 aPropertyName
= "NonMetric";
276 meFieldUnit
= static_cast<FieldUnit
>(
277 aConfigItem
.ReadInt32(aPropertyName
, sal_Int32(FieldUnit::CM
)));
283 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
284 com_sun_star_svtools_SvFilterOptionsDialog_get_implementation(
285 css::uno::XComponentContext
* context
,
286 css::uno::Sequence
<css::uno::Any
> const &)
288 return cppu::acquire(new SvFilterOptionsDialog(context
));
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */