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 
25 // MARKER(update_precomp.py): autogen include statement, do not remove
26 #include "precompiled_sd.hxx"
27 #include <osl/file.hxx>
28 #include <vos/module.hxx>
29 #include <com/sun/star/frame/XModel.hpp>
30 #include <com/sun/star/document/XViewDataSupplier.hpp>
31 #include <com/sun/star/container/XIndexAccess.hpp>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/uno/Sequence.h>
34 #include <com/sun/star/uno/Any.h>
35 #include <com/sun/star/lang/XInitialization.hpp>
36 #include <com/sun/star/lang/XServiceInfo.hpp>
37 #include <com/sun/star/beans/XPropertyAccess.hpp>
38 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
39 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
40 #include <com/sun/star/document/XExporter.hpp>
41 #include <cppuhelper/implbase5.hxx>
42 #include <vcl/svapp.hxx>
43 
44 using namespace com::sun::star::uno;
45 using namespace com::sun::star::lang;
46 using namespace com::sun::star::document;
47 using namespace com::sun::star::beans;
48 using namespace com::sun::star::container;
49 using namespace com::sun::star::frame;
50 using namespace com::sun::star::ui::dialogs;
51 
52 #include "pres.hxx"
53 #include "sdabstdlg.hxx"
54 #include "tools/debug.hxx"
55 class SdHtmlOptionsDialog : public cppu::WeakImplHelper5
56 <
57 	XExporter,
58 	XExecutableDialog,
59     XPropertyAccess,
60 	XInitialization,
61 	XServiceInfo
62 >
63 {
64     const Reference< XMultiServiceFactory > &mrxMgr;
65     Sequence< PropertyValue > maMediaDescriptor;
66     Sequence< PropertyValue > maFilterDataSequence;
67     ::rtl::OUString aDialogTitle;
68 	DocumentType meDocType;
69 
70 public:
71 
72 	SdHtmlOptionsDialog( const Reference< XMultiServiceFactory >& _rxORB );
73 	~SdHtmlOptionsDialog();
74 
75 	// XInterface
76     virtual void SAL_CALL acquire() throw();
77     virtual void SAL_CALL release() throw();
78 
79 	// XInitialization
80     virtual void SAL_CALL initialize( const Sequence< Any > & aArguments ) throw ( Exception, RuntimeException );
81 
82 	// XServiceInfo
83     virtual ::rtl::OUString SAL_CALL getImplementationName() throw ( RuntimeException );
84     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw ( RuntimeException );
85     virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw ( RuntimeException );
86 
87 	// XPropertyAccess
88     virtual Sequence< PropertyValue > SAL_CALL getPropertyValues() throw ( RuntimeException );
89     virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > & aProps )
90         throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException,
91                 ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException,
92                 ::com::sun::star::uno::RuntimeException );
93 
94 	// XExecuteDialog
95     virtual sal_Int16 SAL_CALL execute()
96         throw ( com::sun::star::uno::RuntimeException );
97     virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle )
98         throw ( ::com::sun::star::uno::RuntimeException );
99 
100 	// XExporter
101     virtual void SAL_CALL setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc )
102 		throw ( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException );
103 
104 };
105 
106 // -------------------------
107 // - SdHtmlOptionsDialog -
108 // -------------------------
109 
110 Reference< XInterface >
SdHtmlOptionsDialog_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)111     SAL_CALL SdHtmlOptionsDialog_CreateInstance(
112         const Reference< XMultiServiceFactory > & _rxFactory )
113 {
114 	return static_cast< ::cppu::OWeakObject* > ( new SdHtmlOptionsDialog( _rxFactory ) );
115 }
116 
SdHtmlOptionsDialog_getImplementationName()117 ::rtl::OUString SdHtmlOptionsDialog_getImplementationName()
118 	throw( RuntimeException )
119 {
120     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.draw.SdHtmlOptionsDialog" ) );
121 }
122 #define SERVICE_NAME "com.sun.star.ui.dialog.FilterOptionsDialog"
SdHtmlOptionsDialog_supportsService(const::rtl::OUString & ServiceName)123 sal_Bool SAL_CALL SdHtmlOptionsDialog_supportsService( const ::rtl::OUString& ServiceName )
124 	throw( RuntimeException )
125 {
126     return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
127 }
128 
SdHtmlOptionsDialog_getSupportedServiceNames()129 Sequence< ::rtl::OUString > SAL_CALL SdHtmlOptionsDialog_getSupportedServiceNames()
130 	throw( RuntimeException )
131 {
132     Sequence< ::rtl::OUString > aRet(1);
133     ::rtl::OUString* pArray = aRet.getArray();
134     pArray[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
135     return aRet;
136 }
137 #undef SERVICE_NAME
138 
139 // -----------------------------------------------------------------------------
140 
SdHtmlOptionsDialog(const Reference<XMultiServiceFactory> & xMgr)141 SdHtmlOptionsDialog::SdHtmlOptionsDialog( const Reference< XMultiServiceFactory > & xMgr ) :
142     mrxMgr		( xMgr ),
143 	meDocType	( DOCUMENT_TYPE_DRAW )
144 {
145 }
146 
147 // -----------------------------------------------------------------------------
148 
~SdHtmlOptionsDialog()149 SdHtmlOptionsDialog::~SdHtmlOptionsDialog()
150 {
151 }
152 
153 // -----------------------------------------------------------------------------
154 
acquire()155 void SAL_CALL SdHtmlOptionsDialog::acquire() throw()
156 {
157 	OWeakObject::acquire();
158 }
159 
160 // -----------------------------------------------------------------------------
161 
release()162 void SAL_CALL SdHtmlOptionsDialog::release() throw()
163 {
164 	OWeakObject::release();
165 }
166 
167 // XInitialization
initialize(const Sequence<Any> &)168 void SAL_CALL SdHtmlOptionsDialog::initialize( const Sequence< Any > & )
169 	throw ( Exception, RuntimeException )
170 {
171 }
172 
173 // XServiceInfo
getImplementationName()174 ::rtl::OUString SAL_CALL SdHtmlOptionsDialog::getImplementationName()
175 	throw( RuntimeException )
176 {
177 	return SdHtmlOptionsDialog_getImplementationName();
178 }
supportsService(const::rtl::OUString & rServiceName)179 sal_Bool SAL_CALL SdHtmlOptionsDialog::supportsService( const ::rtl::OUString& rServiceName )
180 	throw( RuntimeException )
181 {
182     return SdHtmlOptionsDialog_supportsService( rServiceName );
183 }
getSupportedServiceNames()184 Sequence< ::rtl::OUString > SAL_CALL SdHtmlOptionsDialog::getSupportedServiceNames()
185 	throw ( RuntimeException )
186 {
187     return SdHtmlOptionsDialog_getSupportedServiceNames();
188 }
189 
190 
191 // XPropertyAccess
getPropertyValues()192 Sequence< PropertyValue > SdHtmlOptionsDialog::getPropertyValues()
193         throw ( RuntimeException )
194 {
195 	sal_Int32 i, nCount;
196 	for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
197 	{
198 		if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) )
199 			break;
200 	}
201 	if ( i == nCount )
202 		maMediaDescriptor.realloc( ++nCount );
203 
204 	// the "FilterData" Property is an Any that will contain our PropertySequence of Values
205     maMediaDescriptor[ i ].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterData" ) );
206 	maMediaDescriptor[ i ].Value <<= maFilterDataSequence;
207     return maMediaDescriptor;
208 }
209 
setPropertyValues(const Sequence<PropertyValue> & aProps)210 void SdHtmlOptionsDialog::setPropertyValues( const Sequence< PropertyValue > & aProps )
211         throw ( UnknownPropertyException, PropertyVetoException,
212                 IllegalArgumentException, WrappedTargetException,
213                 RuntimeException )
214 {
215     maMediaDescriptor = aProps;
216 
217 	sal_Int32 i, nCount;
218 	for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
219 	{
220 		if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) )
221 		{
222 			maMediaDescriptor[ i ].Value >>= maFilterDataSequence;
223 			break;
224 		}
225 	}
226 }
227 
228 // XExecutableDialog
setTitle(const::rtl::OUString & aTitle)229 void SdHtmlOptionsDialog::setTitle( const ::rtl::OUString& aTitle )
230     throw ( RuntimeException )
231 {
232     aDialogTitle = aTitle;
233 }
234 
execute()235 sal_Int16 SdHtmlOptionsDialog::execute()
236 	throw ( RuntimeException )
237 {
238 	sal_Int16 nRet = ExecutableDialogResults::CANCEL;
239 
240 	SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
241 	if( pFact )
242 	{
243 		AbstractSdPublishingDlg* pDlg = pFact->CreateSdPublishingDlg( Application::GetDefDialogParent(), meDocType );
244 		if( pDlg )
245 		{
246 			if( pDlg->Execute() )
247 			{
248 				pDlg->GetParameterSequence( maFilterDataSequence );
249 				nRet = ExecutableDialogResults::OK;
250 			}
251 			else
252 			{
253 				nRet = ExecutableDialogResults::CANCEL;
254 			}
255 			delete pDlg;
256 		}
257 	}
258 	return nRet;
259 }
260 
261 // XEmporter
setSourceDocument(const Reference<XComponent> & xDoc)262 void SdHtmlOptionsDialog::setSourceDocument( const Reference< XComponent >& xDoc )
263 		throw ( IllegalArgumentException, RuntimeException )
264 {
265 	// try to set the corresponding metric unit
266 	String aConfigPath;
267     Reference< XServiceInfo > xServiceInfo
268             ( xDoc, UNO_QUERY );
269 	if ( xServiceInfo.is() )
270 	{
271         if ( xServiceInfo->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ) )
272 		{
273 			meDocType = DOCUMENT_TYPE_IMPRESS;
274 			return;
275 		}
276         else if ( xServiceInfo->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ) )
277 		{
278 			meDocType = DOCUMENT_TYPE_DRAW;
279 			return;
280 		}
281 	}
282 	throw IllegalArgumentException();
283 }
284