LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/forms/source/component - Currency.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 62 96 64.6 %
Date: 2013-07-09 Functions: 17 21 81.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 "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()
      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           2 : Sequence<Type> OCurrencyModel::_getTypes()
      86             : {
      87           2 :     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 = String(aLocaleInfo.getCurrSymbol());
     107          10 :                     bPrependCurrencySymbol = sal_True;
     108          10 :                     break;
     109             :                 case 1: // 1$
     110           0 :                     sCurrencySymbol = String(aLocaleInfo.getCurrSymbol());
     111           0 :                     bPrependCurrencySymbol = sal_False;
     112           0 :                     break;
     113             :                 case 2: // $ 1
     114           0 :                     sCurrencySymbol = OUString(String(aLocaleInfo.getCurrSymbol())) + OUString(" ");
     115           0 :                     bPrependCurrencySymbol = sal_True;
     116           0 :                     break;
     117             :                 case 3: // 1 $
     118           0 :                     sCurrencySymbol = OUString(" ") + OUString(String(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             : DBG_NAME( OCurrencyModel )
     137             : //------------------------------------------------------------------
     138           9 : OCurrencyModel::OCurrencyModel(const Reference<XComponentContext>& _rxFactory)
     139           9 :     :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_CURRENCYFIELD, FRM_SUN_CONTROL_CURRENCYFIELD, sal_False, sal_True )
     140             :                                     // use the old control name for compytibility reasons
     141             : {
     142             :     DBG_CTOR( OCurrencyModel, NULL );
     143             : 
     144           9 :     m_nClassId = FormComponentType::CURRENCYFIELD;
     145           9 :     initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
     146             : 
     147           9 :     implConstruct();
     148           9 : }
     149             : 
     150             : //------------------------------------------------------------------
     151           1 : OCurrencyModel::OCurrencyModel( const OCurrencyModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
     152           1 :     :OEditBaseModel( _pOriginal, _rxFactory )
     153             : {
     154             :     DBG_CTOR( OCurrencyModel, NULL );
     155           1 :     implConstruct();
     156           1 : }
     157             : 
     158             : //------------------------------------------------------------------
     159          20 : OCurrencyModel::~OCurrencyModel()
     160             : {
     161             :     DBG_DTOR( OCurrencyModel, NULL );
     162          20 : }
     163             : 
     164             : // XCloneable
     165             : //------------------------------------------------------------------------------
     166           1 : IMPLEMENT_DEFAULT_CLONING( OCurrencyModel )
     167             : 
     168             : // XServiceInfo
     169             : //------------------------------------------------------------------------------
     170           7 : StringSequence SAL_CALL OCurrencyModel::getSupportedServiceNames() throw()
     171             : {
     172           7 :     StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
     173             : 
     174           7 :     sal_Int32 nOldLen = aSupported.getLength();
     175           7 :     aSupported.realloc( nOldLen + 4 );
     176           7 :     OUString* pStoreTo = aSupported.getArray() + nOldLen;
     177             : 
     178           7 :     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
     179           7 :     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
     180             : 
     181           7 :     *pStoreTo++ = FRM_SUN_COMPONENT_CURRENCYFIELD;
     182           7 :     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD;
     183             : 
     184           7 :     return aSupported;
     185             : }
     186             : 
     187             : //------------------------------------------------------------------------------
     188          11 : void OCurrencyModel::describeFixedProperties( Sequence< Property >& _rProps ) const
     189             : {
     190          11 :     BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel )
     191             :         // Value auf transient setzen
     192             : //      ModifyPropertyAttributes(_rAggregateProps, PROPERTY_VALUE, PropertyAttribute::TRANSIENT, 0);
     193             : 
     194          11 :         DECL_PROP3(DEFAULT_VALUE,       double,             BOUND, MAYBEDEFAULT, MAYBEVOID);
     195          11 :         DECL_PROP1(TABINDEX,        sal_Int16,              BOUND);
     196             :     END_DESCRIBE_PROPERTIES();
     197          11 : }
     198             : 
     199             : //------------------------------------------------------------------------------
     200           1 : OUString SAL_CALL OCurrencyModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
     201             : {
     202           1 :     return OUString(FRM_COMPONENT_CURRENCYFIELD); // old (non-sun) name for compatibility !
     203             : }
     204             : 
     205             : //------------------------------------------------------------------------------
     206           0 : sal_Bool OCurrencyModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
     207             : {
     208           0 :     Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
     209           0 :     if ( !compare( aControlValue, m_aSaveValue ) )
     210             :     {
     211           0 :         if ( aControlValue.getValueType().getTypeClass() == TypeClass_VOID )
     212           0 :             m_xColumnUpdate->updateNull();
     213             :         else
     214             :         {
     215             :             try
     216             :             {
     217           0 :                 m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
     218             :             }
     219           0 :             catch(const Exception&)
     220             :             {
     221           0 :                 return sal_False;
     222             :             }
     223             :         }
     224           0 :         m_aSaveValue = aControlValue;
     225             :     }
     226           0 :     return sal_True;
     227             : }
     228             : 
     229             : //------------------------------------------------------------------------------
     230           0 : Any OCurrencyModel::translateDbColumnToControlValue()
     231             : {
     232           0 :     m_aSaveValue <<= m_xColumn->getDouble();
     233           0 :     if ( m_xColumn->wasNull() )
     234           0 :         m_aSaveValue.clear();
     235           0 :     return m_aSaveValue;
     236             : }
     237             : 
     238             : // XReset
     239             : //------------------------------------------------------------------------------
     240           3 : Any OCurrencyModel::getDefaultForReset() const
     241             : {
     242           3 :     Any aValue;
     243           3 :     if ( m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE )
     244           0 :         aValue = m_aDefault;
     245             : 
     246           3 :     return aValue;
     247             : }
     248             : 
     249             : //------------------------------------------------------------------------------
     250           3 : void OCurrencyModel::resetNoBroadcast()
     251             : {
     252           3 :     OEditBaseModel::resetNoBroadcast();
     253           3 :     m_aSaveValue.clear();
     254           3 : }
     255             : 
     256             : //.........................................................................
     257          72 : }   // namespace frm
     258             : //.........................................................................
     259             : 
     260             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10