xref: /trunk/main/sd/source/filter/html/HtmlOptionsDialog.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 );
81 
82     // XServiceInfo
83     virtual ::rtl::OUString SAL_CALL getImplementationName();
84     virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName );
85     virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
86 
87     // XPropertyAccess
88     virtual Sequence< PropertyValue > SAL_CALL getPropertyValues();
89     virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > & aProps );
90 
91     // XExecuteDialog
92     virtual sal_Int16 SAL_CALL execute();
93     virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle );
94 
95     // XExporter
96     virtual void SAL_CALL setSourceDocument( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& xDoc );
97 
98 };
99 
100 // -------------------------
101 // - SdHtmlOptionsDialog -
102 // -------------------------
103 
104 Reference< XInterface >
SdHtmlOptionsDialog_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)105     SAL_CALL SdHtmlOptionsDialog_CreateInstance(
106         const Reference< XMultiServiceFactory > & _rxFactory )
107 {
108     return static_cast< ::cppu::OWeakObject* > ( new SdHtmlOptionsDialog( _rxFactory ) );
109 }
110 
SdHtmlOptionsDialog_getImplementationName()111 ::rtl::OUString SdHtmlOptionsDialog_getImplementationName()
112 {
113     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.draw.SdHtmlOptionsDialog" ) );
114 }
115 #define SERVICE_NAME "com.sun.star.ui.dialog.FilterOptionsDialog"
SdHtmlOptionsDialog_supportsService(const::rtl::OUString & ServiceName)116 sal_Bool SAL_CALL SdHtmlOptionsDialog_supportsService( const ::rtl::OUString& ServiceName )
117 {
118     return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SERVICE_NAME ) );
119 }
120 
SdHtmlOptionsDialog_getSupportedServiceNames()121 Sequence< ::rtl::OUString > SAL_CALL SdHtmlOptionsDialog_getSupportedServiceNames()
122 {
123     Sequence< ::rtl::OUString > aRet(1);
124     ::rtl::OUString* pArray = aRet.getArray();
125     pArray[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICE_NAME ) );
126     return aRet;
127 }
128 #undef SERVICE_NAME
129 
130 // -----------------------------------------------------------------------------
131 
SdHtmlOptionsDialog(const Reference<XMultiServiceFactory> & xMgr)132 SdHtmlOptionsDialog::SdHtmlOptionsDialog( const Reference< XMultiServiceFactory > & xMgr ) :
133     mrxMgr      ( xMgr ),
134     meDocType   ( DOCUMENT_TYPE_DRAW )
135 {
136 }
137 
138 // -----------------------------------------------------------------------------
139 
~SdHtmlOptionsDialog()140 SdHtmlOptionsDialog::~SdHtmlOptionsDialog()
141 {
142 }
143 
144 // -----------------------------------------------------------------------------
145 
acquire()146 void SAL_CALL SdHtmlOptionsDialog::acquire() throw()
147 {
148     OWeakObject::acquire();
149 }
150 
151 // -----------------------------------------------------------------------------
152 
release()153 void SAL_CALL SdHtmlOptionsDialog::release() throw()
154 {
155     OWeakObject::release();
156 }
157 
158 // XInitialization
initialize(const Sequence<Any> &)159 void SAL_CALL SdHtmlOptionsDialog::initialize( const Sequence< Any > & )
160 {
161 }
162 
163 // XServiceInfo
getImplementationName()164 ::rtl::OUString SAL_CALL SdHtmlOptionsDialog::getImplementationName()
165 {
166     return SdHtmlOptionsDialog_getImplementationName();
167 }
supportsService(const::rtl::OUString & rServiceName)168 sal_Bool SAL_CALL SdHtmlOptionsDialog::supportsService( const ::rtl::OUString& rServiceName )
169 {
170     return SdHtmlOptionsDialog_supportsService( rServiceName );
171 }
getSupportedServiceNames()172 Sequence< ::rtl::OUString > SAL_CALL SdHtmlOptionsDialog::getSupportedServiceNames()
173 {
174     return SdHtmlOptionsDialog_getSupportedServiceNames();
175 }
176 
177 
178 // XPropertyAccess
getPropertyValues()179 Sequence< PropertyValue > SdHtmlOptionsDialog::getPropertyValues()
180 {
181     sal_Int32 i, nCount;
182     for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
183     {
184         if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) )
185             break;
186     }
187     if ( i == nCount )
188         maMediaDescriptor.realloc( ++nCount );
189 
190     // the "FilterData" Property is an Any that will contain our PropertySequence of Values
191     maMediaDescriptor[ i ].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FilterData" ) );
192     maMediaDescriptor[ i ].Value <<= maFilterDataSequence;
193     return maMediaDescriptor;
194 }
195 
setPropertyValues(const Sequence<PropertyValue> & aProps)196 void SdHtmlOptionsDialog::setPropertyValues( const Sequence< PropertyValue > & aProps )
197 {
198     maMediaDescriptor = aProps;
199 
200     sal_Int32 i, nCount;
201     for ( i = 0, nCount = maMediaDescriptor.getLength(); i < nCount; i++ )
202     {
203         if ( maMediaDescriptor[ i ].Name.equalsAscii( "FilterData" ) )
204         {
205             maMediaDescriptor[ i ].Value >>= maFilterDataSequence;
206             break;
207         }
208     }
209 }
210 
211 // XExecutableDialog
setTitle(const::rtl::OUString & aTitle)212 void SdHtmlOptionsDialog::setTitle( const ::rtl::OUString& aTitle )
213 {
214     aDialogTitle = aTitle;
215 }
216 
execute()217 sal_Int16 SdHtmlOptionsDialog::execute()
218 {
219     sal_Int16 nRet = ExecutableDialogResults::CANCEL;
220 
221     SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
222     if( pFact )
223     {
224         AbstractSdPublishingDlg* pDlg = pFact->CreateSdPublishingDlg( Application::GetDefDialogParent(), meDocType );
225         if( pDlg )
226         {
227             if( pDlg->Execute() )
228             {
229                 pDlg->GetParameterSequence( maFilterDataSequence );
230                 nRet = ExecutableDialogResults::OK;
231             }
232             else
233             {
234                 nRet = ExecutableDialogResults::CANCEL;
235             }
236             delete pDlg;
237         }
238     }
239     return nRet;
240 }
241 
242 // XEmporter
setSourceDocument(const Reference<XComponent> & xDoc)243 void SdHtmlOptionsDialog::setSourceDocument( const Reference< XComponent >& xDoc )
244 {
245     // try to set the corresponding metric unit
246     String aConfigPath;
247     Reference< XServiceInfo > xServiceInfo
248             ( xDoc, UNO_QUERY );
249     if ( xServiceInfo.is() )
250     {
251         if ( xServiceInfo->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ) )
252         {
253             meDocType = DOCUMENT_TYPE_IMPRESS;
254             return;
255         }
256         else if ( xServiceInfo->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ) )
257         {
258             meDocType = DOCUMENT_TYPE_DRAW;
259             return;
260         }
261     }
262     throw IllegalArgumentException();
263 }
264