LCOV - code coverage report
Current view: top level - forms/source/component - Time.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 73 125 58.4 %
Date: 2014-04-11 Functions: 19 26 73.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "Time.hxx"
      21             : #include <tools/debug.hxx>
      22             : #include <tools/time.hxx>
      23             : #include <connectivity/dbconversion.hxx>
      24             : #include <com/sun/star/sdbc/DataType.hpp>
      25             : #include <comphelper/processfactory.hxx>
      26             : 
      27             : using namespace dbtools;
      28             : 
      29             : 
      30             : namespace frm
      31             : {
      32             : 
      33             : 
      34             : using namespace ::com::sun::star;
      35             : using namespace ::com::sun::star::uno;
      36             : using namespace ::com::sun::star::sdb;
      37             : using namespace ::com::sun::star::sdbc;
      38             : using namespace ::com::sun::star::sdbcx;
      39             : using namespace ::com::sun::star::beans;
      40             : using namespace ::com::sun::star::container;
      41             : using namespace ::com::sun::star::form;
      42             : using namespace ::com::sun::star::util;
      43             : using namespace ::com::sun::star::awt;
      44             : using namespace ::com::sun::star::io;
      45             : using namespace ::com::sun::star::lang;
      46             : 
      47             : 
      48             : //=
      49             : 
      50             : 
      51             : 
      52             : //= OTimeControl
      53             : 
      54             : 
      55           6 : OTimeControl::OTimeControl(const Reference<XComponentContext>& _rxFactory)
      56           6 :                :OBoundControl(_rxFactory, VCL_CONTROL_TIMEFIELD)
      57             : {
      58           6 : }
      59             : 
      60             : 
      61           6 : InterfaceRef SAL_CALL OTimeControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      62             : {
      63           6 :     return *(new OTimeControl( comphelper::getComponentContext(_rxFactory) ));
      64             : }
      65             : 
      66             : 
      67           0 : Sequence<Type> OTimeControl::_getTypes()
      68             : {
      69           0 :     return OBoundControl::_getTypes();
      70             : }
      71             : 
      72             : 
      73           0 : StringSequence SAL_CALL OTimeControl::getSupportedServiceNames() throw(std::exception)
      74             : {
      75           0 :     StringSequence aSupported = OBoundControl::getSupportedServiceNames();
      76           0 :     aSupported.realloc(aSupported.getLength() + 1);
      77             : 
      78           0 :     OUString*pArray = aSupported.getArray();
      79           0 :     pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_TIMEFIELD;
      80           0 :     return aSupported;
      81             : }
      82             : 
      83             : 
      84             : //= OTimeModel
      85             : 
      86             : 
      87           9 : InterfaceRef SAL_CALL OTimeModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      88             : {
      89           9 :     return *(new OTimeModel( comphelper::getComponentContext(_rxFactory) ));
      90             : }
      91             : 
      92             : // XServiceInfo
      93             : 
      94           7 : StringSequence SAL_CALL OTimeModel::getSupportedServiceNames() throw(std::exception)
      95             : {
      96           7 :     StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
      97             : 
      98           7 :     sal_Int32 nOldLen = aSupported.getLength();
      99           7 :     aSupported.realloc( nOldLen + 8 );
     100           7 :     OUString* pStoreTo = aSupported.getArray() + nOldLen;
     101             : 
     102           7 :     *pStoreTo++ = BINDABLE_CONTROL_MODEL;
     103           7 :     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
     104           7 :     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
     105             : 
     106           7 :     *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
     107           7 :     *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
     108             : 
     109           7 :     *pStoreTo++ = FRM_SUN_COMPONENT_TIMEFIELD;
     110           7 :     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_TIMEFIELD;
     111           7 :     *pStoreTo++ = BINDABLE_DATABASE_TIME_FIELD;
     112             : 
     113           7 :     return aSupported;
     114             : }
     115             : 
     116             : 
     117           0 : Sequence<Type> OTimeModel::_getTypes()
     118             : {
     119           0 :     return OBoundControlModel::_getTypes();
     120             : }
     121             : 
     122             : 
     123             : 
     124           9 : OTimeModel::OTimeModel(const Reference<XComponentContext>& _rxFactory)
     125             :     : OEditBaseModel(_rxFactory, VCL_CONTROLMODEL_TIMEFIELD,
     126             :         FRM_SUN_CONTROL_TIMEFIELD, sal_True, sal_True)
     127             :       // use the old control name for compatibility reasons
     128             :     , OLimitedFormats(_rxFactory, FormComponentType::TIMEFIELD)
     129           9 :     , m_bDateTimeField(false)
     130             : {
     131           9 :     m_nClassId = FormComponentType::TIMEFIELD;
     132           9 :     initValueProperty( PROPERTY_TIME, PROPERTY_ID_TIME );
     133             : 
     134           9 :     setAggregateSet(m_xAggregateFastSet, getOriginalHandle(PROPERTY_ID_TIMEFORMAT));
     135           9 : }
     136             : 
     137             : 
     138           1 : OTimeModel::OTimeModel(const OTimeModel* _pOriginal, const Reference<XComponentContext>& _rxFactory)
     139             :     : OEditBaseModel(_pOriginal, _rxFactory)
     140             :     , OLimitedFormats(_rxFactory, FormComponentType::TIMEFIELD)
     141           1 :     , m_bDateTimeField(false)
     142             : {
     143           1 :     setAggregateSet( m_xAggregateFastSet, getOriginalHandle( PROPERTY_ID_TIMEFORMAT ) );
     144           1 : }
     145             : 
     146             : 
     147          30 : OTimeModel::~OTimeModel( )
     148             : {
     149          10 :     setAggregateSet(Reference< XFastPropertySet >(), -1);
     150          20 : }
     151             : 
     152             : // XCloneable
     153             : 
     154           1 : IMPLEMENT_DEFAULT_CLONING( OTimeModel )
     155             : 
     156             : 
     157           1 : OUString SAL_CALL OTimeModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     158             : {
     159           1 :     return OUString(FRM_COMPONENT_TIMEFIELD); // old (non-sun) name for compatibility !
     160             : }
     161             : 
     162             : // XPropertySet
     163             : 
     164          12 : void OTimeModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     165             : {
     166          12 :     BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel )
     167          12 :         DECL_PROP3(DEFAULT_TIME,            util::Time,             BOUND, MAYBEDEFAULT, MAYBEVOID);
     168          12 :         DECL_PROP1(TABINDEX,                sal_Int16,              BOUND);
     169          12 :         DECL_PROP1(FORMATKEY,               sal_Int32,              TRANSIENT);
     170          12 :         DECL_IFACE_PROP2(FORMATSSUPPLIER,   XNumberFormatsSupplier, READONLY, TRANSIENT);
     171             :     END_DESCRIBE_PROPERTIES();
     172          12 : }
     173             : 
     174             : 
     175        4156 : void SAL_CALL OTimeModel::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle ) const
     176             : {
     177        4156 :     switch (_nHandle)
     178             :     {
     179             :         case PROPERTY_ID_FORMATKEY:
     180          23 :             getFormatKeyPropertyValue(_rValue);
     181          23 :             break;
     182             :         case PROPERTY_ID_FORMATSSUPPLIER:
     183          22 :             _rValue <<= getFormatsSupplier();
     184          22 :             break;
     185             :         default:
     186        4111 :             OEditBaseModel::getFastPropertyValue(_rValue, _nHandle);
     187        4111 :             break;
     188             :     }
     189        4156 : }
     190             : 
     191             : 
     192         458 : sal_Bool SAL_CALL OTimeModel::convertFastPropertyValue(Any& _rConvertedValue, Any& _rOldValue,
     193             :         sal_Int32 _nHandle, const Any& _rValue ) throw(IllegalArgumentException)
     194             : {
     195         458 :     if (PROPERTY_ID_FORMATKEY == _nHandle)
     196           1 :         return convertFormatKeyPropertyValue(_rConvertedValue, _rOldValue, _rValue);
     197             :     else
     198         457 :         return OEditBaseModel::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue );
     199             : }
     200             : 
     201             : 
     202          88 : void SAL_CALL OTimeModel::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw ( ::com::sun::star::uno::Exception, std::exception)
     203             : {
     204          88 :     if (PROPERTY_ID_FORMATKEY == _nHandle)
     205           0 :         setFormatKeyPropertyValue(_rValue);
     206             :     else
     207          88 :         OEditBaseModel::setFastPropertyValue_NoBroadcast(_nHandle, _rValue);
     208          88 : }
     209             : 
     210             : // XLoadListener
     211             : 
     212           0 : void OTimeModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
     213             : {
     214           0 :     OBoundControlModel::onConnectedDbColumn( _rxForm );
     215           0 :     Reference<XPropertySet> xField = getField();
     216           0 :     if (xField.is())
     217             :     {
     218           0 :         m_bDateTimeField = sal_False;
     219             :         try
     220             :         {
     221           0 :             sal_Int32 nFieldType = 0;
     222           0 :             xField->getPropertyValue(PROPERTY_FIELDTYPE) >>= nFieldType;
     223           0 :             m_bDateTimeField = (nFieldType == DataType::TIMESTAMP);
     224             :         }
     225           0 :         catch(const Exception&)
     226             :         {
     227             :         }
     228           0 :     }
     229           0 : }
     230             : 
     231             : 
     232           0 : sal_Bool OTimeModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
     233             : {
     234           0 :     Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
     235           0 :     if ( !compare( aControlValue, m_aSaveValue ) )
     236             :     {
     237           0 :         if ( !aControlValue.hasValue() )
     238           0 :             m_xColumnUpdate->updateNull();
     239             :         else
     240             :         {
     241             :             try
     242             :             {
     243           0 :                 util::Time aTime;
     244           0 :                 if ( !( aControlValue >>= aTime ) )
     245             :                 {
     246           0 :                     sal_Int64 nAsInt(0);
     247           0 :                     aControlValue >>= nAsInt;
     248           0 :                     aTime = DBTypeConversion::toTime(nAsInt);
     249             :                 }
     250             : 
     251           0 :                 if (!m_bDateTimeField)
     252           0 :                     m_xColumnUpdate->updateTime(aTime);
     253             :                 else
     254             :                 {
     255           0 :                     util::DateTime aDateTime = m_xColumn->getTimestamp();
     256           0 :                     aDateTime.NanoSeconds = aTime.NanoSeconds;
     257           0 :                     aDateTime.Seconds = aTime.Seconds;
     258           0 :                     aDateTime.Minutes = aTime.Minutes;
     259           0 :                     aDateTime.Hours = aTime.Hours;
     260           0 :                     m_xColumnUpdate->updateTimestamp(aDateTime);
     261             :                 }
     262             :             }
     263           0 :             catch(const Exception&)
     264             :             {
     265           0 :                 return sal_False;
     266             :             }
     267             :         }
     268           0 :         m_aSaveValue = aControlValue;
     269             :     }
     270           0 :     return sal_True;
     271             : }
     272             : 
     273             : 
     274           0 : Any OTimeModel::translateControlValueToExternalValue( ) const
     275             : {
     276           0 :     return getControlValue();
     277             : }
     278             : 
     279             : 
     280           2 : Any OTimeModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
     281             : {
     282           2 :     return _rExternalValue;
     283             : }
     284             : 
     285             : 
     286           5 : Any OTimeModel::translateControlValueToValidatableValue( ) const
     287             : {
     288           5 :     return getControlValue();
     289             : }
     290             : 
     291             : 
     292           0 : Any OTimeModel::translateDbColumnToControlValue()
     293             : {
     294           0 :     util::Time aTime = m_xColumn->getTime();
     295           0 :     if ( m_xColumn->wasNull() )
     296           0 :         m_aSaveValue.clear();
     297             :     else
     298           0 :         m_aSaveValue <<= aTime;
     299             : 
     300           0 :     return m_aSaveValue;
     301             : }
     302             : 
     303             : 
     304           3 : Any OTimeModel::getDefaultForReset() const
     305             : {
     306           3 :     return m_aDefault;
     307             : }
     308             : 
     309             : 
     310           3 : void OTimeModel::resetNoBroadcast()
     311             : {
     312           3 :     OEditBaseModel::resetNoBroadcast();
     313           3 :     m_aSaveValue.clear();
     314           3 : }
     315             : 
     316             : 
     317           4 : Sequence< Type > OTimeModel::getSupportedBindingTypes()
     318             : {
     319           4 :     return Sequence< Type >( &::getCppuType( static_cast< util::Time* >( NULL ) ), 1 );
     320             : }
     321             : 
     322             : 
     323             : }   // namespace frm
     324             : 
     325             : 
     326             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10