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

Generated by: LCOV version 1.10