1*24acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*24acc546SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*24acc546SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*24acc546SAndrew Rist  * distributed with this work for additional information
6*24acc546SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*24acc546SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*24acc546SAndrew Rist  * "License"); you may not use this file except in compliance
9*24acc546SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*24acc546SAndrew Rist  *
11*24acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*24acc546SAndrew Rist  *
13*24acc546SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*24acc546SAndrew Rist  * software distributed under the License is distributed on an
15*24acc546SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*24acc546SAndrew Rist  * KIND, either express or implied.  See the License for the
17*24acc546SAndrew Rist  * specific language governing permissions and limitations
18*24acc546SAndrew Rist  * under the License.
19*24acc546SAndrew Rist  *
20*24acc546SAndrew Rist  *************************************************************/
21*24acc546SAndrew Rist 
22*24acc546SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir #include "Currency.hxx"
27cdf0e10cSrcweir #include <tools/debug.hxx>
28cdf0e10cSrcweir #include <unotools/localedatawrapper.hxx>
29cdf0e10cSrcweir #include <vcl/svapp.hxx>
30cdf0e10cSrcweir #include <unotools/syslocale.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir //.........................................................................
33cdf0e10cSrcweir namespace frm
34cdf0e10cSrcweir {
35cdf0e10cSrcweir //.........................................................................
36cdf0e10cSrcweir using namespace ::com::sun::star::uno;
37cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
38cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
39cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
40cdf0e10cSrcweir using namespace ::com::sun::star::beans;
41cdf0e10cSrcweir using namespace ::com::sun::star::container;
42cdf0e10cSrcweir using namespace ::com::sun::star::form;
43cdf0e10cSrcweir using namespace ::com::sun::star::awt;
44cdf0e10cSrcweir using namespace ::com::sun::star::io;
45cdf0e10cSrcweir using namespace ::com::sun::star::lang;
46cdf0e10cSrcweir using namespace ::com::sun::star::util;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir //==================================================================
49cdf0e10cSrcweir // OCurrencyControl
50cdf0e10cSrcweir //==================================================================
51cdf0e10cSrcweir //------------------------------------------------------------------
OCurrencyControl(const Reference<XMultiServiceFactory> & _rxFactory)52cdf0e10cSrcweir OCurrencyControl::OCurrencyControl(const Reference<XMultiServiceFactory>& _rxFactory)
53cdf0e10cSrcweir 	:OBoundControl(_rxFactory, VCL_CONTROL_CURRENCYFIELD)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //------------------------------------------------------------------
OCurrencyControl_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)58cdf0e10cSrcweir InterfaceRef SAL_CALL OCurrencyControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
59cdf0e10cSrcweir {
60cdf0e10cSrcweir 	return *(new OCurrencyControl(_rxFactory));
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir //------------------------------------------------------------------------------
_getTypes()64cdf0e10cSrcweir Sequence<Type> OCurrencyControl::_getTypes()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	return OBoundControl::_getTypes();
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir //------------------------------------------------------------------------------
getSupportedServiceNames()70cdf0e10cSrcweir StringSequence SAL_CALL OCurrencyControl::getSupportedServiceNames() throw()
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	StringSequence aSupported = OBoundControl::getSupportedServiceNames();
73cdf0e10cSrcweir 	aSupported.realloc(aSupported.getLength() + 1);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	::rtl::OUString*pArray = aSupported.getArray();
76cdf0e10cSrcweir 	pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_CURRENCYFIELD;
77cdf0e10cSrcweir 	return aSupported;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir //==================================================================
81cdf0e10cSrcweir // OCurrencyModel
82cdf0e10cSrcweir //==================================================================
83cdf0e10cSrcweir //------------------------------------------------------------------
OCurrencyModel_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)84cdf0e10cSrcweir InterfaceRef SAL_CALL OCurrencyModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 	return *(new OCurrencyModel(_rxFactory));
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
89cdf0e10cSrcweir //------------------------------------------------------------------------------
_getTypes()90cdf0e10cSrcweir Sequence<Type> OCurrencyModel::_getTypes()
91cdf0e10cSrcweir {
92cdf0e10cSrcweir 	return OEditBaseModel::_getTypes();
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir //------------------------------------------------------------------
implConstruct()96cdf0e10cSrcweir void OCurrencyModel::implConstruct()
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	if (m_xAggregateSet.is())
99cdf0e10cSrcweir 	{
100cdf0e10cSrcweir 		try
101cdf0e10cSrcweir 		{
102cdf0e10cSrcweir 			// get the system international informations
103cdf0e10cSrcweir             const SvtSysLocale aSysLocale;
104cdf0e10cSrcweir 			const LocaleDataWrapper& aLocaleInfo = aSysLocale.GetLocaleData();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 			::rtl::OUString sCurrencySymbol;
107cdf0e10cSrcweir 			sal_Bool bPrependCurrencySymbol;
108cdf0e10cSrcweir 			switch ( aLocaleInfo.getCurrPositiveFormat() )
109cdf0e10cSrcweir 			{
110cdf0e10cSrcweir 				case 0:	// $1
111cdf0e10cSrcweir 					sCurrencySymbol = String(aLocaleInfo.getCurrSymbol());
112cdf0e10cSrcweir 					bPrependCurrencySymbol = sal_True;
113cdf0e10cSrcweir 					break;
114cdf0e10cSrcweir 				case 1:	// 1$
115cdf0e10cSrcweir 					sCurrencySymbol = String(aLocaleInfo.getCurrSymbol());
116cdf0e10cSrcweir 					bPrependCurrencySymbol = sal_False;
117cdf0e10cSrcweir 					break;
118cdf0e10cSrcweir 				case 2:	// $ 1
119cdf0e10cSrcweir 					sCurrencySymbol = ::rtl::OUString(String(aLocaleInfo.getCurrSymbol())) + ::rtl::OUString::createFromAscii(" ");
120cdf0e10cSrcweir 					bPrependCurrencySymbol = sal_True;
121cdf0e10cSrcweir 					break;
122cdf0e10cSrcweir 				case 3: // 1 $
123cdf0e10cSrcweir 					sCurrencySymbol = ::rtl::OUString::createFromAscii(" ") + ::rtl::OUString(String(aLocaleInfo.getCurrSymbol()));
124cdf0e10cSrcweir 					bPrependCurrencySymbol = sal_False;
125cdf0e10cSrcweir 					break;
126cdf0e10cSrcweir 			}
127cdf0e10cSrcweir 			if (sCurrencySymbol.getLength())
128cdf0e10cSrcweir 			{
129cdf0e10cSrcweir 				m_xAggregateSet->setPropertyValue(PROPERTY_CURRENCYSYMBOL, makeAny(sCurrencySymbol));
130cdf0e10cSrcweir 				m_xAggregateSet->setPropertyValue(PROPERTY_CURRSYM_POSITION, makeAny(bPrependCurrencySymbol));
131cdf0e10cSrcweir 			}
132cdf0e10cSrcweir 		}
133cdf0e10cSrcweir 		catch(Exception&)
134cdf0e10cSrcweir 		{
135cdf0e10cSrcweir 			DBG_ERROR( "OCurrencyModel::implConstruct: caught an exception while initializing the aggregate!" );
136cdf0e10cSrcweir 		}
137cdf0e10cSrcweir 	}
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir //------------------------------------------------------------------
DBG_NAME(OCurrencyModel)141cdf0e10cSrcweir DBG_NAME( OCurrencyModel )
142cdf0e10cSrcweir //------------------------------------------------------------------
143cdf0e10cSrcweir OCurrencyModel::OCurrencyModel(const Reference<XMultiServiceFactory>& _rxFactory)
144cdf0e10cSrcweir 	:OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_CURRENCYFIELD, FRM_SUN_CONTROL_CURRENCYFIELD, sal_False, sal_True )
145cdf0e10cSrcweir 									// use the old control name for compytibility reasons
146cdf0e10cSrcweir {
147cdf0e10cSrcweir 	DBG_CTOR( OCurrencyModel, NULL );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	m_nClassId = FormComponentType::CURRENCYFIELD;
150cdf0e10cSrcweir     initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	implConstruct();
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir //------------------------------------------------------------------
OCurrencyModel(const OCurrencyModel * _pOriginal,const Reference<XMultiServiceFactory> & _rxFactory)156cdf0e10cSrcweir OCurrencyModel::OCurrencyModel( const OCurrencyModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
157cdf0e10cSrcweir 	:OEditBaseModel( _pOriginal, _rxFactory )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir 	DBG_CTOR( OCurrencyModel, NULL );
160cdf0e10cSrcweir 	implConstruct();
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir //------------------------------------------------------------------
~OCurrencyModel()164cdf0e10cSrcweir OCurrencyModel::~OCurrencyModel()
165cdf0e10cSrcweir {
166cdf0e10cSrcweir 	DBG_DTOR( OCurrencyModel, NULL );
167cdf0e10cSrcweir }
168cdf0e10cSrcweir 
169cdf0e10cSrcweir // XCloneable
170cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPLEMENT_DEFAULT_CLONING(OCurrencyModel)171cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( OCurrencyModel )
172cdf0e10cSrcweir 
173cdf0e10cSrcweir // XServiceInfo
174cdf0e10cSrcweir //------------------------------------------------------------------------------
175cdf0e10cSrcweir StringSequence SAL_CALL OCurrencyModel::getSupportedServiceNames() throw()
176cdf0e10cSrcweir {
177cdf0e10cSrcweir 	StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     sal_Int32 nOldLen = aSupported.getLength();
180cdf0e10cSrcweir 	aSupported.realloc( nOldLen + 4 );
181cdf0e10cSrcweir 	::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen;
182cdf0e10cSrcweir 
183cdf0e10cSrcweir     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
184cdf0e10cSrcweir     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     *pStoreTo++ = FRM_SUN_COMPONENT_CURRENCYFIELD;
187cdf0e10cSrcweir     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 	return aSupported;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir //------------------------------------------------------------------------------
describeFixedProperties(Sequence<Property> & _rProps) const193cdf0e10cSrcweir void OCurrencyModel::describeFixedProperties( Sequence< Property >& _rProps ) const
194cdf0e10cSrcweir {
195cdf0e10cSrcweir 	BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel )
196cdf0e10cSrcweir 		// Value auf transient setzen
197cdf0e10cSrcweir //		ModifyPropertyAttributes(_rAggregateProps, PROPERTY_VALUE, PropertyAttribute::TRANSIENT, 0);
198cdf0e10cSrcweir 
199cdf0e10cSrcweir 		DECL_PROP3(DEFAULT_VALUE,		double,				BOUND, MAYBEDEFAULT, MAYBEVOID);
200cdf0e10cSrcweir 		DECL_PROP1(TABINDEX,		sal_Int16,				BOUND);
201cdf0e10cSrcweir 	END_DESCRIBE_PROPERTIES();
202cdf0e10cSrcweir }
203cdf0e10cSrcweir 
204cdf0e10cSrcweir //------------------------------------------------------------------------------
getServiceName()205cdf0e10cSrcweir ::rtl::OUString SAL_CALL OCurrencyModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
206cdf0e10cSrcweir {
207cdf0e10cSrcweir 	return FRM_COMPONENT_CURRENCYFIELD;	// old (non-sun) name for compatibility !
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir //------------------------------------------------------------------------------
commitControlValueToDbColumn(bool)211cdf0e10cSrcweir sal_Bool OCurrencyModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
212cdf0e10cSrcweir {
213cdf0e10cSrcweir 	Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
214cdf0e10cSrcweir 	if ( !compare( aControlValue, m_aSaveValue ) )
215cdf0e10cSrcweir 	{
216cdf0e10cSrcweir 		if ( aControlValue.getValueType().getTypeClass() == TypeClass_VOID )
217cdf0e10cSrcweir 			m_xColumnUpdate->updateNull();
218cdf0e10cSrcweir 		else
219cdf0e10cSrcweir 		{
220cdf0e10cSrcweir 			try
221cdf0e10cSrcweir 			{
222cdf0e10cSrcweir 				m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
223cdf0e10cSrcweir 			}
224cdf0e10cSrcweir 			catch(Exception&)
225cdf0e10cSrcweir 			{
226cdf0e10cSrcweir 				return sal_False;
227cdf0e10cSrcweir 			}
228cdf0e10cSrcweir 		}
229cdf0e10cSrcweir 		m_aSaveValue = aControlValue;
230cdf0e10cSrcweir 	}
231cdf0e10cSrcweir 	return sal_True;
232cdf0e10cSrcweir }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir //------------------------------------------------------------------------------
translateDbColumnToControlValue()235cdf0e10cSrcweir Any OCurrencyModel::translateDbColumnToControlValue()
236cdf0e10cSrcweir {
237cdf0e10cSrcweir 	m_aSaveValue <<= m_xColumn->getDouble();
238cdf0e10cSrcweir 	if ( m_xColumn->wasNull() )
239cdf0e10cSrcweir 		m_aSaveValue.clear();
240cdf0e10cSrcweir     return m_aSaveValue;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir // XReset
244cdf0e10cSrcweir //------------------------------------------------------------------------------
getDefaultForReset() const245cdf0e10cSrcweir Any OCurrencyModel::getDefaultForReset() const
246cdf0e10cSrcweir {
247cdf0e10cSrcweir 	Any aValue;
248cdf0e10cSrcweir 	if ( m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE )
249cdf0e10cSrcweir 		aValue = m_aDefault;
250cdf0e10cSrcweir 
251cdf0e10cSrcweir     return aValue;
252cdf0e10cSrcweir }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir //------------------------------------------------------------------------------
resetNoBroadcast()255cdf0e10cSrcweir void OCurrencyModel::resetNoBroadcast()
256cdf0e10cSrcweir {
257cdf0e10cSrcweir     OEditBaseModel::resetNoBroadcast();
258cdf0e10cSrcweir     m_aSaveValue.clear();
259cdf0e10cSrcweir }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir //.........................................................................
262cdf0e10cSrcweir }	// namespace frm
263cdf0e10cSrcweir //.........................................................................
264cdf0e10cSrcweir 
265