LCOV - code coverage report
Current view: top level - framework/source/helper - uielementwrapperbase.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 48 80 60.0 %
Date: 2014-04-11 Functions: 7 18 38.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <helper/uielementwrapperbase.hxx>
      21             : #include <general.h>
      22             : #include <properties.h>
      23             : 
      24             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      25             : #include <com/sun/star/beans/PropertyValue.hpp>
      26             : #include <com/sun/star/beans/XPropertySet.hpp>
      27             : 
      28             : #include <vcl/svapp.hxx>
      29             : #include <comphelper/sequence.hxx>
      30             : 
      31             : const int UIELEMENT_PROPHANDLE_RESOURCEURL  = 1;
      32             : const int UIELEMENT_PROPHANDLE_TYPE         = 2;
      33             : const int UIELEMENT_PROPHANDLE_FRAME        = 3;
      34             : const int UIELEMENT_PROPCOUNT               = 3;
      35             : const char UIELEMENT_PROPNAME_RESOURCEURL[] = "ResourceURL";
      36             : const char UIELEMENT_PROPNAME_TYPE[] = "Type";
      37             : const char UIELEMENT_PROPNAME_FRAME[] = "Frame";
      38             : 
      39             : using namespace ::com::sun::star::uno;
      40             : using namespace ::com::sun::star::beans;
      41             : using namespace ::com::sun::star::frame;
      42             : 
      43             : namespace framework
      44             : {
      45             : 
      46        3808 : UIElementWrapperBase::UIElementWrapperBase( sal_Int16 nType )
      47             :     :   ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aMutex )
      48             :     ,   ::cppu::OPropertySetHelper  ( *(static_cast< ::cppu::OBroadcastHelper* >(this)) )
      49             :     ,   m_aListenerContainer        ( m_aMutex )
      50             :     ,   m_nType                     ( nType                                             )
      51             :     ,   m_bInitialized              ( false                                         )
      52        3808 :     ,   m_bDisposed                 ( false                                         )
      53             : {
      54        3808 : }
      55             : 
      56        3794 : UIElementWrapperBase::~UIElementWrapperBase()
      57             : {
      58        3794 : }
      59             : 
      60       67947 : Any SAL_CALL UIElementWrapperBase::queryInterface( const Type& _rType ) throw(RuntimeException, std::exception)
      61             : {
      62       67947 :     Any aRet = UIElementWrapperBase_BASE::queryInterface( _rType );
      63       67947 :     if ( !aRet.hasValue() )
      64           1 :         aRet = OPropertySetHelper::queryInterface( _rType );
      65       67947 :     return aRet;
      66             : }
      67             : 
      68           0 : Sequence< Type > SAL_CALL UIElementWrapperBase::getTypes(  ) throw(RuntimeException, std::exception)
      69             : {
      70             :     return comphelper::concatSequences(
      71             :         UIElementWrapperBase_BASE::getTypes(),
      72             :         ::cppu::OPropertySetHelper::getTypes()
      73           0 :     );
      74             : }
      75             : 
      76           0 : void SAL_CALL UIElementWrapperBase::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception)
      77             : {
      78           0 :     m_aListenerContainer.addInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), xListener );
      79           0 : }
      80             : 
      81           0 : void SAL_CALL UIElementWrapperBase::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception)
      82             : {
      83           0 :     m_aListenerContainer.removeInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), xListener );
      84           0 : }
      85             : 
      86        1731 : void SAL_CALL UIElementWrapperBase::initialize( const Sequence< Any >& aArguments )
      87             : throw ( Exception, RuntimeException, std::exception )
      88             : {
      89        1731 :     SolarMutexGuard g;
      90             : 
      91        1731 :     if ( !m_bInitialized )
      92             :     {
      93        6924 :         for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ )
      94             :         {
      95        5193 :             PropertyValue aPropValue;
      96        5193 :             if ( aArguments[n] >>= aPropValue )
      97             :             {
      98        5193 :                 if ( aPropValue.Name == "ResourceURL" )
      99        1731 :                     aPropValue.Value >>= m_aResourceURL;
     100        3462 :                 else if ( aPropValue.Name == "Frame" )
     101             :                 {
     102        1731 :                     Reference< XFrame > xFrame;
     103        1731 :                     aPropValue.Value >>= xFrame;
     104        1731 :                     m_xWeakFrame = xFrame;
     105             :                 }
     106             :             }
     107        5193 :         }
     108             : 
     109        1731 :         m_bInitialized = true;
     110        1731 :     }
     111        1731 : }
     112             : 
     113             : // XUIElement
     114           0 : ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SAL_CALL UIElementWrapperBase::getFrame() throw (::com::sun::star::uno::RuntimeException, std::exception)
     115             : {
     116           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( m_xWeakFrame );
     117           0 :     return xFrame;
     118             : }
     119             : 
     120           0 : OUString SAL_CALL UIElementWrapperBase::getResourceURL() throw (::com::sun::star::uno::RuntimeException, std::exception)
     121             : {
     122           0 :     return m_aResourceURL;
     123             : }
     124             : 
     125           0 : ::sal_Int16 SAL_CALL UIElementWrapperBase::getType() throw (::com::sun::star::uno::RuntimeException, std::exception)
     126             : {
     127           0 :     return m_nType;
     128             : }
     129             : 
     130             : // XUpdatable
     131           0 : void SAL_CALL UIElementWrapperBase::update() throw (::com::sun::star::uno::RuntimeException, std::exception)
     132             : {
     133             :     // can be implemented by derived class
     134           0 : }
     135             : 
     136             : // XPropertySet helper
     137           0 : sal_Bool SAL_CALL UIElementWrapperBase::convertFastPropertyValue( Any&       /*aConvertedValue*/ ,
     138             :                                                                   Any&       /*aOldValue*/       ,
     139             :                                                                   sal_Int32  /*nHandle*/         ,
     140             :                                                                   const Any& /*aValue*/             ) throw( com::sun::star::lang::IllegalArgumentException )
     141             : {
     142             :     //  Initialize state with sal_False !!!
     143             :     //  (Handle can be invalid)
     144           0 :     return sal_False;
     145             : }
     146             : 
     147           0 : void SAL_CALL UIElementWrapperBase::setFastPropertyValue_NoBroadcast(   sal_Int32               /*nHandle*/ ,
     148             :                                                                         const com::sun::star::uno::Any&    /*aValue*/  ) throw( com::sun::star::uno::Exception, std::exception )
     149             : {
     150           0 : }
     151             : 
     152           2 : void SAL_CALL UIElementWrapperBase::getFastPropertyValue( com::sun::star::uno::Any& aValue  ,
     153             :                                                           sal_Int32      nHandle                ) const
     154             : {
     155           2 :     switch( nHandle )
     156             :     {
     157             :         case UIELEMENT_PROPHANDLE_RESOURCEURL:
     158           1 :             aValue <<= m_aResourceURL;
     159           1 :             break;
     160             :         case UIELEMENT_PROPHANDLE_TYPE:
     161           1 :             aValue <<= m_nType;
     162           1 :             break;
     163             :         case UIELEMENT_PROPHANDLE_FRAME:
     164           0 :             Reference< XFrame > xFrame( m_xWeakFrame );
     165           0 :             aValue <<= xFrame;
     166           0 :             break;
     167             :     }
     168           2 : }
     169             : 
     170           4 : ::cppu::IPropertyArrayHelper& SAL_CALL UIElementWrapperBase::getInfoHelper()
     171             : {
     172             :     // Optimize this method !
     173             :     // We initialize a static variable only one time. And we don't must use a mutex at every call!
     174             :     // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
     175             :     static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL;
     176             : 
     177           4 :     if( pInfoHelper == NULL )
     178             :     {
     179             :         // Ready for multithreading
     180           1 :         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
     181             : 
     182             :         // Control this pointer again, another instance can be faster then these!
     183           1 :         if( pInfoHelper == NULL )
     184             :         {
     185             :             // Define static member to give structure of properties to baseclass "OPropertySetHelper".
     186             :             // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
     187             :             // "sal_True" say: Table is sorted by name.
     188           1 :             static ::cppu::OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
     189           1 :             pInfoHelper = &aInfoHelper;
     190           1 :         }
     191             :     }
     192             : 
     193           4 :     return(*pInfoHelper);
     194             : }
     195             : 
     196           0 : com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL UIElementWrapperBase::getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException, std::exception)
     197             : {
     198             :     // Optimize this method !
     199             :     // We initialize a static variable only one time. And we don't must use a mutex at every call!
     200             :     // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
     201             :     static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >* pInfo = NULL;
     202             : 
     203           0 :     if( pInfo == NULL )
     204             :     {
     205             :         // Ready for multithreading
     206           0 :         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
     207             :         // Control this pointer again, another instance can be faster then these!
     208           0 :         if( pInfo == NULL )
     209             :         {
     210             :             // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
     211             :             // (Use method "getInfoHelper()".)
     212           0 :             static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
     213           0 :             pInfo = &xInfo;
     214           0 :         }
     215             :     }
     216             : 
     217           0 :     return (*pInfo);
     218             : }
     219             : 
     220           1 : const com::sun::star::uno::Sequence< com::sun::star::beans::Property > UIElementWrapperBase::impl_getStaticPropertyDescriptor()
     221             : {
     222             :     // Create a property array to initialize sequence!
     223             :     // Table of all predefined properties of this class. Its used from OPropertySetHelper-class!
     224             :     // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
     225             :     // It's necessary for methods of OPropertySetHelper.
     226             :     // ATTENTION:
     227             :     //      YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
     228             : 
     229             :     const com::sun::star::beans::Property pProperties[] =
     230             :     {
     231           1 :         com::sun::star::beans::Property( OUString(UIELEMENT_PROPNAME_FRAME), UIELEMENT_PROPHANDLE_FRAME          , ::getCppuType((Reference< XFrame >*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ),
     232           1 :         com::sun::star::beans::Property( OUString(UIELEMENT_PROPNAME_RESOURCEURL), UIELEMENT_PROPHANDLE_RESOURCEURL    , ::getCppuType((sal_Int16*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ),
     233           1 :         com::sun::star::beans::Property( OUString(UIELEMENT_PROPNAME_TYPE), UIELEMENT_PROPHANDLE_TYPE           , ::getCppuType((const OUString*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY )
     234           7 :     };
     235             :     // Use it to initialize sequence!
     236           1 :     const com::sun::star::uno::Sequence< com::sun::star::beans::Property > lPropertyDescriptor( pProperties, UIELEMENT_PROPCOUNT );
     237             :     // Return "PropertyDescriptor"
     238           4 :     return lPropertyDescriptor;
     239             : }
     240             : 
     241             : }
     242             : 
     243             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10