xref: /AOO41X/main/forms/source/component/Currency.cxx (revision 24acc54625a85f778a4f966495e8f4cd9d7b247c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_forms.hxx"
26 #include "Currency.hxx"
27 #include <tools/debug.hxx>
28 #include <unotools/localedatawrapper.hxx>
29 #include <vcl/svapp.hxx>
30 #include <unotools/syslocale.hxx>
31 
32 //.........................................................................
33 namespace frm
34 {
35 //.........................................................................
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::sdb;
38 using namespace ::com::sun::star::sdbc;
39 using namespace ::com::sun::star::sdbcx;
40 using namespace ::com::sun::star::beans;
41 using namespace ::com::sun::star::container;
42 using namespace ::com::sun::star::form;
43 using namespace ::com::sun::star::awt;
44 using namespace ::com::sun::star::io;
45 using namespace ::com::sun::star::lang;
46 using namespace ::com::sun::star::util;
47 
48 //==================================================================
49 // OCurrencyControl
50 //==================================================================
51 //------------------------------------------------------------------
OCurrencyControl(const Reference<XMultiServiceFactory> & _rxFactory)52 OCurrencyControl::OCurrencyControl(const Reference<XMultiServiceFactory>& _rxFactory)
53     :OBoundControl(_rxFactory, VCL_CONTROL_CURRENCYFIELD)
54 {
55 }
56 
57 //------------------------------------------------------------------
OCurrencyControl_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)58 InterfaceRef SAL_CALL OCurrencyControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
59 {
60     return *(new OCurrencyControl(_rxFactory));
61 }
62 
63 //------------------------------------------------------------------------------
_getTypes()64 Sequence<Type> OCurrencyControl::_getTypes()
65 {
66     return OBoundControl::_getTypes();
67 }
68 
69 //------------------------------------------------------------------------------
getSupportedServiceNames()70 StringSequence SAL_CALL OCurrencyControl::getSupportedServiceNames() throw()
71 {
72     StringSequence aSupported = OBoundControl::getSupportedServiceNames();
73     aSupported.realloc(aSupported.getLength() + 1);
74 
75     ::rtl::OUString*pArray = aSupported.getArray();
76     pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_CURRENCYFIELD;
77     return aSupported;
78 }
79 
80 //==================================================================
81 // OCurrencyModel
82 //==================================================================
83 //------------------------------------------------------------------
OCurrencyModel_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)84 InterfaceRef SAL_CALL OCurrencyModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
85 {
86     return *(new OCurrencyModel(_rxFactory));
87 }
88 
89 //------------------------------------------------------------------------------
_getTypes()90 Sequence<Type> OCurrencyModel::_getTypes()
91 {
92     return OEditBaseModel::_getTypes();
93 }
94 
95 //------------------------------------------------------------------
implConstruct()96 void OCurrencyModel::implConstruct()
97 {
98     if (m_xAggregateSet.is())
99     {
100         try
101         {
102             // get the system international informations
103             const SvtSysLocale aSysLocale;
104             const LocaleDataWrapper& aLocaleInfo = aSysLocale.GetLocaleData();
105 
106             ::rtl::OUString sCurrencySymbol;
107             sal_Bool bPrependCurrencySymbol;
108             switch ( aLocaleInfo.getCurrPositiveFormat() )
109             {
110                 case 0: // $1
111                     sCurrencySymbol = String(aLocaleInfo.getCurrSymbol());
112                     bPrependCurrencySymbol = sal_True;
113                     break;
114                 case 1: // 1$
115                     sCurrencySymbol = String(aLocaleInfo.getCurrSymbol());
116                     bPrependCurrencySymbol = sal_False;
117                     break;
118                 case 2: // $ 1
119                     sCurrencySymbol = ::rtl::OUString(String(aLocaleInfo.getCurrSymbol())) + ::rtl::OUString::createFromAscii(" ");
120                     bPrependCurrencySymbol = sal_True;
121                     break;
122                 case 3: // 1 $
123                     sCurrencySymbol = ::rtl::OUString::createFromAscii(" ") + ::rtl::OUString(String(aLocaleInfo.getCurrSymbol()));
124                     bPrependCurrencySymbol = sal_False;
125                     break;
126             }
127             if (sCurrencySymbol.getLength())
128             {
129                 m_xAggregateSet->setPropertyValue(PROPERTY_CURRENCYSYMBOL, makeAny(sCurrencySymbol));
130                 m_xAggregateSet->setPropertyValue(PROPERTY_CURRSYM_POSITION, makeAny(bPrependCurrencySymbol));
131             }
132         }
133         catch(Exception&)
134         {
135             DBG_ERROR( "OCurrencyModel::implConstruct: caught an exception while initializing the aggregate!" );
136         }
137     }
138 }
139 
140 //------------------------------------------------------------------
DBG_NAME(OCurrencyModel)141 DBG_NAME( OCurrencyModel )
142 //------------------------------------------------------------------
143 OCurrencyModel::OCurrencyModel(const Reference<XMultiServiceFactory>& _rxFactory)
144     :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_CURRENCYFIELD, FRM_SUN_CONTROL_CURRENCYFIELD, sal_False, sal_True )
145                                     // use the old control name for compytibility reasons
146 {
147     DBG_CTOR( OCurrencyModel, NULL );
148 
149     m_nClassId = FormComponentType::CURRENCYFIELD;
150     initValueProperty( PROPERTY_VALUE, PROPERTY_ID_VALUE );
151 
152     implConstruct();
153 }
154 
155 //------------------------------------------------------------------
OCurrencyModel(const OCurrencyModel * _pOriginal,const Reference<XMultiServiceFactory> & _rxFactory)156 OCurrencyModel::OCurrencyModel( const OCurrencyModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
157     :OEditBaseModel( _pOriginal, _rxFactory )
158 {
159     DBG_CTOR( OCurrencyModel, NULL );
160     implConstruct();
161 }
162 
163 //------------------------------------------------------------------
~OCurrencyModel()164 OCurrencyModel::~OCurrencyModel()
165 {
166     DBG_DTOR( OCurrencyModel, NULL );
167 }
168 
169 // XCloneable
170 //------------------------------------------------------------------------------
IMPLEMENT_DEFAULT_CLONING(OCurrencyModel)171 IMPLEMENT_DEFAULT_CLONING( OCurrencyModel )
172 
173 // XServiceInfo
174 //------------------------------------------------------------------------------
175 StringSequence SAL_CALL OCurrencyModel::getSupportedServiceNames() throw()
176 {
177     StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
178 
179     sal_Int32 nOldLen = aSupported.getLength();
180     aSupported.realloc( nOldLen + 4 );
181     ::rtl::OUString* pStoreTo = aSupported.getArray() + nOldLen;
182 
183     *pStoreTo++ = DATA_AWARE_CONTROL_MODEL;
184     *pStoreTo++ = VALIDATABLE_CONTROL_MODEL;
185 
186     *pStoreTo++ = FRM_SUN_COMPONENT_CURRENCYFIELD;
187     *pStoreTo++ = FRM_SUN_COMPONENT_DATABASE_CURRENCYFIELD;
188 
189     return aSupported;
190 }
191 
192 //------------------------------------------------------------------------------
describeFixedProperties(Sequence<Property> & _rProps) const193 void OCurrencyModel::describeFixedProperties( Sequence< Property >& _rProps ) const
194 {
195     BEGIN_DESCRIBE_PROPERTIES( 2, OEditBaseModel )
196         // Value auf transient setzen
197 //      ModifyPropertyAttributes(_rAggregateProps, PROPERTY_VALUE, PropertyAttribute::TRANSIENT, 0);
198 
199         DECL_PROP3(DEFAULT_VALUE,       double,             BOUND, MAYBEDEFAULT, MAYBEVOID);
200         DECL_PROP1(TABINDEX,        sal_Int16,              BOUND);
201     END_DESCRIBE_PROPERTIES();
202 }
203 
204 //------------------------------------------------------------------------------
getServiceName()205 ::rtl::OUString SAL_CALL OCurrencyModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
206 {
207     return FRM_COMPONENT_CURRENCYFIELD; // old (non-sun) name for compatibility !
208 }
209 
210 //------------------------------------------------------------------------------
commitControlValueToDbColumn(bool)211 sal_Bool OCurrencyModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
212 {
213     Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
214     if ( !compare( aControlValue, m_aSaveValue ) )
215     {
216         if ( aControlValue.getValueType().getTypeClass() == TypeClass_VOID )
217             m_xColumnUpdate->updateNull();
218         else
219         {
220             try
221             {
222                 m_xColumnUpdate->updateDouble( getDouble( aControlValue ) );
223             }
224             catch(Exception&)
225             {
226                 return sal_False;
227             }
228         }
229         m_aSaveValue = aControlValue;
230     }
231     return sal_True;
232 }
233 
234 //------------------------------------------------------------------------------
translateDbColumnToControlValue()235 Any OCurrencyModel::translateDbColumnToControlValue()
236 {
237     m_aSaveValue <<= m_xColumn->getDouble();
238     if ( m_xColumn->wasNull() )
239         m_aSaveValue.clear();
240     return m_aSaveValue;
241 }
242 
243 // XReset
244 //------------------------------------------------------------------------------
getDefaultForReset() const245 Any OCurrencyModel::getDefaultForReset() const
246 {
247     Any aValue;
248     if ( m_aDefault.getValueType().getTypeClass() == TypeClass_DOUBLE )
249         aValue = m_aDefault;
250 
251     return aValue;
252 }
253 
254 //------------------------------------------------------------------------------
resetNoBroadcast()255 void OCurrencyModel::resetNoBroadcast()
256 {
257     OEditBaseModel::resetNoBroadcast();
258     m_aSaveValue.clear();
259 }
260 
261 //.........................................................................
262 }   // namespace frm
263 //.........................................................................
264 
265