1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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
;
39 #include <sdabstdlg.hxx>
43 class SdHtmlOptionsDialog
: public cppu::WeakImplHelper
52 Sequence
< PropertyValue
> maMediaDescriptor
;
53 Sequence
< PropertyValue
> maFilterDataSequence
;
54 DocumentType meDocType
;
58 SdHtmlOptionsDialog();
61 virtual void SAL_CALL
acquire() noexcept override
;
62 virtual void SAL_CALL
release() noexcept override
;
65 virtual void SAL_CALL
initialize( const Sequence
< Any
> & aArguments
) override
;
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
;
73 virtual Sequence
< PropertyValue
> SAL_CALL
getPropertyValues() override
;
74 virtual void SAL_CALL
setPropertyValues( const css::uno::Sequence
< css::beans::PropertyValue
> & aProps
) override
;
77 virtual sal_Int16 SAL_CALL
execute() override
;
78 virtual void SAL_CALL
setTitle( const OUString
& aTitle
) override
;
81 virtual void SAL_CALL
setSourceDocument( const css::uno::Reference
< css::lang::XComponent
>& xDoc
) override
;
87 SdHtmlOptionsDialog::SdHtmlOptionsDialog() :
88 meDocType ( DocumentType::Draw
)
92 void SAL_CALL
SdHtmlOptionsDialog::acquire() noexcept
94 OWeakObject::acquire();
97 void SAL_CALL
SdHtmlOptionsDialog::release() noexcept
99 OWeakObject::release();
103 void SAL_CALL
SdHtmlOptionsDialog::initialize( const Sequence
< Any
> & )
108 OUString SAL_CALL
SdHtmlOptionsDialog::getImplementationName()
110 return "com.sun.star.comp.draw.SdHtmlOptionsDialog";
113 sal_Bool SAL_CALL
SdHtmlOptionsDialog::supportsService( const OUString
& rServiceName
)
115 return cppu::supportsService(this, rServiceName
);
118 Sequence
< OUString
> SAL_CALL
SdHtmlOptionsDialog::getSupportedServiceNames()
120 return { "com.sun.star.ui.dialog.FilterOptionsDialog" };
124 Sequence
< PropertyValue
> SdHtmlOptionsDialog::getPropertyValues()
126 auto pProp
= std::find_if(std::cbegin(maMediaDescriptor
), std::cend(maMediaDescriptor
),
127 [](const PropertyValue
& rProp
) { return rProp
.Name
== "FilterData"; });
128 auto i
= static_cast<sal_Int32
>(std::distance(std::cbegin(maMediaDescriptor
), pProp
));
129 sal_Int32 nCount
= maMediaDescriptor
.getLength();
131 maMediaDescriptor
.realloc( ++nCount
);
133 // the "FilterData" Property is an Any that will contain our PropertySequence of Values
134 auto& el
= maMediaDescriptor
.getArray()[ i
];
135 el
.Name
= "FilterData";
136 el
.Value
<<= maFilterDataSequence
;
137 return maMediaDescriptor
;
140 void SdHtmlOptionsDialog::setPropertyValues( const Sequence
< PropertyValue
> & aProps
)
142 maMediaDescriptor
= aProps
;
144 auto pProp
= std::find_if(std::cbegin(maMediaDescriptor
), std::cend(maMediaDescriptor
),
145 [](const PropertyValue
& rProp
) { return rProp
.Name
== "FilterData"; });
146 if (pProp
!= std::cend(maMediaDescriptor
))
147 pProp
->Value
>>= maFilterDataSequence
;
151 void SdHtmlOptionsDialog::setTitle( const OUString
& )
155 sal_Int16
SdHtmlOptionsDialog::execute()
157 sal_Int16 nRet
= ExecutableDialogResults::CANCEL
;
159 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
160 ScopedVclPtr
<AbstractSdPublishingDlg
> pDlg(pFact
->CreateSdPublishingDlg(nullptr /*TODO*/, meDocType
));
161 if( pDlg
->Execute() )
163 pDlg
->GetParameterSequence( maFilterDataSequence
);
164 nRet
= ExecutableDialogResults::OK
;
168 nRet
= ExecutableDialogResults::CANCEL
;
174 void SdHtmlOptionsDialog::setSourceDocument( const Reference
< XComponent
>& xDoc
)
176 // try to set the corresponding metric unit
177 Reference
< XServiceInfo
> xServiceInfo(xDoc
, UNO_QUERY
);
178 if ( xServiceInfo
.is() )
180 if ( xServiceInfo
->supportsService( "com.sun.star.presentation.PresentationDocument" ) )
182 meDocType
= DocumentType::Impress
;
185 else if ( xServiceInfo
->supportsService( "com.sun.star.drawing.DrawingDocument" ) )
187 meDocType
= DocumentType::Draw
;
191 throw IllegalArgumentException();
195 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
196 com_sun_star_comp_draw_SdHtmlOptionsDialog_get_implementation(css::uno::XComponentContext
*,
197 css::uno::Sequence
<css::uno::Any
> const &)
199 return cppu::acquire(new SdHtmlOptionsDialog());
203 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */