1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Currency.cxx,v $
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 //.........................................................................
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 //==================================================================
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
;
87 //==================================================================
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() )
117 sCurrencySymbol
= String(aLocaleInfo
.getCurrSymbol());
118 bPrependCurrencySymbol
= sal_True
;
121 sCurrencySymbol
= String(aLocaleInfo
.getCurrSymbol());
122 bPrependCurrencySymbol
= sal_False
;
125 sCurrencySymbol
= ::rtl::OUString(String(aLocaleInfo
.getCurrSymbol())) + ::rtl::OUString::createFromAscii(" ");
126 bPrependCurrencySymbol
= sal_True
;
129 sCurrencySymbol
= ::rtl::OUString::createFromAscii(" ") + ::rtl::OUString(String(aLocaleInfo
.getCurrSymbol()));
130 bPrependCurrencySymbol
= sal_False
;
133 if (sCurrencySymbol
.getLength())
135 m_xAggregateSet
->setPropertyValue(PROPERTY_CURRENCYSYMBOL
, makeAny(sCurrencySymbol
));
136 m_xAggregateSet
->setPropertyValue(PROPERTY_CURRSYM_POSITION
, makeAny(bPrependCurrencySymbol
));
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
);
161 //------------------------------------------------------------------
162 OCurrencyModel::OCurrencyModel( const OCurrencyModel
* _pOriginal
, const Reference
<XMultiServiceFactory
>& _rxFactory
)
163 :OEditBaseModel( _pOriginal
, _rxFactory
)
165 DBG_CTOR( OCurrencyModel
, NULL
);
169 //------------------------------------------------------------------
170 OCurrencyModel::~OCurrencyModel()
172 DBG_DTOR( OCurrencyModel
, NULL
);
176 //------------------------------------------------------------------------------
177 IMPLEMENT_DEFAULT_CLONING( OCurrencyModel
)
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
;
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();
228 m_xColumnUpdate
->updateDouble( getDouble( aControlValue
) );
235 m_aSaveValue
= aControlValue
;
240 //------------------------------------------------------------------------------
241 Any
OCurrencyModel::translateDbColumnToControlValue()
243 m_aSaveValue
<<= m_xColumn
->getDouble();
244 if ( m_xColumn
->wasNull() )
245 m_aSaveValue
.clear();
250 //------------------------------------------------------------------------------
251 Any
OCurrencyModel::getDefaultForReset() const
254 if ( m_aDefault
.getValueType().getTypeClass() == TypeClass_DOUBLE
)
260 //.........................................................................
262 //.........................................................................