LCOV - code coverage report
Current view: top level - forms/source/component - Time.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 90 143 62.9 %
Date: 2012-08-25 Functions: 21 27 77.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 52 171 30.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "Time.hxx"
      30                 :            : #include <tools/debug.hxx>
      31                 :            : #include <tools/time.hxx>
      32                 :            : #include <connectivity/dbconversion.hxx>
      33                 :            : #include <com/sun/star/sdbc/DataType.hpp>
      34                 :            : 
      35                 :            : using namespace dbtools;
      36                 :            : 
      37                 :            : //.........................................................................
      38                 :            : namespace frm
      39                 :            : {
      40                 :            : //.........................................................................
      41                 :            : 
      42                 :            : using namespace ::com::sun::star;
      43                 :            : using namespace ::com::sun::star::uno;
      44                 :            : using namespace ::com::sun::star::sdb;
      45                 :            : using namespace ::com::sun::star::sdbc;
      46                 :            : using namespace ::com::sun::star::sdbcx;
      47                 :            : using namespace ::com::sun::star::beans;
      48                 :            : using namespace ::com::sun::star::container;
      49                 :            : using namespace ::com::sun::star::form;
      50                 :            : using namespace ::com::sun::star::util;
      51                 :            : using namespace ::com::sun::star::awt;
      52                 :            : using namespace ::com::sun::star::io;
      53                 :            : using namespace ::com::sun::star::lang;
      54                 :            : 
      55                 :            : //==================================================================
      56                 :            : //=
      57                 :            : //==================================================================
      58                 :            : 
      59                 :            : //==================================================================
      60                 :            : //= OTimeControl
      61                 :            : //==================================================================
      62                 :            : //------------------------------------------------------------------
      63                 :         12 : OTimeControl::OTimeControl(const Reference<XMultiServiceFactory>& _rxFactory)
      64         [ +  - ]:         12 :                :OBoundControl(_rxFactory, VCL_CONTROL_TIMEFIELD)
      65                 :            : {
      66                 :         12 : }
      67                 :            : 
      68                 :            : //------------------------------------------------------------------
      69                 :         12 : InterfaceRef SAL_CALL OTimeControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      70                 :            : {
      71         [ +  - ]:         12 :     return *(new OTimeControl(_rxFactory));
      72                 :            : }
      73                 :            : 
      74                 :            : //------------------------------------------------------------------------------
      75                 :          0 : Sequence<Type> OTimeControl::_getTypes()
      76                 :            : {
      77                 :          0 :     return OBoundControl::_getTypes();
      78                 :            : }
      79                 :            : 
      80                 :            : //------------------------------------------------------------------------------
      81                 :          0 : StringSequence SAL_CALL OTimeControl::getSupportedServiceNames() throw()
      82                 :            : {
      83                 :          0 :     StringSequence aSupported = OBoundControl::getSupportedServiceNames();
      84         [ #  # ]:          0 :     aSupported.realloc(aSupported.getLength() + 1);
      85                 :            : 
      86         [ #  # ]:          0 :     ::rtl::OUString*pArray = aSupported.getArray();
      87         [ #  # ]:          0 :     pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_TIMEFIELD;
      88                 :          0 :     return aSupported;
      89                 :            : }
      90                 :            : 
      91                 :            : //==================================================================
      92                 :            : //= OTimeModel
      93                 :            : //==================================================================
      94                 :            : //------------------------------------------------------------------
      95                 :         17 : InterfaceRef SAL_CALL OTimeModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      96                 :            : {
      97         [ +  - ]:         17 :     return *(new OTimeModel(_rxFactory));
      98                 :            : }
      99                 :            : 
     100                 :            : // XServiceInfo
     101                 :            : //------------------------------------------------------------------------------
     102                 :         14 : StringSequence SAL_CALL OTimeModel::getSupportedServiceNames() throw()
     103                 :            : {
     104                 :         14 :     StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
     105                 :            : 
     106                 :         14 :     sal_Int32 nOldLen = aSupported.getLength();
     107         [ +  - ]:         14 :     aSupported.realloc( nOldLen + 8 );
     108         [ +  - ]:         14 :     ::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen;
     109                 :            : 
     110         [ +  - ]:         14 :     *pStoreTo++ = BINDABLE_CONTROL_MODEL;
     111         [ +  - ]:         14 :     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
     112         [ +  - ]:         14 :     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
     113                 :            : 
     114         [ +  - ]:         14 :     *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
     115         [ +  - ]:         14 :     *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
     116                 :            : 
     117         [ +  - ]:         14 :     *pStoreTo++ = FRM_SUN_COMPONENT_TIMEFIELD;
     118         [ +  - ]:         14 :     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_TIMEFIELD;
     119         [ +  - ]:         14 :     *pStoreTo++ = BINDABLE_DATABASE_TIME_FIELD;
     120                 :            : 
     121                 :         14 :     return aSupported;
     122                 :            : }
     123                 :            : 
     124                 :            : //------------------------------------------------------------------------------
     125                 :          4 : Sequence<Type> OTimeModel::_getTypes()
     126                 :            : {
     127                 :          4 :     return OBoundControlModel::_getTypes();
     128                 :            : }
     129                 :            : 
     130                 :            : //------------------------------------------------------------------
     131                 :            : DBG_NAME( OTimeModel )
     132                 :            : //------------------------------------------------------------------
     133                 :         17 : OTimeModel::OTimeModel(const Reference<XMultiServiceFactory>& _rxFactory)
     134                 :            :             :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_TIMEFIELD, FRM_SUN_CONTROL_TIMEFIELD, sal_True, sal_True )
     135                 :            :                                     // use the old control name for compytibility reasons
     136 [ +  - ][ +  - ]:         17 :             ,OLimitedFormats(_rxFactory, FormComponentType::TIMEFIELD)
                 [ +  - ]
     137                 :            : {
     138                 :            :     DBG_CTOR( OTimeModel, NULL );
     139                 :            : 
     140                 :         17 :     m_nClassId = FormComponentType::TIMEFIELD;
     141 [ +  - ][ +  - ]:         17 :     initValueProperty( PROPERTY_TIME, PROPERTY_ID_TIME );
     142                 :            : 
     143 [ +  - ][ +  - ]:         17 :     setAggregateSet(m_xAggregateFastSet, getOriginalHandle(PROPERTY_ID_TIMEFORMAT));
     144                 :         17 : }
     145                 :            : 
     146                 :            : //------------------------------------------------------------------------------
     147                 :          2 : OTimeModel::OTimeModel( const OTimeModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
     148                 :            :     :OEditBaseModel( _pOriginal, _rxFactory )
     149         [ +  - ]:          2 :     ,OLimitedFormats( _rxFactory, FormComponentType::TIMEFIELD )
     150                 :            : {
     151                 :            :     DBG_CTOR( OTimeModel, NULL );
     152                 :            : 
     153 [ +  - ][ +  - ]:          2 :     setAggregateSet( m_xAggregateFastSet, getOriginalHandle( PROPERTY_ID_TIMEFORMAT ) );
     154                 :          2 : }
     155                 :            : 
     156                 :            : //------------------------------------------------------------------------------
     157         [ +  - ]:         19 : OTimeModel::~OTimeModel( )
     158                 :            : {
     159         [ +  - ]:         19 :     setAggregateSet(Reference< XFastPropertySet >(), -1);
     160                 :            :     DBG_DTOR( OTimeModel, NULL );
     161         [ -  + ]:         38 : }
     162                 :            : 
     163                 :            : // XCloneable
     164                 :            : //------------------------------------------------------------------------------
     165 [ +  - ][ +  - ]:          2 : IMPLEMENT_DEFAULT_CLONING( OTimeModel )
     166                 :            : 
     167                 :            : //------------------------------------------------------------------------------
     168                 :          2 : ::rtl::OUString SAL_CALL OTimeModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
     169                 :            : {
     170                 :          2 :     return FRM_COMPONENT_TIMEFIELD; // old (non-sun) name for compatibility !
     171                 :            : }
     172                 :            : 
     173                 :            : // XPropertySet
     174                 :            : //------------------------------------------------------------------------------
     175                 :         23 : void OTimeModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     176                 :            : {
     177                 :         23 :     BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel )
     178 [ +  - ][ +  - ]:         23 :         DECL_PROP3(DEFAULT_TIME,            sal_Int32,              BOUND, MAYBEDEFAULT, MAYBEVOID);
     179         [ +  - ]:         23 :         DECL_PROP1(TABINDEX,                sal_Int16,              BOUND);
     180         [ +  - ]:         23 :         DECL_PROP1(FORMATKEY,               sal_Int32,              TRANSIENT);
     181 [ +  - ][ +  - ]:         23 :         DECL_IFACE_PROP2(FORMATSSUPPLIER,   XNumberFormatsSupplier, READONLY, TRANSIENT);
     182                 :            :     END_DESCRIBE_PROPERTIES();
     183                 :         23 : }
     184                 :            : 
     185                 :            : //------------------------------------------------------------------------------
     186                 :       7780 : void SAL_CALL OTimeModel::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle ) const
     187                 :            : {
     188      [ +  +  + ]:       7780 :     switch (_nHandle)
     189                 :            :     {
     190                 :            :         case PROPERTY_ID_FORMATKEY:
     191                 :         46 :             getFormatKeyPropertyValue(_rValue);
     192                 :         46 :             break;
     193                 :            :         case PROPERTY_ID_FORMATSSUPPLIER:
     194         [ +  - ]:         44 :             _rValue <<= getFormatsSupplier();
     195                 :         44 :             break;
     196                 :            :         default:
     197                 :       7690 :             OEditBaseModel::getFastPropertyValue(_rValue, _nHandle);
     198                 :       7690 :             break;
     199                 :            :     }
     200                 :       7780 : }
     201                 :            : 
     202                 :            : //------------------------------------------------------------------------------
     203                 :        677 : sal_Bool SAL_CALL OTimeModel::convertFastPropertyValue(Any& _rConvertedValue, Any& _rOldValue,
     204                 :            :         sal_Int32 _nHandle, const Any& _rValue ) throw(IllegalArgumentException)
     205                 :            : {
     206         [ +  + ]:        677 :     if (PROPERTY_ID_FORMATKEY == _nHandle)
     207                 :          2 :         return convertFormatKeyPropertyValue(_rConvertedValue, _rOldValue, _rValue);
     208                 :            :     else
     209                 :        675 :         return OEditBaseModel::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue );
     210                 :            : }
     211                 :            : 
     212                 :            : //------------------------------------------------------------------------------
     213                 :        147 : void SAL_CALL OTimeModel::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw ( ::com::sun::star::uno::Exception)
     214                 :            : {
     215         [ -  + ]:        147 :     if (PROPERTY_ID_FORMATKEY == _nHandle)
     216                 :          0 :         setFormatKeyPropertyValue(_rValue);
     217                 :            :     else
     218                 :        147 :         OEditBaseModel::setFastPropertyValue_NoBroadcast(_nHandle, _rValue);
     219                 :        147 : }
     220                 :            : 
     221                 :            : // XLoadListener
     222                 :            : //------------------------------------------------------------------------------
     223                 :          0 : void OTimeModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
     224                 :            : {
     225         [ #  # ]:          0 :     OBoundControlModel::onConnectedDbColumn( _rxForm );
     226                 :          0 :     Reference<XPropertySet> xField = getField();
     227         [ #  # ]:          0 :     if (xField.is())
     228                 :            :     {
     229                 :          0 :         m_bDateTimeField = sal_False;
     230                 :            :         try
     231                 :            :         {
     232                 :          0 :             sal_Int32 nFieldType = 0;
     233 [ #  # ][ #  # ]:          0 :             xField->getPropertyValue(PROPERTY_FIELDTYPE) >>= nFieldType;
         [ #  # ][ #  # ]
     234                 :          0 :             m_bDateTimeField = (nFieldType == DataType::TIMESTAMP);
     235                 :            :         }
     236         [ #  # ]:          0 :         catch(const Exception&)
     237                 :            :         {
     238                 :            :         }
     239                 :          0 :     }
     240                 :          0 : }
     241                 :            : 
     242                 :            : //------------------------------------------------------------------------------
     243                 :          0 : sal_Bool OTimeModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
     244                 :            : {
     245 [ #  # ][ #  # ]:          0 :     Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
     246 [ #  # ][ #  # ]:          0 :     if ( !compare( aControlValue, m_aSaveValue ) )
     247                 :            :     {
     248         [ #  # ]:          0 :         if ( !aControlValue.hasValue() )
     249 [ #  # ][ #  # ]:          0 :             m_xColumnUpdate->updateNull();
     250                 :            :         else
     251                 :            :         {
     252                 :            :             try
     253                 :            :             {
     254                 :          0 :                 util::Time aTime;
     255 [ #  # ][ #  # ]:          0 :                 if ( !( aControlValue >>= aTime ) )
     256                 :            :                 {
     257                 :          0 :                     sal_Int32 nAsInt(0);
     258                 :          0 :                     aControlValue >>= nAsInt;
     259         [ #  # ]:          0 :                     aTime = DBTypeConversion::toTime(nAsInt);
     260                 :            :                 }
     261                 :            : 
     262         [ #  # ]:          0 :                 if (!m_bDateTimeField)
     263 [ #  # ][ #  # ]:          0 :                     m_xColumnUpdate->updateTime(aTime);
     264                 :            :                 else
     265                 :            :                 {
     266 [ #  # ][ #  # ]:          0 :                     util::DateTime aDateTime = m_xColumn->getTimestamp();
     267                 :          0 :                     aDateTime.HundredthSeconds = aTime.HundredthSeconds;
     268                 :          0 :                     aDateTime.Seconds = aTime.Seconds;
     269                 :          0 :                     aDateTime.Minutes = aTime.Minutes;
     270                 :          0 :                     aDateTime.Hours = aTime.Hours;
     271 [ #  # ][ #  # ]:          0 :                     m_xColumnUpdate->updateTimestamp(aDateTime);
     272                 :            :                 }
     273                 :            :             }
     274         [ #  # ]:          0 :             catch(const Exception&)
     275                 :            :             {
     276                 :          0 :                 return sal_False;
     277                 :            :             }
     278                 :            :         }
     279                 :          0 :         m_aSaveValue = aControlValue;
     280                 :            :     }
     281         [ #  # ]:          0 :     return sal_True;
     282                 :            : }
     283                 :            : 
     284                 :            : //------------------------------------------------------------------------------
     285                 :         12 : void OTimeModel::impl_translateControlValueToUNOTime( Any& _rUNOValue ) const
     286                 :            : {
     287                 :         12 :     _rUNOValue = getControlValue();
     288         [ +  + ]:         12 :     if ( _rUNOValue.hasValue() )
     289                 :            :     {
     290                 :          2 :         sal_Int32 nTime = 0;
     291                 :          2 :         OSL_VERIFY( _rUNOValue >>= nTime );
     292 [ -  + ][ +  - ]:          2 :         if ( nTime == ::Time( 99, 99, 99 ).GetTime() )
     293                 :            :             // "invalid time" in VCL is different from "invalid time" in UNO
     294                 :          0 :             _rUNOValue.clear();
     295                 :            :         else
     296 [ +  - ][ +  - ]:          2 :             _rUNOValue <<= DBTypeConversion::toTime( nTime );
     297                 :            :     }
     298                 :         12 : }
     299                 :            : 
     300                 :            : //------------------------------------------------------------------------------
     301                 :          0 : Any OTimeModel::translateControlValueToExternalValue( ) const
     302                 :            : {
     303                 :          0 :     Any aExternalValue;
     304         [ #  # ]:          0 :     impl_translateControlValueToUNOTime( aExternalValue );
     305                 :          0 :     return aExternalValue;
     306                 :            : }
     307                 :            : 
     308                 :            : //------------------------------------------------------------------------------
     309                 :          4 : Any OTimeModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
     310                 :            : {
     311                 :          4 :     Any aControlValue;
     312         [ +  - ]:          4 :     if ( _rExternalValue.hasValue() )
     313                 :            :     {
     314                 :          4 :         util::Time aTime;
     315         [ +  - ]:          4 :         OSL_VERIFY( _rExternalValue >>= aTime );
     316 [ +  - ][ +  - ]:          4 :         aControlValue <<= DBTypeConversion::toINT32( aTime );
     317                 :            :     }
     318                 :          4 :     return aControlValue;
     319                 :            : }
     320                 :            : 
     321                 :            : //------------------------------------------------------------------------------
     322                 :         12 : Any OTimeModel::translateControlValueToValidatableValue( ) const
     323                 :            : {
     324                 :         12 :     Any aValidatableValue;
     325         [ +  - ]:         12 :     impl_translateControlValueToUNOTime( aValidatableValue );
     326                 :         12 :     return aValidatableValue;
     327                 :            : }
     328                 :            : 
     329                 :            : //------------------------------------------------------------------------------
     330                 :          0 : Any OTimeModel::translateDbColumnToControlValue()
     331                 :            : {
     332 [ #  # ][ #  # ]:          0 :     util::Time aTime = m_xColumn->getTime();
     333 [ #  # ][ #  # ]:          0 :     if ( m_xColumn->wasNull() )
                 [ #  # ]
     334                 :          0 :         m_aSaveValue.clear();
     335                 :            :     else
     336                 :            :         // the aggregated set expects an Int32 as value ...
     337 [ #  # ][ #  # ]:          0 :         m_aSaveValue <<= DBTypeConversion::toINT32( aTime );
     338                 :            : 
     339                 :          0 :     return m_aSaveValue;
     340                 :            : }
     341                 :            : 
     342                 :            : //------------------------------------------------------------------------------
     343                 :          6 : Any OTimeModel::getDefaultForReset() const
     344                 :            : {
     345                 :          6 :     return m_aDefault;
     346                 :            : }
     347                 :            : 
     348                 :            : //------------------------------------------------------------------------------
     349                 :          6 : void OTimeModel::resetNoBroadcast()
     350                 :            : {
     351                 :          6 :     OEditBaseModel::resetNoBroadcast();
     352                 :          6 :     m_aSaveValue.clear();
     353                 :          6 : }
     354                 :            : 
     355                 :            : //------------------------------------------------------------------------------
     356                 :          8 : Sequence< Type > OTimeModel::getSupportedBindingTypes()
     357                 :            : {
     358                 :          8 :     return Sequence< Type >( &::getCppuType( static_cast< util::Time* >( NULL ) ), 1 );
     359                 :            : }
     360                 :            : 
     361                 :            : //.........................................................................
     362                 :            : }   // namespace frm
     363                 :            : //.........................................................................
     364                 :            : 
     365                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10