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