1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <com/sun/star/lang/XServiceInfo.hpp>
21 #include <com/sun/star/uno/Sequence.h>
22 #include <com/sun/star/uno/Any.h>
23 #include <com/sun/star/lang/XInitialization.hpp>
24 #include <com/sun/star/beans/XPropertyAccess.hpp>
25 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
26 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
27 #include <com/sun/star/document/XExporter.hpp>
28 #include <cppuhelper/implbase.hxx>
29 #include <cppuhelper/supportsservice.hxx>
30 #include <vcl/svapp.hxx>
31 
32 using namespace com::sun::star::uno;
33 using namespace com::sun::star::lang;
34 using namespace com::sun::star::document;
35 using namespace com::sun::star::beans;
36 using namespace com::sun::star::ui::dialogs;
37 
38 #include <pres.hxx>
39 #include <sdabstdlg.hxx>
40 
41 namespace {
42 
43 class SdHtmlOptionsDialog : public cppu::WeakImplHelper
44 <
45     XExporter,
46     XExecutableDialog,
47     XPropertyAccess,
48     XInitialization,
49     XServiceInfo
50 >
51 {
52     Sequence< PropertyValue > maMediaDescriptor;
53     Sequence< PropertyValue > maFilterDataSequence;
54     DocumentType meDocType;
55 
56 public:
57 
58     SdHtmlOptionsDialog();
59 
60     // XInterface
61     virtual void SAL_CALL acquire() noexcept override;
62     virtual void SAL_CALL release() noexcept override;
63 
64     // XInitialization
65     virtual void SAL_CALL initialize( const Sequence< Any > & aArguments ) override;
66 
67     // XServiceInfo
68     virtual OUString SAL_CALL getImplementationName() override;
69     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
70     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
71 
72     // XPropertyAccess
73     virtual Sequence< PropertyValue > SAL_CALL getPropertyValues() override;
74     virtual void SAL_CALL setPropertyValues( const css::uno::Sequence< css::beans::PropertyValue > & aProps ) override;
75 
76     // XExecuteDialog
77     virtual sal_Int16 SAL_CALL execute() override;
78     virtual void SAL_CALL setTitle( const OUString& aTitle ) override;
79 
80     // XExporter
81     virtual void SAL_CALL setSourceDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) override;
82 
83 };
84 
85 }
86 
SdHtmlOptionsDialog()87 SdHtmlOptionsDialog::SdHtmlOptionsDialog() :
88     meDocType   ( DocumentType::Draw )
89 {
90 }
91 
acquire()92 void SAL_CALL SdHtmlOptionsDialog::acquire() noexcept
93 {
94     OWeakObject::acquire();
95 }
96 
release()97 void SAL_CALL SdHtmlOptionsDialog::release() noexcept
98 {
99     OWeakObject::release();
100 }
101 
102 // XInitialization
initialize(const Sequence<Any> &)103 void SAL_CALL SdHtmlOptionsDialog::initialize( const Sequence< Any > & )
104 {
105 }
106 
107 // XServiceInfo
getImplementationName()108 OUString SAL_CALL SdHtmlOptionsDialog::getImplementationName()
109 {
110     return "com.sun.star.comp.draw.SdHtmlOptionsDialog";
111 }
112 
supportsService(const OUString & rServiceName)113 sal_Bool SAL_CALL SdHtmlOptionsDialog::supportsService( const OUString& rServiceName )
114 {
115     return cppu::supportsService(this, rServiceName);
116 }
117 
getSupportedServiceNames()118 Sequence< OUString > SAL_CALL SdHtmlOptionsDialog::getSupportedServiceNames()
119 {
120   return { "com.sun.star.ui.dialog.FilterOptionsDialog" };
121 }
122 
123 // XPropertyAccess
getPropertyValues()124 Sequence< PropertyValue > SdHtmlOptionsDialog::getPropertyValues()
125 {
126     auto pProp = std::find_if(maMediaDescriptor.begin(), maMediaDescriptor.end(),
127         [](const PropertyValue& rProp) { return rProp.Name == "FilterData"; });
128     auto i = static_cast<sal_Int32>(std::distance(maMediaDescriptor.begin(), pProp));
129     sal_Int32 nCount = maMediaDescriptor.getLength();
130     if ( i == nCount )
131         maMediaDescriptor.realloc( ++nCount );
132 
133     // the "FilterData" Property is an Any that will contain our PropertySequence of Values
134     maMediaDescriptor[ i ].Name = "FilterData";
135     maMediaDescriptor[ i ].Value <<= maFilterDataSequence;
136     return maMediaDescriptor;
137 }
138 
setPropertyValues(const Sequence<PropertyValue> & aProps)139 void SdHtmlOptionsDialog::setPropertyValues( const Sequence< PropertyValue > & aProps )
140 {
141     maMediaDescriptor = aProps;
142 
143     auto pProp = std::find_if(maMediaDescriptor.begin(), maMediaDescriptor.end(),
144         [](const PropertyValue& rProp) { return rProp.Name == "FilterData"; });
145     if (pProp != maMediaDescriptor.end())
146         pProp->Value >>= maFilterDataSequence;
147 }
148 
149 // XExecutableDialog
setTitle(const OUString &)150 void SdHtmlOptionsDialog::setTitle( const OUString& )
151 {
152 }
153 
execute()154 sal_Int16 SdHtmlOptionsDialog::execute()
155 {
156     sal_Int16 nRet = ExecutableDialogResults::CANCEL;
157 
158     SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
159     ScopedVclPtr<AbstractSdPublishingDlg> pDlg(pFact->CreateSdPublishingDlg(nullptr /*TODO*/, meDocType));
160     if( pDlg->Execute() )
161     {
162         pDlg->GetParameterSequence( maFilterDataSequence );
163         nRet = ExecutableDialogResults::OK;
164     }
165     else
166     {
167         nRet = ExecutableDialogResults::CANCEL;
168     }
169     return nRet;
170 }
171 
172 // XEmporter
setSourceDocument(const Reference<XComponent> & xDoc)173 void SdHtmlOptionsDialog::setSourceDocument( const Reference< XComponent >& xDoc )
174 {
175     // try to set the corresponding metric unit
176     Reference< XServiceInfo > xServiceInfo(xDoc, UNO_QUERY);
177     if ( xServiceInfo.is() )
178     {
179         if ( xServiceInfo->supportsService( "com.sun.star.presentation.PresentationDocument" ) )
180         {
181             meDocType = DocumentType::Impress;
182             return;
183         }
184         else if ( xServiceInfo->supportsService( "com.sun.star.drawing.DrawingDocument" ) )
185         {
186             meDocType = DocumentType::Draw;
187             return;
188         }
189     }
190     throw IllegalArgumentException();
191 }
192 
193 
194 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
com_sun_star_comp_draw_SdHtmlOptionsDialog_get_implementation(css::uno::XComponentContext *,css::uno::Sequence<css::uno::Any> const &)195 com_sun_star_comp_draw_SdHtmlOptionsDialog_get_implementation(css::uno::XComponentContext*,
196                                                               css::uno::Sequence<css::uno::Any> const &)
197 {
198     return cppu::acquire(new SdHtmlOptionsDialog());
199 }
200 
201 
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
203