LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / forms / source / component / Currency.cxx
blobfe3018659df80328d1c6dd401c5093cb782b9dac
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <tools/diagnose_ex.h>
27 #include <com/sun/star/form/FormComponentType.hpp>
30 namespace frm
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::sdb;
35 using namespace ::com::sun::star::sdbc;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::container;
38 using namespace ::com::sun::star::form;
39 using namespace ::com::sun::star::awt;
40 using namespace ::com::sun::star::io;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::util;
44 OCurrencyControl::OCurrencyControl(const Reference<XComponentContext>& _rxFactory)
45 :OBoundControl(_rxFactory, VCL_CONTROL_CURRENCYFIELD)
49 css::uno::Sequence<OUString> SAL_CALL OCurrencyControl::getSupportedServiceNames()
51 css::uno::Sequence<OUString> aSupported = OBoundControl::getSupportedServiceNames();
52 aSupported.realloc(aSupported.getLength() + 2);
54 OUString*pArray = aSupported.getArray();
55 pArray[aSupported.getLength()-2] = FRM_SUN_CONTROL_CURRENCYFIELD;
56 pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_CURRENCYFIELD;
57 return aSupported;
61 // OCurrencyModel
63 void OCurrencyModel::implConstruct()
65 if (!m_xAggregateSet.is())
66 return;
68 try
70 // get the system international information
71 const SvtSysLocale aSysLocale;
72 const LocaleDataWrapper& aLocaleInfo = aSysLocale.GetLocaleData();
74 OUString sCurrencySymbol;
75 bool bPrependCurrencySymbol = false;
76 switch ( aLocaleInfo.getCurrPositiveFormat() )
78 case 0: // $1
79 sCurrencySymbol = aLocaleInfo.getCurrSymbol();
80 bPrependCurrencySymbol = true;
81 break;
82 case 1: // 1$
83 sCurrencySymbol = aLocaleInfo.getCurrSymbol();
84 bPrependCurrencySymbol = false;
85 break;
86 case 2: // $ 1
87 sCurrencySymbol = aLocaleInfo.getCurrSymbol() + " ";
88 bPrependCurrencySymbol = true;
89 break;
90 case 3: // 1 $
91 sCurrencySymbol = " " + aLocaleInfo.getCurrSymbol();
92 bPrependCurrencySymbol = false;
93 break;
95 if (!sCurrencySymbol.isEmpty())
97 m_xAggregateSet->setPropertyValue(PROPERTY_CURRENCYSYMBOL, makeAny(sCurrencySymbol));
98 m_xAggregateSet->setPropertyValue(PROPERTY_CURRSYM_POSITION, makeAny(bPrependCurrencySymbol));
101 catch(const Exception&)
103 TOOLS_WARN_EXCEPTION( "forms.component", "OCurrencyModel::implConstruct: caught an exception while initializing the aggregate!" );
108 OCurrencyModel::OCurrencyModel(const Reference<XComponentContext>& _rxFactory)
109 :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_CURRENCYFIELD, FRM_SUN_CONTROL_CURRENCYFIELD, false, true )
110 // use the old control name for compatibility reasons
113 m_nClassId = FormComponentType::CURRENCYFIELD;
114 initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
116 implConstruct();
120 OCurrencyModel::OCurrencyModel( const OCurrencyModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
121 :OEditBaseModel( _pOriginal, _rxFactory )
123 implConstruct();
127 OCurrencyModel::~OCurrencyModel()
131 // XCloneable
133 css::uno::Reference< css::util::XCloneable > SAL_CALL OCurrencyModel::createClone()
135 rtl::Reference<OCurrencyModel> pClone = new OCurrencyModel(this, getContext());
136 pClone->clonedFrom(this);
137 return pClone;
141 // XServiceInfo
143 css::uno::Sequence<OUString> SAL_CALL OCurrencyModel::getSupportedServiceNames()
145 css::uno::Sequence<OUString> aSupported = OBoundControlModel::getSupportedServiceNames();
147 sal_Int32 nOldLen = aSupported.getLength();
148 aSupported.realloc( nOldLen + 5 );
149 OUString* pStoreTo = aSupported.getArray() + nOldLen;
151 *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
152 *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
154 *pStoreTo++ = FRM_SUN_COMPONENT_CURRENCYFIELD;
155 *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD;
157 *pStoreTo++ = FRM_COMPONENT_CURRENCYFIELD;
159 return aSupported;
163 void OCurrencyModel::describeFixedProperties( Sequence< Property >& _rProps ) const
165 OEditBaseModel::describeFixedProperties( _rProps );
166 sal_Int32 nOldCount = _rProps.getLength();
167 _rProps.realloc( nOldCount + 2);
168 css::beans::Property* pProperties = _rProps.getArray() + nOldCount;
169 // Set Value to transient
170 // ModifyPropertyAttributes(_rAggregateProps, PROPERTY_VALUE, PropertyAttribute::TRANSIENT, 0);
172 *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);
173 *pProperties++ = css::beans::Property(PROPERTY_TABINDEX, PROPERTY_ID_TABINDEX, cppu::UnoType<sal_Int16>::get(), css::beans::PropertyAttribute::BOUND);
174 DBG_ASSERT( pProperties == _rProps.getArray() + _rProps.getLength(), "<...>::describeFixedProperties/getInfoHelper: forgot to adjust the count ?");
178 OUString SAL_CALL OCurrencyModel::getServiceName()
180 return FRM_COMPONENT_CURRENCYFIELD; // old (non-sun) name for compatibility !
184 bool OCurrencyModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
186 Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
187 if ( aControlValue != m_aSaveValue )
189 if ( aControlValue.getValueType().getTypeClass() == TypeClass_VOID )
190 m_xColumnUpdate->updateNull();
191 else
195 m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
197 catch(const Exception&)
199 return false;
202 m_aSaveValue = aControlValue;
204 return true;
208 Any OCurrencyModel::translateDbColumnToControlValue()
210 m_aSaveValue <<= m_xColumn->getDouble();
211 if ( m_xColumn->wasNull() )
212 m_aSaveValue.clear();
213 return m_aSaveValue;
216 // XReset
218 Any OCurrencyModel::getDefaultForReset() const
220 Any aValue;
221 if ( m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE )
222 aValue = m_aDefault;
224 return aValue;
228 void OCurrencyModel::resetNoBroadcast()
230 OEditBaseModel::resetNoBroadcast();
231 m_aSaveValue.clear();
235 } // namespace frm
237 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
238 com_sun_star_form_OCurrencyModel_get_implementation(css::uno::XComponentContext* component,
239 css::uno::Sequence<css::uno::Any> const &)
241 return cppu::acquire(new frm::OCurrencyModel(component));
244 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
245 com_sun_star_form_OCurrencyControl_get_implementation(css::uno::XComponentContext* component,
246 css::uno::Sequence<css::uno::Any> const &)
248 return cppu::acquire(new frm::OCurrencyControl(component));
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */