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

Generated by: LCOV version 1.10