LCOV - code coverage report
Current view: top level - forms/source/component - Currency.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 59 95 62.1 %
Date: 2014-04-11 Functions: 14 19 73.7 %
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 "Currency.hxx"
      21             : #include <tools/debug.hxx>
      22             : #include <unotools/localedatawrapper.hxx>
      23             : #include <vcl/svapp.hxx>
      24             : #include <unotools/syslocale.hxx>
      25             : #include <comphelper/processfactory.hxx>
      26             : 
      27             : 
      28             : namespace frm
      29             : {
      30             : 
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::sdb;
      33             : using namespace ::com::sun::star::sdbc;
      34             : using namespace ::com::sun::star::sdbcx;
      35             : using namespace ::com::sun::star::beans;
      36             : using namespace ::com::sun::star::container;
      37             : using namespace ::com::sun::star::form;
      38             : using namespace ::com::sun::star::awt;
      39             : using namespace ::com::sun::star::io;
      40             : using namespace ::com::sun::star::lang;
      41             : using namespace ::com::sun::star::util;
      42             : 
      43             : 
      44             : // OCurrencyControl
      45             : 
      46             : 
      47           6 : OCurrencyControl::OCurrencyControl(const Reference<XComponentContext>& _rxFactory)
      48           6 :     :OBoundControl(_rxFactory, VCL_CONTROL_CURRENCYFIELD)
      49             : {
      50           6 : }
      51             : 
      52             : 
      53           6 : InterfaceRef SAL_CALL OCurrencyControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      54             : {
      55           6 :     return *(new OCurrencyControl( comphelper::getComponentContext(_rxFactory) ));
      56             : }
      57             : 
      58             : 
      59           0 : Sequence<Type> OCurrencyControl::_getTypes()
      60             : {
      61           0 :     return OBoundControl::_getTypes();
      62             : }
      63             : 
      64             : 
      65           0 : StringSequence SAL_CALL OCurrencyControl::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_CURRENCYFIELD;
      72           0 :     return aSupported;
      73             : }
      74             : 
      75             : 
      76             : // OCurrencyModel
      77             : 
      78             : 
      79           9 : InterfaceRef SAL_CALL OCurrencyModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
      80             : {
      81           9 :     return *(new OCurrencyModel( comphelper::getComponentContext(_rxFactory) ));
      82             : }
      83             : 
      84             : 
      85           0 : Sequence<Type> OCurrencyModel::_getTypes()
      86             : {
      87           0 :     return OEditBaseModel::_getTypes();
      88             : }
      89             : 
      90             : 
      91          10 : void OCurrencyModel::implConstruct()
      92             : {
      93          10 :     if (m_xAggregateSet.is())
      94             :     {
      95             :         try
      96             :         {
      97             :             // get the system international information
      98          10 :             const SvtSysLocale aSysLocale;
      99          10 :             const LocaleDataWrapper& aLocaleInfo = aSysLocale.GetLocaleData();
     100             : 
     101          20 :             OUString sCurrencySymbol;
     102             :             sal_Bool bPrependCurrencySymbol;
     103          10 :             switch ( aLocaleInfo.getCurrPositiveFormat() )
     104             :             {
     105             :                 case 0: // $1
     106          10 :                     sCurrencySymbol = aLocaleInfo.getCurrSymbol();
     107          10 :                     bPrependCurrencySymbol = sal_True;
     108          10 :                     break;
     109             :                 case 1: // 1$
     110           0 :                     sCurrencySymbol = aLocaleInfo.getCurrSymbol();
     111           0 :                     bPrependCurrencySymbol = sal_False;
     112           0 :                     break;
     113             :                 case 2: // $ 1
     114           0 :                     sCurrencySymbol = aLocaleInfo.getCurrSymbol() + " ";
     115           0 :                     bPrependCurrencySymbol = sal_True;
     116           0 :                     break;
     117             :                 case 3: // 1 $
     118           0 :                     sCurrencySymbol = " " + aLocaleInfo.getCurrSymbol();
     119           0 :                     bPrependCurrencySymbol = sal_False;
     120           0 :                     break;
     121             :             }
     122          10 :             if (!sCurrencySymbol.isEmpty())
     123             :             {
     124          10 :                 m_xAggregateSet->setPropertyValue(PROPERTY_CURRENCYSYMBOL, makeAny(sCurrencySymbol));
     125          10 :                 m_xAggregateSet->setPropertyValue(PROPERTY_CURRSYM_POSITION, makeAny(bPrependCurrencySymbol));
     126          10 :             }
     127             :         }
     128           0 :         catch(const Exception&)
     129             :         {
     130             :             OSL_FAIL( "OCurrencyModel::implConstruct: caught an exception while initializing the aggregate!" );
     131             :         }
     132             :     }
     133          10 : }
     134             : 
     135             : 
     136             : 
     137           9 : OCurrencyModel::OCurrencyModel(const Reference<XComponentContext>& _rxFactory)
     138           9 :     :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_CURRENCYFIELD, FRM_SUN_CONTROL_CURRENCYFIELD, sal_False, sal_True )
     139             :                                     // use the old control name for compytibility reasons
     140             : {
     141             : 
     142           9 :     m_nClassId = FormComponentType::CURRENCYFIELD;
     143           9 :     initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
     144             : 
     145           9 :     implConstruct();
     146           9 : }
     147             : 
     148             : 
     149           1 : OCurrencyModel::OCurrencyModel( const OCurrencyModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
     150           1 :     :OEditBaseModel( _pOriginal, _rxFactory )
     151             : {
     152           1 :     implConstruct();
     153           1 : }
     154             : 
     155             : 
     156          20 : OCurrencyModel::~OCurrencyModel()
     157             : {
     158          20 : }
     159             : 
     160             : // XCloneable
     161             : 
     162           1 : IMPLEMENT_DEFAULT_CLONING( OCurrencyModel )
     163             : 
     164             : // XServiceInfo
     165             : 
     166           7 : StringSequence SAL_CALL OCurrencyModel::getSupportedServiceNames() throw(std::exception)
     167             : {
     168           7 :     StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
     169             : 
     170           7 :     sal_Int32 nOldLen = aSupported.getLength();
     171           7 :     aSupported.realloc( nOldLen + 4 );
     172           7 :     OUString* pStoreTo = aSupported.getArray() + nOldLen;
     173             : 
     174           7 :     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
     175           7 :     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
     176             : 
     177           7 :     *pStoreTo++ = FRM_SUN_COMPONENT_CURRENCYFIELD;
     178           7 :     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD;
     179             : 
     180           7 :     return aSupported;
     181             : }
     182             : 
     183             : 
     184          11 : void OCurrencyModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     185             : {
     186          11 :     BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel )
     187             :         // Value auf transient setzen
     188             : //      ModifyPropertyAttributes(_rAggregateProps, PROPERTY_VALUE, PropertyAttribute::TRANSIENT, 0);
     189             : 
     190          11 :         DECL_PROP3(DEFAULT_VALUE,       double,             BOUND, MAYBEDEFAULT, MAYBEVOID);
     191          11 :         DECL_PROP1(TABINDEX,        sal_Int16,              BOUND);
     192             :     END_DESCRIBE_PROPERTIES();
     193          11 : }
     194             : 
     195             : 
     196           1 : OUString SAL_CALL OCurrencyModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
     197             : {
     198           1 :     return OUString(FRM_COMPONENT_CURRENCYFIELD); // old (non-sun) name for compatibility !
     199             : }
     200             : 
     201             : 
     202           0 : sal_Bool OCurrencyModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
     203             : {
     204           0 :     Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
     205           0 :     if ( !compare( aControlValue, m_aSaveValue ) )
     206             :     {
     207           0 :         if ( aControlValue.getValueType().getTypeClass() == TypeClass_VOID )
     208           0 :             m_xColumnUpdate->updateNull();
     209             :         else
     210             :         {
     211             :             try
     212             :             {
     213           0 :                 m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
     214             :             }
     215           0 :             catch(const Exception&)
     216             :             {
     217           0 :                 return sal_False;
     218             :             }
     219             :         }
     220           0 :         m_aSaveValue = aControlValue;
     221             :     }
     222           0 :     return sal_True;
     223             : }
     224             : 
     225             : 
     226           0 : Any OCurrencyModel::translateDbColumnToControlValue()
     227             : {
     228           0 :     m_aSaveValue <<= m_xColumn->getDouble();
     229           0 :     if ( m_xColumn->wasNull() )
     230           0 :         m_aSaveValue.clear();
     231           0 :     return m_aSaveValue;
     232             : }
     233             : 
     234             : // XReset
     235             : 
     236           3 : Any OCurrencyModel::getDefaultForReset() const
     237             : {
     238           3 :     Any aValue;
     239           3 :     if ( m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE )
     240           0 :         aValue = m_aDefault;
     241             : 
     242           3 :     return aValue;
     243             : }
     244             : 
     245             : 
     246           3 : void OCurrencyModel::resetNoBroadcast()
     247             : {
     248           3 :     OEditBaseModel::resetNoBroadcast();
     249           3 :     m_aSaveValue.clear();
     250           3 : }
     251             : 
     252             : 
     253             : }   // namespace frm
     254             : 
     255             : 
     256             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10