LibreOffice Module chart2 (master) 1
dlg_CreationWizard_UNO.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
22#include <ChartModel.hxx>
23#include <servicenames.hxx>
25#include <utility>
26#include <vcl/svapp.hxx>
27#include <vcl/weldutils.hxx>
29#include <com/sun/star/awt/Point.hpp>
30#include <com/sun/star/awt/Size.hpp>
31#include <com/sun/star/beans/PropertyValue.hpp>
32#include <com/sun/star/frame/Desktop.hpp>
34#include <sfx2/viewsh.hxx>
35
36
37namespace chart
38{
39using namespace ::com::sun::star;
40
41CreationWizardUnoDlg::CreationWizardUnoDlg(uno::Reference<uno::XComponentContext> xContext)
42 : OComponentHelper(m_aMutex)
43 , m_xCC(std::move(xContext))
44 , m_bUnlockControllersOnExecute(false)
45{
46 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(m_xCC);
47 uno::Reference< frame::XTerminateListener > xListener( this );
48 xDesktop->addTerminateListener( xListener );
49}
50
51CreationWizardUnoDlg::~CreationWizardUnoDlg()
52{
53 SolarMutexGuard aSolarGuard;
54 m_xDialog.reset();
55}
56
57// lang::XServiceInfo
58OUString SAL_CALL CreationWizardUnoDlg::getImplementationName()
59{
61}
62
63sal_Bool SAL_CALL CreationWizardUnoDlg::supportsService( const OUString& rServiceName )
64{
65 return cppu::supportsService(this, rServiceName);
66}
67
68css::uno::Sequence< OUString > SAL_CALL CreationWizardUnoDlg::getSupportedServiceNames()
69{
71}
72
73// XInterface
74uno::Any SAL_CALL CreationWizardUnoDlg::queryInterface( const uno::Type& aType )
75{
76 return OComponentHelper::queryInterface( aType );
77}
78void SAL_CALL CreationWizardUnoDlg::acquire() noexcept
79{
80 OComponentHelper::acquire();
81}
82void SAL_CALL CreationWizardUnoDlg::release() noexcept
83{
84 OComponentHelper::release();
85}
86uno::Any SAL_CALL CreationWizardUnoDlg::queryAggregation( uno::Type const & rType )
87{
89 {
90 void * p = static_cast< ui::dialogs::XAsynchronousExecutableDialog * >( this );
91 return uno::Any( &p, rType );
92 }
94 {
95 void * p = static_cast< lang::XServiceInfo * >( this );
96 return uno::Any( &p, rType );
97 }
99 {
100 void * p = static_cast< lang::XInitialization * >( this );
101 return uno::Any( &p, rType );
102 }
104 {
105 void * p = static_cast< frame::XTerminateListener * >( this );
106 return uno::Any( &p, rType );
107 }
108 else if (rType == cppu::UnoType<beans::XPropertySet>::get())
109 {
110 void * p = static_cast< beans::XPropertySet * >( this );
111 return uno::Any( &p, rType );
112 }
113 return OComponentHelper::queryAggregation( rType );
114}
115
116uno::Sequence< uno::Type > CreationWizardUnoDlg::getTypes()
117{
127 return aTypeList;
128}
129
130uno::Sequence< sal_Int8 > SAL_CALL CreationWizardUnoDlg::getImplementationId()
131{
132 return css::uno::Sequence<sal_Int8>();
133}
134
135// XTerminateListener
136void SAL_CALL CreationWizardUnoDlg::queryTermination( const lang::EventObject& /*Event*/ )
137{
138}
139
140void SAL_CALL CreationWizardUnoDlg::notifyTermination( const lang::EventObject& /*Event*/ )
141{
142 // we are going down, so dispose us!
143 dispose();
144}
145
146void SAL_CALL CreationWizardUnoDlg::disposing( const lang::EventObject& /*Source*/ )
147{
148 //Listener should deregister himself and release all references to the closing object.
149}
150
151void SAL_CALL CreationWizardUnoDlg::setDialogTitle( const OUString& /*rTitle*/ )
152{
153}
154void CreationWizardUnoDlg::createDialogOnDemand()
155{
156 SolarMutexGuard aSolarGuard;
157 if (m_xDialog)
158 return;
159
160 if( !m_xParentWindow.is() && m_xChartModel.is() )
161 {
163 m_xChartModel->getCurrentController() );
164 if( xController.is() )
165 {
167 xController->getFrame() );
168 if(xFrame.is())
169 m_xParentWindow = xFrame->getContainerWindow();
170 }
171 }
172
173 weld::Window* pParent(Application::GetFrameWeld(m_xParentWindow));
174 if (!pParent)
175 {
176 if (weld::TransportAsXWindow* pTunnel = dynamic_cast<weld::TransportAsXWindow*>(m_xParentWindow.get()))
177 pParent = dynamic_cast<weld::Window*>(pTunnel->getWidget());
178 }
179
180 uno::Reference< XComponent > xKeepAlive( this );
181 if( m_xChartModel.is() )
182 {
183 m_xDialog = std::make_shared<CreationWizard>(pParent, m_xChartModel, m_xCC);
184 }
185}
186
188{
189 return SfxViewShell::Current();
190}
191
192void SAL_CALL CreationWizardUnoDlg::startExecuteModal( const css::uno::Reference<css::ui::dialogs::XDialogClosedListener>& xListener )
193{
194 SolarMutexGuard aSolarGuard;
195 createDialogOnDemand();
196
197 if( !m_xDialog )
198 return;
199
200 m_xDialog->getDialog()->SetInstallLOKNotifierHdl(
201 LINK(this, CreationWizardUnoDlg, InstallLOKNotifierHdl));
202
203 TimerTriggeredControllerLock aTimerTriggeredControllerLock( m_xChartModel );
204 if( m_bUnlockControllersOnExecute && m_xChartModel.is() )
205 m_xChartModel->unlockControllers();
206
207 CreationWizardUnoDlg* xThat = this;
208 weld::DialogController::runAsync(m_xDialog, [xListener, xThat](sal_Int32 nResult){
209 if( xListener.is() )
210 {
211 ::css::uno::Reference< ::css::uno::XInterface > xSource;
212 // Notify UNO listener to perform correct action depending on the result
213 css::ui::dialogs::DialogClosedEvent aEvent( xSource, nResult );
214 xListener->dialogClosed( aEvent );
215 }
216 xThat->m_xDialog.reset();
217 });
218}
219
220void SAL_CALL CreationWizardUnoDlg::initialize( const uno::Sequence< uno::Any >& aArguments )
221{
222 for(const uno::Any& rArgument : aArguments)
223 {
224 beans::PropertyValue aProperty;
225 if(rArgument >>= aProperty)
226 {
227 if( aProperty.Name == "ParentWindow" )
228 {
229 aProperty.Value >>= m_xParentWindow;
230 }
231 else if( aProperty.Name == "ChartModel" )
232 {
234 aProperty.Value >>= xInt;
235 m_xChartModel = dynamic_cast<::chart::ChartModel*>(xInt.get());
236 assert(m_xChartModel);
237 }
238 }
239 }
240}
241
242// ____ OComponentHelper ____
244void SAL_CALL CreationWizardUnoDlg::disposing()
245{
246 m_xChartModel.clear();
247 m_xParentWindow.clear();
248
249 SolarMutexGuard aSolarGuard;
250 m_xDialog.reset();
251
252 try
253 {
254 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(m_xCC);
256 xDesktop->removeTerminateListener( xListener );
257 }
258 catch( const uno::Exception & )
259 {
260 DBG_UNHANDLED_EXCEPTION("chart2");
261 }
262}
263
264//XPropertySet
265uno::Reference< beans::XPropertySetInfo > SAL_CALL CreationWizardUnoDlg::getPropertySetInfo()
266{
267 OSL_FAIL("not implemented");
268 return nullptr;
269}
270
271void SAL_CALL CreationWizardUnoDlg::setPropertyValue(const OUString& rPropertyName,
272 const uno::Any& rValue)
273{
274 if( rPropertyName == "Position" )
275 {
276 SolarMutexGuard aSolarGuard;
277 createDialogOnDemand();
278
279 //read only property, do nothing else
280 }
281 else if( rPropertyName == "Size")
282 {
283 //read only property, do nothing
284 }
285 else if( rPropertyName == "UnlockControllersOnExecute" )
286 {
287 if( ! (rValue >>= m_bUnlockControllersOnExecute) )
288 throw lang::IllegalArgumentException( "Property 'UnlockControllers' requires value of type boolean" , nullptr, 0 );
289 }
290 else
291 throw beans::UnknownPropertyException( "unknown property was tried to set to chart wizard" , nullptr );
292}
293
294uno::Any SAL_CALL CreationWizardUnoDlg::getPropertyValue( const OUString& rPropertyName )
295{
296 uno::Any aRet;
297 if( rPropertyName == "Position" )
298 {
299 //get left upper outer corner relative to screen
300 //pixels, screen position
301 SolarMutexGuard aSolarGuard;
302 createDialogOnDemand();
303 if (m_xDialog)
304 {
305 Point aPos(m_xDialog->getDialog()->get_position());
306 awt::Point aPoint(aPos.X(), aPos.Y());
307 aRet <<= aPoint;
308 }
309 }
310 else if( rPropertyName == "Size" )
311 {
312 //get outer size inclusive decoration
313 //pixels, screen position
314 SolarMutexGuard aSolarGuard;
315 createDialogOnDemand();
316 if (m_xDialog)
317 {
318 Size aRect(m_xDialog->getDialog()->get_size());
319 awt::Size aSize(aRect.Width(), aRect.Height());
320 aRet <<= aSize;
321 }
322 }
323 else if( rPropertyName == "UnlockControllersOnExecute" )
324 {
325 aRet <<= m_bUnlockControllersOnExecute;
326 }
327 else
328 throw beans::UnknownPropertyException( "unknown property was tried to get from chart wizard" , nullptr );
329 return aRet;
330}
331
332void SAL_CALL CreationWizardUnoDlg::addPropertyChangeListener(
333 const OUString& /* aPropertyName */, const uno::Reference< beans::XPropertyChangeListener >& /* xListener */ )
334{
335 OSL_FAIL("not implemented");
336}
337void SAL_CALL CreationWizardUnoDlg::removePropertyChangeListener(
338 const OUString& /* aPropertyName */, const uno::Reference< beans::XPropertyChangeListener >& /* aListener */ )
339{
340 OSL_FAIL("not implemented");
341}
342
343void SAL_CALL CreationWizardUnoDlg::addVetoableChangeListener( const OUString& /* PropertyName */, const uno::Reference< beans::XVetoableChangeListener >& /* aListener */ )
344{
345 OSL_FAIL("not implemented");
346}
347
348void SAL_CALL CreationWizardUnoDlg::removeVetoableChangeListener( const OUString& /* PropertyName */, const uno::Reference< beans::XVetoableChangeListener >& /* aListener */ )
349{
350 OSL_FAIL("not implemented");
351}
352
353} //namespace chart
354
355extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
357 css::uno::Sequence<css::uno::Any> const &)
358{
359 return cppu::acquire(new chart::CreationWizardUnoDlg(context));
360}
361
362/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
constexpr tools::Long Y() const
constexpr tools::Long X() const
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
constexpr tools::Long Height() const
constexpr tools::Long Width() const
std::shared_ptr< CreationWizard > m_xDialog
css::uno::Type const & get()
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
#define DBG_UNHANDLED_EXCEPTION(...)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_WizardDialog_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
std::mutex m_aMutex
Sequence< PropertyValue > aArguments
void * p
void setPropertyValue(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Set a property to a certain value in the given map.
IMPL_STATIC_LINK_NOARG(CreationWizardUnoDlg, InstallLOKNotifierHdl, void *, vcl::ILibreOfficeKitNotifier *)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
void dispose()
constexpr OUStringLiteral CHART_WIZARD_DIALOG_SERVICE_NAME
constexpr OUStringLiteral CHART_WIZARD_DIALOG_SERVICE_IMPLEMENTATION_NAME
Reference< XController > xController
Reference< XFrame > xFrame
unsigned char sal_Bool