Line data Source code
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 "macros.hxx"
23 : #include "servicenames.hxx"
24 : #include "ContainerHelper.hxx"
25 : #include "TimerTriggeredControllerLock.hxx"
26 : #include <osl/mutex.hxx>
27 : #include <vcl/svapp.hxx>
28 : #include <toolkit/awt/vclxwindow.hxx>
29 : #include <vcl/msgbox.hxx>
30 : #include <cppuhelper/typeprovider.hxx>
31 : #include <cppuhelper/supportsservice.hxx>
32 : #include <comphelper/servicehelper.hxx>
33 : #include <com/sun/star/awt/Point.hpp>
34 : #include <com/sun/star/awt/Size.hpp>
35 : #include <com/sun/star/beans/PropertyValue.hpp>
36 : #include <com/sun/star/frame/Desktop.hpp>
37 :
38 : namespace chart
39 : {
40 : using namespace ::com::sun::star;
41 :
42 0 : CreationWizardUnoDlg::CreationWizardUnoDlg( const uno::Reference< uno::XComponentContext >& xContext )
43 : : OComponentHelper( m_aMutex )
44 : , m_xChartModel( 0 )
45 : , m_xCC( xContext )
46 : , m_xParentWindow( 0 )
47 : , m_pDialog( 0 )
48 0 : , m_bUnlockControllersOnExecute(false)
49 : {
50 0 : uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(m_xCC);
51 0 : uno::Reference< frame::XTerminateListener > xListener( this );
52 0 : xDesktop->addTerminateListener( xListener );
53 0 : }
54 0 : CreationWizardUnoDlg::~CreationWizardUnoDlg()
55 : {
56 0 : SolarMutexGuard aSolarGuard;
57 0 : m_pDialog.disposeAndClear();
58 0 : }
59 : // lang::XServiceInfo
60 0 : OUString SAL_CALL CreationWizardUnoDlg::getImplementationName()
61 : throw( css::uno::RuntimeException, std::exception )
62 : {
63 0 : return getImplementationName_Static();
64 : }
65 :
66 0 : OUString CreationWizardUnoDlg::getImplementationName_Static()
67 : {
68 0 : return OUString(CHART_WIZARD_DIALOG_SERVICE_IMPLEMENTATION_NAME);
69 : }
70 :
71 0 : sal_Bool SAL_CALL CreationWizardUnoDlg::supportsService( const OUString& rServiceName )
72 : throw( css::uno::RuntimeException, std::exception )
73 : {
74 0 : return cppu::supportsService(this, rServiceName);
75 : }
76 :
77 0 : css::uno::Sequence< OUString > SAL_CALL CreationWizardUnoDlg::getSupportedServiceNames()
78 : throw( css::uno::RuntimeException, std::exception )
79 : {
80 0 : return getSupportedServiceNames_Static();
81 : }
82 :
83 0 : uno::Sequence< OUString > CreationWizardUnoDlg::getSupportedServiceNames_Static()
84 : {
85 0 : uno::Sequence< OUString > aSNS( 1 );
86 0 : aSNS.getArray()[ 0 ] = CHART_WIZARD_DIALOG_SERVICE_NAME;
87 0 : return aSNS;
88 : }
89 :
90 : // XInterface
91 0 : uno::Any SAL_CALL CreationWizardUnoDlg::queryInterface( const uno::Type& aType ) throw (uno::RuntimeException, std::exception)
92 : {
93 0 : return OComponentHelper::queryInterface( aType );
94 : }
95 0 : void SAL_CALL CreationWizardUnoDlg::acquire() throw ()
96 : {
97 0 : OComponentHelper::acquire();
98 0 : }
99 0 : void SAL_CALL CreationWizardUnoDlg::release() throw ()
100 : {
101 0 : OComponentHelper::release();
102 0 : }
103 0 : uno::Any SAL_CALL CreationWizardUnoDlg::queryAggregation( uno::Type const & rType ) throw (uno::RuntimeException, std::exception)
104 : {
105 0 : if (rType == cppu::UnoType<ui::dialogs::XExecutableDialog>::get())
106 : {
107 0 : void * p = static_cast< ui::dialogs::XExecutableDialog * >( this );
108 0 : return uno::Any( &p, rType );
109 : }
110 0 : else if (rType == cppu::UnoType<lang::XServiceInfo>::get())
111 : {
112 0 : void * p = static_cast< lang::XTypeProvider * >( this );
113 0 : return uno::Any( &p, rType );
114 : }
115 0 : else if (rType == cppu::UnoType<lang::XInitialization>::get())
116 : {
117 0 : void * p = static_cast< lang::XInitialization * >( this );
118 0 : return uno::Any( &p, rType );
119 : }
120 0 : else if (rType == cppu::UnoType<frame::XTerminateListener>::get())
121 : {
122 0 : void * p = static_cast< frame::XTerminateListener * >( this );
123 0 : return uno::Any( &p, rType );
124 : }
125 0 : else if (rType == cppu::UnoType<beans::XPropertySet>::get())
126 : {
127 0 : void * p = static_cast< beans::XPropertySet * >( this );
128 0 : return uno::Any( &p, rType );
129 : }
130 0 : return OComponentHelper::queryAggregation( rType );
131 : }
132 :
133 0 : uno::Sequence< uno::Type > CreationWizardUnoDlg::getTypes() throw(uno::RuntimeException, std::exception)
134 : {
135 0 : static uno::Sequence< uno::Type > aTypeList;
136 :
137 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
138 0 : if( !aTypeList.getLength() )
139 : {
140 0 : ::std::vector< uno::Type > aTypes;
141 0 : aTypes.push_back( cppu::UnoType<lang::XComponent>::get() );
142 0 : aTypes.push_back( cppu::UnoType<lang::XTypeProvider>::get() );
143 0 : aTypes.push_back( cppu::UnoType<uno::XAggregation>::get() );
144 0 : aTypes.push_back( cppu::UnoType<uno::XWeak>::get() );
145 0 : aTypes.push_back( cppu::UnoType<lang::XServiceInfo>::get() );
146 0 : aTypes.push_back( cppu::UnoType<lang::XInitialization>::get() );
147 0 : aTypes.push_back( cppu::UnoType<frame::XTerminateListener>::get() );
148 0 : aTypes.push_back( cppu::UnoType<ui::dialogs::XExecutableDialog>::get() );
149 0 : aTypes.push_back( cppu::UnoType<beans::XPropertySet>::get() );
150 0 : aTypeList = ::chart::ContainerHelper::ContainerToSequence( aTypes );
151 : }
152 :
153 0 : return aTypeList;
154 : }
155 :
156 0 : uno::Sequence< sal_Int8 > SAL_CALL CreationWizardUnoDlg::getImplementationId() throw( uno::RuntimeException, std::exception )
157 : {
158 0 : return css::uno::Sequence<sal_Int8>();
159 : }
160 :
161 : // XTerminateListener
162 0 : void SAL_CALL CreationWizardUnoDlg::queryTermination( const lang::EventObject& /*Event*/ ) throw( frame::TerminationVetoException, uno::RuntimeException, std::exception)
163 : {
164 0 : SolarMutexGuard aSolarGuard;
165 :
166 : // we will never give a veto here
167 0 : if( m_pDialog && !m_pDialog->isClosable() )
168 : {
169 0 : m_pDialog->ToTop();
170 0 : throw frame::TerminationVetoException();
171 0 : }
172 0 : }
173 :
174 0 : void SAL_CALL CreationWizardUnoDlg::notifyTermination( const lang::EventObject& /*Event*/ ) throw (uno::RuntimeException, std::exception)
175 : {
176 : // we are going down, so dispose us!
177 0 : dispose();
178 0 : }
179 :
180 0 : void SAL_CALL CreationWizardUnoDlg::disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException, std::exception)
181 : {
182 : //Listener should deregister himself and release all references to the closing object.
183 0 : }
184 :
185 0 : void SAL_CALL CreationWizardUnoDlg::setTitle( const OUString& /*rTitle*/ ) throw(uno::RuntimeException, std::exception)
186 : {
187 0 : }
188 0 : void CreationWizardUnoDlg::createDialogOnDemand()
189 : {
190 0 : SolarMutexGuard aSolarGuard;
191 0 : if( !m_pDialog )
192 : {
193 0 : vcl::Window* pParent = NULL;
194 0 : if( !m_xParentWindow.is() && m_xChartModel.is() )
195 : {
196 : uno::Reference< frame::XController > xController(
197 0 : m_xChartModel->getCurrentController() );
198 0 : if( xController.is() )
199 : {
200 : uno::Reference< frame::XFrame > xFrame(
201 0 : xController->getFrame() );
202 0 : if(xFrame.is())
203 0 : m_xParentWindow = xFrame->getContainerWindow();
204 0 : }
205 : }
206 0 : if( m_xParentWindow.is() )
207 : {
208 0 : VCLXWindow* pImplementation = VCLXWindow::GetImplementation(m_xParentWindow);
209 0 : if (pImplementation)
210 0 : pParent = pImplementation->GetWindow();
211 : }
212 0 : uno::Reference< XComponent > xComp( this );
213 0 : if( m_xChartModel.is() )
214 : {
215 0 : m_pDialog = VclPtr<CreationWizard>::Create( pParent, m_xChartModel, m_xCC );
216 0 : m_pDialog->AddEventListener( LINK( this, CreationWizardUnoDlg, DialogEventHdl ) );
217 0 : }
218 0 : }
219 0 : }
220 0 : IMPL_LINK( CreationWizardUnoDlg, DialogEventHdl, VclWindowEvent*, pEvent )
221 : {
222 0 : if(pEvent && (pEvent->GetId() == VCLEVENT_OBJECT_DYING) )
223 0 : m_pDialog = 0;//avoid duplicate destruction of m_pDialog
224 0 : return 0;
225 : }
226 :
227 0 : sal_Int16 SAL_CALL CreationWizardUnoDlg::execute( ) throw(uno::RuntimeException, std::exception)
228 : {
229 0 : sal_Int16 nRet = RET_CANCEL;
230 : {
231 0 : SolarMutexGuard aSolarGuard;
232 0 : createDialogOnDemand();
233 0 : if( !m_pDialog )
234 0 : return nRet;
235 0 : TimerTriggeredControllerLock aTimerTriggeredControllerLock( m_xChartModel );
236 0 : if( m_bUnlockControllersOnExecute && m_xChartModel.is() )
237 0 : m_xChartModel->unlockControllers();
238 0 : nRet = m_pDialog->Execute();
239 : }
240 0 : return nRet;
241 : }
242 :
243 0 : void SAL_CALL CreationWizardUnoDlg::initialize( const uno::Sequence< uno::Any >& aArguments ) throw(uno::Exception, uno::RuntimeException, std::exception)
244 : {
245 0 : const uno::Any* pArguments = aArguments.getConstArray();
246 0 : for(sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments)
247 : {
248 0 : beans::PropertyValue aProperty;
249 0 : if(*pArguments >>= aProperty)
250 : {
251 0 : if( aProperty.Name == "ParentWindow" )
252 : {
253 0 : aProperty.Value >>= m_xParentWindow;
254 : }
255 0 : else if( aProperty.Name == "ChartModel" )
256 : {
257 0 : aProperty.Value >>= m_xChartModel;
258 : }
259 : }
260 0 : }
261 0 : }
262 :
263 : // ____ OComponentHelper ____
264 : /// Called in dispose method after the listeners were notified.
265 0 : void SAL_CALL CreationWizardUnoDlg::disposing()
266 : {
267 0 : m_xChartModel.clear();
268 0 : m_xParentWindow.clear();
269 :
270 0 : SolarMutexGuard aSolarGuard;
271 0 : m_pDialog.disposeAndClear();
272 :
273 : try
274 : {
275 0 : uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(m_xCC);
276 0 : uno::Reference< frame::XTerminateListener > xListener( this );
277 0 : xDesktop->removeTerminateListener( xListener );
278 : }
279 0 : catch( const uno::Exception & ex )
280 : {
281 : ASSERT_EXCEPTION( ex );
282 0 : }
283 0 : }
284 :
285 : //XPropertySet
286 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL CreationWizardUnoDlg::getPropertySetInfo()
287 : throw (uno::RuntimeException, std::exception)
288 : {
289 : OSL_FAIL("not implemented");
290 0 : return 0;
291 : }
292 :
293 0 : void SAL_CALL CreationWizardUnoDlg::setPropertyValue( const OUString& rPropertyName
294 : , const uno::Any& rValue )
295 : throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException
296 : , lang::WrappedTargetException, uno::RuntimeException, std::exception)
297 : {
298 0 : if( rPropertyName == "Position" )
299 : {
300 0 : awt::Point aPos;
301 0 : if( ! (rValue >>= aPos) )
302 0 : throw lang::IllegalArgumentException( "Property 'Position' requires value of type awt::Point", 0, 0 );
303 :
304 : //set left upper outer corner relative to screen
305 : //pixels, screen position
306 0 : SolarMutexGuard aSolarGuard;
307 0 : createDialogOnDemand();
308 0 : if( m_pDialog )
309 : {
310 0 : m_pDialog->SetPosPixel( Point(0,0) );
311 0 : Rectangle aRect( m_pDialog->GetWindowExtentsRelative( 0 ) );
312 :
313 0 : Point aNewOuterPos = Point( aPos.X - aRect.Left(), aPos.Y - aRect.Top() );
314 0 : m_pDialog->SetPosPixel( aNewOuterPos );
315 0 : }
316 : }
317 0 : else if( rPropertyName == "Size")
318 : {
319 : //read only property, do nothing
320 : }
321 0 : else if( rPropertyName == "UnlockControllersOnExecute" )
322 : {
323 0 : if( ! (rValue >>= m_bUnlockControllersOnExecute) )
324 0 : throw lang::IllegalArgumentException( "Property 'UnlockControllers' requires value of type boolean" , 0, 0 );
325 : }
326 : else
327 0 : throw beans::UnknownPropertyException( "unknown property was tried to set to chart wizard" , 0 );
328 0 : }
329 :
330 0 : uno::Any SAL_CALL CreationWizardUnoDlg::getPropertyValue( const OUString& rPropertyName )
331 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
332 : {
333 0 : uno::Any aRet;
334 0 : if( rPropertyName == "Position" )
335 : {
336 : //get left upper outer corner relative to screen
337 : //pixels, screen position
338 0 : SolarMutexGuard aSolarGuard;
339 0 : createDialogOnDemand();
340 0 : if( m_pDialog )
341 : {
342 0 : Rectangle aRect( m_pDialog->GetWindowExtentsRelative( 0 ) );
343 0 : awt::Point aPoint(aRect.Left(),aRect.Top());
344 0 : aRet = uno::makeAny( aPoint );
345 0 : }
346 : }
347 0 : else if( rPropertyName == "Size" )
348 : {
349 : //get outer size inclusive decoration
350 : //pixels, screen position
351 0 : SolarMutexGuard aSolarGuard;
352 0 : createDialogOnDemand();
353 0 : if( m_pDialog )
354 : {
355 0 : Rectangle aRect( m_pDialog->GetWindowExtentsRelative( 0 ) );
356 0 : awt::Size aSize(aRect.GetWidth(),aRect.GetHeight());
357 0 : aRet = uno::makeAny( aSize );
358 0 : }
359 : }
360 0 : else if( rPropertyName == "UnlockControllersOnExecute" )
361 : {
362 0 : aRet = uno::makeAny( m_bUnlockControllersOnExecute );
363 : }
364 : else
365 0 : throw beans::UnknownPropertyException( "unknown property was tried to get from chart wizard" , 0 );
366 0 : return aRet;
367 : }
368 :
369 0 : void SAL_CALL CreationWizardUnoDlg::addPropertyChangeListener(
370 : const OUString& /* aPropertyName */, const uno::Reference< beans::XPropertyChangeListener >& /* xListener */ )
371 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
372 : {
373 : OSL_FAIL("not implemented");
374 0 : }
375 0 : void SAL_CALL CreationWizardUnoDlg::removePropertyChangeListener(
376 : const OUString& /* aPropertyName */, const uno::Reference< beans::XPropertyChangeListener >& /* aListener */ )
377 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
378 : {
379 : OSL_FAIL("not implemented");
380 0 : }
381 :
382 0 : void SAL_CALL CreationWizardUnoDlg::addVetoableChangeListener( const OUString& /* PropertyName */, const uno::Reference< beans::XVetoableChangeListener >& /* aListener */ )
383 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
384 : {
385 : OSL_FAIL("not implemented");
386 0 : }
387 :
388 0 : void SAL_CALL CreationWizardUnoDlg::removeVetoableChangeListener( const OUString& /* PropertyName */, const uno::Reference< beans::XVetoableChangeListener >& /* aListener */ )
389 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
390 : {
391 : OSL_FAIL("not implemented");
392 0 : }
393 :
394 : } //namespace chart
395 :
396 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
397 0 : com_sun_star_comp_chart2_WizardDialog_get_implementation(css::uno::XComponentContext *context,
398 : css::uno::Sequence<css::uno::Any> const &)
399 : {
400 0 : return cppu::acquire(new chart::CreationWizardUnoDlg(context));
401 : }
402 :
403 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|