Debian Codegraph @

chart2/source/controller/dialogs/dlg_CreationWizard_UNO.cxx

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