1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <tools/debug.hxx>
22 #include <tools/time.hxx>
23 #include <connectivity/dbconversion.hxx>
24 #include <com/sun/star/sdbc/DataType.hpp>
25 #include <comphelper/processfactory.hxx>
27 using namespace dbtools
;
29 //.........................................................................
32 //.........................................................................
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::sdb
;
37 using namespace ::com::sun::star::sdbc
;
38 using namespace ::com::sun::star::sdbcx
;
39 using namespace ::com::sun::star::beans
;
40 using namespace ::com::sun::star::container
;
41 using namespace ::com::sun::star::form
;
42 using namespace ::com::sun::star::util
;
43 using namespace ::com::sun::star::awt
;
44 using namespace ::com::sun::star::io
;
45 using namespace ::com::sun::star::lang
;
47 //==================================================================
49 //==================================================================
51 //==================================================================
53 //==================================================================
54 //------------------------------------------------------------------
55 OTimeControl::OTimeControl(const Reference
<XMultiServiceFactory
>& _rxFactory
)
56 :OBoundControl(_rxFactory
, VCL_CONTROL_TIMEFIELD
)
60 //------------------------------------------------------------------
61 InterfaceRef SAL_CALL
OTimeControl_CreateInstance(const Reference
<XMultiServiceFactory
>& _rxFactory
)
63 return *(new OTimeControl(_rxFactory
));
66 //------------------------------------------------------------------------------
67 Sequence
<Type
> OTimeControl::_getTypes()
69 return OBoundControl::_getTypes();
72 //------------------------------------------------------------------------------
73 StringSequence SAL_CALL
OTimeControl::getSupportedServiceNames() throw()
75 StringSequence aSupported
= OBoundControl::getSupportedServiceNames();
76 aSupported
.realloc(aSupported
.getLength() + 1);
78 OUString
*pArray
= aSupported
.getArray();
79 pArray
[aSupported
.getLength()-1] = FRM_SUN_CONTROL_TIMEFIELD
;
83 //==================================================================
85 //==================================================================
86 //------------------------------------------------------------------
87 InterfaceRef SAL_CALL
OTimeModel_CreateInstance(const Reference
<XMultiServiceFactory
>& _rxFactory
)
89 return *(new OTimeModel(_rxFactory
));
93 //------------------------------------------------------------------------------
94 StringSequence SAL_CALL
OTimeModel::getSupportedServiceNames() throw()
96 StringSequence aSupported
= OBoundControlModel::getSupportedServiceNames();
98 sal_Int32 nOldLen
= aSupported
.getLength();
99 aSupported
.realloc( nOldLen
+ 8 );
100 OUString
* pStoreTo
= aSupported
.getArray() + nOldLen
;
102 *pStoreTo
++ = BINDABLE_CONTROL_MODEL
;
103 *pStoreTo
++ = DATA_AWARE_CONTROL_MODEL
;
104 *pStoreTo
++ = VALIDATABLE_CONTROL_MODEL
;
106 *pStoreTo
++ = BINDABLE_DATA_AWARE_CONTROL_MODEL
;
107 *pStoreTo
++ = VALIDATABLE_BINDABLE_CONTROL_MODEL
;
109 *pStoreTo
++ = FRM_SUN_COMPONENT_TIMEFIELD
;
110 *pStoreTo
++ = FRM_SUN_COMPONENT_DATABASE_TIMEFIELD
;
111 *pStoreTo
++ = BINDABLE_DATABASE_TIME_FIELD
;
116 //------------------------------------------------------------------------------
117 Sequence
<Type
> OTimeModel::_getTypes()
119 return OBoundControlModel::_getTypes();
122 //------------------------------------------------------------------
123 DBG_NAME( OTimeModel
)
124 //------------------------------------------------------------------
125 OTimeModel::OTimeModel(const Reference
<XMultiServiceFactory
>& _rxFactory
)
126 :OEditBaseModel( _rxFactory
, VCL_CONTROLMODEL_TIMEFIELD
, FRM_SUN_CONTROL_TIMEFIELD
, sal_True
, sal_True
)
127 // use the old control name for compytibility reasons
128 ,OLimitedFormats( comphelper::getComponentContext(_rxFactory
), FormComponentType::TIMEFIELD
)
130 DBG_CTOR( OTimeModel
, NULL
);
132 m_nClassId
= FormComponentType::TIMEFIELD
;
133 initValueProperty( PROPERTY_TIME
, PROPERTY_ID_TIME
);
135 setAggregateSet(m_xAggregateFastSet
, getOriginalHandle(PROPERTY_ID_TIMEFORMAT
));
138 //------------------------------------------------------------------------------
139 OTimeModel::OTimeModel( const OTimeModel
* _pOriginal
, const Reference
<XMultiServiceFactory
>& _rxFactory
)
140 :OEditBaseModel( _pOriginal
, _rxFactory
)
141 ,OLimitedFormats( comphelper::getComponentContext(_rxFactory
), FormComponentType::TIMEFIELD
)
143 DBG_CTOR( OTimeModel
, NULL
);
145 setAggregateSet( m_xAggregateFastSet
, getOriginalHandle( PROPERTY_ID_TIMEFORMAT
) );
148 //------------------------------------------------------------------------------
149 OTimeModel::~OTimeModel( )
151 setAggregateSet(Reference
< XFastPropertySet
>(), -1);
152 DBG_DTOR( OTimeModel
, NULL
);
156 //------------------------------------------------------------------------------
157 IMPLEMENT_DEFAULT_CLONING( OTimeModel
)
159 //------------------------------------------------------------------------------
160 OUString SAL_CALL
OTimeModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException
)
162 return OUString(FRM_COMPONENT_TIMEFIELD
); // old (non-sun) name for compatibility !
166 //------------------------------------------------------------------------------
167 void OTimeModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
169 BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel
)
170 DECL_PROP3(DEFAULT_TIME
, util::Time
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
171 DECL_PROP1(TABINDEX
, sal_Int16
, BOUND
);
172 DECL_PROP1(FORMATKEY
, sal_Int32
, TRANSIENT
);
173 DECL_IFACE_PROP2(FORMATSSUPPLIER
, XNumberFormatsSupplier
, READONLY
, TRANSIENT
);
174 END_DESCRIBE_PROPERTIES();
177 //------------------------------------------------------------------------------
178 void SAL_CALL
OTimeModel::getFastPropertyValue(Any
& _rValue
, sal_Int32 _nHandle
) const
182 case PROPERTY_ID_FORMATKEY
:
183 getFormatKeyPropertyValue(_rValue
);
185 case PROPERTY_ID_FORMATSSUPPLIER
:
186 _rValue
<<= getFormatsSupplier();
189 OEditBaseModel::getFastPropertyValue(_rValue
, _nHandle
);
194 //------------------------------------------------------------------------------
195 sal_Bool SAL_CALL
OTimeModel::convertFastPropertyValue(Any
& _rConvertedValue
, Any
& _rOldValue
,
196 sal_Int32 _nHandle
, const Any
& _rValue
) throw(IllegalArgumentException
)
198 if (PROPERTY_ID_FORMATKEY
== _nHandle
)
199 return convertFormatKeyPropertyValue(_rConvertedValue
, _rOldValue
, _rValue
);
201 return OEditBaseModel::convertFastPropertyValue(_rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
204 //------------------------------------------------------------------------------
205 void SAL_CALL
OTimeModel::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle
, const Any
& _rValue
) throw ( ::com::sun::star::uno::Exception
)
207 if (PROPERTY_ID_FORMATKEY
== _nHandle
)
208 setFormatKeyPropertyValue(_rValue
);
210 OEditBaseModel::setFastPropertyValue_NoBroadcast(_nHandle
, _rValue
);
214 //------------------------------------------------------------------------------
215 void OTimeModel::onConnectedDbColumn( const Reference
< XInterface
>& _rxForm
)
217 OBoundControlModel::onConnectedDbColumn( _rxForm
);
218 Reference
<XPropertySet
> xField
= getField();
221 m_bDateTimeField
= sal_False
;
224 sal_Int32 nFieldType
= 0;
225 xField
->getPropertyValue(PROPERTY_FIELDTYPE
) >>= nFieldType
;
226 m_bDateTimeField
= (nFieldType
== DataType::TIMESTAMP
);
228 catch(const Exception
&)
234 //------------------------------------------------------------------------------
235 sal_Bool
OTimeModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
237 Any
aControlValue( m_xAggregateFastSet
->getFastPropertyValue( getValuePropertyAggHandle() ) );
238 if ( !compare( aControlValue
, m_aSaveValue
) )
240 if ( !aControlValue
.hasValue() )
241 m_xColumnUpdate
->updateNull();
247 if ( !( aControlValue
>>= aTime
) )
250 aControlValue
>>= nAsInt
;
251 aTime
= DBTypeConversion::toTime(nAsInt
);
254 if (!m_bDateTimeField
)
255 m_xColumnUpdate
->updateTime(aTime
);
258 util::DateTime aDateTime
= m_xColumn
->getTimestamp();
259 aDateTime
.NanoSeconds
= aTime
.NanoSeconds
;
260 aDateTime
.Seconds
= aTime
.Seconds
;
261 aDateTime
.Minutes
= aTime
.Minutes
;
262 aDateTime
.Hours
= aTime
.Hours
;
263 m_xColumnUpdate
->updateTimestamp(aDateTime
);
266 catch(const Exception
&)
271 m_aSaveValue
= aControlValue
;
276 //------------------------------------------------------------------------------
277 Any
OTimeModel::translateControlValueToExternalValue( ) const
279 return getControlValue();
282 //------------------------------------------------------------------------------
283 Any
OTimeModel::translateExternalValueToControlValue( const Any
& _rExternalValue
) const
285 return _rExternalValue
;
288 //------------------------------------------------------------------------------
289 Any
OTimeModel::translateControlValueToValidatableValue( ) const
291 return getControlValue();
294 //------------------------------------------------------------------------------
295 Any
OTimeModel::translateDbColumnToControlValue()
297 util::Time aTime
= m_xColumn
->getTime();
298 if ( m_xColumn
->wasNull() )
299 m_aSaveValue
.clear();
301 m_aSaveValue
<<= aTime
;
306 //------------------------------------------------------------------------------
307 Any
OTimeModel::getDefaultForReset() const
312 //------------------------------------------------------------------------------
313 void OTimeModel::resetNoBroadcast()
315 OEditBaseModel::resetNoBroadcast();
316 m_aSaveValue
.clear();
319 //------------------------------------------------------------------------------
320 Sequence
< Type
> OTimeModel::getSupportedBindingTypes()
322 return Sequence
< Type
>( &::getCppuType( static_cast< util::Time
* >( NULL
) ), 1 );
325 //.........................................................................
327 //.........................................................................
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */