1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26
27 #include "SvFilterOptionsDialog.hxx"
28 #include <svtools/FilterConfigItem.hxx>
29 #include <svtools/filter.hxx>
30 #include "FilterConfigCache.hxx"
31 #include <osl/file.hxx>
32 #include <osl/module.hxx>
33 #include <svl/solar.hrc>
34 #include <svtools/fltcall.hxx>
35 #include "exportdialog.hxx"
36 #include <uno/mapping.hxx>
37 #include <com/sun/star/frame/XModel.hpp>
38 #include <com/sun/star/document/XViewDataSupplier.hpp>
39 #include <com/sun/star/container/XIndexAccess.hpp>
40 #include <com/sun/star/lang/XServiceInfo.hpp>
41 #include <com/sun/star/uno/Sequence.h>
42 #include <com/sun/star/uno/Any.h>
43 #include <unotools/syslocale.hxx>
44 #include "vcl/svapp.hxx"
45
46 using namespace ::rtl;
47 using namespace ::com::sun::star;
48
49 // -------------------------
50 // - SvFilterOptionsDialog -
51 // -------------------------
52
53 uno::Reference< uno::XInterface >
SvFilterOptionsDialog_CreateInstance(const uno::Reference<lang::XMultiServiceFactory> & _rxFactory)54 SAL_CALL SvFilterOptionsDialog_CreateInstance(
55 const uno::Reference< lang::XMultiServiceFactory > & _rxFactory )
56 {
57 return static_cast< ::cppu::OWeakObject* > ( new SvFilterOptionsDialog( _rxFactory ) );
58 }
59
SvFilterOptionsDialog_getImplementationName()60 OUString SvFilterOptionsDialog_getImplementationName()
61 throw( uno::RuntimeException )
62 {
63 return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.SvFilterOptionsDialog" ) );
64 }
65 #define SERVICE_NAME "com.sun.star.ui.dialog.FilterOptionsDialog"
SvFilterOptionsDialog_supportsService(const OUString & ServiceName)66 sal_Bool SAL_CALL SvFilterOptionsDialog_supportsService( const OUString& ServiceName )
67 throw( uno::RuntimeException )
68 {
69 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
70 }
71
SvFilterOptionsDialog_getSupportedServiceNames()72 uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog_getSupportedServiceNames()
73 throw( uno::RuntimeException )
74 {
75 uno::Sequence< OUString > aRet(1);
76 OUString* pArray = aRet.getArray();
77 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
78 return aRet;
79 }
80 #undef SERVICE_NAME
81
82 // -----------------------------------------------------------------------------
83
SvFilterOptionsDialog(const uno::Reference<lang::XMultiServiceFactory> xMgr)84 SvFilterOptionsDialog::SvFilterOptionsDialog( const uno::Reference< lang::XMultiServiceFactory > xMgr ) :
85 mxMgr ( xMgr ),
86 meFieldUnit ( FUNIT_CM ),
87 mbExportSelection ( sal_False )
88 {
89 }
90
91 // -----------------------------------------------------------------------------
92
~SvFilterOptionsDialog()93 SvFilterOptionsDialog::~SvFilterOptionsDialog()
94 {
95 }
96
97 // -----------------------------------------------------------------------------
98
acquire()99 void SAL_CALL SvFilterOptionsDialog::acquire() throw()
100 {
101 OWeakObject::acquire();
102 }
103
104 // -----------------------------------------------------------------------------
105
release()106 void SAL_CALL SvFilterOptionsDialog::release() throw()
107 {
108 OWeakObject::release();
109 }
110
111 // XInitialization
initialize(const uno::Sequence<uno::Any> &)112 void SAL_CALL SvFilterOptionsDialog::initialize( const uno::Sequence< uno::Any > & )
113 throw ( uno::Exception, uno::RuntimeException )
114 {
115 }
116
117 // XServiceInfo
getImplementationName()118 OUString SAL_CALL SvFilterOptionsDialog::getImplementationName()
119 throw( uno::RuntimeException )
120 {
121 return SvFilterOptionsDialog_getImplementationName();
122 }
supportsService(const OUString & rServiceName)123 sal_Bool SAL_CALL SvFilterOptionsDialog::supportsService( const OUString& rServiceName )
124 throw( uno::RuntimeException )
125 {
126 return SvFilterOptionsDialog_supportsService( rServiceName );
127 }
getSupportedServiceNames()128 uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog::getSupportedServiceNames()
129 throw ( uno::RuntimeException )
130 {
131 return SvFilterOptionsDialog_getSupportedServiceNames();
132 }
133
134
135 // XPropertyAccess
getPropertyValues()136 uno::Sequence< beans::PropertyValue > SvFilterOptionsDialog::getPropertyValues()
137 throw ( uno::RuntimeException )
138 {
139 sal_Int32 i, nCount;
140 for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
141 {
142 if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) )
143 break;
144 }
145 if ( i == nCount )
146 maMediaDescriptor.realloc( ++nCount );
147
148 // the "FilterData" Property is an Any that will contain our PropertySequence of Values
149 maMediaDescriptor[ i ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "FilterData" ) );
150 maMediaDescriptor[ i ].Value <<= maFilterDataSequence;
151 return maMediaDescriptor;
152 }
153
setPropertyValues(const uno::Sequence<beans::PropertyValue> & aProps)154 void SvFilterOptionsDialog::setPropertyValues( const uno::Sequence< beans::PropertyValue > & aProps )
155 throw ( beans::UnknownPropertyException, beans::PropertyVetoException,
156 lang::IllegalArgumentException, lang::WrappedTargetException,
157 uno::RuntimeException )
158 {
159 maMediaDescriptor = aProps;
160
161 sal_Int32 i, nCount;
162 for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
163 {
164 if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) )
165 {
166 maMediaDescriptor[ i ].Value >>= maFilterDataSequence;
167 }
168 else if ( maMediaDescriptor[ i ].Name.equalsAscii( "SelectionOnly" ) )
169 {
170 maMediaDescriptor[ i ].Value >>= mbExportSelection;
171 }
172 }
173 }
174
175 // XExecutableDialog
setTitle(const OUString & aTitle)176 void SvFilterOptionsDialog::setTitle( const OUString& aTitle )
177 throw ( uno::RuntimeException )
178 {
179 maDialogTitle = aTitle;
180 }
181
execute()182 sal_Int16 SvFilterOptionsDialog::execute()
183 throw ( uno::RuntimeException )
184 {
185 sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
186
187 String aFilterNameStr( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
188 String aInternalFilterName;
189 sal_Int32 j, nCount = maMediaDescriptor.getLength();
190 for ( j = 0; j < nCount; j++ )
191 {
192 if ( maMediaDescriptor[ j ].Name.equals( aFilterNameStr ) )
193 {
194 OUString aStr;
195 maMediaDescriptor[ j ].Value >>= aStr;
196 aInternalFilterName = aStr;
197 aInternalFilterName.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "draw_" ) ), String(), 0 );
198 aInternalFilterName.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "impress_" ) ), String(), 0 );
199 break;
200 }
201 }
202 if ( aInternalFilterName.Len() )
203 {
204 GraphicFilter aGraphicFilter( sal_True );
205
206 sal_uInt16 nFormat, nFilterCount = aGraphicFilter.pConfig->GetExportFormatCount();
207 for ( nFormat = 0; nFormat < nFilterCount; nFormat++ )
208 {
209 if ( aGraphicFilter.pConfig->GetExportInternalFilterName( nFormat ) == aInternalFilterName )
210 break;
211 }
212 if ( nFormat < nFilterCount )
213 {
214 FltCallDialogParameter aFltCallDlgPara( Application::GetDefDialogParent(), NULL, meFieldUnit );
215 aFltCallDlgPara.aFilterData = maFilterDataSequence;
216
217 ByteString aResMgrName( "svt", 3 );
218 ResMgr* pResMgr;
219
220 pResMgr = ResMgr::CreateResMgr( aResMgrName.GetBuffer(), Application::GetSettings().GetUILocale() );
221 aFltCallDlgPara.pResMgr = pResMgr;
222
223 aFltCallDlgPara.aFilterExt = aGraphicFilter.pConfig->GetExportFormatShortName( nFormat );
224 sal_Bool bIsPixelFormat( aGraphicFilter.pConfig->IsExportPixelFormat( nFormat ) );
225 if ( ExportDialog( aFltCallDlgPara, mxMgr, mxSourceDocument, mbExportSelection, bIsPixelFormat ).Execute() == RET_OK )
226 nRet = ui::dialogs::ExecutableDialogResults::OK;
227
228 delete pResMgr;
229
230 // taking the out parameter from the dialog
231 maFilterDataSequence = aFltCallDlgPara.aFilterData;
232 }
233 }
234 return nRet;
235 }
236
237 // XEmporter
setSourceDocument(const uno::Reference<lang::XComponent> & xDoc)238 void SvFilterOptionsDialog::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
239 throw ( lang::IllegalArgumentException, uno::RuntimeException )
240 {
241 mxSourceDocument = xDoc;
242
243 // try to set the corresponding metric unit
244 String aConfigPath;
245 uno::Reference< lang::XServiceInfo > xServiceInfo
246 ( xDoc, uno::UNO_QUERY );
247 if ( xServiceInfo.is() )
248 {
249 if ( xServiceInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ) )
250 aConfigPath = String( RTL_CONSTASCII_USTRINGPARAM( "Office.Impress/Layout/Other/MeasureUnit" ) );
251 else if ( xServiceInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ) )
252 aConfigPath = String( RTL_CONSTASCII_USTRINGPARAM( "Office.Draw/Layout/Other/MeasureUnit" ) );
253 if ( aConfigPath.Len() )
254 {
255 FilterConfigItem aConfigItem( aConfigPath );
256 String aPropertyName;
257 SvtSysLocale aSysLocale;
258 if ( aSysLocale.GetLocaleDataPtr()->getMeasurementSystemEnum() == MEASURE_METRIC )
259 aPropertyName = String( RTL_CONSTASCII_USTRINGPARAM( "Metric" ) );
260 else
261 aPropertyName = String( RTL_CONSTASCII_USTRINGPARAM( "NonMetric" ) );
262 meFieldUnit = (FieldUnit)aConfigItem.ReadInt32( aPropertyName, FUNIT_CM );
263 }
264 }
265 }
266
267