LibreOffice Module forms (master) 1
Currency.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "Currency.hxx"
21#include <property.hxx>
22#include <services.hxx>
25#include <comphelper/types.hxx>
26#include <tools/debug.hxx>
28#include <com/sun/star/beans/PropertyAttribute.hpp>
29#include <com/sun/star/form/FormComponentType.hpp>
30
31
32namespace frm
33{
34
35using namespace ::com::sun::star::uno;
36using namespace ::com::sun::star::sdb;
37using namespace ::com::sun::star::sdbc;
38using namespace ::com::sun::star::beans;
39using namespace ::com::sun::star::container;
40using namespace ::com::sun::star::form;
41using namespace ::com::sun::star::awt;
42using namespace ::com::sun::star::io;
43using namespace ::com::sun::star::lang;
44using namespace ::com::sun::star::util;
45
46OCurrencyControl::OCurrencyControl(const Reference<XComponentContext>& _rxFactory)
48{
49}
50
51css::uno::Sequence<OUString> SAL_CALL OCurrencyControl::getSupportedServiceNames()
52{
53 css::uno::Sequence<OUString> aSupported = OBoundControl::getSupportedServiceNames();
54 aSupported.realloc(aSupported.getLength() + 2);
55
56 OUString*pArray = aSupported.getArray();
57 pArray[aSupported.getLength()-2] = FRM_SUN_CONTROL_CURRENCYFIELD;
58 pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_CURRENCYFIELD;
59 return aSupported;
60}
61
62
63// OCurrencyModel
64
66{
67 if (!m_xAggregateSet.is())
68 return;
69
70 try
71 {
72 // get the system international information
73 const SvtSysLocale aSysLocale;
74 const LocaleDataWrapper& aLocaleInfo = aSysLocale.GetLocaleData();
75
76 OUString sCurrencySymbol;
77 bool bPrependCurrencySymbol = false;
78 switch ( aLocaleInfo.getCurrPositiveFormat() )
79 {
80 case 0: // $1
81 sCurrencySymbol = aLocaleInfo.getCurrSymbol();
82 bPrependCurrencySymbol = true;
83 break;
84 case 1: // 1$
85 sCurrencySymbol = aLocaleInfo.getCurrSymbol();
86 bPrependCurrencySymbol = false;
87 break;
88 case 2: // $ 1
89 sCurrencySymbol = aLocaleInfo.getCurrSymbol() + " ";
90 bPrependCurrencySymbol = true;
91 break;
92 case 3: // 1 $
93 sCurrencySymbol = " " + aLocaleInfo.getCurrSymbol();
94 bPrependCurrencySymbol = false;
95 break;
96 }
97 if (!sCurrencySymbol.isEmpty())
98 {
99 m_xAggregateSet->setPropertyValue(PROPERTY_CURRENCYSYMBOL, Any(sCurrencySymbol));
100 m_xAggregateSet->setPropertyValue(PROPERTY_CURRSYM_POSITION, Any(bPrependCurrencySymbol));
101 }
102 }
103 catch(const Exception&)
104 {
105 TOOLS_WARN_EXCEPTION( "forms.component", "OCurrencyModel::implConstruct: caught an exception while initializing the aggregate!" );
106 }
107}
108
109
110OCurrencyModel::OCurrencyModel(const Reference<XComponentContext>& _rxFactory)
112 // use the old control name for compatibility reasons
113{
114
115 m_nClassId = FormComponentType::CURRENCYFIELD;
117
119}
120
121
122OCurrencyModel::OCurrencyModel( const OCurrencyModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
123 :OEditBaseModel( _pOriginal, _rxFactory )
124{
126}
127
128
130{
131}
132
133// XCloneable
134
135css::uno::Reference< css::util::XCloneable > SAL_CALL OCurrencyModel::createClone()
136{
138 pClone->clonedFrom(this);
139 return pClone;
140}
141
142
143// XServiceInfo
144
145css::uno::Sequence<OUString> SAL_CALL OCurrencyModel::getSupportedServiceNames()
146{
147 css::uno::Sequence<OUString> aSupported = OBoundControlModel::getSupportedServiceNames();
148
149 sal_Int32 nOldLen = aSupported.getLength();
150 aSupported.realloc( nOldLen + 5 );
151 OUString* pStoreTo = aSupported.getArray() + nOldLen;
152
153 *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
154 *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
155
158
159 *pStoreTo++ = FRM_COMPONENT_CURRENCYFIELD;
160
161 return aSupported;
162}
163
164
165void OCurrencyModel::describeFixedProperties( Sequence< Property >& _rProps ) const
166{
168 sal_Int32 nOldCount = _rProps.getLength();
169 _rProps.realloc( nOldCount + 2);
170 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
171 // Set Value to transient
172 // ModifyPropertyAttributes(_rAggregateProps, PROPERTY_VALUE, PropertyAttribute::TRANSIENT, 0);
173
174 *pProperties++ = css::beans::Property(PROPERTY_DEFAULT_VALUE, PROPERTY_ID_DEFAULT_VALUE, cppu::UnoType<double>::get(), css::beans::PropertyAttribute::BOUND | css::beans::PropertyAttribute::MAYBEDEFAULT | css::beans::PropertyAttribute::MAYBEVOID);
175 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND);
176 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
177}
178
179
181{
182 return FRM_COMPONENT_CURRENCYFIELD; // old (non-sun) name for compatibility !
183}
184
185
187{
188 Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
189 if ( aControlValue != m_aSaveValue )
190 {
191 if ( aControlValue.getValueType().getTypeClass() == TypeClass_VOID )
192 m_xColumnUpdate->updateNull();
193 else
194 {
195 try
196 {
197 m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
198 }
199 catch(const Exception&)
200 {
201 return false;
202 }
203 }
204 m_aSaveValue = aControlValue;
205 }
206 return true;
207}
208
209
211{
212 m_aSaveValue <<= m_xColumn->getDouble();
213 if ( m_xColumn->wasNull() )
214 m_aSaveValue.clear();
215 return m_aSaveValue;
216}
217
218// XReset
219
221{
222 Any aValue;
223 if ( m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE )
224 aValue = m_aDefault;
225
226 return aValue;
227}
228
229
231{
233 m_aSaveValue.clear();
234}
235
236
237} // namespace frm
238
239extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
240com_sun_star_form_OCurrencyModel_get_implementation(css::uno::XComponentContext* component,
241 css::uno::Sequence<css::uno::Any> const &)
242{
243 return cppu::acquire(new frm::OCurrencyModel(component));
244}
245
246extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
247com_sun_star_form_OCurrencyControl_get_implementation(css::uno::XComponentContext* component,
248 css::uno::Sequence<css::uno::Any> const &)
249{
250 return cppu::acquire(new frm::OCurrencyControl(component));
251}
252
253/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_OCurrencyModel_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
Definition: Currency.cxx:240
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_form_OCurrencyControl_get_implementation(css::uno::XComponentContext *component, css::uno::Sequence< css::uno::Any > const &)
Definition: Currency.cxx:247
const OUString & getCurrSymbol() const
sal_uInt16 getCurrPositiveFormat() const
const LocaleDataWrapper & GetLocaleData() const
sal_Int32 getValuePropertyAggHandle() const
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void initValueProperty(const OUString &_rValuePropertyName, sal_Int32 _nValuePropertyExternalHandle)
initializes the part of the class which is related to the control value.
css::uno::Reference< css::sdb::XColumn > m_xColumn
virtual void describeFixedProperties(css::uno::Sequence< css::beans::Property > &_rProps) const override
describes the properties provided by this class, or its respective derived class
virtual void resetNoBroadcast()
called to reset the control to some kind of default.
css::uno::Reference< css::sdb::XColumnUpdate > m_xColumnUpdate
const css::uno::Reference< css::uno::XComponentContext > & getContext() const
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
OCurrencyControl(const css::uno::Reference< css::uno::XComponentContext > &_rxContext)
Definition: Currency.cxx:46
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: Currency.cxx:51
virtual void describeFixedProperties(css::uno::Sequence< css::beans::Property > &_rProps) const override
describes the properties provided by this class, or its respective derived class
Definition: Currency.cxx:165
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: Currency.cxx:135
virtual ~OCurrencyModel() override
Definition: Currency.cxx:129
virtual bool commitControlValueToDbColumn(bool _bPostReset) override
commits the current control value to the database column we're bound to @precond we're properly bound...
Definition: Currency.cxx:186
css::uno::Any m_aSaveValue
Definition: Currency.hxx:31
virtual OUString SAL_CALL getServiceName() override
Definition: Currency.cxx:180
virtual css::uno::Any translateDbColumnToControlValue() override
translates a db column value into a control value.
Definition: Currency.cxx:210
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: Currency.cxx:145
OCurrencyModel(const css::uno::Reference< css::uno::XComponentContext > &_rxFactory)
virtual css::uno::Any getDefaultForReset() const override
returns the default which should be used when resetting the control
Definition: Currency.cxx:220
virtual void resetNoBroadcast() override
called to reset the control to some kind of default.
Definition: Currency.cxx:230
css::uno::Any m_aDefault
Definition: EditBase.hxx:44
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
constexpr OUStringLiteral PROPERTY_TABINDEX
Definition: frm_strings.hxx:26
constexpr OUStringLiteral PROPERTY_DEFAULT_VALUE
Definition: frm_strings.hxx:88
constexpr OUStringLiteral PROPERTY_CURRSYM_POSITION
constexpr OUStringLiteral PROPERTY_CURRENCYSYMBOL
constexpr OUStringLiteral PROPERTY_VALUE
Definition: frm_strings.hxx:32
@ Exception
double getDouble(const Any &_rAny)
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
#define PROPERTY_ID_DEFAULT_VALUE
Definition: property.hxx:110
#define PROPERTY_ID_VALUE
Definition: property.hxx:66
#define PROPERTY_ID_TABINDEX
Definition: property.hxx:41
constexpr OUStringLiteral STARDIV_ONE_FORM_CONTROL_CURRENCYFIELD
Definition: services.hxx:102
constexpr OUStringLiteral FRM_SUN_COMPONENT_CURRENCYFIELD
Definition: services.hxx:127
constexpr OUStringLiteral FRM_SUN_CONTROL_CURRENCYFIELD
Definition: services.hxx:162
constexpr OUStringLiteral FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD
Definition: services.hxx:147
constexpr OUStringLiteral FRM_COMPONENT_CURRENCYFIELD
Definition: services.hxx:81
constexpr OUStringLiteral VCL_CONTROL_CURRENCYFIELD
Definition: services.hxx:34
constexpr OUStringLiteral VCL_CONTROLMODEL_CURRENCYFIELD
Definition: services.hxx:52
constexpr OUStringLiteral DATA_AWARE_CONTROL_MODEL
Definition: services.hxx:182
constexpr OUStringLiteral VALIDATABLE_CONTROL_MODEL
Definition: services.hxx:183