LCOV - code coverage report
Current view: top level - libreoffice/framework/source/fwe/classes - actiontriggerpropertyset.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 156 0.0 %
Date: 2012-12-27 Functions: 0 20 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 <classes/actiontriggerpropertyset.hxx>
      22             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      23             : #include <cppuhelper/proptypehlp.hxx>
      24             : #include <cppuhelper/typeprovider.hxx>
      25             : #include <vcl/svapp.hxx>
      26             : 
      27             : 
      28             : using namespace cppu;
      29             : using namespace com::sun::star::uno;
      30             : using namespace com::sun::star::beans;
      31             : using namespace com::sun::star::lang;
      32             : using namespace com::sun::star::awt;
      33             : 
      34             : //struct SAL_DLLPUBLIC_IMPORT ::cppu::OBroadcastHelperVar< OMultiTypeInterfaceContainerHelper, OMultiTypeInterfaceContainerHelper::keyType >;
      35             : 
      36             : // Handles for properties
      37             : // (PLEASE SORT THIS FIELD, IF YOU ADD NEW PROPERTIES!)
      38             : // We use an enum to define these handles, to use all numbers from 0 to nn and
      39             : // if you add someone, you don't must control this!
      40             : // But don't forget to change values of follow defines, if you do something with this enum!
      41             : enum EPROPERTIES
      42             : {
      43             :     HANDLE_COMMANDURL,
      44             :     HANDLE_HELPURL,
      45             :     HANDLE_IMAGE,
      46             :     HANDLE_SUBCONTAINER,
      47             :     HANDLE_TEXT,
      48             :     PROPERTYCOUNT
      49             : };
      50             : 
      51             : namespace framework
      52             : {
      53             : 
      54           0 : ActionTriggerPropertySet::ActionTriggerPropertySet( const Reference< XMultiServiceFactory >& /*xServiceManager*/ )
      55           0 :     : ThreadHelpBase           ( &Application::GetSolarMutex()               )
      56           0 :     , OBroadcastHelper         ( m_aLock.getShareableOslMutex()              )
      57             :     ,   OPropertySetHelper       ( *(static_cast< OBroadcastHelper * >(this)))
      58             :     , OWeakObject              ()
      59             :     , m_xBitmap                ( 0 )
      60           0 :     , m_xActionTriggerContainer( 0 )
      61             : {
      62           0 : }
      63             : 
      64           0 : ActionTriggerPropertySet::~ActionTriggerPropertySet()
      65             : {
      66           0 : }
      67             : 
      68             : // XInterface
      69           0 : Any SAL_CALL ActionTriggerPropertySet::queryInterface( const Type& aType )
      70             : throw ( RuntimeException )
      71             : {
      72             :     Any a = ::cppu::queryInterface(
      73             :                 aType,
      74             :                 (static_cast< XServiceInfo* >(this)),
      75           0 :                 (static_cast< XTypeProvider* >(this)));
      76             : 
      77           0 :     if( a.hasValue() )
      78           0 :         return a;
      79             :     else
      80             :     {
      81           0 :         a = OPropertySetHelper::queryInterface( aType );
      82             : 
      83           0 :         if( a.hasValue() )
      84           0 :             return a;
      85             :     }
      86             : 
      87           0 :     return OWeakObject::queryInterface( aType );
      88             : }
      89             : 
      90           0 : void SAL_CALL ActionTriggerPropertySet::acquire() throw ()
      91             : {
      92           0 :     OWeakObject::acquire();
      93           0 : }
      94             : 
      95           0 : void SAL_CALL ActionTriggerPropertySet::release() throw ()
      96             : {
      97           0 :     OWeakObject::release();
      98           0 : }
      99             : 
     100             : 
     101             : // XServiceInfo
     102           0 : ::rtl::OUString SAL_CALL ActionTriggerPropertySet::getImplementationName()
     103             : throw ( RuntimeException )
     104             : {
     105           0 :     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( IMPLEMENTATIONNAME_ACTIONTRIGGER ));
     106             : }
     107             : 
     108           0 : sal_Bool SAL_CALL ActionTriggerPropertySet::supportsService( const ::rtl::OUString& ServiceName )
     109             : throw ( RuntimeException )
     110             : {
     111           0 :     if ( ServiceName.equalsAscii( SERVICENAME_ACTIONTRIGGER ))
     112           0 :         return sal_True;
     113             : 
     114           0 :     return sal_False;
     115             : }
     116             : 
     117           0 : Sequence< ::rtl::OUString > SAL_CALL ActionTriggerPropertySet::getSupportedServiceNames()
     118             : throw ( RuntimeException )
     119             : {
     120           0 :     Sequence< ::rtl::OUString > seqServiceNames( 1 );
     121           0 :     seqServiceNames[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SERVICENAME_ACTIONTRIGGER ));
     122           0 :     return seqServiceNames;
     123             : }
     124             : 
     125             : // XTypeProvider
     126           0 : Sequence< Type > SAL_CALL ActionTriggerPropertySet::getTypes() throw ( RuntimeException )
     127             : {
     128             :     // Optimize this method !
     129             :     // We initialize a static variable only one time. And we don't must use a mutex at every call!
     130             :     // For the first call; pTypeCollection is NULL - for the second call pTypeCollection is different from NULL!
     131             :     static ::cppu::OTypeCollection* pTypeCollection = NULL ;
     132             : 
     133           0 :     if ( pTypeCollection == NULL )
     134             :     {
     135             :         // Ready for multithreading; get global mutex for first call of this method only! see before
     136           0 :         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
     137             : 
     138             :         // Control these pointer again ... it can be, that another instance will be faster then these!
     139           0 :         if ( pTypeCollection == NULL )
     140             :         {
     141             :             // Create a static typecollection ...
     142             :             static ::cppu::OTypeCollection aTypeCollection(
     143           0 :                         ::getCppuType(( const Reference< XPropertySet           >*)NULL ) ,
     144           0 :                         ::getCppuType(( const Reference< XFastPropertySet       >*)NULL ) ,
     145           0 :                         ::getCppuType(( const Reference< XMultiPropertySet      >*)NULL ) ,
     146           0 :                         ::getCppuType(( const Reference< XServiceInfo           >*)NULL ) ,
     147           0 :                         ::getCppuType(( const Reference< XTypeProvider          >*)NULL ) ) ;
     148             : 
     149             :             // ... and set his address to static pointer!
     150           0 :             pTypeCollection = &aTypeCollection ;
     151           0 :         }
     152             :     }
     153             : 
     154           0 :     return pTypeCollection->getTypes() ;
     155             : }
     156             : 
     157           0 : Sequence< sal_Int8 > SAL_CALL ActionTriggerPropertySet::getImplementationId() throw ( RuntimeException )
     158             : {
     159             :     // Create one Id for all instances of this class.
     160             :     // Use ethernet address to do this! (sal_True)
     161             : 
     162             :     // Optimize this method
     163             :     // We initialize a static variable only one time. And we don't must use a mutex at every call!
     164             :     // For the first call; pID is NULL - for the second call pID is different from NULL!
     165             :     static ::cppu::OImplementationId* pID = NULL ;
     166             : 
     167           0 :     if ( pID == NULL )
     168             :     {
     169             :         // Ready for multithreading; get global mutex for first call of this method only! see before
     170           0 :         osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
     171             : 
     172             :         // Control these pointer again ... it can be, that another instance will be faster then these!
     173           0 :         if ( pID == NULL )
     174             :         {
     175             :             // Create a new static ID ...
     176           0 :             static ::cppu::OImplementationId aID( sal_False ) ;
     177             :             // ... and set his address to static pointer!
     178           0 :             pID = &aID ;
     179           0 :         }
     180             :     }
     181             : 
     182           0 :     return pID->getImplementationId() ;
     183             : }
     184             : 
     185             : //---------------------------------------------------------------------------------------------------------
     186             : //  OPropertySetHelper implementation
     187             : //---------------------------------------------------------------------------------------------------------
     188             : 
     189           0 : sal_Bool SAL_CALL ActionTriggerPropertySet::convertFastPropertyValue(
     190             :     Any&        aConvertedValue,
     191             :     Any&        aOldValue,
     192             :     sal_Int32   nHandle,
     193             :     const Any&  aValue  )
     194             : throw( IllegalArgumentException )
     195             : {
     196             :     //  Check, if value of property will changed in method "setFastPropertyValue_NoBroadcast()".
     197             :     //  Return sal_True, if changed - else return sal_False.
     198             :     //  Attention: Method "impl_tryToChangeProperty()" can throw the IllegalArgumentException !!!
     199             :     //  Initialize return value with sal_False !!!
     200             :     //  (Handle can be invalid)
     201           0 :     sal_Bool bReturn = sal_False;
     202             : 
     203           0 :     switch( nHandle )
     204             :     {
     205             :         case HANDLE_COMMANDURL:
     206           0 :             bReturn = impl_tryToChangeProperty( m_aCommandURL, aValue, aOldValue, aConvertedValue );
     207           0 :             break;
     208             : 
     209             :         case HANDLE_HELPURL:
     210           0 :             bReturn = impl_tryToChangeProperty( m_aHelpURL, aValue, aOldValue, aConvertedValue ) ;
     211           0 :             break;
     212             : 
     213             :         case HANDLE_IMAGE:
     214           0 :             bReturn = impl_tryToChangeProperty( m_xBitmap, aValue, aOldValue, aConvertedValue ) ;
     215           0 :             break;
     216             : 
     217             :         case HANDLE_SUBCONTAINER:
     218           0 :             bReturn = impl_tryToChangeProperty( m_xActionTriggerContainer, aValue, aOldValue, aConvertedValue );
     219           0 :             break;
     220             : 
     221             :         case HANDLE_TEXT:
     222           0 :             bReturn = impl_tryToChangeProperty( m_aText, aValue, aOldValue, aConvertedValue ) ;
     223           0 :             break;
     224             :     }
     225             : 
     226             :     // Return state of operation.
     227           0 :     return bReturn;
     228             : }
     229             : 
     230             : 
     231           0 : void SAL_CALL ActionTriggerPropertySet::setFastPropertyValue_NoBroadcast(
     232             :     sal_Int32 nHandle, const Any& aValue )
     233             : throw( Exception )
     234             : {
     235           0 :     ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
     236             : 
     237             :     // Search for right handle ... and try to set property value.
     238           0 :     switch( nHandle )
     239             :     {
     240             :         case HANDLE_COMMANDURL:
     241           0 :             aValue >>= m_aCommandURL;
     242           0 :             break;
     243             : 
     244             :         case HANDLE_HELPURL:
     245           0 :             aValue >>= m_aHelpURL;
     246           0 :             break;
     247             : 
     248             :         case HANDLE_IMAGE:
     249           0 :             aValue >>= m_xBitmap;
     250           0 :             break;
     251             : 
     252             :         case HANDLE_SUBCONTAINER:
     253           0 :             aValue >>= m_xActionTriggerContainer;
     254           0 :             break;
     255             : 
     256             :         case HANDLE_TEXT:
     257           0 :             aValue >>= m_aText;
     258           0 :             break;
     259           0 :     }
     260           0 : }
     261             : 
     262           0 : void SAL_CALL ActionTriggerPropertySet::getFastPropertyValue(
     263             :     Any& aValue, sal_Int32 nHandle ) const
     264             : {
     265           0 :     ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
     266             : 
     267             :     // Search for right handle ... and try to get property value.
     268           0 :     switch( nHandle )
     269             :     {
     270             :         case HANDLE_COMMANDURL:
     271           0 :             aValue <<= m_aCommandURL;
     272           0 :             break;
     273             : 
     274             :         case HANDLE_HELPURL:
     275           0 :             aValue <<= m_aHelpURL;
     276           0 :             break;
     277             : 
     278             :         case HANDLE_IMAGE:
     279           0 :             aValue <<= m_xBitmap;
     280           0 :             break;
     281             : 
     282             :         case HANDLE_SUBCONTAINER:
     283           0 :             aValue <<= m_xActionTriggerContainer;
     284           0 :             break;
     285             : 
     286             :         case HANDLE_TEXT:
     287           0 :             aValue <<= m_aText;
     288           0 :             break;
     289           0 :     }
     290           0 : }
     291             : 
     292           0 : ::cppu::IPropertyArrayHelper& SAL_CALL ActionTriggerPropertySet::getInfoHelper()
     293             : {
     294             :     // Optimize this method !
     295             :     // We initialize a static variable only one time. And we don't must use a mutex at every call!
     296             :     // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
     297             :     static OPropertyArrayHelper* pInfoHelper = NULL;
     298             : 
     299           0 :     if( pInfoHelper == NULL )
     300             :     {
     301             :         // Ready for multithreading
     302           0 :         ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
     303             :         // Control this pointer again, another instance can be faster then these!
     304           0 :         if( pInfoHelper == NULL )
     305             :         {
     306             :             // Define static member to give structure of properties to baseclass "OPropertySetHelper".
     307             :             // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
     308             :             // "sal_True" say: Table is sorted by name.
     309           0 :             static OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
     310           0 :             pInfoHelper = &aInfoHelper;
     311           0 :         }
     312             :     }
     313             : 
     314           0 :     return (*pInfoHelper);
     315             : }
     316             : 
     317           0 : Reference< XPropertySetInfo > SAL_CALL ActionTriggerPropertySet::getPropertySetInfo()
     318             : throw ( RuntimeException )
     319             : {
     320             :     // Optimize this method !
     321             :     // We initialize a static variable only one time. And we don't must use a mutex at every call!
     322             :     // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
     323             :     static Reference< XPropertySetInfo >* pInfo = NULL ;
     324             : 
     325           0 :     if( pInfo == NULL )
     326             :     {
     327             :         // Ready for multithreading
     328           0 :         ::osl::MutexGuard aGuard( LockHelper::getGlobalLock().getShareableOslMutex() );
     329             :         // Control this pointer again, another instance can be faster then these!
     330           0 :         if( pInfo == NULL )
     331             :         {
     332             :             // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
     333             :             // (Use method "getInfoHelper()".)
     334           0 :             static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
     335           0 :             pInfo = &xInfo;
     336           0 :         }
     337             :     }
     338             : 
     339           0 :     return (*pInfo);
     340             : }
     341             : 
     342           0 : const Sequence< Property > ActionTriggerPropertySet::impl_getStaticPropertyDescriptor()
     343             : {
     344             :     const Property pActionTriggerPropertys[] =
     345             :     {
     346           0 :         Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CommandURL"    )), HANDLE_COMMANDURL   , ::getCppuType((::rtl::OUString*)0)                , PropertyAttribute::TRANSIENT  ),
     347           0 :         Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpURL"       )), HANDLE_HELPURL      , ::getCppuType((::rtl::OUString*)0)                , PropertyAttribute::TRANSIENT  ),
     348           0 :         Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Image"        )), HANDLE_IMAGE     , ::getCppuType((Reference<XBitmap>*)0)     , PropertyAttribute::TRANSIENT  ),
     349           0 :         Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SubContainer"  )), HANDLE_SUBCONTAINER , ::getCppuType((::rtl::OUString*)0)                , PropertyAttribute::TRANSIENT  ),
     350           0 :         Property( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text"          )), HANDLE_TEXT         , ::getCppuType((Reference<XInterface>*)0)  , PropertyAttribute::TRANSIENT  )
     351           0 :     };
     352             : 
     353             :     // Use it to initialize sequence!
     354           0 :     const Sequence< Property > seqActionTriggerPropertyDescriptor( pActionTriggerPropertys, PROPERTYCOUNT );
     355             : 
     356             :     // Return "PropertyDescriptor"
     357           0 :     return seqActionTriggerPropertyDescriptor ;
     358             : }
     359             : 
     360             : 
     361             : //******************************************************************************************************************************
     362             : //  private method
     363             : //******************************************************************************************************************************
     364           0 : sal_Bool ActionTriggerPropertySet::impl_tryToChangeProperty(
     365             :     const   ::rtl::OUString&    sCurrentValue   ,
     366             :     const   Any&        aNewValue       ,
     367             :     Any&        aOldValue       ,
     368             :     Any&        aConvertedValue )
     369             : throw( IllegalArgumentException )
     370             : {
     371             :     // Set default return value if method failed.
     372           0 :     sal_Bool bReturn = sal_False;
     373             :     // Get new value from any.
     374             :     // IllegalArgumentException() can be thrown!
     375           0 :     ::rtl::OUString sValue ;
     376           0 :     convertPropertyValue( sValue, aNewValue );
     377             : 
     378             :     // If value change ...
     379           0 :     if( sValue != sCurrentValue )
     380             :     {
     381             :         // ... set information of change.
     382           0 :         aOldValue       <<= sCurrentValue   ;
     383           0 :         aConvertedValue <<= sValue          ;
     384             :         // Return OK - "value will be change ..."
     385           0 :         bReturn = sal_True;
     386             :     }
     387             :     else
     388             :     {
     389             :         // ... clear information of return parameter!
     390           0 :         aOldValue.clear         () ;
     391           0 :         aConvertedValue.clear   () ;
     392             :         // Return NOTHING - "value will not be change ..."
     393           0 :         bReturn = sal_False;
     394             :     }
     395             : 
     396           0 :     return bReturn;
     397             : }
     398             : 
     399             : 
     400           0 : sal_Bool ActionTriggerPropertySet::impl_tryToChangeProperty(
     401             :     const Reference< XBitmap >  aCurrentValue   ,
     402             :     const Any&                  aNewValue       ,
     403             :     Any&                        aOldValue       ,
     404             :     Any&                        aConvertedValue )
     405             : throw( IllegalArgumentException )
     406             : {
     407             :     // Set default return value if method failed.
     408           0 :     sal_Bool bReturn = sal_False;
     409             :     // Get new value from any.
     410             :     // IllegalArgumentException() can be thrown!
     411           0 :     Reference< XBitmap > aValue ;
     412           0 :     convertPropertyValue( aValue, aNewValue );
     413             : 
     414             :     // If value change ...
     415           0 :     if( aValue != aCurrentValue )
     416             :     {
     417             :         // ... set information of change.
     418           0 :         aOldValue       <<= aCurrentValue   ;
     419           0 :         aConvertedValue <<= aValue          ;
     420             :         // Return OK - "value will be change ..."
     421           0 :         bReturn = sal_True;
     422             :     }
     423             :     else
     424             :     {
     425             :         // ... clear information of return parameter!
     426           0 :         aOldValue.clear         () ;
     427           0 :         aConvertedValue.clear   () ;
     428             :         // Return NOTHING - "value will not be change ..."
     429           0 :         bReturn = sal_False;
     430             :     }
     431             : 
     432           0 :     return bReturn;
     433             : }
     434             : 
     435           0 : sal_Bool ActionTriggerPropertySet::impl_tryToChangeProperty(
     436             :     const Reference< XInterface >   aCurrentValue   ,
     437             :     const Any&                      aNewValue       ,
     438             :     Any&                            aOldValue       ,
     439             :     Any&                            aConvertedValue )
     440             : throw( IllegalArgumentException )
     441             : {
     442             :     // Set default return value if method failed.
     443           0 :     sal_Bool bReturn = sal_False;
     444             :     // Get new value from any.
     445             :     // IllegalArgumentException() can be thrown!
     446           0 :     Reference< XInterface > aValue ;
     447           0 :     convertPropertyValue( aValue, aNewValue );
     448             : 
     449             :     // If value change ...
     450           0 :     if( aValue != aCurrentValue )
     451             :     {
     452             :         // ... set information of change.
     453           0 :         aOldValue       <<= aCurrentValue   ;
     454           0 :         aConvertedValue <<= aValue          ;
     455             :         // Return OK - "value will be change ..."
     456           0 :         bReturn = sal_True;
     457             :     }
     458             :     else
     459             :     {
     460             :         // ... clear information of return parameter!
     461           0 :         aOldValue.clear         () ;
     462           0 :         aConvertedValue.clear   () ;
     463             :         // Return NOTHING - "value will not be change ..."
     464           0 :         bReturn = sal_False;
     465             :     }
     466             : 
     467           0 :     return bReturn;
     468             : }
     469             : 
     470             : }
     471             : 
     472             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10