LibreOffice Module svtools (master) 1
SvFilterOptionsDialog.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <utility>
23#include <vcl/graphicfilter.hxx>
24#include <vcl/svapp.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>
43
44using namespace ::com::sun::star;
45
46namespace {
47
48class SvFilterOptionsDialog : public cppu::WeakImplHelper
49<
50 document::XExporter,
51 ui::dialogs::XExecutableDialog,
52 beans::XPropertyAccess,
53 lang::XInitialization,
54 lang::XServiceInfo
55>
56{
57 const uno::Reference< uno::XComponentContext >
59 uno::Sequence< beans::PropertyValue >
60 maMediaDescriptor;
61 uno::Sequence< beans::PropertyValue >
62 maFilterDataSequence;
63 uno::Reference< lang::XComponent >
64 mxSourceDocument;
65
66 css::uno::Reference<css::awt::XWindow> mxParent;
67 FieldUnit meFieldUnit;
68 bool mbExportSelection;
69 bool mbGraphicsSource;
70
71public:
72
73 explicit SvFilterOptionsDialog( uno::Reference< uno::XComponentContext > _xORB );
74
75 // XInterface
76 virtual void SAL_CALL acquire() noexcept override;
77 virtual void SAL_CALL release() noexcept override;
78
79 // XInitialization
80 virtual void SAL_CALL initialize( const uno::Sequence< uno::Any > & aArguments ) override;
81
82 // XServiceInfo
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;
86
87 // XPropertyAccess
88 virtual uno::Sequence< beans::PropertyValue > SAL_CALL getPropertyValues() override;
89 virtual void SAL_CALL setPropertyValues( const uno::Sequence< beans::PropertyValue > & aProps ) override;
90
91 // XExecuteDialog
92 virtual sal_Int16 SAL_CALL execute() override;
93 virtual void SAL_CALL setTitle( const OUString& aTitle ) override;
94
95 // XExporter
96 virtual void SAL_CALL setSourceDocument( const uno::Reference< lang::XComponent >& xDoc ) override;
97
98};
99
100SvFilterOptionsDialog::SvFilterOptionsDialog( uno::Reference< uno::XComponentContext > xContext ) :
101 mxContext (std::move( xContext )),
102 meFieldUnit ( FieldUnit::CM ),
103 mbExportSelection ( false ),
104 mbGraphicsSource ( true )
105{
106}
107
108void SAL_CALL SvFilterOptionsDialog::acquire() noexcept
109{
110 OWeakObject::acquire();
111}
112
113
114void SAL_CALL SvFilterOptionsDialog::release() noexcept
115{
116 OWeakObject::release();
117}
118
119// XInitialization
120void SAL_CALL SvFilterOptionsDialog::initialize(const uno::Sequence<uno::Any>& rArguments)
121{
122 for(const uno::Any& rArgument : rArguments)
123 {
124 beans::PropertyValue aProperty;
125 if (rArgument >>= aProperty)
126 {
127 if( aProperty.Name == "ParentWindow" )
128 {
129 aProperty.Value >>= mxParent;
130 }
131 }
132 }
133}
134
135// XServiceInfo
136OUString SAL_CALL SvFilterOptionsDialog::getImplementationName()
137{
138 return "com.sun.star.svtools.SvFilterOptionsDialog";
139}
140sal_Bool SAL_CALL SvFilterOptionsDialog::supportsService( const OUString& rServiceName )
141{
142 return cppu::supportsService(this, rServiceName);
143}
144uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog::getSupportedServiceNames()
145{
146 return { "com.sun.star.ui.dialogs.FilterOptionsDialog" };
147}
148
149// XPropertyAccess
150uno::Sequence< beans::PropertyValue > SvFilterOptionsDialog::getPropertyValues()
151{
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();
156 if ( i == nCount )
157 maMediaDescriptor.realloc( ++nCount );
158
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;
164}
165
166void SvFilterOptionsDialog::setPropertyValues( const uno::Sequence< beans::PropertyValue > & aProps )
167{
168 maMediaDescriptor = aProps;
169
170 for ( const auto& rProp : std::as_const(maMediaDescriptor) )
171 {
172 if ( rProp.Name == "FilterData" )
173 {
174 rProp.Value >>= maFilterDataSequence;
175 }
176 else if ( rProp.Name == "SelectionOnly" )
177 {
178 rProp.Value >>= mbExportSelection;
179 }
180 }
181}
182
183// XExecutableDialog
184void SvFilterOptionsDialog::setTitle( const OUString& )
185{
186}
187
188sal_Int16 SvFilterOptionsDialog::execute()
189{
190 sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
191
192 OUString aInternalFilterName;
193 uno::Reference<graphic::XGraphic> xGraphic;
194 for ( const auto& rProp : std::as_const(maMediaDescriptor) )
195 {
196 const OUString& rName = rProp.Name;
197 if ( rName == "FilterName" )
198 {
199 OUString aStr;
200 rProp.Value >>= aStr;
201 aInternalFilterName = aStr.replaceFirst( "draw_", "" );
202 aInternalFilterName = aInternalFilterName.replaceFirst( "impress_", "" );
203 aInternalFilterName = aInternalFilterName.replaceFirst( "calc_", "" );
204 aInternalFilterName = aInternalFilterName.replaceFirst( "writer_", "" );
205 break;
206 }
207 else if ( rName == "Graphic" )
208 {
209 rProp.Value >>= xGraphic;
210 }
211 }
212 if ( !aInternalFilterName.isEmpty() )
213 {
214 GraphicFilter aGraphicFilter( true );
215
216 sal_uInt16 nFormat, nFilterCount = aGraphicFilter.GetExportFormatCount();
217 for ( nFormat = 0; nFormat < nFilterCount; nFormat++ )
218 {
219 if ( aGraphicFilter.GetExportInternalFilterName( nFormat ) == aInternalFilterName )
220 break;
221 }
222 if ( nFormat < nFilterCount )
223 {
224 FltCallDialogParameter aFltCallDlgPara(Application::GetFrameWeld(mxParent), meFieldUnit);
225 aFltCallDlgPara.aFilterData = maFilterDataSequence;
226 aFltCallDlgPara.aFilterExt = aGraphicFilter.GetExportFormatShortName( nFormat );
227 bool bIsPixelFormat( aGraphicFilter.IsExportPixelFormat( nFormat ) );
228
229 ExportDialog aDialog(aFltCallDlgPara, mxContext, mxSourceDocument, mbExportSelection,
230 bIsPixelFormat, mbGraphicsSource, xGraphic);
231 if (aDialog.run() == RET_OK)
232 nRet = ui::dialogs::ExecutableDialogResults::OK;
233
234 // taking the out parameter from the dialog
235 maFilterDataSequence = aFltCallDlgPara.aFilterData;
236 }
237 }
238 return nRet;
239}
240
241// XEmporter
242void SvFilterOptionsDialog::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
243{
244 mxSourceDocument = xDoc;
245
246 mbGraphicsSource = true; // default Draw and Impress like it was before
247
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() )
253 return;
254
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";
259 else
260 {
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";
266 }
267 if ( !aConfigPath.isEmpty() )
268 {
269 FilterConfigItem aConfigItem( aConfigPath );
270 OUString aPropertyName;
271 SvtSysLocale aSysLocale;
272 if ( aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric )
273 aPropertyName = "Metric";
274 else
275 aPropertyName = "NonMetric";
276 meFieldUnit = static_cast<FieldUnit>(
277 aConfigItem.ReadInt32(aPropertyName, sal_Int32(FieldUnit::CM)));
278 }
279}
280
281}
282
283extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
285 css::uno::XComponentContext * context,
286 css::uno::Sequence<css::uno::Any> const &)
287{
288 return cppu::acquire(new SvFilterOptionsDialog(context));
289}
290
291/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_svtools_SvFilterOptionsDialog_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
unotools::WeakReference< AnimationNode > mxParent
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
MeasurementSystem getMeasurementSystemEnum() const
const LocaleDataWrapper & GetLocaleData() const
int nCount
uno::Reference< uno::XComponentContext > mxContext
FieldUnit
aStr
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
unsigned char sal_Bool