Line data Source code
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 "services.hxx"
22 : #include <unotools/localedatawrapper.hxx>
23 : #include <vcl/svapp.hxx>
24 : #include <unotools/syslocale.hxx>
25 : #include <comphelper/processfactory.hxx>
26 :
27 : namespace frm
28 : {
29 :
30 : using namespace ::com::sun::star::uno;
31 : using namespace ::com::sun::star::sdb;
32 : using namespace ::com::sun::star::sdbc;
33 : using namespace ::com::sun::star::sdbcx;
34 : using namespace ::com::sun::star::beans;
35 : using namespace ::com::sun::star::container;
36 : using namespace ::com::sun::star::form;
37 : using namespace ::com::sun::star::awt;
38 : using namespace ::com::sun::star::io;
39 : using namespace ::com::sun::star::lang;
40 : using namespace ::com::sun::star::util;
41 :
42 12 : OCurrencyControl::OCurrencyControl(const Reference<XComponentContext>& _rxFactory)
43 12 : :OBoundControl(_rxFactory, VCL_CONTROL_CURRENCYFIELD)
44 : {
45 12 : }
46 :
47 :
48 12 : InterfaceRef SAL_CALL OCurrencyControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
49 : {
50 12 : return *(new OCurrencyControl( comphelper::getComponentContext(_rxFactory) ));
51 : }
52 :
53 :
54 0 : Sequence<Type> OCurrencyControl::_getTypes()
55 : {
56 0 : return OBoundControl::_getTypes();
57 : }
58 :
59 :
60 0 : StringSequence SAL_CALL OCurrencyControl::getSupportedServiceNames() throw(std::exception)
61 : {
62 0 : StringSequence aSupported = OBoundControl::getSupportedServiceNames();
63 0 : aSupported.realloc(aSupported.getLength() + 1);
64 :
65 0 : OUString*pArray = aSupported.getArray();
66 0 : pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_CURRENCYFIELD;
67 0 : return aSupported;
68 : }
69 :
70 :
71 : // OCurrencyModel
72 :
73 :
74 18 : InterfaceRef SAL_CALL OCurrencyModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
75 : {
76 18 : return *(new OCurrencyModel( comphelper::getComponentContext(_rxFactory) ));
77 : }
78 :
79 :
80 0 : Sequence<Type> OCurrencyModel::_getTypes()
81 : {
82 0 : return OEditBaseModel::_getTypes();
83 : }
84 :
85 :
86 20 : void OCurrencyModel::implConstruct()
87 : {
88 20 : if (m_xAggregateSet.is())
89 : {
90 : try
91 : {
92 : // get the system international information
93 20 : const SvtSysLocale aSysLocale;
94 20 : const LocaleDataWrapper& aLocaleInfo = aSysLocale.GetLocaleData();
95 :
96 40 : OUString sCurrencySymbol;
97 20 : bool bPrependCurrencySymbol = false;
98 20 : switch ( aLocaleInfo.getCurrPositiveFormat() )
99 : {
100 : case 0: // $1
101 20 : sCurrencySymbol = aLocaleInfo.getCurrSymbol();
102 20 : bPrependCurrencySymbol = true;
103 20 : break;
104 : case 1: // 1$
105 0 : sCurrencySymbol = aLocaleInfo.getCurrSymbol();
106 0 : bPrependCurrencySymbol = false;
107 0 : break;
108 : case 2: // $ 1
109 0 : sCurrencySymbol = aLocaleInfo.getCurrSymbol() + " ";
110 0 : bPrependCurrencySymbol = true;
111 0 : break;
112 : case 3: // 1 $
113 0 : sCurrencySymbol = " " + aLocaleInfo.getCurrSymbol();
114 0 : bPrependCurrencySymbol = false;
115 0 : break;
116 : }
117 20 : if (!sCurrencySymbol.isEmpty())
118 : {
119 20 : m_xAggregateSet->setPropertyValue(PROPERTY_CURRENCYSYMBOL, makeAny(sCurrencySymbol));
120 20 : m_xAggregateSet->setPropertyValue(PROPERTY_CURRSYM_POSITION, makeAny(bPrependCurrencySymbol));
121 20 : }
122 : }
123 0 : catch(const Exception&)
124 : {
125 : OSL_FAIL( "OCurrencyModel::implConstruct: caught an exception while initializing the aggregate!" );
126 : }
127 : }
128 20 : }
129 :
130 :
131 :
132 18 : OCurrencyModel::OCurrencyModel(const Reference<XComponentContext>& _rxFactory)
133 18 : :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_CURRENCYFIELD, FRM_SUN_CONTROL_CURRENCYFIELD, false, true )
134 : // use the old control name for compaytibility reasons
135 : {
136 :
137 18 : m_nClassId = FormComponentType::CURRENCYFIELD;
138 18 : initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
139 :
140 18 : implConstruct();
141 18 : }
142 :
143 :
144 2 : OCurrencyModel::OCurrencyModel( const OCurrencyModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
145 2 : :OEditBaseModel( _pOriginal, _rxFactory )
146 : {
147 2 : implConstruct();
148 2 : }
149 :
150 :
151 40 : OCurrencyModel::~OCurrencyModel()
152 : {
153 40 : }
154 :
155 : // XCloneable
156 :
157 2 : IMPLEMENT_DEFAULT_CLONING( OCurrencyModel )
158 :
159 : // XServiceInfo
160 :
161 14 : StringSequence SAL_CALL OCurrencyModel::getSupportedServiceNames() throw(std::exception)
162 : {
163 14 : StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
164 :
165 14 : sal_Int32 nOldLen = aSupported.getLength();
166 14 : aSupported.realloc( nOldLen + 4 );
167 14 : OUString* pStoreTo = aSupported.getArray() + nOldLen;
168 :
169 14 : *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
170 14 : *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
171 :
172 14 : *pStoreTo++ = FRM_SUN_COMPONENT_CURRENCYFIELD;
173 14 : *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD;
174 :
175 14 : return aSupported;
176 : }
177 :
178 :
179 22 : void OCurrencyModel::describeFixedProperties( Sequence< Property >& _rProps ) const
180 : {
181 22 : BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel )
182 : // Set Value to transient
183 : // ModifyPropertyAttributes(_rAggregateProps, PROPERTY_VALUE, PropertyAttribute::TRANSIENT, 0);
184 :
185 22 : DECL_PROP3(DEFAULT_VALUE, double, BOUND, MAYBEDEFAULT, MAYBEVOID);
186 22 : DECL_PROP1(TABINDEX, sal_Int16, BOUND);
187 : END_DESCRIBE_PROPERTIES();
188 22 : }
189 :
190 :
191 2 : OUString SAL_CALL OCurrencyModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
192 : {
193 2 : return OUString(FRM_COMPONENT_CURRENCYFIELD); // old (non-sun) name for compatibility !
194 : }
195 :
196 :
197 0 : bool OCurrencyModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
198 : {
199 0 : Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
200 0 : if ( !compare( aControlValue, m_aSaveValue ) )
201 : {
202 0 : if ( aControlValue.getValueType().getTypeClass() == TypeClass_VOID )
203 0 : m_xColumnUpdate->updateNull();
204 : else
205 : {
206 : try
207 : {
208 0 : m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
209 : }
210 0 : catch(const Exception&)
211 : {
212 0 : return false;
213 : }
214 : }
215 0 : m_aSaveValue = aControlValue;
216 : }
217 0 : return true;
218 : }
219 :
220 :
221 0 : Any OCurrencyModel::translateDbColumnToControlValue()
222 : {
223 0 : m_aSaveValue <<= m_xColumn->getDouble();
224 0 : if ( m_xColumn->wasNull() )
225 0 : m_aSaveValue.clear();
226 0 : return m_aSaveValue;
227 : }
228 :
229 : // XReset
230 :
231 6 : Any OCurrencyModel::getDefaultForReset() const
232 : {
233 6 : Any aValue;
234 6 : if ( m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE )
235 0 : aValue = m_aDefault;
236 :
237 6 : return aValue;
238 : }
239 :
240 :
241 6 : void OCurrencyModel::resetNoBroadcast()
242 : {
243 6 : OEditBaseModel::resetNoBroadcast();
244 6 : m_aSaveValue.clear();
245 6 : }
246 :
247 :
248 192 : } // namespace frm
249 :
250 :
251 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|