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

Generated by: LCOV version 1.11