LCOV - code coverage report
Current view: top level - forms/source/component - Time.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 125 0.0 %
Date: 2014-04-14 Functions: 0 26 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 "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           0 : OTimeControl::OTimeControl(const Reference<XComponentContext>& _rxFactory)
      56           0 :                :OBoundControl(_rxFactory, VCL_CONTROL_TIMEFIELD)
      57             : {
      58           0 : }
      59             : 
      60             : 
      61           0 : InterfaceRef SAL_CALL OTimeControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      62             : {
      63           0 :     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           0 : InterfaceRef SAL_CALL OTimeModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      88             : {
      89           0 :     return *(new OTimeModel( comphelper::getComponentContext(_rxFactory) ));
      90             : }
      91             : 
      92             : // XServiceInfo
      93             : 
      94           0 : StringSequence SAL_CALL OTimeModel::getSupportedServiceNames() throw(std::exception)
      95             : {
      96           0 :     StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
      97             : 
      98           0 :     sal_Int32 nOldLen = aSupported.getLength();
      99           0 :     aSupported.realloc( nOldLen + 8 );
     100           0 :     OUString* pStoreTo = aSupported.getArray() + nOldLen;
     101             : 
     102           0 :     *pStoreTo++ = BINDABLE_CONTROL_MODEL;
     103           0 :     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
     104           0 :     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
     105             : 
     106           0 :     *pStoreTo++ = BINDABLE_DATA_AWARE_CONTROL_MODEL;
     107           0 :     *pStoreTo++ = VALIDATABLE_BINDABLE_CONTROL_MODEL;
     108             : 
     109           0 :     *pStoreTo++ = FRM_SUN_COMPONENT_TIMEFIELD;
     110           0 :     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_TIMEFIELD;
     111           0 :     *pStoreTo++ = BINDABLE_DATABASE_TIME_FIELD;
     112             : 
     113           0 :     return aSupported;
     114             : }
     115             : 
     116             : 
     117           0 : Sequence<Type> OTimeModel::_getTypes()
     118             : {
     119           0 :     return OBoundControlModel::_getTypes();
     120             : }
     121             : 
     122             : 
     123             : 
     124           0 : 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           0 :     , m_bDateTimeField(false)
     130             : {
     131           0 :     m_nClassId = FormComponentType::TIMEFIELD;
     132           0 :     initValueProperty( PROPERTY_TIME, PROPERTY_ID_TIME );
     133             : 
     134           0 :     setAggregateSet(m_xAggregateFastSet, getOriginalHandle(PROPERTY_ID_TIMEFORMAT));
     135           0 : }
     136             : 
     137             : 
     138           0 : OTimeModel::OTimeModel(const OTimeModel* _pOriginal, const Reference<XComponentContext>& _rxFactory)
     139             :     : OEditBaseModel(_pOriginal, _rxFactory)
     140             :     , OLimitedFormats(_rxFactory, FormComponentType::TIMEFIELD)
     141           0 :     , m_bDateTimeField(false)
     142             : {
     143           0 :     setAggregateSet( m_xAggregateFastSet, getOriginalHandle( PROPERTY_ID_TIMEFORMAT ) );
     144           0 : }
     145             : 
     146             : 
     147           0 : OTimeModel::~OTimeModel( )
     148             : {
     149           0 :     setAggregateSet(Reference< XFastPropertySet >(), -1);
     150           0 : }
     151             : 
     152             : // XCloneable
     153             : 
     154           0 : IMPLEMENT_DEFAULT_CLONING( OTimeModel )
     155             : 
     156             : 
     157           0 : OUString SAL_CALL OTimeModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     158             : {
     159           0 :     return OUString(FRM_COMPONENT_TIMEFIELD); // old (non-sun) name for compatibility !
     160             : }
     161             : 
     162             : // XPropertySet
     163             : 
     164           0 : void OTimeModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     165             : {
     166           0 :     BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel )
     167           0 :         DECL_PROP3(DEFAULT_TIME,            util::Time,             BOUND, MAYBEDEFAULT, MAYBEVOID);
     168           0 :         DECL_PROP1(TABINDEX,                sal_Int16,              BOUND);
     169           0 :         DECL_PROP1(FORMATKEY,               sal_Int32,              TRANSIENT);
     170           0 :         DECL_IFACE_PROP2(FORMATSSUPPLIER,   XNumberFormatsSupplier, READONLY, TRANSIENT);
     171             :     END_DESCRIBE_PROPERTIES();
     172           0 : }
     173             : 
     174             : 
     175           0 : void SAL_CALL OTimeModel::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle ) const
     176             : {
     177           0 :     switch (_nHandle)
     178             :     {
     179             :         case PROPERTY_ID_FORMATKEY:
     180           0 :             getFormatKeyPropertyValue(_rValue);
     181           0 :             break;
     182             :         case PROPERTY_ID_FORMATSSUPPLIER:
     183           0 :             _rValue <<= getFormatsSupplier();
     184           0 :             break;
     185             :         default:
     186           0 :             OEditBaseModel::getFastPropertyValue(_rValue, _nHandle);
     187           0 :             break;
     188             :     }
     189           0 : }
     190             : 
     191             : 
     192           0 : sal_Bool SAL_CALL OTimeModel::convertFastPropertyValue(Any& _rConvertedValue, Any& _rOldValue,
     193             :         sal_Int32 _nHandle, const Any& _rValue ) throw(IllegalArgumentException)
     194             : {
     195           0 :     if (PROPERTY_ID_FORMATKEY == _nHandle)
     196           0 :         return convertFormatKeyPropertyValue(_rConvertedValue, _rOldValue, _rValue);
     197             :     else
     198           0 :         return OEditBaseModel::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue );
     199             : }
     200             : 
     201             : 
     202           0 : void SAL_CALL OTimeModel::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw ( ::com::sun::star::uno::Exception, std::exception)
     203             : {
     204           0 :     if (PROPERTY_ID_FORMATKEY == _nHandle)
     205           0 :         setFormatKeyPropertyValue(_rValue);
     206             :     else
     207           0 :         OEditBaseModel::setFastPropertyValue_NoBroadcast(_nHandle, _rValue);
     208           0 : }
     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           0 : Any OTimeModel::translateExternalValueToControlValue( const Any& _rExternalValue ) const
     281             : {
     282           0 :     return _rExternalValue;
     283             : }
     284             : 
     285             : 
     286           0 : Any OTimeModel::translateControlValueToValidatableValue( ) const
     287             : {
     288           0 :     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           0 : Any OTimeModel::getDefaultForReset() const
     305             : {
     306           0 :     return m_aDefault;
     307             : }
     308             : 
     309             : 
     310           0 : void OTimeModel::resetNoBroadcast()
     311             : {
     312           0 :     OEditBaseModel::resetNoBroadcast();
     313           0 :     m_aSaveValue.clear();
     314           0 : }
     315             : 
     316             : 
     317           0 : Sequence< Type > OTimeModel::getSupportedBindingTypes()
     318             : {
     319           0 :     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