1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dlg_CreationWizard_UNO.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "dlg_CreationWizard_UNO.hxx"
35 #include "dlg_CreationWizard.hxx"
37 #include "servicenames.hxx"
38 #include "ContainerHelper.hxx"
39 #include "TimerTriggeredControllerLock.hxx"
40 #include <osl/mutex.hxx>
41 #include <vos/mutex.hxx>
42 // header for class Application
43 #include <vcl/svapp.hxx>
44 #include <toolkit/awt/vclxwindow.hxx>
45 // header for define RET_CANCEL
46 #include <vcl/msgbox.hxx>
47 // header for class OImplementationId
48 #include <cppuhelper/typeprovider.hxx>
49 #include <com/sun/star/awt/Point.hpp>
50 #include <com/sun/star/awt/Size.hpp>
51 #include <com/sun/star/beans/PropertyValue.hpp>
52 #include <com/sun/star/frame/XDesktop.hpp>
54 //.............................................................................
57 //.............................................................................
58 using namespace ::com::sun::star
;
60 CreationWizardUnoDlg::CreationWizardUnoDlg( const uno::Reference
< uno::XComponentContext
>& xContext
)
61 : OComponentHelper( m_aMutex
)
64 , m_xParentWindow( 0 )
66 , m_bUnlockControllersOnExecute(false)
68 uno::Reference
< frame::XDesktop
> xDesktop(
69 m_xCC
->getServiceManager()->createInstanceWithContext(
70 C2U( "com.sun.star.frame.Desktop" ), m_xCC
), uno::UNO_QUERY
);
73 uno::Reference
< frame::XTerminateListener
> xListener( this );
74 xDesktop
->addTerminateListener( xListener
);
77 CreationWizardUnoDlg::~CreationWizardUnoDlg()
79 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex());
86 //-------------------------------------------------------------------------
88 APPHELPER_XSERVICEINFO_IMPL(CreationWizardUnoDlg
,CHART_WIZARD_DIALOG_SERVICE_IMPLEMENTATION_NAME
)
90 uno::Sequence
< rtl::OUString
> CreationWizardUnoDlg
91 ::getSupportedServiceNames_Static()
93 uno::Sequence
< rtl::OUString
> aSNS( 1 );
94 aSNS
.getArray()[ 0 ] = CHART_WIZARD_DIALOG_SERVICE_NAME
;
98 //-------------------------------------------------------------------------
100 uno::Any SAL_CALL
CreationWizardUnoDlg::queryInterface( const uno::Type
& aType
) throw (uno::RuntimeException
)
102 return OComponentHelper::queryInterface( aType
);
104 void SAL_CALL
CreationWizardUnoDlg::acquire() throw ()
106 OComponentHelper::acquire();
108 void SAL_CALL
CreationWizardUnoDlg::release() throw ()
110 OComponentHelper::release();
112 uno::Any SAL_CALL
CreationWizardUnoDlg::queryAggregation( uno::Type
const & rType
) throw (uno::RuntimeException
)
114 if (rType
== ::getCppuType( (uno::Reference
< ui::dialogs::XExecutableDialog
> const *)0 ))
116 void * p
= static_cast< ui::dialogs::XExecutableDialog
* >( this );
117 return uno::Any( &p
, rType
);
119 else if (rType
== ::getCppuType( (uno::Reference
< lang::XServiceInfo
> const *)0 ))
121 void * p
= static_cast< lang::XTypeProvider
* >( this );
122 return uno::Any( &p
, rType
);
124 else if (rType
== ::getCppuType( (uno::Reference
< lang::XInitialization
> const *)0 ))
126 void * p
= static_cast< lang::XInitialization
* >( this );
127 return uno::Any( &p
, rType
);
129 else if (rType
== ::getCppuType( (uno::Reference
< frame::XTerminateListener
> const *)0 ))
131 void * p
= static_cast< frame::XTerminateListener
* >( this );
132 return uno::Any( &p
, rType
);
134 else if (rType
== ::getCppuType( (uno::Reference
< beans::XPropertySet
> const *)0 ))
136 void * p
= static_cast< beans::XPropertySet
* >( this );
137 return uno::Any( &p
, rType
);
139 return OComponentHelper::queryAggregation( rType
);
142 //-------------------------------------------------------------------------
143 #define LCL_CPPUTYPE(t) (::getCppuType( reinterpret_cast< const uno::Reference<t> *>(0)))
145 uno::Sequence
< uno::Type
> CreationWizardUnoDlg::getTypes() throw(uno::RuntimeException
)
147 static uno::Sequence
< uno::Type
> aTypeList
;
150 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
151 if( !aTypeList
.getLength() )
153 ::std::vector
< uno::Type
> aTypes
;
154 aTypes
.push_back( LCL_CPPUTYPE( lang::XComponent
));
155 aTypes
.push_back( LCL_CPPUTYPE( lang::XTypeProvider
));
156 aTypes
.push_back( LCL_CPPUTYPE( uno::XAggregation
));
157 aTypes
.push_back( LCL_CPPUTYPE( uno::XWeak
));
158 aTypes
.push_back( LCL_CPPUTYPE( lang::XServiceInfo
));
159 aTypes
.push_back( LCL_CPPUTYPE( lang::XInitialization
));
160 aTypes
.push_back( LCL_CPPUTYPE( frame::XTerminateListener
));
161 aTypes
.push_back( LCL_CPPUTYPE( ui::dialogs::XExecutableDialog
));
162 aTypes
.push_back( LCL_CPPUTYPE( beans::XPropertySet
));
163 aTypeList
= ::chart::ContainerHelper::ContainerToSequence( aTypes
);
169 uno::Sequence
< sal_Int8
> SAL_CALL
CreationWizardUnoDlg::getImplementationId( void ) throw( uno::RuntimeException
)
171 static uno::Sequence
< sal_Int8
> aId
;
172 if( aId
.getLength() == 0 )
175 rtl_createUuid( (sal_uInt8
*)aId
.getArray(), 0, sal_True
);
180 //-------------------------------------------------------------------------
182 // XTerminateListener
183 void SAL_CALL
CreationWizardUnoDlg::queryTermination( const lang::EventObject
& /*Event*/ ) throw( frame::TerminationVetoException
, uno::RuntimeException
)
185 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex());
187 // we will never give a veto here
188 if( m_pDialog
&& !m_pDialog
->isClosable() )
191 throw frame::TerminationVetoException();
195 //-------------------------------------------------------------------------
197 void SAL_CALL
CreationWizardUnoDlg::notifyTermination( const lang::EventObject
& /*Event*/ ) throw (uno::RuntimeException
)
199 // we are going down, so dispose us!
203 void SAL_CALL
CreationWizardUnoDlg::disposing( const lang::EventObject
& /*Source*/ ) throw (uno::RuntimeException
)
205 //Listener should deregister himself and relaese all references to the closing object.
208 //-------------------------------------------------------------------------
209 void SAL_CALL
CreationWizardUnoDlg::setTitle( const ::rtl::OUString
& /*rTitle*/ ) throw(uno::RuntimeException
)
212 //-------------------------------------------------------------------------
213 void CreationWizardUnoDlg::createDialogOnDemand()
215 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex());
218 Window
* pParent
= NULL
;
219 if( !m_xParentWindow
.is() && m_xChartModel
.is() )
221 uno::Reference
< frame::XController
> xController(
222 m_xChartModel
->getCurrentController() );
223 if( xController
.is() )
225 uno::Reference
< frame::XFrame
> xFrame(
226 xController
->getFrame() );
228 m_xParentWindow
= xFrame
->getContainerWindow();
231 if( m_xParentWindow
.is() )
233 VCLXWindow
* pImplementation
= VCLXWindow::GetImplementation(m_xParentWindow
);
235 pParent
= pImplementation
->GetWindow();
237 uno::Reference
< XComponent
> xComp( this );
238 if( m_xChartModel
.is() )
240 m_pDialog
= new CreationWizard( pParent
, m_xChartModel
, m_xCC
);
241 m_pDialog
->AddEventListener( LINK( this, CreationWizardUnoDlg
, DialogEventHdl
) );
245 //-------------------------------------------------------------------------
246 IMPL_LINK( CreationWizardUnoDlg
, DialogEventHdl
, VclWindowEvent
*, pEvent
)
248 if(pEvent
&& (pEvent
->GetId() == VCLEVENT_OBJECT_DYING
) )
249 m_pDialog
= 0;//avoid duplicate destruction of m_pDialog
253 //-------------------------------------------------------------------------
254 sal_Int16 SAL_CALL
CreationWizardUnoDlg::execute( ) throw(uno::RuntimeException
)
256 sal_Int16 nRet
= RET_CANCEL
;
258 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex());
259 createDialogOnDemand();
262 TimerTriggeredControllerLock
aTimerTriggeredControllerLock( m_xChartModel
);
263 if( m_bUnlockControllersOnExecute
&& m_xChartModel
.is() )
264 m_xChartModel
->unlockControllers();
265 nRet
= m_pDialog
->Execute();
270 //-------------------------------------------------------------------------
271 void SAL_CALL
CreationWizardUnoDlg::initialize( const uno::Sequence
< uno::Any
>& aArguments
) throw(uno::Exception
, uno::RuntimeException
)
273 const uno::Any
* pArguments
= aArguments
.getConstArray();
274 for(sal_Int32 i
=0; i
<aArguments
.getLength(); ++i
, ++pArguments
)
276 beans::PropertyValue aProperty
;
277 if(*pArguments
>>= aProperty
)
279 if( aProperty
.Name
.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ParentWindow" ) ) == 0 )
281 aProperty
.Value
>>= m_xParentWindow
;
283 else if( aProperty
.Name
.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ChartModel" ) ) == 0 )
285 aProperty
.Value
>>= m_xChartModel
;
291 //-------------------------------------------------------------------------
292 // ____ OComponentHelper ____
293 /// Called in dispose method after the listeners were notified.
294 void SAL_CALL
CreationWizardUnoDlg::disposing()
296 m_xChartModel
.clear();
297 m_xParentWindow
.clear();
300 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex());
309 uno::Reference
< frame::XDesktop
> xDesktop(
310 m_xCC
->getServiceManager()->createInstanceWithContext(
311 C2U( "com.sun.star.frame.Desktop" ), m_xCC
), uno::UNO_QUERY
);
314 uno::Reference
< frame::XTerminateListener
> xListener( this );
315 xDesktop
->removeTerminateListener( xListener
);
318 catch( const uno::Exception
& ex
)
320 ASSERT_EXCEPTION( ex
);
326 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
CreationWizardUnoDlg::getPropertySetInfo()
327 throw (uno::RuntimeException
)
329 OSL_ENSURE(false,"not implemented");
333 void SAL_CALL
CreationWizardUnoDlg::setPropertyValue( const ::rtl::OUString
& rPropertyName
334 , const uno::Any
& rValue
)
335 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
336 , lang::WrappedTargetException
, uno::RuntimeException
)
338 if( rPropertyName
.equals(C2U("Position")) )
341 if( ! (rValue
>>= aPos
) )
342 throw lang::IllegalArgumentException( C2U("Property 'Position' requires value of type awt::Point"), 0, 0 );
344 //set left upper outer corner relative to screen
345 //pixels, screen position
346 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex());
347 createDialogOnDemand();
350 m_pDialog
->SetPosPixel( Point(0,0) );
351 Rectangle
aRect( m_pDialog
->GetWindowExtentsRelative( 0 ) );
353 Point aNewOuterPos
= Point( aPos
.X
- aRect
.Left(), aPos
.Y
- aRect
.Top() );
354 m_pDialog
->SetPosPixel( aNewOuterPos
);
357 else if( rPropertyName
.equals(C2U("Size")) )
359 //read only property, do nothing
361 else if( rPropertyName
.equals(C2U("UnlockControllersOnExecute")) )
363 if( ! (rValue
>>= m_bUnlockControllersOnExecute
) )
364 throw lang::IllegalArgumentException( C2U("Property 'UnlockControllers' requires value of type boolean"), 0, 0 );
367 throw beans::UnknownPropertyException( C2U("unknown property was tried to set to chart wizard"), 0 );
370 uno::Any SAL_CALL
CreationWizardUnoDlg::getPropertyValue( const ::rtl::OUString
& rPropertyName
)
371 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
374 if( rPropertyName
.equals(C2U("Position")) )
376 //get left upper outer corner relative to screen
377 //pixels, screen position
378 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex());
379 createDialogOnDemand();
382 Rectangle
aRect( m_pDialog
->GetWindowExtentsRelative( 0 ) );
383 awt::Point
aPoint(aRect
.Left(),aRect
.Top());
384 aRet
= uno::makeAny( aPoint
);
387 else if( rPropertyName
.equals(C2U("Size")) )
389 //get outer size inclusive decoration
390 //pixels, screen position
391 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex());
392 createDialogOnDemand();
395 Rectangle
aRect( m_pDialog
->GetWindowExtentsRelative( 0 ) );
396 awt::Size
aSize(aRect
.GetWidth(),aRect
.GetHeight());
397 aRet
= uno::makeAny( aSize
);
400 else if( rPropertyName
.equals(C2U("UnlockControllersOnExecute")) )
402 aRet
= uno::makeAny( m_bUnlockControllersOnExecute
);
405 throw beans::UnknownPropertyException( C2U("unknown property was tried to get from chart wizard"), 0 );
409 void SAL_CALL
CreationWizardUnoDlg::addPropertyChangeListener(
410 const ::rtl::OUString
& /* aPropertyName */, const uno::Reference
< beans::XPropertyChangeListener
>& /* xListener */ )
411 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
413 OSL_ENSURE(false,"not implemented");
415 void SAL_CALL
CreationWizardUnoDlg::removePropertyChangeListener(
416 const ::rtl::OUString
& /* aPropertyName */, const uno::Reference
< beans::XPropertyChangeListener
>& /* aListener */ )
417 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
419 OSL_ENSURE(false,"not implemented");
422 void SAL_CALL
CreationWizardUnoDlg::addVetoableChangeListener( const ::rtl::OUString
& /* PropertyName */, const uno::Reference
< beans::XVetoableChangeListener
>& /* aListener */ )
423 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
425 OSL_ENSURE(false,"not implemented");
428 void SAL_CALL
CreationWizardUnoDlg::removeVetoableChangeListener( const ::rtl::OUString
& /* PropertyName */, const uno::Reference
< beans::XVetoableChangeListener
>& /* aListener */ )
429 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
431 OSL_ENSURE(false,"not implemented");
434 //.............................................................................
436 //.............................................................................