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 "services.hxx"
22 #include <unotools/localedatawrapper.hxx>
23 #include <vcl/svapp.hxx>
24 #include <unotools/syslocale.hxx>
25 #include <comphelper/processfactory.hxx>
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::sdb
;
33 using namespace ::com::sun::star::sdbc
;
34 using namespace ::com::sun::star::sdbcx
;
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 Sequence
<Type
> OCurrencyControl::_getTypes()
50 return OBoundControl::_getTypes();
54 StringSequence SAL_CALL
OCurrencyControl::getSupportedServiceNames() throw(std::exception
)
56 StringSequence aSupported
= OBoundControl::getSupportedServiceNames();
57 aSupported
.realloc(aSupported
.getLength() + 2);
59 OUString
*pArray
= aSupported
.getArray();
60 pArray
[aSupported
.getLength()-2] = FRM_SUN_CONTROL_CURRENCYFIELD
;
61 pArray
[aSupported
.getLength()-1] = STARDIV_ONE_FORM_CONTROL_CURRENCYFIELD
;
68 Sequence
<Type
> OCurrencyModel::_getTypes()
70 return OEditBaseModel::_getTypes();
74 void OCurrencyModel::implConstruct()
76 if (m_xAggregateSet
.is())
80 // get the system international information
81 const SvtSysLocale aSysLocale
;
82 const LocaleDataWrapper
& aLocaleInfo
= aSysLocale
.GetLocaleData();
84 OUString sCurrencySymbol
;
85 bool bPrependCurrencySymbol
= false;
86 switch ( aLocaleInfo
.getCurrPositiveFormat() )
89 sCurrencySymbol
= aLocaleInfo
.getCurrSymbol();
90 bPrependCurrencySymbol
= true;
93 sCurrencySymbol
= aLocaleInfo
.getCurrSymbol();
94 bPrependCurrencySymbol
= false;
97 sCurrencySymbol
= aLocaleInfo
.getCurrSymbol() + " ";
98 bPrependCurrencySymbol
= true;
101 sCurrencySymbol
= " " + aLocaleInfo
.getCurrSymbol();
102 bPrependCurrencySymbol
= false;
105 if (!sCurrencySymbol
.isEmpty())
107 m_xAggregateSet
->setPropertyValue(PROPERTY_CURRENCYSYMBOL
, makeAny(sCurrencySymbol
));
108 m_xAggregateSet
->setPropertyValue(PROPERTY_CURRSYM_POSITION
, makeAny(bPrependCurrencySymbol
));
111 catch(const Exception
&)
113 OSL_FAIL( "OCurrencyModel::implConstruct: caught an exception while initializing the aggregate!" );
120 OCurrencyModel::OCurrencyModel(const Reference
<XComponentContext
>& _rxFactory
)
121 :OEditBaseModel( _rxFactory
, VCL_CONTROLMODEL_CURRENCYFIELD
, FRM_SUN_CONTROL_CURRENCYFIELD
, false, true )
122 // use the old control name for compaytibility reasons
125 m_nClassId
= FormComponentType::CURRENCYFIELD
;
126 initValueProperty( PROPERTY_VALUE
, PROPERTY_ID_VALUE
);
132 OCurrencyModel::OCurrencyModel( const OCurrencyModel
* _pOriginal
, const Reference
<XComponentContext
>& _rxFactory
)
133 :OEditBaseModel( _pOriginal
, _rxFactory
)
139 OCurrencyModel::~OCurrencyModel()
145 IMPLEMENT_DEFAULT_CLONING( OCurrencyModel
)
149 StringSequence SAL_CALL
OCurrencyModel::getSupportedServiceNames() throw(std::exception
)
151 StringSequence aSupported
= OBoundControlModel::getSupportedServiceNames();
153 sal_Int32 nOldLen
= aSupported
.getLength();
154 aSupported
.realloc( nOldLen
+ 5 );
155 OUString
* pStoreTo
= aSupported
.getArray() + nOldLen
;
157 *pStoreTo
++ = DATA_AWARE_CONTROL_MODEL
;
158 *pStoreTo
++ = VALIDATABLE_CONTROL_MODEL
;
160 *pStoreTo
++ = FRM_SUN_COMPONENT_CURRENCYFIELD
;
161 *pStoreTo
++ = FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD
;
163 *pStoreTo
++ = FRM_COMPONENT_CURRENCYFIELD
;
169 void OCurrencyModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
171 BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel
)
172 // Set Value to transient
173 // ModifyPropertyAttributes(_rAggregateProps, PROPERTY_VALUE, PropertyAttribute::TRANSIENT, 0);
175 DECL_PROP3(DEFAULT_VALUE
, double, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
176 DECL_PROP1(TABINDEX
, sal_Int16
, BOUND
);
177 END_DESCRIBE_PROPERTIES();
181 OUString SAL_CALL
OCurrencyModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException
, std::exception
)
183 return OUString(FRM_COMPONENT_CURRENCYFIELD
); // old (non-sun) name for compatibility !
187 bool OCurrencyModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
189 Any
aControlValue( m_xAggregateFastSet
->getFastPropertyValue( getValuePropertyAggHandle() ) );
190 if ( !compare( aControlValue
, m_aSaveValue
) )
192 if ( aControlValue
.getValueType().getTypeClass() == TypeClass_VOID
)
193 m_xColumnUpdate
->updateNull();
198 m_xColumnUpdate
->updateDouble( getDouble( aControlValue
) );
200 catch(const Exception
&)
205 m_aSaveValue
= aControlValue
;
211 Any
OCurrencyModel::translateDbColumnToControlValue()
213 m_aSaveValue
<<= m_xColumn
->getDouble();
214 if ( m_xColumn
->wasNull() )
215 m_aSaveValue
.clear();
221 Any
OCurrencyModel::getDefaultForReset() const
224 if ( m_aDefault
.getValueType().getTypeClass() == TypeClass_DOUBLE
)
231 void OCurrencyModel::resetNoBroadcast()
233 OEditBaseModel::resetNoBroadcast();
234 m_aSaveValue
.clear();
240 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface
* SAL_CALL
241 com_sun_star_form_OCurrencyModel_get_implementation(::com::sun::star::uno::XComponentContext
* component
,
242 ::com::sun::star::uno::Sequence
<css::uno::Any
> const &)
244 return cppu::acquire(new frm::OCurrencyModel(component
));
247 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface
* SAL_CALL
248 com_sun_star_form_OCurrencyControl_get_implementation(::com::sun::star::uno::XComponentContext
* component
,
249 ::com::sun::star::uno::Sequence
<css::uno::Any
> const &)
251 return cppu::acquire(new frm::OCurrencyControl(component
));
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */