1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <property.hxx>
22 #include <services.hxx>
23 #include <unotools/localedatawrapper.hxx>
24 #include <unotools/syslocale.hxx>
25 #include <comphelper/types.hxx>
26 #include <com/sun/star/form/FormComponentType.hpp>
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::sdb
;
34 using namespace ::com::sun::star::sdbc
;
35 using namespace ::com::sun::star::beans
;
36 using namespace ::com::sun::star::container
;
37 using namespace ::com::sun::star::form
;
38 using namespace ::com::sun::star::awt
;
39 using namespace ::com::sun::star::io
;
40 using namespace ::com::sun::star::lang
;
41 using namespace ::com::sun::star::util
;
43 OCurrencyControl::OCurrencyControl(const Reference
<XComponentContext
>& _rxFactory
)
44 :OBoundControl(_rxFactory
, VCL_CONTROL_CURRENCYFIELD
)
48 css::uno::Sequence
<OUString
> SAL_CALL
OCurrencyControl::getSupportedServiceNames()
50 css::uno::Sequence
<OUString
> aSupported
= OBoundControl::getSupportedServiceNames();
51 aSupported
.realloc(aSupported
.getLength() + 2);
53 OUString
*pArray
= aSupported
.getArray();
54 pArray
[aSupported
.getLength()-2] = FRM_SUN_CONTROL_CURRENCYFIELD
;
55 pArray
[aSupported
.getLength()-1] = STARDIV_ONE_FORM_CONTROL_CURRENCYFIELD
;
62 void OCurrencyModel::implConstruct()
64 if (!m_xAggregateSet
.is())
69 // get the system international information
70 const SvtSysLocale aSysLocale
;
71 const LocaleDataWrapper
& aLocaleInfo
= aSysLocale
.GetLocaleData();
73 OUString sCurrencySymbol
;
74 bool bPrependCurrencySymbol
= false;
75 switch ( aLocaleInfo
.getCurrPositiveFormat() )
78 sCurrencySymbol
= aLocaleInfo
.getCurrSymbol();
79 bPrependCurrencySymbol
= true;
82 sCurrencySymbol
= aLocaleInfo
.getCurrSymbol();
83 bPrependCurrencySymbol
= false;
86 sCurrencySymbol
= aLocaleInfo
.getCurrSymbol() + " ";
87 bPrependCurrencySymbol
= true;
90 sCurrencySymbol
= " " + aLocaleInfo
.getCurrSymbol();
91 bPrependCurrencySymbol
= false;
94 if (!sCurrencySymbol
.isEmpty())
96 m_xAggregateSet
->setPropertyValue(PROPERTY_CURRENCYSYMBOL
, makeAny(sCurrencySymbol
));
97 m_xAggregateSet
->setPropertyValue(PROPERTY_CURRSYM_POSITION
, makeAny(bPrependCurrencySymbol
));
100 catch(const Exception
&)
102 OSL_FAIL( "OCurrencyModel::implConstruct: caught an exception while initializing the aggregate!" );
107 OCurrencyModel::OCurrencyModel(const Reference
<XComponentContext
>& _rxFactory
)
108 :OEditBaseModel( _rxFactory
, VCL_CONTROLMODEL_CURRENCYFIELD
, FRM_SUN_CONTROL_CURRENCYFIELD
, false, true )
109 // use the old control name for compatibility reasons
112 m_nClassId
= FormComponentType::CURRENCYFIELD
;
113 initValueProperty( PROPERTY_VALUE
, PROPERTY_ID_VALUE
);
119 OCurrencyModel::OCurrencyModel( const OCurrencyModel
* _pOriginal
, const Reference
<XComponentContext
>& _rxFactory
)
120 :OEditBaseModel( _pOriginal
, _rxFactory
)
126 OCurrencyModel::~OCurrencyModel()
132 IMPLEMENT_DEFAULT_CLONING( OCurrencyModel
)
136 css::uno::Sequence
<OUString
> SAL_CALL
OCurrencyModel::getSupportedServiceNames()
138 css::uno::Sequence
<OUString
> aSupported
= OBoundControlModel::getSupportedServiceNames();
140 sal_Int32 nOldLen
= aSupported
.getLength();
141 aSupported
.realloc( nOldLen
+ 5 );
142 OUString
* pStoreTo
= aSupported
.getArray() + nOldLen
;
144 *pStoreTo
++ = DATA_AWARE_CONTROL_MODEL
;
145 *pStoreTo
++ = VALIDATABLE_CONTROL_MODEL
;
147 *pStoreTo
++ = FRM_SUN_COMPONENT_CURRENCYFIELD
;
148 *pStoreTo
++ = FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD
;
150 *pStoreTo
++ = FRM_COMPONENT_CURRENCYFIELD
;
156 void OCurrencyModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
158 BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel
)
159 // Set Value to transient
160 // ModifyPropertyAttributes(_rAggregateProps, PROPERTY_VALUE, PropertyAttribute::TRANSIENT, 0);
162 DECL_PROP3(DEFAULT_VALUE
, double, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
163 DECL_PROP1(TABINDEX
, sal_Int16
, BOUND
);
164 END_DESCRIBE_PROPERTIES();
168 OUString SAL_CALL
OCurrencyModel::getServiceName()
170 return FRM_COMPONENT_CURRENCYFIELD
; // old (non-sun) name for compatibility !
174 bool OCurrencyModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
176 Any
aControlValue( m_xAggregateFastSet
->getFastPropertyValue( getValuePropertyAggHandle() ) );
177 if ( aControlValue
!= m_aSaveValue
)
179 if ( aControlValue
.getValueType().getTypeClass() == TypeClass_VOID
)
180 m_xColumnUpdate
->updateNull();
185 m_xColumnUpdate
->updateDouble( getDouble( aControlValue
) );
187 catch(const Exception
&)
192 m_aSaveValue
= aControlValue
;
198 Any
OCurrencyModel::translateDbColumnToControlValue()
200 m_aSaveValue
<<= m_xColumn
->getDouble();
201 if ( m_xColumn
->wasNull() )
202 m_aSaveValue
.clear();
208 Any
OCurrencyModel::getDefaultForReset() const
211 if ( m_aDefault
.getValueType().getTypeClass() == TypeClass_DOUBLE
)
218 void OCurrencyModel::resetNoBroadcast()
220 OEditBaseModel::resetNoBroadcast();
221 m_aSaveValue
.clear();
227 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
228 com_sun_star_form_OCurrencyModel_get_implementation(css::uno::XComponentContext
* component
,
229 css::uno::Sequence
<css::uno::Any
> const &)
231 return cppu::acquire(new frm::OCurrencyModel(component
));
234 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
235 com_sun_star_form_OCurrencyControl_get_implementation(css::uno::XComponentContext
* component
,
236 css::uno::Sequence
<css::uno::Any
> const &)
238 return cppu::acquire(new frm::OCurrencyControl(component
));
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */