LCOV - code coverage report
Current view: top level - forms/source/component - Time.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 73 125 58.4 %
Date: 2014-11-03 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/time.hxx>
      22             : #include <connectivity/dbconversion.hxx>
      23             : #include <com/sun/star/sdbc/DataType.hpp>
      24             : #include <comphelper/processfactory.hxx>
      25             : 
      26             : using namespace dbtools;
      27             : 
      28             : namespace frm
      29             : {
      30             : 
      31             : using namespace ::com::sun::star;
      32             : using namespace ::com::sun::star::uno;
      33             : using namespace ::com::sun::star::sdb;
      34             : using namespace ::com::sun::star::sdbc;
      35             : using namespace ::com::sun::star::sdbcx;
      36             : using namespace ::com::sun::star::beans;
      37             : using namespace ::com::sun::star::container;
      38             : using namespace ::com::sun::star::form;
      39             : using namespace ::com::sun::star::util;
      40             : using namespace ::com::sun::star::awt;
      41             : using namespace ::com::sun::star::io;
      42             : using namespace ::com::sun::star::lang;
      43             : 
      44             : 
      45             : //=
      46             : 
      47          12 : OTimeControl::OTimeControl(const Reference<XComponentContext>& _rxFactory)
      48          12 :                :OBoundControl(_rxFactory, VCL_CONTROL_TIMEFIELD)
      49             : {
      50          12 : }
      51             : 
      52             : 
      53          12 : InterfaceRef SAL_CALL OTimeControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      54             : {
      55          12 :     return *(new OTimeControl( comphelper::getComponentContext(_rxFactory) ));
      56             : }
      57             : 
      58             : 
      59           0 : Sequence<Type> OTimeControl::_getTypes()
      60             : {
      61           0 :     return OBoundControl::_getTypes();
      62             : }
      63             : 
      64             : 
      65           0 : StringSequence SAL_CALL OTimeControl::getSupportedServiceNames() throw(std::exception)
      66             : {
      67           0 :     StringSequence aSupported = OBoundControl::getSupportedServiceNames();
      68           0 :     aSupported.realloc(aSupported.getLength() + 1);
      69             : 
      70           0 :     OUString*pArray = aSupported.getArray();
      71           0 :     pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_TIMEFIELD;
      72           0 :     return aSupported;
      73             : }
      74             : 
      75             : 
      76             : //= OTimeModel
      77             : 
      78             : 
      79          18 : InterfaceRef SAL_CALL OTimeModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      80             : {
      81          18 :     return *(new OTimeModel( comphelper::getComponentContext(_rxFactory) ));
      82             : }
      83             : 
      84             : // XServiceInfo
      85             : 
      86          14 : StringSequence SAL_CALL OTimeModel::getSupportedServiceNames() throw(std::exception)
      87             : {
      88          14 :     StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
      89             : 
      90          14 :     sal_Int32 nOldLen = aSupported.getLength();
      91          14 :     aSupported.realloc( nOldLen + 8 );
      92          14 :     OUString* pStoreTo = aSupported.getArray() + nOldLen;
      93             : 
      94          14 :     *pStoreTo++ = BINDABLE_CONTROL_MODEL;
      95          14 :     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
      96          14 :     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
      97             : 
      98          14 :     *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
      99          14 :     *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
     100             : 
     101          14 :     *pStoreTo++ = FRM_SUN_COMPONENT_TIMEFIELD;
     102          14 :     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_TIMEFIELD;
     103          14 :     *pStoreTo++ = BINDABLE_DATABASE_TIME_FIELD;
     104             : 
     105          14 :     return aSupported;
     106             : }
     107             : 
     108             : 
     109           0 : Sequence<Type> OTimeModel::_getTypes()
     110             : {
     111           0 :     return OBoundControlModel::_getTypes();
     112             : }
     113             : 
     114             : 
     115             : 
     116          18 : OTimeModel::OTimeModel(const Reference<XComponentContext>& _rxFactory)
     117             :     : OEditBaseModel(_rxFactory, VCL_CONTROLMODEL_TIMEFIELD,
     118             :         FRM_SUN_CONTROL_TIMEFIELD, true, true)
     119             :       // use the old control name for compatibility reasons
     120             :     , OLimitedFormats(_rxFactory, FormComponentType::TIMEFIELD)
     121          18 :     , m_bDateTimeField(false)
     122             : {
     123          18 :     m_nClassId = FormComponentType::TIMEFIELD;
     124          18 :     initValueProperty( PROPERTY_TIME, PROPERTY_ID_TIME );
     125             : 
     126          18 :     setAggregateSet(m_xAggregateFastSet, getOriginalHandle(PROPERTY_ID_TIMEFORMAT));
     127          18 : }
     128             : 
     129             : 
     130           2 : OTimeModel::OTimeModel(const OTimeModel* _pOriginal, const Reference<XComponentContext>& _rxFactory)
     131             :     : OEditBaseModel(_pOriginal, _rxFactory)
     132             :     , OLimitedFormats(_rxFactory, FormComponentType::TIMEFIELD)
     133           2 :     , m_bDateTimeField(false)
     134             : {
     135           2 :     setAggregateSet( m_xAggregateFastSet, getOriginalHandle( PROPERTY_ID_TIMEFORMAT ) );
     136           2 : }
     137             : 
     138             : 
     139          60 : OTimeModel::~OTimeModel( )
     140             : {
     141          20 :     setAggregateSet(Reference< XFastPropertySet >(), -1);
     142          40 : }
     143             : 
     144             : // XCloneable
     145             : 
     146           2 : IMPLEMENT_DEFAULT_CLONING( OTimeModel )
     147             : 
     148             : 
     149           2 : OUString SAL_CALL OTimeModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     150             : {
     151           2 :     return OUString(FRM_COMPONENT_TIMEFIELD); // old (non-sun) name for compatibility !
     152             : }
     153             : 
     154             : // XPropertySet
     155             : 
     156          24 : void OTimeModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     157             : {
     158          24 :     BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel )
     159          24 :         DECL_PROP3(DEFAULT_TIME,            util::Time,             BOUND, MAYBEDEFAULT, MAYBEVOID);
     160          24 :         DECL_PROP1(TABINDEX,                sal_Int16,              BOUND);
     161          24 :         DECL_PROP1(FORMATKEY,               sal_Int32,              TRANSIENT);
     162          24 :         DECL_IFACE_PROP2(FORMATSSUPPLIER,   XNumberFormatsSupplier, READONLY, TRANSIENT);
     163             :     END_DESCRIBE_PROPERTIES();
     164          24 : }
     165             : 
     166             : 
     167        8302 : void SAL_CALL OTimeModel::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle ) const
     168             : {
     169        8302 :     switch (_nHandle)
     170             :     {
     171             :         case PROPERTY_ID_FORMATKEY:
     172          46 :             getFormatKeyPropertyValue(_rValue);
     173          46 :             break;
     174             :         case PROPERTY_ID_FORMATSSUPPLIER:
     175          44 :             _rValue <<= getFormatsSupplier();
     176          44 :             break;
     177             :         default:
     178        8212 :             OEditBaseModel::getFastPropertyValue(_rValue, _nHandle);
     179        8212 :             break;
     180             :     }
     181        8302 : }
     182             : 
     183             : 
     184         915 : sal_Bool SAL_CALL OTimeModel::convertFastPropertyValue(Any& _rConvertedValue, Any& _rOldValue,
     185             :         sal_Int32 _nHandle, const Any& _rValue ) throw(IllegalArgumentException)
     186             : {
     187         915 :     if (PROPERTY_ID_FORMATKEY == _nHandle)
     188           2 :         return convertFormatKeyPropertyValue(_rConvertedValue, _rOldValue, _rValue);
     189             :     else
     190         913 :         return OEditBaseModel::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue );
     191             : }
     192             : 
     193             : 
     194         175 : void SAL_CALL OTimeModel::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw ( ::com::sun::star::uno::Exception, std::exception)
     195             : {
     196         175 :     if (PROPERTY_ID_FORMATKEY == _nHandle)
     197           0 :         setFormatKeyPropertyValue(_rValue);
     198             :     else
     199         175 :         OEditBaseModel::setFastPropertyValue_NoBroadcast(_nHandle, _rValue);
     200         175 : }
     201             : 
     202             : // XLoadListener
     203             : 
     204           0 : void OTimeModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
     205             : {
     206           0 :     OBoundControlModel::onConnectedDbColumn( _rxForm );
     207           0 :     Reference<XPropertySet> xField = getField();
     208           0 :     if (xField.is())
     209             :     {
     210           0 :         m_bDateTimeField = false;
     211             :         try
     212             :         {
     213           0 :             sal_Int32 nFieldType = 0;
     214           0 :             xField->getPropertyValue(PROPERTY_FIELDTYPE) >>= nFieldType;
     215           0 :             m_bDateTimeField = (nFieldType == DataType::TIMESTAMP);
     216             :         }
     217           0 :         catch(const Exception&)
     218             :         {
     219             :         }
     220           0 :     }
     221           0 : }
     222             : 
     223             : 
     224           0 : bool OTimeModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
     225             : {
     226           0 :     Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
     227           0 :     if ( !compare( aControlValue, m_aSaveValue ) )
     228             :     {
     229           0 :         if ( !aControlValue.hasValue() )
     230           0 :             m_xColumnUpdate->updateNull();
     231             :         else
     232             :         {
     233             :             try
     234             :             {
     235           0 :                 util::Time aTime;
     236           0 :                 if ( !( aControlValue >>= aTime ) )
     237             :                 {
     238           0 :                     sal_Int64 nAsInt(0);
     239           0 :                     aControlValue >>= nAsInt;
     240           0 :                     aTime = DBTypeConversion::toTime(nAsInt);
     241             :                 }
     242             : 
     243           0 :                 if (!m_bDateTimeField)
     244           0 :                     m_xColumnUpdate->updateTime(aTime);
     245             :                 else
     246             :                 {
     247           0 :                     util::DateTime aDateTime = m_xColumn->getTimestamp();
     248           0 :                     aDateTime.NanoSeconds = aTime.NanoSeconds;
     249           0 :                     aDateTime.Seconds = aTime.Seconds;
     250           0 :                     aDateTime.Minutes = aTime.Minutes;
     251           0 :                     aDateTime.Hours = aTime.Hours;
     252           0 :                     m_xColumnUpdate->updateTimestamp(aDateTime);
     253             :                 }
     254             :             }
     255           0 :             catch(const Exception&)
     256             :             {
     257           0 :                 return false;
     258             :             }
     259             :         }
     260           0 :         m_aSaveValue = aControlValue;
     261             :     }
     262           0 :     return true;
     263             : }
     264             : 
     265             : 
     266           0 : Any OTimeModel::translateControlValueToExternalValue( ) const
     267             : {
     268           0 :     return getControlValue();
     269             : }
     270             : 
     271             : 
     272           4 : Any OTimeModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
     273             : {
     274           4 :     return _rExternalValue;
     275             : }
     276             : 
     277             : 
     278          10 : Any OTimeModel::translateControlValueToValidatableValue( ) const
     279             : {
     280          10 :     return getControlValue();
     281             : }
     282             : 
     283             : 
     284           0 : Any OTimeModel::translateDbColumnToControlValue()
     285             : {
     286           0 :     util::Time aTime = m_xColumn->getTime();
     287           0 :     if ( m_xColumn->wasNull() )
     288           0 :         m_aSaveValue.clear();
     289             :     else
     290           0 :         m_aSaveValue <<= aTime;
     291             : 
     292           0 :     return m_aSaveValue;
     293             : }
     294             : 
     295             : 
     296           6 : Any OTimeModel::getDefaultForReset() const
     297             : {
     298           6 :     return m_aDefault;
     299             : }
     300             : 
     301             : 
     302           6 : void OTimeModel::resetNoBroadcast()
     303             : {
     304           6 :     OEditBaseModel::resetNoBroadcast();
     305           6 :     m_aSaveValue.clear();
     306           6 : }
     307             : 
     308             : 
     309           8 : Sequence< Type > OTimeModel::getSupportedBindingTypes()
     310             : {
     311           8 :     return Sequence< Type >( & cppu::UnoType<util::Time>::get(), 1 );
     312             : }
     313             : 
     314             : 
     315             : }   // namespace frm
     316             : 
     317             : 
     318             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10