Line data Source code
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 "SvFilterOptionsDialog.hxx"
22 : #include <vcl/FilterConfigItem.hxx>
23 : #include <vcl/graphicfilter.hxx>
24 : #include <osl/file.hxx>
25 : #include <osl/module.hxx>
26 : #include <svl/solar.hrc>
27 : #include <vcl/fltcall.hxx>
28 : #include "exportdialog.hxx"
29 : #include <uno/mapping.hxx>
30 : #include <com/sun/star/frame/XModel.hpp>
31 : #include <com/sun/star/document/XViewDataSupplier.hpp>
32 : #include <com/sun/star/container/XIndexAccess.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 <unotools/syslocale.hxx>
37 : #include <comphelper/processfactory.hxx>
38 : #include "vcl/svapp.hxx"
39 :
40 : using namespace ::rtl;
41 : using namespace ::com::sun::star;
42 :
43 : // -------------------------
44 : // - SvFilterOptionsDialog -
45 : // -------------------------
46 :
47 : uno::Reference< uno::XInterface >
48 0 : SAL_CALL SvFilterOptionsDialog_CreateInstance(
49 : const uno::Reference< lang::XMultiServiceFactory > & _rxFactory )
50 : {
51 0 : return static_cast< ::cppu::OWeakObject* > ( new SvFilterOptionsDialog( comphelper::getComponentContext(_rxFactory) ) );
52 : }
53 :
54 0 : OUString SvFilterOptionsDialog_getImplementationName()
55 : throw( uno::RuntimeException )
56 : {
57 0 : return OUString( "com.sun.star.comp.svtools.SvFilterOptionsDialog" );
58 : }
59 : #define SERVICE_NAME "com.sun.star.ui.dialog.FilterOptionsDialog"
60 0 : sal_Bool SAL_CALL SvFilterOptionsDialog_supportsService( const OUString& ServiceName )
61 : throw( uno::RuntimeException )
62 : {
63 0 : return ServiceName == SERVICE_NAME;
64 : }
65 :
66 0 : uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog_getSupportedServiceNames()
67 : throw( uno::RuntimeException )
68 : {
69 0 : uno::Sequence< OUString > aRet(1);
70 0 : OUString* pArray = aRet.getArray();
71 0 : pArray[0] = OUString( SERVICE_NAME );
72 0 : return aRet;
73 : }
74 : #undef SERVICE_NAME
75 :
76 : // -----------------------------------------------------------------------------
77 :
78 0 : SvFilterOptionsDialog::SvFilterOptionsDialog( const uno::Reference< uno::XComponentContext >& rxContext ) :
79 : mxContext ( rxContext ),
80 : meFieldUnit ( FUNIT_CM ),
81 0 : mbExportSelection ( sal_False )
82 : {
83 0 : }
84 :
85 : // -----------------------------------------------------------------------------
86 :
87 0 : SvFilterOptionsDialog::~SvFilterOptionsDialog()
88 : {
89 0 : }
90 :
91 : // -----------------------------------------------------------------------------
92 :
93 0 : void SAL_CALL SvFilterOptionsDialog::acquire() throw()
94 : {
95 0 : OWeakObject::acquire();
96 0 : }
97 :
98 : // -----------------------------------------------------------------------------
99 :
100 0 : void SAL_CALL SvFilterOptionsDialog::release() throw()
101 : {
102 0 : OWeakObject::release();
103 0 : }
104 :
105 : // XInitialization
106 0 : void SAL_CALL SvFilterOptionsDialog::initialize( const uno::Sequence< uno::Any > & )
107 : throw ( uno::Exception, uno::RuntimeException )
108 : {
109 0 : }
110 :
111 : // XServiceInfo
112 0 : OUString SAL_CALL SvFilterOptionsDialog::getImplementationName()
113 : throw( uno::RuntimeException )
114 : {
115 0 : return SvFilterOptionsDialog_getImplementationName();
116 : }
117 0 : sal_Bool SAL_CALL SvFilterOptionsDialog::supportsService( const OUString& rServiceName )
118 : throw( uno::RuntimeException )
119 : {
120 0 : return SvFilterOptionsDialog_supportsService( rServiceName );
121 : }
122 0 : uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog::getSupportedServiceNames()
123 : throw ( uno::RuntimeException )
124 : {
125 0 : return SvFilterOptionsDialog_getSupportedServiceNames();
126 : }
127 :
128 :
129 : // XPropertyAccess
130 0 : uno::Sequence< beans::PropertyValue > SvFilterOptionsDialog::getPropertyValues()
131 : throw ( uno::RuntimeException )
132 : {
133 : sal_Int32 i, nCount;
134 0 : for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
135 : {
136 0 : if ( maMediaDescriptor[ i ].Name == "FilterData" )
137 0 : break;
138 : }
139 0 : if ( i == nCount )
140 0 : maMediaDescriptor.realloc( ++nCount );
141 :
142 : // the "FilterData" Property is an Any that will contain our PropertySequence of Values
143 0 : maMediaDescriptor[ i ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "FilterData" ) );
144 0 : maMediaDescriptor[ i ].Value <<= maFilterDataSequence;
145 0 : return maMediaDescriptor;
146 : }
147 :
148 0 : void SvFilterOptionsDialog::setPropertyValues( const uno::Sequence< beans::PropertyValue > & aProps )
149 : throw ( beans::UnknownPropertyException, beans::PropertyVetoException,
150 : lang::IllegalArgumentException, lang::WrappedTargetException,
151 : uno::RuntimeException )
152 : {
153 0 : maMediaDescriptor = aProps;
154 :
155 : sal_Int32 i, nCount;
156 0 : for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
157 : {
158 0 : if ( maMediaDescriptor[ i ].Name == "FilterData" )
159 : {
160 0 : maMediaDescriptor[ i ].Value >>= maFilterDataSequence;
161 : }
162 0 : else if ( maMediaDescriptor[ i ].Name == "SelectionOnly" )
163 : {
164 0 : maMediaDescriptor[ i ].Value >>= mbExportSelection;
165 : }
166 : }
167 0 : }
168 :
169 : // XExecutableDialog
170 0 : void SvFilterOptionsDialog::setTitle( const OUString& aTitle )
171 : throw ( uno::RuntimeException )
172 : {
173 0 : maDialogTitle = aTitle;
174 0 : }
175 :
176 0 : sal_Int16 SvFilterOptionsDialog::execute()
177 : throw ( uno::RuntimeException )
178 : {
179 0 : sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
180 :
181 0 : String aFilterNameStr( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
182 0 : String aInternalFilterName;
183 0 : sal_Int32 j, nCount = maMediaDescriptor.getLength();
184 0 : for ( j = 0; j < nCount; j++ )
185 : {
186 0 : if ( maMediaDescriptor[ j ].Name.equals( aFilterNameStr ) )
187 : {
188 0 : OUString aStr;
189 0 : maMediaDescriptor[ j ].Value >>= aStr;
190 0 : aInternalFilterName = aStr;
191 0 : aInternalFilterName.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "draw_" ) ), String(), 0 );
192 0 : aInternalFilterName.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "impress_" ) ), String(), 0 );
193 0 : break;
194 : }
195 : }
196 0 : if ( aInternalFilterName.Len() )
197 : {
198 0 : GraphicFilter aGraphicFilter( sal_True );
199 :
200 0 : sal_uInt16 nFormat, nFilterCount = aGraphicFilter.GetExportFormatCount();
201 0 : for ( nFormat = 0; nFormat < nFilterCount; nFormat++ )
202 : {
203 0 : if ( aGraphicFilter.GetExportInternalFilterName( nFormat ) == aInternalFilterName )
204 0 : break;
205 : }
206 0 : if ( nFormat < nFilterCount )
207 : {
208 0 : FltCallDialogParameter aFltCallDlgPara( Application::GetDefDialogParent(), NULL, meFieldUnit );
209 0 : aFltCallDlgPara.aFilterData = maFilterDataSequence;
210 :
211 : ResMgr* pResMgr;
212 :
213 0 : pResMgr = ResMgr::CreateResMgr( "svt", Application::GetSettings().GetUILanguageTag() );
214 0 : aFltCallDlgPara.pResMgr = pResMgr;
215 :
216 0 : aFltCallDlgPara.aFilterExt = aGraphicFilter.GetExportFormatShortName( nFormat );
217 0 : sal_Bool bIsPixelFormat( aGraphicFilter.IsExportPixelFormat( nFormat ) );
218 0 : if ( ExportDialog( aFltCallDlgPara, mxContext, mxSourceDocument, mbExportSelection, bIsPixelFormat ).Execute() == RET_OK )
219 0 : nRet = ui::dialogs::ExecutableDialogResults::OK;
220 :
221 0 : delete pResMgr;
222 :
223 : // taking the out parameter from the dialog
224 0 : maFilterDataSequence = aFltCallDlgPara.aFilterData;
225 0 : }
226 : }
227 0 : return nRet;
228 : }
229 :
230 : // XEmporter
231 0 : void SvFilterOptionsDialog::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
232 : throw ( lang::IllegalArgumentException, uno::RuntimeException )
233 : {
234 0 : mxSourceDocument = xDoc;
235 :
236 : // try to set the corresponding metric unit
237 0 : String aConfigPath;
238 : uno::Reference< lang::XServiceInfo > xServiceInfo
239 0 : ( xDoc, uno::UNO_QUERY );
240 0 : if ( xServiceInfo.is() )
241 : {
242 0 : if ( xServiceInfo->supportsService("com.sun.star.presentation.PresentationDocument") )
243 0 : aConfigPath = String( RTL_CONSTASCII_USTRINGPARAM( "Office.Impress/Layout/Other/MeasureUnit" ) );
244 0 : else if ( xServiceInfo->supportsService("com.sun.star.drawing.DrawingDocument") )
245 0 : aConfigPath = String( RTL_CONSTASCII_USTRINGPARAM( "Office.Draw/Layout/Other/MeasureUnit" ) );
246 0 : if ( aConfigPath.Len() )
247 : {
248 0 : FilterConfigItem aConfigItem( aConfigPath );
249 0 : String aPropertyName;
250 0 : SvtSysLocale aSysLocale;
251 0 : if ( aSysLocale.GetLocaleDataPtr()->getMeasurementSystemEnum() == MEASURE_METRIC )
252 0 : aPropertyName = String( RTL_CONSTASCII_USTRINGPARAM( "Metric" ) );
253 : else
254 0 : aPropertyName = String( RTL_CONSTASCII_USTRINGPARAM( "NonMetric" ) );
255 0 : meFieldUnit = (FieldUnit)aConfigItem.ReadInt32( aPropertyName, FUNIT_CM );
256 : }
257 0 : }
258 465 : }
259 :
260 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|