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

Generated by: LCOV version 1.10