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