bump product version to 4.1.6.2
[LibreOffice.git] / forms / source / component / Currency.cxx
blobc47f18d428d8a82f0ca0cd171c27ba547d86fc4c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "Currency.hxx"
21 #include <tools/debug.hxx>
22 #include <unotools/localedatawrapper.hxx>
23 #include <vcl/svapp.hxx>
24 #include <unotools/syslocale.hxx>
26 //.........................................................................
27 namespace frm
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;
42 //==================================================================
43 // OCurrencyControl
44 //==================================================================
45 //------------------------------------------------------------------
46 OCurrencyControl::OCurrencyControl(const Reference<XMultiServiceFactory>& _rxFactory)
47 :OBoundControl(_rxFactory, VCL_CONTROL_CURRENCYFIELD)
51 //------------------------------------------------------------------
52 InterfaceRef SAL_CALL OCurrencyControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
54 return *(new OCurrencyControl(_rxFactory));
57 //------------------------------------------------------------------------------
58 Sequence<Type> OCurrencyControl::_getTypes()
60 return OBoundControl::_getTypes();
63 //------------------------------------------------------------------------------
64 StringSequence SAL_CALL OCurrencyControl::getSupportedServiceNames() throw()
66 StringSequence aSupported = OBoundControl::getSupportedServiceNames();
67 aSupported.realloc(aSupported.getLength() + 1);
69 OUString*pArray = aSupported.getArray();
70 pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_CURRENCYFIELD;
71 return aSupported;
74 //==================================================================
75 // OCurrencyModel
76 //==================================================================
77 //------------------------------------------------------------------
78 InterfaceRef SAL_CALL OCurrencyModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
80 return *(new OCurrencyModel(_rxFactory));
83 //------------------------------------------------------------------------------
84 Sequence<Type> OCurrencyModel::_getTypes()
86 return OEditBaseModel::_getTypes();
89 //------------------------------------------------------------------
90 void OCurrencyModel::implConstruct()
92 if (m_xAggregateSet.is())
94 try
96 // get the system international information
97 const SvtSysLocale aSysLocale;
98 const LocaleDataWrapper& aLocaleInfo = aSysLocale.GetLocaleData();
100 OUString sCurrencySymbol;
101 sal_Bool bPrependCurrencySymbol;
102 switch ( aLocaleInfo.getCurrPositiveFormat() )
104 case 0: // $1
105 sCurrencySymbol = String(aLocaleInfo.getCurrSymbol());
106 bPrependCurrencySymbol = sal_True;
107 break;
108 case 1: // 1$
109 sCurrencySymbol = String(aLocaleInfo.getCurrSymbol());
110 bPrependCurrencySymbol = sal_False;
111 break;
112 case 2: // $ 1
113 sCurrencySymbol = OUString(String(aLocaleInfo.getCurrSymbol())) + OUString(" ");
114 bPrependCurrencySymbol = sal_True;
115 break;
116 case 3: // 1 $
117 sCurrencySymbol = OUString(" ") + OUString(String(aLocaleInfo.getCurrSymbol()));
118 bPrependCurrencySymbol = sal_False;
119 break;
121 if (!sCurrencySymbol.isEmpty())
123 m_xAggregateSet->setPropertyValue(PROPERTY_CURRENCYSYMBOL, makeAny(sCurrencySymbol));
124 m_xAggregateSet->setPropertyValue(PROPERTY_CURRSYM_POSITION, makeAny(bPrependCurrencySymbol));
127 catch(const Exception&)
129 OSL_FAIL( "OCurrencyModel::implConstruct: caught an exception while initializing the aggregate!" );
134 //------------------------------------------------------------------
135 DBG_NAME( OCurrencyModel )
136 //------------------------------------------------------------------
137 OCurrencyModel::OCurrencyModel(const Reference<XMultiServiceFactory>& _rxFactory)
138 :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_CURRENCYFIELD, FRM_SUN_CONTROL_CURRENCYFIELD, sal_False, sal_True )
139 // use the old control name for compytibility reasons
141 DBG_CTOR( OCurrencyModel, NULL );
143 m_nClassId = FormComponentType::CURRENCYFIELD;
144 initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
146 implConstruct();
149 //------------------------------------------------------------------
150 OCurrencyModel::OCurrencyModel( const OCurrencyModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
151 :OEditBaseModel( _pOriginal, _rxFactory )
153 DBG_CTOR( OCurrencyModel, NULL );
154 implConstruct();
157 //------------------------------------------------------------------
158 OCurrencyModel::~OCurrencyModel()
160 DBG_DTOR( OCurrencyModel, NULL );
163 // XCloneable
164 //------------------------------------------------------------------------------
165 IMPLEMENT_DEFAULT_CLONING( OCurrencyModel )
167 // XServiceInfo
168 //------------------------------------------------------------------------------
169 StringSequence SAL_CALL OCurrencyModel::getSupportedServiceNames() throw()
171 StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
173 sal_Int32 nOldLen = aSupported.getLength();
174 aSupported.realloc( nOldLen + 4 );
175 OUString* pStoreTo = aSupported.getArray() + nOldLen;
177 *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
178 *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
180 *pStoreTo++ = FRM_SUN_COMPONENT_CURRENCYFIELD;
181 *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD;
183 return aSupported;
186 //------------------------------------------------------------------------------
187 void OCurrencyModel::describeFixedProperties( Sequence< Property >& _rProps ) const
189 BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel )
190 // Value auf transient setzen
191 // ModifyPropertyAttributes(_rAggregateProps, PROPERTY_VALUE, PropertyAttribute::TRANSIENT, 0);
193 DECL_PROP3(DEFAULT_VALUE, double, BOUND, MAYBEDEFAULT, MAYBEVOID);
194 DECL_PROP1(TABINDEX, sal_Int16, BOUND);
195 END_DESCRIBE_PROPERTIES();
198 //------------------------------------------------------------------------------
199 OUString SAL_CALL OCurrencyModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
201 return OUString(FRM_COMPONENT_CURRENCYFIELD); // old (non-sun) name for compatibility !
204 //------------------------------------------------------------------------------
205 sal_Bool OCurrencyModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
207 Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
208 if ( !compare( aControlValue, m_aSaveValue ) )
210 if ( aControlValue.getValueType().getTypeClass() == TypeClass_VOID )
211 m_xColumnUpdate->updateNull();
212 else
216 m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
218 catch(const Exception&)
220 return sal_False;
223 m_aSaveValue = aControlValue;
225 return sal_True;
228 //------------------------------------------------------------------------------
229 Any OCurrencyModel::translateDbColumnToControlValue()
231 m_aSaveValue <<= m_xColumn->getDouble();
232 if ( m_xColumn->wasNull() )
233 m_aSaveValue.clear();
234 return m_aSaveValue;
237 // XReset
238 //------------------------------------------------------------------------------
239 Any OCurrencyModel::getDefaultForReset() const
241 Any aValue;
242 if ( m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE )
243 aValue = m_aDefault;
245 return aValue;
248 //------------------------------------------------------------------------------
249 void OCurrencyModel::resetNoBroadcast()
251 OEditBaseModel::resetNoBroadcast();
252 m_aSaveValue.clear();
255 //.........................................................................
256 } // namespace frm
257 //.........................................................................
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */