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 "dlg_CreationWizard_UNO.hxx"
21 #include "dlg_CreationWizard.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>
40 using namespace ::com::sun::star
;
42 CreationWizardUnoDlg::CreationWizardUnoDlg( const uno::Reference
< uno::XComponentContext
>& xContext
)
43 : OComponentHelper( m_aMutex
)
46 , m_xParentWindow( 0 )
48 , m_bUnlockControllersOnExecute(false)
50 uno::Reference
< frame::XDesktop2
> xDesktop
= frame::Desktop::create(m_xCC
);
51 uno::Reference
< frame::XTerminateListener
> xListener( this );
52 xDesktop
->addTerminateListener( xListener
);
54 CreationWizardUnoDlg::~CreationWizardUnoDlg()
56 SolarMutexGuard aSolarGuard
;
57 m_pDialog
.disposeAndClear();
60 OUString SAL_CALL
CreationWizardUnoDlg::getImplementationName()
61 throw( css::uno::RuntimeException
, std::exception
)
63 return getImplementationName_Static();
66 OUString
CreationWizardUnoDlg::getImplementationName_Static()
68 return OUString(CHART_WIZARD_DIALOG_SERVICE_IMPLEMENTATION_NAME
);
71 sal_Bool SAL_CALL
CreationWizardUnoDlg::supportsService( const OUString
& rServiceName
)
72 throw( css::uno::RuntimeException
, std::exception
)
74 return cppu::supportsService(this, rServiceName
);
77 css::uno::Sequence
< OUString
> SAL_CALL
CreationWizardUnoDlg::getSupportedServiceNames()
78 throw( css::uno::RuntimeException
, std::exception
)
80 return getSupportedServiceNames_Static();
83 uno::Sequence
< OUString
> CreationWizardUnoDlg::getSupportedServiceNames_Static()
85 uno::Sequence
< OUString
> aSNS( 1 );
86 aSNS
.getArray()[ 0 ] = CHART_WIZARD_DIALOG_SERVICE_NAME
;
91 uno::Any SAL_CALL
CreationWizardUnoDlg::queryInterface( const uno::Type
& aType
) throw (uno::RuntimeException
, std::exception
)
93 return OComponentHelper::queryInterface( aType
);
95 void SAL_CALL
CreationWizardUnoDlg::acquire() throw ()
97 OComponentHelper::acquire();
99 void SAL_CALL
CreationWizardUnoDlg::release() throw ()
101 OComponentHelper::release();
103 uno::Any SAL_CALL
CreationWizardUnoDlg::queryAggregation( uno::Type
const & rType
) throw (uno::RuntimeException
, std::exception
)
105 if (rType
== cppu::UnoType
<ui::dialogs::XExecutableDialog
>::get())
107 void * p
= static_cast< ui::dialogs::XExecutableDialog
* >( this );
108 return uno::Any( &p
, rType
);
110 else if (rType
== cppu::UnoType
<lang::XServiceInfo
>::get())
112 void * p
= static_cast< lang::XTypeProvider
* >( this );
113 return uno::Any( &p
, rType
);
115 else if (rType
== cppu::UnoType
<lang::XInitialization
>::get())
117 void * p
= static_cast< lang::XInitialization
* >( this );
118 return uno::Any( &p
, rType
);
120 else if (rType
== cppu::UnoType
<frame::XTerminateListener
>::get())
122 void * p
= static_cast< frame::XTerminateListener
* >( this );
123 return uno::Any( &p
, rType
);
125 else if (rType
== cppu::UnoType
<beans::XPropertySet
>::get())
127 void * p
= static_cast< beans::XPropertySet
* >( this );
128 return uno::Any( &p
, rType
);
130 return OComponentHelper::queryAggregation( rType
);
133 uno::Sequence
< uno::Type
> CreationWizardUnoDlg::getTypes() throw(uno::RuntimeException
, std::exception
)
135 static uno::Sequence
< uno::Type
> aTypeList
;
137 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
138 if( !aTypeList
.getLength() )
140 ::std::vector
< uno::Type
> aTypes
;
141 aTypes
.push_back( cppu::UnoType
<lang::XComponent
>::get() );
142 aTypes
.push_back( cppu::UnoType
<lang::XTypeProvider
>::get() );
143 aTypes
.push_back( cppu::UnoType
<uno::XAggregation
>::get() );
144 aTypes
.push_back( cppu::UnoType
<uno::XWeak
>::get() );
145 aTypes
.push_back( cppu::UnoType
<lang::XServiceInfo
>::get() );
146 aTypes
.push_back( cppu::UnoType
<lang::XInitialization
>::get() );
147 aTypes
.push_back( cppu::UnoType
<frame::XTerminateListener
>::get() );
148 aTypes
.push_back( cppu::UnoType
<ui::dialogs::XExecutableDialog
>::get() );
149 aTypes
.push_back( cppu::UnoType
<beans::XPropertySet
>::get() );
150 aTypeList
= ::chart::ContainerHelper::ContainerToSequence( aTypes
);
156 uno::Sequence
< sal_Int8
> SAL_CALL
CreationWizardUnoDlg::getImplementationId() throw( uno::RuntimeException
, std::exception
)
158 return css::uno::Sequence
<sal_Int8
>();
161 // XTerminateListener
162 void SAL_CALL
CreationWizardUnoDlg::queryTermination( const lang::EventObject
& /*Event*/ ) throw( frame::TerminationVetoException
, uno::RuntimeException
, std::exception
)
164 SolarMutexGuard aSolarGuard
;
166 // we will never give a veto here
167 if( m_pDialog
&& !m_pDialog
->isClosable() )
170 throw frame::TerminationVetoException();
174 void SAL_CALL
CreationWizardUnoDlg::notifyTermination( const lang::EventObject
& /*Event*/ ) throw (uno::RuntimeException
, std::exception
)
176 // we are going down, so dispose us!
180 void SAL_CALL
CreationWizardUnoDlg::disposing( const lang::EventObject
& /*Source*/ ) throw (uno::RuntimeException
, std::exception
)
182 //Listener should deregister himself and release all references to the closing object.
185 void SAL_CALL
CreationWizardUnoDlg::setTitle( const OUString
& /*rTitle*/ ) throw(uno::RuntimeException
, std::exception
)
188 void CreationWizardUnoDlg::createDialogOnDemand()
190 SolarMutexGuard aSolarGuard
;
193 vcl::Window
* pParent
= NULL
;
194 if( !m_xParentWindow
.is() && m_xChartModel
.is() )
196 uno::Reference
< frame::XController
> xController(
197 m_xChartModel
->getCurrentController() );
198 if( xController
.is() )
200 uno::Reference
< frame::XFrame
> xFrame(
201 xController
->getFrame() );
203 m_xParentWindow
= xFrame
->getContainerWindow();
206 if( m_xParentWindow
.is() )
208 VCLXWindow
* pImplementation
= VCLXWindow::GetImplementation(m_xParentWindow
);
210 pParent
= pImplementation
->GetWindow();
212 uno::Reference
< XComponent
> xComp( this );
213 if( m_xChartModel
.is() )
215 m_pDialog
= VclPtr
<CreationWizard
>::Create( pParent
, m_xChartModel
, m_xCC
);
216 m_pDialog
->AddEventListener( LINK( this, CreationWizardUnoDlg
, DialogEventHdl
) );
220 IMPL_LINK( CreationWizardUnoDlg
, DialogEventHdl
, VclWindowEvent
*, pEvent
)
222 if(pEvent
&& (pEvent
->GetId() == VCLEVENT_OBJECT_DYING
) )
223 m_pDialog
= 0;//avoid duplicate destruction of m_pDialog
227 sal_Int16 SAL_CALL
CreationWizardUnoDlg::execute( ) throw(uno::RuntimeException
, std::exception
)
229 sal_Int16 nRet
= RET_CANCEL
;
231 SolarMutexGuard aSolarGuard
;
232 createDialogOnDemand();
235 TimerTriggeredControllerLock
aTimerTriggeredControllerLock( m_xChartModel
);
236 if( m_bUnlockControllersOnExecute
&& m_xChartModel
.is() )
237 m_xChartModel
->unlockControllers();
238 nRet
= m_pDialog
->Execute();
243 void SAL_CALL
CreationWizardUnoDlg::initialize( const uno::Sequence
< uno::Any
>& aArguments
) throw(uno::Exception
, uno::RuntimeException
, std::exception
)
245 const uno::Any
* pArguments
= aArguments
.getConstArray();
246 for(sal_Int32 i
=0; i
<aArguments
.getLength(); ++i
, ++pArguments
)
248 beans::PropertyValue aProperty
;
249 if(*pArguments
>>= aProperty
)
251 if( aProperty
.Name
== "ParentWindow" )
253 aProperty
.Value
>>= m_xParentWindow
;
255 else if( aProperty
.Name
== "ChartModel" )
257 aProperty
.Value
>>= m_xChartModel
;
263 // ____ OComponentHelper ____
264 /// Called in dispose method after the listeners were notified.
265 void SAL_CALL
CreationWizardUnoDlg::disposing()
267 m_xChartModel
.clear();
268 m_xParentWindow
.clear();
270 SolarMutexGuard aSolarGuard
;
271 m_pDialog
.disposeAndClear();
275 uno::Reference
< frame::XDesktop2
> xDesktop
= frame::Desktop::create(m_xCC
);
276 uno::Reference
< frame::XTerminateListener
> xListener( this );
277 xDesktop
->removeTerminateListener( xListener
);
279 catch( const uno::Exception
& ex
)
281 ASSERT_EXCEPTION( ex
);
286 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
CreationWizardUnoDlg::getPropertySetInfo()
287 throw (uno::RuntimeException
, std::exception
)
289 OSL_FAIL("not implemented");
293 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
)
298 if( rPropertyName
== "Position" )
301 if( ! (rValue
>>= aPos
) )
302 throw lang::IllegalArgumentException( "Property 'Position' requires value of type awt::Point", 0, 0 );
304 //set left upper outer corner relative to screen
305 //pixels, screen position
306 SolarMutexGuard aSolarGuard
;
307 createDialogOnDemand();
310 m_pDialog
->SetPosPixel( Point(0,0) );
311 Rectangle
aRect( m_pDialog
->GetWindowExtentsRelative( 0 ) );
313 Point aNewOuterPos
= Point( aPos
.X
- aRect
.Left(), aPos
.Y
- aRect
.Top() );
314 m_pDialog
->SetPosPixel( aNewOuterPos
);
317 else if( rPropertyName
== "Size")
319 //read only property, do nothing
321 else if( rPropertyName
== "UnlockControllersOnExecute" )
323 if( ! (rValue
>>= m_bUnlockControllersOnExecute
) )
324 throw lang::IllegalArgumentException( "Property 'UnlockControllers' requires value of type boolean" , 0, 0 );
327 throw beans::UnknownPropertyException( "unknown property was tried to set to chart wizard" , 0 );
330 uno::Any SAL_CALL
CreationWizardUnoDlg::getPropertyValue( const OUString
& rPropertyName
)
331 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
334 if( rPropertyName
== "Position" )
336 //get left upper outer corner relative to screen
337 //pixels, screen position
338 SolarMutexGuard aSolarGuard
;
339 createDialogOnDemand();
342 Rectangle
aRect( m_pDialog
->GetWindowExtentsRelative( 0 ) );
343 awt::Point
aPoint(aRect
.Left(),aRect
.Top());
344 aRet
= uno::makeAny( aPoint
);
347 else if( rPropertyName
== "Size" )
349 //get outer size inclusive decoration
350 //pixels, screen position
351 SolarMutexGuard aSolarGuard
;
352 createDialogOnDemand();
355 Rectangle
aRect( m_pDialog
->GetWindowExtentsRelative( 0 ) );
356 awt::Size
aSize(aRect
.GetWidth(),aRect
.GetHeight());
357 aRet
= uno::makeAny( aSize
);
360 else if( rPropertyName
== "UnlockControllersOnExecute" )
362 aRet
= uno::makeAny( m_bUnlockControllersOnExecute
);
365 throw beans::UnknownPropertyException( "unknown property was tried to get from chart wizard" , 0 );
369 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
)
373 OSL_FAIL("not implemented");
375 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
)
379 OSL_FAIL("not implemented");
382 void SAL_CALL
CreationWizardUnoDlg::addVetoableChangeListener( const OUString
& /* PropertyName */, const uno::Reference
< beans::XVetoableChangeListener
>& /* aListener */ )
383 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
385 OSL_FAIL("not implemented");
388 void SAL_CALL
CreationWizardUnoDlg::removeVetoableChangeListener( const OUString
& /* PropertyName */, const uno::Reference
< beans::XVetoableChangeListener
>& /* aListener */ )
389 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
391 OSL_FAIL("not implemented");
396 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
397 com_sun_star_comp_chart2_WizardDialog_get_implementation(css::uno::XComponentContext
*context
,
398 css::uno::Sequence
<css::uno::Any
> const &)
400 return cppu::acquire(new chart::CreationWizardUnoDlg(context
));
403 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */