LCOV - code coverage report
Current view: top level - libreoffice/toolkit/source/controls - tabpagecontainer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 169 0.0 %
Date: 2012-12-17 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             : 
      21             : #include <toolkit/controls/geometrycontrolmodel.hxx>
      22             : #include <toolkit/controls/tabpagecontainer.hxx>
      23             : #include <toolkit/controls/tabpagemodel.hxx>
      24             : #include <toolkit/helper/property.hxx>
      25             : #include <toolkit/helper/unopropertyarrayhelper.hxx>
      26             : 
      27             : #include <com/sun/star/awt/XControlModel.hpp>
      28             : #include <com/sun/star/awt/XVclWindowPeer.hpp>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : 
      31             : #include <comphelper/processfactory.hxx>
      32             : #include <osl/diagnose.h>
      33             : #include <tools/diagnose_ex.h>
      34             : #include <vcl/svapp.hxx>
      35             : 
      36             : using ::rtl::OUString;
      37             : using namespace ::com::sun::star;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::lang;
      40             : using namespace ::com::sun::star::beans;
      41             : using namespace ::com::sun::star::container;
      42             : using namespace ::com::sun::star::view;
      43             : using ::com::sun::star::awt::tab::XTabPageModel;
      44             : 
      45             : #define WRONG_TYPE_EXCEPTION "Type must be ::com::sun::star::awt::tab::XTabPageModel!"
      46             : //  ----------------------------------------------------
      47             : //  class UnoControlTabPageContainerModel
      48             : //  ----------------------------------------------------
      49           0 : UnoControlTabPageContainerModel::UnoControlTabPageContainerModel( const Reference< XMultiServiceFactory >& i_factory )
      50             :     :UnoControlTabPageContainerModel_Base( i_factory )
      51           0 :     ,maContainerListeners( *this )
      52             : {
      53           0 :     ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
      54           0 :     ImplRegisterProperty( BASEPROPERTY_BORDER );
      55           0 :     ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
      56           0 :     ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
      57           0 :     ImplRegisterProperty( BASEPROPERTY_ENABLED );
      58           0 :     ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
      59           0 :     ImplRegisterProperty( BASEPROPERTY_HELPURL );
      60           0 :     ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
      61           0 :     ImplRegisterProperty( BASEPROPERTY_TEXT );
      62           0 : }
      63             : 
      64           0 : ::rtl::OUString UnoControlTabPageContainerModel::getServiceName() throw(RuntimeException)
      65             : {
      66           0 :     return ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPageContainerModel );
      67             : }
      68             : 
      69           0 : uno::Any UnoControlTabPageContainerModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
      70             : {
      71           0 :     switch(nPropId)
      72             :     {
      73             :         case BASEPROPERTY_DEFAULTCONTROL:
      74           0 :             return uno::makeAny( ::rtl::OUString::createFromAscii( szServiceName_UnoControlTabPageContainer ) );
      75             :         case BASEPROPERTY_BORDER:
      76           0 :             return uno::makeAny((sal_Int16) 0);              // No Border
      77             :         default:
      78           0 :             return UnoControlModel::ImplGetDefaultValue( nPropId );
      79             :     }
      80             : }
      81             : 
      82           0 : ::cppu::IPropertyArrayHelper& UnoControlTabPageContainerModel::getInfoHelper()
      83             : {
      84             :     static UnoPropertyArrayHelper* pHelper = NULL;
      85           0 :     if ( !pHelper )
      86             :     {
      87           0 :         com::sun::star::uno::Sequence<sal_Int32>    aIDs = ImplGetPropertyIds();
      88           0 :         pHelper = new UnoPropertyArrayHelper( aIDs );
      89             :     }
      90           0 :     return *pHelper;
      91             : }
      92           0 : Reference< ::com::sun::star::beans::XPropertySetInfo > UnoControlTabPageContainerModel::getPropertySetInfo(  ) throw(RuntimeException)
      93             : {
      94           0 :     static Reference< ::com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
      95           0 :     return xInfo;
      96             : }
      97             : 
      98             : namespace
      99             : {
     100           0 :     Reference< XTabPageModel > lcl_createTabPageModel( ::comphelper::ComponentContext const & i_context,
     101             :         Sequence< Any > const & i_initArguments, Reference< XPropertySet > const & i_parentModel )
     102             :     {
     103             :         try
     104             :         {
     105           0 :             Reference< XPropertySet > const xParentDelegator( i_parentModel, UNO_QUERY_THROW );
     106           0 :             Reference< XPropertySetInfo > const xPSI( xParentDelegator->getPropertySetInfo() );
     107           0 :             bool const isGeometryControlModel = xPSI.is() && xPSI->hasPropertyByName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ) );
     108             : 
     109           0 :             Reference< XInterface > xInstance;
     110           0 :             if ( isGeometryControlModel )
     111           0 :                 xInstance = *( new OGeometryControlModel< UnoControlTabPageModel >( i_context.getLegacyServiceFactory() ) );
     112             :             else
     113           0 :                 xInstance = *( new UnoControlTabPageModel( i_context.getLegacyServiceFactory() ) );
     114             : 
     115           0 :             Reference< XTabPageModel > const xTabPageModel( xInstance, UNO_QUERY_THROW );
     116           0 :             Reference< XInitialization > const xInit( xTabPageModel, UNO_QUERY_THROW );
     117           0 :             xInit->initialize( i_initArguments );
     118             : 
     119           0 :             return xTabPageModel;
     120             :         }
     121           0 :         catch( const RuntimeException& )
     122             :         {
     123           0 :             throw;
     124             :         }
     125           0 :         catch( const Exception& )
     126             :         {
     127             :             DBG_UNHANDLED_EXCEPTION();
     128             :         }
     129           0 :         return NULL;
     130             :     }
     131             : }
     132             : 
     133           0 : Reference< XTabPageModel > SAL_CALL UnoControlTabPageContainerModel::createTabPage( ::sal_Int16 i_tabPageID ) throw (RuntimeException)
     134             : {
     135           0 :     Sequence< Any > aInitArgs(1);
     136           0 :     aInitArgs[0] <<= i_tabPageID;
     137           0 :     return lcl_createTabPageModel( maContext, aInitArgs, this );
     138             : }
     139             : 
     140           0 : Reference< XTabPageModel > SAL_CALL UnoControlTabPageContainerModel::loadTabPage( ::sal_Int16 i_tabPageID, const ::rtl::OUString& i_resourceURL ) throw (RuntimeException)
     141             : {
     142           0 :     Sequence< Any > aInitArgs(2);
     143           0 :     aInitArgs[0] <<= i_tabPageID;
     144           0 :     aInitArgs[1] <<= i_resourceURL;
     145           0 :     return lcl_createTabPageModel( maContext, aInitArgs, this );
     146             : }
     147             : 
     148           0 : void SAL_CALL UnoControlTabPageContainerModel::insertByIndex( ::sal_Int32 nIndex, const com::sun::star::uno::Any& aElement) throw (IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, uno::RuntimeException)
     149             : {
     150           0 :     SolarMutexGuard aSolarGuard;
     151           0 :     uno::Reference < XTabPageModel > xTabPageModel;
     152           0 :     if(aElement >>= xTabPageModel)
     153             :     {
     154           0 :         if ( sal_Int32( m_aTabPageVector.size()) ==nIndex )
     155           0 :             m_aTabPageVector.push_back( xTabPageModel );
     156           0 :         else if ( sal_Int32( m_aTabPageVector.size()) > nIndex )
     157             :         {
     158           0 :             std::vector< uno::Reference< XTabPageModel > >::iterator aIter = m_aTabPageVector.begin();
     159           0 :             aIter += nIndex;
     160           0 :             m_aTabPageVector.insert( aIter, xTabPageModel );
     161             :         }
     162             :         else
     163           0 :             throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
     164           0 :         ContainerEvent aEvent;
     165           0 :         aEvent.Source = *this;
     166           0 :         aEvent.Element <<= aElement;
     167           0 :         aEvent.Accessor <<= ::rtl::OUString::valueOf(nIndex);
     168           0 :         maContainerListeners.elementInserted( aEvent );
     169             :     }
     170             :     else
     171             :         throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
     172           0 :             (OWeakObject *)this, 2 );
     173           0 : }
     174             : // -----------------------------------------------------------------------------
     175           0 : void SAL_CALL UnoControlTabPageContainerModel::removeByIndex( ::sal_Int32 /*Index*/ ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
     176             : {
     177           0 : }
     178             : // XIndexReplace
     179           0 : void SAL_CALL UnoControlTabPageContainerModel::replaceByIndex( ::sal_Int32 /*Index*/, const uno::Any& /*Element*/ ) throw (lang::IllegalArgumentException, lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
     180             : {
     181           0 : }
     182             : // -----------------------------------------------------------------------------
     183             : // XIndexAccess
     184           0 : ::sal_Int32 SAL_CALL UnoControlTabPageContainerModel::getCount(  ) throw (uno::RuntimeException)
     185             : {
     186           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     187           0 :     return sal_Int32( m_aTabPageVector.size());
     188             : }
     189             : // -----------------------------------------------------------------------------
     190           0 : uno::Any SAL_CALL UnoControlTabPageContainerModel::getByIndex( ::sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
     191             : {
     192           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     193           0 :     if ( nIndex < 0 || nIndex > sal_Int32(m_aTabPageVector.size()) )
     194           0 :         throw lang::IndexOutOfBoundsException();
     195           0 :     return uno::makeAny(m_aTabPageVector[nIndex]);
     196             : }
     197             : // -----------------------------------------------------------------------------
     198             : // XElementAccess
     199           0 : uno::Type SAL_CALL UnoControlTabPageContainerModel::getElementType(  ) throw (uno::RuntimeException)
     200             : {
     201           0 :     return ::getCppuType(static_cast<  Reference< com::sun::star::awt::XControlModel>* >(NULL));
     202             : }
     203             : // -----------------------------------------------------------------------------
     204           0 : ::sal_Bool SAL_CALL UnoControlTabPageContainerModel::hasElements(  ) throw (uno::RuntimeException)
     205             : {
     206           0 :     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
     207           0 :     return !m_aTabPageVector.empty();
     208             : }
     209             : // XContainer
     210           0 : void UnoControlTabPageContainerModel::addContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException)
     211             : {
     212           0 :     maContainerListeners.addInterface( l );
     213           0 : }
     214             : 
     215           0 : void UnoControlTabPageContainerModel::removeContainerListener( const Reference< XContainerListener >& l ) throw(RuntimeException)
     216             : {
     217           0 :     maContainerListeners.removeInterface( l );
     218           0 : }
     219             : 
     220             : //  ----------------------------------------------------
     221             : //  class UnoControlTabPageContainer
     222             : //  ----------------------------------------------------
     223           0 : UnoControlTabPageContainer::UnoControlTabPageContainer( const Reference< XMultiServiceFactory >& i_factory )
     224             :     :UnoControlTabPageContainer_Base( i_factory )
     225           0 :     ,m_aTabPageListeners( *this )
     226             : {
     227           0 : }
     228             : 
     229           0 : OUString UnoControlTabPageContainer::GetComponentServiceName()
     230             : {
     231           0 :     return OUString(RTL_CONSTASCII_USTRINGPARAM("TabPageContainer"));
     232             : }
     233             : 
     234           0 : void SAL_CALL UnoControlTabPageContainer::dispose(  ) throw(RuntimeException)
     235             : {
     236           0 :     lang::EventObject aEvt;
     237           0 :     aEvt.Source = (::cppu::OWeakObject*)this;
     238           0 :     m_aTabPageListeners.disposeAndClear( aEvt );
     239           0 :     UnoControl::dispose();
     240           0 : }
     241             : 
     242           0 : void UnoControlTabPageContainer::createPeer( const uno::Reference< awt::XToolkit > & rxToolkit, const uno::Reference< awt::XWindowPeer >  & rParentPeer ) throw(uno::RuntimeException)
     243             : {
     244           0 :     UnoControlBase::createPeer( rxToolkit, rParentPeer );
     245             : 
     246           0 :     Reference< XTabPageContainer >  xTPContainer( getPeer(), UNO_QUERY_THROW );
     247           0 :     if ( m_aTabPageListeners.getLength() )
     248           0 :         xTPContainer->addTabPageContainerListener(&m_aTabPageListeners);
     249           0 : }
     250             : 
     251             : // -------------------------------------------------------------------
     252             : // XTabPageContainer
     253             : 
     254           0 : ::sal_Int16 SAL_CALL UnoControlTabPageContainer::getActiveTabPageID() throw (RuntimeException)
     255             : {
     256           0 :     SolarMutexGuard aSolarGuard;
     257           0 :     Reference< XTabPageContainer >  xTPContainer( getPeer(), UNO_QUERY_THROW );
     258           0 :     return xTPContainer->getActiveTabPageID();
     259             : }
     260           0 : void SAL_CALL UnoControlTabPageContainer::setActiveTabPageID( ::sal_Int16 _activetabpageid ) throw (RuntimeException)
     261             : {
     262           0 :     SolarMutexGuard aSolarGuard;
     263           0 :     Reference< XTabPageContainer >  xTPContainer( getPeer(), UNO_QUERY_THROW );
     264           0 :     xTPContainer->setActiveTabPageID(_activetabpageid);
     265           0 : }
     266           0 : ::sal_Int16 SAL_CALL UnoControlTabPageContainer::getTabPageCount(  ) throw (RuntimeException)
     267             : {
     268           0 :     SolarMutexGuard aSolarGuard;
     269           0 :     Reference< XTabPageContainer >  xTPContainer( getPeer(), UNO_QUERY_THROW );
     270           0 :     return xTPContainer->getTabPageCount();
     271             : }
     272           0 : ::sal_Bool SAL_CALL UnoControlTabPageContainer::isTabPageActive( ::sal_Int16 tabPageIndex ) throw (RuntimeException)
     273             : {
     274           0 :     SolarMutexGuard aSolarGuard;
     275           0 :     Reference< XTabPageContainer >  xTPContainer( getPeer(), UNO_QUERY_THROW );
     276           0 :     return xTPContainer->isTabPageActive(tabPageIndex);
     277             : }
     278           0 : Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex ) throw (RuntimeException)
     279             : {
     280           0 :     SolarMutexGuard aSolarGuard;
     281           0 :     Reference< XTabPageContainer >  xTPContainer( getPeer(), UNO_QUERY_THROW );
     282           0 :     return xTPContainer->getTabPage(tabPageIndex);
     283             : }
     284           0 : Reference< ::com::sun::star::awt::tab::XTabPage > SAL_CALL UnoControlTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID ) throw (RuntimeException)
     285             : {
     286           0 :     SolarMutexGuard aSolarGuard;
     287           0 :     Reference< XTabPageContainer >  xTPContainer( getPeer(), UNO_QUERY_THROW );
     288           0 :     return xTPContainer->getTabPageByID(tabPageID);
     289             : }
     290           0 : void SAL_CALL UnoControlTabPageContainer::addTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException)
     291             : {
     292           0 :     m_aTabPageListeners.addInterface( listener );
     293           0 :     if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
     294             :     {
     295           0 :         uno::Reference < awt::tab::XTabPageContainer >  xTabPageContainer( getPeer(), uno::UNO_QUERY );
     296           0 :         xTabPageContainer->addTabPageContainerListener( &m_aTabPageListeners );
     297             :     }
     298           0 : }
     299           0 : void SAL_CALL UnoControlTabPageContainer::removeTabPageContainerListener( const Reference< ::com::sun::star::awt::tab::XTabPageContainerListener >& listener ) throw (RuntimeException)
     300             : {
     301           0 :     if( getPeer().is() && m_aTabPageListeners.getLength() == 1 )
     302             :     {
     303           0 :         uno::Reference < awt::tab::XTabPageContainer >  xTabPageContainer( getPeer(), uno::UNO_QUERY );
     304           0 :         xTabPageContainer->addTabPageContainerListener( &m_aTabPageListeners );
     305             :     }
     306           0 :     m_aTabPageListeners.removeInterface( listener );
     307           0 : }
     308             : 
     309           0 : void UnoControlTabPageContainer::updateFromModel()
     310             : {
     311           0 :     UnoControlTabPageContainer_Base::updateFromModel();
     312           0 :     Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
     313           0 :     ENSURE_OR_RETURN_VOID( xContainerListener.is(), "UnoListBoxControl::updateFromModel: a peer which is no ItemListListener?!" );
     314             : 
     315           0 :     ContainerEvent aEvent;
     316           0 :     aEvent.Source = getModel();
     317           0 :     Sequence< Reference< XControl > > aControls = getControls();
     318           0 :     const Reference< XControl >* pCtrls = aControls.getConstArray();
     319           0 :     const Reference< XControl >* pCtrlsEnd = pCtrls + aControls.getLength();
     320             : 
     321           0 :     for ( ; pCtrls < pCtrlsEnd; ++pCtrls )
     322             :     {
     323           0 :         aEvent.Element <<= *pCtrls;
     324           0 :         xContainerListener->elementInserted( aEvent );
     325           0 :     }
     326             : }
     327           0 : void SAL_CALL UnoControlTabPageContainer::addControl( const ::rtl::OUString& Name, const Reference< ::com::sun::star::awt::XControl >& Control ) throw (RuntimeException)
     328             : {
     329           0 :     SolarMutexGuard aSolarGuard;
     330           0 :     ControlContainerBase::addControl(Name,Control);
     331           0 :     Reference< XContainerListener > xContainerListener( getPeer(), UNO_QUERY );
     332           0 :     ContainerEvent aEvent;
     333           0 :     aEvent.Source = getModel();
     334           0 :     aEvent.Element <<= Control;
     335           0 :     xContainerListener->elementInserted( aEvent );
     336           0 : }
     337             : 
     338             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10