Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "Currency.hxx"
30 : : #include <tools/debug.hxx>
31 : : #include <unotools/localedatawrapper.hxx>
32 : : #include <vcl/svapp.hxx>
33 : : #include <unotools/syslocale.hxx>
34 : :
35 : : //.........................................................................
36 : : namespace frm
37 : : {
38 : : //.........................................................................
39 : : using namespace ::com::sun::star::uno;
40 : : using namespace ::com::sun::star::sdb;
41 : : using namespace ::com::sun::star::sdbc;
42 : : using namespace ::com::sun::star::sdbcx;
43 : : using namespace ::com::sun::star::beans;
44 : : using namespace ::com::sun::star::container;
45 : : using namespace ::com::sun::star::form;
46 : : using namespace ::com::sun::star::awt;
47 : : using namespace ::com::sun::star::io;
48 : : using namespace ::com::sun::star::lang;
49 : : using namespace ::com::sun::star::util;
50 : :
51 : : //==================================================================
52 : : // OCurrencyControl
53 : : //==================================================================
54 : : //------------------------------------------------------------------
55 : 12 : OCurrencyControl::OCurrencyControl(const Reference<XMultiServiceFactory>& _rxFactory)
56 [ + - ]: 12 : :OBoundControl(_rxFactory, VCL_CONTROL_CURRENCYFIELD)
57 : : {
58 : 12 : }
59 : :
60 : : //------------------------------------------------------------------
61 : 12 : InterfaceRef SAL_CALL OCurrencyControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
62 : : {
63 [ + - ]: 12 : return *(new OCurrencyControl(_rxFactory));
64 : : }
65 : :
66 : : //------------------------------------------------------------------------------
67 : 0 : Sequence<Type> OCurrencyControl::_getTypes()
68 : : {
69 : 0 : return OBoundControl::_getTypes();
70 : : }
71 : :
72 : : //------------------------------------------------------------------------------
73 : 0 : StringSequence SAL_CALL OCurrencyControl::getSupportedServiceNames() throw()
74 : : {
75 : 0 : StringSequence aSupported = OBoundControl::getSupportedServiceNames();
76 [ # # ]: 0 : aSupported.realloc(aSupported.getLength() + 1);
77 : :
78 [ # # ]: 0 : ::rtl::OUString*pArray = aSupported.getArray();
79 [ # # ]: 0 : pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_CURRENCYFIELD;
80 : 0 : return aSupported;
81 : : }
82 : :
83 : : //==================================================================
84 : : // OCurrencyModel
85 : : //==================================================================
86 : : //------------------------------------------------------------------
87 : 17 : InterfaceRef SAL_CALL OCurrencyModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
88 : : {
89 [ + - ]: 17 : return *(new OCurrencyModel(_rxFactory));
90 : : }
91 : :
92 : : //------------------------------------------------------------------------------
93 : 4 : Sequence<Type> OCurrencyModel::_getTypes()
94 : : {
95 : 4 : return OEditBaseModel::_getTypes();
96 : : }
97 : :
98 : : //------------------------------------------------------------------
99 : 19 : void OCurrencyModel::implConstruct()
100 : : {
101 [ + - ]: 19 : if (m_xAggregateSet.is())
102 : : {
103 : : try
104 : : {
105 : : // get the system international informations
106 [ + - ]: 19 : const SvtSysLocale aSysLocale;
107 [ + - ]: 19 : const LocaleDataWrapper& aLocaleInfo = aSysLocale.GetLocaleData();
108 : :
109 : 19 : ::rtl::OUString sCurrencySymbol;
110 : : sal_Bool bPrependCurrencySymbol;
111 [ + - - - : 19 : switch ( aLocaleInfo.getCurrPositiveFormat() )
- ][ + - ]
112 : : {
113 : : case 0: // $1
114 [ + - ][ + - ]: 19 : sCurrencySymbol = String(aLocaleInfo.getCurrSymbol());
[ + - ][ + - ]
115 : 19 : bPrependCurrencySymbol = sal_True;
116 : 19 : break;
117 : : case 1: // 1$
118 [ # # ][ # # ]: 0 : sCurrencySymbol = String(aLocaleInfo.getCurrSymbol());
[ # # ][ # # ]
119 : 0 : bPrependCurrencySymbol = sal_False;
120 : 0 : break;
121 : : case 2: // $ 1
122 [ # # ][ # # ]: 0 : sCurrencySymbol = ::rtl::OUString(String(aLocaleInfo.getCurrSymbol())) + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ") );
[ # # ][ # # ]
[ # # ]
123 : 0 : bPrependCurrencySymbol = sal_True;
124 : 0 : break;
125 : : case 3: // 1 $
126 [ # # ][ # # ]: 0 : sCurrencySymbol = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" ") ) + ::rtl::OUString(String(aLocaleInfo.getCurrSymbol()));
[ # # ][ # # ]
[ # # ]
127 : 0 : bPrependCurrencySymbol = sal_False;
128 : 0 : break;
129 : : }
130 [ + - ]: 19 : if (!sCurrencySymbol.isEmpty())
131 : : {
132 [ + - ][ + - ]: 19 : m_xAggregateSet->setPropertyValue(PROPERTY_CURRENCYSYMBOL, makeAny(sCurrencySymbol));
[ + - ][ + - ]
133 [ + - ][ + - ]: 19 : m_xAggregateSet->setPropertyValue(PROPERTY_CURRSYM_POSITION, makeAny(bPrependCurrencySymbol));
[ + - ][ + - ]
134 [ + - ][ # # ]: 19 : }
135 : : }
136 : 0 : catch(const Exception&)
137 : : {
138 : : OSL_FAIL( "OCurrencyModel::implConstruct: caught an exception while initializing the aggregate!" );
139 : : }
140 : : }
141 : 19 : }
142 : :
143 : : //------------------------------------------------------------------
144 : : DBG_NAME( OCurrencyModel )
145 : : //------------------------------------------------------------------
146 : 17 : OCurrencyModel::OCurrencyModel(const Reference<XMultiServiceFactory>& _rxFactory)
147 [ + - ][ + - ]: 17 : :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_CURRENCYFIELD, FRM_SUN_CONTROL_CURRENCYFIELD, sal_False, sal_True )
148 : : // use the old control name for compytibility reasons
149 : : {
150 : : DBG_CTOR( OCurrencyModel, NULL );
151 : :
152 : 17 : m_nClassId = FormComponentType::CURRENCYFIELD;
153 [ + - ][ + - ]: 17 : initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
154 : :
155 [ + - ]: 17 : implConstruct();
156 : 17 : }
157 : :
158 : : //------------------------------------------------------------------
159 : 2 : OCurrencyModel::OCurrencyModel( const OCurrencyModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
160 : 2 : :OEditBaseModel( _pOriginal, _rxFactory )
161 : : {
162 : : DBG_CTOR( OCurrencyModel, NULL );
163 [ + - ]: 2 : implConstruct();
164 : 2 : }
165 : :
166 : : //------------------------------------------------------------------
167 : 19 : OCurrencyModel::~OCurrencyModel()
168 : : {
169 : : DBG_DTOR( OCurrencyModel, NULL );
170 [ - + ]: 38 : }
171 : :
172 : : // XCloneable
173 : : //------------------------------------------------------------------------------
174 [ + - ][ + - ]: 2 : IMPLEMENT_DEFAULT_CLONING( OCurrencyModel )
175 : :
176 : : // XServiceInfo
177 : : //------------------------------------------------------------------------------
178 : 14 : StringSequence SAL_CALL OCurrencyModel::getSupportedServiceNames() throw()
179 : : {
180 : 14 : StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
181 : :
182 : 14 : sal_Int32 nOldLen = aSupported.getLength();
183 [ + - ]: 14 : aSupported.realloc( nOldLen + 4 );
184 [ + - ]: 14 : ::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen;
185 : :
186 [ + - ]: 14 : *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
187 [ + - ]: 14 : *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
188 : :
189 [ + - ]: 14 : *pStoreTo++ = FRM_SUN_COMPONENT_CURRENCYFIELD;
190 [ + - ]: 14 : *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD;
191 : :
192 : 14 : return aSupported;
193 : : }
194 : :
195 : : //------------------------------------------------------------------------------
196 : 21 : void OCurrencyModel::describeFixedProperties( Sequence< Property >& _rProps ) const
197 : : {
198 : 21 : BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel )
199 : : // Value auf transient setzen
200 : : // ModifyPropertyAttributes(_rAggregateProps, PROPERTY_VALUE, PropertyAttribute::TRANSIENT, 0);
201 : :
202 [ + - ][ + - ]: 21 : DECL_PROP3(DEFAULT_VALUE, double, BOUND, MAYBEDEFAULT, MAYBEVOID);
203 [ + - ]: 21 : DECL_PROP1(TABINDEX, sal_Int16, BOUND);
204 : : END_DESCRIBE_PROPERTIES();
205 : 21 : }
206 : :
207 : : //------------------------------------------------------------------------------
208 : 2 : ::rtl::OUString SAL_CALL OCurrencyModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
209 : : {
210 : 2 : return FRM_COMPONENT_CURRENCYFIELD; // old (non-sun) name for compatibility !
211 : : }
212 : :
213 : : //------------------------------------------------------------------------------
214 : 0 : sal_Bool OCurrencyModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
215 : : {
216 [ # # ][ # # ]: 0 : Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
217 [ # # ][ # # ]: 0 : if ( !compare( aControlValue, m_aSaveValue ) )
218 : : {
219 [ # # ]: 0 : if ( aControlValue.getValueType().getTypeClass() == TypeClass_VOID )
220 [ # # ][ # # ]: 0 : m_xColumnUpdate->updateNull();
221 : : else
222 : : {
223 : : try
224 : : {
225 [ # # ][ # # ]: 0 : m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
[ # # ]
226 : : }
227 [ # # ]: 0 : catch(const Exception&)
228 : : {
229 : 0 : return sal_False;
230 : : }
231 : : }
232 : 0 : m_aSaveValue = aControlValue;
233 : : }
234 [ # # ]: 0 : return sal_True;
235 : : }
236 : :
237 : : //------------------------------------------------------------------------------
238 : 0 : Any OCurrencyModel::translateDbColumnToControlValue()
239 : : {
240 [ # # ]: 0 : m_aSaveValue <<= m_xColumn->getDouble();
241 [ # # ]: 0 : if ( m_xColumn->wasNull() )
242 : 0 : m_aSaveValue.clear();
243 : 0 : return m_aSaveValue;
244 : : }
245 : :
246 : : // XReset
247 : : //------------------------------------------------------------------------------
248 : 6 : Any OCurrencyModel::getDefaultForReset() const
249 : : {
250 : 6 : Any aValue;
251 [ - + ]: 6 : if ( m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE )
252 : 0 : aValue = m_aDefault;
253 : :
254 : 6 : return aValue;
255 : : }
256 : :
257 : : //------------------------------------------------------------------------------
258 : 6 : void OCurrencyModel::resetNoBroadcast()
259 : : {
260 : 6 : OEditBaseModel::resetNoBroadcast();
261 : 6 : m_aSaveValue.clear();
262 : 6 : }
263 : :
264 : : //.........................................................................
265 : : } // namespace frm
266 : : //.........................................................................
267 : :
268 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|