merge the formfield patch from ooo-build
[ooovba.git] / sd / source / filter / html / HtmlOptionsDialog.cxx
blob980c44b28658f81c3a30b7e9f4c48eb3fd7244ab
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: HtmlOptionsDialog.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sd.hxx"
34 #include <osl/file.hxx>
35 #include <vos/module.hxx>
36 #include <com/sun/star/frame/XModel.hpp>
37 #include <com/sun/star/document/XViewDataSupplier.hpp>
38 #include <com/sun/star/container/XIndexAccess.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/uno/Sequence.h>
41 #include <com/sun/star/uno/Any.h>
42 #include <com/sun/star/lang/XInitialization.hpp>
43 #include <com/sun/star/lang/XServiceInfo.hpp>
44 #include <com/sun/star/beans/XPropertyAccess.hpp>
45 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
46 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
47 #include <com/sun/star/document/XExporter.hpp>
48 #include <cppuhelper/implbase5.hxx>
49 #include <vcl/svapp.hxx>
51 using namespace com::sun::star::uno;
52 using namespace com::sun::star::lang;
53 using namespace com::sun::star::document;
54 using namespace com::sun::star::beans;
55 using namespace com::sun::star::container;
56 using namespace com::sun::star::frame;
57 using namespace com::sun::star::ui::dialogs;
59 #include "pres.hxx"
60 #include "sdabstdlg.hxx"
61 #include "tools/debug.hxx"
62 class SdHtmlOptionsDialog : public cppu::WeakImplHelper5
64 XExporter,
65 XExecutableDialog,
66 XPropertyAccess,
67 XInitialization,
68 XServiceInfo
71 const Reference< XMultiServiceFactory > &mrxMgr;
72 Sequence< PropertyValue > maMediaDescriptor;
73 Sequence< PropertyValue > maFilterDataSequence;
74 ::rtl::OUString aDialogTitle;
75 DocumentType meDocType;
77 public:
79 SdHtmlOptionsDialog( const Reference< XMultiServiceFactory >& _rxORB );
80 ~SdHtmlOptionsDialog();
82 // XInterface
83 virtual void SAL_CALL acquire() throw();
84 virtual void SAL_CALL release() throw();
86 // XInitialization
87 virtual void SAL_CALL initialize( const Sequence< Any > & aArguments ) throw ( Exception, RuntimeException );
89 // XServiceInfo
90 virtual ::rtl::OUString SAL_CALL getImplementationName() throw ( RuntimeException );
91 virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw ( RuntimeException );
92 virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw ( RuntimeException );
94 // XPropertyAccess
95 virtual Sequence< PropertyValue > SAL_CALL getPropertyValues() throw ( RuntimeException );
96 virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > & aProps )
97 throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException,
98 ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException,
99 ::com::sun::star::uno::RuntimeException );
101 // XExecuteDialog
102 virtual sal_Int16 SAL_CALL execute()
103 throw ( com::sun::star::uno::RuntimeException );
104 virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle )
105 throw ( ::com::sun::star::uno::RuntimeException );
107 // XExporter
108 virtual void SAL_CALL setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
109 throw ( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
113 // -------------------------
114 // - SdHtmlOptionsDialog -
115 // -------------------------
117 Reference< XInterface >
118 SAL_CALL SdHtmlOptionsDialog_CreateInstance(
119 const Reference< XMultiServiceFactory > & _rxFactory )
121 return static_cast< ::cppu::OWeakObject* > ( new SdHtmlOptionsDialog( _rxFactory ) );
124 ::rtl::OUString SdHtmlOptionsDialog_getImplementationName()
125 throw( RuntimeException )
127 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.draw.SdHtmlOptionsDialog" ) );
129 #define SERVICE_NAME "com.sun.star.ui.dialog.FilterOptionsDialog"
130 sal_Bool SAL_CALL SdHtmlOptionsDialog_supportsService( const ::rtl::OUString& ServiceName )
131 throw( RuntimeException )
133 return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
136 Sequence< ::rtl::OUString > SAL_CALL SdHtmlOptionsDialog_getSupportedServiceNames()
137 throw( RuntimeException )
139 Sequence< ::rtl::OUString > aRet(1);
140 ::rtl::OUString* pArray = aRet.getArray();
141 pArray[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
142 return aRet;
144 #undef SERVICE_NAME
146 // -----------------------------------------------------------------------------
148 SdHtmlOptionsDialog::SdHtmlOptionsDialog( const Reference< XMultiServiceFactory > & xMgr ) :
149 mrxMgr ( xMgr ),
150 meDocType ( DOCUMENT_TYPE_DRAW )
154 // -----------------------------------------------------------------------------
156 SdHtmlOptionsDialog::~SdHtmlOptionsDialog()
160 // -----------------------------------------------------------------------------
162 void SAL_CALL SdHtmlOptionsDialog::acquire() throw()
164 OWeakObject::acquire();
167 // -----------------------------------------------------------------------------
169 void SAL_CALL SdHtmlOptionsDialog::release() throw()
171 OWeakObject::release();
174 // XInitialization
175 void SAL_CALL SdHtmlOptionsDialog::initialize( const Sequence< Any > & )
176 throw ( Exception, RuntimeException )
180 // XServiceInfo
181 ::rtl::OUString SAL_CALL SdHtmlOptionsDialog::getImplementationName()
182 throw( RuntimeException )
184 return SdHtmlOptionsDialog_getImplementationName();
186 sal_Bool SAL_CALL SdHtmlOptionsDialog::supportsService( const ::rtl::OUString& rServiceName )
187 throw( RuntimeException )
189 return SdHtmlOptionsDialog_supportsService( rServiceName );
191 Sequence< ::rtl::OUString > SAL_CALL SdHtmlOptionsDialog::getSupportedServiceNames()
192 throw ( RuntimeException )
194 return SdHtmlOptionsDialog_getSupportedServiceNames();
198 // XPropertyAccess
199 Sequence< PropertyValue > SdHtmlOptionsDialog::getPropertyValues()
200 throw ( RuntimeException )
202 sal_Int32 i, nCount;
203 for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
205 if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) )
206 break;
208 if ( i == nCount )
209 maMediaDescriptor.realloc( ++nCount );
211 // the "FilterData" Property is an Any that will contain our PropertySequence of Values
212 maMediaDescriptor[ i ].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterData" ) );
213 maMediaDescriptor[ i ].Value <<= maFilterDataSequence;
214 return maMediaDescriptor;
217 void SdHtmlOptionsDialog::setPropertyValues( const Sequence< PropertyValue > & aProps )
218 throw ( UnknownPropertyException, PropertyVetoException,
219 IllegalArgumentException, WrappedTargetException,
220 RuntimeException )
222 maMediaDescriptor = aProps;
224 sal_Int32 i, nCount;
225 for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
227 if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) )
229 maMediaDescriptor[ i ].Value >>= maFilterDataSequence;
230 break;
235 // XExecutableDialog
236 void SdHtmlOptionsDialog::setTitle( const ::rtl::OUString& aTitle )
237 throw ( RuntimeException )
239 aDialogTitle = aTitle;
242 sal_Int16 SdHtmlOptionsDialog::execute()
243 throw ( RuntimeException )
245 sal_Int16 nRet = ExecutableDialogResults::CANCEL;
247 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
248 if( pFact )
250 AbstractSdPublishingDlg* pDlg = pFact->CreateSdPublishingDlg( Application::GetDefDialogParent(), meDocType );
251 if( pDlg )
253 if( pDlg->Execute() )
255 pDlg->GetParameterSequence( maFilterDataSequence );
256 nRet = ExecutableDialogResults::OK;
258 else
260 nRet = ExecutableDialogResults::CANCEL;
262 delete pDlg;
265 return nRet;
268 // XEmporter
269 void SdHtmlOptionsDialog::setSourceDocument( const Reference< XComponent >& xDoc )
270 throw ( IllegalArgumentException, RuntimeException )
272 // try to set the corresponding metric unit
273 String aConfigPath;
274 Reference< XServiceInfo > xServiceInfo
275 ( xDoc, UNO_QUERY );
276 if ( xServiceInfo.is() )
278 if ( xServiceInfo->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ) )
280 meDocType = DOCUMENT_TYPE_IMPRESS;
281 return;
283 else if ( xServiceInfo->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ) )
285 meDocType = DOCUMENT_TYPE_DRAW;
286 return;
289 throw IllegalArgumentException();