update dev300-m58
[ooovba.git] / forms / source / component / Currency.cxx
blobca3dae5a48c0d4c9eb22ac3866174d00ac70a735
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Currency.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
33 #include "Currency.hxx"
34 #include <tools/debug.hxx>
35 #include <unotools/localedatawrapper.hxx>
36 #include <vcl/svapp.hxx>
37 #include <svtools/syslocale.hxx>
39 //.........................................................................
40 namespace frm
42 //.........................................................................
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::sdb;
45 using namespace ::com::sun::star::sdbc;
46 using namespace ::com::sun::star::sdbcx;
47 using namespace ::com::sun::star::beans;
48 using namespace ::com::sun::star::container;
49 using namespace ::com::sun::star::form;
50 using namespace ::com::sun::star::awt;
51 using namespace ::com::sun::star::io;
52 using namespace ::com::sun::star::lang;
53 using namespace ::com::sun::star::util;
55 //==================================================================
56 // OCurrencyControl
57 //==================================================================
58 //------------------------------------------------------------------
59 OCurrencyControl::OCurrencyControl(const Reference<XMultiServiceFactory>& _rxFactory)
60 :OBoundControl(_rxFactory, VCL_CONTROL_CURRENCYFIELD)
64 //------------------------------------------------------------------
65 InterfaceRef SAL_CALL OCurrencyControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
67 return *(new OCurrencyControl(_rxFactory));
70 //------------------------------------------------------------------------------
71 Sequence<Type> OCurrencyControl::_getTypes()
73 return OBoundControl::_getTypes();
76 //------------------------------------------------------------------------------
77 StringSequence SAL_CALL OCurrencyControl::getSupportedServiceNames() throw()
79 StringSequence aSupported = OBoundControl::getSupportedServiceNames();
80 aSupported.realloc(aSupported.getLength() + 1);
82 ::rtl::OUString*pArray = aSupported.getArray();
83 pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_CURRENCYFIELD;
84 return aSupported;
87 //==================================================================
88 // OCurrencyModel
89 //==================================================================
90 //------------------------------------------------------------------
91 InterfaceRef SAL_CALL OCurrencyModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
93 return *(new OCurrencyModel(_rxFactory));
96 //------------------------------------------------------------------------------
97 Sequence<Type> OCurrencyModel::_getTypes()
99 return OEditBaseModel::_getTypes();
102 //------------------------------------------------------------------
103 void OCurrencyModel::implConstruct()
105 if (m_xAggregateSet.is())
109 // get the system international informations
110 const LocaleDataWrapper& aLocaleInfo = SvtSysLocale().GetLocaleData();
112 ::rtl::OUString sCurrencySymbol;
113 sal_Bool bPrependCurrencySymbol;
114 switch ( aLocaleInfo.getCurrPositiveFormat() )
116 case 0: // $1
117 sCurrencySymbol = String(aLocaleInfo.getCurrSymbol());
118 bPrependCurrencySymbol = sal_True;
119 break;
120 case 1: // 1$
121 sCurrencySymbol = String(aLocaleInfo.getCurrSymbol());
122 bPrependCurrencySymbol = sal_False;
123 break;
124 case 2: // $ 1
125 sCurrencySymbol = ::rtl::OUString(String(aLocaleInfo.getCurrSymbol())) + ::rtl::OUString::createFromAscii(" ");
126 bPrependCurrencySymbol = sal_True;
127 break;
128 case 3: // 1 $
129 sCurrencySymbol = ::rtl::OUString::createFromAscii(" ") + ::rtl::OUString(String(aLocaleInfo.getCurrSymbol()));
130 bPrependCurrencySymbol = sal_False;
131 break;
133 if (sCurrencySymbol.getLength())
135 m_xAggregateSet->setPropertyValue(PROPERTY_CURRENCYSYMBOL, makeAny(sCurrencySymbol));
136 m_xAggregateSet->setPropertyValue(PROPERTY_CURRSYM_POSITION, makeAny(bPrependCurrencySymbol));
139 catch(Exception&)
141 DBG_ERROR( "OCurrencyModel::implConstruct: caught an exception while initializing the aggregate!" );
146 //------------------------------------------------------------------
147 DBG_NAME( OCurrencyModel )
148 //------------------------------------------------------------------
149 OCurrencyModel::OCurrencyModel(const Reference<XMultiServiceFactory>& _rxFactory)
150 :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_CURRENCYFIELD, FRM_SUN_CONTROL_CURRENCYFIELD, sal_False, sal_True )
151 // use the old control name for compytibility reasons
153 DBG_CTOR( OCurrencyModel, NULL );
155 m_nClassId = FormComponentType::CURRENCYFIELD;
156 initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
158 implConstruct();
161 //------------------------------------------------------------------
162 OCurrencyModel::OCurrencyModel( const OCurrencyModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
163 :OEditBaseModel( _pOriginal, _rxFactory )
165 DBG_CTOR( OCurrencyModel, NULL );
166 implConstruct();
169 //------------------------------------------------------------------
170 OCurrencyModel::~OCurrencyModel()
172 DBG_DTOR( OCurrencyModel, NULL );
175 // XCloneable
176 //------------------------------------------------------------------------------
177 IMPLEMENT_DEFAULT_CLONING( OCurrencyModel )
179 // XServiceInfo
180 //------------------------------------------------------------------------------
181 StringSequence SAL_CALL OCurrencyModel::getSupportedServiceNames() throw()
183 StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
185 sal_Int32 nOldLen = aSupported.getLength();
186 aSupported.realloc( nOldLen + 4 );
187 ::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen;
189 *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
190 *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
192 *pStoreTo++ = FRM_SUN_COMPONENT_CURRENCYFIELD;
193 *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD;
195 return aSupported;
198 //------------------------------------------------------------------------------
199 void OCurrencyModel::describeFixedProperties( Sequence< Property >& _rProps ) const
201 BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel )
202 // Value auf transient setzen
203 // ModifyPropertyAttributes(_rAggregateProps, PROPERTY_VALUE, PropertyAttribute::TRANSIENT, 0);
205 DECL_PROP3(DEFAULT_VALUE, double, BOUND, MAYBEDEFAULT, MAYBEVOID);
206 DECL_PROP1(TABINDEX, sal_Int16, BOUND);
207 END_DESCRIBE_PROPERTIES();
210 //------------------------------------------------------------------------------
211 ::rtl::OUString SAL_CALL OCurrencyModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
213 return FRM_COMPONENT_CURRENCYFIELD; // old (non-sun) name for compatibility !
216 //------------------------------------------------------------------------------
217 sal_Bool OCurrencyModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
219 Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
220 if ( !compare( aControlValue, m_aSaveValue ) )
222 if ( aControlValue.getValueType().getTypeClass() == TypeClass_VOID )
223 m_xColumnUpdate->updateNull();
224 else
228 m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
230 catch(Exception&)
232 return sal_False;
235 m_aSaveValue = aControlValue;
237 return sal_True;
240 //------------------------------------------------------------------------------
241 Any OCurrencyModel::translateDbColumnToControlValue()
243 m_aSaveValue <<= m_xColumn->getDouble();
244 if ( m_xColumn->wasNull() )
245 m_aSaveValue.clear();
246 return m_aSaveValue;
249 // XReset
250 //------------------------------------------------------------------------------
251 Any OCurrencyModel::getDefaultForReset() const
253 Any aValue;
254 if ( m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE )
255 aValue = m_aDefault;
257 return aValue;
260 //.........................................................................
261 } // namespace frm
262 //.........................................................................