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

Generated by: LCOV version 1.10