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

Generated by: LCOV version 1.10