LCOV - code coverage report
Current view: top level - chart2/source/controller/dialogs - dlg_CreationWizard_UNO.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 187 0.0 %
Date: 2014-04-14 Functions: 0 31 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10