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

Generated by: LCOV version 1.10