LibreOffice Module filter (master) 1
xmlfilterdialogcomponent.cxx
Go to the documentation of this file.
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
23#include <com/sun/star/frame/Desktop.hpp>
24#include <com/sun/star/frame/XTerminateListener.hpp>
26#include <com/sun/star/lang/XServiceInfo.hpp>
27#include <com/sun/star/lang/XInitialization.hpp>
28#include <com/sun/star/awt/XWindow.hpp>
29#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
30#include <com/sun/star/beans/PropertyValue.hpp>
31#include <vcl/svapp.hxx>
32
34
35using namespace ::cppu;
36using namespace ::osl;
37using namespace ::com::sun::star::uno;
38using namespace ::com::sun::star::lang;
39using namespace ::com::sun::star::beans;
40using namespace ::com::sun::star::registry;
41using namespace ::com::sun::star::frame;
42
43namespace {
44
45
46class XMLFilterDialogComponent : public comphelper::WeakComponentImplHelper<
47 css::ui::dialogs::XExecutableDialog,
48 XServiceInfo,
49 XInitialization,
50 XTerminateListener>
51{
52public:
53 explicit XMLFilterDialogComponent( const Reference< XComponentContext >& rxContext );
54
55protected:
56 // XTypeProvider
57 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
58
59 // XServiceInfo
60 virtual OUString SAL_CALL getImplementationName() override;
61 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
62 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
63
64 // XExecutableDialog
65 virtual void SAL_CALL setTitle( const OUString& aTitle ) override;
66 virtual sal_Int16 SAL_CALL execute( ) override;
67
68 // XInitialization
69 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
70
71 // XTerminateListener
72 virtual void SAL_CALL queryTermination( const EventObject& Event ) override;
73 virtual void SAL_CALL notifyTermination( const EventObject& Event ) override;
74 virtual void SAL_CALL disposing( const EventObject& Source ) override;
75
78 virtual void disposing(std::unique_lock<std::mutex>& rGuard) override;
79
80private:
81 css::uno::Reference<css::awt::XWindow> mxParent;
82 css::uno::Reference< XComponentContext > mxContext;
83
84 std::shared_ptr<XMLFilterSettingsDialog> mxDialog;
85};
86
87}
88
89XMLFilterDialogComponent::XMLFilterDialogComponent(const css::uno::Reference< XComponentContext >& rxContext)
90 : mxContext(rxContext)
91{
92 Reference< XDesktop2 > xDesktop = Desktop::create( rxContext );
93 Reference< XTerminateListener > xListener( this );
94 xDesktop->addTerminateListener( xListener );
95}
96
97OUString SAL_CALL XMLFilterDialogComponent::getImplementationName()
98{
99 return "com.sun.star.comp.ui.XSLTFilterDialog";
100}
101
102Sequence< sal_Int8 > SAL_CALL XMLFilterDialogComponent::getImplementationId()
103{
104 static const comphelper::UnoIdInit implId;
105 return implId.getSeq();
106}
107
108
109Sequence< OUString > SAL_CALL XMLFilterDialogComponent::getSupportedServiceNames()
110{
111 return { "com.sun.star.ui.dialogs.XSLTFilterDialog" };
112}
113
114sal_Bool SAL_CALL XMLFilterDialogComponent::supportsService(const OUString& ServiceName)
115{
116 return cppu::supportsService( this, ServiceName );
117}
118
121void XMLFilterDialogComponent::disposing(std::unique_lock<std::mutex>& rGuard)
122{
123 rGuard.unlock();
124 {
125 ::SolarMutexGuard aGuard;
126
127 if (mxDialog)
128 mxDialog->response(RET_CLOSE);
129 }
130 rGuard.lock();
131}
132
133
134// XTerminateListener
135void SAL_CALL XMLFilterDialogComponent::queryTermination( const EventObject& /* Event */ )
136{
137 ::SolarMutexGuard aGuard;
138 if (!mxDialog)
139 return;
140 mxDialog->present();
141}
142
143void SAL_CALL XMLFilterDialogComponent::notifyTermination( const EventObject& /* Event */ )
144{
145 {
146 ::SolarMutexGuard aGuard;
147 if (mxDialog)
148 mxDialog->response(RET_CLOSE);
149 }
150
151 // we are going down, so dispose us!
152 dispose();
153}
154
155void SAL_CALL XMLFilterDialogComponent::disposing( const EventObject& /* Source */ )
156{
157}
158
159void SAL_CALL XMLFilterDialogComponent::setTitle( const OUString& /* _rTitle */ )
160{
161}
162
163sal_Int16 SAL_CALL XMLFilterDialogComponent::execute()
164{
165 ::SolarMutexGuard aGuard;
166
167 bool bLaunch = false;
168 if (!mxDialog)
169 {
170 Reference< XComponent > xKeepAlive( this );
171 mxDialog = std::make_shared<XMLFilterSettingsDialog>(Application::GetFrameWeld(mxParent), mxContext);
172 bLaunch = true;
173 }
174
175 mxDialog->UpdateWindow();
176
177 if (!bLaunch)
178 {
179 mxDialog->present();
180 return 0;
181 }
182
183 weld::DialogController::runAsync(mxDialog, [this](sal_Int32)
184 {
185 mxDialog.reset();
186 });
187
188 return 0;
189}
190
191void SAL_CALL XMLFilterDialogComponent::initialize( const Sequence< Any >& aArguments )
192{
193 for(const Any& rArgument : aArguments)
194 {
195 PropertyValue aProperty;
196 if(rArgument >>= aProperty)
197 {
198 if( aProperty.Name == "ParentWindow" )
199 {
200 aProperty.Value >>= mxParent;
201 }
202 }
203 }
204}
205
206
207extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
209 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
210{
211 return cppu::acquire(new XMLFilterDialogComponent(context));
212}
213
214
215/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
unotools::WeakReference< AnimationNode > mxParent
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
const css::uno::Sequence< sal_Int8 > & getSeq() const
virtual void disposing(std::unique_lock< std::mutex > &)
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
uno::Reference< uno::XComponentContext > mxContext
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void dispose()
unsigned char sal_Bool
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * filter_XSLTFilterDialog_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)