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/time.hxx>
22 #include <connectivity/dbconversion.hxx>
23 #include <com/sun/star/sdbc/DataType.hpp>
24 #include <comphelper/processfactory.hxx>
26 using namespace dbtools
;
31 using namespace ::com::sun::star
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::sdb
;
34 using namespace ::com::sun::star::sdbc
;
35 using namespace ::com::sun::star::sdbcx
;
36 using namespace ::com::sun::star::beans
;
37 using namespace ::com::sun::star::container
;
38 using namespace ::com::sun::star::form
;
39 using namespace ::com::sun::star::util
;
40 using namespace ::com::sun::star::awt
;
41 using namespace ::com::sun::star::io
;
42 using namespace ::com::sun::star::lang
;
47 OTimeControl::OTimeControl(const Reference
<XComponentContext
>& _rxFactory
)
48 :OBoundControl(_rxFactory
, VCL_CONTROL_TIMEFIELD
)
53 Sequence
<Type
> OTimeControl::_getTypes()
55 return OBoundControl::_getTypes();
59 StringSequence SAL_CALL
OTimeControl::getSupportedServiceNames() throw(std::exception
)
61 StringSequence aSupported
= OBoundControl::getSupportedServiceNames();
62 aSupported
.realloc(aSupported
.getLength() + 2);
64 OUString
*pArray
= aSupported
.getArray();
65 pArray
[aSupported
.getLength()-2] = FRM_SUN_CONTROL_TIMEFIELD
;
66 pArray
[aSupported
.getLength()-1] = STARDIV_ONE_FORM_CONTROL_TIMEFIELD
;
75 StringSequence SAL_CALL
OTimeModel::getSupportedServiceNames() throw(std::exception
)
77 StringSequence aSupported
= OBoundControlModel::getSupportedServiceNames();
79 sal_Int32 nOldLen
= aSupported
.getLength();
80 aSupported
.realloc( nOldLen
+ 9 );
81 OUString
* pStoreTo
= aSupported
.getArray() + nOldLen
;
83 *pStoreTo
++ = BINDABLE_CONTROL_MODEL
;
84 *pStoreTo
++ = DATA_AWARE_CONTROL_MODEL
;
85 *pStoreTo
++ = VALIDATABLE_CONTROL_MODEL
;
87 *pStoreTo
++ = BINDABLE_DATA_AWARE_CONTROL_MODEL
;
88 *pStoreTo
++ = VALIDATABLE_BINDABLE_CONTROL_MODEL
;
90 *pStoreTo
++ = FRM_SUN_COMPONENT_TIMEFIELD
;
91 *pStoreTo
++ = FRM_SUN_COMPONENT_DATABASE_TIMEFIELD
;
92 *pStoreTo
++ = BINDABLE_DATABASE_TIME_FIELD
;
94 *pStoreTo
++ = FRM_COMPONENT_TIMEFIELD
;
100 Sequence
<Type
> OTimeModel::_getTypes()
102 return OBoundControlModel::_getTypes();
107 OTimeModel::OTimeModel(const Reference
<XComponentContext
>& _rxFactory
)
108 : OEditBaseModel(_rxFactory
, VCL_CONTROLMODEL_TIMEFIELD
,
109 FRM_SUN_CONTROL_TIMEFIELD
, true, true)
110 // use the old control name for compatibility reasons
111 , OLimitedFormats(_rxFactory
, FormComponentType::TIMEFIELD
)
112 , m_bDateTimeField(false)
114 m_nClassId
= FormComponentType::TIMEFIELD
;
115 initValueProperty( PROPERTY_TIME
, PROPERTY_ID_TIME
);
117 setAggregateSet(m_xAggregateFastSet
, getOriginalHandle(PROPERTY_ID_TIMEFORMAT
));
121 OTimeModel::OTimeModel(const OTimeModel
* _pOriginal
, const Reference
<XComponentContext
>& _rxFactory
)
122 : OEditBaseModel(_pOriginal
, _rxFactory
)
123 , OLimitedFormats(_rxFactory
, FormComponentType::TIMEFIELD
)
124 , m_bDateTimeField(false)
126 setAggregateSet( m_xAggregateFastSet
, getOriginalHandle( PROPERTY_ID_TIMEFORMAT
) );
130 OTimeModel::~OTimeModel( )
132 setAggregateSet(Reference
< XFastPropertySet
>(), -1);
137 IMPLEMENT_DEFAULT_CLONING( OTimeModel
)
140 OUString SAL_CALL
OTimeModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException
, std::exception
)
142 return OUString(FRM_COMPONENT_TIMEFIELD
); // old (non-sun) name for compatibility !
147 void OTimeModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
149 BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel
)
150 DECL_PROP3(DEFAULT_TIME
, util::Time
, BOUND
, MAYBEDEFAULT
, MAYBEVOID
);
151 DECL_PROP1(TABINDEX
, sal_Int16
, BOUND
);
152 DECL_PROP1(FORMATKEY
, sal_Int32
, TRANSIENT
);
153 DECL_IFACE_PROP2(FORMATSSUPPLIER
, XNumberFormatsSupplier
, READONLY
, TRANSIENT
);
154 END_DESCRIBE_PROPERTIES();
158 void SAL_CALL
OTimeModel::getFastPropertyValue(Any
& _rValue
, sal_Int32 _nHandle
) const
162 case PROPERTY_ID_FORMATKEY
:
163 getFormatKeyPropertyValue(_rValue
);
165 case PROPERTY_ID_FORMATSSUPPLIER
:
166 _rValue
<<= getFormatsSupplier();
169 OEditBaseModel::getFastPropertyValue(_rValue
, _nHandle
);
175 sal_Bool SAL_CALL
OTimeModel::convertFastPropertyValue(Any
& _rConvertedValue
, Any
& _rOldValue
,
176 sal_Int32 _nHandle
, const Any
& _rValue
) throw(IllegalArgumentException
)
178 if (PROPERTY_ID_FORMATKEY
== _nHandle
)
179 return convertFormatKeyPropertyValue(_rConvertedValue
, _rOldValue
, _rValue
);
181 return OEditBaseModel::convertFastPropertyValue(_rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
185 void SAL_CALL
OTimeModel::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle
, const Any
& _rValue
) throw ( ::com::sun::star::uno::Exception
, std::exception
)
187 if (PROPERTY_ID_FORMATKEY
== _nHandle
)
188 setFormatKeyPropertyValue(_rValue
);
190 OEditBaseModel::setFastPropertyValue_NoBroadcast(_nHandle
, _rValue
);
195 void OTimeModel::onConnectedDbColumn( const Reference
< XInterface
>& _rxForm
)
197 OBoundControlModel::onConnectedDbColumn( _rxForm
);
198 Reference
<XPropertySet
> xField
= getField();
201 m_bDateTimeField
= false;
204 sal_Int32 nFieldType
= 0;
205 xField
->getPropertyValue(PROPERTY_FIELDTYPE
) >>= nFieldType
;
206 m_bDateTimeField
= (nFieldType
== DataType::TIMESTAMP
);
208 catch(const Exception
&)
215 bool OTimeModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
217 Any
aControlValue( m_xAggregateFastSet
->getFastPropertyValue( getValuePropertyAggHandle() ) );
218 if ( !compare( aControlValue
, m_aSaveValue
) )
220 if ( !aControlValue
.hasValue() )
221 m_xColumnUpdate
->updateNull();
227 if ( !( aControlValue
>>= aTime
) )
230 aControlValue
>>= nAsInt
;
231 aTime
= DBTypeConversion::toTime(nAsInt
);
234 if (!m_bDateTimeField
)
235 m_xColumnUpdate
->updateTime(aTime
);
238 util::DateTime aDateTime
= m_xColumn
->getTimestamp();
239 aDateTime
.NanoSeconds
= aTime
.NanoSeconds
;
240 aDateTime
.Seconds
= aTime
.Seconds
;
241 aDateTime
.Minutes
= aTime
.Minutes
;
242 aDateTime
.Hours
= aTime
.Hours
;
243 m_xColumnUpdate
->updateTimestamp(aDateTime
);
246 catch(const Exception
&)
251 m_aSaveValue
= aControlValue
;
257 Any
OTimeModel::translateControlValueToExternalValue( ) const
259 return getControlValue();
263 Any
OTimeModel::translateExternalValueToControlValue( const Any
& _rExternalValue
) const
265 return _rExternalValue
;
269 Any
OTimeModel::translateControlValueToValidatableValue( ) const
271 return getControlValue();
275 Any
OTimeModel::translateDbColumnToControlValue()
277 util::Time aTime
= m_xColumn
->getTime();
278 if ( m_xColumn
->wasNull() )
279 m_aSaveValue
.clear();
281 m_aSaveValue
<<= aTime
;
287 Any
OTimeModel::getDefaultForReset() const
293 void OTimeModel::resetNoBroadcast()
295 OEditBaseModel::resetNoBroadcast();
296 m_aSaveValue
.clear();
300 Sequence
< Type
> OTimeModel::getSupportedBindingTypes()
302 return Sequence
< Type
>( & cppu::UnoType
<util::Time
>::get(), 1 );
307 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface
* SAL_CALL
308 com_sun_star_form_OTimeModel_get_implementation(::com::sun::star::uno::XComponentContext
* component
,
309 ::com::sun::star::uno::Sequence
<css::uno::Any
> const &)
311 return cppu::acquire(new frm::OTimeModel(component
));
314 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface
* SAL_CALL
315 com_sun_star_form_OTimeControl_get_implementation(::com::sun::star::uno::XComponentContext
* component
,
316 ::com::sun::star::uno::Sequence
<css::uno::Any
> const &)
318 return cppu::acquire(new frm::OTimeControl(component
));
321 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */