Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "SvFilterOptionsDialog.hxx"
31 : : #include <svtools/FilterConfigItem.hxx>
32 : : #include <svtools/filter.hxx>
33 : : #include "FilterConfigCache.hxx"
34 : : #include <osl/file.hxx>
35 : : #include <osl/module.hxx>
36 : : #include <svl/solar.hrc>
37 : : #include <svtools/fltcall.hxx>
38 : : #include "exportdialog.hxx"
39 : : #include <uno/mapping.hxx>
40 : : #include <com/sun/star/frame/XModel.hpp>
41 : : #include <com/sun/star/document/XViewDataSupplier.hpp>
42 : : #include <com/sun/star/container/XIndexAccess.hpp>
43 : : #include <com/sun/star/lang/XServiceInfo.hpp>
44 : : #include <com/sun/star/uno/Sequence.h>
45 : : #include <com/sun/star/uno/Any.h>
46 : : #include <unotools/syslocale.hxx>
47 : : #include "vcl/svapp.hxx"
48 : :
49 : : using namespace ::rtl;
50 : : using namespace ::com::sun::star;
51 : :
52 : : // -------------------------
53 : : // - SvFilterOptionsDialog -
54 : : // -------------------------
55 : :
56 : : uno::Reference< uno::XInterface >
57 : 0 : SAL_CALL SvFilterOptionsDialog_CreateInstance(
58 : : const uno::Reference< lang::XMultiServiceFactory > & _rxFactory )
59 : : {
60 [ # # ][ # # ]: 0 : return static_cast< ::cppu::OWeakObject* > ( new SvFilterOptionsDialog( _rxFactory ) );
61 : : }
62 : :
63 : 0 : OUString SvFilterOptionsDialog_getImplementationName()
64 : : throw( uno::RuntimeException )
65 : : {
66 : 0 : return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.SvFilterOptionsDialog" ) );
67 : : }
68 : : #define SERVICE_NAME "com.sun.star.ui.dialog.FilterOptionsDialog"
69 : 0 : sal_Bool SAL_CALL SvFilterOptionsDialog_supportsService( const OUString& ServiceName )
70 : : throw( uno::RuntimeException )
71 : : {
72 : 0 : return ServiceName == SERVICE_NAME;
73 : : }
74 : :
75 : 0 : uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog_getSupportedServiceNames()
76 : : throw( uno::RuntimeException )
77 : : {
78 : 0 : uno::Sequence< OUString > aRet(1);
79 [ # # ]: 0 : OUString* pArray = aRet.getArray();
80 [ # # ]: 0 : pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
81 : 0 : return aRet;
82 : : }
83 : : #undef SERVICE_NAME
84 : :
85 : : // -----------------------------------------------------------------------------
86 : :
87 : 0 : SvFilterOptionsDialog::SvFilterOptionsDialog( const uno::Reference< lang::XMultiServiceFactory > xMgr ) :
88 : : mxMgr ( xMgr ),
89 : : meFieldUnit ( FUNIT_CM ),
90 [ # # ][ # # ]: 0 : mbExportSelection ( sal_False )
91 : : {
92 : 0 : }
93 : :
94 : : // -----------------------------------------------------------------------------
95 : :
96 [ # # ][ # # ]: 0 : SvFilterOptionsDialog::~SvFilterOptionsDialog()
97 : : {
98 [ # # ]: 0 : }
99 : :
100 : : // -----------------------------------------------------------------------------
101 : :
102 : 0 : void SAL_CALL SvFilterOptionsDialog::acquire() throw()
103 : : {
104 : 0 : OWeakObject::acquire();
105 : 0 : }
106 : :
107 : : // -----------------------------------------------------------------------------
108 : :
109 : 0 : void SAL_CALL SvFilterOptionsDialog::release() throw()
110 : : {
111 : 0 : OWeakObject::release();
112 : 0 : }
113 : :
114 : : // XInitialization
115 : 0 : void SAL_CALL SvFilterOptionsDialog::initialize( const uno::Sequence< uno::Any > & )
116 : : throw ( uno::Exception, uno::RuntimeException )
117 : : {
118 : 0 : }
119 : :
120 : : // XServiceInfo
121 : 0 : OUString SAL_CALL SvFilterOptionsDialog::getImplementationName()
122 : : throw( uno::RuntimeException )
123 : : {
124 : 0 : return SvFilterOptionsDialog_getImplementationName();
125 : : }
126 : 0 : sal_Bool SAL_CALL SvFilterOptionsDialog::supportsService( const OUString& rServiceName )
127 : : throw( uno::RuntimeException )
128 : : {
129 : 0 : return SvFilterOptionsDialog_supportsService( rServiceName );
130 : : }
131 : 0 : uno::Sequence< OUString > SAL_CALL SvFilterOptionsDialog::getSupportedServiceNames()
132 : : throw ( uno::RuntimeException )
133 : : {
134 : 0 : return SvFilterOptionsDialog_getSupportedServiceNames();
135 : : }
136 : :
137 : :
138 : : // XPropertyAccess
139 : 0 : uno::Sequence< beans::PropertyValue > SvFilterOptionsDialog::getPropertyValues()
140 : : throw ( uno::RuntimeException )
141 : : {
142 : : sal_Int32 i, nCount;
143 [ # # ]: 0 : for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
144 : : {
145 [ # # ]: 0 : if ( maMediaDescriptor[ i ].Name == "FilterData" )
146 : 0 : break;
147 : : }
148 [ # # ]: 0 : if ( i == nCount )
149 : 0 : maMediaDescriptor.realloc( ++nCount );
150 : :
151 : : // the "FilterData" Property is an Any that will contain our PropertySequence of Values
152 [ # # ][ # # ]: 0 : maMediaDescriptor[ i ].Name = String( RTL_CONSTASCII_USTRINGPARAM( "FilterData" ) );
153 : 0 : maMediaDescriptor[ i ].Value <<= maFilterDataSequence;
154 : 0 : return maMediaDescriptor;
155 : : }
156 : :
157 : 0 : void SvFilterOptionsDialog::setPropertyValues( const uno::Sequence< beans::PropertyValue > & aProps )
158 : : throw ( beans::UnknownPropertyException, beans::PropertyVetoException,
159 : : lang::IllegalArgumentException, lang::WrappedTargetException,
160 : : uno::RuntimeException )
161 : : {
162 : 0 : maMediaDescriptor = aProps;
163 : :
164 : : sal_Int32 i, nCount;
165 [ # # ]: 0 : for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
166 : : {
167 [ # # ]: 0 : if ( maMediaDescriptor[ i ].Name == "FilterData" )
168 : : {
169 : 0 : maMediaDescriptor[ i ].Value >>= maFilterDataSequence;
170 : : }
171 [ # # ]: 0 : else if ( maMediaDescriptor[ i ].Name == "SelectionOnly" )
172 : : {
173 : 0 : maMediaDescriptor[ i ].Value >>= mbExportSelection;
174 : : }
175 : : }
176 : 0 : }
177 : :
178 : : // XExecutableDialog
179 : 0 : void SvFilterOptionsDialog::setTitle( const OUString& aTitle )
180 : : throw ( uno::RuntimeException )
181 : : {
182 : 0 : maDialogTitle = aTitle;
183 : 0 : }
184 : :
185 : 0 : sal_Int16 SvFilterOptionsDialog::execute()
186 : : throw ( uno::RuntimeException )
187 : : {
188 : 0 : sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL;
189 : :
190 [ # # ]: 0 : String aFilterNameStr( RTL_CONSTASCII_USTRINGPARAM( "FilterName" ) );
191 [ # # ]: 0 : String aInternalFilterName;
192 : 0 : sal_Int32 j, nCount = maMediaDescriptor.getLength();
193 [ # # ]: 0 : for ( j = 0; j < nCount; j++ )
194 : : {
195 [ # # ][ # # ]: 0 : if ( maMediaDescriptor[ j ].Name.equals( aFilterNameStr ) )
[ # # ]
196 : : {
197 : 0 : OUString aStr;
198 [ # # ]: 0 : maMediaDescriptor[ j ].Value >>= aStr;
199 [ # # ]: 0 : aInternalFilterName = aStr;
200 [ # # ][ # # ]: 0 : aInternalFilterName.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "draw_" ) ), String(), 0 );
[ # # ][ # # ]
[ # # ]
201 [ # # ][ # # ]: 0 : aInternalFilterName.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "impress_" ) ), String(), 0 );
[ # # ][ # # ]
[ # # ]
202 : 0 : break;
203 : : }
204 : : }
205 [ # # ]: 0 : if ( aInternalFilterName.Len() )
206 : : {
207 [ # # ]: 0 : GraphicFilter aGraphicFilter( sal_True );
208 : :
209 [ # # ]: 0 : sal_uInt16 nFormat, nFilterCount = aGraphicFilter.pConfig->GetExportFormatCount();
210 [ # # ]: 0 : for ( nFormat = 0; nFormat < nFilterCount; nFormat++ )
211 : : {
212 [ # # ][ # # ]: 0 : if ( aGraphicFilter.pConfig->GetExportInternalFilterName( nFormat ) == aInternalFilterName )
[ # # ][ # # ]
213 : 0 : break;
214 : : }
215 [ # # ]: 0 : if ( nFormat < nFilterCount )
216 : : {
217 [ # # ][ # # ]: 0 : FltCallDialogParameter aFltCallDlgPara( Application::GetDefDialogParent(), NULL, meFieldUnit );
218 [ # # ]: 0 : aFltCallDlgPara.aFilterData = maFilterDataSequence;
219 : :
220 : : ResMgr* pResMgr;
221 : :
222 [ # # ][ # # ]: 0 : pResMgr = ResMgr::CreateResMgr( "svt", Application::GetSettings().GetUILocale() );
[ # # ]
223 : 0 : aFltCallDlgPara.pResMgr = pResMgr;
224 : :
225 [ # # ][ # # ]: 0 : aFltCallDlgPara.aFilterExt = aGraphicFilter.pConfig->GetExportFormatShortName( nFormat );
[ # # ]
226 [ # # ]: 0 : sal_Bool bIsPixelFormat( aGraphicFilter.pConfig->IsExportPixelFormat( nFormat ) );
227 [ # # ][ # # ]: 0 : if ( ExportDialog( aFltCallDlgPara, mxMgr, mxSourceDocument, mbExportSelection, bIsPixelFormat ).Execute() == RET_OK )
[ # # ][ # # ]
228 : 0 : nRet = ui::dialogs::ExecutableDialogResults::OK;
229 : :
230 [ # # ][ # # ]: 0 : delete pResMgr;
231 : :
232 : : // taking the out parameter from the dialog
233 [ # # ][ # # ]: 0 : maFilterDataSequence = aFltCallDlgPara.aFilterData;
234 [ # # ]: 0 : }
235 : : }
236 [ # # ][ # # ]: 0 : return nRet;
237 : : }
238 : :
239 : : // XEmporter
240 : 0 : void SvFilterOptionsDialog::setSourceDocument( const uno::Reference< lang::XComponent >& xDoc )
241 : : throw ( lang::IllegalArgumentException, uno::RuntimeException )
242 : : {
243 [ # # ]: 0 : mxSourceDocument = xDoc;
244 : :
245 : : // try to set the corresponding metric unit
246 [ # # ]: 0 : String aConfigPath;
247 : : uno::Reference< lang::XServiceInfo > xServiceInfo
248 [ # # ]: 0 : ( xDoc, uno::UNO_QUERY );
249 [ # # ]: 0 : if ( xServiceInfo.is() )
250 : : {
251 [ # # ][ # # ]: 0 : if ( xServiceInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ) )
[ # # ][ # # ]
252 [ # # ][ # # ]: 0 : aConfigPath = String( RTL_CONSTASCII_USTRINGPARAM( "Office.Impress/Layout/Other/MeasureUnit" ) );
[ # # ]
253 [ # # ][ # # ]: 0 : else if ( xServiceInfo->supportsService( OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ) )
[ # # ][ # # ]
254 [ # # ][ # # ]: 0 : aConfigPath = String( RTL_CONSTASCII_USTRINGPARAM( "Office.Draw/Layout/Other/MeasureUnit" ) );
[ # # ]
255 [ # # ]: 0 : if ( aConfigPath.Len() )
256 : : {
257 [ # # ][ # # ]: 0 : FilterConfigItem aConfigItem( aConfigPath );
258 [ # # ]: 0 : String aPropertyName;
259 [ # # ]: 0 : SvtSysLocale aSysLocale;
260 [ # # ][ # # ]: 0 : if ( aSysLocale.GetLocaleDataPtr()->getMeasurementSystemEnum() == MEASURE_METRIC )
[ # # ]
261 [ # # ][ # # ]: 0 : aPropertyName = String( RTL_CONSTASCII_USTRINGPARAM( "Metric" ) );
[ # # ]
262 : : else
263 [ # # ][ # # ]: 0 : aPropertyName = String( RTL_CONSTASCII_USTRINGPARAM( "NonMetric" ) );
[ # # ]
264 [ # # ][ # # ]: 0 : meFieldUnit = (FieldUnit)aConfigItem.ReadInt32( aPropertyName, FUNIT_CM );
[ # # ][ # # ]
[ # # ]
265 : : }
266 [ # # ]: 0 : }
267 : 0 : }
268 : :
269 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|