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

Generated by: LCOV version 1.11